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