blob: 4d87878fa24513250c8f37ba143575d7eeddb9f7 [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
Angel Pons8bf19762020-08-03 14:55:18 +020038int decode_pcie_bar(u32 *const base, u32 *const len)
Stefan Reinauer00636b02012-04-04 00:08:51 +020039{
Stefan Reinauer00636b02012-04-04 00:08:51 +020040 *base = 0;
Angel Pons20905cf2020-08-03 14:18:41 +020041 *len = 0;
Stefan Reinauer00636b02012-04-04 00:08:51 +020042
Angel Pons20905cf2020-08-03 14:18:41 +020043 struct device *dev = pcidev_on_root(0, 0);
Stefan Reinauer00636b02012-04-04 00:08:51 +020044 if (!dev)
45 return 0;
46
Angel Pons20905cf2020-08-03 14:18:41 +020047 const u32 pciexbar_reg = pci_read_config32(dev, PCIEXBAR);
Stefan Reinauer00636b02012-04-04 00:08:51 +020048
Angel Pons7c49cb82020-03-16 23:17:32 +010049 /* MMCFG not supported or not enabled */
Stefan Reinauer00636b02012-04-04 00:08:51 +020050 if (!(pciexbar_reg & (1 << 0)))
51 return 0;
52
53 switch ((pciexbar_reg >> 1) & 3) {
Angel Pons7c49cb82020-03-16 23:17:32 +010054 case 0: /* 256MB */
Angel Pons20905cf2020-08-03 14:18:41 +020055 *base = pciexbar_reg & (0x0f << 28);
56 *len = 256 * MiB;
57 return 1;
Angel Pons7c49cb82020-03-16 23:17:32 +010058 case 1: /* 128M */
Angel Pons20905cf2020-08-03 14:18:41 +020059 *base = pciexbar_reg & (0x1f << 27);
60 *len = 128 * MiB;
61 return 1;
Angel Pons7c49cb82020-03-16 23:17:32 +010062 case 2: /* 64M */
Angel Pons20905cf2020-08-03 14:18:41 +020063 *base = pciexbar_reg & (0x3f << 26);
64 *len = 64 * MiB;
65 return 1;
Stefan Reinauer00636b02012-04-04 00:08:51 +020066 }
67
68 return 0;
69}
70
Aaron Durbin1ca24332020-05-13 11:38:35 -060071static const char *northbridge_acpi_name(const struct device *dev)
72{
73 if (dev->path.type == DEVICE_PATH_DOMAIN)
74 return "PCI0";
75
76 if (dev->path.type != DEVICE_PATH_PCI)
77 return NULL;
78
79 switch (dev->path.pci.devfn) {
80 case PCI_DEVFN(0, 0):
81 return "MCHC";
82 }
83
84 return NULL;
85}
86
87/*
88 * TODO We could determine how many PCIe busses we need in the bar.
89 * For now, that number is hardcoded to a max of 64.
90 */
91static struct device_operations pci_domain_ops = {
92 .read_resources = pci_domain_read_resources,
93 .set_resources = pci_domain_set_resources,
94 .scan_bus = pci_domain_scan_bus,
95 .write_acpi_tables = northbridge_write_acpi_tables,
96 .acpi_name = northbridge_acpi_name,
97};
98
Stefan Reinauer00636b02012-04-04 00:08:51 +020099static void add_fixed_resources(struct device *dev, int index)
100{
Kyösti Mälkki7f189cc2012-07-27 13:12:03 +0300101 mmio_resource(dev, index++, uma_memory_base >> 10, uma_memory_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200102
Angel Pons7c49cb82020-03-16 23:17:32 +0100103 mmio_resource(dev, index++, legacy_hole_base_k, (0xc0000 >> 10) - legacy_hole_base_k);
104
105 reserved_ram_resource(dev, index++, 0xc0000 >> 10, (0x100000 - 0xc0000) >> 10);
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +0300106
Julius Wernercd49cce2019-03-05 16:53:33 -0800107#if CONFIG(CHROMEOS_RAMOOPS)
Aaron Durbinc9650762013-03-22 22:03:09 -0500108 reserved_ram_resource(dev, index++,
109 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
Angel Pons7c49cb82020-03-16 23:17:32 +0100110 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +0300111#endif
112
Angel Pons964d91f2020-12-07 13:11:17 +0100113 if (is_sandybridge()) {
Nico Huber593e7de2015-11-04 15:46:00 +0100114 /* Required for SandyBridge sighting 3715511 */
115 bad_ram_resource(dev, index++, 0x20000000 >> 10, 0x00200000 >> 10);
116 bad_ram_resource(dev, index++, 0x40000000 >> 10, 0x00200000 >> 10);
117 }
Nico Huberbb9469c2015-10-21 11:49:23 +0200118
119 /* Reserve IOMMU BARs */
Angel Pons7c49cb82020-03-16 23:17:32 +0100120 const u32 capid0_a = pci_read_config32(dev, CAPID0_A);
Nico Huberbb9469c2015-10-21 11:49:23 +0200121 if (!(capid0_a & (1 << 23))) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100122 mmio_resource(dev, index++, GFXVT_BASE >> 10, 4);
123 mmio_resource(dev, index++, VTVC0_BASE >> 10, 4);
Nico Huberbb9469c2015-10-21 11:49:23 +0200124 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200125}
126
Aaron Durbin1ca24332020-05-13 11:38:35 -0600127static void mc_read_resources(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200128{
Angel Pons20905cf2020-08-03 14:18:41 +0200129 u32 pcie_config_base, pcie_config_len;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200130 uint64_t tom, me_base, touud;
131 uint32_t tseg_base, uma_size, tolud;
132 uint16_t ggc;
133 unsigned long long tomk;
Angel Pons14ea2fc2020-05-13 21:46:46 +0200134 unsigned long index = 3;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200135
Aaron Durbin1ca24332020-05-13 11:38:35 -0600136 pci_dev_read_resources(dev);
137
Angel Pons20905cf2020-08-03 14:18:41 +0200138 if (decode_pcie_bar(&pcie_config_base, &pcie_config_len)) {
139 const int buses = pcie_config_len / MiB;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600140 struct resource *resource = new_resource(dev, PCIEXBAR);
141 mmconf_resource_init(resource, pcie_config_base, buses);
142 }
143
Stefan Reinauer00636b02012-04-04 00:08:51 +0200144 /* Total Memory 2GB example:
145 *
146 * 00000000 0000MB-1992MB 1992MB RAM (writeback)
147 * 7c800000 1992MB-2000MB 8MB TSEG (SMRR)
148 * 7d000000 2000MB-2002MB 2MB GFX GTT (uncached)
149 * 7d200000 2002MB-2034MB 32MB GFX UMA (uncached)
150 * 7f200000 2034MB TOLUD
151 * 7f800000 2040MB MEBASE
152 * 7f800000 2040MB-2048MB 8MB ME UMA (uncached)
153 * 80000000 2048MB TOM
154 * 100000000 4096MB-4102MB 6MB RAM (writeback)
155 *
156 * Total Memory 4GB example:
157 *
158 * 00000000 0000MB-2768MB 2768MB RAM (writeback)
159 * ad000000 2768MB-2776MB 8MB TSEG (SMRR)
160 * ad800000 2776MB-2778MB 2MB GFX GTT (uncached)
161 * ada00000 2778MB-2810MB 32MB GFX UMA (uncached)
162 * afa00000 2810MB TOLUD
163 * ff800000 4088MB MEBASE
164 * ff800000 4088MB-4096MB 8MB ME UMA (uncached)
165 * 100000000 4096MB TOM
166 * 100000000 4096MB-5374MB 1278MB RAM (writeback)
167 * 14fe00000 5368MB TOUUD
168 */
169
170 /* Top of Upper Usable DRAM, including remap */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600171 touud = pci_read_config32(dev, TOUUD + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200172 touud <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600173 touud |= pci_read_config32(dev, TOUUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200174
175 /* Top of Lower Usable DRAM */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600176 tolud = pci_read_config32(dev, TOLUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200177
178 /* Top of Memory - does not account for any UMA */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600179 tom = pci_read_config32(dev, TOM + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200180 tom <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600181 tom |= pci_read_config32(dev, TOM);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200182
183 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
184 touud, tolud, tom);
185
Angel Pons7c49cb82020-03-16 23:17:32 +0100186 /* ME UMA needs excluding if total memory < 4GB */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600187 me_base = pci_read_config32(dev, MESEG_BASE + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200188 me_base <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600189 me_base |= pci_read_config32(dev, MESEG_BASE);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200190
191 printk(BIOS_DEBUG, "MEBASE 0x%llx\n", me_base);
192
Patrick Rudolph240766a2015-10-15 15:33:25 +0200193 uma_memory_base = tolud;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200194 tomk = tolud >> 10;
195 if (me_base == tolud) {
196 /* ME is from MEBASE-TOM */
197 uma_size = (tom - me_base) >> 10;
198 /* Increment TOLUD to account for ME as RAM */
199 tolud += uma_size << 10;
200 /* UMA starts at old TOLUD */
201 uma_memory_base = tomk * 1024ULL;
202 uma_memory_size = uma_size * 1024ULL;
203 printk(BIOS_DEBUG, "ME UMA base 0x%llx size %uM\n",
204 me_base, uma_size >> 10);
205 }
206
207 /* Graphics memory comes next */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600208 ggc = pci_read_config16(dev, GGC);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200209 if (!(ggc & 2)) {
210 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
211
212 /* Graphics memory */
213 uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL;
214 printk(BIOS_DEBUG, "%uM UMA", uma_size >> 10);
215 tomk -= uma_size;
216 uma_memory_base = tomk * 1024ULL;
217 uma_memory_size += uma_size * 1024ULL;
218
219 /* GTT Graphics Stolen Memory Size (GGMS) */
220 uma_size = ((ggc >> 8) & 0x3) * 1024ULL;
221 tomk -= uma_size;
222 uma_memory_base = tomk * 1024ULL;
223 uma_memory_size += uma_size * 1024ULL;
224 printk(BIOS_DEBUG, " and %uM GTT\n", uma_size >> 10);
225 }
226
227 /* Calculate TSEG size from its base which must be below GTT */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600228 tseg_base = pci_read_config32(dev, TSEGMB);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200229 uma_size = (uma_memory_base - tseg_base) >> 10;
230 tomk -= uma_size;
231 uma_memory_base = tomk * 1024ULL;
232 uma_memory_size += uma_size * 1024ULL;
Angel Pons7c49cb82020-03-16 23:17:32 +0100233 printk(BIOS_DEBUG, "TSEG base 0x%08x size %uM\n", tseg_base, uma_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200234
235 printk(BIOS_INFO, "Available memory below 4GB: %lluM\n", tomk >> 10);
236
237 /* Report the memory regions */
Angel Pons14ea2fc2020-05-13 21:46:46 +0200238 ram_resource(dev, index++, 0, legacy_hole_base_k);
239 ram_resource(dev, index++, legacy_hole_base_k + legacy_hole_size_k,
240 (tomk - (legacy_hole_base_k + legacy_hole_size_k)));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200241
242 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100243 * If >= 4GB installed, then memory from TOLUD to 4GB is remapped above TOM.
244 * TOUUD will account for both memory chunks.
Stefan Reinauer00636b02012-04-04 00:08:51 +0200245 */
246 touud >>= 10; /* Convert to KB */
247 if (touud > 4096 * 1024) {
Angel Pons14ea2fc2020-05-13 21:46:46 +0200248 ram_resource(dev, index++, 4096 * 1024, touud - (4096 * 1024));
Angel Pons7c49cb82020-03-16 23:17:32 +0100249 printk(BIOS_INFO, "Available memory above 4GB: %lluM\n", (touud >> 10) - 4096);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200250 }
251
Angel Pons14ea2fc2020-05-13 21:46:46 +0200252 add_fixed_resources(dev, index++);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200253}
254
Stefan Reinauer00636b02012-04-04 00:08:51 +0200255static void northbridge_dmi_init(struct device *dev)
256{
Angel Pons964d91f2020-12-07 13:11:17 +0100257 const bool is_sandy = is_sandybridge();
258
Stefan Reinauer00636b02012-04-04 00:08:51 +0200259 u32 reg32;
260
261 /* Clear error status bits */
Angel Ponsf950a7e2020-09-14 17:15:37 +0200262 DMIBAR32(DMIUESTS) = 0xffffffff;
263 DMIBAR32(DMICESTS) = 0xffffffff;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200264
265 /* Steps prior to DMI ASPM */
Angel Pons964d91f2020-12-07 13:11:17 +0100266 if (is_sandy) {
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700267 reg32 = DMIBAR32(0x250);
Angel Pons7c49cb82020-03-16 23:17:32 +0100268 reg32 &= ~((1 << 22) | (1 << 20));
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700269 reg32 |= (1 << 21);
270 DMIBAR32(0x250) = reg32;
271 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200272
Angel Ponsf950a7e2020-09-14 17:15:37 +0200273 reg32 = DMIBAR32(DMILLTC);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200274 reg32 |= (1 << 29);
Angel Ponsf950a7e2020-09-14 17:15:37 +0200275 DMIBAR32(DMILLTC) = reg32;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200276
Angel Pons964d91f2020-12-07 13:11:17 +0100277 if (!is_sandy || cpu_stepping() >= SNB_STEP_D0) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200278 reg32 = DMIBAR32(0x1f8);
279 reg32 |= (1 << 16);
280 DMIBAR32(0x1f8) = reg32;
Angel Pons7c49cb82020-03-16 23:17:32 +0100281
Angel Pons964d91f2020-12-07 13:11:17 +0100282 } else if (!is_sandy || cpu_stepping() >= SNB_STEP_D1) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200283 reg32 = DMIBAR32(0x1f8);
284 reg32 &= ~(1 << 26);
285 reg32 |= (1 << 16);
286 DMIBAR32(0x1f8) = reg32;
287
288 reg32 = DMIBAR32(0x1fc);
289 reg32 |= (1 << 12) | (1 << 23);
290 DMIBAR32(0x1fc) = reg32;
291 }
292
293 /* Enable ASPM on SNB link, should happen before PCH link */
Angel Pons964d91f2020-12-07 13:11:17 +0100294 if (is_sandy) {
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700295 reg32 = DMIBAR32(0xd04);
296 reg32 |= (1 << 4);
297 DMIBAR32(0xd04) = reg32;
298 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200299
Angel Ponsf950a7e2020-09-14 17:15:37 +0200300 reg32 = DMIBAR32(DMILCTL);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200301 reg32 |= (1 << 1) | (1 << 0);
Angel Ponsf950a7e2020-09-14 17:15:37 +0200302 DMIBAR32(DMILCTL) = reg32;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200303}
304
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200305/* Disable unused PEG devices based on devicetree */
306static void disable_peg(void)
307{
308 struct device *dev;
309 u32 reg;
310
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300311 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200312 reg = pci_read_config32(dev, DEVEN);
313
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300314 dev = pcidev_on_root(1, 2);
Nico Huber2dc15e92016-02-04 18:59:48 +0100315 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200316 printk(BIOS_DEBUG, "Disabling PEG12.\n");
317 reg &= ~DEVEN_PEG12;
318 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300319 dev = pcidev_on_root(1, 1);
Nico Huber2dc15e92016-02-04 18:59:48 +0100320 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200321 printk(BIOS_DEBUG, "Disabling PEG11.\n");
322 reg &= ~DEVEN_PEG11;
323 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300324 dev = pcidev_on_root(1, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100325 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200326 printk(BIOS_DEBUG, "Disabling PEG10.\n");
327 reg &= ~DEVEN_PEG10;
328 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300329 dev = pcidev_on_root(2, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100330 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200331 printk(BIOS_DEBUG, "Disabling IGD.\n");
332 reg &= ~DEVEN_IGD;
333 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300334 dev = pcidev_on_root(4, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200335 if (!dev || !dev->enabled) {
336 printk(BIOS_DEBUG, "Disabling Device 4.\n");
337 reg &= ~DEVEN_D4EN;
338 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300339 dev = pcidev_on_root(6, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100340 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200341 printk(BIOS_DEBUG, "Disabling PEG60.\n");
342 reg &= ~DEVEN_PEG60;
343 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300344 dev = pcidev_on_root(7, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200345 if (!dev || !dev->enabled) {
346 printk(BIOS_DEBUG, "Disabling Device 7.\n");
347 reg &= ~DEVEN_D7EN;
348 }
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200349
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300350 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200351 pci_write_config32(dev, DEVEN, reg);
Angel Pons7c49cb82020-03-16 23:17:32 +0100352
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200353 if (!(reg & (DEVEN_PEG60 | DEVEN_PEG10 | DEVEN_PEG11 | DEVEN_PEG12))) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100354 /*
355 * Set the PEG clock gating bit. Disables the IO clock on all PEG devices.
356 *
Angel Pons78b43c82020-03-17 23:55:18 +0100357 * FIXME: Never clock gate on Ivy Bridge stepping A0!
Angel Pons7c49cb82020-03-16 23:17:32 +0100358 */
359 MCHBAR32_OR(PEGCTL, 1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200360 printk(BIOS_DEBUG, "Disabling PEG IO clock.\n");
Angel Pons78b43c82020-03-17 23:55:18 +0100361 } else {
362 MCHBAR32_AND(PEGCTL, ~1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200363 }
364}
365
Stefan Reinauer00636b02012-04-04 00:08:51 +0200366static void northbridge_init(struct device *dev)
367{
368 u8 bios_reset_cpl;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700369 u32 bridge_type;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200370
371 northbridge_dmi_init(dev);
372
Angel Pons88521882020-01-05 20:21:20 +0100373 bridge_type = MCHBAR32(SAPMTIMERS);
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700374 bridge_type &= ~0xff;
375
Angel Pons964d91f2020-12-07 13:11:17 +0100376 if (is_sandybridge()) {
377 /* 20h for Sandybridge */
378 bridge_type |= 0x20;
379 } else {
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700380 /* Enable Power Aware Interrupt Routing */
Angel Pons7c49cb82020-03-16 23:17:32 +0100381 u8 pair = MCHBAR8(INTRDIRCTL);
382 pair &= ~0x0f; /* Clear 3:0 */
383 pair |= 0x04; /* Fixed Priority */
384 MCHBAR8(INTRDIRCTL) = pair;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700385
386 /* 30h for IvyBridge */
387 bridge_type |= 0x30;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700388 }
Angel Pons88521882020-01-05 20:21:20 +0100389 MCHBAR32(SAPMTIMERS) = bridge_type;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700390
Angel Pons7c49cb82020-03-16 23:17:32 +0100391 /* Turn off unused devices. Has to be done before setting BIOS_RESET_CPL. */
Patrick Rudolphaad34cd2015-10-21 18:05:01 +0200392 disable_peg();
393
Stefan Reinauer00636b02012-04-04 00:08:51 +0200394 /*
395 * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
396 * that BIOS has initialized memory and power management
397 */
398 bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL);
399 bios_reset_cpl |= 1;
400 MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl;
401 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
402
403 /* Configure turbo power limits 1ms after reset complete bit */
404 mdelay(1);
405 set_power_limits(28);
406
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700407 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100408 * CPUs with configurable TDP also need power limits set in MCHBAR.
409 * Use the same values from MSR_PKG_POWER_LIMIT.
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700410 */
411 if (cpu_config_tdp_levels()) {
412 msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT);
Angel Pons7c49cb82020-03-16 23:17:32 +0100413 MCHBAR32(MCH_PKG_POWER_LIMIT_LO) = msr.lo;
414 MCHBAR32(MCH_PKG_POWER_LIMIT_HI) = msr.hi;
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700415 }
416
Stefan Reinauer00636b02012-04-04 00:08:51 +0200417 /* Set here before graphics PM init */
Angel Pons7c49cb82020-03-16 23:17:32 +0100418 MCHBAR32(PAVP_MSG) = 0x00100001;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200419}
420
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200421void northbridge_write_smram(u8 smram)
422{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300423 pci_write_config8(pcidev_on_root(0, 0), SMRAM, smram);
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200424}
425
Stefan Reinauer00636b02012-04-04 00:08:51 +0200426static struct device_operations mc_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200427 .read_resources = mc_read_resources,
428 .set_resources = pci_dev_set_resources,
429 .enable_resources = pci_dev_enable_resources,
430 .init = northbridge_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200431 .ops_pci = &pci_dev_ops_pci,
Nico Huber68680dd2020-03-31 17:34:52 +0200432 .acpi_fill_ssdt = generate_cpu_entries,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200433};
434
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600435static const unsigned short pci_device_ids[] = {
Jonathan A. Kollaschd346a192020-02-11 09:03:48 -0600436 0x0100, 0x0104, 0x0108, /* Sandy Bridge */
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600437 0x0150, 0x0154, 0x0158, /* Ivy Bridge */
438 0
Walter Murphy496f4a02012-04-23 11:08:03 -0700439};
440
Stefan Reinauer00636b02012-04-04 00:08:51 +0200441static const struct pci_driver mc_driver __pci_driver = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100442 .ops = &mc_ops,
443 .vendor = PCI_VENDOR_ID_INTEL,
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600444 .devices = pci_device_ids,
Vagiz Trakhanov1dd448c2017-09-28 14:42:11 +0000445};
446
Stefan Reinauer00636b02012-04-04 00:08:51 +0200447static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200448 .read_resources = noop_read_resources,
449 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300450 .init = mp_cpu_bus_init,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200451};
452
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100453static void enable_dev(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200454{
455 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800456 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200457 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800458 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200459 dev->ops = &cpu_bus_ops;
460 }
461}
462
463struct chip_operations northbridge_intel_sandybridge_ops = {
Damien Zammit35170382014-10-29 00:11:53 +1100464 CHIP_NAME("Intel SandyBridge/IvyBridge integrated Northbridge")
Stefan Reinauer00636b02012-04-04 00:08:51 +0200465 .enable_dev = enable_dev,
466};