blob: d2f5c79fe15a200a305b7b69b1825e1247a045b1 [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>
Felix Held928a9c82022-02-24 00:51:11 +01005#include <arch/hpet.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02006#include <device/pci_ops.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01007#include <stdint.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01008#include <cpu/intel/model_2065x/model_2065x.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01009#include <device/device.h>
10#include <device/pci.h>
11#include <device/pci_ids.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010012#include "chip.h"
Arthur Heymans64734732021-01-18 00:30:23 +010013#include <commonlib/bsd/helpers.h>
Angel Pons95de2312020-02-17 13:08:53 +010014#include "ironlake.h"
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030015#include <cpu/intel/smm_reloc.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010016
17static int bridge_revision_id = -1;
18
19int bridge_silicon_revision(void)
20{
21 if (bridge_revision_id < 0) {
Angel Pons43bcc7b2020-06-22 18:11:31 +020022 uint8_t stepping = cpuid_eax(1) & 0x0f;
23 uint8_t bridge_id = pci_read_config16(pcidev_on_root(0, 0), PCI_DEVICE_ID);
24 bridge_revision_id = (bridge_id & 0xf0) | stepping;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010025 }
26 return bridge_revision_id;
27}
28
Angel Pons43bcc7b2020-06-22 18:11:31 +020029/*
30 * Reserve everything between A segment and 1MB:
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010031 *
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;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010037
38static void add_fixed_resources(struct device *dev, int index)
39{
40 struct resource *resource;
41
42 /* 0xe0000000-0xf0000000 PCIe config.
43 0xfed10000-0xfed14000 MCH
44 0xfed17000-0xfed18000 HECI
45 0xfed18000-0xfed19000 DMI
46 0xfed19000-0xfed1a000 EPBAR
47 0xfed1c000-0xfed20000 RCBA
48 0xfed90000-0xfed94000 IOMMU
49 0xff800000-0xffffffff ROM. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010050
51 resource = new_resource(dev, index++);
Felix Held928a9c82022-02-24 00:51:11 +010052 resource->base = (resource_t) HPET_BASE_ADDRESS;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010053 resource->size = (resource_t) 0x00100000;
Angel Pons43bcc7b2020-06-22 18:11:31 +020054 resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE | IORESOURCE_FIXED |
55 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010056
Kyösti Mälkki27d62992022-05-24 20:25:58 +030057 mmio_resource_kb(dev, index++, legacy_hole_base_k, (0xc0000 / KiB) - legacy_hole_base_k);
58 reserved_ram_resource_kb(dev, index++, 0xc0000 / KiB, (0x100000 - 0xc0000) / KiB);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010059}
60
Julius Wernercd49cce2019-03-05 16:53:33 -080061#if CONFIG(HAVE_ACPI_TABLES)
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020062static const char *northbridge_acpi_name(const struct device *dev)
63{
64 if (dev->path.type == DEVICE_PATH_DOMAIN)
65 return "PCI0";
66
67 if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
68 return NULL;
69
70 switch (dev->path.pci.devfn) {
71 case PCI_DEVFN(0, 0):
72 return "MCHC";
73 }
74
75 return NULL;
76}
77#endif
78
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010079static struct device_operations pci_domain_ops = {
Angel Pons43bcc7b2020-06-22 18:11:31 +020080 .read_resources = pci_domain_read_resources,
81 .set_resources = pci_domain_set_resources,
82 .scan_bus = pci_domain_scan_bus,
Julius Wernercd49cce2019-03-05 16:53:33 -080083#if CONFIG(HAVE_ACPI_TABLES)
Angel Pons43bcc7b2020-06-22 18:11:31 +020084 .acpi_name = northbridge_acpi_name,
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020085#endif
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010086};
87
Elyes HAOUAS706aabc2018-02-09 08:49:32 +010088static void mc_read_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010089{
Nico Huber308540d2020-09-13 21:59:14 +020090 uint32_t tseg_base, tseg_end;
Angel Pons9333b742020-07-22 16:04:15 +020091 uint64_t touud;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010092 uint16_t reg16;
Nico Huber08e8e472020-09-13 21:56:50 +020093 int index = 3;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010094
95 pci_dev_read_resources(dev);
96
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020097 mmconf_resource(dev, 0x50);
98
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030099 tseg_base = pci_read_config32(pcidev_on_root(0, 0), TSEG);
Nico Huber308540d2020-09-13 21:59:14 +0200100 tseg_end = tseg_base + CONFIG_SMM_TSEG_SIZE;
Angel Pons9333b742020-07-22 16:04:15 +0200101 touud = pci_read_config16(pcidev_on_root(0, 0),
Angel Pons16fe1e02020-07-22 16:12:33 +0200102 TOUUD);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100103
104 printk(BIOS_DEBUG, "ram_before_4g_top: 0x%x\n", tseg_base);
Angel Pons9333b742020-07-22 16:04:15 +0200105 printk(BIOS_DEBUG, "TOUUD: 0x%x\n", (unsigned int)touud);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100106
107 /* Report the memory regions */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300108 ram_resource_kb(dev, index++, 0, 0xa0000 / KiB);
109 ram_resource_kb(dev, index++, 1 * MiB / KiB, (tseg_base - 1 * MiB) / KiB);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100110
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300111 mmio_resource_kb(dev, index++, tseg_base / KiB, CONFIG_SMM_TSEG_SIZE / KiB);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100112
Angel Pons16fe1e02020-07-22 16:12:33 +0200113 reg16 = pci_read_config16(pcidev_on_root(0, 0), GGC);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100114 const int uma_sizes_gtt[16] =
115 { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4, 42, 42, 42, 42 };
116 /* Igd memory */
117 const int uma_sizes_igd[16] = {
118 0, 0, 0, 0, 0, 32, 48, 64, 128, 256, 96, 160, 224, 352, 256, 512
119 };
120 u32 igd_base, gtt_base;
121 int uma_size_igd, uma_size_gtt;
122
123 uma_size_igd = uma_sizes_igd[(reg16 >> 4) & 0xF];
124 uma_size_gtt = uma_sizes_gtt[(reg16 >> 8) & 0xF];
125
126 igd_base =
Angel Pons16fe1e02020-07-22 16:12:33 +0200127 pci_read_config32(pcidev_on_root(0, 0), IGD_BASE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100128 gtt_base =
Angel Pons16fe1e02020-07-22 16:12:33 +0200129 pci_read_config32(pcidev_on_root(0, 0), GTT_BASE);
Nico Huber308540d2020-09-13 21:59:14 +0200130 if (gtt_base > tseg_end) {
131 /* Reserve the gap. MMIO doesn't work in this range. Keep
132 it uncacheable, though, for easier MTRR allocation. */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300133 mmio_resource_kb(dev, index++, tseg_end / KiB, (gtt_base - tseg_end) / KiB);
Nico Huber308540d2020-09-13 21:59:14 +0200134 }
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300135 mmio_resource_kb(dev, index++, gtt_base / KiB, uma_size_gtt * KiB);
136 mmio_resource_kb(dev, index++, igd_base / KiB, uma_size_igd * KiB);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100137
Angel Pons9333b742020-07-22 16:04:15 +0200138 if (touud > 4096)
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300139 ram_resource_kb(dev, index++, (4096 * KiB), ((touud - 4096) * KiB));
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100140
141 /* This memory is not DMA-capable. */
Angel Pons9333b742020-07-22 16:04:15 +0200142 if (touud >= 8192 - 64)
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300143 bad_ram_resource_kb(dev, index++, 0x1fc000000ULL / KiB, 0x004000000 / KiB);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100144
Nico Huber08e8e472020-09-13 21:56:50 +0200145 add_fixed_resources(dev, index);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100146}
147
Angel Ponsecdbc842020-06-22 17:28:42 +0200148static void northbridge_init(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100149{
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100150 /* Clear error status bits */
Angel Ponsdea722b2021-03-26 14:11:12 +0100151 dmibar_write32(DMIUESTS, 0xffffffff);
152 dmibar_write32(DMICESTS, 0xffffffff);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100153
Angel Ponsdea722b2021-03-26 14:11:12 +0100154 dmibar_setbits32(DMILLTC, 1 << 29);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100155
Angel Ponsdea722b2021-03-26 14:11:12 +0100156 dmibar_setbits32(0x1f8, 1 << 16);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100157
Angel Ponsdea722b2021-03-26 14:11:12 +0100158 dmibar_setbits32(DMILCTL, 1 << 1 | 1 << 0);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100159}
160
Arthur Heymans28bca052019-10-01 21:20:33 +0200161/* Disable unused PEG devices based on devicetree before PCI enumeration */
Angel Pons95de2312020-02-17 13:08:53 +0100162static void ironlake_init(void *const chip_info)
Arthur Heymans28bca052019-10-01 21:20:33 +0200163{
164 u32 deven_mask = UINT32_MAX;
165 const struct device *dev;
166
167 dev = pcidev_on_root(1, 0);
168 if (!dev || !dev->enabled) {
169 printk(BIOS_DEBUG, "Disabling PEG10.\n");
170 deven_mask &= ~DEVEN_PEG10;
171 }
172 dev = pcidev_on_root(2, 0);
173 if (!dev || !dev->enabled) {
174 printk(BIOS_DEBUG, "Disabling IGD.\n");
175 deven_mask &= ~DEVEN_IGD;
176 }
177 const struct device *const d0f0 = pcidev_on_root(0, 0);
178 if (d0f0)
Angel Pons16fe1e02020-07-22 16:12:33 +0200179 pci_update_config32(d0f0, DEVEN, deven_mask, 0);
Arthur Heymans28bca052019-10-01 21:20:33 +0200180
181}
182
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100183static struct device_operations mc_ops = {
Angel Pons43bcc7b2020-06-22 18:11:31 +0200184 .read_resources = mc_read_resources,
185 .set_resources = pci_dev_set_resources,
186 .enable_resources = pci_dev_enable_resources,
187 .init = northbridge_init,
188 .acpi_fill_ssdt = generate_cpu_entries,
189 .ops_pci = &pci_dev_ops_pci,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100190};
191
Angel Pons6642b442020-09-21 21:03:46 +0200192/*
193 * The host bridge PCI device ID can be changed by the firmware. There
194 * is no documentation about it, though. There's 'official' IDs, which
195 * appear in spec updates and Windows drivers, and 'mysterious' IDs,
196 * which Intel doesn't want OSes to know about and thus are not listed.
197 *
198 * The current coreboot code seems to be able to change the device ID
199 * of the host bridge, but it seems to be missing a warm reset so that
200 * the device ID changes. Account for the 'mysterious' device IDs in
201 * the northbridge driver, so that booting an OS has a chance to work.
202 */
203static const unsigned short pci_device_ids[] = {
204 /* 'Official' DIDs */
205 0x0040, /* Clarkdale */
206 0x0044, /* Arrandale */
207 0x0048, /* Unknown, but it appears in OS drivers and raminit */
208
209 /* Mysterious DIDs, taken from Linux' intel-agp driver */
210 0x0062, /* Arrandale A-? */
211 0x0069, /* Clarkdale K-0 */
212 0x006a, /* Arrandale K-0 */
213 0
214};
215
216static const struct pci_driver mc_driver_ilk __pci_driver = {
217 .ops = &mc_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100218 .vendor = PCI_VID_INTEL,
Angel Pons6642b442020-09-21 21:03:46 +0200219 .devices = pci_device_ids,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100220};
221
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100222static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200223 .read_resources = noop_read_resources,
224 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300225 .init = mp_cpu_bus_init,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100226};
227
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100228static void enable_dev(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100229{
230 /* Set the operations if it is a special bus type */
231 if (dev->path.type == DEVICE_PATH_DOMAIN) {
232 dev->ops = &pci_domain_ops;
233 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
234 dev->ops = &cpu_bus_ops;
235 }
236}
237
Angel Pons95de2312020-02-17 13:08:53 +0100238struct chip_operations northbridge_intel_ironlake_ops = {
Angel Pons9d7431c2020-10-22 23:55:39 +0200239 CHIP_NAME("Intel Ironlake integrated Northbridge")
Arthur Heymans28bca052019-10-01 21:20:33 +0200240 .enable_dev = enable_dev,
Angel Pons95de2312020-02-17 13:08:53 +0100241 .init = ironlake_init,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100242};