blob: d8c8799de5303fa1b7cb086fe5afa267cb1c1832 [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 */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010036
37static void add_fixed_resources(struct device *dev, int index)
38{
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010039 /* 0xe0000000-0xf0000000 PCIe config.
40 0xfed10000-0xfed14000 MCH
41 0xfed17000-0xfed18000 HECI
42 0xfed18000-0xfed19000 DMI
43 0xfed19000-0xfed1a000 EPBAR
44 0xfed1c000-0xfed20000 RCBA
45 0xfed90000-0xfed94000 IOMMU
46 0xff800000-0xffffffff ROM. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010047
Arthur Heymans5acb1a02023-07-05 07:57:27 +020048 mmio_range(dev, index++, HPET_BASE_ADDRESS, 0x00100000);
Kyösti Mälkki8ee11b32021-06-27 21:08:32 +030049 mmio_from_to(dev, index++, 0xa0000, 0xc0000);
50 reserved_ram_from_to(dev, index++, 0xc0000, 1 * MiB);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010051}
52
Julius Wernercd49cce2019-03-05 16:53:33 -080053#if CONFIG(HAVE_ACPI_TABLES)
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020054static const char *northbridge_acpi_name(const struct device *dev)
55{
56 if (dev->path.type == DEVICE_PATH_DOMAIN)
57 return "PCI0";
58
Fabio Aiuto61ed4ef2022-09-30 14:55:53 +020059 if (!is_pci_dev_on_bus(dev, 0))
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020060 return NULL;
61
62 switch (dev->path.pci.devfn) {
63 case PCI_DEVFN(0, 0):
64 return "MCHC";
65 }
66
67 return NULL;
68}
69#endif
70
Arthur Heymans62eb94c2022-11-07 08:34:41 +010071struct device_operations ironlake_pci_domain_ops = {
Angel Pons43bcc7b2020-06-22 18:11:31 +020072 .read_resources = pci_domain_read_resources,
73 .set_resources = pci_domain_set_resources,
Arthur Heymans0b0113f2023-08-31 17:09:28 +020074 .scan_bus = pci_host_bridge_scan_bus,
Julius Wernercd49cce2019-03-05 16:53:33 -080075#if CONFIG(HAVE_ACPI_TABLES)
Angel Pons43bcc7b2020-06-22 18:11:31 +020076 .acpi_name = northbridge_acpi_name,
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020077#endif
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010078};
79
Elyes HAOUAS706aabc2018-02-09 08:49:32 +010080static void mc_read_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010081{
Nico Huber308540d2020-09-13 21:59:14 +020082 uint32_t tseg_base, tseg_end;
Angel Pons9333b742020-07-22 16:04:15 +020083 uint64_t touud;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010084 uint16_t reg16;
Nico Huber08e8e472020-09-13 21:56:50 +020085 int index = 3;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010086
87 pci_dev_read_resources(dev);
88
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +020089 mmconf_resource(dev, 0x50);
90
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030091 tseg_base = pci_read_config32(pcidev_on_root(0, 0), TSEG);
Nico Huber308540d2020-09-13 21:59:14 +020092 tseg_end = tseg_base + CONFIG_SMM_TSEG_SIZE;
Angel Pons9333b742020-07-22 16:04:15 +020093 touud = pci_read_config16(pcidev_on_root(0, 0),
Angel Pons16fe1e02020-07-22 16:12:33 +020094 TOUUD);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010095
96 printk(BIOS_DEBUG, "ram_before_4g_top: 0x%x\n", tseg_base);
Angel Pons9333b742020-07-22 16:04:15 +020097 printk(BIOS_DEBUG, "TOUUD: 0x%x\n", (unsigned int)touud);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010098
99 /* Report the memory regions */
Arthur Heymans5acb1a02023-07-05 07:57:27 +0200100 ram_range(dev, index++, 0, 0xa0000);
101 ram_from_to(dev, index++, 1 * MiB, tseg_base);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100102
Arthur Heymans5acb1a02023-07-05 07:57:27 +0200103 mmio_range(dev, index++, tseg_base, CONFIG_SMM_TSEG_SIZE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100104
Angel Pons16fe1e02020-07-22 16:12:33 +0200105 reg16 = pci_read_config16(pcidev_on_root(0, 0), GGC);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100106 const int uma_sizes_gtt[16] =
107 { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4, 42, 42, 42, 42 };
108 /* Igd memory */
109 const int uma_sizes_igd[16] = {
110 0, 0, 0, 0, 0, 32, 48, 64, 128, 256, 96, 160, 224, 352, 256, 512
111 };
112 u32 igd_base, gtt_base;
113 int uma_size_igd, uma_size_gtt;
114
115 uma_size_igd = uma_sizes_igd[(reg16 >> 4) & 0xF];
116 uma_size_gtt = uma_sizes_gtt[(reg16 >> 8) & 0xF];
117
118 igd_base =
Angel Pons16fe1e02020-07-22 16:12:33 +0200119 pci_read_config32(pcidev_on_root(0, 0), IGD_BASE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100120 gtt_base =
Angel Pons16fe1e02020-07-22 16:12:33 +0200121 pci_read_config32(pcidev_on_root(0, 0), GTT_BASE);
Nico Huber308540d2020-09-13 21:59:14 +0200122 if (gtt_base > tseg_end) {
123 /* Reserve the gap. MMIO doesn't work in this range. Keep
124 it uncacheable, though, for easier MTRR allocation. */
Arthur Heymans5acb1a02023-07-05 07:57:27 +0200125 mmio_from_to(dev, index++, tseg_end, gtt_base);
Nico Huber308540d2020-09-13 21:59:14 +0200126 }
Arthur Heymans5acb1a02023-07-05 07:57:27 +0200127 mmio_range(dev, index++, gtt_base, uma_size_gtt * MiB);
128 mmio_range(dev, index++, igd_base, uma_size_igd * MiB);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100129
Kyösti Mälkki0a18d642021-06-28 21:43:31 +0300130 upper_ram_end(dev, index++, touud * MiB);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100131
132 /* This memory is not DMA-capable. */
Angel Pons9333b742020-07-22 16:04:15 +0200133 if (touud >= 8192 - 64)
Arthur Heymans5acb1a02023-07-05 07:57:27 +0200134 bad_ram_range(dev, index++, 0x1fc000000ULL, 0x004000000);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100135
Nico Huber08e8e472020-09-13 21:56:50 +0200136 add_fixed_resources(dev, index);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100137}
138
Angel Ponsecdbc842020-06-22 17:28:42 +0200139static void northbridge_init(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100140{
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100141 /* Clear error status bits */
Angel Ponsdea722b2021-03-26 14:11:12 +0100142 dmibar_write32(DMIUESTS, 0xffffffff);
143 dmibar_write32(DMICESTS, 0xffffffff);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100144
Angel Ponsdea722b2021-03-26 14:11:12 +0100145 dmibar_setbits32(DMILLTC, 1 << 29);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100146
Angel Ponsdea722b2021-03-26 14:11:12 +0100147 dmibar_setbits32(0x1f8, 1 << 16);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100148
Angel Ponsdea722b2021-03-26 14:11:12 +0100149 dmibar_setbits32(DMILCTL, 1 << 1 | 1 << 0);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100150}
151
Arthur Heymans28bca052019-10-01 21:20:33 +0200152/* Disable unused PEG devices based on devicetree before PCI enumeration */
Angel Pons95de2312020-02-17 13:08:53 +0100153static void ironlake_init(void *const chip_info)
Arthur Heymans28bca052019-10-01 21:20:33 +0200154{
155 u32 deven_mask = UINT32_MAX;
156 const struct device *dev;
157
158 dev = pcidev_on_root(1, 0);
159 if (!dev || !dev->enabled) {
160 printk(BIOS_DEBUG, "Disabling PEG10.\n");
161 deven_mask &= ~DEVEN_PEG10;
162 }
163 dev = pcidev_on_root(2, 0);
164 if (!dev || !dev->enabled) {
165 printk(BIOS_DEBUG, "Disabling IGD.\n");
166 deven_mask &= ~DEVEN_IGD;
167 }
168 const struct device *const d0f0 = pcidev_on_root(0, 0);
169 if (d0f0)
Angel Pons16fe1e02020-07-22 16:12:33 +0200170 pci_update_config32(d0f0, DEVEN, deven_mask, 0);
Arthur Heymans28bca052019-10-01 21:20:33 +0200171}
172
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100173static struct device_operations mc_ops = {
Angel Pons43bcc7b2020-06-22 18:11:31 +0200174 .read_resources = mc_read_resources,
175 .set_resources = pci_dev_set_resources,
176 .enable_resources = pci_dev_enable_resources,
177 .init = northbridge_init,
178 .acpi_fill_ssdt = generate_cpu_entries,
179 .ops_pci = &pci_dev_ops_pci,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100180};
181
Angel Pons6642b442020-09-21 21:03:46 +0200182/*
183 * The host bridge PCI device ID can be changed by the firmware. There
184 * is no documentation about it, though. There's 'official' IDs, which
185 * appear in spec updates and Windows drivers, and 'mysterious' IDs,
186 * which Intel doesn't want OSes to know about and thus are not listed.
187 *
188 * The current coreboot code seems to be able to change the device ID
189 * of the host bridge, but it seems to be missing a warm reset so that
190 * the device ID changes. Account for the 'mysterious' device IDs in
191 * the northbridge driver, so that booting an OS has a chance to work.
192 */
193static const unsigned short pci_device_ids[] = {
194 /* 'Official' DIDs */
195 0x0040, /* Clarkdale */
196 0x0044, /* Arrandale */
197 0x0048, /* Unknown, but it appears in OS drivers and raminit */
198
199 /* Mysterious DIDs, taken from Linux' intel-agp driver */
200 0x0062, /* Arrandale A-? */
201 0x0069, /* Clarkdale K-0 */
202 0x006a, /* Arrandale K-0 */
203 0
204};
205
206static const struct pci_driver mc_driver_ilk __pci_driver = {
207 .ops = &mc_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100208 .vendor = PCI_VID_INTEL,
Angel Pons6642b442020-09-21 21:03:46 +0200209 .devices = pci_device_ids,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100210};
211
Arthur Heymans62eb94c2022-11-07 08:34:41 +0100212struct device_operations ironlake_cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200213 .read_resources = noop_read_resources,
214 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300215 .init = mp_cpu_bus_init,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100216};
217
Angel Pons95de2312020-02-17 13:08:53 +0100218struct chip_operations northbridge_intel_ironlake_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900219 .name = "Intel Ironlake integrated Northbridge",
Angel Pons95de2312020-02-17 13:08:53 +0100220 .init = ironlake_init,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100221};