blob: ead3c67c0db7fe3985011ae6a06776e984c8ddc8 [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>
Kyösti Mälkkib8b41332021-02-10 19:11:55 +020017#include <vendorcode/google/chromeos/chromeos.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020018
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
Angel Pons964d91f2020-12-07 13:11:17 +010023bool is_sandybridge(void)
Stefan Reinauer00636b02012-04-04 00:08:51 +020024{
Angel Pons964d91f2020-12-07 13:11:17 +010025 const uint16_t bridge_id = pci_read_config16(pcidev_on_root(0, 0), PCI_DEVICE_ID);
26
27 return (bridge_id & BASE_REV_MASK) == BASE_REV_SNB;
Stefan Reinauer00636b02012-04-04 00:08:51 +020028}
29
30/* Reserve everything between A segment and 1MB:
31 *
32 * 0xa0000 - 0xbffff: legacy VGA
33 * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel)
34 * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI
35 */
36static const int legacy_hole_base_k = 0xa0000 / 1024;
37static const int legacy_hole_size_k = 384;
38
Aaron Durbin1ca24332020-05-13 11:38:35 -060039static const char *northbridge_acpi_name(const struct device *dev)
40{
41 if (dev->path.type == DEVICE_PATH_DOMAIN)
42 return "PCI0";
43
44 if (dev->path.type != DEVICE_PATH_PCI)
45 return NULL;
46
47 switch (dev->path.pci.devfn) {
48 case PCI_DEVFN(0, 0):
49 return "MCHC";
50 }
51
52 return NULL;
53}
54
Aaron Durbin1ca24332020-05-13 11:38:35 -060055static struct device_operations pci_domain_ops = {
56 .read_resources = pci_domain_read_resources,
57 .set_resources = pci_domain_set_resources,
58 .scan_bus = pci_domain_scan_bus,
59 .write_acpi_tables = northbridge_write_acpi_tables,
60 .acpi_name = northbridge_acpi_name,
61};
62
Stefan Reinauer00636b02012-04-04 00:08:51 +020063static void add_fixed_resources(struct device *dev, int index)
64{
Kyösti Mälkki7f189cc2012-07-27 13:12:03 +030065 mmio_resource(dev, index++, uma_memory_base >> 10, uma_memory_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +020066
Angel Pons7c49cb82020-03-16 23:17:32 +010067 mmio_resource(dev, index++, legacy_hole_base_k, (0xc0000 >> 10) - legacy_hole_base_k);
68
69 reserved_ram_resource(dev, index++, 0xc0000 >> 10, (0x100000 - 0xc0000) >> 10);
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +030070
Kyösti Mälkkib8b41332021-02-10 19:11:55 +020071 if (CONFIG(CHROMEOS_RAMOOPS))
72 chromeos_reserve_ram_oops(dev, index++);
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +030073
Angel Pons964d91f2020-12-07 13:11:17 +010074 if (is_sandybridge()) {
Nico Huber593e7de2015-11-04 15:46:00 +010075 /* Required for SandyBridge sighting 3715511 */
76 bad_ram_resource(dev, index++, 0x20000000 >> 10, 0x00200000 >> 10);
77 bad_ram_resource(dev, index++, 0x40000000 >> 10, 0x00200000 >> 10);
78 }
Nico Huberbb9469c2015-10-21 11:49:23 +020079
80 /* Reserve IOMMU BARs */
Angel Pons7c49cb82020-03-16 23:17:32 +010081 const u32 capid0_a = pci_read_config32(dev, CAPID0_A);
Nico Huberbb9469c2015-10-21 11:49:23 +020082 if (!(capid0_a & (1 << 23))) {
Angel Pons7c49cb82020-03-16 23:17:32 +010083 mmio_resource(dev, index++, GFXVT_BASE >> 10, 4);
84 mmio_resource(dev, index++, VTVC0_BASE >> 10, 4);
Nico Huberbb9469c2015-10-21 11:49:23 +020085 }
Stefan Reinauer00636b02012-04-04 00:08:51 +020086}
87
Aaron Durbin1ca24332020-05-13 11:38:35 -060088static void mc_read_resources(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +020089{
90 uint64_t tom, me_base, touud;
91 uint32_t tseg_base, uma_size, tolud;
92 uint16_t ggc;
93 unsigned long long tomk;
Angel Pons14ea2fc2020-05-13 21:46:46 +020094 unsigned long index = 3;
Stefan Reinauer00636b02012-04-04 00:08:51 +020095
Aaron Durbin1ca24332020-05-13 11:38:35 -060096 pci_dev_read_resources(dev);
97
Angel Pons10f9b832021-01-20 14:58:32 +010098 mmconf_resource(dev, PCIEXBAR);
Aaron Durbin1ca24332020-05-13 11:38:35 -060099
Stefan Reinauer00636b02012-04-04 00:08:51 +0200100 /* Total Memory 2GB example:
101 *
102 * 00000000 0000MB-1992MB 1992MB RAM (writeback)
103 * 7c800000 1992MB-2000MB 8MB TSEG (SMRR)
104 * 7d000000 2000MB-2002MB 2MB GFX GTT (uncached)
105 * 7d200000 2002MB-2034MB 32MB GFX UMA (uncached)
106 * 7f200000 2034MB TOLUD
107 * 7f800000 2040MB MEBASE
108 * 7f800000 2040MB-2048MB 8MB ME UMA (uncached)
109 * 80000000 2048MB TOM
110 * 100000000 4096MB-4102MB 6MB RAM (writeback)
111 *
112 * Total Memory 4GB example:
113 *
114 * 00000000 0000MB-2768MB 2768MB RAM (writeback)
115 * ad000000 2768MB-2776MB 8MB TSEG (SMRR)
116 * ad800000 2776MB-2778MB 2MB GFX GTT (uncached)
117 * ada00000 2778MB-2810MB 32MB GFX UMA (uncached)
118 * afa00000 2810MB TOLUD
119 * ff800000 4088MB MEBASE
120 * ff800000 4088MB-4096MB 8MB ME UMA (uncached)
121 * 100000000 4096MB TOM
122 * 100000000 4096MB-5374MB 1278MB RAM (writeback)
123 * 14fe00000 5368MB TOUUD
124 */
125
126 /* Top of Upper Usable DRAM, including remap */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600127 touud = pci_read_config32(dev, TOUUD + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200128 touud <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600129 touud |= pci_read_config32(dev, TOUUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200130
131 /* Top of Lower Usable DRAM */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600132 tolud = pci_read_config32(dev, TOLUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200133
134 /* Top of Memory - does not account for any UMA */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600135 tom = pci_read_config32(dev, TOM + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200136 tom <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600137 tom |= pci_read_config32(dev, TOM);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200138
139 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
140 touud, tolud, tom);
141
Angel Pons7c49cb82020-03-16 23:17:32 +0100142 /* ME UMA needs excluding if total memory < 4GB */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600143 me_base = pci_read_config32(dev, MESEG_BASE + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200144 me_base <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600145 me_base |= pci_read_config32(dev, MESEG_BASE);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200146
147 printk(BIOS_DEBUG, "MEBASE 0x%llx\n", me_base);
148
Patrick Rudolph240766a2015-10-15 15:33:25 +0200149 uma_memory_base = tolud;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200150 tomk = tolud >> 10;
151 if (me_base == tolud) {
152 /* ME is from MEBASE-TOM */
153 uma_size = (tom - me_base) >> 10;
154 /* Increment TOLUD to account for ME as RAM */
155 tolud += uma_size << 10;
156 /* UMA starts at old TOLUD */
157 uma_memory_base = tomk * 1024ULL;
158 uma_memory_size = uma_size * 1024ULL;
159 printk(BIOS_DEBUG, "ME UMA base 0x%llx size %uM\n",
160 me_base, uma_size >> 10);
161 }
162
163 /* Graphics memory comes next */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600164 ggc = pci_read_config16(dev, GGC);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200165 if (!(ggc & 2)) {
166 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
167
168 /* Graphics memory */
169 uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL;
170 printk(BIOS_DEBUG, "%uM UMA", uma_size >> 10);
171 tomk -= uma_size;
172 uma_memory_base = tomk * 1024ULL;
173 uma_memory_size += uma_size * 1024ULL;
174
175 /* GTT Graphics Stolen Memory Size (GGMS) */
176 uma_size = ((ggc >> 8) & 0x3) * 1024ULL;
177 tomk -= uma_size;
178 uma_memory_base = tomk * 1024ULL;
179 uma_memory_size += uma_size * 1024ULL;
180 printk(BIOS_DEBUG, " and %uM GTT\n", uma_size >> 10);
181 }
182
183 /* Calculate TSEG size from its base which must be below GTT */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600184 tseg_base = pci_read_config32(dev, TSEGMB);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200185 uma_size = (uma_memory_base - tseg_base) >> 10;
186 tomk -= uma_size;
187 uma_memory_base = tomk * 1024ULL;
188 uma_memory_size += uma_size * 1024ULL;
Angel Pons7c49cb82020-03-16 23:17:32 +0100189 printk(BIOS_DEBUG, "TSEG base 0x%08x size %uM\n", tseg_base, uma_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200190
191 printk(BIOS_INFO, "Available memory below 4GB: %lluM\n", tomk >> 10);
192
193 /* Report the memory regions */
Angel Pons14ea2fc2020-05-13 21:46:46 +0200194 ram_resource(dev, index++, 0, legacy_hole_base_k);
195 ram_resource(dev, index++, legacy_hole_base_k + legacy_hole_size_k,
196 (tomk - (legacy_hole_base_k + legacy_hole_size_k)));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200197
198 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100199 * If >= 4GB installed, then memory from TOLUD to 4GB is remapped above TOM.
200 * TOUUD will account for both memory chunks.
Stefan Reinauer00636b02012-04-04 00:08:51 +0200201 */
202 touud >>= 10; /* Convert to KB */
203 if (touud > 4096 * 1024) {
Angel Pons14ea2fc2020-05-13 21:46:46 +0200204 ram_resource(dev, index++, 4096 * 1024, touud - (4096 * 1024));
Angel Pons7c49cb82020-03-16 23:17:32 +0100205 printk(BIOS_INFO, "Available memory above 4GB: %lluM\n", (touud >> 10) - 4096);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200206 }
207
Angel Pons14ea2fc2020-05-13 21:46:46 +0200208 add_fixed_resources(dev, index++);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200209}
210
Stefan Reinauer00636b02012-04-04 00:08:51 +0200211static void northbridge_dmi_init(struct device *dev)
212{
Angel Pons964d91f2020-12-07 13:11:17 +0100213 const bool is_sandy = is_sandybridge();
214
Angel Pons77516ca2020-12-10 16:43:25 +0100215 const u8 stepping = cpu_stepping();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200216
Angel Pons77516ca2020-12-10 16:43:25 +0100217 u32 reg32;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200218
219 /* Steps prior to DMI ASPM */
Angel Pons964d91f2020-12-07 13:11:17 +0100220 if (is_sandy) {
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700221 reg32 = DMIBAR32(0x250);
Angel Pons77516ca2020-12-10 16:43:25 +0100222 reg32 &= ~(7 << 20);
223 reg32 |= (2 << 20);
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700224 DMIBAR32(0x250) = reg32;
225 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200226
Angel Ponsf950a7e2020-09-14 17:15:37 +0200227 reg32 = DMIBAR32(DMILLTC);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200228 reg32 |= (1 << 29);
Angel Ponsf950a7e2020-09-14 17:15:37 +0200229 DMIBAR32(DMILLTC) = reg32;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200230
Angel Pons77516ca2020-12-10 16:43:25 +0100231 if (is_sandy && stepping == SNB_STEP_C0) {
232 reg32 = DMIBAR32(0xbc8);
233 reg32 &= ~(0xfff << 7);
234 reg32 |= (0x7d3 << 7);
235 DMIBAR32(0xbc8) = reg32;
236 }
Angel Pons7c49cb82020-03-16 23:17:32 +0100237
Angel Pons77516ca2020-12-10 16:43:25 +0100238 if (!is_sandy || stepping >= SNB_STEP_D1) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200239 reg32 = DMIBAR32(0x1f8);
240 reg32 &= ~(1 << 26);
241 reg32 |= (1 << 16);
242 DMIBAR32(0x1f8) = reg32;
243
244 reg32 = DMIBAR32(0x1fc);
245 reg32 |= (1 << 12) | (1 << 23);
246 DMIBAR32(0x1fc) = reg32;
Angel Pons77516ca2020-12-10 16:43:25 +0100247
248 } else if (stepping >= SNB_STEP_D0) {
249 reg32 = DMIBAR32(0x1f8);
250 reg32 |= (1 << 16);
251 DMIBAR32(0x1f8) = reg32;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200252 }
253
Angel Pons77516ca2020-12-10 16:43:25 +0100254 /* Clear error status bits */
255 DMIBAR32(DMIUESTS) = 0xffffffff;
256 DMIBAR32(DMICESTS) = 0xffffffff;
257
258 if (!is_sandy)
259 DMIBAR32(0xc34) = 0xffffffff;
260
Stefan Reinauer00636b02012-04-04 00:08:51 +0200261 /* Enable ASPM on SNB link, should happen before PCH link */
Angel Pons964d91f2020-12-07 13:11:17 +0100262 if (is_sandy) {
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700263 reg32 = DMIBAR32(0xd04);
264 reg32 |= (1 << 4);
265 DMIBAR32(0xd04) = reg32;
266 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200267
Angel Ponsf950a7e2020-09-14 17:15:37 +0200268 reg32 = DMIBAR32(DMILCTL);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200269 reg32 |= (1 << 1) | (1 << 0);
Angel Ponsf950a7e2020-09-14 17:15:37 +0200270 DMIBAR32(DMILCTL) = reg32;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200271}
272
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200273/* Disable unused PEG devices based on devicetree */
274static void disable_peg(void)
275{
276 struct device *dev;
277 u32 reg;
278
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300279 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200280 reg = pci_read_config32(dev, DEVEN);
281
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300282 dev = pcidev_on_root(1, 2);
Nico Huber2dc15e92016-02-04 18:59:48 +0100283 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200284 printk(BIOS_DEBUG, "Disabling PEG12.\n");
285 reg &= ~DEVEN_PEG12;
286 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300287 dev = pcidev_on_root(1, 1);
Nico Huber2dc15e92016-02-04 18:59:48 +0100288 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200289 printk(BIOS_DEBUG, "Disabling PEG11.\n");
290 reg &= ~DEVEN_PEG11;
291 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300292 dev = pcidev_on_root(1, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100293 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200294 printk(BIOS_DEBUG, "Disabling PEG10.\n");
295 reg &= ~DEVEN_PEG10;
296 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300297 dev = pcidev_on_root(2, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100298 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200299 printk(BIOS_DEBUG, "Disabling IGD.\n");
300 reg &= ~DEVEN_IGD;
301 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300302 dev = pcidev_on_root(4, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200303 if (!dev || !dev->enabled) {
304 printk(BIOS_DEBUG, "Disabling Device 4.\n");
305 reg &= ~DEVEN_D4EN;
306 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300307 dev = pcidev_on_root(6, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100308 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200309 printk(BIOS_DEBUG, "Disabling PEG60.\n");
310 reg &= ~DEVEN_PEG60;
311 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300312 dev = pcidev_on_root(7, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200313 if (!dev || !dev->enabled) {
314 printk(BIOS_DEBUG, "Disabling Device 7.\n");
315 reg &= ~DEVEN_D7EN;
316 }
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200317
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300318 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200319 pci_write_config32(dev, DEVEN, reg);
Angel Pons7c49cb82020-03-16 23:17:32 +0100320
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200321 if (!(reg & (DEVEN_PEG60 | DEVEN_PEG10 | DEVEN_PEG11 | DEVEN_PEG12))) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100322 /*
323 * Set the PEG clock gating bit. Disables the IO clock on all PEG devices.
324 *
Angel Pons78b43c82020-03-17 23:55:18 +0100325 * FIXME: Never clock gate on Ivy Bridge stepping A0!
Angel Pons7c49cb82020-03-16 23:17:32 +0100326 */
327 MCHBAR32_OR(PEGCTL, 1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200328 printk(BIOS_DEBUG, "Disabling PEG IO clock.\n");
Angel Pons78b43c82020-03-17 23:55:18 +0100329 } else {
330 MCHBAR32_AND(PEGCTL, ~1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200331 }
332}
333
Stefan Reinauer00636b02012-04-04 00:08:51 +0200334static void northbridge_init(struct device *dev)
335{
336 u8 bios_reset_cpl;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700337 u32 bridge_type;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200338
339 northbridge_dmi_init(dev);
340
Angel Pons88521882020-01-05 20:21:20 +0100341 bridge_type = MCHBAR32(SAPMTIMERS);
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700342 bridge_type &= ~0xff;
343
Angel Pons964d91f2020-12-07 13:11:17 +0100344 if (is_sandybridge()) {
345 /* 20h for Sandybridge */
346 bridge_type |= 0x20;
347 } else {
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700348 /* Enable Power Aware Interrupt Routing */
Angel Pons7c49cb82020-03-16 23:17:32 +0100349 u8 pair = MCHBAR8(INTRDIRCTL);
350 pair &= ~0x0f; /* Clear 3:0 */
351 pair |= 0x04; /* Fixed Priority */
352 MCHBAR8(INTRDIRCTL) = pair;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700353
354 /* 30h for IvyBridge */
355 bridge_type |= 0x30;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700356 }
Angel Pons88521882020-01-05 20:21:20 +0100357 MCHBAR32(SAPMTIMERS) = bridge_type;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700358
Angel Pons7c49cb82020-03-16 23:17:32 +0100359 /* Turn off unused devices. Has to be done before setting BIOS_RESET_CPL. */
Patrick Rudolphaad34cd2015-10-21 18:05:01 +0200360 disable_peg();
361
Stefan Reinauer00636b02012-04-04 00:08:51 +0200362 /*
363 * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
364 * that BIOS has initialized memory and power management
365 */
366 bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL);
367 bios_reset_cpl |= 1;
368 MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl;
369 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
370
371 /* Configure turbo power limits 1ms after reset complete bit */
372 mdelay(1);
373 set_power_limits(28);
374
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700375 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100376 * CPUs with configurable TDP also need power limits set in MCHBAR.
377 * Use the same values from MSR_PKG_POWER_LIMIT.
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700378 */
379 if (cpu_config_tdp_levels()) {
380 msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT);
Angel Pons7c49cb82020-03-16 23:17:32 +0100381 MCHBAR32(MCH_PKG_POWER_LIMIT_LO) = msr.lo;
382 MCHBAR32(MCH_PKG_POWER_LIMIT_HI) = msr.hi;
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700383 }
384
Stefan Reinauer00636b02012-04-04 00:08:51 +0200385 /* Set here before graphics PM init */
Angel Pons7c49cb82020-03-16 23:17:32 +0100386 MCHBAR32(PAVP_MSG) = 0x00100001;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200387}
388
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200389void northbridge_write_smram(u8 smram)
390{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300391 pci_write_config8(pcidev_on_root(0, 0), SMRAM, smram);
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200392}
393
Stefan Reinauer00636b02012-04-04 00:08:51 +0200394static struct device_operations mc_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200395 .read_resources = mc_read_resources,
396 .set_resources = pci_dev_set_resources,
397 .enable_resources = pci_dev_enable_resources,
398 .init = northbridge_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200399 .ops_pci = &pci_dev_ops_pci,
Nico Huber68680dd2020-03-31 17:34:52 +0200400 .acpi_fill_ssdt = generate_cpu_entries,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200401};
402
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600403static const unsigned short pci_device_ids[] = {
Jonathan A. Kollaschd346a192020-02-11 09:03:48 -0600404 0x0100, 0x0104, 0x0108, /* Sandy Bridge */
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600405 0x0150, 0x0154, 0x0158, /* Ivy Bridge */
406 0
Walter Murphy496f4a02012-04-23 11:08:03 -0700407};
408
Stefan Reinauer00636b02012-04-04 00:08:51 +0200409static const struct pci_driver mc_driver __pci_driver = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100410 .ops = &mc_ops,
411 .vendor = PCI_VENDOR_ID_INTEL,
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600412 .devices = pci_device_ids,
Vagiz Trakhanov1dd448c2017-09-28 14:42:11 +0000413};
414
Stefan Reinauer00636b02012-04-04 00:08:51 +0200415static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200416 .read_resources = noop_read_resources,
417 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300418 .init = mp_cpu_bus_init,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200419};
420
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100421static void enable_dev(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200422{
423 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800424 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200425 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800426 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200427 dev->ops = &cpu_bus_ops;
428 }
429}
430
431struct chip_operations northbridge_intel_sandybridge_ops = {
Damien Zammit35170382014-10-29 00:11:53 +1100432 CHIP_NAME("Intel SandyBridge/IvyBridge integrated Northbridge")
Stefan Reinauer00636b02012-04-04 00:08:51 +0200433 .enable_dev = enable_dev,
434};