blob: ce28c05fd43a63b493b05b9c6261da28685cb51e [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>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +02006#include <stdint.h>
7#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>
Stefan Reinauer00636b02012-04-04 00:08:51 +020013#include "chip.h"
14#include "sandybridge.h"
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030015#include <cpu/intel/smm_reloc.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020016
17static int bridge_revision_id = -1;
18
Kyösti Mälkkif7bfc342013-10-18 11:02:46 +030019/* IGD UMA memory */
20static uint64_t uma_memory_base = 0;
21static uint64_t uma_memory_size = 0;
22
Stefan Reinauer00636b02012-04-04 00:08:51 +020023int bridge_silicon_revision(void)
24{
25 if (bridge_revision_id < 0) {
Angel Pons7c49cb82020-03-16 23:17:32 +010026 uint8_t stepping = cpuid_eax(1) & 0x0f;
27 uint8_t bridge_id = pci_read_config16(pcidev_on_root(0, 0), PCI_DEVICE_ID);
28 bridge_revision_id = (bridge_id & 0xf0) | stepping;
Stefan Reinauer00636b02012-04-04 00:08:51 +020029 }
30 return bridge_revision_id;
31}
32
33/* Reserve everything between A segment and 1MB:
34 *
35 * 0xa0000 - 0xbffff: legacy VGA
36 * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel)
37 * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI
38 */
39static const int legacy_hole_base_k = 0xa0000 / 1024;
40static const int legacy_hole_size_k = 384;
41
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020042static int get_pcie_bar(u32 *base)
Stefan Reinauer00636b02012-04-04 00:08:51 +020043{
Elyes HAOUASab8743c2018-02-09 08:21:40 +010044 struct device *dev;
Stefan Reinauer00636b02012-04-04 00:08:51 +020045 u32 pciexbar_reg;
46
47 *base = 0;
Stefan Reinauer00636b02012-04-04 00:08:51 +020048
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030049 dev = pcidev_on_root(0, 0);
Stefan Reinauer00636b02012-04-04 00:08:51 +020050 if (!dev)
51 return 0;
52
53 pciexbar_reg = pci_read_config32(dev, PCIEXBAR);
54
Angel Pons7c49cb82020-03-16 23:17:32 +010055 /* MMCFG not supported or not enabled */
Stefan Reinauer00636b02012-04-04 00:08:51 +020056 if (!(pciexbar_reg & (1 << 0)))
57 return 0;
58
59 switch ((pciexbar_reg >> 1) & 3) {
Angel Pons7c49cb82020-03-16 23:17:32 +010060 case 0: /* 256MB */
61 *base = pciexbar_reg & (0xffffffffULL << 28);
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020062 return 256;
Angel Pons7c49cb82020-03-16 23:17:32 +010063 case 1: /* 128M */
64 *base = pciexbar_reg & (0xffffffffULL << 27);
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020065 return 128;
Angel Pons7c49cb82020-03-16 23:17:32 +010066 case 2: /* 64M */
67 *base = pciexbar_reg & (0xffffffffULL << 26);
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020068 return 64;
Stefan Reinauer00636b02012-04-04 00:08:51 +020069 }
70
71 return 0;
72}
73
Aaron Durbin1ca24332020-05-13 11:38:35 -060074static const char *northbridge_acpi_name(const struct device *dev)
75{
76 if (dev->path.type == DEVICE_PATH_DOMAIN)
77 return "PCI0";
78
79 if (dev->path.type != DEVICE_PATH_PCI)
80 return NULL;
81
82 switch (dev->path.pci.devfn) {
83 case PCI_DEVFN(0, 0):
84 return "MCHC";
85 }
86
87 return NULL;
88}
89
90/*
91 * TODO We could determine how many PCIe busses we need in the bar.
92 * For now, that number is hardcoded to a max of 64.
93 */
94static struct device_operations pci_domain_ops = {
95 .read_resources = pci_domain_read_resources,
96 .set_resources = pci_domain_set_resources,
97 .scan_bus = pci_domain_scan_bus,
98 .write_acpi_tables = northbridge_write_acpi_tables,
99 .acpi_name = northbridge_acpi_name,
100};
101
Stefan Reinauer00636b02012-04-04 00:08:51 +0200102static void add_fixed_resources(struct device *dev, int index)
103{
Kyösti Mälkki7f189cc2012-07-27 13:12:03 +0300104 mmio_resource(dev, index++, uma_memory_base >> 10, uma_memory_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200105
Angel Pons7c49cb82020-03-16 23:17:32 +0100106 mmio_resource(dev, index++, legacy_hole_base_k, (0xc0000 >> 10) - legacy_hole_base_k);
107
108 reserved_ram_resource(dev, index++, 0xc0000 >> 10, (0x100000 - 0xc0000) >> 10);
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +0300109
Julius Wernercd49cce2019-03-05 16:53:33 -0800110#if CONFIG(CHROMEOS_RAMOOPS)
Aaron Durbinc9650762013-03-22 22:03:09 -0500111 reserved_ram_resource(dev, index++,
112 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
Angel Pons7c49cb82020-03-16 23:17:32 +0100113 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +0300114#endif
115
Nico Huber593e7de2015-11-04 15:46:00 +0100116 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
117 /* Required for SandyBridge sighting 3715511 */
118 bad_ram_resource(dev, index++, 0x20000000 >> 10, 0x00200000 >> 10);
119 bad_ram_resource(dev, index++, 0x40000000 >> 10, 0x00200000 >> 10);
120 }
Nico Huberbb9469c2015-10-21 11:49:23 +0200121
122 /* Reserve IOMMU BARs */
Angel Pons7c49cb82020-03-16 23:17:32 +0100123 const u32 capid0_a = pci_read_config32(dev, CAPID0_A);
Nico Huberbb9469c2015-10-21 11:49:23 +0200124 if (!(capid0_a & (1 << 23))) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100125 mmio_resource(dev, index++, GFXVT_BASE >> 10, 4);
126 mmio_resource(dev, index++, VTVC0_BASE >> 10, 4);
Nico Huberbb9469c2015-10-21 11:49:23 +0200127 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200128}
129
Aaron Durbin1ca24332020-05-13 11:38:35 -0600130static void mc_read_resources(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200131{
Aaron Durbin1ca24332020-05-13 11:38:35 -0600132 u32 pcie_config_base;
133 int buses;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200134 uint64_t tom, me_base, touud;
135 uint32_t tseg_base, uma_size, tolud;
136 uint16_t ggc;
137 unsigned long long tomk;
Angel Pons14ea2fc2020-05-13 21:46:46 +0200138 unsigned long index = 3;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200139
Aaron Durbin1ca24332020-05-13 11:38:35 -0600140 pci_dev_read_resources(dev);
141
142 buses = get_pcie_bar(&pcie_config_base);
143 if (buses) {
144 struct resource *resource = new_resource(dev, PCIEXBAR);
145 mmconf_resource_init(resource, pcie_config_base, buses);
146 }
147
Stefan Reinauer00636b02012-04-04 00:08:51 +0200148 /* Total Memory 2GB example:
149 *
150 * 00000000 0000MB-1992MB 1992MB RAM (writeback)
151 * 7c800000 1992MB-2000MB 8MB TSEG (SMRR)
152 * 7d000000 2000MB-2002MB 2MB GFX GTT (uncached)
153 * 7d200000 2002MB-2034MB 32MB GFX UMA (uncached)
154 * 7f200000 2034MB TOLUD
155 * 7f800000 2040MB MEBASE
156 * 7f800000 2040MB-2048MB 8MB ME UMA (uncached)
157 * 80000000 2048MB TOM
158 * 100000000 4096MB-4102MB 6MB RAM (writeback)
159 *
160 * Total Memory 4GB example:
161 *
162 * 00000000 0000MB-2768MB 2768MB RAM (writeback)
163 * ad000000 2768MB-2776MB 8MB TSEG (SMRR)
164 * ad800000 2776MB-2778MB 2MB GFX GTT (uncached)
165 * ada00000 2778MB-2810MB 32MB GFX UMA (uncached)
166 * afa00000 2810MB TOLUD
167 * ff800000 4088MB MEBASE
168 * ff800000 4088MB-4096MB 8MB ME UMA (uncached)
169 * 100000000 4096MB TOM
170 * 100000000 4096MB-5374MB 1278MB RAM (writeback)
171 * 14fe00000 5368MB TOUUD
172 */
173
174 /* Top of Upper Usable DRAM, including remap */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600175 touud = pci_read_config32(dev, TOUUD + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200176 touud <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600177 touud |= pci_read_config32(dev, TOUUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200178
179 /* Top of Lower Usable DRAM */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600180 tolud = pci_read_config32(dev, TOLUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200181
182 /* Top of Memory - does not account for any UMA */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600183 tom = pci_read_config32(dev, TOM + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200184 tom <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600185 tom |= pci_read_config32(dev, TOM);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200186
187 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
188 touud, tolud, tom);
189
Angel Pons7c49cb82020-03-16 23:17:32 +0100190 /* ME UMA needs excluding if total memory < 4GB */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600191 me_base = pci_read_config32(dev, MESEG_BASE + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200192 me_base <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600193 me_base |= pci_read_config32(dev, MESEG_BASE);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200194
195 printk(BIOS_DEBUG, "MEBASE 0x%llx\n", me_base);
196
Patrick Rudolph240766a2015-10-15 15:33:25 +0200197 uma_memory_base = tolud;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200198 tomk = tolud >> 10;
199 if (me_base == tolud) {
200 /* ME is from MEBASE-TOM */
201 uma_size = (tom - me_base) >> 10;
202 /* Increment TOLUD to account for ME as RAM */
203 tolud += uma_size << 10;
204 /* UMA starts at old TOLUD */
205 uma_memory_base = tomk * 1024ULL;
206 uma_memory_size = uma_size * 1024ULL;
207 printk(BIOS_DEBUG, "ME UMA base 0x%llx size %uM\n",
208 me_base, uma_size >> 10);
209 }
210
211 /* Graphics memory comes next */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600212 ggc = pci_read_config16(dev, GGC);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200213 if (!(ggc & 2)) {
214 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
215
216 /* Graphics memory */
217 uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL;
218 printk(BIOS_DEBUG, "%uM UMA", uma_size >> 10);
219 tomk -= uma_size;
220 uma_memory_base = tomk * 1024ULL;
221 uma_memory_size += uma_size * 1024ULL;
222
223 /* GTT Graphics Stolen Memory Size (GGMS) */
224 uma_size = ((ggc >> 8) & 0x3) * 1024ULL;
225 tomk -= uma_size;
226 uma_memory_base = tomk * 1024ULL;
227 uma_memory_size += uma_size * 1024ULL;
228 printk(BIOS_DEBUG, " and %uM GTT\n", uma_size >> 10);
229 }
230
231 /* Calculate TSEG size from its base which must be below GTT */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600232 tseg_base = pci_read_config32(dev, TSEGMB);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200233 uma_size = (uma_memory_base - tseg_base) >> 10;
234 tomk -= uma_size;
235 uma_memory_base = tomk * 1024ULL;
236 uma_memory_size += uma_size * 1024ULL;
Angel Pons7c49cb82020-03-16 23:17:32 +0100237 printk(BIOS_DEBUG, "TSEG base 0x%08x size %uM\n", tseg_base, uma_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200238
239 printk(BIOS_INFO, "Available memory below 4GB: %lluM\n", tomk >> 10);
240
241 /* Report the memory regions */
Angel Pons14ea2fc2020-05-13 21:46:46 +0200242 ram_resource(dev, index++, 0, legacy_hole_base_k);
243 ram_resource(dev, index++, legacy_hole_base_k + legacy_hole_size_k,
244 (tomk - (legacy_hole_base_k + legacy_hole_size_k)));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200245
246 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100247 * If >= 4GB installed, then memory from TOLUD to 4GB is remapped above TOM.
248 * TOUUD will account for both memory chunks.
Stefan Reinauer00636b02012-04-04 00:08:51 +0200249 */
250 touud >>= 10; /* Convert to KB */
251 if (touud > 4096 * 1024) {
Angel Pons14ea2fc2020-05-13 21:46:46 +0200252 ram_resource(dev, index++, 4096 * 1024, touud - (4096 * 1024));
Angel Pons7c49cb82020-03-16 23:17:32 +0100253 printk(BIOS_INFO, "Available memory above 4GB: %lluM\n", (touud >> 10) - 4096);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200254 }
255
Angel Pons14ea2fc2020-05-13 21:46:46 +0200256 add_fixed_resources(dev, index++);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200257}
258
Stefan Reinauer00636b02012-04-04 00:08:51 +0200259static void northbridge_dmi_init(struct device *dev)
260{
261 u32 reg32;
262
263 /* Clear error status bits */
264 DMIBAR32(0x1c4) = 0xffffffff;
265 DMIBAR32(0x1d0) = 0xffffffff;
266
267 /* Steps prior to DMI ASPM */
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700268 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
269 reg32 = DMIBAR32(0x250);
Angel Pons7c49cb82020-03-16 23:17:32 +0100270 reg32 &= ~((1 << 22) | (1 << 20));
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700271 reg32 |= (1 << 21);
272 DMIBAR32(0x250) = reg32;
273 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200274
275 reg32 = DMIBAR32(0x238);
276 reg32 |= (1 << 29);
277 DMIBAR32(0x238) = reg32;
278
279 if (bridge_silicon_revision() >= SNB_STEP_D0) {
280 reg32 = DMIBAR32(0x1f8);
281 reg32 |= (1 << 16);
282 DMIBAR32(0x1f8) = reg32;
Angel Pons7c49cb82020-03-16 23:17:32 +0100283
Stefan Reinauer00636b02012-04-04 00:08:51 +0200284 } else if (bridge_silicon_revision() >= SNB_STEP_D1) {
285 reg32 = DMIBAR32(0x1f8);
286 reg32 &= ~(1 << 26);
287 reg32 |= (1 << 16);
288 DMIBAR32(0x1f8) = reg32;
289
290 reg32 = DMIBAR32(0x1fc);
291 reg32 |= (1 << 12) | (1 << 23);
292 DMIBAR32(0x1fc) = reg32;
293 }
294
295 /* Enable ASPM on SNB link, should happen before PCH link */
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700296 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
297 reg32 = DMIBAR32(0xd04);
298 reg32 |= (1 << 4);
299 DMIBAR32(0xd04) = reg32;
300 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200301
302 reg32 = DMIBAR32(0x88);
303 reg32 |= (1 << 1) | (1 << 0);
304 DMIBAR32(0x88) = reg32;
305}
306
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200307/* Disable unused PEG devices based on devicetree */
308static void disable_peg(void)
309{
310 struct device *dev;
311 u32 reg;
312
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300313 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200314 reg = pci_read_config32(dev, DEVEN);
315
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300316 dev = pcidev_on_root(1, 2);
Nico Huber2dc15e92016-02-04 18:59:48 +0100317 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200318 printk(BIOS_DEBUG, "Disabling PEG12.\n");
319 reg &= ~DEVEN_PEG12;
320 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300321 dev = pcidev_on_root(1, 1);
Nico Huber2dc15e92016-02-04 18:59:48 +0100322 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200323 printk(BIOS_DEBUG, "Disabling PEG11.\n");
324 reg &= ~DEVEN_PEG11;
325 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300326 dev = pcidev_on_root(1, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100327 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200328 printk(BIOS_DEBUG, "Disabling PEG10.\n");
329 reg &= ~DEVEN_PEG10;
330 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300331 dev = pcidev_on_root(2, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100332 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200333 printk(BIOS_DEBUG, "Disabling IGD.\n");
334 reg &= ~DEVEN_IGD;
335 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300336 dev = pcidev_on_root(4, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200337 if (!dev || !dev->enabled) {
338 printk(BIOS_DEBUG, "Disabling Device 4.\n");
339 reg &= ~DEVEN_D4EN;
340 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300341 dev = pcidev_on_root(6, 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 PEG60.\n");
344 reg &= ~DEVEN_PEG60;
345 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300346 dev = pcidev_on_root(7, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200347 if (!dev || !dev->enabled) {
348 printk(BIOS_DEBUG, "Disabling Device 7.\n");
349 reg &= ~DEVEN_D7EN;
350 }
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200351
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300352 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200353 pci_write_config32(dev, DEVEN, reg);
Angel Pons7c49cb82020-03-16 23:17:32 +0100354
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200355 if (!(reg & (DEVEN_PEG60 | DEVEN_PEG10 | DEVEN_PEG11 | DEVEN_PEG12))) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100356 /*
357 * Set the PEG clock gating bit. Disables the IO clock on all PEG devices.
358 *
Angel Pons78b43c82020-03-17 23:55:18 +0100359 * FIXME: Never clock gate on Ivy Bridge stepping A0!
Angel Pons7c49cb82020-03-16 23:17:32 +0100360 */
361 MCHBAR32_OR(PEGCTL, 1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200362 printk(BIOS_DEBUG, "Disabling PEG IO clock.\n");
Angel Pons78b43c82020-03-17 23:55:18 +0100363 } else {
364 MCHBAR32_AND(PEGCTL, ~1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200365 }
366}
367
Stefan Reinauer00636b02012-04-04 00:08:51 +0200368static void northbridge_init(struct device *dev)
369{
370 u8 bios_reset_cpl;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700371 u32 bridge_type;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200372
373 northbridge_dmi_init(dev);
374
Angel Pons88521882020-01-05 20:21:20 +0100375 bridge_type = MCHBAR32(SAPMTIMERS);
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700376 bridge_type &= ~0xff;
377
378 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
379 /* Enable Power Aware Interrupt Routing */
Angel Pons7c49cb82020-03-16 23:17:32 +0100380 u8 pair = MCHBAR8(INTRDIRCTL);
381 pair &= ~0x0f; /* Clear 3:0 */
382 pair |= 0x04; /* Fixed Priority */
383 MCHBAR8(INTRDIRCTL) = pair;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700384
385 /* 30h for IvyBridge */
386 bridge_type |= 0x30;
387 } else {
388 /* 20h for Sandybridge */
389 bridge_type |= 0x20;
390 }
Angel Pons88521882020-01-05 20:21:20 +0100391 MCHBAR32(SAPMTIMERS) = bridge_type;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700392
Angel Pons7c49cb82020-03-16 23:17:32 +0100393 /* Turn off unused devices. Has to be done before setting BIOS_RESET_CPL. */
Patrick Rudolphaad34cd2015-10-21 18:05:01 +0200394 disable_peg();
395
Stefan Reinauer00636b02012-04-04 00:08:51 +0200396 /*
397 * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
398 * that BIOS has initialized memory and power management
399 */
400 bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL);
401 bios_reset_cpl |= 1;
402 MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl;
403 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
404
405 /* Configure turbo power limits 1ms after reset complete bit */
406 mdelay(1);
407 set_power_limits(28);
408
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700409 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100410 * CPUs with configurable TDP also need power limits set in MCHBAR.
411 * Use the same values from MSR_PKG_POWER_LIMIT.
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700412 */
413 if (cpu_config_tdp_levels()) {
414 msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT);
Angel Pons7c49cb82020-03-16 23:17:32 +0100415 MCHBAR32(MCH_PKG_POWER_LIMIT_LO) = msr.lo;
416 MCHBAR32(MCH_PKG_POWER_LIMIT_HI) = msr.hi;
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700417 }
418
Stefan Reinauer00636b02012-04-04 00:08:51 +0200419 /* Set here before graphics PM init */
Angel Pons7c49cb82020-03-16 23:17:32 +0100420 MCHBAR32(PAVP_MSG) = 0x00100001;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200421}
422
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200423void northbridge_write_smram(u8 smram)
424{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300425 pci_write_config8(pcidev_on_root(0, 0), SMRAM, smram);
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200426}
427
Stefan Reinauer00636b02012-04-04 00:08:51 +0200428static struct pci_operations intel_pci_ops = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100429 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200430};
431
432static struct device_operations mc_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200433 .read_resources = mc_read_resources,
434 .set_resources = pci_dev_set_resources,
435 .enable_resources = pci_dev_enable_resources,
436 .init = northbridge_init,
Nico Huber68680dd2020-03-31 17:34:52 +0200437 .ops_pci = &intel_pci_ops,
438 .acpi_fill_ssdt = generate_cpu_entries,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200439};
440
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600441static const unsigned short pci_device_ids[] = {
Jonathan A. Kollaschd346a192020-02-11 09:03:48 -0600442 0x0100, 0x0104, 0x0108, /* Sandy Bridge */
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600443 0x0150, 0x0154, 0x0158, /* Ivy Bridge */
444 0
Walter Murphy496f4a02012-04-23 11:08:03 -0700445};
446
Stefan Reinauer00636b02012-04-04 00:08:51 +0200447static const struct pci_driver mc_driver __pci_driver = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100448 .ops = &mc_ops,
449 .vendor = PCI_VENDOR_ID_INTEL,
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600450 .devices = pci_device_ids,
Vagiz Trakhanov1dd448c2017-09-28 14:42:11 +0000451};
452
Stefan Reinauer00636b02012-04-04 00:08:51 +0200453static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200454 .read_resources = noop_read_resources,
455 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300456 .init = mp_cpu_bus_init,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200457};
458
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100459static void enable_dev(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200460{
461 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800462 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200463 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800464 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200465 dev->ops = &cpu_bus_ops;
466 }
467}
468
469struct chip_operations northbridge_intel_sandybridge_ops = {
Damien Zammit35170382014-10-29 00:11:53 +1100470 CHIP_NAME("Intel SandyBridge/IvyBridge integrated Northbridge")
Stefan Reinauer00636b02012-04-04 00:08:51 +0200471 .enable_dev = enable_dev,
472};