Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 4 | #include <acpi/acpi.h> |
Felix Held | 928a9c8 | 2022-02-24 00:51:11 +0100 | [diff] [blame] | 5 | #include <arch/hpet.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 6 | #include <device/pci_ops.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 7 | #include <stdint.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 8 | #include <cpu/intel/model_2065x/model_2065x.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 9 | #include <device/device.h> |
| 10 | #include <device/pci.h> |
| 11 | #include <device/pci_ids.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 12 | #include "chip.h" |
Arthur Heymans | 6473473 | 2021-01-18 00:30:23 +0100 | [diff] [blame] | 13 | #include <commonlib/bsd/helpers.h> |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 14 | #include "ironlake.h" |
Kyösti Mälkki | f091f4d | 2019-08-14 03:49:21 +0300 | [diff] [blame] | 15 | #include <cpu/intel/smm_reloc.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 16 | |
| 17 | static int bridge_revision_id = -1; |
| 18 | |
| 19 | int bridge_silicon_revision(void) |
| 20 | { |
| 21 | if (bridge_revision_id < 0) { |
Angel Pons | 43bcc7b | 2020-06-22 18:11:31 +0200 | [diff] [blame] | 22 | 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 Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 25 | } |
| 26 | return bridge_revision_id; |
| 27 | } |
| 28 | |
Angel Pons | 43bcc7b | 2020-06-22 18:11:31 +0200 | [diff] [blame] | 29 | /* |
| 30 | * Reserve everything between A segment and 1MB: |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 31 | * |
| 32 | * 0xa0000 - 0xbffff: legacy VGA |
| 33 | * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel) |
| 34 | * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI |
| 35 | */ |
| 36 | static const int legacy_hole_base_k = 0xa0000 / 1024; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 37 | |
| 38 | static 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 Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 50 | |
| 51 | resource = new_resource(dev, index++); |
Felix Held | 928a9c8 | 2022-02-24 00:51:11 +0100 | [diff] [blame] | 52 | resource->base = (resource_t) HPET_BASE_ADDRESS; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 53 | resource->size = (resource_t) 0x00100000; |
Angel Pons | 43bcc7b | 2020-06-22 18:11:31 +0200 | [diff] [blame] | 54 | resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE | IORESOURCE_FIXED | |
| 55 | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 56 | |
Arthur Heymans | 6473473 | 2021-01-18 00:30:23 +0100 | [diff] [blame] | 57 | mmio_resource(dev, index++, legacy_hole_base_k, (0xc0000 / KiB) - legacy_hole_base_k); |
| 58 | reserved_ram_resource(dev, index++, 0xc0000 / KiB, (0x100000 - 0xc0000) / KiB); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 61 | #if CONFIG(HAVE_ACPI_TABLES) |
Patrick Rudolph | 5c3452b | 2018-05-15 11:37:26 +0200 | [diff] [blame] | 62 | static 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 Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 79 | static struct device_operations pci_domain_ops = { |
Angel Pons | 43bcc7b | 2020-06-22 18:11:31 +0200 | [diff] [blame] | 80 | .read_resources = pci_domain_read_resources, |
| 81 | .set_resources = pci_domain_set_resources, |
| 82 | .scan_bus = pci_domain_scan_bus, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 83 | #if CONFIG(HAVE_ACPI_TABLES) |
Angel Pons | 43bcc7b | 2020-06-22 18:11:31 +0200 | [diff] [blame] | 84 | .acpi_name = northbridge_acpi_name, |
Patrick Rudolph | 5c3452b | 2018-05-15 11:37:26 +0200 | [diff] [blame] | 85 | #endif |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
Elyes HAOUAS | 706aabc | 2018-02-09 08:49:32 +0100 | [diff] [blame] | 88 | static void mc_read_resources(struct device *dev) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 89 | { |
Nico Huber | 308540d | 2020-09-13 21:59:14 +0200 | [diff] [blame] | 90 | uint32_t tseg_base, tseg_end; |
Angel Pons | 9333b74 | 2020-07-22 16:04:15 +0200 | [diff] [blame] | 91 | uint64_t touud; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 92 | uint16_t reg16; |
Nico Huber | 08e8e47 | 2020-09-13 21:56:50 +0200 | [diff] [blame] | 93 | int index = 3; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 94 | |
| 95 | pci_dev_read_resources(dev); |
| 96 | |
Kyösti Mälkki | e25b5ef | 2016-12-02 08:56:05 +0200 | [diff] [blame] | 97 | mmconf_resource(dev, 0x50); |
| 98 | |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 99 | tseg_base = pci_read_config32(pcidev_on_root(0, 0), TSEG); |
Nico Huber | 308540d | 2020-09-13 21:59:14 +0200 | [diff] [blame] | 100 | tseg_end = tseg_base + CONFIG_SMM_TSEG_SIZE; |
Angel Pons | 9333b74 | 2020-07-22 16:04:15 +0200 | [diff] [blame] | 101 | touud = pci_read_config16(pcidev_on_root(0, 0), |
Angel Pons | 16fe1e0 | 2020-07-22 16:12:33 +0200 | [diff] [blame] | 102 | TOUUD); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 103 | |
| 104 | printk(BIOS_DEBUG, "ram_before_4g_top: 0x%x\n", tseg_base); |
Angel Pons | 9333b74 | 2020-07-22 16:04:15 +0200 | [diff] [blame] | 105 | printk(BIOS_DEBUG, "TOUUD: 0x%x\n", (unsigned int)touud); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 106 | |
| 107 | /* Report the memory regions */ |
Arthur Heymans | 6473473 | 2021-01-18 00:30:23 +0100 | [diff] [blame] | 108 | ram_resource(dev, index++, 0, 0xa0000 / KiB); |
Arthur Heymans | 839c98a | 2021-01-18 00:43:46 +0100 | [diff] [blame] | 109 | ram_resource(dev, index++, 1 * MiB / KiB, (tseg_base - 1 * MiB) / KiB); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 110 | |
Arthur Heymans | 6473473 | 2021-01-18 00:30:23 +0100 | [diff] [blame] | 111 | mmio_resource(dev, index++, tseg_base / KiB, CONFIG_SMM_TSEG_SIZE / KiB); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 112 | |
Angel Pons | 16fe1e0 | 2020-07-22 16:12:33 +0200 | [diff] [blame] | 113 | reg16 = pci_read_config16(pcidev_on_root(0, 0), GGC); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 114 | 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 Pons | 16fe1e0 | 2020-07-22 16:12:33 +0200 | [diff] [blame] | 127 | pci_read_config32(pcidev_on_root(0, 0), IGD_BASE); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 128 | gtt_base = |
Angel Pons | 16fe1e0 | 2020-07-22 16:12:33 +0200 | [diff] [blame] | 129 | pci_read_config32(pcidev_on_root(0, 0), GTT_BASE); |
Nico Huber | 308540d | 2020-09-13 21:59:14 +0200 | [diff] [blame] | 130 | 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. */ |
Arthur Heymans | 6473473 | 2021-01-18 00:30:23 +0100 | [diff] [blame] | 133 | mmio_resource(dev, index++, tseg_end / KiB, (gtt_base - tseg_end) / KiB); |
Nico Huber | 308540d | 2020-09-13 21:59:14 +0200 | [diff] [blame] | 134 | } |
Arthur Heymans | 6473473 | 2021-01-18 00:30:23 +0100 | [diff] [blame] | 135 | mmio_resource(dev, index++, gtt_base / KiB, uma_size_gtt * KiB); |
| 136 | mmio_resource(dev, index++, igd_base / KiB, uma_size_igd * KiB); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 137 | |
Angel Pons | 9333b74 | 2020-07-22 16:04:15 +0200 | [diff] [blame] | 138 | if (touud > 4096) |
Arthur Heymans | 6473473 | 2021-01-18 00:30:23 +0100 | [diff] [blame] | 139 | ram_resource(dev, index++, (4096 * KiB), ((touud - 4096) * KiB)); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 140 | |
| 141 | /* This memory is not DMA-capable. */ |
Angel Pons | 9333b74 | 2020-07-22 16:04:15 +0200 | [diff] [blame] | 142 | if (touud >= 8192 - 64) |
Arthur Heymans | 6473473 | 2021-01-18 00:30:23 +0100 | [diff] [blame] | 143 | bad_ram_resource(dev, index++, 0x1fc000000ULL / KiB, 0x004000000 / KiB); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 144 | |
Nico Huber | 08e8e47 | 2020-09-13 21:56:50 +0200 | [diff] [blame] | 145 | add_fixed_resources(dev, index); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Angel Pons | ecdbc84 | 2020-06-22 17:28:42 +0200 | [diff] [blame] | 148 | static void northbridge_init(struct device *dev) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 149 | { |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 150 | /* Clear error status bits */ |
Angel Pons | dea722b | 2021-03-26 14:11:12 +0100 | [diff] [blame] | 151 | dmibar_write32(DMIUESTS, 0xffffffff); |
| 152 | dmibar_write32(DMICESTS, 0xffffffff); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 153 | |
Angel Pons | dea722b | 2021-03-26 14:11:12 +0100 | [diff] [blame] | 154 | dmibar_setbits32(DMILLTC, 1 << 29); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 155 | |
Angel Pons | dea722b | 2021-03-26 14:11:12 +0100 | [diff] [blame] | 156 | dmibar_setbits32(0x1f8, 1 << 16); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 157 | |
Angel Pons | dea722b | 2021-03-26 14:11:12 +0100 | [diff] [blame] | 158 | dmibar_setbits32(DMILCTL, 1 << 1 | 1 << 0); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 159 | } |
| 160 | |
Arthur Heymans | 28bca05 | 2019-10-01 21:20:33 +0200 | [diff] [blame] | 161 | /* Disable unused PEG devices based on devicetree before PCI enumeration */ |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 162 | static void ironlake_init(void *const chip_info) |
Arthur Heymans | 28bca05 | 2019-10-01 21:20:33 +0200 | [diff] [blame] | 163 | { |
| 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 Pons | 16fe1e0 | 2020-07-22 16:12:33 +0200 | [diff] [blame] | 179 | pci_update_config32(d0f0, DEVEN, deven_mask, 0); |
Arthur Heymans | 28bca05 | 2019-10-01 21:20:33 +0200 | [diff] [blame] | 180 | |
| 181 | } |
| 182 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 183 | static struct device_operations mc_ops = { |
Angel Pons | 43bcc7b | 2020-06-22 18:11:31 +0200 | [diff] [blame] | 184 | .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 Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 190 | }; |
| 191 | |
Angel Pons | 6642b44 | 2020-09-21 21:03:46 +0200 | [diff] [blame] | 192 | /* |
| 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 | */ |
| 203 | static 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 | |
| 216 | static const struct pci_driver mc_driver_ilk __pci_driver = { |
| 217 | .ops = &mc_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 218 | .vendor = PCI_VID_INTEL, |
Angel Pons | 6642b44 | 2020-09-21 21:03:46 +0200 | [diff] [blame] | 219 | .devices = pci_device_ids, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 220 | }; |
| 221 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 222 | static struct device_operations cpu_bus_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 223 | .read_resources = noop_read_resources, |
| 224 | .set_resources = noop_set_resources, |
Kyösti Mälkki | b3267e0 | 2019-08-13 16:44:04 +0300 | [diff] [blame] | 225 | .init = mp_cpu_bus_init, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 226 | }; |
| 227 | |
Elyes HAOUAS | 706aabc | 2018-02-09 08:49:32 +0100 | [diff] [blame] | 228 | static void enable_dev(struct device *dev) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 229 | { |
| 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 Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 238 | struct chip_operations northbridge_intel_ironlake_ops = { |
Angel Pons | 9d7431c | 2020-10-22 23:55:39 +0200 | [diff] [blame] | 239 | CHIP_NAME("Intel Ironlake integrated Northbridge") |
Arthur Heymans | 28bca05 | 2019-10-01 21:20:33 +0200 | [diff] [blame] | 240 | .enable_dev = enable_dev, |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 241 | .init = ironlake_init, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 242 | }; |