Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 2 | |
Elyes HAOUAS | 3dff32c | 2020-03-30 17:16:51 +0200 | [diff] [blame] | 3 | #include <cbmem.h> |
Elyes HAOUAS | 5db9871 | 2019-04-21 18:50:34 +0200 | [diff] [blame] | 4 | #include <cf9_reset.h> |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 5 | #include <console/console.h> |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 6 | #include <device/pci_def.h> |
Elyes HAOUAS | 3dff32c | 2020-03-30 17:16:51 +0200 | [diff] [blame] | 7 | #include <device/pci_ops.h> |
| 8 | #include <device/pci.h> |
Kyösti Mälkki | cbf9571 | 2020-01-05 08:05:45 +0200 | [diff] [blame] | 9 | #include <option.h> |
Elyes HAOUAS | 3dff32c | 2020-03-30 17:16:51 +0200 | [diff] [blame] | 10 | #include <romstage_handoff.h> |
Elyes HAOUAS | 51401c3 | 2019-05-15 21:09:30 +0200 | [diff] [blame] | 11 | #include <types.h> |
| 12 | |
| 13 | #include "i945.h" |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 14 | |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 15 | int i945_silicon_revision(void) |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 16 | { |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 17 | return pci_read_config8(HOST_BRIDGE, PCI_CLASS_REVISION); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 18 | } |
| 19 | |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 20 | static void i945m_detect_chipset(void) |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 21 | { |
| 22 | u8 reg8; |
| 23 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 24 | printk(BIOS_INFO, "\n"); |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 25 | reg8 = (pci_read_config8(HOST_BRIDGE, 0xe7) & 0x70) >> 4; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 26 | switch (reg8) { |
| 27 | case 1: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 28 | printk(BIOS_INFO, "Mobile Intel(R) 82945GM/GME Express"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 29 | break; |
| 30 | case 2: |
Stefan Reinauer | 7981b94 | 2011-04-01 22:33:25 +0200 | [diff] [blame] | 31 | printk(BIOS_INFO, "Mobile Intel(R) 82945GMS/GU/GSE Express"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 32 | break; |
| 33 | case 3: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 34 | printk(BIOS_INFO, "Mobile Intel(R) 82945PM Express"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 35 | break; |
| 36 | case 5: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 37 | printk(BIOS_INFO, "Intel(R) 82945GT Express"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 38 | break; |
| 39 | case 6: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 40 | printk(BIOS_INFO, "Mobile Intel(R) 82943/82940GML Express"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 41 | break; |
Elyes HAOUAS | 3dff32c | 2020-03-30 17:16:51 +0200 | [diff] [blame] | 42 | default: /* Others reserved. */ |
| 43 | printk(BIOS_INFO, "Unknown (%02x)", reg8); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 44 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 45 | printk(BIOS_INFO, " Chipset\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 46 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 47 | printk(BIOS_DEBUG, "(G)MCH capable of up to FSB "); |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 48 | reg8 = (pci_read_config8(HOST_BRIDGE, 0xe3) & 0xe0) >> 5; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 49 | switch (reg8) { |
| 50 | case 2: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 51 | printk(BIOS_DEBUG, "800 MHz"); /* According to 965 spec */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 52 | break; |
| 53 | case 3: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 54 | printk(BIOS_DEBUG, "667 MHz"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 55 | break; |
| 56 | case 4: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 57 | printk(BIOS_DEBUG, "533 MHz"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 58 | break; |
| 59 | default: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 60 | printk(BIOS_DEBUG, "N/A MHz (%02x)", reg8); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 61 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 62 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 63 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 64 | printk(BIOS_DEBUG, "(G)MCH capable of "); |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 65 | reg8 = (pci_read_config8(HOST_BRIDGE, 0xe4) & 0x07); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 66 | switch (reg8) { |
| 67 | case 2: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 68 | printk(BIOS_DEBUG, "up to DDR2-667"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 69 | break; |
| 70 | case 3: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 71 | printk(BIOS_DEBUG, "up to DDR2-533"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 72 | break; |
| 73 | case 4: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 74 | printk(BIOS_DEBUG, "DDR2-400"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 75 | break; |
Elyes HAOUAS | 3dff32c | 2020-03-30 17:16:51 +0200 | [diff] [blame] | 76 | default: /* Others reserved. */ |
| 77 | printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 78 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 79 | printk(BIOS_DEBUG, "\n"); |
Elyes HAOUAS | 6372a0e | 2016-10-30 18:39:53 +0100 | [diff] [blame] | 80 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 81 | if (CONFIG(NORTHBRIDGE_INTEL_SUBTYPE_I945GC)) |
Elyes HAOUAS | 6372a0e | 2016-10-30 18:39:53 +0100 | [diff] [blame] | 82 | printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 85 | static void i945_detect_chipset(void) |
| 86 | { |
| 87 | u8 reg8; |
| 88 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 89 | printk(BIOS_INFO, "\nIntel(R) "); |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 90 | |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 91 | reg8 = ((pci_read_config8(HOST_BRIDGE, 0xe7) >> 5) & 4) |
| 92 | | ((pci_read_config8(HOST_BRIDGE, 0xe4) >> 4) & 3); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 93 | switch (reg8) { |
| 94 | case 0: |
| 95 | case 1: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 96 | printk(BIOS_INFO, "82945G"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 97 | break; |
| 98 | case 2: |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 99 | case 3: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 100 | printk(BIOS_INFO, "82945P"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 101 | break; |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 102 | case 4: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 103 | printk(BIOS_INFO, "82945GC"); |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 104 | break; |
| 105 | case 5: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 106 | printk(BIOS_INFO, "82945GZ"); |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 107 | break; |
| 108 | case 6: |
| 109 | case 7: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 110 | printk(BIOS_INFO, "82945PL"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 111 | break; |
| 112 | default: |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 113 | break; |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 114 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 115 | printk(BIOS_INFO, " Chipset\n"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 116 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 117 | printk(BIOS_DEBUG, "(G)MCH capable of "); |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 118 | reg8 = (pci_read_config8(HOST_BRIDGE, 0xe4) & 0x07); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 119 | switch (reg8) { |
| 120 | case 0: |
Elyes HAOUAS | 5db9450 | 2016-10-30 18:30:21 +0100 | [diff] [blame] | 121 | case 2: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 122 | printk(BIOS_DEBUG, "up to DDR2-667"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 123 | break; |
| 124 | case 3: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 125 | printk(BIOS_DEBUG, "up to DDR2-533"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 126 | break; |
Elyes HAOUAS | 3dff32c | 2020-03-30 17:16:51 +0200 | [diff] [blame] | 127 | default: /* Others reserved. */ |
| 128 | printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 129 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 130 | printk(BIOS_DEBUG, "\n"); |
Elyes HAOUAS | 6372a0e | 2016-10-30 18:39:53 +0100 | [diff] [blame] | 131 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 132 | if (CONFIG(NORTHBRIDGE_INTEL_SUBTYPE_I945GM)) |
Elyes HAOUAS | 6372a0e | 2016-10-30 18:39:53 +0100 | [diff] [blame] | 133 | printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 136 | static void i945_setup_bars(void) |
| 137 | { |
Arthur Heymans | 874a8f9 | 2016-05-19 16:06:09 +0200 | [diff] [blame] | 138 | u8 reg8, gfxsize; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 139 | |
| 140 | /* As of now, we don't have all the A0 workarounds implemented */ |
| 141 | if (i945_silicon_revision() == 0) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 142 | printk(BIOS_INFO, "Warning: i945 silicon revision A0 might not work correctly.\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 143 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 144 | printk(BIOS_DEBUG, "Setting up static northbridge registers..."); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 145 | /* Set up all hardcoded northbridge BARs */ |
Angel Pons | 4299cb4 | 2021-01-20 12:32:22 +0100 | [diff] [blame] | 146 | pci_write_config32(HOST_BRIDGE, EPBAR, CONFIG_FIXED_EPBAR_MMIO_BASE | 1); |
| 147 | pci_write_config32(HOST_BRIDGE, MCHBAR, CONFIG_FIXED_MCHBAR_MMIO_BASE | 1); |
| 148 | pci_write_config32(HOST_BRIDGE, DMIBAR, CONFIG_FIXED_DMIBAR_MMIO_BASE | 1); |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 149 | pci_write_config32(HOST_BRIDGE, X60BAR, DEFAULT_X60BAR | 1); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 150 | |
Elyes HAOUAS | 2119d0b | 2020-02-16 10:01:33 +0100 | [diff] [blame] | 151 | /* vram size from CMOS option */ |
Arthur Heymans | 874a8f9 | 2016-05-19 16:06:09 +0200 | [diff] [blame] | 152 | if (get_option(&gfxsize, "gfx_uma_size") != CB_SUCCESS) |
| 153 | gfxsize = 2; /* 2 for 8MB */ |
| 154 | /* make sure no invalid setting is used */ |
| 155 | if (gfxsize > 6) |
| 156 | gfxsize = 2; |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 157 | pci_write_config16(HOST_BRIDGE, GGC, ((gfxsize + 1) << 4)); |
Arthur Heymans | d522db0 | 2018-08-06 15:50:54 +0200 | [diff] [blame] | 158 | /* TSEG 2M, This amount can easily be covered by SMRR MTRR's, |
| 159 | which requires to have TSEG_BASE aligned to TSEG_SIZE. */ |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 160 | pci_update_config8(HOST_BRIDGE, ESMRAMC, ~0x07, (1 << 1) | (1 << 0)); |
Arthur Heymans | e07df9d | 2018-04-09 22:03:21 +0200 | [diff] [blame] | 161 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 162 | /* Set C0000-FFFFF to access RAM on both reads and writes */ |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 163 | pci_write_config8(HOST_BRIDGE, PAM0, 0x30); |
| 164 | pci_write_config8(HOST_BRIDGE, PAM1, 0x33); |
| 165 | pci_write_config8(HOST_BRIDGE, PAM2, 0x33); |
| 166 | pci_write_config8(HOST_BRIDGE, PAM3, 0x33); |
| 167 | pci_write_config8(HOST_BRIDGE, PAM4, 0x33); |
| 168 | pci_write_config8(HOST_BRIDGE, PAM5, 0x33); |
| 169 | pci_write_config8(HOST_BRIDGE, PAM6, 0x33); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 170 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 171 | printk(BIOS_DEBUG, " done.\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 172 | |
| 173 | /* Wait for MCH BAR to come up */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 174 | printk(BIOS_DEBUG, "Waiting for MCHBAR to come up..."); |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 175 | if ((pci_read_config32(HOST_BRIDGE, 0xe4) & 0x20000) == 0x00) { /* Bit 49 of CAPID0 */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 176 | do { |
| 177 | reg8 = *(volatile u8 *)0xfed40000; |
| 178 | } while (!(reg8 & 0x80)); |
| 179 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 180 | printk(BIOS_DEBUG, "ok\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static void i945_setup_egress_port(void) |
| 184 | { |
| 185 | u32 reg32; |
| 186 | u32 timeout; |
| 187 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 188 | printk(BIOS_DEBUG, "Setting up Egress Port RCRB\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 189 | |
| 190 | /* Egress Port Virtual Channel 0 Configuration */ |
| 191 | |
| 192 | /* map only TC0 to VC0 */ |
| 193 | reg32 = EPBAR32(EPVC0RCTL); |
| 194 | reg32 &= 0xffffff01; |
| 195 | EPBAR32(EPVC0RCTL) = reg32; |
| 196 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 197 | reg32 = EPBAR32(EPPVCCAP1); |
| 198 | reg32 &= ~(7 << 0); |
| 199 | reg32 |= 1; |
| 200 | EPBAR32(EPPVCCAP1) = reg32; |
| 201 | |
| 202 | /* Egress Port Virtual Channel 1 Configuration */ |
| 203 | reg32 = EPBAR32(0x2c); |
| 204 | reg32 &= 0xffffff00; |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 205 | if (CONFIG(NORTHBRIDGE_INTEL_SUBTYPE_I945GC)) { |
Elyes HAOUAS | f7acdf8 | 2016-10-31 18:55:04 +0100 | [diff] [blame] | 206 | if ((MCHBAR32(CLKCFG) & 7) == 0) |
| 207 | reg32 |= 0x1a; /* 1067MHz */ |
| 208 | } |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 209 | if ((MCHBAR32(CLKCFG) & 7) == 1) |
| 210 | reg32 |= 0x0d; /* 533MHz */ |
Elyes HAOUAS | f7acdf8 | 2016-10-31 18:55:04 +0100 | [diff] [blame] | 211 | if ((MCHBAR32(CLKCFG) & 7) == 2) |
| 212 | reg32 |= 0x14; /* 800MHz */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 213 | if ((MCHBAR32(CLKCFG) & 7) == 3) |
| 214 | reg32 |= 0x10; /* 667MHz */ |
| 215 | EPBAR32(0x2c) = reg32; |
| 216 | |
| 217 | EPBAR32(EPVC1MTS) = 0x0a0a0a0a; |
| 218 | |
| 219 | reg32 = EPBAR32(EPVC1RCAP); |
| 220 | reg32 &= ~(0x7f << 16); |
| 221 | reg32 |= (0x0a << 16); |
| 222 | EPBAR32(EPVC1RCAP) = reg32; |
| 223 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 224 | if (CONFIG(NORTHBRIDGE_INTEL_SUBTYPE_I945GC)) { |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 225 | if ((MCHBAR32(CLKCFG) & 7) == 0) { /* 1067MHz */ |
Elyes HAOUAS | f7acdf8 | 2016-10-31 18:55:04 +0100 | [diff] [blame] | 226 | EPBAR32(EPVC1IST + 0) = 0x01380138; |
| 227 | EPBAR32(EPVC1IST + 4) = 0x01380138; |
| 228 | } |
| 229 | } |
| 230 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 231 | if ((MCHBAR32(CLKCFG) & 7) == 1) { /* 533MHz */ |
| 232 | EPBAR32(EPVC1IST + 0) = 0x009c009c; |
| 233 | EPBAR32(EPVC1IST + 4) = 0x009c009c; |
| 234 | } |
| 235 | |
Elyes HAOUAS | f7acdf8 | 2016-10-31 18:55:04 +0100 | [diff] [blame] | 236 | if ((MCHBAR32(CLKCFG) & 7) == 2) { /* 800MHz */ |
| 237 | EPBAR32(EPVC1IST + 0) = 0x00f000f0; |
| 238 | EPBAR32(EPVC1IST + 4) = 0x00f000f0; |
| 239 | } |
| 240 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 241 | if ((MCHBAR32(CLKCFG) & 7) == 3) { /* 667MHz */ |
| 242 | EPBAR32(EPVC1IST + 0) = 0x00c000c0; |
| 243 | EPBAR32(EPVC1IST + 4) = 0x00c000c0; |
| 244 | } |
| 245 | |
| 246 | /* Is internal graphics enabled? */ |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 247 | if (pci_read_config8(HOST_BRIDGE, DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 248 | MCHBAR32(MMARB1) |= (1 << 17); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 249 | |
| 250 | /* Assign Virtual Channel ID 1 to VC1 */ |
| 251 | reg32 = EPBAR32(EPVC1RCTL); |
| 252 | reg32 &= ~(7 << 24); |
| 253 | reg32 |= (1 << 24); |
| 254 | EPBAR32(EPVC1RCTL) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 255 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 256 | reg32 = EPBAR32(EPVC1RCTL); |
| 257 | reg32 &= 0xffffff01; |
| 258 | reg32 |= (1 << 7); |
| 259 | EPBAR32(EPVC1RCTL) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 260 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 261 | EPBAR32(PORTARB + 0x00) = 0x01000001; |
| 262 | EPBAR32(PORTARB + 0x04) = 0x00040000; |
| 263 | EPBAR32(PORTARB + 0x08) = 0x00001000; |
| 264 | EPBAR32(PORTARB + 0x0c) = 0x00000040; |
| 265 | EPBAR32(PORTARB + 0x10) = 0x01000001; |
| 266 | EPBAR32(PORTARB + 0x14) = 0x00040000; |
| 267 | EPBAR32(PORTARB + 0x18) = 0x00001000; |
| 268 | EPBAR32(PORTARB + 0x1c) = 0x00000040; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 269 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 270 | EPBAR32(EPVC1RCTL) |= (1 << 16); |
| 271 | EPBAR32(EPVC1RCTL) |= (1 << 16); |
| 272 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 273 | printk(BIOS_DEBUG, "Loading port arbitration table ..."); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 274 | /* Loop until bit 0 becomes 0 */ |
| 275 | timeout = 0x7fffff; |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 276 | while ((EPBAR16(EPVC1RSTS) & 1) && --timeout) |
| 277 | ; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 278 | if (!timeout) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 279 | printk(BIOS_DEBUG, "timeout!\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 280 | else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 281 | printk(BIOS_DEBUG, "ok\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 282 | |
| 283 | /* Now enable VC1 */ |
| 284 | EPBAR32(EPVC1RCTL) |= (1 << 31); |
| 285 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 286 | printk(BIOS_DEBUG, "Wait for VC1 negotiation ..."); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 287 | /* Wait for VC1 negotiation pending */ |
| 288 | timeout = 0x7fff; |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 289 | while ((EPBAR16(EPVC1RSTS) & (1 << 1)) && --timeout) |
| 290 | ; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 291 | if (!timeout) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 292 | printk(BIOS_DEBUG, "timeout!\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 293 | else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 294 | printk(BIOS_DEBUG, "ok\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 295 | |
| 296 | } |
| 297 | |
| 298 | static void ich7_setup_dmi_rcrb(void) |
| 299 | { |
| 300 | u16 reg16; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 301 | u32 reg32; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 302 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 303 | reg16 = RCBA16(LCTL); |
| 304 | reg16 &= ~(3 << 0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 305 | reg16 |= 3; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 306 | RCBA16(LCTL) = reg16; |
| 307 | |
| 308 | RCBA32(V0CTL) = 0x80000001; |
| 309 | RCBA32(V1CAP) = 0x03128010; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 310 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 311 | pci_write_config16(PCI_DEV(0, 0x1c, 0), 0x42, 0x0141); |
| 312 | pci_write_config16(PCI_DEV(0, 0x1c, 4), 0x42, 0x0141); |
| 313 | pci_write_config16(PCI_DEV(0, 0x1c, 5), 0x42, 0x0141); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 314 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 315 | pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0); |
| 316 | pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0); |
| 317 | |
| 318 | reg32 = RCBA32(V1CTL); |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 319 | reg32 &= ~((0x7f << 1) | (7 << 17) | (7 << 24)); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 320 | reg32 |= (0x40 << 1) | (4 << 17) | (1 << 24) | (1 << 31); |
| 321 | RCBA32(V1CTL) = reg32; |
| 322 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 323 | RCBA32(LCAP) |= (3 << 10); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static void i945_setup_dmi_rcrb(void) |
| 327 | { |
| 328 | u32 reg32; |
| 329 | u32 timeout; |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 330 | int activate_aspm = 1; /* hardcode ASPM for now */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 331 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 332 | printk(BIOS_DEBUG, "Setting up DMI RCRB\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 333 | |
| 334 | /* Virtual Channel 0 Configuration */ |
| 335 | reg32 = DMIBAR32(DMIVC0RCTL0); |
| 336 | reg32 &= 0xffffff01; |
| 337 | DMIBAR32(DMIVC0RCTL0) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 338 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 339 | reg32 = DMIBAR32(DMIPVCCAP1); |
| 340 | reg32 &= ~(7 << 0); |
| 341 | reg32 |= 1; |
| 342 | DMIBAR32(DMIPVCCAP1) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 343 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 344 | reg32 = DMIBAR32(DMIVC1RCTL); |
| 345 | reg32 &= ~(7 << 24); |
| 346 | reg32 |= (1 << 24); /* NOTE: This ID must match ICH7 side */ |
| 347 | DMIBAR32(DMIVC1RCTL) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 348 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 349 | reg32 = DMIBAR32(DMIVC1RCTL); |
| 350 | reg32 &= 0xffffff01; |
| 351 | reg32 |= (1 << 7); |
| 352 | DMIBAR32(DMIVC1RCTL) = reg32; |
| 353 | |
| 354 | /* Now enable VC1 */ |
| 355 | DMIBAR32(DMIVC1RCTL) |= (1 << 31); |
| 356 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 357 | printk(BIOS_DEBUG, "Wait for VC1 negotiation ..."); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 358 | /* Wait for VC1 negotiation pending */ |
| 359 | timeout = 0x7ffff; |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 360 | while ((DMIBAR16(DMIVC1RSTS) & (1 << 1)) && --timeout) |
| 361 | ; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 362 | if (!timeout) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 363 | printk(BIOS_DEBUG, "timeout!\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 364 | else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 365 | printk(BIOS_DEBUG, "done..\n"); |
Angel Pons | 81c9c27 | 2020-07-07 23:19:38 +0200 | [diff] [blame] | 366 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 367 | /* Enable Active State Power Management (ASPM) L0 state */ |
| 368 | |
| 369 | reg32 = DMIBAR32(DMILCAP); |
| 370 | reg32 &= ~(7 << 12); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 371 | reg32 |= (2 << 12); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 372 | |
| 373 | reg32 &= ~(7 << 15); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 374 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 375 | reg32 |= (2 << 15); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 376 | DMIBAR32(DMILCAP) = reg32; |
| 377 | |
| 378 | reg32 = DMIBAR32(DMICC); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 379 | reg32 &= 0x00ffffff; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 380 | reg32 &= ~(3 << 0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 381 | reg32 |= (1 << 0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 382 | reg32 &= ~(3 << 20); |
| 383 | reg32 |= (1 << 20); |
| 384 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 385 | DMIBAR32(DMICC) = reg32; |
| 386 | |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 387 | if (activate_aspm) |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 388 | DMIBAR32(DMILCTL) |= (3 << 0); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 389 | |
| 390 | /* Last but not least, some additional steps */ |
| 391 | reg32 = MCHBAR32(FSBSNPCTL); |
| 392 | reg32 &= ~(0xff << 2); |
| 393 | reg32 |= (0xaa << 2); |
| 394 | MCHBAR32(FSBSNPCTL) = reg32; |
| 395 | |
| 396 | DMIBAR32(0x2c) = 0x86000040; |
| 397 | |
| 398 | reg32 = DMIBAR32(0x204); |
| 399 | reg32 &= ~0x3ff; |
| 400 | #if 1 |
Elyes HAOUAS | 3dff32c | 2020-03-30 17:16:51 +0200 | [diff] [blame] | 401 | reg32 |= 0x13f; /* for x4 DMI only */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 402 | #else |
Elyes HAOUAS | 3dff32c | 2020-03-30 17:16:51 +0200 | [diff] [blame] | 403 | reg32 |= 0x1e4; /* for x2 DMI only */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 404 | #endif |
| 405 | DMIBAR32(0x204) = reg32; |
| 406 | |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 407 | if (pci_read_config8(HOST_BRIDGE, DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 408 | printk(BIOS_DEBUG, "Internal graphics: enabled\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 409 | DMIBAR32(0x200) |= (1 << 21); |
| 410 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 411 | printk(BIOS_DEBUG, "Internal graphics: disabled\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 412 | DMIBAR32(0x200) &= ~(1 << 21); |
| 413 | } |
| 414 | |
| 415 | reg32 = DMIBAR32(0x204); |
| 416 | reg32 &= ~((1 << 11) | (1 << 10)); |
| 417 | DMIBAR32(0x204) = reg32; |
| 418 | |
| 419 | reg32 = DMIBAR32(0x204); |
| 420 | reg32 &= ~(0xff << 12); |
| 421 | reg32 |= (0x0d << 12); |
| 422 | DMIBAR32(0x204) = reg32; |
| 423 | |
| 424 | DMIBAR32(DMICTL1) |= (3 << 24); |
| 425 | |
| 426 | reg32 = DMIBAR32(0x200); |
| 427 | reg32 &= ~(0x3 << 26); |
| 428 | reg32 |= (0x02 << 26); |
| 429 | DMIBAR32(0x200) = reg32; |
| 430 | |
| 431 | DMIBAR32(DMIDRCCFG) &= ~(1 << 31); |
| 432 | DMIBAR32(DMICTL2) |= (1 << 31); |
| 433 | |
| 434 | if (i945_silicon_revision() >= 3) { |
| 435 | reg32 = DMIBAR32(0xec0); |
| 436 | reg32 &= 0x0fffffff; |
| 437 | reg32 |= (2 << 28); |
| 438 | DMIBAR32(0xec0) = reg32; |
| 439 | |
| 440 | reg32 = DMIBAR32(0xed4); |
| 441 | reg32 &= 0x0fffffff; |
| 442 | reg32 |= (2 << 28); |
| 443 | DMIBAR32(0xed4) = reg32; |
| 444 | |
| 445 | reg32 = DMIBAR32(0xee8); |
| 446 | reg32 &= 0x0fffffff; |
| 447 | reg32 |= (2 << 28); |
| 448 | DMIBAR32(0xee8) = reg32; |
| 449 | |
| 450 | reg32 = DMIBAR32(0xefc); |
| 451 | reg32 &= 0x0fffffff; |
| 452 | reg32 |= (2 << 28); |
| 453 | DMIBAR32(0xefc) = reg32; |
| 454 | } |
| 455 | |
| 456 | /* wait for bit toggle to 0 */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 457 | printk(BIOS_DEBUG, "Waiting for DMI hardware..."); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 458 | timeout = 0x7fffff; |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 459 | while ((DMIBAR8(0x32) & (1 << 1)) && --timeout) |
| 460 | ; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 461 | if (!timeout) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 462 | printk(BIOS_DEBUG, "timeout!\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 463 | else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 464 | printk(BIOS_DEBUG, "ok\n"); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 465 | |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 466 | /* Clear Error Status Bits! */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 467 | DMIBAR32(0x1c4) = 0xffffffff; |
| 468 | DMIBAR32(0x1d0) = 0xffffffff; |
| 469 | DMIBAR32(0x228) = 0xffffffff; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 470 | |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 471 | /* Program Read-Only Write-Once Registers */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 472 | DMIBAR32(0x308) = DMIBAR32(0x308); |
| 473 | DMIBAR32(0x314) = DMIBAR32(0x314); |
| 474 | DMIBAR32(0x324) = DMIBAR32(0x324); |
| 475 | DMIBAR32(0x328) = DMIBAR32(0x328); |
Elyes HAOUAS | d3fa7fa5 | 2019-01-24 11:47:27 +0100 | [diff] [blame] | 476 | DMIBAR32(0x334) = DMIBAR32(0x334); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 477 | DMIBAR32(0x338) = DMIBAR32(0x338); |
| 478 | |
Patrick Georgi | a341a77 | 2014-09-29 19:51:21 +0200 | [diff] [blame] | 479 | if (i945_silicon_revision() == 1 && (MCHBAR8(DFT_STRAP1) & (1 << 5))) { |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 480 | if ((MCHBAR32(0x214) & 0xf) != 0x3) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 481 | printk(BIOS_INFO, "DMI link requires A1 stepping workaround. Rebooting.\n"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 482 | reg32 = DMIBAR32(0x224); |
| 483 | reg32 &= ~(7 << 0); |
| 484 | reg32 |= (3 << 0); |
| 485 | DMIBAR32(0x224) = reg32; |
Elyes HAOUAS | 5db9871 | 2019-04-21 18:50:34 +0200 | [diff] [blame] | 486 | system_reset(); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | static void i945_setup_pci_express_x16(void) |
| 492 | { |
| 493 | u32 timeout; |
| 494 | u32 reg32; |
| 495 | u16 reg16; |
Elyes HAOUAS | 961658f | 2020-04-06 09:42:21 +0200 | [diff] [blame] | 496 | const pci_devfn_t p2peg = PCI_DEV(0, 0x01, 0); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 497 | |
Kyösti Mälkki | 2647b6f | 2019-09-29 07:03:55 +0300 | [diff] [blame] | 498 | u8 tmp_secondary = 0x0a; |
Elyes HAOUAS | 961658f | 2020-04-06 09:42:21 +0200 | [diff] [blame] | 499 | const pci_devfn_t peg_plugin = PCI_DEV(tmp_secondary, 0, 0); |
Kyösti Mälkki | 2647b6f | 2019-09-29 07:03:55 +0300 | [diff] [blame] | 500 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 501 | printk(BIOS_DEBUG, "Enabling PCI Express x16 Link\n"); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 502 | |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 503 | pci_or_config16(HOST_BRIDGE, DEVEN, DEVEN_D1F0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 504 | |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 505 | pci_and_config32(p2peg, PEGCC, ~(1 << 8)); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 506 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 507 | /* We have no success with querying the usual PCIe registers |
| 508 | * for link setup success on the i945. Hence we assign a temporary |
| 509 | * PCI bus 0x0a and check whether we find a device on 0:a.0 |
| 510 | */ |
| 511 | |
Kyösti Mälkki | ad787e1 | 2019-09-30 04:14:19 +0300 | [diff] [blame] | 512 | /* Force PCIRST# */ |
| 513 | pci_s_assert_secondary_reset(p2peg); |
| 514 | pci_s_deassert_secondary_reset(p2peg); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 515 | |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 516 | reg16 = pci_read_config16(p2peg, SLOTSTS); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 517 | printk(BIOS_DEBUG, "SLOTSTS: %04x\n", reg16); |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 518 | if (!(reg16 & 0x48)) |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 519 | goto disable_pciexpress_x16_link; |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 520 | reg16 |= (1 << 4) | (1 << 0); |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 521 | pci_write_config16(p2peg, SLOTSTS, reg16); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 522 | |
Kyösti Mälkki | ad787e1 | 2019-09-30 04:14:19 +0300 | [diff] [blame] | 523 | pci_s_bridge_set_secondary(p2peg, tmp_secondary); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 524 | |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 525 | pci_and_config32(p2peg, 0x224, ~(1 << 8)); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 526 | |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 527 | MCHBAR16(UPMC1) &= ~((1 << 5) | (1 << 0)); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 528 | |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 529 | /* Initialize PEG_CAP */ |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 530 | pci_or_config16(p2peg, PEG_CAP, 1 << 8); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 531 | |
| 532 | /* Setup SLOTCAP */ |
Elyes HAOUAS | 3dff32c | 2020-03-30 17:16:51 +0200 | [diff] [blame] | 533 | /* TODO: These values are mainboard dependent and should be set from devicetree.cb. |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 534 | */ |
| 535 | /* NOTE: SLOTCAP becomes RO after the first write! */ |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 536 | reg32 = pci_read_config32(p2peg, SLOTCAP); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 537 | reg32 &= 0x0007ffff; |
| 538 | |
| 539 | reg32 &= 0xfffe007f; |
| 540 | |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 541 | pci_write_config32(p2peg, SLOTCAP, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 542 | |
| 543 | /* Wait for training to succeed */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 544 | printk(BIOS_DEBUG, "PCIe link training ..."); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 545 | timeout = 0x7ffff; |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 546 | while ((((pci_read_config32(p2peg, PEGSTS) >> 16) & 3) != 3) && --timeout) |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 547 | ; |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 548 | |
Kyösti Mälkki | 2647b6f | 2019-09-29 07:03:55 +0300 | [diff] [blame] | 549 | reg32 = pci_read_config32(peg_plugin, PCI_VENDOR_ID); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 550 | if (reg32 != 0x00000000 && reg32 != 0xffffffff) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 551 | printk(BIOS_DEBUG, " Detected PCIe device %04x:%04x\n", |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 552 | reg32 & 0xffff, reg32 >> 16); |
| 553 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 554 | printk(BIOS_DEBUG, " timeout!\n"); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 555 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 556 | printk(BIOS_DEBUG, "Restrain PCIe port to x1\n"); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 557 | |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 558 | pci_update_config32(p2peg, PEGSTS, ~(0xf << 1), 1); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 559 | |
Kyösti Mälkki | ad787e1 | 2019-09-30 04:14:19 +0300 | [diff] [blame] | 560 | /* Force PCIRST# */ |
| 561 | pci_s_assert_secondary_reset(p2peg); |
| 562 | pci_s_deassert_secondary_reset(p2peg); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 563 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 564 | printk(BIOS_DEBUG, "PCIe link training ..."); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 565 | timeout = 0x7ffff; |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 566 | while ((((pci_read_config32(p2peg, PEGSTS) >> 16) & 3) != 3) && --timeout) |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 567 | ; |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 568 | |
Kyösti Mälkki | 2647b6f | 2019-09-29 07:03:55 +0300 | [diff] [blame] | 569 | reg32 = pci_read_config32(peg_plugin, PCI_VENDOR_ID); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 570 | if (reg32 != 0x00000000 && reg32 != 0xffffffff) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 571 | printk(BIOS_DEBUG, " Detected PCIe x1 device %04x:%04x\n", |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 572 | reg32 & 0xffff, reg32 >> 16); |
| 573 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 574 | printk(BIOS_DEBUG, " timeout!\n"); |
| 575 | printk(BIOS_DEBUG, "Disabling PCIe x16 port completely.\n"); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 576 | goto disable_pciexpress_x16_link; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 577 | } |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 578 | } |
| 579 | |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 580 | reg16 = pci_read_config16(p2peg, 0xb2); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 581 | reg16 >>= 4; |
| 582 | reg16 &= 0x3f; |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 583 | /* reg16 == 1 -> x1; reg16 == 16 -> x16 */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 584 | printk(BIOS_DEBUG, "PCIe x%d link training succeeded.\n", reg16); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 585 | |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 586 | reg32 = pci_read_config32(p2peg, PEGTC); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 587 | reg32 &= 0xfffffc00; /* clear [9:0] */ |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 588 | if (reg16 == 1) |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 589 | reg32 |= 0x32b; |
| 590 | // TODO |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 591 | /* pci_write_config32(p2peg, PEGTC, reg32); */ |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 592 | else if (reg16 == 16) |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 593 | reg32 |= 0x0f4; |
| 594 | // TODO |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 595 | /* pci_write_config32(p2peg, PEGTC, reg32); */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 596 | |
Kyösti Mälkki | 2647b6f | 2019-09-29 07:03:55 +0300 | [diff] [blame] | 597 | reg32 = (pci_read_config32(peg_plugin, 0x8) >> 8); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 598 | printk(BIOS_DEBUG, "PCIe device class: %06x\n", reg32); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 599 | if (reg32 == 0x030000) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 600 | printk(BIOS_DEBUG, "PCIe device is VGA. Disabling IGD.\n"); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 601 | reg16 = (1 << 1); |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 602 | pci_write_config16(HOST_BRIDGE, GGC, reg16); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 603 | |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 604 | pci_and_config32(HOST_BRIDGE, DEVEN, ~(DEVEN_D2F0 | DEVEN_D2F1)); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 607 | /* Enable GPEs: PMEGPE, HPGPE, GENGPE */ |
| 608 | pci_or_config32(p2peg, PEG_LC, (1 << 2) | (1 << 1) | (1 << 0)); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 609 | |
| 610 | /* Virtual Channel Configuration: Only VC0 on PCIe x16 */ |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 611 | pci_and_config32(p2peg, VC0RCTL, ~0x000000fe); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 612 | |
| 613 | /* Extended VC count */ |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 614 | pci_and_config32(p2peg, PVCCAP1, ~(7 << 0)); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 615 | |
| 616 | /* Active State Power Management ASPM */ |
| 617 | |
| 618 | /* TODO */ |
| 619 | |
| 620 | /* Clear error bits */ |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 621 | pci_write_config16(p2peg, PCISTS1, 0xffff); |
| 622 | pci_write_config16(p2peg, SSTS1, 0xffff); |
| 623 | pci_write_config16(p2peg, DSTS, 0xffff); |
| 624 | pci_write_config32(p2peg, UESTS, 0xffffffff); |
| 625 | pci_write_config32(p2peg, CESTS, 0xffffffff); |
| 626 | pci_write_config32(p2peg, 0x1f0, 0xffffffff); |
| 627 | pci_write_config32(p2peg, 0x228, 0xffffffff); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 628 | |
| 629 | /* Program R/WO registers */ |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 630 | pci_update_config32(p2peg, 0x308, ~0, 0); |
| 631 | pci_update_config32(p2peg, 0x314, ~0, 0); |
| 632 | pci_update_config32(p2peg, 0x324, ~0, 0); |
| 633 | pci_update_config32(p2peg, 0x328, ~0, 0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 634 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 635 | /* Additional PCIe graphics setup */ |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 636 | pci_or_config32(p2peg, 0xf0, 3 << 26); |
| 637 | pci_or_config32(p2peg, 0xf0, 3 << 24); |
| 638 | pci_or_config32(p2peg, 0xf0, 1 << 5); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 639 | |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 640 | pci_update_config32(p2peg, 0x200, ~(3 << 26), 2 << 26); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 641 | |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 642 | reg32 = pci_read_config32(p2peg, 0xe80); |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 643 | if (i945_silicon_revision() >= 2) |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 644 | reg32 |= (1 << 12); |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 645 | else |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 646 | reg32 &= ~(1 << 12); |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 647 | pci_write_config32(p2peg, 0xe80, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 648 | |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 649 | pci_and_config32(p2peg, 0xeb4, ~(1 << 31)); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 650 | |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 651 | pci_or_config32(p2peg, 0xfc, 1 << 31); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 652 | |
| 653 | if (i945_silicon_revision() >= 3) { |
| 654 | static const u32 reglist[] = { |
Elyes HAOUAS | 3dff32c | 2020-03-30 17:16:51 +0200 | [diff] [blame] | 655 | 0xec0, 0xed4, 0xee8, 0xefc, 0xf10, 0xf24, 0xf38, 0xf4c, |
| 656 | 0xf60, 0xf74, 0xf88, 0xf9c, 0xfb0, 0xfc4, 0xfd8, 0xfec |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 657 | }; |
| 658 | |
| 659 | int i; |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 660 | for (i = 0; i < ARRAY_SIZE(reglist); i++) |
| 661 | pci_update_config32(p2peg, reglist[i], ~(0xf << 28), 2 << 28); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 662 | } |
| 663 | |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 664 | if (i945_silicon_revision() <= 2) { |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 665 | /* Set voltage specific parameters */ |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 666 | reg32 = pci_read_config32(p2peg, 0xe80); |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 667 | reg32 &= (0xf << 4); /* Default case 1.05V */ |
Patrick Georgi | 3cb86de | 2014-09-29 20:42:33 +0200 | [diff] [blame] | 668 | if ((MCHBAR32(DFT_STRAP1) & (1 << 20)) == 0) { /* 1.50V */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 669 | reg32 |= (7 << 4); |
| 670 | } |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 671 | pci_write_config32(p2peg, 0xe80, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | return; |
| 675 | |
| 676 | disable_pciexpress_x16_link: |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 677 | /* For now we just disable the x16 link */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 678 | printk(BIOS_DEBUG, "Disabling PCI Express x16 Link\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 679 | |
| 680 | MCHBAR16(UPMC1) |= (1 << 5) | (1 << 0); |
| 681 | |
Kyösti Mälkki | ad787e1 | 2019-09-30 04:14:19 +0300 | [diff] [blame] | 682 | /* Toggle PCIRST# */ |
| 683 | pci_s_assert_secondary_reset(p2peg); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 684 | |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 685 | pci_or_config32(p2peg, 0x224, 1 << 8); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 686 | |
Kyösti Mälkki | ad787e1 | 2019-09-30 04:14:19 +0300 | [diff] [blame] | 687 | pci_s_deassert_secondary_reset(p2peg); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 688 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 689 | printk(BIOS_DEBUG, "Wait for link to enter detect state... "); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 690 | timeout = 0x7fffff; |
Kyösti Mälkki | 444d2af | 2019-09-29 07:03:31 +0300 | [diff] [blame] | 691 | for (reg32 = pci_read_config32(p2peg, PEGSTS); |
Arthur Heymans | 70a8e34 | 2017-03-09 11:30:23 +0100 | [diff] [blame] | 692 | (reg32 & 0x000f0000) && --timeout;) |
| 693 | ; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 694 | if (!timeout) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 695 | printk(BIOS_DEBUG, "timeout!\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 696 | else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 697 | printk(BIOS_DEBUG, "ok\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 698 | |
| 699 | /* Finally: Disable the PCI config header */ |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 700 | pci_and_config16(HOST_BRIDGE, DEVEN, ~DEVEN_D1F0); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | static void i945_setup_root_complex_topology(void) |
| 704 | { |
| 705 | u32 reg32; |
Elyes HAOUAS | 961658f | 2020-04-06 09:42:21 +0200 | [diff] [blame] | 706 | const pci_devfn_t p2peg = PCI_DEV(0, 0x01, 0); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 707 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 708 | printk(BIOS_DEBUG, "Setting up Root Complex Topology\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 709 | /* Egress Port Root Topology */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 710 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 711 | reg32 = EPBAR32(EPESD); |
| 712 | reg32 &= 0xff00ffff; |
| 713 | reg32 |= (1 << 16); |
| 714 | EPBAR32(EPESD) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 715 | |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 716 | EPBAR32(EPLE1D) |= (1 << 16) | (1 << 0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 717 | |
Angel Pons | 4299cb4 | 2021-01-20 12:32:22 +0100 | [diff] [blame] | 718 | EPBAR32(EPLE1A) = CONFIG_FIXED_DMIBAR_MMIO_BASE; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 719 | |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 720 | EPBAR32(EPLE2D) |= (1 << 16) | (1 << 0); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 721 | |
| 722 | /* DMI Port Root Topology */ |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 723 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 724 | reg32 = DMIBAR32(DMILE1D); |
| 725 | reg32 &= 0x00ffffff; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 726 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 727 | reg32 &= 0xff00ffff; |
| 728 | reg32 |= (2 << 16); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 729 | |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 730 | reg32 |= (1 << 0); |
| 731 | DMIBAR32(DMILE1D) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 732 | |
Angel Pons | 6e732d3 | 2021-01-28 13:56:18 +0100 | [diff] [blame] | 733 | DMIBAR32(DMILE1A) = CONFIG_FIXED_RCBA_MMIO_BASE; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 734 | |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 735 | DMIBAR32(DMILE2D) |= (1 << 16) | (1 << 0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 736 | |
Angel Pons | 4299cb4 | 2021-01-20 12:32:22 +0100 | [diff] [blame] | 737 | DMIBAR32(DMILE2A) = CONFIG_FIXED_EPBAR_MMIO_BASE; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 738 | |
| 739 | /* PCI Express x16 Port Root Topology */ |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 740 | if (pci_read_config8(HOST_BRIDGE, DEVEN) & DEVEN_D1F0) { |
Angel Pons | 4299cb4 | 2021-01-20 12:32:22 +0100 | [diff] [blame] | 741 | pci_write_config32(p2peg, LE1A, CONFIG_FIXED_EPBAR_MMIO_BASE); |
Angel Pons | e3c68d2 | 2020-06-08 12:09:03 +0200 | [diff] [blame] | 742 | pci_or_config32(p2peg, LE1D, 1 << 0); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | |
| 746 | static void ich7_setup_root_complex_topology(void) |
| 747 | { |
Elyes HAOUAS | b217baa | 2019-01-18 15:32:39 +0100 | [diff] [blame] | 748 | /* Write the R/WO registers */ |
| 749 | |
| 750 | RCBA32(ESD) |= (2 << 16); |
| 751 | |
| 752 | RCBA32(ULD) |= (1 << 24) | (1 << 16); |
| 753 | |
Angel Pons | 4299cb4 | 2021-01-20 12:32:22 +0100 | [diff] [blame] | 754 | RCBA32(ULBA) = CONFIG_FIXED_DMIBAR_MMIO_BASE; |
Elyes HAOUAS | b217baa | 2019-01-18 15:32:39 +0100 | [diff] [blame] | 755 | /* Write ESD.CID to TCID */ |
| 756 | RCBA32(RP1D) |= (2 << 16); |
| 757 | RCBA32(RP2D) |= (2 << 16); |
| 758 | RCBA32(RP3D) |= (2 << 16); |
| 759 | RCBA32(RP4D) |= (2 << 16); |
| 760 | RCBA32(HDD) |= (2 << 16); |
| 761 | RCBA32(RP5D) |= (2 << 16); |
| 762 | RCBA32(RP6D) |= (2 << 16); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | static void ich7_setup_pci_express(void) |
| 766 | { |
Elyes HAOUAS | 1374607 | 2019-12-08 11:34:24 +0100 | [diff] [blame] | 767 | /* Enable PCIe Root Port Clock Gate */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 768 | RCBA32(CG) |= (1 << 0); |
| 769 | |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 770 | /* Initialize slot power limit for root ports */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 771 | pci_write_config32(PCI_DEV(0, 0x1c, 0), 0x54, 0x00000060); |
| 772 | |
| 773 | pci_write_config32(PCI_DEV(0, 0x1c, 0), 0xd8, 0x00110000); |
| 774 | } |
| 775 | |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 776 | void i945_early_initialization(void) |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 777 | { |
| 778 | /* Print some chipset specific information */ |
Angel Pons | 3580d81 | 2020-06-11 14:13:33 +0200 | [diff] [blame] | 779 | switch (pci_read_config32(HOST_BRIDGE, 0)) { |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 780 | case 0x27708086: /* 82945G/GZ/GC/P/PL */ |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 781 | i945_detect_chipset(); |
| 782 | break; |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 783 | case 0x27a08086: /* 945GME/GSE */ |
| 784 | case 0x27ac8086: /* 945GM/PM/GMS/GU/GT, 943/940GML */ |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 785 | i945m_detect_chipset(); |
| 786 | break; |
| 787 | } |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 788 | |
| 789 | /* Setup all BARs required for early PCIe and raminit */ |
| 790 | i945_setup_bars(); |
| 791 | |
| 792 | /* Change port80 to LPC */ |
| 793 | RCBA32(GCS) &= (~0x04); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 794 | |
| 795 | /* Just do it that way */ |
| 796 | RCBA32(0x2010) |= (1 << 10); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 797 | } |
| 798 | |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 799 | static void i945_prepare_resume(int s3resume) |
| 800 | { |
| 801 | int cbmem_was_initted; |
| 802 | |
| 803 | cbmem_was_initted = !cbmem_recovery(s3resume); |
| 804 | |
Kyösti Mälkki | 8183025 | 2016-06-25 11:40:00 +0300 | [diff] [blame] | 805 | romstage_handoff_init(cbmem_was_initted && s3resume); |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | void i945_late_initialization(int s3resume) |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 809 | { |
| 810 | i945_setup_egress_port(); |
| 811 | |
| 812 | ich7_setup_root_complex_topology(); |
| 813 | |
| 814 | ich7_setup_pci_express(); |
| 815 | |
| 816 | ich7_setup_dmi_rcrb(); |
| 817 | |
| 818 | i945_setup_dmi_rcrb(); |
| 819 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 820 | if (CONFIG(NORTHBRIDGE_INTEL_SUBTYPE_I945GM)) |
Arthur Heymans | 2f6b52e | 2017-03-02 23:51:09 +0100 | [diff] [blame] | 821 | i945_setup_pci_express_x16(); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 822 | |
| 823 | i945_setup_root_complex_topology(); |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 824 | |
Kyösti Mälkki | 346d201 | 2019-03-23 10:07:16 +0200 | [diff] [blame] | 825 | if (CONFIG(DEBUG_RAM_SETUP)) |
| 826 | sdram_dump_mchbar_registers(); |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 827 | |
| 828 | MCHBAR16(SSKPD) = 0xCAFE; |
| 829 | |
| 830 | i945_prepare_resume(s3resume); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 831 | } |