Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 15 | #include <console/console.h> |
Patrick Rudolph | 2cdb65d | 2019-03-24 18:08:43 +0100 | [diff] [blame] | 16 | #include <device/mmio.h> |
| 17 | #include <device/device.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 18 | #include <device/pci_ops.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 19 | #include <device/pci_def.h> |
Kyösti Mälkki | cbf9571 | 2020-01-05 08:05:45 +0200 | [diff] [blame] | 20 | #include <option.h> |
Kyösti Mälkki | e39a8a9 | 2016-06-25 11:40:00 +0300 | [diff] [blame] | 21 | #include <romstage_handoff.h> |
Elyes HAOUAS | 51401c3 | 2019-05-15 21:09:30 +0200 | [diff] [blame] | 22 | #include <types.h> |
| 23 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 24 | #include "sandybridge.h" |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 25 | |
Patrick Rudolph | 2cdb65d | 2019-03-24 18:08:43 +0100 | [diff] [blame] | 26 | static void systemagent_vtd_init(void) |
| 27 | { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 28 | const u32 capid0_a = pci_read_config32(HOST_BRIDGE, CAPID0_A); |
Patrick Rudolph | 2cdb65d | 2019-03-24 18:08:43 +0100 | [diff] [blame] | 29 | if (capid0_a & (1 << 23)) |
| 30 | return; |
| 31 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 32 | /* Setup BARs */ |
| 33 | MCHBAR32(GFXVTBAR + 4) = GFXVT_BASE >> 32; |
| 34 | MCHBAR32(GFXVTBAR) = GFXVT_BASE | 1; |
| 35 | MCHBAR32(VTVC0BAR + 4) = VTVC0_BASE >> 32; |
| 36 | MCHBAR32(VTVC0BAR) = VTVC0_BASE | 1; |
Patrick Rudolph | 2cdb65d | 2019-03-24 18:08:43 +0100 | [diff] [blame] | 37 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 38 | /* Lock policies */ |
| 39 | write32((void *)(GFXVT_BASE + 0xff0), 0x80000000); |
Patrick Rudolph | 2cdb65d | 2019-03-24 18:08:43 +0100 | [diff] [blame] | 40 | |
| 41 | const struct device *const azalia = pcidev_on_root(0x1b, 0); |
| 42 | if (azalia && azalia->enabled) { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 43 | write32((void *)(VTVC0_BASE + 0xff0), 0x20000000); |
| 44 | write32((void *)(VTVC0_BASE + 0xff0), 0xa0000000); |
Patrick Rudolph | 2cdb65d | 2019-03-24 18:08:43 +0100 | [diff] [blame] | 45 | } else { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 46 | write32((void *)(VTVC0_BASE + 0xff0), 0x80000000); |
Patrick Rudolph | 2cdb65d | 2019-03-24 18:08:43 +0100 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |
| 50 | static void enable_pam_region(void) |
| 51 | { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 52 | pci_write_config8(HOST_BRIDGE, PAM0, 0x30); |
| 53 | pci_write_config8(HOST_BRIDGE, PAM1, 0x33); |
| 54 | pci_write_config8(HOST_BRIDGE, PAM2, 0x33); |
| 55 | pci_write_config8(HOST_BRIDGE, PAM3, 0x33); |
| 56 | pci_write_config8(HOST_BRIDGE, PAM4, 0x33); |
| 57 | pci_write_config8(HOST_BRIDGE, PAM5, 0x33); |
| 58 | pci_write_config8(HOST_BRIDGE, PAM6, 0x33); |
Patrick Rudolph | 2cdb65d | 2019-03-24 18:08:43 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 61 | static void sandybridge_setup_bars(void) |
| 62 | { |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 63 | printk(BIOS_DEBUG, "Setting up static northbridge registers..."); |
| 64 | /* Set up all hardcoded northbridge BARs */ |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 65 | pci_write_config32(HOST_BRIDGE, EPBAR, DEFAULT_EPBAR | 1); |
| 66 | pci_write_config32(HOST_BRIDGE, EPBAR + 4, (0LL + DEFAULT_EPBAR) >> 32); |
| 67 | pci_write_config32(HOST_BRIDGE, MCHBAR, (uintptr_t)DEFAULT_MCHBAR | 1); |
| 68 | pci_write_config32(HOST_BRIDGE, MCHBAR + 4, (0LL + (uintptr_t)DEFAULT_MCHBAR) >> 32); |
| 69 | pci_write_config32(HOST_BRIDGE, DMIBAR, (uintptr_t)DEFAULT_DMIBAR | 1); |
| 70 | pci_write_config32(HOST_BRIDGE, DMIBAR + 4, (0LL + (uintptr_t)DEFAULT_DMIBAR) >> 32); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 71 | |
Patrick Rudolph | 9005071 | 2019-03-25 09:53:23 +0100 | [diff] [blame] | 72 | printk(BIOS_DEBUG, " done\n"); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static void sandybridge_setup_graphics(void) |
| 76 | { |
| 77 | u32 reg32; |
| 78 | u16 reg16; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 79 | u8 reg8, gfxsize; |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 80 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 81 | reg16 = pci_read_config16(PCI_DEV(0, 2, 0), PCI_DEVICE_ID); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 82 | switch (reg16) { |
| 83 | case 0x0102: /* GT1 Desktop */ |
| 84 | case 0x0106: /* GT1 Mobile */ |
| 85 | case 0x010a: /* GT1 Server */ |
| 86 | case 0x0112: /* GT2 Desktop */ |
| 87 | case 0x0116: /* GT2 Mobile */ |
| 88 | case 0x0122: /* GT2 Desktop >=1.3GHz */ |
| 89 | case 0x0126: /* GT2 Mobile >=1.3GHz */ |
Patrick Rudolph | 03a88d3 | 2015-07-05 13:29:41 +0200 | [diff] [blame] | 90 | case 0x0152: /* IvyBridge */ |
Stefan Reinauer | 816e9d1 | 2013-01-14 10:25:43 -0800 | [diff] [blame] | 91 | case 0x0156: /* IvyBridge */ |
Damien Zammit | a10bde9 | 2014-10-23 13:29:32 +1100 | [diff] [blame] | 92 | case 0x0162: /* IvyBridge */ |
Stefan Reinauer | 816e9d1 | 2013-01-14 10:25:43 -0800 | [diff] [blame] | 93 | case 0x0166: /* IvyBridge */ |
Vagiz Trakhanov | 1dd448c | 2017-09-28 14:42:11 +0000 | [diff] [blame] | 94 | case 0x016a: /* IvyBridge */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 95 | break; |
| 96 | default: |
| 97 | printk(BIOS_DEBUG, "Graphics not supported by this CPU/chipset.\n"); |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | printk(BIOS_DEBUG, "Initializing Graphics...\n"); |
| 102 | |
Vladimir Serbinenko | 5fc04d1 | 2014-08-03 01:59:38 +0200 | [diff] [blame] | 103 | if (get_option(&gfxsize, "gfx_uma_size") != CB_SUCCESS) { |
| 104 | /* Setup IGD memory by setting GGC[7:3] = 1 for 32MB */ |
| 105 | gfxsize = 0; |
| 106 | } |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 107 | reg16 = pci_read_config16(HOST_BRIDGE, GGC); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 108 | reg16 &= ~0x00f8; |
Vladimir Serbinenko | 5fc04d1 | 2014-08-03 01:59:38 +0200 | [diff] [blame] | 109 | reg16 |= (gfxsize + 1) << 3; |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 110 | /* Program GTT memory by setting GGC[9:8] = 2MB */ |
| 111 | reg16 &= ~0x0300; |
| 112 | reg16 |= 2 << 8; |
| 113 | /* Enable VGA decode */ |
| 114 | reg16 &= ~0x0002; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 115 | pci_write_config16(HOST_BRIDGE, GGC, reg16); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 116 | |
| 117 | /* Enable 256MB aperture */ |
| 118 | reg8 = pci_read_config8(PCI_DEV(0, 2, 0), MSAC); |
| 119 | reg8 &= ~0x06; |
| 120 | reg8 |= 0x02; |
| 121 | pci_write_config8(PCI_DEV(0, 2, 0), MSAC, reg8); |
| 122 | |
| 123 | /* Erratum workarounds */ |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 124 | reg32 = MCHBAR32(SAPMCTL); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 125 | reg32 |= (1 << 9) | (1 << 10); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 126 | MCHBAR32(SAPMCTL) = reg32; |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 127 | |
| 128 | /* Enable SA Clock Gating */ |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 129 | reg32 = MCHBAR32(SAPMCTL); |
| 130 | MCHBAR32(SAPMCTL) = reg32 | 1; |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 131 | |
| 132 | /* GPU RC6 workaround for sighting 366252 */ |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 133 | reg32 = MCHBAR32(SSKPD_HI); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 134 | reg32 |= (1 << 31); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 135 | MCHBAR32(SSKPD_HI) = reg32; |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 136 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 137 | /* VLW (Virtual Legacy Wire?) */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 138 | reg32 = MCHBAR32(0x6120); |
| 139 | reg32 &= ~(1 << 0); |
| 140 | MCHBAR32(0x6120) = reg32; |
| 141 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 142 | reg32 = MCHBAR32(INTRDIRCTL); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 143 | reg32 |= (1 << 4) | (1 << 5); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 144 | MCHBAR32(INTRDIRCTL) = reg32; |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 145 | } |
| 146 | |
Patrick Rudolph | e4f9d5c | 2015-10-15 11:09:15 +0200 | [diff] [blame] | 147 | static void start_peg_link_training(void) |
| 148 | { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 149 | u32 tmp, deven; |
Patrick Rudolph | e4f9d5c | 2015-10-15 11:09:15 +0200 | [diff] [blame] | 150 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 151 | const u16 base_rev = pci_read_config16(HOST_BRIDGE, PCI_DEVICE_ID) & BASE_REV_MASK; |
| 152 | /* |
| 153 | * PEG on IvyBridge+ needs a special startup sequence. |
| 154 | * As the MRC has its own initialization code skip it. |
| 155 | */ |
| 156 | if ((base_rev != BASE_REV_IVB) || CONFIG(HAVE_MRC)) |
Patrick Rudolph | e4f9d5c | 2015-10-15 11:09:15 +0200 | [diff] [blame] | 157 | return; |
| 158 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 159 | deven = pci_read_config32(HOST_BRIDGE, DEVEN); |
Patrick Rudolph | e4f9d5c | 2015-10-15 11:09:15 +0200 | [diff] [blame] | 160 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 161 | /* |
| 162 | * For each PEG device, set bit 5 to use three retries for OC (Offset Calibration). |
| 163 | * We also clear DEFER_OC (bit 16) in order to start PEG training. |
| 164 | */ |
Patrick Rudolph | e4f9d5c | 2015-10-15 11:09:15 +0200 | [diff] [blame] | 165 | if (deven & DEVEN_PEG10) { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 166 | tmp = pci_read_config32(PCI_DEV(0, 1, 0), AFE_PWRON) & ~(1 << 16); |
| 167 | pci_write_config32(PCI_DEV(0, 1, 0), AFE_PWRON, tmp | (1 << 5)); |
Patrick Rudolph | e4f9d5c | 2015-10-15 11:09:15 +0200 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | if (deven & DEVEN_PEG11) { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 171 | tmp = pci_read_config32(PCI_DEV(0, 1, 1), AFE_PWRON) & ~(1 << 16); |
| 172 | pci_write_config32(PCI_DEV(0, 1, 1), AFE_PWRON, tmp | (1 << 5)); |
Patrick Rudolph | e4f9d5c | 2015-10-15 11:09:15 +0200 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | if (deven & DEVEN_PEG12) { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 176 | tmp = pci_read_config32(PCI_DEV(0, 1, 2), AFE_PWRON) & ~(1 << 16); |
| 177 | pci_write_config32(PCI_DEV(0, 1, 2), AFE_PWRON, tmp | (1 << 5)); |
Patrick Rudolph | e4f9d5c | 2015-10-15 11:09:15 +0200 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | if (deven & DEVEN_PEG60) { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 181 | tmp = pci_read_config32(PCI_DEV(0, 6, 0), AFE_PWRON) & ~(1 << 16); |
| 182 | pci_write_config32(PCI_DEV(0, 6, 0), AFE_PWRON, tmp | (1 << 5)); |
Patrick Rudolph | e4f9d5c | 2015-10-15 11:09:15 +0200 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | |
Patrick Rudolph | 2cdb65d | 2019-03-24 18:08:43 +0100 | [diff] [blame] | 186 | void systemagent_early_init(void) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 187 | { |
| 188 | u32 capid0_a; |
Patrick Rudolph | 2a510a7 | 2015-07-28 07:51:10 +0200 | [diff] [blame] | 189 | u32 deven; |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 190 | u8 reg8; |
| 191 | |
| 192 | /* Device ID Override Enable should be done very early */ |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 193 | capid0_a = pci_read_config32(HOST_BRIDGE, CAPID0_A); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 194 | if (capid0_a & (1 << 10)) { |
Patrick Rudolph | 74203de | 2017-11-20 11:57:01 +0100 | [diff] [blame] | 195 | const size_t is_mobile = get_platform_type() == PLATFORM_MOBILE; |
| 196 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 197 | reg8 = pci_read_config8(HOST_BRIDGE, DIDOR); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 198 | reg8 &= ~7; /* Clear 2:0 */ |
| 199 | |
Patrick Rudolph | 74203de | 2017-11-20 11:57:01 +0100 | [diff] [blame] | 200 | if (is_mobile) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 201 | reg8 |= 1; /* Set bit 0 */ |
| 202 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 203 | pci_write_config8(HOST_BRIDGE, DIDOR, reg8); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /* Setup all BARs required for early PCIe and raminit */ |
| 207 | sandybridge_setup_bars(); |
| 208 | |
Patrick Rudolph | 2cdb65d | 2019-03-24 18:08:43 +0100 | [diff] [blame] | 209 | /* Set C0000-FFFFF to access RAM on both reads and writes */ |
| 210 | enable_pam_region(); |
| 211 | |
Nico Huber | bb9469c | 2015-10-21 11:49:23 +0200 | [diff] [blame] | 212 | /* Setup IOMMU BARs */ |
Patrick Rudolph | 2cdb65d | 2019-03-24 18:08:43 +0100 | [diff] [blame] | 213 | systemagent_vtd_init(); |
Nico Huber | bb9469c | 2015-10-21 11:49:23 +0200 | [diff] [blame] | 214 | |
Patrick Rudolph | 2a510a7 | 2015-07-28 07:51:10 +0200 | [diff] [blame] | 215 | /* Device Enable, don't touch PEG bits */ |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 216 | deven = pci_read_config32(HOST_BRIDGE, DEVEN) | DEVEN_IGD; |
| 217 | pci_write_config32(HOST_BRIDGE, DEVEN, deven); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 218 | |
| 219 | sandybridge_setup_graphics(); |
Patrick Rudolph | e4f9d5c | 2015-10-15 11:09:15 +0200 | [diff] [blame] | 220 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 221 | /* |
| 222 | * Write magic values to start PEG link training. This should be done in PCI device |
| 223 | * enumeration, but the PCIe specification requires to wait at least 100msec after |
| 224 | * reset for devices to come up. As we don't want to increase boot time, enable it |
| 225 | * early and assume that PEG is up as soon as PCI enumeration starts. |
| 226 | * |
| 227 | * TODO: use timestamps to ensure the timings are met. |
| 228 | */ |
Patrick Rudolph | e4f9d5c | 2015-10-15 11:09:15 +0200 | [diff] [blame] | 229 | start_peg_link_training(); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 230 | } |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 231 | |
| 232 | void northbridge_romstage_finalize(int s3resume) |
| 233 | { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 234 | MCHBAR16(SSKPD_HI) = 0xCAFE; |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 235 | |
Aaron Durbin | 77e1399 | 2016-11-29 17:43:04 -0600 | [diff] [blame] | 236 | romstage_handoff_init(s3resume); |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 237 | } |