blob: 081bc1f47d481418996469b76b71f125a243c824 [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
Felix Heldaf17f0b2022-03-02 23:36:55 +010063 /* The northbridge has no PCI BARs implemented, so there's no need to call
64 pci_dev_read_resources for it */
65
Marc Jones1587dc82017-05-15 18:55:11 -060066 /*
67 * This MMCONF resource must be reserved in the PCI domain.
68 * It is not honored by the coreboot resource allocator if it is in
69 * the CPU_CLUSTER.
70 */
Felix Held56b037b2022-03-02 22:57:01 +010071 mmconf_resource(dev, idx++);
Marc Jonesd6a82002018-03-31 22:46:57 -060072
73 /* NB IOAPIC2 resource */
Felix Held8f0075c2023-08-09 19:28:39 +020074 mmio_range(dev, idx++, IO_APIC2_ADDR, 0x1000);
Marc Jones1587dc82017-05-15 18:55:11 -060075}
76
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -070077static void set_resource(struct device *dev, struct resource *res, u32 nodeid)
Marc Jones1587dc82017-05-15 18:55:11 -060078{
79 resource_t rbase, rend;
Marshall Dawson4e101ad2017-06-15 12:17:38 -060080 unsigned int reg, link_num;
Marc Jones1587dc82017-05-15 18:55:11 -060081 char buf[50];
82
83 /* Make certain the resource has actually been set */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -070084 if (!(res->flags & IORESOURCE_ASSIGNED))
Marc Jones1587dc82017-05-15 18:55:11 -060085 return;
86
87 /* If I have already stored this resource don't worry about it */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -070088 if (res->flags & IORESOURCE_STORED)
Marc Jones1587dc82017-05-15 18:55:11 -060089 return;
90
91 /* Only handle PCI memory and IO resources */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -070092 if (!(res->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
Marc Jones1587dc82017-05-15 18:55:11 -060093 return;
94
95 /* Ensure I am actually looking at a resource of function 1 */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -070096 if ((res->index & 0xffff) < 0x1000)
Marc Jones1587dc82017-05-15 18:55:11 -060097 return;
98
99 /* Get the base address */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700100 rbase = res->base;
Marc Jones1587dc82017-05-15 18:55:11 -0600101
102 /* Get the limit (rounded up) */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700103 rend = resource_end(res);
Marc Jones1587dc82017-05-15 18:55:11 -0600104
105 /* Get the register and link */
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700106 reg = res->index & 0xfff; /* 4k */
107 link_num = IOINDEX_LINK(res->index);
Marc Jones1587dc82017-05-15 18:55:11 -0600108
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700109 if (res->flags & IORESOURCE_IO)
Elyes Haouas55d0f402022-07-16 09:53:05 +0200110 set_io_addr_reg(dev, nodeid, link_num, reg, rbase >> 8, rend >> 8);
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700111 else if (res->flags & IORESOURCE_MEM)
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600112 set_mmio_addr_reg(nodeid, link_num, reg,
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700113 (res->index >> 24), rbase >> 8, rend >> 8);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600114
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700115 res->flags |= IORESOURCE_STORED;
Marc Jones1587dc82017-05-15 18:55:11 -0600116 snprintf(buf, sizeof(buf), " <node %x link %x>",
117 nodeid, link_num);
Richard Spiegel2b7cd1d2018-10-22 14:39:37 -0700118 report_resource_stored(dev, res, buf);
Marc Jones1587dc82017-05-15 18:55:11 -0600119}
120
121/**
122 * I tried to reuse the resource allocation code in set_resource()
123 * but it is too difficult to deal with the resource allocation magic.
124 */
125
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200126static void create_vga_resource(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -0600127{
128 struct bus *link;
129
130 /* find out which link the VGA card is connected,
131 * we only deal with the 'first' vga card */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600132 for (link = dev->link_list ; link ; link = link->next)
Marc Jones1587dc82017-05-15 18:55:11 -0600133 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA)
134 break;
Marc Jones1587dc82017-05-15 18:55:11 -0600135
136 /* no VGA card installed */
137 if (link == NULL)
138 return;
139
Marshall Dawsone2697de2017-09-06 10:46:36 -0600140 printk(BIOS_DEBUG, "VGA: %s has VGA device\n", dev_path(dev));
Marshall Dawson38bded02017-09-01 09:54:48 -0600141 /* Route A0000-BFFFF, IO 3B0-3BB 3C0-3DF */
Richard Spiegel41baf0c2018-10-22 13:57:18 -0700142 pci_write_config32(SOC_ADDR_DEV, D18F1_VGAEN, VGA_ADDR_ENABLE);
Marc Jones1587dc82017-05-15 18:55:11 -0600143}
144
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200145static void set_resources(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -0600146{
147 struct bus *bus;
148 struct resource *res;
149
Marc Jones1587dc82017-05-15 18:55:11 -0600150 /* do we need this? */
151 create_vga_resource(dev);
152
153 /* Set each resource we have found */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600154 for (res = dev->resource_list ; res ; res = res->next)
Marc Jones1587dc82017-05-15 18:55:11 -0600155 set_resource(dev, res, 0);
Marc Jones1587dc82017-05-15 18:55:11 -0600156
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600157 for (bus = dev->link_list ; bus ; bus = bus->next)
158 if (bus->children)
Marc Jones1587dc82017-05-15 18:55:11 -0600159 assign_resources(bus);
Marc Jones1587dc82017-05-15 18:55:11 -0600160}
161
162static void northbridge_init(struct device *dev)
163{
Kyösti Mälkki2e65e9c2021-06-16 11:00:40 +0300164 register_new_ioapic((u8 *)IO_APIC2_ADDR);
Marc Jones1587dc82017-05-15 18:55:11 -0600165}
166
Felix Held8cab80c2023-05-05 15:20:15 +0200167/* Used by \_SB.PCI0._CRS */
168static void acpi_fill_root_complex_tom(const struct device *device)
169{
170 const char *scope;
171
172 assert(device);
173
174 scope = acpi_device_scope(device);
175 assert(scope);
176 acpigen_write_scope(scope);
177
178 acpigen_write_name_dword("TOM1", get_top_of_mem_below_4gb());
179
180 /*
181 * Since XP only implements parts of ACPI 2.0, we can't use a qword
182 * here.
183 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
184 * slide 22ff.
185 * Shift value right by 20 bit to make it fit into 32bit,
186 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
187 */
188 acpigen_write_name_dword("TOM2", get_top_of_mem_above_4gb() >> 20);
189 acpigen_pop_len();
190}
191
Marc Jones1587dc82017-05-15 18:55:11 -0600192static unsigned long acpi_fill_hest(acpi_hest_t *hest)
193{
194 void *addr, *current;
195
196 /* Skip the HEST header. */
197 current = (void *)(hest + 1);
198
199 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
200 if (addr != NULL)
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600201 current += acpi_create_hest_error_source(hest, current, 0,
Richard Spiegel271b8a52018-11-06 16:32:28 -0700202 (void *)((u32)addr + 2), *(uint16_t *)addr - 2);
Marc Jones1587dc82017-05-15 18:55:11 -0600203
204 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
205 if (addr != NULL)
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600206 current += acpi_create_hest_error_source(hest, current, 1,
Richard Spiegel271b8a52018-11-06 16:32:28 -0700207 (void *)((u32)addr + 2), *(uint16_t *)addr - 2);
Marc Jones1587dc82017-05-15 18:55:11 -0600208
209 return (unsigned long)current;
210}
211
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700212static unsigned long agesa_write_acpi_tables(const struct device *device,
Marc Jones1587dc82017-05-15 18:55:11 -0600213 unsigned long current,
214 acpi_rsdp_t *rsdp)
215{
216 acpi_srat_t *srat;
217 acpi_slit_t *slit;
Marc Jones1587dc82017-05-15 18:55:11 -0600218 acpi_header_t *alib;
219 acpi_header_t *ivrs;
220 acpi_hest_t *hest;
221
222 /* HEST */
Felix Held9abc4112023-01-18 15:47:39 +0100223 current = acpi_align_current(current);
Marc Jones1587dc82017-05-15 18:55:11 -0600224 hest = (acpi_hest_t *)current;
Richard Spiegel6a9e6cd2018-11-30 10:53:40 -0700225 acpi_write_hest(hest, acpi_fill_hest);
Marc Jones1587dc82017-05-15 18:55:11 -0600226 acpi_add_table(rsdp, (void *)current);
Richard Spiegel6a9e6cd2018-11-30 10:53:40 -0700227 current += hest->header.length;
Marc Jones1587dc82017-05-15 18:55:11 -0600228
Felix Held9abc4112023-01-18 15:47:39 +0100229 current = acpi_align_current(current);
Marc Jones1587dc82017-05-15 18:55:11 -0600230 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
231 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
232 if (ivrs != NULL) {
233 memcpy((void *)current, ivrs, ivrs->length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600234 ivrs = (acpi_header_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600235 current += ivrs->length;
236 acpi_add_table(rsdp, ivrs);
237 } else {
238 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
239 }
240
241 /* SRAT */
Felix Held9abc4112023-01-18 15:47:39 +0100242 current = acpi_align_current(current);
Marc Jones1587dc82017-05-15 18:55:11 -0600243 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600244 srat = (acpi_srat_t *)agesawrapper_getlateinitptr(PICK_SRAT);
Marc Jones1587dc82017-05-15 18:55:11 -0600245 if (srat != NULL) {
246 memcpy((void *)current, srat, srat->header.length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600247 srat = (acpi_srat_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600248 current += srat->header.length;
249 acpi_add_table(rsdp, srat);
250 } else {
251 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
252 }
253
254 /* SLIT */
Felix Held9abc4112023-01-18 15:47:39 +0100255 current = acpi_align_current(current);
Marc Jones1587dc82017-05-15 18:55:11 -0600256 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600257 slit = (acpi_slit_t *)agesawrapper_getlateinitptr(PICK_SLIT);
Marc Jones1587dc82017-05-15 18:55:11 -0600258 if (slit != NULL) {
259 memcpy((void *)current, slit, slit->header.length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600260 slit = (acpi_slit_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600261 current += slit->header.length;
262 acpi_add_table(rsdp, slit);
263 } else {
264 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
265 }
266
267 /* ALIB */
Felix Held9abc4112023-01-18 15:47:39 +0100268 current = acpi_align_current(current);
Marc Jones1587dc82017-05-15 18:55:11 -0600269 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600270 alib = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_ALIB);
Marc Jones1587dc82017-05-15 18:55:11 -0600271 if (alib != NULL) {
272 memcpy((void *)current, alib, alib->length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600273 alib = (acpi_header_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600274 current += alib->length;
275 acpi_add_table(rsdp, (void *)alib);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600276 } else {
277 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL."
278 " Skipping.\n");
Marc Jones1587dc82017-05-15 18:55:11 -0600279 }
280
Marc Jones1587dc82017-05-15 18:55:11 -0600281 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
282 return current;
283}
284
Felix Held26651c82022-10-13 16:12:40 +0200285struct device_operations stoneyridge_northbridge_operations = {
Marc Jones1587dc82017-05-15 18:55:11 -0600286 .read_resources = read_resources,
287 .set_resources = set_resources,
288 .enable_resources = pci_dev_enable_resources,
289 .init = northbridge_init,
Felix Held915c3872023-04-11 21:21:35 +0200290 .acpi_fill_ssdt = acpi_fill_root_complex_tom,
Marc Jones1587dc82017-05-15 18:55:11 -0600291 .write_acpi_tables = agesa_write_acpi_tables,
Marc Jones1587dc82017-05-15 18:55:11 -0600292};
293
Marshall Dawson154239a2017-11-02 09:49:30 -0600294/*
295 * Enable VGA cycles. Set memory ranges of the FCH legacy devices (TPM, HPET,
296 * BIOS RAM, Watchdog Timer, IOAPIC and ACPI) as non-posted. Set remaining
297 * MMIO to posted. Route all I/O to the southbridge.
298 */
299void amd_initcpuio(void)
300{
Felix Held5e9afe72023-04-20 12:55:55 +0200301 uintptr_t topmem = get_top_of_mem_below_4gb();
Marshall Dawson154239a2017-11-02 09:49:30 -0600302 uintptr_t base, limit;
303
304 /* Enable legacy video routing: D18F1xF4 VGA Enable */
305 pci_write_config32(SOC_ADDR_DEV, D18F1_VGAEN, VGA_ADDR_ENABLE);
306
307 /* Non-posted: range(HPET-LAPIC) or 0xfed00000 through 0xfee00000-1 */
308 base = (HPET_BASE_ADDRESS >> 8) | MMIO_WE | MMIO_RE;
Kyösti Mälkkidea42e02021-05-31 20:26:16 +0300309 limit = (ALIGN_DOWN(LAPIC_DEFAULT_BASE - 1, 64 * KiB) >> 8) | MMIO_NP;
Marshall Dawson154239a2017-11-02 09:49:30 -0600310 pci_write_config32(SOC_ADDR_DEV, NB_MMIO_LIMIT_LO(0), limit);
311 pci_write_config32(SOC_ADDR_DEV, NB_MMIO_BASE_LO(0), base);
312
313 /* Remaining PCI hole posted MMIO: TOM-HPET (TOM through 0xfed00000-1 */
314 base = (topmem >> 8) | MMIO_WE | MMIO_RE;
315 limit = ALIGN_DOWN(HPET_BASE_ADDRESS - 1, 64 * KiB) >> 8;
316 pci_write_config32(SOC_ADDR_DEV, NB_MMIO_LIMIT_LO(1), limit);
317 pci_write_config32(SOC_ADDR_DEV, NB_MMIO_BASE_LO(1), base);
318
319 /* Route all I/O downstream */
320 base = 0 | IO_WE | IO_RE;
321 limit = ALIGN_DOWN(0xffff, 4 * KiB);
322 pci_write_config32(SOC_ADDR_DEV, NB_IO_LIMIT(0), limit);
323 pci_write_config32(SOC_ADDR_DEV, NB_IO_BASE(0), base);
324}
325
Marc Jones1587dc82017-05-15 18:55:11 -0600326void fam15_finalize(void *chip_info)
327{
Marc Jones1587dc82017-05-15 18:55:11 -0600328 u32 value;
Richard Spiegel41baf0c2018-10-22 13:57:18 -0700329
330 /* TODO: move IOAPIC code to dsdt.asl */
331 pci_write_config32(SOC_GNB_DEV, NB_IOAPIC_INDEX, 0);
332 pci_write_config32(SOC_GNB_DEV, NB_IOAPIC_DATA, 5);
Marc Jones1587dc82017-05-15 18:55:11 -0600333
334 /* disable No Snoop */
Richard Spiegel41baf0c2018-10-22 13:57:18 -0700335 value = pci_read_config32(SOC_HDA0_DEV, HDA_DEV_CTRL_STATUS);
Richard Spiegel3d34ae32018-04-13 13:20:08 -0700336 value &= ~HDA_NO_SNOOP_EN;
Richard Spiegel41baf0c2018-10-22 13:57:18 -0700337 pci_write_config32(SOC_HDA0_DEV, HDA_DEV_CTRL_STATUS, value);
Marc Jones1587dc82017-05-15 18:55:11 -0600338}
339
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200340void domain_enable_resources(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -0600341{
Marc Jones1587dc82017-05-15 18:55:11 -0600342 /* Must be called after PCI enumeration and resource allocation */
Kyösti Mälkki9e591c42021-01-09 12:37:25 +0200343 if (!acpi_is_wakeup_s3())
Kyösti Mälkki6e512c42018-06-14 06:57:05 +0300344 do_agesawrapper(AMD_INIT_MID, "amdinitmid");
Marc Jones1587dc82017-05-15 18:55:11 -0600345}
346
Furquan Shaikhfc752b62020-05-13 12:14:11 -0700347void domain_read_resources(struct device *dev)
Marc Jones1587dc82017-05-15 18:55:11 -0600348{
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700349 uint64_t uma_base = get_uma_base();
350 uint32_t uma_size = get_uma_size();
351 uint32_t mem_useable = (uintptr_t)cbmem_top();
Felix Held392cf2f2023-04-20 13:23:23 +0200352 uint32_t tom = get_top_of_mem_below_4gb();
Felix Held27af3e62023-04-22 05:59:52 +0200353 uint64_t high_tom = get_top_of_mem_above_4gb();
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700354 uint64_t high_mem_useable;
355 int idx = 0x10;
Marc Jones1587dc82017-05-15 18:55:11 -0600356
Furquan Shaikhfc752b62020-05-13 12:14:11 -0700357 pci_domain_read_resources(dev);
358
Felix Heldd7ad1402023-06-05 15:30:10 +0200359 fixed_io_range_reserved(dev, idx++, PCI_IO_CONFIG_INDEX, PCI_IO_CONFIG_PORT_COUNT);
360
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700361 /* 0x0 -> 0x9ffff */
Arthur Heymans885efa12023-07-05 12:11:12 +0200362 ram_range(dev, idx++, 0, 0xa0000);
Marc Jones1587dc82017-05-15 18:55:11 -0600363
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700364 /* 0xa0000 -> 0xbffff: legacy VGA */
Arthur Heymans885efa12023-07-05 12:11:12 +0200365 mmio_range(dev, idx++, VGA_MMIO_BASE, VGA_MMIO_SIZE);
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700366
367 /* 0xc0000 -> 0xfffff: Option ROM */
Arthur Heymans885efa12023-07-05 12:11:12 +0200368 reserved_ram_from_to(dev, idx++, 0xc0000, 1 * MiB);
Marc Jones1587dc82017-05-15 18:55:11 -0600369
Marshall Dawson29f1b742017-09-06 14:59:45 -0600370 /*
Martin Roth26f97f92021-10-01 14:53:22 -0600371 * 0x100000 (1MiB) -> low top usable RAM
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700372 * cbmem_top() accounts for low UMA and TSEG if they are used.
Marc Jones1587dc82017-05-15 18:55:11 -0600373 */
Arthur Heymans885efa12023-07-05 12:11:12 +0200374 ram_from_to(dev, idx++, 1 * MiB, mem_useable);
Marc Jones1587dc82017-05-15 18:55:11 -0600375
Martin Roth26f97f92021-10-01 14:53:22 -0600376 /* Low top usable RAM -> Low top RAM (bottom pci mmio hole) */
Arthur Heymans885efa12023-07-05 12:11:12 +0200377 reserved_ram_from_to(dev, idx++, mem_useable, tom);
Marc Jones1587dc82017-05-15 18:55:11 -0600378
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700379 /* If there is memory above 4GiB */
Felix Held392cf2f2023-04-20 13:23:23 +0200380 if (high_tom >> 32) {
Martin Roth26f97f92021-10-01 14:53:22 -0600381 /* 4GiB -> high top usable */
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700382 if (uma_base >= (4ull * GiB))
383 high_mem_useable = uma_base;
384 else
Felix Held392cf2f2023-04-20 13:23:23 +0200385 high_mem_useable = high_tom;
Marc Jones1587dc82017-05-15 18:55:11 -0600386
Arthur Heymans885efa12023-07-05 12:11:12 +0200387 ram_from_to(dev, idx++, 4ull * GiB, high_mem_useable);
Marc Jones1587dc82017-05-15 18:55:11 -0600388
Martin Roth26f97f92021-10-01 14:53:22 -0600389 /* High top usable RAM -> high top RAM */
Marc Jones5fd1d5a2018-02-08 15:41:54 -0700390 if (uma_base >= (4ull * GiB)) {
Arthur Heymans885efa12023-07-05 12:11:12 +0200391 reserved_ram_range(dev, idx++, uma_base, uma_size);
Marc Jones1587dc82017-05-15 18:55:11 -0600392 }
Marc Jones1587dc82017-05-15 18:55:11 -0600393 }
Marc Jones1587dc82017-05-15 18:55:11 -0600394}
395
Richard Spiegel2e90ee32018-07-24 12:08:22 -0700396__weak void set_board_env_params(GNB_ENV_CONFIGURATION *params) { }
397
Marshall Dawson2942db62017-12-14 10:00:27 -0700398void SetNbEnvParams(GNB_ENV_CONFIGURATION *params)
399{
Martin Roth50f2e4c2018-10-29 11:16:53 -0600400 const struct device *dev = SOC_IOMMU_DEV;
401 params->IommuSupport = dev && dev->enabled;
Richard Spiegel2e90ee32018-07-24 12:08:22 -0700402 set_board_env_params(params);
Marshall Dawson2942db62017-12-14 10:00:27 -0700403}
404
405void SetNbMidParams(GNB_MID_CONFIGURATION *params)
406{
407 /* 0=Primary and decode all VGA resources, 1=Secondary - decode none */
408 params->iGpuVgaMode = 0;
409 params->GnbIoapicAddress = IO_APIC2_ADDR;
410}
Furquan Shaikh91a7abf2020-04-27 18:48:48 -0700411
412void hda_soc_ssdt_quirks(const struct device *dev)
413{
414 const char *scope = acpi_device_path(dev);
415 static const struct fieldlist list[] = {
416 FIELDLIST_OFFSET(0x42),
417 FIELDLIST_NAMESTR("NSDI", 1),
418 FIELDLIST_NAMESTR("NSDO", 1),
419 FIELDLIST_NAMESTR("NSEN", 1),
420 };
421 struct opregion opreg = OPREGION("AZPD", PCI_CONFIG, 0x0, 0x100);
422
423 assert(scope);
424
425 acpigen_write_scope(scope);
426
427 /*
428 * OperationRegion(AZPD, PCI_Config, 0x00, 0x100)
429 * Field (AZPD, AnyAcc, NoLock, Preserve) {
430 * Offset (0x42),
431 * NSDI, 1,
432 * NSDO, 1,
433 * NSEN, 1,
434 * }
435 */
436 acpigen_write_opregion(&opreg);
437 acpigen_write_field(opreg.name, list, ARRAY_SIZE(list),
438 FIELD_ANYACC | FIELD_NOLOCK | FIELD_PRESERVE);
439
440 /*
441 * Method (_INI, 0, NotSerialized) {
Kyösti Mälkkiff9ba542021-02-09 17:38:23 +0200442 * Store (Zero, NSEN)
443 * Store (One, NSDO)
444 * Store (One, NSDI)
Furquan Shaikh91a7abf2020-04-27 18:48:48 -0700445 * }
446 */
447 acpigen_write_method("_INI", 0);
448
Furquan Shaikhac204ba2021-02-19 10:23:17 -0800449 acpigen_write_store_op_to_namestr(ZERO_OP, "NSEN");
450 acpigen_write_store_op_to_namestr(ONE_OP, "NSDO");
451 acpigen_write_store_op_to_namestr(ONE_OP, "NSDI");
Furquan Shaikh91a7abf2020-04-27 18:48:48 -0700452
Furquan Shaikh91a7abf2020-04-27 18:48:48 -0700453 acpigen_pop_len(); /* Method _INI */
454
455 acpigen_pop_len(); /* Scope */
456}