blob: 415c142946a8e3685f6ad31adbdcf5e670723451 [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>
7#include <delay.h>
8#include <cpu/intel/model_2065x/model_2065x.h>
9#include <cpu/x86/msr.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010010#include <device/device.h>
11#include <device/pci.h>
12#include <device/pci_ids.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010013#include "chip.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) {
22 uint8_t stepping = cpuid_eax(1) & 0xf;
23 uint8_t bridge_id =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030024 pci_read_config16(pcidev_on_root(0, 0),
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010025 PCI_DEVICE_ID) & 0xf0;
26 bridge_revision_id = bridge_id | stepping;
27 }
28 return bridge_revision_id;
29}
30
31/* Reserve everything between A segment and 1MB:
32 *
33 * 0xa0000 - 0xbffff: legacy VGA
34 * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel)
35 * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI
36 */
37static const int legacy_hole_base_k = 0xa0000 / 1024;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010038
39static void add_fixed_resources(struct device *dev, int index)
40{
41 struct resource *resource;
42
43 /* 0xe0000000-0xf0000000 PCIe config.
44 0xfed10000-0xfed14000 MCH
45 0xfed17000-0xfed18000 HECI
46 0xfed18000-0xfed19000 DMI
47 0xfed19000-0xfed1a000 EPBAR
48 0xfed1c000-0xfed20000 RCBA
49 0xfed90000-0xfed94000 IOMMU
50 0xff800000-0xffffffff ROM. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010051
52 resource = new_resource(dev, index++);
53 resource->base = (resource_t) 0xfed00000;
54 resource->size = (resource_t) 0x00100000;
55 resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
56 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
57
58 mmio_resource(dev, index++, legacy_hole_base_k,
59 (0xc0000 >> 10) - legacy_hole_base_k);
60 reserved_ram_resource(dev, index++, 0xc0000 >> 10,
61 (0x100000 - 0xc0000) >> 10);
62
Julius Wernercd49cce2019-03-05 16:53:33 -080063#if CONFIG(CHROMEOS_RAMOOPS)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010064 reserved_ram_resource(dev, index++,
65 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
66 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
67#endif
68}
69
Julius Wernercd49cce2019-03-05 16:53:33 -080070#if CONFIG(HAVE_ACPI_TABLES)
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020071static const char *northbridge_acpi_name(const struct device *dev)
72{
73 if (dev->path.type == DEVICE_PATH_DOMAIN)
74 return "PCI0";
75
76 if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
77 return NULL;
78
79 switch (dev->path.pci.devfn) {
80 case PCI_DEVFN(0, 0):
81 return "MCHC";
82 }
83
84 return NULL;
85}
86#endif
87
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010088static struct device_operations pci_domain_ops = {
89 .read_resources = pci_domain_read_resources,
90 .set_resources = pci_domain_set_resources,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010091 .scan_bus = pci_domain_scan_bus,
Julius Wernercd49cce2019-03-05 16:53:33 -080092#if CONFIG(HAVE_ACPI_TABLES)
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020093 .acpi_name = northbridge_acpi_name,
94#endif
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010095};
96
Elyes HAOUAS706aabc2018-02-09 08:49:32 +010097static void mc_read_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010098{
99 uint32_t tseg_base;
100 uint64_t TOUUD;
101 uint16_t reg16;
102
103 pci_dev_read_resources(dev);
104
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200105 mmconf_resource(dev, 0x50);
106
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300107 tseg_base = pci_read_config32(pcidev_on_root(0, 0), TSEG);
108 TOUUD = pci_read_config16(pcidev_on_root(0, 0),
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100109 D0F0_TOUUD);
110
111 printk(BIOS_DEBUG, "ram_before_4g_top: 0x%x\n", tseg_base);
Martin Roth468d02c2019-10-23 21:44:42 -0600112 printk(BIOS_DEBUG, "TOUUD: 0x%x\n", (unsigned int)TOUUD);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100113
114 /* Report the memory regions */
115 ram_resource(dev, 3, 0, 640);
116 ram_resource(dev, 4, 768, ((tseg_base >> 10) - 768));
117
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100118 mmio_resource(dev, 5, tseg_base >> 10, CONFIG_SMM_TSEG_SIZE >> 10);
119
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300120 reg16 = pci_read_config16(pcidev_on_root(0, 0), D0F0_GGC);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100121 const int uma_sizes_gtt[16] =
122 { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4, 42, 42, 42, 42 };
123 /* Igd memory */
124 const int uma_sizes_igd[16] = {
125 0, 0, 0, 0, 0, 32, 48, 64, 128, 256, 96, 160, 224, 352, 256, 512
126 };
127 u32 igd_base, gtt_base;
128 int uma_size_igd, uma_size_gtt;
129
130 uma_size_igd = uma_sizes_igd[(reg16 >> 4) & 0xF];
131 uma_size_gtt = uma_sizes_gtt[(reg16 >> 8) & 0xF];
132
133 igd_base =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300134 pci_read_config32(pcidev_on_root(0, 0), D0F0_IGD_BASE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100135 gtt_base =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300136 pci_read_config32(pcidev_on_root(0, 0), D0F0_GTT_BASE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100137 mmio_resource(dev, 6, gtt_base >> 10, uma_size_gtt << 10);
138 mmio_resource(dev, 7, igd_base >> 10, uma_size_igd << 10);
139
140 if (TOUUD > 4096)
141 ram_resource(dev, 8, (4096 << 10), ((TOUUD - 4096) << 10));
142
143 /* This memory is not DMA-capable. */
144 if (TOUUD >= 8192 - 64)
145 bad_ram_resource(dev, 9, 0x1fc000000ULL >> 10, 0x004000000 >> 10);
146
147 add_fixed_resources(dev, 10);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100148}
149
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100150static void mc_set_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100151{
152 /* And call the normal set_resources */
153 pci_dev_set_resources(dev);
154}
155
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100156static void northbridge_dmi_init(struct device *dev)
157{
158 u32 reg32;
159
160 /* Clear error status bits */
161 DMIBAR32(0x1c4) = 0xffffffff;
162 DMIBAR32(0x1d0) = 0xffffffff;
163
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100164 reg32 = DMIBAR32(0x238);
165 reg32 |= (1 << 29);
166 DMIBAR32(0x238) = reg32;
167
Angel Ponsb6397072020-06-22 17:41:49 +0200168 reg32 = DMIBAR32(0x1f8);
169 reg32 |= (1 << 16);
170 DMIBAR32(0x1f8) = reg32;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100171
172 reg32 = DMIBAR32(0x88);
173 reg32 |= (1 << 1) | (1 << 0);
174 DMIBAR32(0x88) = reg32;
175}
176
177static void northbridge_init(struct device *dev)
178{
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100179 northbridge_dmi_init(dev);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100180}
181
Arthur Heymans28bca052019-10-01 21:20:33 +0200182/* Disable unused PEG devices based on devicetree before PCI enumeration */
Angel Pons95de2312020-02-17 13:08:53 +0100183static void ironlake_init(void *const chip_info)
Arthur Heymans28bca052019-10-01 21:20:33 +0200184{
185 u32 deven_mask = UINT32_MAX;
186 const struct device *dev;
187
188 dev = pcidev_on_root(1, 0);
189 if (!dev || !dev->enabled) {
190 printk(BIOS_DEBUG, "Disabling PEG10.\n");
191 deven_mask &= ~DEVEN_PEG10;
192 }
193 dev = pcidev_on_root(2, 0);
194 if (!dev || !dev->enabled) {
195 printk(BIOS_DEBUG, "Disabling IGD.\n");
196 deven_mask &= ~DEVEN_IGD;
197 }
198 const struct device *const d0f0 = pcidev_on_root(0, 0);
199 if (d0f0)
200 pci_update_config32(d0f0, D0F0_DEVEN, deven_mask, 0);
201
202}
203
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100204static struct device_operations mc_ops = {
205 .read_resources = mc_read_resources,
206 .set_resources = mc_set_resources,
207 .enable_resources = pci_dev_enable_resources,
208 .init = northbridge_init,
Nico Huber68680dd2020-03-31 17:34:52 +0200209 .acpi_fill_ssdt = generate_cpu_entries,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200210 .ops_pci = &pci_dev_ops_pci,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100211};
212
Angel Pons31b7ee42020-02-17 14:04:28 +0100213static const struct pci_driver mc_driver_ard __pci_driver = {
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100214 .ops = &mc_ops,
215 .vendor = PCI_VENDOR_ID_INTEL,
Angel Pons31b7ee42020-02-17 14:04:28 +0100216 .device = 0x0044, /* Arrandale DRAM controller */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100217};
218
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100219static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200220 .read_resources = noop_read_resources,
221 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300222 .init = mp_cpu_bus_init,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100223};
224
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100225static void enable_dev(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100226{
227 /* Set the operations if it is a special bus type */
228 if (dev->path.type == DEVICE_PATH_DOMAIN) {
229 dev->ops = &pci_domain_ops;
230 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
231 dev->ops = &cpu_bus_ops;
232 }
233}
234
Angel Pons95de2312020-02-17 13:08:53 +0100235struct chip_operations northbridge_intel_ironlake_ops = {
Angel Pons31b7ee42020-02-17 14:04:28 +0100236 CHIP_NAME("Intel i7 (Arrandale) integrated Northbridge")
Arthur Heymans28bca052019-10-01 21:20:33 +0200237 .enable_dev = enable_dev,
Angel Pons95de2312020-02-17 13:08:53 +0100238 .init = ironlake_init,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100239};