blob: c78ca7cb58bf6292b5eb3f0ce9b4024a115a461f [file] [log] [blame]
Marc Jones1587dc82017-05-15 18:55:11 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2015-2016 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16
17#include <arch/io.h>
Marc Jonesd6a82002018-03-31 22:46:57 -060018#include <arch/ioapic.h>
Marc Jones1587dc82017-05-15 18:55:11 -060019#include <arch/acpi.h>
20#include <arch/acpigen.h>
21#include <cbmem.h>
22#include <chip.h>
23#include <console/console.h>
Marc Jones1587dc82017-05-15 18:55:11 -060024#include <cpu/amd/mtrr.h>
Aaron Durbin3173d442017-11-03 12:14:25 -060025#include <cpu/amd/amdfam15.h>
Marc Jones1587dc82017-05-15 18:55:11 -060026#include <cpu/cpu.h>
Marshall Dawson154239a2017-11-02 09:49:30 -060027#include <cpu/x86/lapic_def.h>
Marshall Dawsonf82aa102017-09-20 18:01:41 -060028#include <cpu/x86/msr.h>
Marc Jones1587dc82017-05-15 18:55:11 -060029#include <device/device.h>
30#include <device/pci.h>
31#include <device/pci_ids.h>
Marshall Dawson8f2a7e02017-11-01 11:44:48 -060032#include <romstage_handoff.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -070033#include <amdblocks/agesawrapper.h>
34#include <amdblocks/agesawrapper_call.h>
Marshall Dawson2942db62017-12-14 10:00:27 -070035#include <agesa_headers.h>
Marc Jones1587dc82017-05-15 18:55:11 -060036#include <soc/northbridge.h>
Marshall Dawson154239a2017-11-02 09:49:30 -060037#include <soc/southbridge.h>
Marshall Dawson38bded02017-09-01 09:54:48 -060038#include <soc/pci_devs.h>
Marshall Dawson2942db62017-12-14 10:00:27 -070039#include <soc/iomap.h>
Marc Jones1587dc82017-05-15 18:55:11 -060040#include <stdint.h>
41#include <stdlib.h>
42#include <string.h>
43
Elyes HAOUAS777ccd42018-05-22 10:52:05 +020044static void set_io_addr_reg(struct device *dev, u32 nodeid, u32 linkn, u32 reg,
Marc Jones1587dc82017-05-15 18:55:11 -060045 u32 io_min, u32 io_max)
46{
47 u32 tempreg;
Elyes HAOUAS777ccd42018-05-22 10:52:05 +020048 struct device *addr_map = dev_find_slot(0, ADDR_DEVFN);
Marshall Dawson38bded02017-09-01 09:54:48 -060049
Marshall Dawson4e101ad2017-06-15 12:17:38 -060050 /* io range allocation. Limit */
51 tempreg = (nodeid & 0xf) | ((nodeid & 0x30) << (8 - 4)) | (linkn << 4)
52 | ((io_max & 0xf0) << (12 - 4));
Marshall Dawson38bded02017-09-01 09:54:48 -060053 pci_write_config32(addr_map, reg + 4, tempreg);
Marshall Dawson4e101ad2017-06-15 12:17:38 -060054 tempreg = 3 | ((io_min & 0xf0) << (12 - 4)); /* base: ISA and VGA ? */
Marshall Dawson38bded02017-09-01 09:54:48 -060055 pci_write_config32(addr_map, reg, tempreg);
Marc Jones1587dc82017-05-15 18:55:11 -060056}
57
Marshall Dawson4e101ad2017-06-15 12:17:38 -060058static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index,
59 u32 mmio_min, u32 mmio_max)
Marc Jones1587dc82017-05-15 18:55:11 -060060{
61 u32 tempreg;
Elyes HAOUAS777ccd42018-05-22 10:52:05 +020062 struct device *addr_map = dev_find_slot(0, ADDR_DEVFN);
Marshall Dawson38bded02017-09-01 09:54:48 -060063
Marshall Dawson4e101ad2017-06-15 12:17:38 -060064 /* io range allocation. Limit */
65 tempreg = (nodeid & 0xf) | (linkn << 4) | (mmio_max & 0xffffff00);
Marshall Dawson38bded02017-09-01 09:54:48 -060066 pci_write_config32(addr_map, reg + 4, tempreg);
Marc Jones1587dc82017-05-15 18:55:11 -060067 tempreg = 3 | (nodeid & 0x30) | (mmio_min & 0xffffff00);
Marshall Dawson38bded02017-09-01 09:54:48 -060068 pci_write_config32(addr_map, reg, tempreg);
Marc Jones1587dc82017-05-15 18:55:11 -060069}
70
Elyes HAOUAS777ccd42018-05-22 10:52:05 +020071static void read_resources(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -060072{
Marc Jonesd6a82002018-03-31 22:46:57 -060073 struct resource *res;
74
Marc Jones1587dc82017-05-15 18:55:11 -060075 /*
76 * This MMCONF resource must be reserved in the PCI domain.
77 * It is not honored by the coreboot resource allocator if it is in
78 * the CPU_CLUSTER.
79 */
Aaron Durbin3173d442017-11-03 12:14:25 -060080 mmconf_resource(dev, MMIO_CONF_BASE);
Marc Jonesd6a82002018-03-31 22:46:57 -060081
82 /* NB IOAPIC2 resource */
83 res = new_resource(dev, IO_APIC2_ADDR); /* IOAPIC2 */
84 res->base = IO_APIC2_ADDR;
85 res->size = 0x00001000;
86 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Marc Jones1587dc82017-05-15 18:55:11 -060087}
88
Elyes HAOUAS777ccd42018-05-22 10:52:05 +020089static void set_resource(struct device *dev, struct resource *resource, u32 nodeid)
Marc Jones1587dc82017-05-15 18:55:11 -060090{
91 resource_t rbase, rend;
Marshall Dawson4e101ad2017-06-15 12:17:38 -060092 unsigned int reg, link_num;
Marc Jones1587dc82017-05-15 18:55:11 -060093 char buf[50];
94
95 /* Make certain the resource has actually been set */
96 if (!(resource->flags & IORESOURCE_ASSIGNED))
97 return;
98
99 /* If I have already stored this resource don't worry about it */
100 if (resource->flags & IORESOURCE_STORED)
101 return;
102
103 /* Only handle PCI memory and IO resources */
104 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
105 return;
106
107 /* Ensure I am actually looking at a resource of function 1 */
108 if ((resource->index & 0xffff) < 0x1000)
109 return;
110
111 /* Get the base address */
112 rbase = resource->base;
113
114 /* Get the limit (rounded up) */
115 rend = resource_end(resource);
116
117 /* Get the register and link */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600118 reg = resource->index & 0xfff; /* 4k */
Marc Jones1587dc82017-05-15 18:55:11 -0600119 link_num = IOINDEX_LINK(resource->index);
120
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600121 if (resource->flags & IORESOURCE_IO)
Marc Jones1587dc82017-05-15 18:55:11 -0600122 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600123 else if (resource->flags & IORESOURCE_MEM)
124 set_mmio_addr_reg(nodeid, link_num, reg,
125 (resource->index >> 24), rbase >> 8, rend >> 8);
126
Marc Jones1587dc82017-05-15 18:55:11 -0600127 resource->flags |= IORESOURCE_STORED;
128 snprintf(buf, sizeof(buf), " <node %x link %x>",
129 nodeid, link_num);
130 report_resource_stored(dev, resource, buf);
131}
132
133/**
134 * I tried to reuse the resource allocation code in set_resource()
135 * but it is too difficult to deal with the resource allocation magic.
136 */
137
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200138static void create_vga_resource(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -0600139{
140 struct bus *link;
141
142 /* find out which link the VGA card is connected,
143 * we only deal with the 'first' vga card */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600144 for (link = dev->link_list ; link ; link = link->next)
Marc Jones1587dc82017-05-15 18:55:11 -0600145 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA)
146 break;
Marc Jones1587dc82017-05-15 18:55:11 -0600147
148 /* no VGA card installed */
149 if (link == NULL)
150 return;
151
Marshall Dawsone2697de2017-09-06 10:46:36 -0600152 printk(BIOS_DEBUG, "VGA: %s has VGA device\n", dev_path(dev));
Marshall Dawson38bded02017-09-01 09:54:48 -0600153 /* Route A0000-BFFFF, IO 3B0-3BB 3C0-3DF */
154 pci_write_config32(dev_find_slot(0, ADDR_DEVFN), 0xf4, 1);
Marc Jones1587dc82017-05-15 18:55:11 -0600155}
156
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200157static void set_resources(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -0600158{
159 struct bus *bus;
160 struct resource *res;
161
162
163 /* do we need this? */
164 create_vga_resource(dev);
165
166 /* Set each resource we have found */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600167 for (res = dev->resource_list ; res ; res = res->next)
Marc Jones1587dc82017-05-15 18:55:11 -0600168 set_resource(dev, res, 0);
Marc Jones1587dc82017-05-15 18:55:11 -0600169
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600170 for (bus = dev->link_list ; bus ; bus = bus->next)
171 if (bus->children)
Marc Jones1587dc82017-05-15 18:55:11 -0600172 assign_resources(bus);
Marc Jones1587dc82017-05-15 18:55:11 -0600173}
174
175static void northbridge_init(struct device *dev)
176{
Marc Jonesd6a82002018-03-31 22:46:57 -0600177 setup_ioapic((u8 *)IO_APIC2_ADDR, CONFIG_MAX_CPUS+1);
Marc Jones1587dc82017-05-15 18:55:11 -0600178}
179
180static unsigned long acpi_fill_hest(acpi_hest_t *hest)
181{
182 void *addr, *current;
183
184 /* Skip the HEST header. */
185 current = (void *)(hest + 1);
186
187 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
188 if (addr != NULL)
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600189 current += acpi_create_hest_error_source(hest, current, 0,
190 (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
Marc Jones1587dc82017-05-15 18:55:11 -0600191
192 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
193 if (addr != NULL)
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600194 current += acpi_create_hest_error_source(hest, current, 1,
195 (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
Marc Jones1587dc82017-05-15 18:55:11 -0600196
197 return (unsigned long)current;
198}
199
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200200static void northbridge_fill_ssdt_generator(struct device *device)
Marc Jones1587dc82017-05-15 18:55:11 -0600201{
202 msr_t msr;
203 char pscope[] = "\\_SB.PCI0";
204
205 acpigen_write_scope(pscope);
206 msr = rdmsr(TOP_MEM);
207 acpigen_write_name_dword("TOM1", msr.lo);
208 msr = rdmsr(TOP_MEM2);
209 /*
210 * Since XP only implements parts of ACPI 2.0, we can't use a qword
211 * here.
212 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
213 * slide 22ff.
214 * Shift value right by 20 bit to make it fit into 32bit,
215 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
216 */
217 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
218 acpigen_pop_len();
219}
220
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200221static unsigned long agesa_write_acpi_tables(struct device *device,
Marc Jones1587dc82017-05-15 18:55:11 -0600222 unsigned long current,
223 acpi_rsdp_t *rsdp)
224{
225 acpi_srat_t *srat;
226 acpi_slit_t *slit;
227 acpi_header_t *ssdt;
228 acpi_header_t *alib;
229 acpi_header_t *ivrs;
230 acpi_hest_t *hest;
231
232 /* HEST */
233 current = ALIGN(current, 8);
234 hest = (acpi_hest_t *)current;
235 acpi_write_hest((void *)current, acpi_fill_hest);
236 acpi_add_table(rsdp, (void *)current);
237 current += ((acpi_header_t *)current)->length;
238
239 current = ALIGN(current, 8);
240 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
241 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
242 if (ivrs != NULL) {
243 memcpy((void *)current, ivrs, ivrs->length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600244 ivrs = (acpi_header_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600245 current += ivrs->length;
246 acpi_add_table(rsdp, ivrs);
247 } else {
248 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
249 }
250
251 /* SRAT */
252 current = ALIGN(current, 8);
253 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600254 srat = (acpi_srat_t *)agesawrapper_getlateinitptr(PICK_SRAT);
Marc Jones1587dc82017-05-15 18:55:11 -0600255 if (srat != NULL) {
256 memcpy((void *)current, srat, srat->header.length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600257 srat = (acpi_srat_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600258 current += srat->header.length;
259 acpi_add_table(rsdp, srat);
260 } else {
261 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
262 }
263
264 /* SLIT */
265 current = ALIGN(current, 8);
266 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600267 slit = (acpi_slit_t *)agesawrapper_getlateinitptr(PICK_SLIT);
Marc Jones1587dc82017-05-15 18:55:11 -0600268 if (slit != NULL) {
269 memcpy((void *)current, slit, slit->header.length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600270 slit = (acpi_slit_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600271 current += slit->header.length;
272 acpi_add_table(rsdp, slit);
273 } else {
274 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
275 }
276
277 /* ALIB */
278 current = ALIGN(current, 16);
279 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600280 alib = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_ALIB);
Marc Jones1587dc82017-05-15 18:55:11 -0600281 if (alib != NULL) {
282 memcpy((void *)current, alib, alib->length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600283 alib = (acpi_header_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600284 current += alib->length;
285 acpi_add_table(rsdp, (void *)alib);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600286 } else {
287 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL."
288 " Skipping.\n");
Marc Jones1587dc82017-05-15 18:55:11 -0600289 }
290
Marc Jones1587dc82017-05-15 18:55:11 -0600291 current = ALIGN(current, 16);
292 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600293 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_PSTATE);
Marc Jones1587dc82017-05-15 18:55:11 -0600294 if (ssdt != NULL) {
295 memcpy((void *)current, ssdt, ssdt->length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600296 ssdt = (acpi_header_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600297 current += ssdt->length;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600298 } else {
Marc Jones1587dc82017-05-15 18:55:11 -0600299 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
300 }
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600301 acpi_add_table(rsdp, ssdt);
Marc Jones1587dc82017-05-15 18:55:11 -0600302
303 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
304 return current;
305}
306
307static struct device_operations northbridge_operations = {
308 .read_resources = read_resources,
309 .set_resources = set_resources,
310 .enable_resources = pci_dev_enable_resources,
311 .init = northbridge_init,
312 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
313 .write_acpi_tables = agesa_write_acpi_tables,
314 .enable = 0,
315 .ops_pci = 0,
316};
317
318static const struct pci_driver family15_northbridge __pci_driver = {
319 .ops = &northbridge_operations,
320 .vendor = PCI_VENDOR_ID_AMD,
321 .device = PCI_DEVICE_ID_AMD_15H_MODEL_707F_NB_HT,
322};
323
Marshall Dawson154239a2017-11-02 09:49:30 -0600324/*
325 * Enable VGA cycles. Set memory ranges of the FCH legacy devices (TPM, HPET,
326 * BIOS RAM, Watchdog Timer, IOAPIC and ACPI) as non-posted. Set remaining
327 * MMIO to posted. Route all I/O to the southbridge.
328 */
329void amd_initcpuio(void)
330{
331 uintptr_t topmem = bsp_topmem();
332 uintptr_t base, limit;
333
334 /* Enable legacy video routing: D18F1xF4 VGA Enable */
335 pci_write_config32(SOC_ADDR_DEV, D18F1_VGAEN, VGA_ADDR_ENABLE);
336
337 /* Non-posted: range(HPET-LAPIC) or 0xfed00000 through 0xfee00000-1 */
338 base = (HPET_BASE_ADDRESS >> 8) | MMIO_WE | MMIO_RE;
339 limit = (ALIGN_DOWN(LOCAL_APIC_ADDR - 1, 64 * KiB) >> 8) | MMIO_NP;
340 pci_write_config32(SOC_ADDR_DEV, NB_MMIO_LIMIT_LO(0), limit);
341 pci_write_config32(SOC_ADDR_DEV, NB_MMIO_BASE_LO(0), base);
342
343 /* Remaining PCI hole posted MMIO: TOM-HPET (TOM through 0xfed00000-1 */
344 base = (topmem >> 8) | MMIO_WE | MMIO_RE;
345 limit = ALIGN_DOWN(HPET_BASE_ADDRESS - 1, 64 * KiB) >> 8;
346 pci_write_config32(SOC_ADDR_DEV, NB_MMIO_LIMIT_LO(1), limit);
347 pci_write_config32(SOC_ADDR_DEV, NB_MMIO_BASE_LO(1), base);
348
349 /* Route all I/O downstream */
350 base = 0 | IO_WE | IO_RE;
351 limit = ALIGN_DOWN(0xffff, 4 * KiB);
352 pci_write_config32(SOC_ADDR_DEV, NB_IO_LIMIT(0), limit);
353 pci_write_config32(SOC_ADDR_DEV, NB_IO_BASE(0), base);
354}
355
Marc Jones1587dc82017-05-15 18:55:11 -0600356void fam15_finalize(void *chip_info)
357{
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200358 struct device *dev;
Marc Jones1587dc82017-05-15 18:55:11 -0600359 u32 value;
Chris Ching6a35fab2017-10-19 11:45:30 -0600360 dev = dev_find_slot(0, GNB_DEVFN); /* clear IoapicSbFeatureEn */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600361 pci_write_config32(dev, 0xf8, 0);
362 pci_write_config32(dev, 0xfc, 5); /* TODO: move it to dsdt.asl */
Marc Jones1587dc82017-05-15 18:55:11 -0600363
364 /* disable No Snoop */
Chris Ching6a35fab2017-10-19 11:45:30 -0600365 dev = dev_find_slot(0, HDA0_DEVFN);
Richard Spiegel3d34ae32018-04-13 13:20:08 -0700366 value = pci_read_config32(dev, HDA_DEV_CTRL_STATUS);
367 value &= ~HDA_NO_SNOOP_EN;
368 pci_write_config32(dev, HDA_DEV_CTRL_STATUS, value);
Marc Jones1587dc82017-05-15 18:55:11 -0600369}
370
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200371void domain_read_resources(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -0600372{
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600373 unsigned int reg;
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200374 struct device *addr_map = dev_find_slot(0, ADDR_DEVFN);
Marc Jones1587dc82017-05-15 18:55:11 -0600375
376 /* Find the already assigned resource pairs */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600377 for (reg = 0x80 ; reg <= 0xd8 ; reg += 0x08) {
Marc Jones1587dc82017-05-15 18:55:11 -0600378 u32 base, limit;
Marshall Dawson38bded02017-09-01 09:54:48 -0600379 base = pci_read_config32(addr_map, reg);
380 limit = pci_read_config32(addr_map, reg + 4);
Marc Jones1587dc82017-05-15 18:55:11 -0600381 /* Is this register allocated? */
382 if ((base & 3) != 0) {
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600383 unsigned int nodeid, reg_link;
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200384 struct device *reg_dev = dev_find_slot(0, HT_DEVFN);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600385 if (reg < 0xc0) /* mmio */
Marc Jones1587dc82017-05-15 18:55:11 -0600386 nodeid = (limit & 0xf) + (base & 0x30);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600387 else /* io */
Marc Jones1587dc82017-05-15 18:55:11 -0600388 nodeid = (limit & 0xf) + ((base >> 4) & 0x30);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600389
Marc Jones1587dc82017-05-15 18:55:11 -0600390 reg_link = (limit >> 4) & 7;
Marc Jones1587dc82017-05-15 18:55:11 -0600391 if (reg_dev) {
392 /* Reserve the resource */
393 struct resource *res;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600394 res = new_resource(reg_dev,
395 IOINDEX(0x1000 + reg,
396 reg_link));
397 if (res)
Marc Jones1587dc82017-05-15 18:55:11 -0600398 res->flags = 1;
Marc Jones1587dc82017-05-15 18:55:11 -0600399 }
400 }
401 }
402 /* FIXME: do we need to check extend conf space?
403 I don't believe that much preset value */
404
405 pci_domain_read_resources(dev);
406}
407
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200408void domain_enable_resources(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -0600409{
Marc Jones1587dc82017-05-15 18:55:11 -0600410 /* Must be called after PCI enumeration and resource allocation */
Marshall Dawson8f2a7e02017-11-01 11:44:48 -0600411 if (!romstage_handoff_is_resume())
Richard Spiegel138a1d22017-12-13 13:26:21 -0700412 do_agesawrapper(agesawrapper_amdinitmid, "amdinitmid");
Marc Jones1587dc82017-05-15 18:55:11 -0600413}
414
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200415void domain_set_resources(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -0600416{
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700417 uint64_t uma_base = get_uma_base();
418 uint32_t uma_size = get_uma_size();
419 uint32_t mem_useable = (uintptr_t)cbmem_top();
420 msr_t tom = rdmsr(TOP_MEM);
421 msr_t high_tom = rdmsr(TOP_MEM2);
422 uint64_t high_mem_useable;
423 int idx = 0x10;
Marc Jones1587dc82017-05-15 18:55:11 -0600424
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700425 /* 0x0 -> 0x9ffff */
426 ram_resource(dev, idx++, 0, 0xa0000 / KiB);
Marc Jones1587dc82017-05-15 18:55:11 -0600427
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700428 /* 0xa0000 -> 0xbffff: legacy VGA */
429 mmio_resource(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB);
430
431 /* 0xc0000 -> 0xfffff: Option ROM */
432 reserved_ram_resource(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB);
Marc Jones1587dc82017-05-15 18:55:11 -0600433
Marshall Dawson29f1b742017-09-06 14:59:45 -0600434 /*
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700435 * 0x100000 (1MiB) -> low top useable RAM
436 * cbmem_top() accounts for low UMA and TSEG if they are used.
Marc Jones1587dc82017-05-15 18:55:11 -0600437 */
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700438 ram_resource(dev, idx++, (1 * MiB) / KiB,
439 (mem_useable - (1 * MiB)) / KiB);
Marc Jones1587dc82017-05-15 18:55:11 -0600440
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700441 /* Low top useable RAM -> Low top RAM (bottom pci mmio hole) */
442 reserved_ram_resource(dev, idx++, mem_useable / KiB,
443 (tom.lo - mem_useable) / KiB);
Marc Jones1587dc82017-05-15 18:55:11 -0600444
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700445 /* If there is memory above 4GiB */
446 if (high_tom.hi) {
447 /* 4GiB -> high top useable */
448 if (uma_base >= (4ull * GiB))
449 high_mem_useable = uma_base;
450 else
451 high_mem_useable = ((uint64_t)high_tom.lo |
452 ((uint64_t)high_tom.hi << 32));
Marc Jones1587dc82017-05-15 18:55:11 -0600453
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700454 ram_resource(dev, idx++, (4ull * GiB) / KiB,
455 ((high_mem_useable - (4ull * GiB)) / KiB));
Marc Jones1587dc82017-05-15 18:55:11 -0600456
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700457 /* High top useable RAM -> high top RAM */
458 if (uma_base >= (4ull * GiB)) {
459 reserved_ram_resource(dev, idx++, uma_base / KiB,
460 uma_size / KiB);
Marc Jones1587dc82017-05-15 18:55:11 -0600461 }
Marc Jones1587dc82017-05-15 18:55:11 -0600462 }
463
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700464 assign_resources(dev->link_list);
Marc Jones1587dc82017-05-15 18:55:11 -0600465}
466
Marc Jones1587dc82017-05-15 18:55:11 -0600467/*********************************************************************
468 * Change the vendor / device IDs to match the generic VBIOS header. *
469 *********************************************************************/
470u32 map_oprom_vendev(u32 vendev)
471{
472 u32 new_vendev;
473 new_vendev =
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600474 ((vendev >= 0x100298e0) && (vendev <= 0x100298ef)) ?
475 0x100298e0 : vendev;
Marc Jones1587dc82017-05-15 18:55:11 -0600476
477 if (vendev != new_vendev)
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600478 printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n",
479 vendev, new_vendev);
Marc Jones1587dc82017-05-15 18:55:11 -0600480
481 return new_vendev;
482}
Marshall Dawson2942db62017-12-14 10:00:27 -0700483
Richard Spiegel2e90ee32018-07-24 12:08:22 -0700484__weak void set_board_env_params(GNB_ENV_CONFIGURATION *params) { }
485
Marshall Dawson2942db62017-12-14 10:00:27 -0700486void SetNbEnvParams(GNB_ENV_CONFIGURATION *params)
487{
488 params->IommuSupport = FALSE;
Richard Spiegel2e90ee32018-07-24 12:08:22 -0700489 set_board_env_params(params);
Marshall Dawson2942db62017-12-14 10:00:27 -0700490}
491
492void SetNbMidParams(GNB_MID_CONFIGURATION *params)
493{
494 /* 0=Primary and decode all VGA resources, 1=Secondary - decode none */
495 params->iGpuVgaMode = 0;
496 params->GnbIoapicAddress = IO_APIC2_ADDR;
497}