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