blob: 3db90865f768642c401cc99a29e6b988f35272f2 [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
Arthur Heymansf8daf862021-02-24 19:21:33 +01003#include <cpu/cpu.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +02004#include <console/console.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07005#include <acpi/acpi.h>
Arthur Heymansf8daf862021-02-24 19:21:33 +01006#include <acpi/acpigen.h>
Angel Pons20905cf2020-08-03 14:18:41 +02007#include <commonlib/helpers.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02008#include <device/pci_ops.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +02009#include <delay.h>
10#include <cpu/intel/model_206ax/model_206ax.h>
Duncan Laurie77dbbac2012-06-25 09:51:59 -070011#include <cpu/x86/msr.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020012#include <device/device.h>
13#include <device/pci.h>
14#include <device/pci_ids.h>
Angel Pons964d91f2020-12-07 13:11:17 +010015#include <types.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020016#include "chip.h"
17#include "sandybridge.h"
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030018#include <cpu/intel/smm_reloc.h>
Michał Żygowskiede87182021-11-21 11:53:42 +010019#include <security/intel/txt/txt_platform.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020020
Kyösti Mälkkif7bfc342013-10-18 11:02:46 +030021/* IGD UMA memory */
22static uint64_t uma_memory_base = 0;
23static uint64_t uma_memory_size = 0;
24
Angel Pons964d91f2020-12-07 13:11:17 +010025bool is_sandybridge(void)
Stefan Reinauer00636b02012-04-04 00:08:51 +020026{
Angel Pons964d91f2020-12-07 13:11:17 +010027 const uint16_t bridge_id = pci_read_config16(pcidev_on_root(0, 0), PCI_DEVICE_ID);
28
29 return (bridge_id & BASE_REV_MASK) == BASE_REV_SNB;
Stefan Reinauer00636b02012-04-04 00:08:51 +020030}
31
32/* Reserve everything between A segment and 1MB:
33 *
34 * 0xa0000 - 0xbffff: legacy VGA
35 * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel)
36 * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI
37 */
Stefan Reinauer00636b02012-04-04 00:08:51 +020038
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
Arthur Heymansfade7232022-11-07 08:47:33 +010055struct device_operations sandybridge_pci_domain_ops = {
Aaron Durbin1ca24332020-05-13 11:38:35 -060056 .read_resources = pci_domain_read_resources,
57 .set_resources = pci_domain_set_resources,
Arthur Heymans0b0113f2023-08-31 17:09:28 +020058 .scan_bus = pci_host_bridge_scan_bus,
Aaron Durbin1ca24332020-05-13 11:38:35 -060059 .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älkki27d62992022-05-24 20:25:58 +030065 mmio_resource_kb(dev, index++, uma_memory_base >> 10, uma_memory_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +020066
Kyösti Mälkki8ee11b32021-06-27 21:08:32 +030067 mmio_from_to(dev, index++, 0xa0000, 0xc0000);
68 reserved_ram_from_to(dev, index++, 0xc0000, 1 * MiB);
Kyösti Mälkki1ec5e742012-07-26 23:51:20 +030069
Angel Pons964d91f2020-12-07 13:11:17 +010070 if (is_sandybridge()) {
Nico Huber593e7de2015-11-04 15:46:00 +010071 /* Required for SandyBridge sighting 3715511 */
Kyösti Mälkki27d62992022-05-24 20:25:58 +030072 bad_ram_resource_kb(dev, index++, 0x20000000 >> 10, 0x00200000 >> 10);
73 bad_ram_resource_kb(dev, index++, 0x40000000 >> 10, 0x00200000 >> 10);
Nico Huber593e7de2015-11-04 15:46:00 +010074 }
Nico Huberbb9469c2015-10-21 11:49:23 +020075
76 /* Reserve IOMMU BARs */
Angel Pons7c49cb82020-03-16 23:17:32 +010077 const u32 capid0_a = pci_read_config32(dev, CAPID0_A);
Nico Huberbb9469c2015-10-21 11:49:23 +020078 if (!(capid0_a & (1 << 23))) {
Kyösti Mälkki27d62992022-05-24 20:25:58 +030079 mmio_resource_kb(dev, index++, GFXVT_BASE >> 10, 4);
80 mmio_resource_kb(dev, index++, VTVC0_BASE >> 10, 4);
Nico Huberbb9469c2015-10-21 11:49:23 +020081 }
Stefan Reinauer00636b02012-04-04 00:08:51 +020082}
83
Arthur Heymansf8daf862021-02-24 19:21:33 +010084static uint64_t get_touud(const struct device *dev)
85{
86 uint64_t touud = pci_read_config32(dev, TOUUD + 4);
87 touud <<= 32;
Arthur Heymans1233c432022-07-29 07:34:03 +020088 touud |= pci_read_config32(dev, TOUUD) & 0xfff00000;
Arthur Heymansf8daf862021-02-24 19:21:33 +010089 return touud;
90}
91
Aaron Durbin1ca24332020-05-13 11:38:35 -060092static void mc_read_resources(struct device *dev)
Stefan Reinauer00636b02012-04-04 00:08:51 +020093{
94 uint64_t tom, me_base, touud;
95 uint32_t tseg_base, uma_size, tolud;
Michał Żygowskiede87182021-11-21 11:53:42 +010096 uint32_t dpr_base_k, dpr_size_k;
Stefan Reinauer00636b02012-04-04 00:08:51 +020097 uint16_t ggc;
98 unsigned long long tomk;
Angel Pons14ea2fc2020-05-13 21:46:46 +020099 unsigned long index = 3;
Michał Żygowskiede87182021-11-21 11:53:42 +0100100 const union dpr_register dpr = txt_get_chipset_dpr();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200101
Aaron Durbin1ca24332020-05-13 11:38:35 -0600102 pci_dev_read_resources(dev);
103
Angel Pons10f9b832021-01-20 14:58:32 +0100104 mmconf_resource(dev, PCIEXBAR);
Aaron Durbin1ca24332020-05-13 11:38:35 -0600105
Stefan Reinauer00636b02012-04-04 00:08:51 +0200106 /* Total Memory 2GB example:
107 *
108 * 00000000 0000MB-1992MB 1992MB RAM (writeback)
109 * 7c800000 1992MB-2000MB 8MB TSEG (SMRR)
110 * 7d000000 2000MB-2002MB 2MB GFX GTT (uncached)
111 * 7d200000 2002MB-2034MB 32MB GFX UMA (uncached)
112 * 7f200000 2034MB TOLUD
113 * 7f800000 2040MB MEBASE
114 * 7f800000 2040MB-2048MB 8MB ME UMA (uncached)
115 * 80000000 2048MB TOM
116 * 100000000 4096MB-4102MB 6MB RAM (writeback)
117 *
118 * Total Memory 4GB example:
119 *
120 * 00000000 0000MB-2768MB 2768MB RAM (writeback)
121 * ad000000 2768MB-2776MB 8MB TSEG (SMRR)
122 * ad800000 2776MB-2778MB 2MB GFX GTT (uncached)
123 * ada00000 2778MB-2810MB 32MB GFX UMA (uncached)
124 * afa00000 2810MB TOLUD
125 * ff800000 4088MB MEBASE
126 * ff800000 4088MB-4096MB 8MB ME UMA (uncached)
127 * 100000000 4096MB TOM
128 * 100000000 4096MB-5374MB 1278MB RAM (writeback)
129 * 14fe00000 5368MB TOUUD
130 */
131
132 /* Top of Upper Usable DRAM, including remap */
Arthur Heymansf8daf862021-02-24 19:21:33 +0100133 touud = get_touud(dev);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200134
135 /* Top of Lower Usable DRAM */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600136 tolud = pci_read_config32(dev, TOLUD);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200137
138 /* Top of Memory - does not account for any UMA */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600139 tom = pci_read_config32(dev, TOM + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200140 tom <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600141 tom |= pci_read_config32(dev, TOM);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200142
143 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
144 touud, tolud, tom);
145
Angel Pons7c49cb82020-03-16 23:17:32 +0100146 /* ME UMA needs excluding if total memory < 4GB */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600147 me_base = pci_read_config32(dev, MESEG_BASE + 4);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200148 me_base <<= 32;
Aaron Durbin1ca24332020-05-13 11:38:35 -0600149 me_base |= pci_read_config32(dev, MESEG_BASE);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200150
151 printk(BIOS_DEBUG, "MEBASE 0x%llx\n", me_base);
152
Patrick Rudolph240766a2015-10-15 15:33:25 +0200153 uma_memory_base = tolud;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200154 tomk = tolud >> 10;
155 if (me_base == tolud) {
156 /* ME is from MEBASE-TOM */
157 uma_size = (tom - me_base) >> 10;
158 /* Increment TOLUD to account for ME as RAM */
159 tolud += uma_size << 10;
160 /* UMA starts at old TOLUD */
161 uma_memory_base = tomk * 1024ULL;
162 uma_memory_size = uma_size * 1024ULL;
163 printk(BIOS_DEBUG, "ME UMA base 0x%llx size %uM\n",
164 me_base, uma_size >> 10);
165 }
166
167 /* Graphics memory comes next */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600168 ggc = pci_read_config16(dev, GGC);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200169 if (!(ggc & 2)) {
170 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
171
172 /* Graphics memory */
173 uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL;
174 printk(BIOS_DEBUG, "%uM UMA", uma_size >> 10);
175 tomk -= uma_size;
176 uma_memory_base = tomk * 1024ULL;
177 uma_memory_size += uma_size * 1024ULL;
178
179 /* GTT Graphics Stolen Memory Size (GGMS) */
180 uma_size = ((ggc >> 8) & 0x3) * 1024ULL;
181 tomk -= uma_size;
182 uma_memory_base = tomk * 1024ULL;
183 uma_memory_size += uma_size * 1024ULL;
184 printk(BIOS_DEBUG, " and %uM GTT\n", uma_size >> 10);
185 }
186
187 /* Calculate TSEG size from its base which must be below GTT */
Aaron Durbin1ca24332020-05-13 11:38:35 -0600188 tseg_base = pci_read_config32(dev, TSEGMB);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200189 uma_size = (uma_memory_base - tseg_base) >> 10;
190 tomk -= uma_size;
191 uma_memory_base = tomk * 1024ULL;
192 uma_memory_size += uma_size * 1024ULL;
Angel Pons7c49cb82020-03-16 23:17:32 +0100193 printk(BIOS_DEBUG, "TSEG base 0x%08x size %uM\n", tseg_base, uma_size >> 10);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200194
Michał Żygowskiede87182021-11-21 11:53:42 +0100195 /* Calculate DMA Protected Region if enabled */
196 if (dpr.epm && dpr.size) {
197 dpr_size_k = dpr.size * MiB / KiB;
198 tomk -= dpr_size_k;
199 dpr_base_k = (tseg_base - dpr.size * MiB) / KiB;
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300200 reserved_ram_resource_kb(dev, index++, dpr_base_k, dpr_size_k);
Michał Żygowskiede87182021-11-21 11:53:42 +0100201 printk(BIOS_DEBUG, "DPR base 0x%08x size %uM\n", dpr_base_k * KiB, dpr.size);
202 }
203
Stefan Reinauer00636b02012-04-04 00:08:51 +0200204 printk(BIOS_INFO, "Available memory below 4GB: %lluM\n", tomk >> 10);
205
206 /* Report the memory regions */
Kyösti Mälkki8ee11b32021-06-27 21:08:32 +0300207 ram_from_to(dev, index++, 0, 0xa0000);
208 ram_from_to(dev, index++, 1 * MiB, tomk * KiB);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200209
210 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100211 * If >= 4GB installed, then memory from TOLUD to 4GB is remapped above TOM.
212 * TOUUD will account for both memory chunks.
Stefan Reinauer00636b02012-04-04 00:08:51 +0200213 */
Kyösti Mälkki0a18d642021-06-28 21:43:31 +0300214 upper_ram_end(dev, index++, touud);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200215
Angel Pons14ea2fc2020-05-13 21:46:46 +0200216 add_fixed_resources(dev, index++);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200217}
218
Stefan Reinauer00636b02012-04-04 00:08:51 +0200219static void northbridge_dmi_init(struct device *dev)
220{
Angel Pons964d91f2020-12-07 13:11:17 +0100221 const bool is_sandy = is_sandybridge();
222
Angel Pons77516ca2020-12-10 16:43:25 +0100223 const u8 stepping = cpu_stepping();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200224
Stefan Reinauer00636b02012-04-04 00:08:51 +0200225 /* Steps prior to DMI ASPM */
Angel Pons964d91f2020-12-07 13:11:17 +0100226 if (is_sandy) {
Angel Pons66780a02021-03-26 13:33:22 +0100227 dmibar_clrsetbits32(0x250, 7 << 20, 2 << 20);
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700228 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200229
Angel Pons66780a02021-03-26 13:33:22 +0100230 dmibar_setbits32(DMILLTC, 1 << 29);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200231
Angel Pons77516ca2020-12-10 16:43:25 +0100232 if (is_sandy && stepping == SNB_STEP_C0) {
Angel Pons66780a02021-03-26 13:33:22 +0100233 dmibar_clrsetbits32(0xbc8, 0xfff << 7, 0x7d3 << 7);
Angel Pons77516ca2020-12-10 16:43:25 +0100234 }
Angel Pons7c49cb82020-03-16 23:17:32 +0100235
Angel Pons77516ca2020-12-10 16:43:25 +0100236 if (!is_sandy || stepping >= SNB_STEP_D1) {
Angel Pons0acfe222021-03-26 13:08:23 +0100237 dmibar_clrsetbits32(0x1f8, 1 << 26, 1 << 16);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200238
Angel Pons66780a02021-03-26 13:33:22 +0100239 dmibar_setbits32(0x1fc, 1 << 12 | 1 << 23);
Angel Pons77516ca2020-12-10 16:43:25 +0100240
241 } else if (stepping >= SNB_STEP_D0) {
Angel Pons66780a02021-03-26 13:33:22 +0100242 dmibar_setbits32(0x1f8, 1 << 16);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200243 }
244
Angel Pons77516ca2020-12-10 16:43:25 +0100245 /* Clear error status bits */
Angel Pons66780a02021-03-26 13:33:22 +0100246 dmibar_write32(DMIUESTS, 0xffffffff);
247 dmibar_write32(DMICESTS, 0xffffffff);
Angel Pons77516ca2020-12-10 16:43:25 +0100248
249 if (!is_sandy)
Angel Pons66780a02021-03-26 13:33:22 +0100250 dmibar_write32(0xc34, 0xffffffff);
Angel Pons77516ca2020-12-10 16:43:25 +0100251
Stefan Reinauer00636b02012-04-04 00:08:51 +0200252 /* Enable ASPM on SNB link, should happen before PCH link */
Angel Pons964d91f2020-12-07 13:11:17 +0100253 if (is_sandy) {
Angel Pons66780a02021-03-26 13:33:22 +0100254 dmibar_setbits32(0xd04, 1 << 4);
Vincent Palatin0ff99b72012-03-28 16:10:29 -0700255 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200256
Angel Pons66780a02021-03-26 13:33:22 +0100257 dmibar_setbits32(DMILCTL, 1 << 1 | 1 << 0);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200258}
259
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200260/* Disable unused PEG devices based on devicetree */
261static void disable_peg(void)
262{
263 struct device *dev;
264 u32 reg;
265
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300266 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200267 reg = pci_read_config32(dev, DEVEN);
268
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300269 dev = pcidev_on_root(1, 2);
Nico Huber2dc15e92016-02-04 18:59:48 +0100270 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200271 printk(BIOS_DEBUG, "Disabling PEG12.\n");
272 reg &= ~DEVEN_PEG12;
273 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300274 dev = pcidev_on_root(1, 1);
Nico Huber2dc15e92016-02-04 18:59:48 +0100275 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200276 printk(BIOS_DEBUG, "Disabling PEG11.\n");
277 reg &= ~DEVEN_PEG11;
278 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300279 dev = pcidev_on_root(1, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100280 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200281 printk(BIOS_DEBUG, "Disabling PEG10.\n");
282 reg &= ~DEVEN_PEG10;
283 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300284 dev = pcidev_on_root(2, 0);
Nico Huber2dc15e92016-02-04 18:59:48 +0100285 if (!dev || !dev->enabled) {
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200286 printk(BIOS_DEBUG, "Disabling IGD.\n");
287 reg &= ~DEVEN_IGD;
288 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300289 dev = pcidev_on_root(4, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200290 if (!dev || !dev->enabled) {
291 printk(BIOS_DEBUG, "Disabling Device 4.\n");
292 reg &= ~DEVEN_D4EN;
293 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300294 dev = pcidev_on_root(6, 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 PEG60.\n");
297 reg &= ~DEVEN_PEG60;
298 }
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300299 dev = pcidev_on_root(7, 0);
Patrick Rudolphecd4be82017-05-14 12:40:50 +0200300 if (!dev || !dev->enabled) {
301 printk(BIOS_DEBUG, "Disabling Device 7.\n");
302 reg &= ~DEVEN_D7EN;
303 }
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200304
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300305 dev = pcidev_on_root(0, 0);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200306 pci_write_config32(dev, DEVEN, reg);
Angel Pons7c49cb82020-03-16 23:17:32 +0100307
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200308 if (!(reg & (DEVEN_PEG60 | DEVEN_PEG10 | DEVEN_PEG11 | DEVEN_PEG12))) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100309 /*
310 * Set the PEG clock gating bit. Disables the IO clock on all PEG devices.
311 *
Angel Pons78b43c82020-03-17 23:55:18 +0100312 * FIXME: Never clock gate on Ivy Bridge stepping A0!
Angel Pons7c49cb82020-03-16 23:17:32 +0100313 */
Angel Pons66780a02021-03-26 13:33:22 +0100314 mchbar_setbits32(PEGCTL, 1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200315 printk(BIOS_DEBUG, "Disabling PEG IO clock.\n");
Angel Pons78b43c82020-03-17 23:55:18 +0100316 } else {
Angel Pons66780a02021-03-26 13:33:22 +0100317 mchbar_clrbits32(PEGCTL, 1);
Patrick Rudolph3660c0f2015-07-28 08:01:02 +0200318 }
319}
320
Stefan Reinauer00636b02012-04-04 00:08:51 +0200321static void northbridge_init(struct device *dev)
322{
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700323 u32 bridge_type;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200324
325 northbridge_dmi_init(dev);
326
Angel Pons66780a02021-03-26 13:33:22 +0100327 bridge_type = mchbar_read32(SAPMTIMERS);
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700328 bridge_type &= ~0xff;
329
Angel Pons964d91f2020-12-07 13:11:17 +0100330 if (is_sandybridge()) {
331 /* 20h for Sandybridge */
332 bridge_type |= 0x20;
333 } else {
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700334 /* Enable Power Aware Interrupt Routing */
Angel Pons66780a02021-03-26 13:33:22 +0100335 mchbar_clrsetbits8(INTRDIRCTL, 0xf, 0x4); /* Clear 3:0, set Fixed Priority */
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700336
337 /* 30h for IvyBridge */
338 bridge_type |= 0x30;
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700339 }
Angel Pons66780a02021-03-26 13:33:22 +0100340 mchbar_write32(SAPMTIMERS, bridge_type);
Duncan Lauriefe7b5d22012-06-23 20:14:07 -0700341
Angel Pons7c49cb82020-03-16 23:17:32 +0100342 /* Turn off unused devices. Has to be done before setting BIOS_RESET_CPL. */
Patrick Rudolphaad34cd2015-10-21 18:05:01 +0200343 disable_peg();
344
Stefan Reinauer00636b02012-04-04 00:08:51 +0200345 /*
346 * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
347 * that BIOS has initialized memory and power management
348 */
Angel Pons66780a02021-03-26 13:33:22 +0100349 mchbar_setbits8(BIOS_RESET_CPL, 1 << 0);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200350 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
351
352 /* Configure turbo power limits 1ms after reset complete bit */
353 mdelay(1);
354 set_power_limits(28);
355
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700356 /*
Angel Pons7c49cb82020-03-16 23:17:32 +0100357 * CPUs with configurable TDP also need power limits set in MCHBAR.
358 * Use the same values from MSR_PKG_POWER_LIMIT.
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700359 */
360 if (cpu_config_tdp_levels()) {
361 msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT);
Angel Pons66780a02021-03-26 13:33:22 +0100362 mchbar_write32(MCH_PKG_POWER_LIMIT_LO, msr.lo);
363 mchbar_write32(MCH_PKG_POWER_LIMIT_HI, msr.hi);
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700364 }
365
Stefan Reinauer00636b02012-04-04 00:08:51 +0200366 /* Set here before graphics PM init */
Angel Pons66780a02021-03-26 13:33:22 +0100367 mchbar_write32(PAVP_MSG, 0x00100001);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200368}
369
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200370void northbridge_write_smram(u8 smram)
371{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300372 pci_write_config8(pcidev_on_root(0, 0), SMRAM, smram);
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200373}
374
Arthur Heymansf8daf862021-02-24 19:21:33 +0100375static void set_above_4g_pci(const struct device *dev)
376{
377 const uint64_t touud = get_touud(dev);
378 const uint64_t len = POWER_OF_2(cpu_phys_address_size()) - touud;
379
380 acpigen_write_scope("\\");
381 acpigen_write_name_qword("A4GB", touud);
382 acpigen_write_name_qword("A4GS", len);
383 acpigen_pop_len();
384
385 printk(BIOS_DEBUG, "PCI space above 4GB MMIO is at 0x%llx, len = 0x%llx\n", touud, len);
386}
387
388static void mc_gen_ssdt(const struct device *dev)
389{
Arthur Heymansf8daf862021-02-24 19:21:33 +0100390 set_above_4g_pci(dev);
391}
392
Felix Held4c4d1942023-11-16 14:03:09 +0100393struct device_operations sandybridge_host_bridge_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200394 .read_resources = mc_read_resources,
395 .set_resources = pci_dev_set_resources,
396 .enable_resources = pci_dev_enable_resources,
397 .init = northbridge_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200398 .ops_pci = &pci_dev_ops_pci,
Arthur Heymansf8daf862021-02-24 19:21:33 +0100399 .acpi_fill_ssdt = mc_gen_ssdt,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200400};
401
Arthur Heymansfade7232022-11-07 08:47:33 +0100402struct device_operations sandybridge_cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200403 .read_resources = noop_read_resources,
404 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300405 .init = mp_cpu_bus_init,
Arthur Heymanscdb26fd2021-11-15 20:12:02 +0100406 .acpi_fill_ssdt = generate_cpu_entries,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200407};
408
Stefan Reinauer00636b02012-04-04 00:08:51 +0200409struct chip_operations northbridge_intel_sandybridge_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900410 .name = "Intel SandyBridge/IvyBridge integrated Northbridge",
Stefan Reinauer00636b02012-04-04 00:08:51 +0200411};