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