blob: cf014fe1172892c1f31cb2cd622dfe0f4192189f [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"
Angel Pons95de2312020-02-17 13:08:53 +010012#include "ironlake.h"
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030013#include <cpu/intel/smm_reloc.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010014
15static int bridge_revision_id = -1;
16
17int bridge_silicon_revision(void)
18{
19 if (bridge_revision_id < 0) {
Angel Pons43bcc7b2020-06-22 18:11:31 +020020 uint8_t stepping = cpuid_eax(1) & 0x0f;
21 uint8_t bridge_id = pci_read_config16(pcidev_on_root(0, 0), PCI_DEVICE_ID);
22 bridge_revision_id = (bridge_id & 0xf0) | stepping;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010023 }
24 return bridge_revision_id;
25}
26
Angel Pons43bcc7b2020-06-22 18:11:31 +020027/*
28 * Reserve everything between A segment and 1MB:
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010029 *
30 * 0xa0000 - 0xbffff: legacy VGA
31 * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel)
32 * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI
33 */
34static const int legacy_hole_base_k = 0xa0000 / 1024;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010035
36static void add_fixed_resources(struct device *dev, int index)
37{
38 struct resource *resource;
39
40 /* 0xe0000000-0xf0000000 PCIe config.
41 0xfed10000-0xfed14000 MCH
42 0xfed17000-0xfed18000 HECI
43 0xfed18000-0xfed19000 DMI
44 0xfed19000-0xfed1a000 EPBAR
45 0xfed1c000-0xfed20000 RCBA
46 0xfed90000-0xfed94000 IOMMU
47 0xff800000-0xffffffff ROM. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010048
49 resource = new_resource(dev, index++);
50 resource->base = (resource_t) 0xfed00000;
51 resource->size = (resource_t) 0x00100000;
Angel Pons43bcc7b2020-06-22 18:11:31 +020052 resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE | IORESOURCE_FIXED |
53 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010054
Angel Pons43bcc7b2020-06-22 18:11:31 +020055 mmio_resource(dev, index++, legacy_hole_base_k, (0xc0000 >> 10) - legacy_hole_base_k);
56
57 reserved_ram_resource(dev, index++, 0xc0000 >> 10, (0x100000 - 0xc0000) >> 10);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010058
Julius Wernercd49cce2019-03-05 16:53:33 -080059#if CONFIG(CHROMEOS_RAMOOPS)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010060 reserved_ram_resource(dev, index++,
61 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
62 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
63#endif
64}
65
Julius Wernercd49cce2019-03-05 16:53:33 -080066#if CONFIG(HAVE_ACPI_TABLES)
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020067static const char *northbridge_acpi_name(const struct device *dev)
68{
69 if (dev->path.type == DEVICE_PATH_DOMAIN)
70 return "PCI0";
71
72 if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
73 return NULL;
74
75 switch (dev->path.pci.devfn) {
76 case PCI_DEVFN(0, 0):
77 return "MCHC";
78 }
79
80 return NULL;
81}
82#endif
83
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010084static struct device_operations pci_domain_ops = {
Angel Pons43bcc7b2020-06-22 18:11:31 +020085 .read_resources = pci_domain_read_resources,
86 .set_resources = pci_domain_set_resources,
87 .scan_bus = pci_domain_scan_bus,
Julius Wernercd49cce2019-03-05 16:53:33 -080088#if CONFIG(HAVE_ACPI_TABLES)
Angel Pons43bcc7b2020-06-22 18:11:31 +020089 .acpi_name = northbridge_acpi_name,
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020090#endif
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010091};
92
Elyes HAOUAS706aabc2018-02-09 08:49:32 +010093static void mc_read_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010094{
Nico Huber308540d2020-09-13 21:59:14 +020095 uint32_t tseg_base, tseg_end;
Angel Pons9333b742020-07-22 16:04:15 +020096 uint64_t touud;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010097 uint16_t reg16;
Nico Huber08e8e472020-09-13 21:56:50 +020098 int index = 3;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010099
100 pci_dev_read_resources(dev);
101
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200102 mmconf_resource(dev, 0x50);
103
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300104 tseg_base = pci_read_config32(pcidev_on_root(0, 0), TSEG);
Nico Huber308540d2020-09-13 21:59:14 +0200105 tseg_end = tseg_base + CONFIG_SMM_TSEG_SIZE;
Angel Pons9333b742020-07-22 16:04:15 +0200106 touud = pci_read_config16(pcidev_on_root(0, 0),
Angel Pons16fe1e02020-07-22 16:12:33 +0200107 TOUUD);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100108
109 printk(BIOS_DEBUG, "ram_before_4g_top: 0x%x\n", tseg_base);
Angel Pons9333b742020-07-22 16:04:15 +0200110 printk(BIOS_DEBUG, "TOUUD: 0x%x\n", (unsigned int)touud);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100111
112 /* Report the memory regions */
Nico Huber08e8e472020-09-13 21:56:50 +0200113 ram_resource(dev, index++, 0, 640);
114 ram_resource(dev, index++, 768, ((tseg_base >> 10) - 768));
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100115
Nico Huber08e8e472020-09-13 21:56:50 +0200116 mmio_resource(dev, index++, tseg_base >> 10, CONFIG_SMM_TSEG_SIZE >> 10);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100117
Angel Pons16fe1e02020-07-22 16:12:33 +0200118 reg16 = pci_read_config16(pcidev_on_root(0, 0), GGC);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100119 const int uma_sizes_gtt[16] =
120 { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4, 42, 42, 42, 42 };
121 /* Igd memory */
122 const int uma_sizes_igd[16] = {
123 0, 0, 0, 0, 0, 32, 48, 64, 128, 256, 96, 160, 224, 352, 256, 512
124 };
125 u32 igd_base, gtt_base;
126 int uma_size_igd, uma_size_gtt;
127
128 uma_size_igd = uma_sizes_igd[(reg16 >> 4) & 0xF];
129 uma_size_gtt = uma_sizes_gtt[(reg16 >> 8) & 0xF];
130
131 igd_base =
Angel Pons16fe1e02020-07-22 16:12:33 +0200132 pci_read_config32(pcidev_on_root(0, 0), IGD_BASE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100133 gtt_base =
Angel Pons16fe1e02020-07-22 16:12:33 +0200134 pci_read_config32(pcidev_on_root(0, 0), GTT_BASE);
Nico Huber308540d2020-09-13 21:59:14 +0200135 if (gtt_base > tseg_end) {
136 /* Reserve the gap. MMIO doesn't work in this range. Keep
137 it uncacheable, though, for easier MTRR allocation. */
138 mmio_resource(dev, index++, tseg_end >> 10, (gtt_base - tseg_end) >> 10);
139 }
Nico Huber08e8e472020-09-13 21:56:50 +0200140 mmio_resource(dev, index++, gtt_base >> 10, uma_size_gtt << 10);
141 mmio_resource(dev, index++, igd_base >> 10, uma_size_igd << 10);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100142
Angel Pons9333b742020-07-22 16:04:15 +0200143 if (touud > 4096)
Nico Huber08e8e472020-09-13 21:56:50 +0200144 ram_resource(dev, index++, (4096 << 10), ((touud - 4096) << 10));
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100145
146 /* This memory is not DMA-capable. */
Angel Pons9333b742020-07-22 16:04:15 +0200147 if (touud >= 8192 - 64)
Nico Huber08e8e472020-09-13 21:56:50 +0200148 bad_ram_resource(dev, index++, 0x1fc000000ULL >> 10, 0x004000000 >> 10);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100149
Nico Huber08e8e472020-09-13 21:56:50 +0200150 add_fixed_resources(dev, index);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100151}
152
Angel Ponsecdbc842020-06-22 17:28:42 +0200153static void northbridge_init(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100154{
155 u32 reg32;
156
157 /* Clear error status bits */
158 DMIBAR32(0x1c4) = 0xffffffff;
159 DMIBAR32(0x1d0) = 0xffffffff;
160
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100161 reg32 = DMIBAR32(0x238);
162 reg32 |= (1 << 29);
163 DMIBAR32(0x238) = reg32;
164
Angel Ponsb6397072020-06-22 17:41:49 +0200165 reg32 = DMIBAR32(0x1f8);
166 reg32 |= (1 << 16);
167 DMIBAR32(0x1f8) = reg32;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100168
169 reg32 = DMIBAR32(0x88);
170 reg32 |= (1 << 1) | (1 << 0);
171 DMIBAR32(0x88) = reg32;
172}
173
Arthur Heymans28bca052019-10-01 21:20:33 +0200174/* Disable unused PEG devices based on devicetree before PCI enumeration */
Angel Pons95de2312020-02-17 13:08:53 +0100175static void ironlake_init(void *const chip_info)
Arthur Heymans28bca052019-10-01 21:20:33 +0200176{
177 u32 deven_mask = UINT32_MAX;
178 const struct device *dev;
179
180 dev = pcidev_on_root(1, 0);
181 if (!dev || !dev->enabled) {
182 printk(BIOS_DEBUG, "Disabling PEG10.\n");
183 deven_mask &= ~DEVEN_PEG10;
184 }
185 dev = pcidev_on_root(2, 0);
186 if (!dev || !dev->enabled) {
187 printk(BIOS_DEBUG, "Disabling IGD.\n");
188 deven_mask &= ~DEVEN_IGD;
189 }
190 const struct device *const d0f0 = pcidev_on_root(0, 0);
191 if (d0f0)
Angel Pons16fe1e02020-07-22 16:12:33 +0200192 pci_update_config32(d0f0, DEVEN, deven_mask, 0);
Arthur Heymans28bca052019-10-01 21:20:33 +0200193
194}
195
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100196static struct device_operations mc_ops = {
Angel Pons43bcc7b2020-06-22 18:11:31 +0200197 .read_resources = mc_read_resources,
198 .set_resources = pci_dev_set_resources,
199 .enable_resources = pci_dev_enable_resources,
200 .init = northbridge_init,
201 .acpi_fill_ssdt = generate_cpu_entries,
202 .ops_pci = &pci_dev_ops_pci,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100203};
204
Angel Pons31b7ee42020-02-17 14:04:28 +0100205static const struct pci_driver mc_driver_ard __pci_driver = {
Angel Pons43bcc7b2020-06-22 18:11:31 +0200206 .ops = &mc_ops,
207 .vendor = PCI_VENDOR_ID_INTEL,
208 .device = 0x0044, /* Arrandale DRAM controller */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100209};
210
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100211static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200212 .read_resources = noop_read_resources,
213 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300214 .init = mp_cpu_bus_init,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100215};
216
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100217static void enable_dev(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100218{
219 /* Set the operations if it is a special bus type */
220 if (dev->path.type == DEVICE_PATH_DOMAIN) {
221 dev->ops = &pci_domain_ops;
222 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
223 dev->ops = &cpu_bus_ops;
224 }
225}
226
Angel Pons95de2312020-02-17 13:08:53 +0100227struct chip_operations northbridge_intel_ironlake_ops = {
Angel Pons31b7ee42020-02-17 14:04:28 +0100228 CHIP_NAME("Intel i7 (Arrandale) integrated Northbridge")
Arthur Heymans28bca052019-10-01 21:20:33 +0200229 .enable_dev = enable_dev,
Angel Pons95de2312020-02-17 13:08:53 +0100230 .init = ironlake_init,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100231};