blob: c1ee207bf1e1f298fe5418902634d49938142234 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01003
4#include <console/console.h>
5#include <arch/acpi.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>
8#include <delay.h>
9#include <cpu/intel/model_2065x/model_2065x.h>
10#include <cpu/x86/msr.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010011#include <device/device.h>
12#include <device/pci.h>
13#include <device/pci_ids.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010014#include "chip.h"
Angel Pons95de2312020-02-17 13:08:53 +010015#include "ironlake.h"
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030016#include <cpu/intel/smm_reloc.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010017
18static int bridge_revision_id = -1;
19
20int bridge_silicon_revision(void)
21{
22 if (bridge_revision_id < 0) {
23 uint8_t stepping = cpuid_eax(1) & 0xf;
24 uint8_t bridge_id =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030025 pci_read_config16(pcidev_on_root(0, 0),
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010026 PCI_DEVICE_ID) & 0xf0;
27 bridge_revision_id = bridge_id | stepping;
28 }
29 return bridge_revision_id;
30}
31
32/* Reserve everything between A segment and 1MB:
33 *
34 * 0xa0000 - 0xbffff: legacy VGA
35 * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel)
36 * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI
37 */
38static const int legacy_hole_base_k = 0xa0000 / 1024;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010039
40static void add_fixed_resources(struct device *dev, int index)
41{
42 struct resource *resource;
43
44 /* 0xe0000000-0xf0000000 PCIe config.
45 0xfed10000-0xfed14000 MCH
46 0xfed17000-0xfed18000 HECI
47 0xfed18000-0xfed19000 DMI
48 0xfed19000-0xfed1a000 EPBAR
49 0xfed1c000-0xfed20000 RCBA
50 0xfed90000-0xfed94000 IOMMU
51 0xff800000-0xffffffff ROM. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010052
53 resource = new_resource(dev, index++);
54 resource->base = (resource_t) 0xfed00000;
55 resource->size = (resource_t) 0x00100000;
56 resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
57 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
58
59 mmio_resource(dev, index++, legacy_hole_base_k,
60 (0xc0000 >> 10) - legacy_hole_base_k);
61 reserved_ram_resource(dev, index++, 0xc0000 >> 10,
62 (0x100000 - 0xc0000) >> 10);
63
Julius Wernercd49cce2019-03-05 16:53:33 -080064#if CONFIG(CHROMEOS_RAMOOPS)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010065 reserved_ram_resource(dev, index++,
66 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
67 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
68#endif
69}
70
Elyes HAOUAS706aabc2018-02-09 08:49:32 +010071static void pci_domain_set_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010072{
73 assign_resources(dev->link_list);
74}
75
Julius Wernercd49cce2019-03-05 16:53:33 -080076#if CONFIG(HAVE_ACPI_TABLES)
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020077static const char *northbridge_acpi_name(const struct device *dev)
78{
79 if (dev->path.type == DEVICE_PATH_DOMAIN)
80 return "PCI0";
81
82 if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
83 return NULL;
84
85 switch (dev->path.pci.devfn) {
86 case PCI_DEVFN(0, 0):
87 return "MCHC";
88 }
89
90 return NULL;
91}
92#endif
93
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010094static struct device_operations pci_domain_ops = {
95 .read_resources = pci_domain_read_resources,
96 .set_resources = pci_domain_set_resources,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010097 .scan_bus = pci_domain_scan_bus,
Julius Wernercd49cce2019-03-05 16:53:33 -080098#if CONFIG(HAVE_ACPI_TABLES)
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020099 .acpi_name = northbridge_acpi_name,
100#endif
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100101};
102
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100103static void mc_read_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100104{
105 uint32_t tseg_base;
106 uint64_t TOUUD;
107 uint16_t reg16;
108
109 pci_dev_read_resources(dev);
110
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200111 mmconf_resource(dev, 0x50);
112
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300113 tseg_base = pci_read_config32(pcidev_on_root(0, 0), TSEG);
114 TOUUD = pci_read_config16(pcidev_on_root(0, 0),
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100115 D0F0_TOUUD);
116
117 printk(BIOS_DEBUG, "ram_before_4g_top: 0x%x\n", tseg_base);
Martin Roth468d02c2019-10-23 21:44:42 -0600118 printk(BIOS_DEBUG, "TOUUD: 0x%x\n", (unsigned int)TOUUD);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100119
120 /* Report the memory regions */
121 ram_resource(dev, 3, 0, 640);
122 ram_resource(dev, 4, 768, ((tseg_base >> 10) - 768));
123
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100124 mmio_resource(dev, 5, tseg_base >> 10, CONFIG_SMM_TSEG_SIZE >> 10);
125
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300126 reg16 = pci_read_config16(pcidev_on_root(0, 0), D0F0_GGC);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100127 const int uma_sizes_gtt[16] =
128 { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4, 42, 42, 42, 42 };
129 /* Igd memory */
130 const int uma_sizes_igd[16] = {
131 0, 0, 0, 0, 0, 32, 48, 64, 128, 256, 96, 160, 224, 352, 256, 512
132 };
133 u32 igd_base, gtt_base;
134 int uma_size_igd, uma_size_gtt;
135
136 uma_size_igd = uma_sizes_igd[(reg16 >> 4) & 0xF];
137 uma_size_gtt = uma_sizes_gtt[(reg16 >> 8) & 0xF];
138
139 igd_base =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300140 pci_read_config32(pcidev_on_root(0, 0), D0F0_IGD_BASE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100141 gtt_base =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300142 pci_read_config32(pcidev_on_root(0, 0), D0F0_GTT_BASE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100143 mmio_resource(dev, 6, gtt_base >> 10, uma_size_gtt << 10);
144 mmio_resource(dev, 7, igd_base >> 10, uma_size_igd << 10);
145
146 if (TOUUD > 4096)
147 ram_resource(dev, 8, (4096 << 10), ((TOUUD - 4096) << 10));
148
149 /* This memory is not DMA-capable. */
150 if (TOUUD >= 8192 - 64)
151 bad_ram_resource(dev, 9, 0x1fc000000ULL >> 10, 0x004000000 >> 10);
152
153 add_fixed_resources(dev, 10);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100154}
155
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100156static void mc_set_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100157{
158 /* And call the normal set_resources */
159 pci_dev_set_resources(dev);
160}
161
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100162static void northbridge_dmi_init(struct device *dev)
163{
164 u32 reg32;
165
166 /* Clear error status bits */
167 DMIBAR32(0x1c4) = 0xffffffff;
168 DMIBAR32(0x1d0) = 0xffffffff;
169
170 /* Steps prior to DMI ASPM */
171 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
172 reg32 = DMIBAR32(0x250);
173 reg32 &= ~((1 << 22) | (1 << 20));
174 reg32 |= (1 << 21);
175 DMIBAR32(0x250) = reg32;
176 }
177
178 reg32 = DMIBAR32(0x238);
179 reg32 |= (1 << 29);
180 DMIBAR32(0x238) = reg32;
181
182 if (bridge_silicon_revision() >= SNB_STEP_D0) {
183 reg32 = DMIBAR32(0x1f8);
184 reg32 |= (1 << 16);
185 DMIBAR32(0x1f8) = reg32;
186 } else if (bridge_silicon_revision() >= SNB_STEP_D1) {
187 reg32 = DMIBAR32(0x1f8);
188 reg32 &= ~(1 << 26);
189 reg32 |= (1 << 16);
190 DMIBAR32(0x1f8) = reg32;
191
192 reg32 = DMIBAR32(0x1fc);
193 reg32 |= (1 << 12) | (1 << 23);
194 DMIBAR32(0x1fc) = reg32;
195 }
196
197 /* Enable ASPM on SNB link, should happen before PCH link */
198 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
199 reg32 = DMIBAR32(0xd04);
200 reg32 |= (1 << 4);
201 DMIBAR32(0xd04) = reg32;
202 }
203
204 reg32 = DMIBAR32(0x88);
205 reg32 |= (1 << 1) | (1 << 0);
206 DMIBAR32(0x88) = reg32;
207}
208
209static void northbridge_init(struct device *dev)
210{
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100211 northbridge_dmi_init(dev);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100212}
213
Arthur Heymans28bca052019-10-01 21:20:33 +0200214/* Disable unused PEG devices based on devicetree before PCI enumeration */
Angel Pons95de2312020-02-17 13:08:53 +0100215static void ironlake_init(void *const chip_info)
Arthur Heymans28bca052019-10-01 21:20:33 +0200216{
217 u32 deven_mask = UINT32_MAX;
218 const struct device *dev;
219
220 dev = pcidev_on_root(1, 0);
221 if (!dev || !dev->enabled) {
222 printk(BIOS_DEBUG, "Disabling PEG10.\n");
223 deven_mask &= ~DEVEN_PEG10;
224 }
225 dev = pcidev_on_root(2, 0);
226 if (!dev || !dev->enabled) {
227 printk(BIOS_DEBUG, "Disabling IGD.\n");
228 deven_mask &= ~DEVEN_IGD;
229 }
230 const struct device *const d0f0 = pcidev_on_root(0, 0);
231 if (d0f0)
232 pci_update_config32(d0f0, D0F0_DEVEN, deven_mask, 0);
233
234}
235
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100236static struct pci_operations intel_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530237 .set_subsystem = pci_dev_set_subsystem,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100238};
239
240static struct device_operations mc_ops = {
241 .read_resources = mc_read_resources,
242 .set_resources = mc_set_resources,
243 .enable_resources = pci_dev_enable_resources,
244 .init = northbridge_init,
Nico Huber68680dd2020-03-31 17:34:52 +0200245 .acpi_fill_ssdt = generate_cpu_entries,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100246 .ops_pci = &intel_pci_ops,
247};
248
Angel Pons31b7ee42020-02-17 14:04:28 +0100249static const struct pci_driver mc_driver_ard __pci_driver = {
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100250 .ops = &mc_ops,
251 .vendor = PCI_VENDOR_ID_INTEL,
Angel Pons31b7ee42020-02-17 14:04:28 +0100252 .device = 0x0044, /* Arrandale DRAM controller */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100253};
254
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100255static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200256 .read_resources = noop_read_resources,
257 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300258 .init = mp_cpu_bus_init,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100259};
260
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100261static void enable_dev(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100262{
263 /* Set the operations if it is a special bus type */
264 if (dev->path.type == DEVICE_PATH_DOMAIN) {
265 dev->ops = &pci_domain_ops;
266 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
267 dev->ops = &cpu_bus_ops;
268 }
269}
270
Angel Pons95de2312020-02-17 13:08:53 +0100271struct chip_operations northbridge_intel_ironlake_ops = {
Angel Pons31b7ee42020-02-17 14:04:28 +0100272 CHIP_NAME("Intel i7 (Arrandale) integrated Northbridge")
Arthur Heymans28bca052019-10-01 21:20:33 +0200273 .enable_dev = enable_dev,
Angel Pons95de2312020-02-17 13:08:53 +0100274 .init = ironlake_init,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100275};