blob: eb102db93328945469237d8851f7c15ac43a141c [file] [log] [blame]
Stefan Reinauer00636b02012-04-04 00:08:51 +02001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer00636b02012-04-04 00:08:51 +02004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Stefan Reinauer00636b02012-04-04 00:08:51 +020013 */
14
15#include <console/console.h>
16#include <arch/acpi.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020017#include <device/pci_ops.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020018#include <stdint.h>
19#include <delay.h>
20#include <cpu/intel/model_206ax/model_206ax.h>
Duncan Laurie77dbbac2012-06-25 09:51:59 -070021#include <cpu/x86/msr.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020022#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020025#include "chip.h"
26#include "sandybridge.h"
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030027#include <cpu/intel/smm_reloc.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020028
29static int bridge_revision_id = -1;
30
Kyösti Mälkkif7bfc342013-10-18 11:02:46 +030031/* IGD UMA memory */
32static uint64_t uma_memory_base = 0;
33static uint64_t uma_memory_size = 0;
34
Stefan Reinauer00636b02012-04-04 00:08:51 +020035int bridge_silicon_revision(void)
36{
37 if (bridge_revision_id < 0) {
38 uint8_t stepping = cpuid_eax(1) & 0xf;
39 uint8_t bridge_id = pci_read_config16(
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030040 pcidev_on_root(0, 0),
Stefan Reinauer00636b02012-04-04 00:08:51 +020041 PCI_DEVICE_ID) & 0xf0;
42 bridge_revision_id = bridge_id | stepping;
43 }
44 return bridge_revision_id;
45}
46
47/* Reserve everything between A segment and 1MB:
48 *
49 * 0xa0000 - 0xbffff: legacy VGA
50 * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel)
51 * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI
52 */
53static const int legacy_hole_base_k = 0xa0000 / 1024;
54static const int legacy_hole_size_k = 384;
55
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020056static int get_pcie_bar(u32 *base)
Stefan Reinauer00636b02012-04-04 00:08:51 +020057{
Elyes HAOUASab8743c2018-02-09 08:21:40 +010058 struct device *dev;
Stefan Reinauer00636b02012-04-04 00:08:51 +020059 u32 pciexbar_reg;
60
61 *base = 0;
Stefan Reinauer00636b02012-04-04 00:08:51 +020062
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030063 dev = pcidev_on_root(0, 0);
Stefan Reinauer00636b02012-04-04 00:08:51 +020064 if (!dev)
65 return 0;
66
67 pciexbar_reg = pci_read_config32(dev, PCIEXBAR);
68
69 if (!(pciexbar_reg & (1 << 0)))
70 return 0;
71
72 switch ((pciexbar_reg >> 1) & 3) {
73 case 0: // 256MB
74 *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28));
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020075 return 256;
Stefan Reinauer00636b02012-04-04 00:08:51 +020076 case 1: // 128M
77 *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020078 return 128;
Stefan Reinauer00636b02012-04-04 00:08:51 +020079 case 2: // 64M
80 *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26));
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020081 return 64;
Stefan Reinauer00636b02012-04-04 00:08:51 +020082 }
83
84 return 0;
85}
86
Stefan Reinauer00636b02012-04-04 00:08:51 +020087static void add_fixed_resources(struct device *dev, int index)
88{
Kyösti Mälkki7f189cc2012-07-27 13:12:03 +030089 mmio_resource(dev, index++, uma_memory_base >> 10, uma_memory_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +020090
Aaron Durbinc9650762013-03-22 22:03:09 -050091 mmio_resource(dev, index++, legacy_hole_base_k,
92 (0xc0000 >> 10) - legacy_hole_base_k);
93 reserved_ram_resource(dev, index++, 0xc0000 >> 10,
94 (0x100000 - 0xc0000) >> 10);
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +030095
Julius Wernercd49cce2019-03-05 16:53:33 -080096#if CONFIG(CHROMEOS_RAMOOPS)
Aaron Durbinc9650762013-03-22 22:03:09 -050097 reserved_ram_resource(dev, index++,
98 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +030099 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
100#endif
101
Nico Huber593e7de2015-11-04 15:46:00 +0100102 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
103 /* Required for SandyBridge sighting 3715511 */
104 bad_ram_resource(dev, index++, 0x20000000 >> 10, 0x00200000 >> 10);
105 bad_ram_resource(dev, index++, 0x40000000 >> 10, 0x00200000 >> 10);
106 }
Nico Huberbb9469c2015-10-21 11:49:23 +0200107
108 /* Reserve IOMMU BARs */
109 const u32 capid0_a = pci_read_config32(dev, 0xe4);
110 if (!(capid0_a & (1 << 23))) {
111 mmio_resource(dev, index++, IOMMU_BASE1 >> 10, 4);
112 mmio_resource(dev, index++, IOMMU_BASE2 >> 10, 4);
113 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200114}
115
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100116static void pci_domain_set_resources(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200117{
118 uint64_t tom, me_base, touud;
119 uint32_t tseg_base, uma_size, tolud;
120 uint16_t ggc;
121 unsigned long long tomk;
122
123 /* Total Memory 2GB example:
124 *
125 * 00000000 0000MB-1992MB 1992MB RAM (writeback)
126 * 7c800000 1992MB-2000MB 8MB TSEG (SMRR)
127 * 7d000000 2000MB-2002MB 2MB GFX GTT (uncached)
128 * 7d200000 2002MB-2034MB 32MB GFX UMA (uncached)
129 * 7f200000 2034MB TOLUD
130 * 7f800000 2040MB MEBASE
131 * 7f800000 2040MB-2048MB 8MB ME UMA (uncached)
132 * 80000000 2048MB TOM
133 * 100000000 4096MB-4102MB 6MB RAM (writeback)
134 *
135 * Total Memory 4GB example:
136 *
137 * 00000000 0000MB-2768MB 2768MB RAM (writeback)
138 * ad000000 2768MB-2776MB 8MB TSEG (SMRR)
139 * ad800000 2776MB-2778MB 2MB GFX GTT (uncached)
140 * ada00000 2778MB-2810MB 32MB GFX UMA (uncached)
141 * afa00000 2810MB TOLUD
142 * ff800000 4088MB MEBASE
143 * ff800000 4088MB-4096MB 8MB ME UMA (uncached)
144 * 100000000 4096MB TOM
145 * 100000000 4096MB-5374MB 1278MB RAM (writeback)
146 * 14fe00000 5368MB TOUUD
147 */
148
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300149 struct device *mch = pcidev_on_root(0, 0);
Arthur Heymans17041202018-06-26 21:06:25 +0200150
Stefan Reinauer00636b02012-04-04 00:08:51 +0200151 /* Top of Upper Usable DRAM, including remap */
Arthur Heymans17041202018-06-26 21:06:25 +0200152 touud = pci_read_config32(mch, TOUUD+4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200153 touud <<= 32;
Arthur Heymans17041202018-06-26 21:06:25 +0200154 touud |= pci_read_config32(mch, TOUUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200155
156 /* Top of Lower Usable DRAM */
Arthur Heymans17041202018-06-26 21:06:25 +0200157 tolud = pci_read_config32(mch, TOLUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200158
159 /* Top of Memory - does not account for any UMA */
Arthur Heymans17041202018-06-26 21:06:25 +0200160 tom = pci_read_config32(mch, 0xa4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200161 tom <<= 32;
Arthur Heymans17041202018-06-26 21:06:25 +0200162 tom |= pci_read_config32(mch, 0xa0);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200163
164 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
165 touud, tolud, tom);
166
167 /* ME UMA needs excluding if total memory <4GB */
Arthur Heymans17041202018-06-26 21:06:25 +0200168 me_base = pci_read_config32(mch, 0x74);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200169 me_base <<= 32;
Arthur Heymans17041202018-06-26 21:06:25 +0200170 me_base |= pci_read_config32(mch, 0x70);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200171
172 printk(BIOS_DEBUG, "MEBASE 0x%llx\n", me_base);
173
Patrick Rudolph240766a2015-10-15 15:33:25 +0200174 uma_memory_base = tolud;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200175 tomk = tolud >> 10;
176 if (me_base == tolud) {
177 /* ME is from MEBASE-TOM */
178 uma_size = (tom - me_base) >> 10;
179 /* Increment TOLUD to account for ME as RAM */
180 tolud += uma_size << 10;
181 /* UMA starts at old TOLUD */
182 uma_memory_base = tomk * 1024ULL;
183 uma_memory_size = uma_size * 1024ULL;
184 printk(BIOS_DEBUG, "ME UMA base 0x%llx size %uM\n",
185 me_base, uma_size >> 10);
186 }
187
188 /* Graphics memory comes next */
Arthur Heymans17041202018-06-26 21:06:25 +0200189 ggc = pci_read_config16(mch, GGC);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200190 if (!(ggc & 2)) {
191 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
192
193 /* Graphics memory */
194 uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL;
195 printk(BIOS_DEBUG, "%uM UMA", uma_size >> 10);
196 tomk -= uma_size;
197 uma_memory_base = tomk * 1024ULL;
198 uma_memory_size += uma_size * 1024ULL;
199
200 /* GTT Graphics Stolen Memory Size (GGMS) */
201 uma_size = ((ggc >> 8) & 0x3) * 1024ULL;
202 tomk -= uma_size;
203 uma_memory_base = tomk * 1024ULL;
204 uma_memory_size += uma_size * 1024ULL;
205 printk(BIOS_DEBUG, " and %uM GTT\n", uma_size >> 10);
206 }
207
208 /* Calculate TSEG size from its base which must be below GTT */
Arthur Heymans17041202018-06-26 21:06:25 +0200209 tseg_base = pci_read_config32(mch, 0xb8);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200210 uma_size = (uma_memory_base - tseg_base) >> 10;
211 tomk -= uma_size;
212 uma_memory_base = tomk * 1024ULL;
213 uma_memory_size += uma_size * 1024ULL;
214 printk(BIOS_DEBUG, "TSEG base 0x%08x size %uM\n",
215 tseg_base, uma_size >> 10);
216
217 printk(BIOS_INFO, "Available memory below 4GB: %lluM\n", tomk >> 10);
218
219 /* Report the memory regions */
220 ram_resource(dev, 3, 0, legacy_hole_base_k);
221 ram_resource(dev, 4, legacy_hole_base_k + legacy_hole_size_k,
222 (tomk - (legacy_hole_base_k + legacy_hole_size_k)));
223
224 /*
225 * If >= 4GB installed then memory from TOLUD to 4GB
226 * is remapped above TOM, TOUUD will account for both
227 */
228 touud >>= 10; /* Convert to KB */
229 if (touud > 4096 * 1024) {
230 ram_resource(dev, 5, 4096 * 1024, touud - (4096 * 1024));
231 printk(BIOS_INFO, "Available memory above 4GB: %lluM\n",
232 (touud >> 10) - 4096);
233 }
234
235 add_fixed_resources(dev, 6);
236
237 assign_resources(dev->link_list);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200238}
239
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600240static const char *northbridge_acpi_name(const struct device *dev)
Patrick Rudolph3e47fc92017-06-07 09:44:07 +0200241{
242 if (dev->path.type == DEVICE_PATH_DOMAIN)
243 return "PCI0";
244
245 if (dev->path.type != DEVICE_PATH_PCI)
246 return NULL;
247
248 switch (dev->path.pci.devfn) {
249 case PCI_DEVFN(0, 0):
250 return "MCHC";
251 }
252
253 return NULL;
254}
255
Stefan Reinauer00636b02012-04-04 00:08:51 +0200256 /* TODO We could determine how many PCIe busses we need in
257 * the bar. For now that number is hardcoded to a max of 64.
Stefan Reinauer00636b02012-04-04 00:08:51 +0200258 */
259static struct device_operations pci_domain_ops = {
260 .read_resources = pci_domain_read_resources,
261 .set_resources = pci_domain_set_resources,
262 .enable_resources = NULL,
263 .init = NULL,
264 .scan_bus = pci_domain_scan_bus,
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100265 .write_acpi_tables = northbridge_write_acpi_tables,
Patrick Rudolph3e47fc92017-06-07 09:44:07 +0200266 .acpi_name = northbridge_acpi_name,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200267};
268
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100269static void mc_read_resources(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200270{
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200271 u32 pcie_config_base;
272 int buses;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200273
274 pci_dev_read_resources(dev);
275
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200276 buses = get_pcie_bar(&pcie_config_base);
277 if (buses) {
Kyösti Mälkki27198ac2016-12-02 14:38:13 +0200278 struct resource *resource = new_resource(dev, PCIEXBAR);
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200279 mmconf_resource_init(resource, pcie_config_base, buses);
280 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200281}
282
Stefan Reinauer00636b02012-04-04 00:08:51 +0200283static void northbridge_dmi_init(struct device *dev)
284{
285 u32 reg32;
286
287 /* Clear error status bits */
288 DMIBAR32(0x1c4) = 0xffffffff;
289 DMIBAR32(0x1d0) = 0xffffffff;
290
291 /* Steps prior to DMI ASPM */
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700292 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
293 reg32 = DMIBAR32(0x250);
294 reg32 &= ~((1 << 22)|(1 << 20));
295 reg32 |= (1 << 21);
296 DMIBAR32(0x250) = reg32;
297 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200298
299 reg32 = DMIBAR32(0x238);
300 reg32 |= (1 << 29);
301 DMIBAR32(0x238) = reg32;
302
303 if (bridge_silicon_revision() >= SNB_STEP_D0) {
304 reg32 = DMIBAR32(0x1f8);
305 reg32 |= (1 << 16);
306 DMIBAR32(0x1f8) = reg32;
307 } else if (bridge_silicon_revision() >= SNB_STEP_D1) {
308 reg32 = DMIBAR32(0x1f8);
309 reg32 &= ~(1 << 26);
310 reg32 |= (1 << 16);
311 DMIBAR32(0x1f8) = reg32;
312
313 reg32 = DMIBAR32(0x1fc);
314 reg32 |= (1 << 12) | (1 << 23);
315 DMIBAR32(0x1fc) = reg32;
316 }
317
318 /* Enable ASPM on SNB link, should happen before PCH link */
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700319 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
320 reg32 = DMIBAR32(0xd04);
321 reg32 |= (1 << 4);
322 DMIBAR32(0xd04) = reg32;
323 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200324
325 reg32 = DMIBAR32(0x88);
326 reg32 |= (1 << 1) | (1 << 0);
327 DMIBAR32(0x88) = reg32;
328}
329
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200330/* Disable unused PEG devices based on devicetree */
331static void disable_peg(void)
332{
333 struct device *dev;
334 u32 reg;
335
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300336 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200337 reg = pci_read_config32(dev, DEVEN);
338
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300339 dev = pcidev_on_root(1, 2);
Nico Huber2dc15e92016-02-04 18:59:48 +0100340 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200341 printk(BIOS_DEBUG, "Disabling PEG12.\n");
342 reg &= ~DEVEN_PEG12;
343 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300344 dev = pcidev_on_root(1, 1);
Nico Huber2dc15e92016-02-04 18:59:48 +0100345 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200346 printk(BIOS_DEBUG, "Disabling PEG11.\n");
347 reg &= ~DEVEN_PEG11;
348 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300349 dev = pcidev_on_root(1, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100350 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200351 printk(BIOS_DEBUG, "Disabling PEG10.\n");
352 reg &= ~DEVEN_PEG10;
353 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300354 dev = pcidev_on_root(2, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100355 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200356 printk(BIOS_DEBUG, "Disabling IGD.\n");
357 reg &= ~DEVEN_IGD;
358 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300359 dev = pcidev_on_root(4, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200360 if (!dev || !dev->enabled) {
361 printk(BIOS_DEBUG, "Disabling Device 4.\n");
362 reg &= ~DEVEN_D4EN;
363 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300364 dev = pcidev_on_root(6, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100365 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200366 printk(BIOS_DEBUG, "Disabling PEG60.\n");
367 reg &= ~DEVEN_PEG60;
368 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300369 dev = pcidev_on_root(7, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200370 if (!dev || !dev->enabled) {
371 printk(BIOS_DEBUG, "Disabling Device 7.\n");
372 reg &= ~DEVEN_D7EN;
373 }
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200374
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300375 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200376 pci_write_config32(dev, DEVEN, reg);
377 if (!(reg & (DEVEN_PEG60 | DEVEN_PEG10 | DEVEN_PEG11 | DEVEN_PEG12))) {
378 /* Set the PEG clock gating bit.
379 * Disables the IO clock on all PEG devices. */
380 MCHBAR32(0x7010) = MCHBAR32(0x7010) | 0x01;
381 printk(BIOS_DEBUG, "Disabling PEG IO clock.\n");
382 }
383}
384
Stefan Reinauer00636b02012-04-04 00:08:51 +0200385static void northbridge_init(struct device *dev)
386{
387 u8 bios_reset_cpl;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700388 u32 bridge_type;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200389
390 northbridge_dmi_init(dev);
391
Angel Pons88521882020-01-05 20:21:20 +0100392 bridge_type = MCHBAR32(SAPMTIMERS);
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700393 bridge_type &= ~0xff;
394
395 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
396 /* Enable Power Aware Interrupt Routing */
Angel Pons88521882020-01-05 20:21:20 +0100397 u8 pair = MCHBAR8(PAIR_CTL);
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700398 pair &= ~0xf; /* Clear 3:0 */
399 pair |= 0x4; /* Fixed Priority */
Angel Pons88521882020-01-05 20:21:20 +0100400 MCHBAR8(PAIR_CTL) = pair;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700401
402 /* 30h for IvyBridge */
403 bridge_type |= 0x30;
404 } else {
405 /* 20h for Sandybridge */
406 bridge_type |= 0x20;
407 }
Angel Pons88521882020-01-05 20:21:20 +0100408 MCHBAR32(SAPMTIMERS) = bridge_type;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700409
Patrick Rudolphaad34cd2015-10-21 18:05:01 +0200410 /* Turn off unused devices. Has to be done before
411 * setting BIOS_RESET_CPL.
412 */
413 disable_peg();
414
Stefan Reinauer00636b02012-04-04 00:08:51 +0200415 /*
416 * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
417 * that BIOS has initialized memory and power management
418 */
419 bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL);
420 bios_reset_cpl |= 1;
421 MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl;
422 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
423
424 /* Configure turbo power limits 1ms after reset complete bit */
425 mdelay(1);
426 set_power_limits(28);
427
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700428 /*
429 * CPUs with configurable TDP also need power limits set
430 * in MCHBAR. Use same values from MSR_PKG_POWER_LIMIT.
431 */
432 if (cpu_config_tdp_levels()) {
433 msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT);
Angel Pons88521882020-01-05 20:21:20 +0100434 MCHBAR32(MC_TURBO_PL1) = msr.lo;
435 MCHBAR32(MC_TURBO_PL2) = msr.hi;
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700436 }
437
Stefan Reinauer00636b02012-04-04 00:08:51 +0200438 /* Set here before graphics PM init */
Angel Pons88521882020-01-05 20:21:20 +0100439 MCHBAR32(MMIO_PAVP_CTL) = 0x00100001;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200440}
441
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200442void northbridge_write_smram(u8 smram)
443{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300444 pci_write_config8(pcidev_on_root(0, 0), SMRAM, smram);
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200445}
446
Stefan Reinauer00636b02012-04-04 00:08:51 +0200447static struct pci_operations intel_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530448 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200449};
450
451static struct device_operations mc_ops = {
452 .read_resources = mc_read_resources,
Kyösti Mälkki27198ac2016-12-02 14:38:13 +0200453 .set_resources = pci_dev_set_resources,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200454 .enable_resources = pci_dev_enable_resources,
455 .init = northbridge_init,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200456 .scan_bus = 0,
457 .ops_pci = &intel_pci_ops,
Vladimir Serbinenko0a669912014-10-05 14:34:17 +0200458 .acpi_fill_ssdt_generator = generate_cpu_entries,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200459};
460
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600461static const unsigned short pci_device_ids[] = {
Jonathan A. Kollaschd346a192020-02-11 09:03:48 -0600462 0x0100, 0x0104, 0x0108, /* Sandy Bridge */
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600463 0x0150, 0x0154, 0x0158, /* Ivy Bridge */
464 0
Walter Murphy496f4a02012-04-23 11:08:03 -0700465};
466
Stefan Reinauer00636b02012-04-04 00:08:51 +0200467static const struct pci_driver mc_driver __pci_driver = {
468 .ops = &mc_ops,
469 .vendor = PCI_VENDOR_ID_INTEL,
Jonathan A. Kollaschbda161b2020-02-13 13:04:48 -0600470 .devices = pci_device_ids,
Vagiz Trakhanov1dd448c2017-09-28 14:42:11 +0000471};
472
Stefan Reinauer00636b02012-04-04 00:08:51 +0200473static struct device_operations cpu_bus_ops = {
Edward O'Callaghan9f744622014-10-31 08:12:34 +1100474 .read_resources = DEVICE_NOOP,
475 .set_resources = DEVICE_NOOP,
476 .enable_resources = DEVICE_NOOP,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300477 .init = mp_cpu_bus_init,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200478 .scan_bus = 0,
479};
480
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100481static void enable_dev(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200482{
483 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800484 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200485 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800486 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200487 dev->ops = &cpu_bus_ops;
488 }
489}
490
491struct chip_operations northbridge_intel_sandybridge_ops = {
Damien Zammit35170382014-10-29 00:11:53 +1100492 CHIP_NAME("Intel SandyBridge/IvyBridge integrated Northbridge")
Stefan Reinauer00636b02012-04-04 00:08:51 +0200493 .enable_dev = enable_dev,
494};