blob: ff5d7f27badbd63056cdab8aaf06dbd6c96d646c [file] [log] [blame]
Angel Pons6e5aabd2020-03-23 23:44:42 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Stefan Reinauer00636b02012-04-04 00:08:51 +02003
4#include <console/console.h>
5#include <arch/acpi.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 <stdint.h>
8#include <delay.h>
9#include <cpu/intel/model_206ax/model_206ax.h>
Duncan Laurie77dbbac2012-06-25 09:51:59 -070010#include <cpu/x86/msr.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020011#include <device/device.h>
12#include <device/pci.h>
13#include <device/pci_ids.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
18static int bridge_revision_id = -1;
19
Kyösti Mälkkif7bfc342013-10-18 11:02:46 +030020/* IGD UMA memory */
21static uint64_t uma_memory_base = 0;
22static uint64_t uma_memory_size = 0;
23
Stefan Reinauer00636b02012-04-04 00:08:51 +020024int bridge_silicon_revision(void)
25{
26 if (bridge_revision_id < 0) {
Angel Pons7c49cb82020-03-16 23:17:32 +010027 uint8_t stepping = cpuid_eax(1) & 0x0f;
28 uint8_t bridge_id = pci_read_config16(pcidev_on_root(0, 0), PCI_DEVICE_ID);
29 bridge_revision_id = (bridge_id & 0xf0) | stepping;
Stefan Reinauer00636b02012-04-04 00:08:51 +020030 }
31 return bridge_revision_id;
32}
33
34/* Reserve everything between A segment and 1MB:
35 *
36 * 0xa0000 - 0xbffff: legacy VGA
37 * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel)
38 * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI
39 */
40static const int legacy_hole_base_k = 0xa0000 / 1024;
41static const int legacy_hole_size_k = 384;
42
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020043static int get_pcie_bar(u32 *base)
Stefan Reinauer00636b02012-04-04 00:08:51 +020044{
Elyes HAOUASab8743c2018-02-09 08:21:40 +010045 struct device *dev;
Stefan Reinauer00636b02012-04-04 00:08:51 +020046 u32 pciexbar_reg;
47
48 *base = 0;
Stefan Reinauer00636b02012-04-04 00:08:51 +020049
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030050 dev = pcidev_on_root(0, 0);
Stefan Reinauer00636b02012-04-04 00:08:51 +020051 if (!dev)
52 return 0;
53
54 pciexbar_reg = pci_read_config32(dev, PCIEXBAR);
55
Angel Pons7c49cb82020-03-16 23:17:32 +010056 /* MMCFG not supported or not enabled */
Stefan Reinauer00636b02012-04-04 00:08:51 +020057 if (!(pciexbar_reg & (1 << 0)))
58 return 0;
59
60 switch ((pciexbar_reg >> 1) & 3) {
Angel Pons7c49cb82020-03-16 23:17:32 +010061 case 0: /* 256MB */
62 *base = pciexbar_reg & (0xffffffffULL << 28);
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020063 return 256;
Angel Pons7c49cb82020-03-16 23:17:32 +010064 case 1: /* 128M */
65 *base = pciexbar_reg & (0xffffffffULL << 27);
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020066 return 128;
Angel Pons7c49cb82020-03-16 23:17:32 +010067 case 2: /* 64M */
68 *base = pciexbar_reg & (0xffffffffULL << 26);
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020069 return 64;
Stefan Reinauer00636b02012-04-04 00:08:51 +020070 }
71
72 return 0;
73}
74
Stefan Reinauer00636b02012-04-04 00:08:51 +020075static void add_fixed_resources(struct device *dev, int index)
76{
Kyösti Mälkki7f189cc2012-07-27 13:12:03 +030077 mmio_resource(dev, index++, uma_memory_base >> 10, uma_memory_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +020078
Angel Pons7c49cb82020-03-16 23:17:32 +010079 mmio_resource(dev, index++, legacy_hole_base_k, (0xc0000 >> 10) - legacy_hole_base_k);
80
81 reserved_ram_resource(dev, index++, 0xc0000 >> 10, (0x100000 - 0xc0000) >> 10);
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +030082
Julius Wernercd49cce2019-03-05 16:53:33 -080083#if CONFIG(CHROMEOS_RAMOOPS)
Aaron Durbinc9650762013-03-22 22:03:09 -050084 reserved_ram_resource(dev, index++,
85 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
Angel Pons7c49cb82020-03-16 23:17:32 +010086 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +030087#endif
88
Nico Huber593e7de2015-11-04 15:46:00 +010089 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
90 /* Required for SandyBridge sighting 3715511 */
91 bad_ram_resource(dev, index++, 0x20000000 >> 10, 0x00200000 >> 10);
92 bad_ram_resource(dev, index++, 0x40000000 >> 10, 0x00200000 >> 10);
93 }
Nico Huberbb9469c2015-10-21 11:49:23 +020094
95 /* Reserve IOMMU BARs */
Angel Pons7c49cb82020-03-16 23:17:32 +010096 const u32 capid0_a = pci_read_config32(dev, CAPID0_A);
Nico Huberbb9469c2015-10-21 11:49:23 +020097 if (!(capid0_a & (1 << 23))) {
Angel Pons7c49cb82020-03-16 23:17:32 +010098 mmio_resource(dev, index++, GFXVT_BASE >> 10, 4);
99 mmio_resource(dev, index++, VTVC0_BASE >> 10, 4);
Nico Huberbb9469c2015-10-21 11:49:23 +0200100 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200101}
102
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100103static void pci_domain_set_resources(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200104{
105 uint64_t tom, me_base, touud;
106 uint32_t tseg_base, uma_size, tolud;
107 uint16_t ggc;
108 unsigned long long tomk;
109
110 /* Total Memory 2GB example:
111 *
112 * 00000000 0000MB-1992MB 1992MB RAM (writeback)
113 * 7c800000 1992MB-2000MB 8MB TSEG (SMRR)
114 * 7d000000 2000MB-2002MB 2MB GFX GTT (uncached)
115 * 7d200000 2002MB-2034MB 32MB GFX UMA (uncached)
116 * 7f200000 2034MB TOLUD
117 * 7f800000 2040MB MEBASE
118 * 7f800000 2040MB-2048MB 8MB ME UMA (uncached)
119 * 80000000 2048MB TOM
120 * 100000000 4096MB-4102MB 6MB RAM (writeback)
121 *
122 * Total Memory 4GB example:
123 *
124 * 00000000 0000MB-2768MB 2768MB RAM (writeback)
125 * ad000000 2768MB-2776MB 8MB TSEG (SMRR)
126 * ad800000 2776MB-2778MB 2MB GFX GTT (uncached)
127 * ada00000 2778MB-2810MB 32MB GFX UMA (uncached)
128 * afa00000 2810MB TOLUD
129 * ff800000 4088MB MEBASE
130 * ff800000 4088MB-4096MB 8MB ME UMA (uncached)
131 * 100000000 4096MB TOM
132 * 100000000 4096MB-5374MB 1278MB RAM (writeback)
133 * 14fe00000 5368MB TOUUD
134 */
135
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300136 struct device *mch = pcidev_on_root(0, 0);
Arthur Heymans17041202018-06-26 21:06:25 +0200137
Stefan Reinauer00636b02012-04-04 00:08:51 +0200138 /* Top of Upper Usable DRAM, including remap */
Angel Pons7c49cb82020-03-16 23:17:32 +0100139 touud = pci_read_config32(mch, TOUUD + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200140 touud <<= 32;
Arthur Heymans17041202018-06-26 21:06:25 +0200141 touud |= pci_read_config32(mch, TOUUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200142
143 /* Top of Lower Usable DRAM */
Arthur Heymans17041202018-06-26 21:06:25 +0200144 tolud = pci_read_config32(mch, TOLUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200145
146 /* Top of Memory - does not account for any UMA */
Angel Pons7c49cb82020-03-16 23:17:32 +0100147 tom = pci_read_config32(mch, TOM + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200148 tom <<= 32;
Angel Pons7c49cb82020-03-16 23:17:32 +0100149 tom |= pci_read_config32(mch, TOM);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200150
151 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
152 touud, tolud, tom);
153
Angel Pons7c49cb82020-03-16 23:17:32 +0100154 /* ME UMA needs excluding if total memory < 4GB */
155 me_base = pci_read_config32(mch, MESEG_BASE + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200156 me_base <<= 32;
Angel Pons7c49cb82020-03-16 23:17:32 +0100157 me_base |= pci_read_config32(mch, MESEG_BASE);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200158
159 printk(BIOS_DEBUG, "MEBASE 0x%llx\n", me_base);
160
Patrick Rudolph240766a2015-10-15 15:33:25 +0200161 uma_memory_base = tolud;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200162 tomk = tolud >> 10;
163 if (me_base == tolud) {
164 /* ME is from MEBASE-TOM */
165 uma_size = (tom - me_base) >> 10;
166 /* Increment TOLUD to account for ME as RAM */
167 tolud += uma_size << 10;
168 /* UMA starts at old TOLUD */
169 uma_memory_base = tomk * 1024ULL;
170 uma_memory_size = uma_size * 1024ULL;
171 printk(BIOS_DEBUG, "ME UMA base 0x%llx size %uM\n",
172 me_base, uma_size >> 10);
173 }
174
175 /* Graphics memory comes next */
Arthur Heymans17041202018-06-26 21:06:25 +0200176 ggc = pci_read_config16(mch, GGC);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200177 if (!(ggc & 2)) {
178 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
179
180 /* Graphics memory */
181 uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL;
182 printk(BIOS_DEBUG, "%uM UMA", uma_size >> 10);
183 tomk -= uma_size;
184 uma_memory_base = tomk * 1024ULL;
185 uma_memory_size += uma_size * 1024ULL;
186
187 /* GTT Graphics Stolen Memory Size (GGMS) */
188 uma_size = ((ggc >> 8) & 0x3) * 1024ULL;
189 tomk -= uma_size;
190 uma_memory_base = tomk * 1024ULL;
191 uma_memory_size += uma_size * 1024ULL;
192 printk(BIOS_DEBUG, " and %uM GTT\n", uma_size >> 10);
193 }
194
195 /* Calculate TSEG size from its base which must be below GTT */
Angel Pons7c49cb82020-03-16 23:17:32 +0100196 tseg_base = pci_read_config32(mch, TSEGMB);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200197 uma_size = (uma_memory_base - tseg_base) >> 10;
198 tomk -= uma_size;
199 uma_memory_base = tomk * 1024ULL;
200 uma_memory_size += uma_size * 1024ULL;
Angel Pons7c49cb82020-03-16 23:17:32 +0100201 printk(BIOS_DEBUG, "TSEG base 0x%08x size %uM\n", tseg_base, uma_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200202
203 printk(BIOS_INFO, "Available memory below 4GB: %lluM\n", tomk >> 10);
204
205 /* Report the memory regions */
206 ram_resource(dev, 3, 0, legacy_hole_base_k);
207 ram_resource(dev, 4, legacy_hole_base_k + legacy_hole_size_k,
Angel Pons7c49cb82020-03-16 23:17:32 +0100208 (tomk - (legacy_hole_base_k + legacy_hole_size_k)));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200209
210 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100211 * If >= 4GB installed, then memory from TOLUD to 4GB is remapped above TOM.
212 * TOUUD will account for both memory chunks.
Stefan Reinauer00636b02012-04-04 00:08:51 +0200213 */
214 touud >>= 10; /* Convert to KB */
215 if (touud > 4096 * 1024) {
216 ram_resource(dev, 5, 4096 * 1024, touud - (4096 * 1024));
Angel Pons7c49cb82020-03-16 23:17:32 +0100217 printk(BIOS_INFO, "Available memory above 4GB: %lluM\n", (touud >> 10) - 4096);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200218 }
219
220 add_fixed_resources(dev, 6);
221
222 assign_resources(dev->link_list);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200223}
224
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600225static const char *northbridge_acpi_name(const struct device *dev)
Patrick Rudolph3e47fc92017-06-07 09:44:07 +0200226{
227 if (dev->path.type == DEVICE_PATH_DOMAIN)
228 return "PCI0";
229
230 if (dev->path.type != DEVICE_PATH_PCI)
231 return NULL;
232
233 switch (dev->path.pci.devfn) {
234 case PCI_DEVFN(0, 0):
235 return "MCHC";
236 }
237
238 return NULL;
239}
240
Angel Pons7c49cb82020-03-16 23:17:32 +0100241/*
242 * TODO We could determine how many PCIe busses we need in the bar.
243 * For now, that number is hardcoded to a max of 64.
244 */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200245static struct device_operations pci_domain_ops = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100246 .read_resources = pci_domain_read_resources,
247 .set_resources = pci_domain_set_resources,
248 .enable_resources = NULL,
249 .init = NULL,
250 .scan_bus = pci_domain_scan_bus,
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100251 .write_acpi_tables = northbridge_write_acpi_tables,
Angel Pons7c49cb82020-03-16 23:17:32 +0100252 .acpi_name = northbridge_acpi_name,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200253};
254
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100255static void mc_read_resources(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200256{
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200257 u32 pcie_config_base;
258 int buses;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200259
260 pci_dev_read_resources(dev);
261
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200262 buses = get_pcie_bar(&pcie_config_base);
263 if (buses) {
Kyösti Mälkki27198ac2016-12-02 14:38:13 +0200264 struct resource *resource = new_resource(dev, PCIEXBAR);
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200265 mmconf_resource_init(resource, pcie_config_base, buses);
266 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200267}
268
Stefan Reinauer00636b02012-04-04 00:08:51 +0200269static void northbridge_dmi_init(struct device *dev)
270{
271 u32 reg32;
272
273 /* Clear error status bits */
274 DMIBAR32(0x1c4) = 0xffffffff;
275 DMIBAR32(0x1d0) = 0xffffffff;
276
277 /* Steps prior to DMI ASPM */
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700278 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
279 reg32 = DMIBAR32(0x250);
Angel Pons7c49cb82020-03-16 23:17:32 +0100280 reg32 &= ~((1 << 22) | (1 << 20));
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700281 reg32 |= (1 << 21);
282 DMIBAR32(0x250) = reg32;
283 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200284
285 reg32 = DMIBAR32(0x238);
286 reg32 |= (1 << 29);
287 DMIBAR32(0x238) = reg32;
288
289 if (bridge_silicon_revision() >= SNB_STEP_D0) {
290 reg32 = DMIBAR32(0x1f8);
291 reg32 |= (1 << 16);
292 DMIBAR32(0x1f8) = reg32;
Angel Pons7c49cb82020-03-16 23:17:32 +0100293
Stefan Reinauer00636b02012-04-04 00:08:51 +0200294 } else if (bridge_silicon_revision() >= SNB_STEP_D1) {
295 reg32 = DMIBAR32(0x1f8);
296 reg32 &= ~(1 << 26);
297 reg32 |= (1 << 16);
298 DMIBAR32(0x1f8) = reg32;
299
300 reg32 = DMIBAR32(0x1fc);
301 reg32 |= (1 << 12) | (1 << 23);
302 DMIBAR32(0x1fc) = reg32;
303 }
304
305 /* Enable ASPM on SNB link, should happen before PCH link */
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700306 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
307 reg32 = DMIBAR32(0xd04);
308 reg32 |= (1 << 4);
309 DMIBAR32(0xd04) = reg32;
310 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200311
312 reg32 = DMIBAR32(0x88);
313 reg32 |= (1 << 1) | (1 << 0);
314 DMIBAR32(0x88) = reg32;
315}
316
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200317/* Disable unused PEG devices based on devicetree */
318static void disable_peg(void)
319{
320 struct device *dev;
321 u32 reg;
322
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300323 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200324 reg = pci_read_config32(dev, DEVEN);
325
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300326 dev = pcidev_on_root(1, 2);
Nico Huber2dc15e92016-02-04 18:59:48 +0100327 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200328 printk(BIOS_DEBUG, "Disabling PEG12.\n");
329 reg &= ~DEVEN_PEG12;
330 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300331 dev = pcidev_on_root(1, 1);
Nico Huber2dc15e92016-02-04 18:59:48 +0100332 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200333 printk(BIOS_DEBUG, "Disabling PEG11.\n");
334 reg &= ~DEVEN_PEG11;
335 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300336 dev = pcidev_on_root(1, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100337 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200338 printk(BIOS_DEBUG, "Disabling PEG10.\n");
339 reg &= ~DEVEN_PEG10;
340 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300341 dev = pcidev_on_root(2, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100342 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200343 printk(BIOS_DEBUG, "Disabling IGD.\n");
344 reg &= ~DEVEN_IGD;
345 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300346 dev = pcidev_on_root(4, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200347 if (!dev || !dev->enabled) {
348 printk(BIOS_DEBUG, "Disabling Device 4.\n");
349 reg &= ~DEVEN_D4EN;
350 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300351 dev = pcidev_on_root(6, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100352 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200353 printk(BIOS_DEBUG, "Disabling PEG60.\n");
354 reg &= ~DEVEN_PEG60;
355 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300356 dev = pcidev_on_root(7, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200357 if (!dev || !dev->enabled) {
358 printk(BIOS_DEBUG, "Disabling Device 7.\n");
359 reg &= ~DEVEN_D7EN;
360 }
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200361
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300362 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200363 pci_write_config32(dev, DEVEN, reg);
Angel Pons7c49cb82020-03-16 23:17:32 +0100364
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200365 if (!(reg & (DEVEN_PEG60 | DEVEN_PEG10 | DEVEN_PEG11 | DEVEN_PEG12))) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100366 /*
367 * Set the PEG clock gating bit. Disables the IO clock on all PEG devices.
368 *
Angel Pons78b43c82020-03-17 23:55:18 +0100369 * FIXME: Never clock gate on Ivy Bridge stepping A0!
Angel Pons7c49cb82020-03-16 23:17:32 +0100370 */
371 MCHBAR32_OR(PEGCTL, 1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200372 printk(BIOS_DEBUG, "Disabling PEG IO clock.\n");
Angel Pons78b43c82020-03-17 23:55:18 +0100373 } else {
374 MCHBAR32_AND(PEGCTL, ~1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200375 }
376}
377
Stefan Reinauer00636b02012-04-04 00:08:51 +0200378static void northbridge_init(struct device *dev)
379{
380 u8 bios_reset_cpl;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700381 u32 bridge_type;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200382
383 northbridge_dmi_init(dev);
384
Angel Pons88521882020-01-05 20:21:20 +0100385 bridge_type = MCHBAR32(SAPMTIMERS);
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700386 bridge_type &= ~0xff;
387
388 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
389 /* Enable Power Aware Interrupt Routing */
Angel Pons7c49cb82020-03-16 23:17:32 +0100390 u8 pair = MCHBAR8(INTRDIRCTL);
391 pair &= ~0x0f; /* Clear 3:0 */
392 pair |= 0x04; /* Fixed Priority */
393 MCHBAR8(INTRDIRCTL) = pair;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700394
395 /* 30h for IvyBridge */
396 bridge_type |= 0x30;
397 } else {
398 /* 20h for Sandybridge */
399 bridge_type |= 0x20;
400 }
Angel Pons88521882020-01-05 20:21:20 +0100401 MCHBAR32(SAPMTIMERS) = bridge_type;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700402
Angel Pons7c49cb82020-03-16 23:17:32 +0100403 /* Turn off unused devices. Has to be done before setting BIOS_RESET_CPL. */
Patrick Rudolphaad34cd2015-10-21 18:05:01 +0200404 disable_peg();
405
Stefan Reinauer00636b02012-04-04 00:08:51 +0200406 /*
407 * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
408 * that BIOS has initialized memory and power management
409 */
410 bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL);
411 bios_reset_cpl |= 1;
412 MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl;
413 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
414
415 /* Configure turbo power limits 1ms after reset complete bit */
416 mdelay(1);
417 set_power_limits(28);
418
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700419 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100420 * CPUs with configurable TDP also need power limits set in MCHBAR.
421 * Use the same values from MSR_PKG_POWER_LIMIT.
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700422 */
423 if (cpu_config_tdp_levels()) {
424 msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT);
Angel Pons7c49cb82020-03-16 23:17:32 +0100425 MCHBAR32(MCH_PKG_POWER_LIMIT_LO) = msr.lo;
426 MCHBAR32(MCH_PKG_POWER_LIMIT_HI) = msr.hi;
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700427 }
428
Stefan Reinauer00636b02012-04-04 00:08:51 +0200429 /* Set here before graphics PM init */
Angel Pons7c49cb82020-03-16 23:17:32 +0100430 MCHBAR32(PAVP_MSG) = 0x00100001;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200431}
432
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200433void northbridge_write_smram(u8 smram)
434{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300435 pci_write_config8(pcidev_on_root(0, 0), SMRAM, smram);
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200436}
437
Stefan Reinauer00636b02012-04-04 00:08:51 +0200438static struct pci_operations intel_pci_ops = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100439 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200440};
441
442static struct device_operations mc_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200443 .read_resources = mc_read_resources,
444 .set_resources = pci_dev_set_resources,
445 .enable_resources = pci_dev_enable_resources,
446 .init = northbridge_init,
447 .scan_bus = NULL,
448 .ops_pci = &intel_pci_ops,
449 .acpi_fill_ssdt = generate_cpu_entries,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200450};
451
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600452static const unsigned short pci_device_ids[] = {
Jonathan A. Kollaschd346a192020-02-11 09:03:48 -0600453 0x0100, 0x0104, 0x0108, /* Sandy Bridge */
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600454 0x0150, 0x0154, 0x0158, /* Ivy Bridge */
455 0
Walter Murphy496f4a02012-04-23 11:08:03 -0700456};
457
Stefan Reinauer00636b02012-04-04 00:08:51 +0200458static const struct pci_driver mc_driver __pci_driver = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100459 .ops = &mc_ops,
460 .vendor = PCI_VENDOR_ID_INTEL,
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600461 .devices = pci_device_ids,
Vagiz Trakhanov1dd448c2017-09-28 14:42:11 +0000462};
463
Stefan Reinauer00636b02012-04-04 00:08:51 +0200464static struct device_operations cpu_bus_ops = {
Edward O'Callaghan9f744622014-10-31 08:12:34 +1100465 .read_resources = DEVICE_NOOP,
466 .set_resources = DEVICE_NOOP,
467 .enable_resources = DEVICE_NOOP,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300468 .init = mp_cpu_bus_init,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200469 .scan_bus = 0,
470};
471
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100472static void enable_dev(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200473{
474 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800475 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200476 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800477 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200478 dev->ops = &cpu_bus_ops;
479 }
480}
481
482struct chip_operations northbridge_intel_sandybridge_ops = {
Damien Zammit35170382014-10-29 00:11:53 +1100483 CHIP_NAME("Intel SandyBridge/IvyBridge integrated Northbridge")
Stefan Reinauer00636b02012-04-04 00:08:51 +0200484 .enable_dev = enable_dev,
485};