blob: 22743553d9bdd66fd1346112bf58076dff702d89 [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
Julius Wernercd49cce2019-03-05 16:53:33 -080070#if CONFIG(CHROMEOS_RAMOOPS)
Aaron Durbinc9650762013-03-22 22:03:09 -050071 reserved_ram_resource(dev, index++,
72 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
Angel Pons7c49cb82020-03-16 23:17:32 +010073 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +030074#endif
75
Angel Pons964d91f2020-12-07 13:11:17 +010076 if (is_sandybridge()) {
Nico Huber593e7de2015-11-04 15:46:00 +010077 /* Required for SandyBridge sighting 3715511 */
78 bad_ram_resource(dev, index++, 0x20000000 >> 10, 0x00200000 >> 10);
79 bad_ram_resource(dev, index++, 0x40000000 >> 10, 0x00200000 >> 10);
80 }
Nico Huberbb9469c2015-10-21 11:49:23 +020081
82 /* Reserve IOMMU BARs */
Angel Pons7c49cb82020-03-16 23:17:32 +010083 const u32 capid0_a = pci_read_config32(dev, CAPID0_A);
Nico Huberbb9469c2015-10-21 11:49:23 +020084 if (!(capid0_a & (1 << 23))) {
Angel Pons7c49cb82020-03-16 23:17:32 +010085 mmio_resource(dev, index++, GFXVT_BASE >> 10, 4);
86 mmio_resource(dev, index++, VTVC0_BASE >> 10, 4);
Nico Huberbb9469c2015-10-21 11:49:23 +020087 }
Stefan Reinauer00636b02012-04-04 00:08:51 +020088}
89
Aaron Durbin1ca24332020-05-13 11:38:35 -060090static void mc_read_resources(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +020091{
92 uint64_t tom, me_base, touud;
93 uint32_t tseg_base, uma_size, tolud;
94 uint16_t ggc;
95 unsigned long long tomk;
Angel Pons14ea2fc2020-05-13 21:46:46 +020096 unsigned long index = 3;
Stefan Reinauer00636b02012-04-04 00:08:51 +020097
Aaron Durbin1ca24332020-05-13 11:38:35 -060098 pci_dev_read_resources(dev);
99
Angel Pons10f9b832021-01-20 14:58:32 +0100100 mmconf_resource(dev, PCIEXBAR);
Aaron Durbin1ca24332020-05-13 11:38:35 -0600101
Stefan Reinauer00636b02012-04-04 00:08:51 +0200102 /* Total Memory 2GB example:
103 *
104 * 00000000 0000MB-1992MB 1992MB RAM (writeback)
105 * 7c800000 1992MB-2000MB 8MB TSEG (SMRR)
106 * 7d000000 2000MB-2002MB 2MB GFX GTT (uncached)
107 * 7d200000 2002MB-2034MB 32MB GFX UMA (uncached)
108 * 7f200000 2034MB TOLUD
109 * 7f800000 2040MB MEBASE
110 * 7f800000 2040MB-2048MB 8MB ME UMA (uncached)
111 * 80000000 2048MB TOM
112 * 100000000 4096MB-4102MB 6MB RAM (writeback)
113 *
114 * Total Memory 4GB example:
115 *
116 * 00000000 0000MB-2768MB 2768MB RAM (writeback)
117 * ad000000 2768MB-2776MB 8MB TSEG (SMRR)
118 * ad800000 2776MB-2778MB 2MB GFX GTT (uncached)
119 * ada00000 2778MB-2810MB 32MB GFX UMA (uncached)
120 * afa00000 2810MB TOLUD
121 * ff800000 4088MB MEBASE
122 * ff800000 4088MB-4096MB 8MB ME UMA (uncached)
123 * 100000000 4096MB TOM
124 * 100000000 4096MB-5374MB 1278MB RAM (writeback)
125 * 14fe00000 5368MB TOUUD
126 */
127
128 /* Top of Upper Usable DRAM, including remap */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600129 touud = pci_read_config32(dev, TOUUD + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200130 touud <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600131 touud |= pci_read_config32(dev, TOUUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200132
133 /* Top of Lower Usable DRAM */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600134 tolud = pci_read_config32(dev, TOLUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200135
136 /* Top of Memory - does not account for any UMA */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600137 tom = pci_read_config32(dev, TOM + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200138 tom <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600139 tom |= pci_read_config32(dev, TOM);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200140
141 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
142 touud, tolud, tom);
143
Angel Pons7c49cb82020-03-16 23:17:32 +0100144 /* ME UMA needs excluding if total memory < 4GB */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600145 me_base = pci_read_config32(dev, MESEG_BASE + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200146 me_base <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600147 me_base |= pci_read_config32(dev, MESEG_BASE);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200148
149 printk(BIOS_DEBUG, "MEBASE 0x%llx\n", me_base);
150
Patrick Rudolph240766a2015-10-15 15:33:25 +0200151 uma_memory_base = tolud;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200152 tomk = tolud >> 10;
153 if (me_base == tolud) {
154 /* ME is from MEBASE-TOM */
155 uma_size = (tom - me_base) >> 10;
156 /* Increment TOLUD to account for ME as RAM */
157 tolud += uma_size << 10;
158 /* UMA starts at old TOLUD */
159 uma_memory_base = tomk * 1024ULL;
160 uma_memory_size = uma_size * 1024ULL;
161 printk(BIOS_DEBUG, "ME UMA base 0x%llx size %uM\n",
162 me_base, uma_size >> 10);
163 }
164
165 /* Graphics memory comes next */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600166 ggc = pci_read_config16(dev, GGC);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200167 if (!(ggc & 2)) {
168 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
169
170 /* Graphics memory */
171 uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL;
172 printk(BIOS_DEBUG, "%uM UMA", uma_size >> 10);
173 tomk -= uma_size;
174 uma_memory_base = tomk * 1024ULL;
175 uma_memory_size += uma_size * 1024ULL;
176
177 /* GTT Graphics Stolen Memory Size (GGMS) */
178 uma_size = ((ggc >> 8) & 0x3) * 1024ULL;
179 tomk -= uma_size;
180 uma_memory_base = tomk * 1024ULL;
181 uma_memory_size += uma_size * 1024ULL;
182 printk(BIOS_DEBUG, " and %uM GTT\n", uma_size >> 10);
183 }
184
185 /* Calculate TSEG size from its base which must be below GTT */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600186 tseg_base = pci_read_config32(dev, TSEGMB);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200187 uma_size = (uma_memory_base - tseg_base) >> 10;
188 tomk -= uma_size;
189 uma_memory_base = tomk * 1024ULL;
190 uma_memory_size += uma_size * 1024ULL;
Angel Pons7c49cb82020-03-16 23:17:32 +0100191 printk(BIOS_DEBUG, "TSEG base 0x%08x size %uM\n", tseg_base, uma_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200192
193 printk(BIOS_INFO, "Available memory below 4GB: %lluM\n", tomk >> 10);
194
195 /* Report the memory regions */
Angel Pons14ea2fc2020-05-13 21:46:46 +0200196 ram_resource(dev, index++, 0, legacy_hole_base_k);
197 ram_resource(dev, index++, legacy_hole_base_k + legacy_hole_size_k,
198 (tomk - (legacy_hole_base_k + legacy_hole_size_k)));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200199
200 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100201 * If >= 4GB installed, then memory from TOLUD to 4GB is remapped above TOM.
202 * TOUUD will account for both memory chunks.
Stefan Reinauer00636b02012-04-04 00:08:51 +0200203 */
204 touud >>= 10; /* Convert to KB */
205 if (touud > 4096 * 1024) {
Angel Pons14ea2fc2020-05-13 21:46:46 +0200206 ram_resource(dev, index++, 4096 * 1024, touud - (4096 * 1024));
Angel Pons7c49cb82020-03-16 23:17:32 +0100207 printk(BIOS_INFO, "Available memory above 4GB: %lluM\n", (touud >> 10) - 4096);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200208 }
209
Angel Pons14ea2fc2020-05-13 21:46:46 +0200210 add_fixed_resources(dev, index++);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200211}
212
Stefan Reinauer00636b02012-04-04 00:08:51 +0200213static void northbridge_dmi_init(struct device *dev)
214{
Angel Pons964d91f2020-12-07 13:11:17 +0100215 const bool is_sandy = is_sandybridge();
216
Angel Pons77516ca2020-12-10 16:43:25 +0100217 const u8 stepping = cpu_stepping();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200218
Angel Pons77516ca2020-12-10 16:43:25 +0100219 u32 reg32;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200220
221 /* Steps prior to DMI ASPM */
Angel Pons964d91f2020-12-07 13:11:17 +0100222 if (is_sandy) {
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700223 reg32 = DMIBAR32(0x250);
Angel Pons77516ca2020-12-10 16:43:25 +0100224 reg32 &= ~(7 << 20);
225 reg32 |= (2 << 20);
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700226 DMIBAR32(0x250) = reg32;
227 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200228
Angel Ponsf950a7e2020-09-14 17:15:37 +0200229 reg32 = DMIBAR32(DMILLTC);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200230 reg32 |= (1 << 29);
Angel Ponsf950a7e2020-09-14 17:15:37 +0200231 DMIBAR32(DMILLTC) = reg32;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200232
Angel Pons77516ca2020-12-10 16:43:25 +0100233 if (is_sandy && stepping == SNB_STEP_C0) {
234 reg32 = DMIBAR32(0xbc8);
235 reg32 &= ~(0xfff << 7);
236 reg32 |= (0x7d3 << 7);
237 DMIBAR32(0xbc8) = reg32;
238 }
Angel Pons7c49cb82020-03-16 23:17:32 +0100239
Angel Pons77516ca2020-12-10 16:43:25 +0100240 if (!is_sandy || stepping >= SNB_STEP_D1) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200241 reg32 = DMIBAR32(0x1f8);
242 reg32 &= ~(1 << 26);
243 reg32 |= (1 << 16);
244 DMIBAR32(0x1f8) = reg32;
245
246 reg32 = DMIBAR32(0x1fc);
247 reg32 |= (1 << 12) | (1 << 23);
248 DMIBAR32(0x1fc) = reg32;
Angel Pons77516ca2020-12-10 16:43:25 +0100249
250 } else if (stepping >= SNB_STEP_D0) {
251 reg32 = DMIBAR32(0x1f8);
252 reg32 |= (1 << 16);
253 DMIBAR32(0x1f8) = reg32;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200254 }
255
Angel Pons77516ca2020-12-10 16:43:25 +0100256 /* Clear error status bits */
257 DMIBAR32(DMIUESTS) = 0xffffffff;
258 DMIBAR32(DMICESTS) = 0xffffffff;
259
260 if (!is_sandy)
261 DMIBAR32(0xc34) = 0xffffffff;
262
Stefan Reinauer00636b02012-04-04 00:08:51 +0200263 /* Enable ASPM on SNB link, should happen before PCH link */
Angel Pons964d91f2020-12-07 13:11:17 +0100264 if (is_sandy) {
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700265 reg32 = DMIBAR32(0xd04);
266 reg32 |= (1 << 4);
267 DMIBAR32(0xd04) = reg32;
268 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200269
Angel Ponsf950a7e2020-09-14 17:15:37 +0200270 reg32 = DMIBAR32(DMILCTL);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200271 reg32 |= (1 << 1) | (1 << 0);
Angel Ponsf950a7e2020-09-14 17:15:37 +0200272 DMIBAR32(DMILCTL) = reg32;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200273}
274
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200275/* Disable unused PEG devices based on devicetree */
276static void disable_peg(void)
277{
278 struct device *dev;
279 u32 reg;
280
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300281 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200282 reg = pci_read_config32(dev, DEVEN);
283
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300284 dev = pcidev_on_root(1, 2);
Nico Huber2dc15e92016-02-04 18:59:48 +0100285 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200286 printk(BIOS_DEBUG, "Disabling PEG12.\n");
287 reg &= ~DEVEN_PEG12;
288 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300289 dev = pcidev_on_root(1, 1);
Nico Huber2dc15e92016-02-04 18:59:48 +0100290 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200291 printk(BIOS_DEBUG, "Disabling PEG11.\n");
292 reg &= ~DEVEN_PEG11;
293 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300294 dev = pcidev_on_root(1, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100295 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200296 printk(BIOS_DEBUG, "Disabling PEG10.\n");
297 reg &= ~DEVEN_PEG10;
298 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300299 dev = pcidev_on_root(2, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100300 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200301 printk(BIOS_DEBUG, "Disabling IGD.\n");
302 reg &= ~DEVEN_IGD;
303 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300304 dev = pcidev_on_root(4, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200305 if (!dev || !dev->enabled) {
306 printk(BIOS_DEBUG, "Disabling Device 4.\n");
307 reg &= ~DEVEN_D4EN;
308 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300309 dev = pcidev_on_root(6, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100310 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200311 printk(BIOS_DEBUG, "Disabling PEG60.\n");
312 reg &= ~DEVEN_PEG60;
313 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300314 dev = pcidev_on_root(7, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200315 if (!dev || !dev->enabled) {
316 printk(BIOS_DEBUG, "Disabling Device 7.\n");
317 reg &= ~DEVEN_D7EN;
318 }
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200319
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300320 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200321 pci_write_config32(dev, DEVEN, reg);
Angel Pons7c49cb82020-03-16 23:17:32 +0100322
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200323 if (!(reg & (DEVEN_PEG60 | DEVEN_PEG10 | DEVEN_PEG11 | DEVEN_PEG12))) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100324 /*
325 * Set the PEG clock gating bit. Disables the IO clock on all PEG devices.
326 *
Angel Pons78b43c82020-03-17 23:55:18 +0100327 * FIXME: Never clock gate on Ivy Bridge stepping A0!
Angel Pons7c49cb82020-03-16 23:17:32 +0100328 */
329 MCHBAR32_OR(PEGCTL, 1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200330 printk(BIOS_DEBUG, "Disabling PEG IO clock.\n");
Angel Pons78b43c82020-03-17 23:55:18 +0100331 } else {
332 MCHBAR32_AND(PEGCTL, ~1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200333 }
334}
335
Stefan Reinauer00636b02012-04-04 00:08:51 +0200336static void northbridge_init(struct device *dev)
337{
338 u8 bios_reset_cpl;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700339 u32 bridge_type;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200340
341 northbridge_dmi_init(dev);
342
Angel Pons88521882020-01-05 20:21:20 +0100343 bridge_type = MCHBAR32(SAPMTIMERS);
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700344 bridge_type &= ~0xff;
345
Angel Pons964d91f2020-12-07 13:11:17 +0100346 if (is_sandybridge()) {
347 /* 20h for Sandybridge */
348 bridge_type |= 0x20;
349 } else {
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700350 /* Enable Power Aware Interrupt Routing */
Angel Pons7c49cb82020-03-16 23:17:32 +0100351 u8 pair = MCHBAR8(INTRDIRCTL);
352 pair &= ~0x0f; /* Clear 3:0 */
353 pair |= 0x04; /* Fixed Priority */
354 MCHBAR8(INTRDIRCTL) = pair;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700355
356 /* 30h for IvyBridge */
357 bridge_type |= 0x30;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700358 }
Angel Pons88521882020-01-05 20:21:20 +0100359 MCHBAR32(SAPMTIMERS) = bridge_type;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700360
Angel Pons7c49cb82020-03-16 23:17:32 +0100361 /* Turn off unused devices. Has to be done before setting BIOS_RESET_CPL. */
Patrick Rudolphaad34cd2015-10-21 18:05:01 +0200362 disable_peg();
363
Stefan Reinauer00636b02012-04-04 00:08:51 +0200364 /*
365 * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
366 * that BIOS has initialized memory and power management
367 */
368 bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL);
369 bios_reset_cpl |= 1;
370 MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl;
371 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
372
373 /* Configure turbo power limits 1ms after reset complete bit */
374 mdelay(1);
375 set_power_limits(28);
376
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700377 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100378 * CPUs with configurable TDP also need power limits set in MCHBAR.
379 * Use the same values from MSR_PKG_POWER_LIMIT.
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700380 */
381 if (cpu_config_tdp_levels()) {
382 msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT);
Angel Pons7c49cb82020-03-16 23:17:32 +0100383 MCHBAR32(MCH_PKG_POWER_LIMIT_LO) = msr.lo;
384 MCHBAR32(MCH_PKG_POWER_LIMIT_HI) = msr.hi;
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700385 }
386
Stefan Reinauer00636b02012-04-04 00:08:51 +0200387 /* Set here before graphics PM init */
Angel Pons7c49cb82020-03-16 23:17:32 +0100388 MCHBAR32(PAVP_MSG) = 0x00100001;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200389}
390
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200391void northbridge_write_smram(u8 smram)
392{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300393 pci_write_config8(pcidev_on_root(0, 0), SMRAM, smram);
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200394}
395
Stefan Reinauer00636b02012-04-04 00:08:51 +0200396static struct device_operations mc_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200397 .read_resources = mc_read_resources,
398 .set_resources = pci_dev_set_resources,
399 .enable_resources = pci_dev_enable_resources,
400 .init = northbridge_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200401 .ops_pci = &pci_dev_ops_pci,
Nico Huber68680dd2020-03-31 17:34:52 +0200402 .acpi_fill_ssdt = generate_cpu_entries,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200403};
404
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600405static const unsigned short pci_device_ids[] = {
Jonathan A. Kollaschd346a192020-02-11 09:03:48 -0600406 0x0100, 0x0104, 0x0108, /* Sandy Bridge */
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600407 0x0150, 0x0154, 0x0158, /* Ivy Bridge */
408 0
Walter Murphy496f4a02012-04-23 11:08:03 -0700409};
410
Stefan Reinauer00636b02012-04-04 00:08:51 +0200411static const struct pci_driver mc_driver __pci_driver = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100412 .ops = &mc_ops,
413 .vendor = PCI_VENDOR_ID_INTEL,
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600414 .devices = pci_device_ids,
Vagiz Trakhanov1dd448c2017-09-28 14:42:11 +0000415};
416
Stefan Reinauer00636b02012-04-04 00:08:51 +0200417static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200418 .read_resources = noop_read_resources,
419 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300420 .init = mp_cpu_bus_init,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200421};
422
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100423static void enable_dev(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200424{
425 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800426 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200427 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800428 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200429 dev->ops = &cpu_bus_ops;
430 }
431}
432
433struct chip_operations northbridge_intel_sandybridge_ops = {
Damien Zammit35170382014-10-29 00:11:53 +1100434 CHIP_NAME("Intel SandyBridge/IvyBridge integrated Northbridge")
Stefan Reinauer00636b02012-04-04 00:08:51 +0200435 .enable_dev = enable_dev,
436};