blob: 6e954611e1847de4813d91149f93d236934ac412 [file] [log] [blame]
Angel Pons6e5aabd2020-03-23 23:44:42 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer00636b02012-04-04 00:08:51 +02002
3#include <console/console.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07004#include <acpi/acpi.h>
Angel Pons20905cf2020-08-03 14:18:41 +02005#include <commonlib/helpers.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02006#include <device/pci_ops.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +02007#include <delay.h>
8#include <cpu/intel/model_206ax/model_206ax.h>
Duncan Laurie77dbbac2012-06-25 09:51:59 -07009#include <cpu/x86/msr.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020010#include <device/device.h>
11#include <device/pci.h>
12#include <device/pci_ids.h>
Angel Pons964d91f2020-12-07 13:11:17 +010013#include <types.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020014#include "chip.h"
15#include "sandybridge.h"
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030016#include <cpu/intel/smm_reloc.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020017
Kyösti Mälkkif7bfc342013-10-18 11:02:46 +030018/* IGD UMA memory */
19static uint64_t uma_memory_base = 0;
20static uint64_t uma_memory_size = 0;
21
Angel Pons964d91f2020-12-07 13:11:17 +010022bool is_sandybridge(void)
Stefan Reinauer00636b02012-04-04 00:08:51 +020023{
Angel Pons964d91f2020-12-07 13:11:17 +010024 const uint16_t bridge_id = pci_read_config16(pcidev_on_root(0, 0), PCI_DEVICE_ID);
25
26 return (bridge_id & BASE_REV_MASK) == BASE_REV_SNB;
Stefan Reinauer00636b02012-04-04 00:08:51 +020027}
28
29/* Reserve everything between A segment and 1MB:
30 *
31 * 0xa0000 - 0xbffff: legacy VGA
32 * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel)
33 * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI
34 */
35static const int legacy_hole_base_k = 0xa0000 / 1024;
36static const int legacy_hole_size_k = 384;
37
Aaron Durbin1ca24332020-05-13 11:38:35 -060038static const char *northbridge_acpi_name(const struct device *dev)
39{
40 if (dev->path.type == DEVICE_PATH_DOMAIN)
41 return "PCI0";
42
43 if (dev->path.type != DEVICE_PATH_PCI)
44 return NULL;
45
46 switch (dev->path.pci.devfn) {
47 case PCI_DEVFN(0, 0):
48 return "MCHC";
49 }
50
51 return NULL;
52}
53
Aaron Durbin1ca24332020-05-13 11:38:35 -060054static struct device_operations pci_domain_ops = {
55 .read_resources = pci_domain_read_resources,
56 .set_resources = pci_domain_set_resources,
57 .scan_bus = pci_domain_scan_bus,
58 .write_acpi_tables = northbridge_write_acpi_tables,
59 .acpi_name = northbridge_acpi_name,
60};
61
Stefan Reinauer00636b02012-04-04 00:08:51 +020062static void add_fixed_resources(struct device *dev, int index)
63{
Kyösti Mälkki7f189cc2012-07-27 13:12:03 +030064 mmio_resource(dev, index++, uma_memory_base >> 10, uma_memory_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +020065
Angel Pons7c49cb82020-03-16 23:17:32 +010066 mmio_resource(dev, index++, legacy_hole_base_k, (0xc0000 >> 10) - legacy_hole_base_k);
67
68 reserved_ram_resource(dev, index++, 0xc0000 >> 10, (0x100000 - 0xc0000) >> 10);
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +030069
Angel Pons964d91f2020-12-07 13:11:17 +010070 if (is_sandybridge()) {
Nico Huber593e7de2015-11-04 15:46:00 +010071 /* Required for SandyBridge sighting 3715511 */
72 bad_ram_resource(dev, index++, 0x20000000 >> 10, 0x00200000 >> 10);
73 bad_ram_resource(dev, index++, 0x40000000 >> 10, 0x00200000 >> 10);
74 }
Nico Huberbb9469c2015-10-21 11:49:23 +020075
76 /* Reserve IOMMU BARs */
Angel Pons7c49cb82020-03-16 23:17:32 +010077 const u32 capid0_a = pci_read_config32(dev, CAPID0_A);
Nico Huberbb9469c2015-10-21 11:49:23 +020078 if (!(capid0_a & (1 << 23))) {
Angel Pons7c49cb82020-03-16 23:17:32 +010079 mmio_resource(dev, index++, GFXVT_BASE >> 10, 4);
80 mmio_resource(dev, index++, VTVC0_BASE >> 10, 4);
Nico Huberbb9469c2015-10-21 11:49:23 +020081 }
Stefan Reinauer00636b02012-04-04 00:08:51 +020082}
83
Aaron Durbin1ca24332020-05-13 11:38:35 -060084static void mc_read_resources(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +020085{
86 uint64_t tom, me_base, touud;
87 uint32_t tseg_base, uma_size, tolud;
88 uint16_t ggc;
89 unsigned long long tomk;
Angel Pons14ea2fc2020-05-13 21:46:46 +020090 unsigned long index = 3;
Stefan Reinauer00636b02012-04-04 00:08:51 +020091
Aaron Durbin1ca24332020-05-13 11:38:35 -060092 pci_dev_read_resources(dev);
93
Angel Pons10f9b832021-01-20 14:58:32 +010094 mmconf_resource(dev, PCIEXBAR);
Aaron Durbin1ca24332020-05-13 11:38:35 -060095
Stefan Reinauer00636b02012-04-04 00:08:51 +020096 /* Total Memory 2GB example:
97 *
98 * 00000000 0000MB-1992MB 1992MB RAM (writeback)
99 * 7c800000 1992MB-2000MB 8MB TSEG (SMRR)
100 * 7d000000 2000MB-2002MB 2MB GFX GTT (uncached)
101 * 7d200000 2002MB-2034MB 32MB GFX UMA (uncached)
102 * 7f200000 2034MB TOLUD
103 * 7f800000 2040MB MEBASE
104 * 7f800000 2040MB-2048MB 8MB ME UMA (uncached)
105 * 80000000 2048MB TOM
106 * 100000000 4096MB-4102MB 6MB RAM (writeback)
107 *
108 * Total Memory 4GB example:
109 *
110 * 00000000 0000MB-2768MB 2768MB RAM (writeback)
111 * ad000000 2768MB-2776MB 8MB TSEG (SMRR)
112 * ad800000 2776MB-2778MB 2MB GFX GTT (uncached)
113 * ada00000 2778MB-2810MB 32MB GFX UMA (uncached)
114 * afa00000 2810MB TOLUD
115 * ff800000 4088MB MEBASE
116 * ff800000 4088MB-4096MB 8MB ME UMA (uncached)
117 * 100000000 4096MB TOM
118 * 100000000 4096MB-5374MB 1278MB RAM (writeback)
119 * 14fe00000 5368MB TOUUD
120 */
121
122 /* Top of Upper Usable DRAM, including remap */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600123 touud = pci_read_config32(dev, TOUUD + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200124 touud <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600125 touud |= pci_read_config32(dev, TOUUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200126
127 /* Top of Lower Usable DRAM */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600128 tolud = pci_read_config32(dev, TOLUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200129
130 /* Top of Memory - does not account for any UMA */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600131 tom = pci_read_config32(dev, TOM + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200132 tom <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600133 tom |= pci_read_config32(dev, TOM);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200134
135 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
136 touud, tolud, tom);
137
Angel Pons7c49cb82020-03-16 23:17:32 +0100138 /* ME UMA needs excluding if total memory < 4GB */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600139 me_base = pci_read_config32(dev, MESEG_BASE + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200140 me_base <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600141 me_base |= pci_read_config32(dev, MESEG_BASE);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200142
143 printk(BIOS_DEBUG, "MEBASE 0x%llx\n", me_base);
144
Patrick Rudolph240766a2015-10-15 15:33:25 +0200145 uma_memory_base = tolud;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200146 tomk = tolud >> 10;
147 if (me_base == tolud) {
148 /* ME is from MEBASE-TOM */
149 uma_size = (tom - me_base) >> 10;
150 /* Increment TOLUD to account for ME as RAM */
151 tolud += uma_size << 10;
152 /* UMA starts at old TOLUD */
153 uma_memory_base = tomk * 1024ULL;
154 uma_memory_size = uma_size * 1024ULL;
155 printk(BIOS_DEBUG, "ME UMA base 0x%llx size %uM\n",
156 me_base, uma_size >> 10);
157 }
158
159 /* Graphics memory comes next */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600160 ggc = pci_read_config16(dev, GGC);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200161 if (!(ggc & 2)) {
162 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
163
164 /* Graphics memory */
165 uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL;
166 printk(BIOS_DEBUG, "%uM UMA", uma_size >> 10);
167 tomk -= uma_size;
168 uma_memory_base = tomk * 1024ULL;
169 uma_memory_size += uma_size * 1024ULL;
170
171 /* GTT Graphics Stolen Memory Size (GGMS) */
172 uma_size = ((ggc >> 8) & 0x3) * 1024ULL;
173 tomk -= uma_size;
174 uma_memory_base = tomk * 1024ULL;
175 uma_memory_size += uma_size * 1024ULL;
176 printk(BIOS_DEBUG, " and %uM GTT\n", uma_size >> 10);
177 }
178
179 /* Calculate TSEG size from its base which must be below GTT */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600180 tseg_base = pci_read_config32(dev, TSEGMB);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200181 uma_size = (uma_memory_base - tseg_base) >> 10;
182 tomk -= uma_size;
183 uma_memory_base = tomk * 1024ULL;
184 uma_memory_size += uma_size * 1024ULL;
Angel Pons7c49cb82020-03-16 23:17:32 +0100185 printk(BIOS_DEBUG, "TSEG base 0x%08x size %uM\n", tseg_base, uma_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200186
187 printk(BIOS_INFO, "Available memory below 4GB: %lluM\n", tomk >> 10);
188
189 /* Report the memory regions */
Angel Pons14ea2fc2020-05-13 21:46:46 +0200190 ram_resource(dev, index++, 0, legacy_hole_base_k);
191 ram_resource(dev, index++, legacy_hole_base_k + legacy_hole_size_k,
192 (tomk - (legacy_hole_base_k + legacy_hole_size_k)));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200193
194 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100195 * If >= 4GB installed, then memory from TOLUD to 4GB is remapped above TOM.
196 * TOUUD will account for both memory chunks.
Stefan Reinauer00636b02012-04-04 00:08:51 +0200197 */
198 touud >>= 10; /* Convert to KB */
199 if (touud > 4096 * 1024) {
Angel Pons14ea2fc2020-05-13 21:46:46 +0200200 ram_resource(dev, index++, 4096 * 1024, touud - (4096 * 1024));
Angel Pons7c49cb82020-03-16 23:17:32 +0100201 printk(BIOS_INFO, "Available memory above 4GB: %lluM\n", (touud >> 10) - 4096);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200202 }
203
Angel Pons14ea2fc2020-05-13 21:46:46 +0200204 add_fixed_resources(dev, index++);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200205}
206
Stefan Reinauer00636b02012-04-04 00:08:51 +0200207static void northbridge_dmi_init(struct device *dev)
208{
Angel Pons964d91f2020-12-07 13:11:17 +0100209 const bool is_sandy = is_sandybridge();
210
Angel Pons77516ca2020-12-10 16:43:25 +0100211 const u8 stepping = cpu_stepping();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200212
Angel Pons77516ca2020-12-10 16:43:25 +0100213 u32 reg32;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200214
215 /* Steps prior to DMI ASPM */
Angel Pons964d91f2020-12-07 13:11:17 +0100216 if (is_sandy) {
Angel Pons66780a02021-03-26 13:33:22 +0100217 dmibar_clrsetbits32(0x250, 7 << 20, 2 << 20);
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700218 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200219
Angel Pons66780a02021-03-26 13:33:22 +0100220 dmibar_setbits32(DMILLTC, 1 << 29);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200221
Angel Pons77516ca2020-12-10 16:43:25 +0100222 if (is_sandy && stepping == SNB_STEP_C0) {
Angel Pons66780a02021-03-26 13:33:22 +0100223 dmibar_clrsetbits32(0xbc8, 0xfff << 7, 0x7d3 << 7);
Angel Pons77516ca2020-12-10 16:43:25 +0100224 }
Angel Pons7c49cb82020-03-16 23:17:32 +0100225
Angel Pons77516ca2020-12-10 16:43:25 +0100226 if (!is_sandy || stepping >= SNB_STEP_D1) {
Angel Pons66780a02021-03-26 13:33:22 +0100227 reg32 = dmibar_read32(0x1f8);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200228 reg32 &= ~(1 << 26);
229 reg32 |= (1 << 16);
Angel Pons66780a02021-03-26 13:33:22 +0100230 dmibar_write32(0x1f8, reg32);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200231
Angel Pons66780a02021-03-26 13:33:22 +0100232 dmibar_setbits32(0x1fc, 1 << 12 | 1 << 23);
Angel Pons77516ca2020-12-10 16:43:25 +0100233
234 } else if (stepping >= SNB_STEP_D0) {
Angel Pons66780a02021-03-26 13:33:22 +0100235 dmibar_setbits32(0x1f8, 1 << 16);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200236 }
237
Angel Pons77516ca2020-12-10 16:43:25 +0100238 /* Clear error status bits */
Angel Pons66780a02021-03-26 13:33:22 +0100239 dmibar_write32(DMIUESTS, 0xffffffff);
240 dmibar_write32(DMICESTS, 0xffffffff);
Angel Pons77516ca2020-12-10 16:43:25 +0100241
242 if (!is_sandy)
Angel Pons66780a02021-03-26 13:33:22 +0100243 dmibar_write32(0xc34, 0xffffffff);
Angel Pons77516ca2020-12-10 16:43:25 +0100244
Stefan Reinauer00636b02012-04-04 00:08:51 +0200245 /* Enable ASPM on SNB link, should happen before PCH link */
Angel Pons964d91f2020-12-07 13:11:17 +0100246 if (is_sandy) {
Angel Pons66780a02021-03-26 13:33:22 +0100247 dmibar_setbits32(0xd04, 1 << 4);
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700248 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200249
Angel Pons66780a02021-03-26 13:33:22 +0100250 dmibar_setbits32(DMILCTL, 1 << 1 | 1 << 0);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200251}
252
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200253/* Disable unused PEG devices based on devicetree */
254static void disable_peg(void)
255{
256 struct device *dev;
257 u32 reg;
258
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300259 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200260 reg = pci_read_config32(dev, DEVEN);
261
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300262 dev = pcidev_on_root(1, 2);
Nico Huber2dc15e92016-02-04 18:59:48 +0100263 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200264 printk(BIOS_DEBUG, "Disabling PEG12.\n");
265 reg &= ~DEVEN_PEG12;
266 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300267 dev = pcidev_on_root(1, 1);
Nico Huber2dc15e92016-02-04 18:59:48 +0100268 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200269 printk(BIOS_DEBUG, "Disabling PEG11.\n");
270 reg &= ~DEVEN_PEG11;
271 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300272 dev = pcidev_on_root(1, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100273 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200274 printk(BIOS_DEBUG, "Disabling PEG10.\n");
275 reg &= ~DEVEN_PEG10;
276 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300277 dev = pcidev_on_root(2, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100278 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200279 printk(BIOS_DEBUG, "Disabling IGD.\n");
280 reg &= ~DEVEN_IGD;
281 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300282 dev = pcidev_on_root(4, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200283 if (!dev || !dev->enabled) {
284 printk(BIOS_DEBUG, "Disabling Device 4.\n");
285 reg &= ~DEVEN_D4EN;
286 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300287 dev = pcidev_on_root(6, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100288 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200289 printk(BIOS_DEBUG, "Disabling PEG60.\n");
290 reg &= ~DEVEN_PEG60;
291 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300292 dev = pcidev_on_root(7, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200293 if (!dev || !dev->enabled) {
294 printk(BIOS_DEBUG, "Disabling Device 7.\n");
295 reg &= ~DEVEN_D7EN;
296 }
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200297
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300298 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200299 pci_write_config32(dev, DEVEN, reg);
Angel Pons7c49cb82020-03-16 23:17:32 +0100300
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200301 if (!(reg & (DEVEN_PEG60 | DEVEN_PEG10 | DEVEN_PEG11 | DEVEN_PEG12))) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100302 /*
303 * Set the PEG clock gating bit. Disables the IO clock on all PEG devices.
304 *
Angel Pons78b43c82020-03-17 23:55:18 +0100305 * FIXME: Never clock gate on Ivy Bridge stepping A0!
Angel Pons7c49cb82020-03-16 23:17:32 +0100306 */
Angel Pons66780a02021-03-26 13:33:22 +0100307 mchbar_setbits32(PEGCTL, 1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200308 printk(BIOS_DEBUG, "Disabling PEG IO clock.\n");
Angel Pons78b43c82020-03-17 23:55:18 +0100309 } else {
Angel Pons66780a02021-03-26 13:33:22 +0100310 mchbar_clrbits32(PEGCTL, 1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200311 }
312}
313
Stefan Reinauer00636b02012-04-04 00:08:51 +0200314static void northbridge_init(struct device *dev)
315{
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700316 u32 bridge_type;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200317
318 northbridge_dmi_init(dev);
319
Angel Pons66780a02021-03-26 13:33:22 +0100320 bridge_type = mchbar_read32(SAPMTIMERS);
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700321 bridge_type &= ~0xff;
322
Angel Pons964d91f2020-12-07 13:11:17 +0100323 if (is_sandybridge()) {
324 /* 20h for Sandybridge */
325 bridge_type |= 0x20;
326 } else {
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700327 /* Enable Power Aware Interrupt Routing */
Angel Pons66780a02021-03-26 13:33:22 +0100328 mchbar_clrsetbits8(INTRDIRCTL, 0xf, 0x4); /* Clear 3:0, set Fixed Priority */
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700329
330 /* 30h for IvyBridge */
331 bridge_type |= 0x30;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700332 }
Angel Pons66780a02021-03-26 13:33:22 +0100333 mchbar_write32(SAPMTIMERS, bridge_type);
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700334
Angel Pons7c49cb82020-03-16 23:17:32 +0100335 /* Turn off unused devices. Has to be done before setting BIOS_RESET_CPL. */
Patrick Rudolphaad34cd2015-10-21 18:05:01 +0200336 disable_peg();
337
Stefan Reinauer00636b02012-04-04 00:08:51 +0200338 /*
339 * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
340 * that BIOS has initialized memory and power management
341 */
Angel Pons66780a02021-03-26 13:33:22 +0100342 mchbar_setbits8(BIOS_RESET_CPL, 1 << 0);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200343 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
344
345 /* Configure turbo power limits 1ms after reset complete bit */
346 mdelay(1);
347 set_power_limits(28);
348
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700349 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100350 * CPUs with configurable TDP also need power limits set in MCHBAR.
351 * Use the same values from MSR_PKG_POWER_LIMIT.
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700352 */
353 if (cpu_config_tdp_levels()) {
354 msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT);
Angel Pons66780a02021-03-26 13:33:22 +0100355 mchbar_write32(MCH_PKG_POWER_LIMIT_LO, msr.lo);
356 mchbar_write32(MCH_PKG_POWER_LIMIT_HI, msr.hi);
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700357 }
358
Stefan Reinauer00636b02012-04-04 00:08:51 +0200359 /* Set here before graphics PM init */
Angel Pons66780a02021-03-26 13:33:22 +0100360 mchbar_write32(PAVP_MSG, 0x00100001);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200361}
362
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200363void northbridge_write_smram(u8 smram)
364{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300365 pci_write_config8(pcidev_on_root(0, 0), SMRAM, smram);
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200366}
367
Stefan Reinauer00636b02012-04-04 00:08:51 +0200368static struct device_operations mc_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200369 .read_resources = mc_read_resources,
370 .set_resources = pci_dev_set_resources,
371 .enable_resources = pci_dev_enable_resources,
372 .init = northbridge_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200373 .ops_pci = &pci_dev_ops_pci,
Nico Huber68680dd2020-03-31 17:34:52 +0200374 .acpi_fill_ssdt = generate_cpu_entries,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200375};
376
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600377static const unsigned short pci_device_ids[] = {
Jonathan A. Kollaschd346a192020-02-11 09:03:48 -0600378 0x0100, 0x0104, 0x0108, /* Sandy Bridge */
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600379 0x0150, 0x0154, 0x0158, /* Ivy Bridge */
380 0
Walter Murphy496f4a02012-04-23 11:08:03 -0700381};
382
Stefan Reinauer00636b02012-04-04 00:08:51 +0200383static const struct pci_driver mc_driver __pci_driver = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100384 .ops = &mc_ops,
385 .vendor = PCI_VENDOR_ID_INTEL,
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600386 .devices = pci_device_ids,
Vagiz Trakhanov1dd448c2017-09-28 14:42:11 +0000387};
388
Stefan Reinauer00636b02012-04-04 00:08:51 +0200389static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200390 .read_resources = noop_read_resources,
391 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300392 .init = mp_cpu_bus_init,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200393};
394
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100395static void enable_dev(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200396{
397 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800398 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200399 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800400 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200401 dev->ops = &cpu_bus_ops;
402 }
403}
404
405struct chip_operations northbridge_intel_sandybridge_ops = {
Damien Zammit35170382014-10-29 00:11:53 +1100406 CHIP_NAME("Intel SandyBridge/IvyBridge integrated Northbridge")
Stefan Reinauer00636b02012-04-04 00:08:51 +0200407 .enable_dev = enable_dev,
408};