blob: 68f8411366f2c06d4486f9979825264764e02fa2 [file] [log] [blame]
Stefan Reinauer00636b02012-04-04 00:08:51 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2009 coresystems GmbH
5 * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
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 Reinauer00636b02012-04-04 00:08:51 +020015 */
16
17#include <console/console.h>
18#include <arch/acpi.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020019#include <device/pci_ops.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020020#include <stdint.h>
21#include <delay.h>
22#include <cpu/intel/model_206ax/model_206ax.h>
Duncan Laurie77dbbac2012-06-25 09:51:59 -070023#include <cpu/x86/msr.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020024#include <device/device.h>
25#include <device/pci.h>
26#include <device/pci_ids.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020027#include "chip.h"
28#include "sandybridge.h"
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030029#include <cpu/intel/smm_reloc.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020030
31static int bridge_revision_id = -1;
32
Kyösti Mälkkif7bfc342013-10-18 11:02:46 +030033/* IGD UMA memory */
34static uint64_t uma_memory_base = 0;
35static uint64_t uma_memory_size = 0;
36
Stefan Reinauer00636b02012-04-04 00:08:51 +020037int bridge_silicon_revision(void)
38{
39 if (bridge_revision_id < 0) {
40 uint8_t stepping = cpuid_eax(1) & 0xf;
41 uint8_t bridge_id = pci_read_config16(
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030042 pcidev_on_root(0, 0),
Stefan Reinauer00636b02012-04-04 00:08:51 +020043 PCI_DEVICE_ID) & 0xf0;
44 bridge_revision_id = bridge_id | stepping;
45 }
46 return bridge_revision_id;
47}
48
49/* Reserve everything between A segment and 1MB:
50 *
51 * 0xa0000 - 0xbffff: legacy VGA
52 * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel)
53 * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI
54 */
55static const int legacy_hole_base_k = 0xa0000 / 1024;
56static const int legacy_hole_size_k = 384;
57
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020058static int get_pcie_bar(u32 *base)
Stefan Reinauer00636b02012-04-04 00:08:51 +020059{
Elyes HAOUASab8743c2018-02-09 08:21:40 +010060 struct device *dev;
Stefan Reinauer00636b02012-04-04 00:08:51 +020061 u32 pciexbar_reg;
62
63 *base = 0;
Stefan Reinauer00636b02012-04-04 00:08:51 +020064
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030065 dev = pcidev_on_root(0, 0);
Stefan Reinauer00636b02012-04-04 00:08:51 +020066 if (!dev)
67 return 0;
68
69 pciexbar_reg = pci_read_config32(dev, PCIEXBAR);
70
71 if (!(pciexbar_reg & (1 << 0)))
72 return 0;
73
74 switch ((pciexbar_reg >> 1) & 3) {
75 case 0: // 256MB
76 *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28));
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020077 return 256;
Stefan Reinauer00636b02012-04-04 00:08:51 +020078 case 1: // 128M
79 *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020080 return 128;
Stefan Reinauer00636b02012-04-04 00:08:51 +020081 case 2: // 64M
82 *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26));
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020083 return 64;
Stefan Reinauer00636b02012-04-04 00:08:51 +020084 }
85
86 return 0;
87}
88
Stefan Reinauer00636b02012-04-04 00:08:51 +020089static void add_fixed_resources(struct device *dev, int index)
90{
Kyösti Mälkki7f189cc2012-07-27 13:12:03 +030091 mmio_resource(dev, index++, uma_memory_base >> 10, uma_memory_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +020092
Aaron Durbinc9650762013-03-22 22:03:09 -050093 mmio_resource(dev, index++, legacy_hole_base_k,
94 (0xc0000 >> 10) - legacy_hole_base_k);
95 reserved_ram_resource(dev, index++, 0xc0000 >> 10,
96 (0x100000 - 0xc0000) >> 10);
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +030097
Julius Wernercd49cce2019-03-05 16:53:33 -080098#if CONFIG(CHROMEOS_RAMOOPS)
Aaron Durbinc9650762013-03-22 22:03:09 -050099 reserved_ram_resource(dev, index++,
100 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +0300101 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
102#endif
103
Nico Huber593e7de2015-11-04 15:46:00 +0100104 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
105 /* Required for SandyBridge sighting 3715511 */
106 bad_ram_resource(dev, index++, 0x20000000 >> 10, 0x00200000 >> 10);
107 bad_ram_resource(dev, index++, 0x40000000 >> 10, 0x00200000 >> 10);
108 }
Nico Huberbb9469c2015-10-21 11:49:23 +0200109
110 /* Reserve IOMMU BARs */
111 const u32 capid0_a = pci_read_config32(dev, 0xe4);
112 if (!(capid0_a & (1 << 23))) {
113 mmio_resource(dev, index++, IOMMU_BASE1 >> 10, 4);
114 mmio_resource(dev, index++, IOMMU_BASE2 >> 10, 4);
115 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200116}
117
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100118static void pci_domain_set_resources(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200119{
120 uint64_t tom, me_base, touud;
121 uint32_t tseg_base, uma_size, tolud;
122 uint16_t ggc;
123 unsigned long long tomk;
124
125 /* Total Memory 2GB example:
126 *
127 * 00000000 0000MB-1992MB 1992MB RAM (writeback)
128 * 7c800000 1992MB-2000MB 8MB TSEG (SMRR)
129 * 7d000000 2000MB-2002MB 2MB GFX GTT (uncached)
130 * 7d200000 2002MB-2034MB 32MB GFX UMA (uncached)
131 * 7f200000 2034MB TOLUD
132 * 7f800000 2040MB MEBASE
133 * 7f800000 2040MB-2048MB 8MB ME UMA (uncached)
134 * 80000000 2048MB TOM
135 * 100000000 4096MB-4102MB 6MB RAM (writeback)
136 *
137 * Total Memory 4GB example:
138 *
139 * 00000000 0000MB-2768MB 2768MB RAM (writeback)
140 * ad000000 2768MB-2776MB 8MB TSEG (SMRR)
141 * ad800000 2776MB-2778MB 2MB GFX GTT (uncached)
142 * ada00000 2778MB-2810MB 32MB GFX UMA (uncached)
143 * afa00000 2810MB TOLUD
144 * ff800000 4088MB MEBASE
145 * ff800000 4088MB-4096MB 8MB ME UMA (uncached)
146 * 100000000 4096MB TOM
147 * 100000000 4096MB-5374MB 1278MB RAM (writeback)
148 * 14fe00000 5368MB TOUUD
149 */
150
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300151 struct device *mch = pcidev_on_root(0, 0);
Arthur Heymans17041202018-06-26 21:06:25 +0200152
Stefan Reinauer00636b02012-04-04 00:08:51 +0200153 /* Top of Upper Usable DRAM, including remap */
Arthur Heymans17041202018-06-26 21:06:25 +0200154 touud = pci_read_config32(mch, TOUUD+4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200155 touud <<= 32;
Arthur Heymans17041202018-06-26 21:06:25 +0200156 touud |= pci_read_config32(mch, TOUUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200157
158 /* Top of Lower Usable DRAM */
Arthur Heymans17041202018-06-26 21:06:25 +0200159 tolud = pci_read_config32(mch, TOLUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200160
161 /* Top of Memory - does not account for any UMA */
Arthur Heymans17041202018-06-26 21:06:25 +0200162 tom = pci_read_config32(mch, 0xa4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200163 tom <<= 32;
Arthur Heymans17041202018-06-26 21:06:25 +0200164 tom |= pci_read_config32(mch, 0xa0);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200165
166 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
167 touud, tolud, tom);
168
169 /* ME UMA needs excluding if total memory <4GB */
Arthur Heymans17041202018-06-26 21:06:25 +0200170 me_base = pci_read_config32(mch, 0x74);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200171 me_base <<= 32;
Arthur Heymans17041202018-06-26 21:06:25 +0200172 me_base |= pci_read_config32(mch, 0x70);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200173
174 printk(BIOS_DEBUG, "MEBASE 0x%llx\n", me_base);
175
Patrick Rudolph240766a2015-10-15 15:33:25 +0200176 uma_memory_base = tolud;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200177 tomk = tolud >> 10;
178 if (me_base == tolud) {
179 /* ME is from MEBASE-TOM */
180 uma_size = (tom - me_base) >> 10;
181 /* Increment TOLUD to account for ME as RAM */
182 tolud += uma_size << 10;
183 /* UMA starts at old TOLUD */
184 uma_memory_base = tomk * 1024ULL;
185 uma_memory_size = uma_size * 1024ULL;
186 printk(BIOS_DEBUG, "ME UMA base 0x%llx size %uM\n",
187 me_base, uma_size >> 10);
188 }
189
190 /* Graphics memory comes next */
Arthur Heymans17041202018-06-26 21:06:25 +0200191 ggc = pci_read_config16(mch, GGC);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200192 if (!(ggc & 2)) {
193 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
194
195 /* Graphics memory */
196 uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL;
197 printk(BIOS_DEBUG, "%uM UMA", uma_size >> 10);
198 tomk -= uma_size;
199 uma_memory_base = tomk * 1024ULL;
200 uma_memory_size += uma_size * 1024ULL;
201
202 /* GTT Graphics Stolen Memory Size (GGMS) */
203 uma_size = ((ggc >> 8) & 0x3) * 1024ULL;
204 tomk -= uma_size;
205 uma_memory_base = tomk * 1024ULL;
206 uma_memory_size += uma_size * 1024ULL;
207 printk(BIOS_DEBUG, " and %uM GTT\n", uma_size >> 10);
208 }
209
210 /* Calculate TSEG size from its base which must be below GTT */
Arthur Heymans17041202018-06-26 21:06:25 +0200211 tseg_base = pci_read_config32(mch, 0xb8);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200212 uma_size = (uma_memory_base - tseg_base) >> 10;
213 tomk -= uma_size;
214 uma_memory_base = tomk * 1024ULL;
215 uma_memory_size += uma_size * 1024ULL;
216 printk(BIOS_DEBUG, "TSEG base 0x%08x size %uM\n",
217 tseg_base, uma_size >> 10);
218
219 printk(BIOS_INFO, "Available memory below 4GB: %lluM\n", tomk >> 10);
220
221 /* Report the memory regions */
222 ram_resource(dev, 3, 0, legacy_hole_base_k);
223 ram_resource(dev, 4, legacy_hole_base_k + legacy_hole_size_k,
224 (tomk - (legacy_hole_base_k + legacy_hole_size_k)));
225
226 /*
227 * If >= 4GB installed then memory from TOLUD to 4GB
228 * is remapped above TOM, TOUUD will account for both
229 */
230 touud >>= 10; /* Convert to KB */
231 if (touud > 4096 * 1024) {
232 ram_resource(dev, 5, 4096 * 1024, touud - (4096 * 1024));
233 printk(BIOS_INFO, "Available memory above 4GB: %lluM\n",
234 (touud >> 10) - 4096);
235 }
236
237 add_fixed_resources(dev, 6);
238
239 assign_resources(dev->link_list);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200240}
241
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600242static const char *northbridge_acpi_name(const struct device *dev)
Patrick Rudolph3e47fc92017-06-07 09:44:07 +0200243{
244 if (dev->path.type == DEVICE_PATH_DOMAIN)
245 return "PCI0";
246
247 if (dev->path.type != DEVICE_PATH_PCI)
248 return NULL;
249
250 switch (dev->path.pci.devfn) {
251 case PCI_DEVFN(0, 0):
252 return "MCHC";
253 }
254
255 return NULL;
256}
257
Stefan Reinauer00636b02012-04-04 00:08:51 +0200258 /* TODO We could determine how many PCIe busses we need in
259 * the bar. For now that number is hardcoded to a max of 64.
Stefan Reinauer00636b02012-04-04 00:08:51 +0200260 */
261static struct device_operations pci_domain_ops = {
262 .read_resources = pci_domain_read_resources,
263 .set_resources = pci_domain_set_resources,
264 .enable_resources = NULL,
265 .init = NULL,
266 .scan_bus = pci_domain_scan_bus,
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100267 .write_acpi_tables = northbridge_write_acpi_tables,
Patrick Rudolph3e47fc92017-06-07 09:44:07 +0200268 .acpi_name = northbridge_acpi_name,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200269};
270
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100271static void mc_read_resources(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200272{
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200273 u32 pcie_config_base;
274 int buses;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200275
276 pci_dev_read_resources(dev);
277
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200278 buses = get_pcie_bar(&pcie_config_base);
279 if (buses) {
Kyösti Mälkki27198ac2016-12-02 14:38:13 +0200280 struct resource *resource = new_resource(dev, PCIEXBAR);
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200281 mmconf_resource_init(resource, pcie_config_base, buses);
282 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200283}
284
Stefan Reinauer00636b02012-04-04 00:08:51 +0200285static void northbridge_dmi_init(struct device *dev)
286{
287 u32 reg32;
288
289 /* Clear error status bits */
290 DMIBAR32(0x1c4) = 0xffffffff;
291 DMIBAR32(0x1d0) = 0xffffffff;
292
293 /* Steps prior to DMI ASPM */
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700294 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
295 reg32 = DMIBAR32(0x250);
296 reg32 &= ~((1 << 22)|(1 << 20));
297 reg32 |= (1 << 21);
298 DMIBAR32(0x250) = reg32;
299 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200300
301 reg32 = DMIBAR32(0x238);
302 reg32 |= (1 << 29);
303 DMIBAR32(0x238) = reg32;
304
305 if (bridge_silicon_revision() >= SNB_STEP_D0) {
306 reg32 = DMIBAR32(0x1f8);
307 reg32 |= (1 << 16);
308 DMIBAR32(0x1f8) = reg32;
309 } else if (bridge_silicon_revision() >= SNB_STEP_D1) {
310 reg32 = DMIBAR32(0x1f8);
311 reg32 &= ~(1 << 26);
312 reg32 |= (1 << 16);
313 DMIBAR32(0x1f8) = reg32;
314
315 reg32 = DMIBAR32(0x1fc);
316 reg32 |= (1 << 12) | (1 << 23);
317 DMIBAR32(0x1fc) = reg32;
318 }
319
320 /* Enable ASPM on SNB link, should happen before PCH link */
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700321 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
322 reg32 = DMIBAR32(0xd04);
323 reg32 |= (1 << 4);
324 DMIBAR32(0xd04) = reg32;
325 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200326
327 reg32 = DMIBAR32(0x88);
328 reg32 |= (1 << 1) | (1 << 0);
329 DMIBAR32(0x88) = reg32;
330}
331
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200332/* Disable unused PEG devices based on devicetree */
333static void disable_peg(void)
334{
335 struct device *dev;
336 u32 reg;
337
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300338 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200339 reg = pci_read_config32(dev, DEVEN);
340
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300341 dev = pcidev_on_root(1, 2);
Nico Huber2dc15e92016-02-04 18:59:48 +0100342 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200343 printk(BIOS_DEBUG, "Disabling PEG12.\n");
344 reg &= ~DEVEN_PEG12;
345 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300346 dev = pcidev_on_root(1, 1);
Nico Huber2dc15e92016-02-04 18:59:48 +0100347 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200348 printk(BIOS_DEBUG, "Disabling PEG11.\n");
349 reg &= ~DEVEN_PEG11;
350 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300351 dev = pcidev_on_root(1, 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 PEG10.\n");
354 reg &= ~DEVEN_PEG10;
355 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300356 dev = pcidev_on_root(2, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100357 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200358 printk(BIOS_DEBUG, "Disabling IGD.\n");
359 reg &= ~DEVEN_IGD;
360 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300361 dev = pcidev_on_root(4, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200362 if (!dev || !dev->enabled) {
363 printk(BIOS_DEBUG, "Disabling Device 4.\n");
364 reg &= ~DEVEN_D4EN;
365 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300366 dev = pcidev_on_root(6, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100367 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200368 printk(BIOS_DEBUG, "Disabling PEG60.\n");
369 reg &= ~DEVEN_PEG60;
370 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300371 dev = pcidev_on_root(7, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200372 if (!dev || !dev->enabled) {
373 printk(BIOS_DEBUG, "Disabling Device 7.\n");
374 reg &= ~DEVEN_D7EN;
375 }
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200376
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300377 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200378 pci_write_config32(dev, DEVEN, reg);
379 if (!(reg & (DEVEN_PEG60 | DEVEN_PEG10 | DEVEN_PEG11 | DEVEN_PEG12))) {
380 /* Set the PEG clock gating bit.
381 * Disables the IO clock on all PEG devices. */
382 MCHBAR32(0x7010) = MCHBAR32(0x7010) | 0x01;
383 printk(BIOS_DEBUG, "Disabling PEG IO clock.\n");
384 }
385}
386
Stefan Reinauer00636b02012-04-04 00:08:51 +0200387static void northbridge_init(struct device *dev)
388{
389 u8 bios_reset_cpl;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700390 u32 bridge_type;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200391
392 northbridge_dmi_init(dev);
393
Angel Pons88521882020-01-05 20:21:20 +0100394 bridge_type = MCHBAR32(SAPMTIMERS);
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700395 bridge_type &= ~0xff;
396
397 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
398 /* Enable Power Aware Interrupt Routing */
Angel Pons88521882020-01-05 20:21:20 +0100399 u8 pair = MCHBAR8(PAIR_CTL);
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700400 pair &= ~0xf; /* Clear 3:0 */
401 pair |= 0x4; /* Fixed Priority */
Angel Pons88521882020-01-05 20:21:20 +0100402 MCHBAR8(PAIR_CTL) = pair;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700403
404 /* 30h for IvyBridge */
405 bridge_type |= 0x30;
406 } else {
407 /* 20h for Sandybridge */
408 bridge_type |= 0x20;
409 }
Angel Pons88521882020-01-05 20:21:20 +0100410 MCHBAR32(SAPMTIMERS) = bridge_type;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700411
Patrick Rudolphaad34cd2015-10-21 18:05:01 +0200412 /* Turn off unused devices. Has to be done before
413 * setting BIOS_RESET_CPL.
414 */
415 disable_peg();
416
Stefan Reinauer00636b02012-04-04 00:08:51 +0200417 /*
418 * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
419 * that BIOS has initialized memory and power management
420 */
421 bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL);
422 bios_reset_cpl |= 1;
423 MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl;
424 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
425
426 /* Configure turbo power limits 1ms after reset complete bit */
427 mdelay(1);
428 set_power_limits(28);
429
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700430 /*
431 * CPUs with configurable TDP also need power limits set
432 * in MCHBAR. Use same values from MSR_PKG_POWER_LIMIT.
433 */
434 if (cpu_config_tdp_levels()) {
435 msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT);
Angel Pons88521882020-01-05 20:21:20 +0100436 MCHBAR32(MC_TURBO_PL1) = msr.lo;
437 MCHBAR32(MC_TURBO_PL2) = msr.hi;
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700438 }
439
Stefan Reinauer00636b02012-04-04 00:08:51 +0200440 /* Set here before graphics PM init */
Angel Pons88521882020-01-05 20:21:20 +0100441 MCHBAR32(MMIO_PAVP_CTL) = 0x00100001;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200442}
443
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200444void northbridge_write_smram(u8 smram)
445{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300446 pci_write_config8(pcidev_on_root(0, 0), SMRAM, smram);
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200447}
448
Stefan Reinauer00636b02012-04-04 00:08:51 +0200449static struct pci_operations intel_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530450 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200451};
452
453static struct device_operations mc_ops = {
454 .read_resources = mc_read_resources,
Kyösti Mälkki27198ac2016-12-02 14:38:13 +0200455 .set_resources = pci_dev_set_resources,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200456 .enable_resources = pci_dev_enable_resources,
457 .init = northbridge_init,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200458 .scan_bus = 0,
459 .ops_pci = &intel_pci_ops,
Vladimir Serbinenko0a669912014-10-05 14:34:17 +0200460 .acpi_fill_ssdt_generator = generate_cpu_entries,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200461};
462
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600463static const unsigned short pci_device_ids[] = {
464 0x0100, 0x0104, /* Sandy Bridge */
465 0x0150, 0x0154, 0x0158, /* Ivy Bridge */
466 0
Walter Murphy496f4a02012-04-23 11:08:03 -0700467};
468
Stefan Reinauer00636b02012-04-04 00:08:51 +0200469static const struct pci_driver mc_driver __pci_driver = {
470 .ops = &mc_ops,
471 .vendor = PCI_VENDOR_ID_INTEL,
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600472 .devices = pci_device_ids,
Vagiz Trakhanov1dd448c2017-09-28 14:42:11 +0000473};
474
Stefan Reinauer00636b02012-04-04 00:08:51 +0200475static struct device_operations cpu_bus_ops = {
Edward O'Callaghan9f744622014-10-31 08:12:34 +1100476 .read_resources = DEVICE_NOOP,
477 .set_resources = DEVICE_NOOP,
478 .enable_resources = DEVICE_NOOP,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300479 .init = mp_cpu_bus_init,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200480 .scan_bus = 0,
481};
482
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100483static void enable_dev(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200484{
485 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800486 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200487 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800488 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200489 dev->ops = &cpu_bus_ops;
490 }
491}
492
493struct chip_operations northbridge_intel_sandybridge_ops = {
Damien Zammit35170382014-10-29 00:11:53 +1100494 CHIP_NAME("Intel SandyBridge/IvyBridge integrated Northbridge")
Stefan Reinauer00636b02012-04-04 00:08:51 +0200495 .enable_dev = enable_dev,
496};