blob: e01bf7dae139d217659ceedf16207fa23961cdd0 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01002
3#include <console/console.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07004#include <acpi/acpi.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01006#include <stdint.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01007#include <cpu/intel/model_2065x/model_2065x.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01008#include <device/device.h>
9#include <device/pci.h>
10#include <device/pci_ids.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010011#include "chip.h"
Arthur Heymans64734732021-01-18 00:30:23 +010012#include <commonlib/bsd/helpers.h>
Angel Pons95de2312020-02-17 13:08:53 +010013#include "ironlake.h"
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030014#include <cpu/intel/smm_reloc.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010015
16static int bridge_revision_id = -1;
17
18int bridge_silicon_revision(void)
19{
20 if (bridge_revision_id < 0) {
Angel Pons43bcc7b2020-06-22 18:11:31 +020021 uint8_t stepping = cpuid_eax(1) & 0x0f;
22 uint8_t bridge_id = pci_read_config16(pcidev_on_root(0, 0), PCI_DEVICE_ID);
23 bridge_revision_id = (bridge_id & 0xf0) | stepping;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010024 }
25 return bridge_revision_id;
26}
27
Angel Pons43bcc7b2020-06-22 18:11:31 +020028/*
29 * Reserve everything between A segment and 1MB:
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010030 *
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;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010036
37static void add_fixed_resources(struct device *dev, int index)
38{
39 struct resource *resource;
40
41 /* 0xe0000000-0xf0000000 PCIe config.
42 0xfed10000-0xfed14000 MCH
43 0xfed17000-0xfed18000 HECI
44 0xfed18000-0xfed19000 DMI
45 0xfed19000-0xfed1a000 EPBAR
46 0xfed1c000-0xfed20000 RCBA
47 0xfed90000-0xfed94000 IOMMU
48 0xff800000-0xffffffff ROM. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010049
50 resource = new_resource(dev, index++);
51 resource->base = (resource_t) 0xfed00000;
52 resource->size = (resource_t) 0x00100000;
Angel Pons43bcc7b2020-06-22 18:11:31 +020053 resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE | IORESOURCE_FIXED |
54 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010055
Arthur Heymans64734732021-01-18 00:30:23 +010056 mmio_resource(dev, index++, legacy_hole_base_k, (0xc0000 / KiB) - legacy_hole_base_k);
57 reserved_ram_resource(dev, index++, 0xc0000 / KiB, (0x100000 - 0xc0000) / KiB);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010058}
59
Julius Wernercd49cce2019-03-05 16:53:33 -080060#if CONFIG(HAVE_ACPI_TABLES)
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020061static const char *northbridge_acpi_name(const struct device *dev)
62{
63 if (dev->path.type == DEVICE_PATH_DOMAIN)
64 return "PCI0";
65
66 if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
67 return NULL;
68
69 switch (dev->path.pci.devfn) {
70 case PCI_DEVFN(0, 0):
71 return "MCHC";
72 }
73
74 return NULL;
75}
76#endif
77
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010078static struct device_operations pci_domain_ops = {
Angel Pons43bcc7b2020-06-22 18:11:31 +020079 .read_resources = pci_domain_read_resources,
80 .set_resources = pci_domain_set_resources,
81 .scan_bus = pci_domain_scan_bus,
Julius Wernercd49cce2019-03-05 16:53:33 -080082#if CONFIG(HAVE_ACPI_TABLES)
Angel Pons43bcc7b2020-06-22 18:11:31 +020083 .acpi_name = northbridge_acpi_name,
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020084#endif
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010085};
86
Elyes HAOUAS706aabc2018-02-09 08:49:32 +010087static void mc_read_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010088{
Nico Huber308540d2020-09-13 21:59:14 +020089 uint32_t tseg_base, tseg_end;
Angel Pons9333b742020-07-22 16:04:15 +020090 uint64_t touud;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010091 uint16_t reg16;
Nico Huber08e8e472020-09-13 21:56:50 +020092 int index = 3;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010093
94 pci_dev_read_resources(dev);
95
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020096 mmconf_resource(dev, 0x50);
97
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030098 tseg_base = pci_read_config32(pcidev_on_root(0, 0), TSEG);
Nico Huber308540d2020-09-13 21:59:14 +020099 tseg_end = tseg_base + CONFIG_SMM_TSEG_SIZE;
Angel Pons9333b742020-07-22 16:04:15 +0200100 touud = pci_read_config16(pcidev_on_root(0, 0),
Angel Pons16fe1e02020-07-22 16:12:33 +0200101 TOUUD);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100102
103 printk(BIOS_DEBUG, "ram_before_4g_top: 0x%x\n", tseg_base);
Angel Pons9333b742020-07-22 16:04:15 +0200104 printk(BIOS_DEBUG, "TOUUD: 0x%x\n", (unsigned int)touud);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100105
106 /* Report the memory regions */
Arthur Heymans64734732021-01-18 00:30:23 +0100107 ram_resource(dev, index++, 0, 0xa0000 / KiB);
108 ram_resource(dev, index++, 0xc0000 / KiB, (tseg_base - 0xc0000) / KiB);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100109
Arthur Heymans64734732021-01-18 00:30:23 +0100110 mmio_resource(dev, index++, tseg_base / KiB, CONFIG_SMM_TSEG_SIZE / KiB);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100111
Angel Pons16fe1e02020-07-22 16:12:33 +0200112 reg16 = pci_read_config16(pcidev_on_root(0, 0), GGC);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100113 const int uma_sizes_gtt[16] =
114 { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4, 42, 42, 42, 42 };
115 /* Igd memory */
116 const int uma_sizes_igd[16] = {
117 0, 0, 0, 0, 0, 32, 48, 64, 128, 256, 96, 160, 224, 352, 256, 512
118 };
119 u32 igd_base, gtt_base;
120 int uma_size_igd, uma_size_gtt;
121
122 uma_size_igd = uma_sizes_igd[(reg16 >> 4) & 0xF];
123 uma_size_gtt = uma_sizes_gtt[(reg16 >> 8) & 0xF];
124
125 igd_base =
Angel Pons16fe1e02020-07-22 16:12:33 +0200126 pci_read_config32(pcidev_on_root(0, 0), IGD_BASE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100127 gtt_base =
Angel Pons16fe1e02020-07-22 16:12:33 +0200128 pci_read_config32(pcidev_on_root(0, 0), GTT_BASE);
Nico Huber308540d2020-09-13 21:59:14 +0200129 if (gtt_base > tseg_end) {
130 /* Reserve the gap. MMIO doesn't work in this range. Keep
131 it uncacheable, though, for easier MTRR allocation. */
Arthur Heymans64734732021-01-18 00:30:23 +0100132 mmio_resource(dev, index++, tseg_end / KiB, (gtt_base - tseg_end) / KiB);
Nico Huber308540d2020-09-13 21:59:14 +0200133 }
Arthur Heymans64734732021-01-18 00:30:23 +0100134 mmio_resource(dev, index++, gtt_base / KiB, uma_size_gtt * KiB);
135 mmio_resource(dev, index++, igd_base / KiB, uma_size_igd * KiB);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100136
Angel Pons9333b742020-07-22 16:04:15 +0200137 if (touud > 4096)
Arthur Heymans64734732021-01-18 00:30:23 +0100138 ram_resource(dev, index++, (4096 * KiB), ((touud - 4096) * KiB));
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100139
140 /* This memory is not DMA-capable. */
Angel Pons9333b742020-07-22 16:04:15 +0200141 if (touud >= 8192 - 64)
Arthur Heymans64734732021-01-18 00:30:23 +0100142 bad_ram_resource(dev, index++, 0x1fc000000ULL / KiB, 0x004000000 / KiB);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100143
Nico Huber08e8e472020-09-13 21:56:50 +0200144 add_fixed_resources(dev, index);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100145}
146
Angel Ponsecdbc842020-06-22 17:28:42 +0200147static void northbridge_init(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100148{
149 u32 reg32;
150
151 /* Clear error status bits */
Angel Pons3b264d02020-09-15 00:25:49 +0200152 DMIBAR32(DMIUESTS) = 0xffffffff;
153 DMIBAR32(DMICESTS) = 0xffffffff;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100154
Angel Pons3b264d02020-09-15 00:25:49 +0200155 reg32 = DMIBAR32(DMILLTC);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100156 reg32 |= (1 << 29);
Angel Pons3b264d02020-09-15 00:25:49 +0200157 DMIBAR32(DMILLTC) = reg32;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100158
Angel Ponsb6397072020-06-22 17:41:49 +0200159 reg32 = DMIBAR32(0x1f8);
160 reg32 |= (1 << 16);
161 DMIBAR32(0x1f8) = reg32;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100162
Angel Pons3b264d02020-09-15 00:25:49 +0200163 reg32 = DMIBAR32(DMILCTL);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100164 reg32 |= (1 << 1) | (1 << 0);
Angel Pons3b264d02020-09-15 00:25:49 +0200165 DMIBAR32(DMILCTL) = reg32;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100166}
167
Arthur Heymans28bca052019-10-01 21:20:33 +0200168/* Disable unused PEG devices based on devicetree before PCI enumeration */
Angel Pons95de2312020-02-17 13:08:53 +0100169static void ironlake_init(void *const chip_info)
Arthur Heymans28bca052019-10-01 21:20:33 +0200170{
171 u32 deven_mask = UINT32_MAX;
172 const struct device *dev;
173
174 dev = pcidev_on_root(1, 0);
175 if (!dev || !dev->enabled) {
176 printk(BIOS_DEBUG, "Disabling PEG10.\n");
177 deven_mask &= ~DEVEN_PEG10;
178 }
179 dev = pcidev_on_root(2, 0);
180 if (!dev || !dev->enabled) {
181 printk(BIOS_DEBUG, "Disabling IGD.\n");
182 deven_mask &= ~DEVEN_IGD;
183 }
184 const struct device *const d0f0 = pcidev_on_root(0, 0);
185 if (d0f0)
Angel Pons16fe1e02020-07-22 16:12:33 +0200186 pci_update_config32(d0f0, DEVEN, deven_mask, 0);
Arthur Heymans28bca052019-10-01 21:20:33 +0200187
188}
189
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100190static struct device_operations mc_ops = {
Angel Pons43bcc7b2020-06-22 18:11:31 +0200191 .read_resources = mc_read_resources,
192 .set_resources = pci_dev_set_resources,
193 .enable_resources = pci_dev_enable_resources,
194 .init = northbridge_init,
195 .acpi_fill_ssdt = generate_cpu_entries,
196 .ops_pci = &pci_dev_ops_pci,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100197};
198
Angel Pons6642b442020-09-21 21:03:46 +0200199/*
200 * The host bridge PCI device ID can be changed by the firmware. There
201 * is no documentation about it, though. There's 'official' IDs, which
202 * appear in spec updates and Windows drivers, and 'mysterious' IDs,
203 * which Intel doesn't want OSes to know about and thus are not listed.
204 *
205 * The current coreboot code seems to be able to change the device ID
206 * of the host bridge, but it seems to be missing a warm reset so that
207 * the device ID changes. Account for the 'mysterious' device IDs in
208 * the northbridge driver, so that booting an OS has a chance to work.
209 */
210static const unsigned short pci_device_ids[] = {
211 /* 'Official' DIDs */
212 0x0040, /* Clarkdale */
213 0x0044, /* Arrandale */
214 0x0048, /* Unknown, but it appears in OS drivers and raminit */
215
216 /* Mysterious DIDs, taken from Linux' intel-agp driver */
217 0x0062, /* Arrandale A-? */
218 0x0069, /* Clarkdale K-0 */
219 0x006a, /* Arrandale K-0 */
220 0
221};
222
223static const struct pci_driver mc_driver_ilk __pci_driver = {
224 .ops = &mc_ops,
225 .vendor = PCI_VENDOR_ID_INTEL,
226 .devices = pci_device_ids,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100227};
228
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100229static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200230 .read_resources = noop_read_resources,
231 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300232 .init = mp_cpu_bus_init,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100233};
234
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100235static void enable_dev(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100236{
237 /* Set the operations if it is a special bus type */
238 if (dev->path.type == DEVICE_PATH_DOMAIN) {
239 dev->ops = &pci_domain_ops;
240 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
241 dev->ops = &cpu_bus_ops;
242 }
243}
244
Angel Pons95de2312020-02-17 13:08:53 +0100245struct chip_operations northbridge_intel_ironlake_ops = {
Angel Pons9d7431c2020-10-22 23:55:39 +0200246 CHIP_NAME("Intel Ironlake integrated Northbridge")
Arthur Heymans28bca052019-10-01 21:20:33 +0200247 .enable_dev = enable_dev,
Angel Pons95de2312020-02-17 13:08:53 +0100248 .init = ironlake_init,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100249};