Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 secunet Security Networks AG |
| 5 | * Copyright (C) 2015 Damien Zammit <damien@zamaudio.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 19 | #include <device/pci_ops.h> |
Martin Roth | cbe3892 | 2016-01-05 19:40:41 -0700 | [diff] [blame] | 20 | #include "iomap.h" |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 21 | #if CONFIG(SOUTHBRIDGE_INTEL_I82801GX) |
Martin Roth | cbe3892 | 2016-01-05 19:40:41 -0700 | [diff] [blame] | 22 | #include <southbridge/intel/i82801gx/i82801gx.h> /* DEFAULT_PMBASE */ |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 23 | #else |
| 24 | #include <southbridge/intel/i82801jx/i82801jx.h> /* DEFAULT_PMBASE */ |
| 25 | #endif |
Arthur Heymans | eff0c6a | 2016-06-18 21:52:30 +0200 | [diff] [blame] | 26 | #include <pc80/mc146818rtc.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 27 | #include "x4x.h" |
Arthur Heymans | ef7e98a | 2016-12-30 21:07:18 +0100 | [diff] [blame] | 28 | #include <console/console.h> |
Arthur Heymans | ef7e98a | 2016-12-30 21:07:18 +0100 | [diff] [blame] | 29 | #include <romstage_handoff.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 30 | |
| 31 | void x4x_early_init(void) |
| 32 | { |
Antonello Dettori | 60a6e15 | 2016-09-03 10:45:33 +0200 | [diff] [blame] | 33 | const pci_devfn_t d0f0 = PCI_DEV(0, 0, 0); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 34 | |
| 35 | /* Setup MCHBAR. */ |
| 36 | pci_write_config32(d0f0, D0F0_MCHBAR_LO, (uintptr_t)DEFAULT_MCHBAR | 1); |
| 37 | |
| 38 | /* Setup DMIBAR. */ |
| 39 | pci_write_config32(d0f0, D0F0_DMIBAR_LO, (uintptr_t)DEFAULT_DMIBAR | 1); |
| 40 | |
| 41 | /* Setup EPBAR. */ |
| 42 | pci_write_config32(d0f0, D0F0_EPBAR_LO, DEFAULT_EPBAR | 1); |
| 43 | |
| 44 | /* Setup PMBASE */ |
Damien Zammit | fe9876a | 2016-01-22 19:11:05 +1100 | [diff] [blame] | 45 | pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1); |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 46 | pci_write_config8(PCI_DEV(0, 0x1f, 0), ACPI_CNTL, 0x80); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 47 | |
| 48 | /* Setup HECIBAR */ |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 49 | pci_write_config32(PCI_DEV(0, 3, 0), 0x10, DEFAULT_HECIBAR); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 50 | |
| 51 | /* Set C0000-FFFFF to access RAM on both reads and writes */ |
| 52 | pci_write_config8(d0f0, D0F0_PAM(0), 0x30); |
| 53 | pci_write_config8(d0f0, D0F0_PAM(1), 0x33); |
| 54 | pci_write_config8(d0f0, D0F0_PAM(2), 0x33); |
| 55 | pci_write_config8(d0f0, D0F0_PAM(3), 0x33); |
| 56 | pci_write_config8(d0f0, D0F0_PAM(4), 0x33); |
| 57 | pci_write_config8(d0f0, D0F0_PAM(5), 0x33); |
| 58 | pci_write_config8(d0f0, D0F0_PAM(6), 0x33); |
| 59 | |
Arthur Heymans | d6f3dd8 | 2017-12-27 00:12:35 +0100 | [diff] [blame] | 60 | printk(BIOS_DEBUG, "Disabling Watchdog reboot..."); |
| 61 | RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */ |
| 62 | outw(1 << 11, DEFAULT_PMBASE + 0x60 + 0x08); /* halt timer */ |
| 63 | outw(1 << 3, DEFAULT_PMBASE + 0x60 + 0x04); /* clear timeout */ |
| 64 | outw(1 << 1, DEFAULT_PMBASE + 0x60 + 0x06); /* clear 2nd timeout */ |
| 65 | printk(BIOS_DEBUG, " done.\n"); |
| 66 | |
Arthur Heymans | 5e3cb72 | 2017-03-05 10:57:02 +0100 | [diff] [blame] | 67 | if (!(pci_read_config32(d0f0, D0F0_CAPID0 + 4) & (1 << (46 - 32)))) { |
| 68 | /* Enable internal GFX */ |
| 69 | pci_write_config32(d0f0, D0F0_DEVEN, BOARD_DEVEN); |
Arthur Heymans | eff0c6a | 2016-06-18 21:52:30 +0200 | [diff] [blame] | 70 | |
Nico Huber | cfd433b | 2017-05-12 17:10:58 +0200 | [diff] [blame] | 71 | /* Set preallocated IGD size from cmos */ |
| 72 | u8 gfxsize = 6; /* 6 for 64MiB, default if not set in cmos */ |
| 73 | get_option(&gfxsize, "gfx_uma_size"); |
| 74 | if (gfxsize > 12) |
Arthur Heymans | 5e3cb72 | 2017-03-05 10:57:02 +0100 | [diff] [blame] | 75 | gfxsize = 6; |
Arthur Heymans | 16a70a4 | 2017-09-22 12:22:24 +0200 | [diff] [blame] | 76 | /* Need at least 4M for cbmem_top alignment */ |
| 77 | else if (gfxsize < 1) |
| 78 | gfxsize = 1; |
| 79 | /* Set GTT size to 2+2M */ |
| 80 | pci_write_config16(d0f0, D0F0_GGC, 0x0b00 | (gfxsize + 1) << 4); |
Arthur Heymans | 5e3cb72 | 2017-03-05 10:57:02 +0100 | [diff] [blame] | 81 | } else { /* Does not feature internal graphics */ |
| 82 | pci_write_config32(d0f0, D0F0_DEVEN, D0EN | D1EN | PEG1EN); |
| 83 | pci_write_config16(d0f0, D0F0_GGC, (1 << 1)); |
Arthur Heymans | eff0c6a | 2016-06-18 21:52:30 +0200 | [diff] [blame] | 84 | } |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 85 | } |
Arthur Heymans | ef7e98a | 2016-12-30 21:07:18 +0100 | [diff] [blame] | 86 | |
| 87 | static void init_egress(void) |
| 88 | { |
| 89 | u32 reg32; |
| 90 | |
| 91 | /* VC0: TC0 only */ |
| 92 | EPBAR8(0x14) = 1; |
| 93 | EPBAR8(0x4) = 1; |
| 94 | |
| 95 | switch (MCHBAR32(0xc00) & 0x7) { |
| 96 | case 0x0: |
| 97 | /* FSB 1066 */ |
| 98 | EPBAR32(0x2c) = 0x0001a6db; |
| 99 | break; |
| 100 | case 0x2: |
| 101 | /* FSB 800 */ |
| 102 | EPBAR32(0x2c) = 0x00014514; |
| 103 | break; |
| 104 | default: |
| 105 | case 0x4: |
| 106 | /* FSB 1333 */ |
| 107 | EPBAR32(0x2c) = 0x00022861; |
| 108 | break; |
| 109 | } |
| 110 | EPBAR32(0x28) = 0x0a0a0a0a; |
| 111 | EPBAR8(0xc) = (EPBAR8(0xc) & ~0xe) | 2; |
| 112 | EPBAR32(0x1c) = (EPBAR32(0x1c) & ~0x7f0000) | 0x0a0000; |
| 113 | MCHBAR8(0x3c) = MCHBAR8(0x3c) | 0x7; |
| 114 | |
| 115 | /* VC1: ID1, TC7 */ |
| 116 | reg32 = (EPBAR32(0x20) & ~(7 << 24)) | (1 << 24); |
| 117 | reg32 = (reg32 & ~0xfe) | (1 << 7); |
| 118 | EPBAR32(0x20) = reg32; |
| 119 | |
| 120 | /* Init VC1 port arbitration table */ |
| 121 | EPBAR32(0x100) = 0x001000001; |
| 122 | EPBAR32(0x104) = 0x000040000; |
| 123 | EPBAR32(0x108) = 0x000001000; |
| 124 | EPBAR32(0x10c) = 0x000000040; |
| 125 | EPBAR32(0x110) = 0x001000001; |
| 126 | EPBAR32(0x114) = 0x000040000; |
| 127 | EPBAR32(0x118) = 0x000001000; |
| 128 | EPBAR32(0x11c) = 0x000000040; |
| 129 | |
| 130 | /* Load table */ |
| 131 | reg32 = EPBAR32(0x20) | (1 << 16); |
| 132 | EPBAR32(0x20) = reg32; |
| 133 | asm("nop"); |
| 134 | EPBAR32(0x20) = reg32; |
| 135 | |
| 136 | /* Wait for table load */ |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 137 | while ((EPBAR8(0x26) & (1 << 0)) != 0) |
| 138 | ; |
Arthur Heymans | ef7e98a | 2016-12-30 21:07:18 +0100 | [diff] [blame] | 139 | |
| 140 | /* VC1: enable */ |
| 141 | EPBAR32(0x20) |= 1 << 31; |
| 142 | |
| 143 | /* Wait for VC1 */ |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 144 | while ((EPBAR8(0x26) & (1 << 1)) != 0) |
| 145 | ; |
Arthur Heymans | ef7e98a | 2016-12-30 21:07:18 +0100 | [diff] [blame] | 146 | |
| 147 | printk(BIOS_DEBUG, "Done Egress Port\n"); |
| 148 | } |
| 149 | |
| 150 | static void init_dmi(void) |
| 151 | { |
| 152 | u32 reg32; |
| 153 | u16 reg16; |
| 154 | |
| 155 | /* Assume IGD present */ |
| 156 | |
| 157 | /* Clear error status */ |
| 158 | DMIBAR32(0x1c4) = 0xffffffff; |
| 159 | DMIBAR32(0x1d0) = 0xffffffff; |
| 160 | |
| 161 | /* VC0: TC0 only */ |
| 162 | DMIBAR8(DMIVC0RCTL) = 1; |
| 163 | DMIBAR8(0x4) = 1; |
| 164 | |
| 165 | /* VC1: ID1, TC7 */ |
| 166 | reg32 = (DMIBAR32(DMIVC1RCTL) & ~(7 << 24)) | (1 << 24); |
| 167 | reg32 = (reg32 & ~0xff) | 1 << 7; |
| 168 | |
| 169 | /* VC1: enable */ |
| 170 | reg32 |= 1 << 31; |
| 171 | reg32 = (reg32 & ~(0x7 << 17)) | (0x4 << 17); |
| 172 | |
| 173 | DMIBAR32(DMIVC1RCTL) = reg32; |
| 174 | |
| 175 | /* Set up VCs in southbridge RCBA */ |
| 176 | RCBA8(0x3022) &= ~1; |
| 177 | |
| 178 | reg32 = (0x5 << 28) | (1 << 6); /* PCIe x4 */ |
| 179 | RCBA32(0x2020) = (RCBA32(0x2020) & ~((0xf << 28) | (0x7 << 6))) | reg32; |
| 180 | |
| 181 | /* Assign VC1 id 1 */ |
| 182 | RCBA32(0x20) = (RCBA32(0x20) & ~(0x7 << 24)) | (1 << 24); |
| 183 | |
| 184 | /* Map TC7 to VC1 */ |
| 185 | RCBA8(0x20) &= 1; |
| 186 | RCBA8(0x20) |= 1 << 7; |
| 187 | |
| 188 | /* Map TC0 to VC0 */ |
| 189 | RCBA8(0x14) &= 1; |
| 190 | |
| 191 | /* Init DMI VC1 port arbitration table */ |
| 192 | RCBA32(0x20) &= 0xfff1ffff; |
| 193 | RCBA32(0x20) |= 1 << 19; |
| 194 | |
| 195 | RCBA32(0x30) = 0x0000000f; |
| 196 | RCBA32(0x34) = 0x000f0000; |
| 197 | RCBA32(0x38) = 0; |
| 198 | RCBA32(0x3c) = 0x000000f0; |
| 199 | RCBA32(0x40) = 0x0f000000; |
| 200 | RCBA32(0x44) = 0; |
| 201 | RCBA32(0x48) = 0x0000f000; |
| 202 | RCBA32(0x4c) = 0; |
| 203 | RCBA32(0x50) = 0x0000000f; |
| 204 | RCBA32(0x54) = 0x000f0000; |
| 205 | RCBA32(0x58) = 0; |
| 206 | RCBA32(0x5c) = 0x000000f0; |
| 207 | RCBA32(0x60) = 0x0f000000; |
| 208 | RCBA32(0x64) = 0; |
| 209 | RCBA32(0x68) = 0x0000f000; |
| 210 | RCBA32(0x6c) = 0; |
| 211 | |
| 212 | RCBA32(0x20) |= 1 << 16; |
| 213 | |
| 214 | /* Enable VC1 */ |
| 215 | RCBA32(0x20) |= 1 << 31; |
| 216 | |
| 217 | /* Wait for VC1 */ |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 218 | while ((RCBA8(0x26) & (1 << 1)) != 0) |
| 219 | ; |
Arthur Heymans | ef7e98a | 2016-12-30 21:07:18 +0100 | [diff] [blame] | 220 | |
| 221 | /* Wait for table load */ |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 222 | while ((RCBA8(0x26) & (1 << 0)) != 0) |
| 223 | ; |
Arthur Heymans | ef7e98a | 2016-12-30 21:07:18 +0100 | [diff] [blame] | 224 | |
| 225 | /* ASPM on DMI link */ |
| 226 | RCBA16(0x1a8) &= ~0x3; |
| 227 | reg16 = RCBA16(0x1a8); |
| 228 | RCBA32(0x2010) = (RCBA32(0x2010) & ~(0x3 << 10)) | (1 << 10); |
| 229 | reg32 = RCBA32(0x2010); |
| 230 | |
| 231 | /* Set up VC1 max time */ |
| 232 | RCBA32(0x1c) = (RCBA32(0x1c) & ~0x7f0000) | 0x120000; |
| 233 | |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 234 | while ((DMIBAR32(0x26) & (1 << 1)) != 0) |
| 235 | ; |
Arthur Heymans | ef7e98a | 2016-12-30 21:07:18 +0100 | [diff] [blame] | 236 | printk(BIOS_DEBUG, "Done DMI setup\n"); |
| 237 | |
| 238 | /* ASPM on DMI */ |
| 239 | DMIBAR32(0x200) &= ~(0x3 << 26); |
| 240 | DMIBAR16(0x210) = (DMIBAR16(0x210) & ~(0xff7)) | 0x101; |
| 241 | DMIBAR32(0x88) &= ~0x3; |
| 242 | DMIBAR32(0x88) |= 0x3; |
| 243 | reg16 = DMIBAR16(0x88); |
| 244 | } |
| 245 | |
| 246 | static void x4x_prepare_resume(int s3resume) |
| 247 | { |
Arthur Heymans | ef7e98a | 2016-12-30 21:07:18 +0100 | [diff] [blame] | 248 | romstage_handoff_init(s3resume); |
| 249 | } |
| 250 | |
| 251 | void x4x_late_init(int s3resume) |
| 252 | { |
| 253 | init_egress(); |
| 254 | init_dmi(); |
| 255 | x4x_prepare_resume(s3resume); |
| 256 | } |