blob: ecdbe4fee91db555e55eef441a0df0774b900564 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marc Jones1587dc82017-05-15 18:55:11 -06002
Furquan Shaikh91a7abf2020-04-27 18:48:48 -07003#include <assert.h>
Felix Held915c3872023-04-11 21:21:35 +02004#include <amdblocks/acpi.h>
Michał Żygowskif65c1e42019-12-01 18:14:39 +01005#include <amdblocks/biosram.h>
Furquan Shaikh91a7abf2020-04-27 18:48:48 -07006#include <amdblocks/hda.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02007#include <device/pci_ops.h>
Felix Held4b2464f2022-02-23 17:54:20 +01008#include <arch/hpet.h>
Marc Jonesd6a82002018-03-31 22:46:57 -06009#include <arch/ioapic.h>
Felix Helda8da0702023-06-05 21:19:27 +020010#include <arch/vga.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070011#include <acpi/acpi.h>
12#include <acpi/acpigen.h>
Marc Jones1587dc82017-05-15 18:55:11 -060013#include <cbmem.h>
Marc Jones1587dc82017-05-15 18:55:11 -060014#include <console/console.h>
Marc Jones1587dc82017-05-15 18:55:11 -060015#include <cpu/amd/mtrr.h>
Marshall Dawson154239a2017-11-02 09:49:30 -060016#include <cpu/x86/lapic_def.h>
Marshall Dawsonf82aa102017-09-20 18:01:41 -060017#include <cpu/x86/msr.h>
Marc Jones1587dc82017-05-15 18:55:11 -060018#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -070021#include <amdblocks/agesawrapper.h>
22#include <amdblocks/agesawrapper_call.h>
Felix Held604ffa62021-02-12 00:43:20 +010023#include <amdblocks/ioapic.h>
Marshall Dawson2942db62017-12-14 10:00:27 -070024#include <agesa_headers.h>
Marshall Dawson653f7602018-09-04 13:25:39 -060025#include <soc/cpu.h>
Marc Jones1587dc82017-05-15 18:55:11 -060026#include <soc/northbridge.h>
Marshall Dawson38bded02017-09-01 09:54:48 -060027#include <soc/pci_devs.h>
Marshall Dawson2942db62017-12-14 10:00:27 -070028#include <soc/iomap.h>
Marc Jones1587dc82017-05-15 18:55:11 -060029#include <stdint.h>
Marc Jones1587dc82017-05-15 18:55:11 -060030#include <string.h>
31
Elyes HAOUASc3385072019-03-21 15:38:06 +010032#include "chip.h"
33
Elyes HAOUAS777ccd42018-05-22 10:52:05 +020034static void set_io_addr_reg(struct device *dev, u32 nodeid, u32 linkn, u32 reg,
Marc Jones1587dc82017-05-15 18:55:11 -060035 u32 io_min, u32 io_max)
36{
37 u32 tempreg;
Marshall Dawson38bded02017-09-01 09:54:48 -060038
Marshall Dawson4e101ad2017-06-15 12:17:38 -060039 /* io range allocation. Limit */
40 tempreg = (nodeid & 0xf) | ((nodeid & 0x30) << (8 - 4)) | (linkn << 4)
41 | ((io_max & 0xf0) << (12 - 4));
Richard Spiegel41baf0c2018-10-22 13:57:18 -070042 pci_write_config32(SOC_ADDR_DEV, reg + 4, tempreg);
Marshall Dawson4e101ad2017-06-15 12:17:38 -060043 tempreg = 3 | ((io_min & 0xf0) << (12 - 4)); /* base: ISA and VGA ? */
Richard Spiegel41baf0c2018-10-22 13:57:18 -070044 pci_write_config32(SOC_ADDR_DEV, reg, tempreg);
Marc Jones1587dc82017-05-15 18:55:11 -060045}
46
Marshall Dawson4e101ad2017-06-15 12:17:38 -060047static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index,
48 u32 mmio_min, u32 mmio_max)
Marc Jones1587dc82017-05-15 18:55:11 -060049{
50 u32 tempreg;
Marshall Dawson38bded02017-09-01 09:54:48 -060051
Marshall Dawson4e101ad2017-06-15 12:17:38 -060052 /* io range allocation. Limit */
53 tempreg = (nodeid & 0xf) | (linkn << 4) | (mmio_max & 0xffffff00);
Felix Heldaec49ae2023-04-19 21:42:46 +020054 pci_write_config32(SOC_ADDR_DEV, reg + 4, tempreg);
Marc Jones1587dc82017-05-15 18:55:11 -060055 tempreg = 3 | (nodeid & 0x30) | (mmio_min & 0xffffff00);
Felix Heldaec49ae2023-04-19 21:42:46 +020056 pci_write_config32(SOC_ADDR_DEV, reg, tempreg);
Marc Jones1587dc82017-05-15 18:55:11 -060057}
58
Elyes HAOUAS777ccd42018-05-22 10:52:05 +020059static void read_resources(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -060060{
Felix Held56b037b2022-03-02 22:57:01 +010061 unsigned int idx = 0;
Marc Jonesd6a82002018-03-31 22:46:57 -060062 struct resource *res;
63
Felix Heldaf17f0b2022-03-02 23:36:55 +010064 /* The northbridge has no PCI BARs implemented, so there's no need to call
65 pci_dev_read_resources for it */
66
Marc Jones1587dc82017-05-15 18:55:11 -060067 /*
68 * This MMCONF resource must be reserved in the PCI domain.
69 * It is not honored by the coreboot resource allocator if it is in
70 * the CPU_CLUSTER.
71 */
Felix Held56b037b2022-03-02 22:57:01 +010072 mmconf_resource(dev, idx++);
Marc Jonesd6a82002018-03-31 22:46:57 -060073
74 /* NB IOAPIC2 resource */
Felix Heldb1197af2022-03-02 23:02:31 +010075 res = new_resource(dev, idx++); /* IOAPIC2 */
Marc Jonesd6a82002018-03-31 22:46:57 -060076 res->base = IO_APIC2_ADDR;
77 res->size = 0x00001000;
78 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Marc Jones1587dc82017-05-15 18:55:11 -060079}
80
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -070081static void set_resource(struct device *dev, struct resource *res, u32 nodeid)
Marc Jones1587dc82017-05-15 18:55:11 -060082{
83 resource_t rbase, rend;
Marshall Dawson4e101ad2017-06-15 12:17:38 -060084 unsigned int reg, link_num;
Marc Jones1587dc82017-05-15 18:55:11 -060085 char buf[50];
86
87 /* Make certain the resource has actually been set */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -070088 if (!(res->flags & IORESOURCE_ASSIGNED))
Marc Jones1587dc82017-05-15 18:55:11 -060089 return;
90
91 /* If I have already stored this resource don't worry about it */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -070092 if (res->flags & IORESOURCE_STORED)
Marc Jones1587dc82017-05-15 18:55:11 -060093 return;
94
95 /* Only handle PCI memory and IO resources */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -070096 if (!(res->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
Marc Jones1587dc82017-05-15 18:55:11 -060097 return;
98
99 /* Ensure I am actually looking at a resource of function 1 */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700100 if ((res->index & 0xffff) < 0x1000)
Marc Jones1587dc82017-05-15 18:55:11 -0600101 return;
102
103 /* Get the base address */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700104 rbase = res->base;
Marc Jones1587dc82017-05-15 18:55:11 -0600105
106 /* Get the limit (rounded up) */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700107 rend = resource_end(res);
Marc Jones1587dc82017-05-15 18:55:11 -0600108
109 /* Get the register and link */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700110 reg = res->index & 0xfff; /* 4k */
111 link_num = IOINDEX_LINK(res->index);
Marc Jones1587dc82017-05-15 18:55:11 -0600112
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700113 if (res->flags & IORESOURCE_IO)
Elyes Haouas55d0f402022-07-16 09:53:05 +0200114 set_io_addr_reg(dev, nodeid, link_num, reg, rbase >> 8, rend >> 8);
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700115 else if (res->flags & IORESOURCE_MEM)
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600116 set_mmio_addr_reg(nodeid, link_num, reg,
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700117 (res->index >> 24), rbase >> 8, rend >> 8);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600118
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700119 res->flags |= IORESOURCE_STORED;
Marc Jones1587dc82017-05-15 18:55:11 -0600120 snprintf(buf, sizeof(buf), " <node %x link %x>",
121 nodeid, link_num);
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700122 report_resource_stored(dev, res, buf);
Marc Jones1587dc82017-05-15 18:55:11 -0600123}
124
125/**
126 * I tried to reuse the resource allocation code in set_resource()
127 * but it is too difficult to deal with the resource allocation magic.
128 */
129
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200130static void create_vga_resource(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -0600131{
132 struct bus *link;
133
134 /* find out which link the VGA card is connected,
135 * we only deal with the 'first' vga card */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600136 for (link = dev->link_list ; link ; link = link->next)
Marc Jones1587dc82017-05-15 18:55:11 -0600137 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA)
138 break;
Marc Jones1587dc82017-05-15 18:55:11 -0600139
140 /* no VGA card installed */
141 if (link == NULL)
142 return;
143
Marshall Dawsone2697de2017-09-06 10:46:36 -0600144 printk(BIOS_DEBUG, "VGA: %s has VGA device\n", dev_path(dev));
Marshall Dawson38bded02017-09-01 09:54:48 -0600145 /* Route A0000-BFFFF, IO 3B0-3BB 3C0-3DF */
Richard Spiegel41baf0c2018-10-22 13:57:18 -0700146 pci_write_config32(SOC_ADDR_DEV, D18F1_VGAEN, VGA_ADDR_ENABLE);
Marc Jones1587dc82017-05-15 18:55:11 -0600147}
148
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200149static void set_resources(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -0600150{
151 struct bus *bus;
152 struct resource *res;
153
Marc Jones1587dc82017-05-15 18:55:11 -0600154 /* do we need this? */
155 create_vga_resource(dev);
156
157 /* Set each resource we have found */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600158 for (res = dev->resource_list ; res ; res = res->next)
Marc Jones1587dc82017-05-15 18:55:11 -0600159 set_resource(dev, res, 0);
Marc Jones1587dc82017-05-15 18:55:11 -0600160
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600161 for (bus = dev->link_list ; bus ; bus = bus->next)
162 if (bus->children)
Marc Jones1587dc82017-05-15 18:55:11 -0600163 assign_resources(bus);
Marc Jones1587dc82017-05-15 18:55:11 -0600164}
165
166static void northbridge_init(struct device *dev)
167{
Kyösti Mälkki2e65e9c2021-06-16 11:00:40 +0300168 register_new_ioapic((u8 *)IO_APIC2_ADDR);
Marc Jones1587dc82017-05-15 18:55:11 -0600169}
170
Felix Held8cab80c2023-05-05 15:20:15 +0200171/* Used by \_SB.PCI0._CRS */
172static void acpi_fill_root_complex_tom(const struct device *device)
173{
174 const char *scope;
175
176 assert(device);
177
178 scope = acpi_device_scope(device);
179 assert(scope);
180 acpigen_write_scope(scope);
181
182 acpigen_write_name_dword("TOM1", get_top_of_mem_below_4gb());
183
184 /*
185 * Since XP only implements parts of ACPI 2.0, we can't use a qword
186 * here.
187 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
188 * slide 22ff.
189 * Shift value right by 20 bit to make it fit into 32bit,
190 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
191 */
192 acpigen_write_name_dword("TOM2", get_top_of_mem_above_4gb() >> 20);
193 acpigen_pop_len();
194}
195
Marc Jones1587dc82017-05-15 18:55:11 -0600196static unsigned long acpi_fill_hest(acpi_hest_t *hest)
197{
198 void *addr, *current;
199
200 /* Skip the HEST header. */
201 current = (void *)(hest + 1);
202
203 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
204 if (addr != NULL)
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600205 current += acpi_create_hest_error_source(hest, current, 0,
Richard Spiegel271b8a52018-11-06 16:32:28 -0700206 (void *)((u32)addr + 2), *(uint16_t *)addr - 2);
Marc Jones1587dc82017-05-15 18:55:11 -0600207
208 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
209 if (addr != NULL)
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600210 current += acpi_create_hest_error_source(hest, current, 1,
Richard Spiegel271b8a52018-11-06 16:32:28 -0700211 (void *)((u32)addr + 2), *(uint16_t *)addr - 2);
Marc Jones1587dc82017-05-15 18:55:11 -0600212
213 return (unsigned long)current;
214}
215
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700216static unsigned long agesa_write_acpi_tables(const struct device *device,
Marc Jones1587dc82017-05-15 18:55:11 -0600217 unsigned long current,
218 acpi_rsdp_t *rsdp)
219{
220 acpi_srat_t *srat;
221 acpi_slit_t *slit;
Marc Jones1587dc82017-05-15 18:55:11 -0600222 acpi_header_t *alib;
223 acpi_header_t *ivrs;
224 acpi_hest_t *hest;
225
226 /* HEST */
Felix Held9abc4112023-01-18 15:47:39 +0100227 current = acpi_align_current(current);
Marc Jones1587dc82017-05-15 18:55:11 -0600228 hest = (acpi_hest_t *)current;
Richard Spiegel6a9e6cd2018-11-30 10:53:40 -0700229 acpi_write_hest(hest, acpi_fill_hest);
Marc Jones1587dc82017-05-15 18:55:11 -0600230 acpi_add_table(rsdp, (void *)current);
Richard Spiegel6a9e6cd2018-11-30 10:53:40 -0700231 current += hest->header.length;
Marc Jones1587dc82017-05-15 18:55:11 -0600232
Felix Held9abc4112023-01-18 15:47:39 +0100233 current = acpi_align_current(current);
Marc Jones1587dc82017-05-15 18:55:11 -0600234 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
235 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
236 if (ivrs != NULL) {
237 memcpy((void *)current, ivrs, ivrs->length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600238 ivrs = (acpi_header_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600239 current += ivrs->length;
240 acpi_add_table(rsdp, ivrs);
241 } else {
242 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
243 }
244
245 /* SRAT */
Felix Held9abc4112023-01-18 15:47:39 +0100246 current = acpi_align_current(current);
Marc Jones1587dc82017-05-15 18:55:11 -0600247 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600248 srat = (acpi_srat_t *)agesawrapper_getlateinitptr(PICK_SRAT);
Marc Jones1587dc82017-05-15 18:55:11 -0600249 if (srat != NULL) {
250 memcpy((void *)current, srat, srat->header.length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600251 srat = (acpi_srat_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600252 current += srat->header.length;
253 acpi_add_table(rsdp, srat);
254 } else {
255 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
256 }
257
258 /* SLIT */
Felix Held9abc4112023-01-18 15:47:39 +0100259 current = acpi_align_current(current);
Marc Jones1587dc82017-05-15 18:55:11 -0600260 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600261 slit = (acpi_slit_t *)agesawrapper_getlateinitptr(PICK_SLIT);
Marc Jones1587dc82017-05-15 18:55:11 -0600262 if (slit != NULL) {
263 memcpy((void *)current, slit, slit->header.length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600264 slit = (acpi_slit_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600265 current += slit->header.length;
266 acpi_add_table(rsdp, slit);
267 } else {
268 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
269 }
270
271 /* ALIB */
Felix Held9abc4112023-01-18 15:47:39 +0100272 current = acpi_align_current(current);
Marc Jones1587dc82017-05-15 18:55:11 -0600273 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600274 alib = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_ALIB);
Marc Jones1587dc82017-05-15 18:55:11 -0600275 if (alib != NULL) {
276 memcpy((void *)current, alib, alib->length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600277 alib = (acpi_header_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600278 current += alib->length;
279 acpi_add_table(rsdp, (void *)alib);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600280 } else {
281 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL."
282 " Skipping.\n");
Marc Jones1587dc82017-05-15 18:55:11 -0600283 }
284
Marc Jones1587dc82017-05-15 18:55:11 -0600285 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
286 return current;
287}
288
Felix Held26651c82022-10-13 16:12:40 +0200289struct device_operations stoneyridge_northbridge_operations = {
Marc Jones1587dc82017-05-15 18:55:11 -0600290 .read_resources = read_resources,
291 .set_resources = set_resources,
292 .enable_resources = pci_dev_enable_resources,
293 .init = northbridge_init,
Felix Held915c3872023-04-11 21:21:35 +0200294 .acpi_fill_ssdt = acpi_fill_root_complex_tom,
Marc Jones1587dc82017-05-15 18:55:11 -0600295 .write_acpi_tables = agesa_write_acpi_tables,
Marc Jones1587dc82017-05-15 18:55:11 -0600296};
297
Marshall Dawson154239a2017-11-02 09:49:30 -0600298/*
299 * Enable VGA cycles. Set memory ranges of the FCH legacy devices (TPM, HPET,
300 * BIOS RAM, Watchdog Timer, IOAPIC and ACPI) as non-posted. Set remaining
301 * MMIO to posted. Route all I/O to the southbridge.
302 */
303void amd_initcpuio(void)
304{
Felix Held5e9afe72023-04-20 12:55:55 +0200305 uintptr_t topmem = get_top_of_mem_below_4gb();
Marshall Dawson154239a2017-11-02 09:49:30 -0600306 uintptr_t base, limit;
307
308 /* Enable legacy video routing: D18F1xF4 VGA Enable */
309 pci_write_config32(SOC_ADDR_DEV, D18F1_VGAEN, VGA_ADDR_ENABLE);
310
311 /* Non-posted: range(HPET-LAPIC) or 0xfed00000 through 0xfee00000-1 */
312 base = (HPET_BASE_ADDRESS >> 8) | MMIO_WE | MMIO_RE;
Kyösti Mälkkidea42e02021-05-31 20:26:16 +0300313 limit = (ALIGN_DOWN(LAPIC_DEFAULT_BASE - 1, 64 * KiB) >> 8) | MMIO_NP;
Marshall Dawson154239a2017-11-02 09:49:30 -0600314 pci_write_config32(SOC_ADDR_DEV, NB_MMIO_LIMIT_LO(0), limit);
315 pci_write_config32(SOC_ADDR_DEV, NB_MMIO_BASE_LO(0), base);
316
317 /* Remaining PCI hole posted MMIO: TOM-HPET (TOM through 0xfed00000-1 */
318 base = (topmem >> 8) | MMIO_WE | MMIO_RE;
319 limit = ALIGN_DOWN(HPET_BASE_ADDRESS - 1, 64 * KiB) >> 8;
320 pci_write_config32(SOC_ADDR_DEV, NB_MMIO_LIMIT_LO(1), limit);
321 pci_write_config32(SOC_ADDR_DEV, NB_MMIO_BASE_LO(1), base);
322
323 /* Route all I/O downstream */
324 base = 0 | IO_WE | IO_RE;
325 limit = ALIGN_DOWN(0xffff, 4 * KiB);
326 pci_write_config32(SOC_ADDR_DEV, NB_IO_LIMIT(0), limit);
327 pci_write_config32(SOC_ADDR_DEV, NB_IO_BASE(0), base);
328}
329
Marc Jones1587dc82017-05-15 18:55:11 -0600330void fam15_finalize(void *chip_info)
331{
Marc Jones1587dc82017-05-15 18:55:11 -0600332 u32 value;
Richard Spiegel41baf0c2018-10-22 13:57:18 -0700333
334 /* TODO: move IOAPIC code to dsdt.asl */
335 pci_write_config32(SOC_GNB_DEV, NB_IOAPIC_INDEX, 0);
336 pci_write_config32(SOC_GNB_DEV, NB_IOAPIC_DATA, 5);
Marc Jones1587dc82017-05-15 18:55:11 -0600337
338 /* disable No Snoop */
Richard Spiegel41baf0c2018-10-22 13:57:18 -0700339 value = pci_read_config32(SOC_HDA0_DEV, HDA_DEV_CTRL_STATUS);
Richard Spiegel3d34ae32018-04-13 13:20:08 -0700340 value &= ~HDA_NO_SNOOP_EN;
Richard Spiegel41baf0c2018-10-22 13:57:18 -0700341 pci_write_config32(SOC_HDA0_DEV, HDA_DEV_CTRL_STATUS, value);
Marc Jones1587dc82017-05-15 18:55:11 -0600342}
343
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200344void domain_enable_resources(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -0600345{
Marc Jones1587dc82017-05-15 18:55:11 -0600346 /* Must be called after PCI enumeration and resource allocation */
Kyösti Mälkki9e591c42021-01-09 12:37:25 +0200347 if (!acpi_is_wakeup_s3())
Kyösti Mälkki6e512c42018-06-14 06:57:05 +0300348 do_agesawrapper(AMD_INIT_MID, "amdinitmid");
Marc Jones1587dc82017-05-15 18:55:11 -0600349}
350
Furquan Shaikhfc752b62020-05-13 12:14:11 -0700351void domain_read_resources(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -0600352{
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700353 uint64_t uma_base = get_uma_base();
354 uint32_t uma_size = get_uma_size();
355 uint32_t mem_useable = (uintptr_t)cbmem_top();
Felix Held392cf2f2023-04-20 13:23:23 +0200356 uint32_t tom = get_top_of_mem_below_4gb();
Felix Held27af3e62023-04-22 05:59:52 +0200357 uint64_t high_tom = get_top_of_mem_above_4gb();
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700358 uint64_t high_mem_useable;
359 int idx = 0x10;
Marc Jones1587dc82017-05-15 18:55:11 -0600360
Furquan Shaikhfc752b62020-05-13 12:14:11 -0700361 pci_domain_read_resources(dev);
362
Felix Heldd7ad1402023-06-05 15:30:10 +0200363 fixed_io_range_reserved(dev, idx++, PCI_IO_CONFIG_INDEX, PCI_IO_CONFIG_PORT_COUNT);
364
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700365 /* 0x0 -> 0x9ffff */
Arthur Heymans885efa12023-07-05 12:11:12 +0200366 ram_range(dev, idx++, 0, 0xa0000);
Marc Jones1587dc82017-05-15 18:55:11 -0600367
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700368 /* 0xa0000 -> 0xbffff: legacy VGA */
Arthur Heymans885efa12023-07-05 12:11:12 +0200369 mmio_range(dev, idx++, VGA_MMIO_BASE, VGA_MMIO_SIZE);
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700370
371 /* 0xc0000 -> 0xfffff: Option ROM */
Arthur Heymans885efa12023-07-05 12:11:12 +0200372 reserved_ram_from_to(dev, idx++, 0xc0000, 1 * MiB);
Marc Jones1587dc82017-05-15 18:55:11 -0600373
Marshall Dawson29f1b742017-09-06 14:59:45 -0600374 /*
Martin Roth26f97f92021-10-01 14:53:22 -0600375 * 0x100000 (1MiB) -> low top usable RAM
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700376 * cbmem_top() accounts for low UMA and TSEG if they are used.
Marc Jones1587dc82017-05-15 18:55:11 -0600377 */
Arthur Heymans885efa12023-07-05 12:11:12 +0200378 ram_from_to(dev, idx++, 1 * MiB, mem_useable);
Marc Jones1587dc82017-05-15 18:55:11 -0600379
Martin Roth26f97f92021-10-01 14:53:22 -0600380 /* Low top usable RAM -> Low top RAM (bottom pci mmio hole) */
Arthur Heymans885efa12023-07-05 12:11:12 +0200381 reserved_ram_from_to(dev, idx++, mem_useable, tom);
Marc Jones1587dc82017-05-15 18:55:11 -0600382
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700383 /* If there is memory above 4GiB */
Felix Held392cf2f2023-04-20 13:23:23 +0200384 if (high_tom >> 32) {
Martin Roth26f97f92021-10-01 14:53:22 -0600385 /* 4GiB -> high top usable */
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700386 if (uma_base >= (4ull * GiB))
387 high_mem_useable = uma_base;
388 else
Felix Held392cf2f2023-04-20 13:23:23 +0200389 high_mem_useable = high_tom;
Marc Jones1587dc82017-05-15 18:55:11 -0600390
Arthur Heymans885efa12023-07-05 12:11:12 +0200391 ram_from_to(dev, idx++, 4ull * GiB, high_mem_useable);
Marc Jones1587dc82017-05-15 18:55:11 -0600392
Martin Roth26f97f92021-10-01 14:53:22 -0600393 /* High top usable RAM -> high top RAM */
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700394 if (uma_base >= (4ull * GiB)) {
Arthur Heymans885efa12023-07-05 12:11:12 +0200395 reserved_ram_range(dev, idx++, uma_base, uma_size);
Marc Jones1587dc82017-05-15 18:55:11 -0600396 }
Marc Jones1587dc82017-05-15 18:55:11 -0600397 }
Marc Jones1587dc82017-05-15 18:55:11 -0600398}
399
Richard Spiegel2e90ee32018-07-24 12:08:22 -0700400__weak void set_board_env_params(GNB_ENV_CONFIGURATION *params) { }
401
Marshall Dawson2942db62017-12-14 10:00:27 -0700402void SetNbEnvParams(GNB_ENV_CONFIGURATION *params)
403{
Martin Roth50f2e4c2018-10-29 11:16:53 -0600404 const struct device *dev = SOC_IOMMU_DEV;
405 params->IommuSupport = dev && dev->enabled;
Richard Spiegel2e90ee32018-07-24 12:08:22 -0700406 set_board_env_params(params);
Marshall Dawson2942db62017-12-14 10:00:27 -0700407}
408
409void SetNbMidParams(GNB_MID_CONFIGURATION *params)
410{
411 /* 0=Primary and decode all VGA resources, 1=Secondary - decode none */
412 params->iGpuVgaMode = 0;
413 params->GnbIoapicAddress = IO_APIC2_ADDR;
414}
Furquan Shaikh91a7abf2020-04-27 18:48:48 -0700415
416void hda_soc_ssdt_quirks(const struct device *dev)
417{
418 const char *scope = acpi_device_path(dev);
419 static const struct fieldlist list[] = {
420 FIELDLIST_OFFSET(0x42),
421 FIELDLIST_NAMESTR("NSDI", 1),
422 FIELDLIST_NAMESTR("NSDO", 1),
423 FIELDLIST_NAMESTR("NSEN", 1),
424 };
425 struct opregion opreg = OPREGION("AZPD", PCI_CONFIG, 0x0, 0x100);
426
427 assert(scope);
428
429 acpigen_write_scope(scope);
430
431 /*
432 * OperationRegion(AZPD, PCI_Config, 0x00, 0x100)
433 * Field (AZPD, AnyAcc, NoLock, Preserve) {
434 * Offset (0x42),
435 * NSDI, 1,
436 * NSDO, 1,
437 * NSEN, 1,
438 * }
439 */
440 acpigen_write_opregion(&opreg);
441 acpigen_write_field(opreg.name, list, ARRAY_SIZE(list),
442 FIELD_ANYACC | FIELD_NOLOCK | FIELD_PRESERVE);
443
444 /*
445 * Method (_INI, 0, NotSerialized) {
Kyösti Mälkkiff9ba542021-02-09 17:38:23 +0200446 * Store (Zero, NSEN)
447 * Store (One, NSDO)
448 * Store (One, NSDI)
Furquan Shaikh91a7abf2020-04-27 18:48:48 -0700449 * }
450 */
451 acpigen_write_method("_INI", 0);
452
Furquan Shaikhac204ba2021-02-19 10:23:17 -0800453 acpigen_write_store_op_to_namestr(ZERO_OP, "NSEN");
454 acpigen_write_store_op_to_namestr(ONE_OP, "NSDO");
455 acpigen_write_store_op_to_namestr(ONE_OP, "NSDI");
Furquan Shaikh91a7abf2020-04-27 18:48:48 -0700456
Furquan Shaikh91a7abf2020-04-27 18:48:48 -0700457 acpigen_pop_len(); /* Method _INI */
458
459 acpigen_pop_len(); /* Scope */
460}