Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 3 | |
Michał Żygowski | f65c1e4 | 2019-12-01 18:14:39 +0100 | [diff] [blame] | 4 | #include <amdblocks/biosram.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
Marc Jones | d6a8200 | 2018-03-31 22:46:57 -0600 | [diff] [blame] | 6 | #include <arch/ioapic.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 7 | #include <arch/acpi.h> |
| 8 | #include <arch/acpigen.h> |
| 9 | #include <cbmem.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 10 | #include <console/console.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 11 | #include <cpu/amd/mtrr.h> |
Marshall Dawson | 154239a | 2017-11-02 09:49:30 -0600 | [diff] [blame] | 12 | #include <cpu/x86/lapic_def.h> |
Marshall Dawson | f82aa10 | 2017-09-20 18:01:41 -0600 | [diff] [blame] | 13 | #include <cpu/x86/msr.h> |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 14 | #include <cpu/amd/msr.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 15 | #include <device/device.h> |
| 16 | #include <device/pci.h> |
| 17 | #include <device/pci_ids.h> |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 18 | #include <romstage_handoff.h> |
Richard Spiegel | 0ad74ac | 2017-12-08 16:53:29 -0700 | [diff] [blame] | 19 | #include <amdblocks/agesawrapper.h> |
| 20 | #include <amdblocks/agesawrapper_call.h> |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 21 | #include <agesa_headers.h> |
Marshall Dawson | 653f760 | 2018-09-04 13:25:39 -0600 | [diff] [blame] | 22 | #include <soc/cpu.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 23 | #include <soc/northbridge.h> |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 24 | #include <soc/pci_devs.h> |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 25 | #include <soc/iomap.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 26 | #include <stdint.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 27 | #include <string.h> |
Marshall Dawson | 653f760 | 2018-09-04 13:25:39 -0600 | [diff] [blame] | 28 | #include <arch/bert_storage.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 29 | |
Elyes HAOUAS | c338507 | 2019-03-21 15:38:06 +0100 | [diff] [blame] | 30 | #include "chip.h" |
| 31 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 32 | static void set_io_addr_reg(struct device *dev, u32 nodeid, u32 linkn, u32 reg, |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 33 | u32 io_min, u32 io_max) |
| 34 | { |
| 35 | u32 tempreg; |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 36 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 37 | /* io range allocation. Limit */ |
| 38 | tempreg = (nodeid & 0xf) | ((nodeid & 0x30) << (8 - 4)) | (linkn << 4) |
| 39 | | ((io_max & 0xf0) << (12 - 4)); |
Richard Spiegel | 41baf0c | 2018-10-22 13:57:18 -0700 | [diff] [blame] | 40 | pci_write_config32(SOC_ADDR_DEV, reg + 4, tempreg); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 41 | tempreg = 3 | ((io_min & 0xf0) << (12 - 4)); /* base: ISA and VGA ? */ |
Richard Spiegel | 41baf0c | 2018-10-22 13:57:18 -0700 | [diff] [blame] | 42 | pci_write_config32(SOC_ADDR_DEV, reg, tempreg); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 43 | } |
| 44 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 45 | static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, |
| 46 | u32 mmio_min, u32 mmio_max) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 47 | { |
| 48 | u32 tempreg; |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 49 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 50 | /* io range allocation. Limit */ |
| 51 | tempreg = (nodeid & 0xf) | (linkn << 4) | (mmio_max & 0xffffff00); |
Richard Spiegel | 41baf0c | 2018-10-22 13:57:18 -0700 | [diff] [blame] | 52 | pci_write_config32(SOC_ADDR_DEV, reg + 4, tempreg); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 53 | tempreg = 3 | (nodeid & 0x30) | (mmio_min & 0xffffff00); |
Richard Spiegel | 41baf0c | 2018-10-22 13:57:18 -0700 | [diff] [blame] | 54 | pci_write_config32(SOC_ADDR_DEV, reg, tempreg); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 55 | } |
| 56 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 57 | static void read_resources(struct device *dev) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 58 | { |
Marc Jones | d6a8200 | 2018-03-31 22:46:57 -0600 | [diff] [blame] | 59 | struct resource *res; |
| 60 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 61 | /* |
| 62 | * This MMCONF resource must be reserved in the PCI domain. |
| 63 | * It is not honored by the coreboot resource allocator if it is in |
| 64 | * the CPU_CLUSTER. |
| 65 | */ |
Aaron Durbin | 3173d44 | 2017-11-03 12:14:25 -0600 | [diff] [blame] | 66 | mmconf_resource(dev, MMIO_CONF_BASE); |
Marc Jones | d6a8200 | 2018-03-31 22:46:57 -0600 | [diff] [blame] | 67 | |
| 68 | /* NB IOAPIC2 resource */ |
| 69 | res = new_resource(dev, IO_APIC2_ADDR); /* IOAPIC2 */ |
| 70 | res->base = IO_APIC2_ADDR; |
| 71 | res->size = 0x00001000; |
| 72 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 73 | } |
| 74 | |
Richard Spiegel | 2b7cd1d | 2018-10-22 14:39:37 -0700 | [diff] [blame] | 75 | static void set_resource(struct device *dev, struct resource *res, u32 nodeid) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 76 | { |
| 77 | resource_t rbase, rend; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 78 | unsigned int reg, link_num; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 79 | char buf[50]; |
| 80 | |
| 81 | /* Make certain the resource has actually been set */ |
Richard Spiegel | 2b7cd1d | 2018-10-22 14:39:37 -0700 | [diff] [blame] | 82 | if (!(res->flags & IORESOURCE_ASSIGNED)) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 83 | return; |
| 84 | |
| 85 | /* If I have already stored this resource don't worry about it */ |
Richard Spiegel | 2b7cd1d | 2018-10-22 14:39:37 -0700 | [diff] [blame] | 86 | if (res->flags & IORESOURCE_STORED) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 87 | return; |
| 88 | |
| 89 | /* Only handle PCI memory and IO resources */ |
Richard Spiegel | 2b7cd1d | 2018-10-22 14:39:37 -0700 | [diff] [blame] | 90 | if (!(res->flags & (IORESOURCE_MEM | IORESOURCE_IO))) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 91 | return; |
| 92 | |
| 93 | /* Ensure I am actually looking at a resource of function 1 */ |
Richard Spiegel | 2b7cd1d | 2018-10-22 14:39:37 -0700 | [diff] [blame] | 94 | if ((res->index & 0xffff) < 0x1000) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 95 | return; |
| 96 | |
| 97 | /* Get the base address */ |
Richard Spiegel | 2b7cd1d | 2018-10-22 14:39:37 -0700 | [diff] [blame] | 98 | rbase = res->base; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 99 | |
| 100 | /* Get the limit (rounded up) */ |
Richard Spiegel | 2b7cd1d | 2018-10-22 14:39:37 -0700 | [diff] [blame] | 101 | rend = resource_end(res); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 102 | |
| 103 | /* Get the register and link */ |
Richard Spiegel | 2b7cd1d | 2018-10-22 14:39:37 -0700 | [diff] [blame] | 104 | reg = res->index & 0xfff; /* 4k */ |
| 105 | link_num = IOINDEX_LINK(res->index); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 106 | |
Richard Spiegel | 2b7cd1d | 2018-10-22 14:39:37 -0700 | [diff] [blame] | 107 | if (res->flags & IORESOURCE_IO) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 108 | set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8); |
Richard Spiegel | 2b7cd1d | 2018-10-22 14:39:37 -0700 | [diff] [blame] | 109 | else if (res->flags & IORESOURCE_MEM) |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 110 | set_mmio_addr_reg(nodeid, link_num, reg, |
Richard Spiegel | 2b7cd1d | 2018-10-22 14:39:37 -0700 | [diff] [blame] | 111 | (res->index >> 24), rbase >> 8, rend >> 8); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 112 | |
Richard Spiegel | 2b7cd1d | 2018-10-22 14:39:37 -0700 | [diff] [blame] | 113 | res->flags |= IORESOURCE_STORED; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 114 | snprintf(buf, sizeof(buf), " <node %x link %x>", |
| 115 | nodeid, link_num); |
Richard Spiegel | 2b7cd1d | 2018-10-22 14:39:37 -0700 | [diff] [blame] | 116 | report_resource_stored(dev, res, buf); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /** |
| 120 | * I tried to reuse the resource allocation code in set_resource() |
| 121 | * but it is too difficult to deal with the resource allocation magic. |
| 122 | */ |
| 123 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 124 | static void create_vga_resource(struct device *dev) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 125 | { |
| 126 | struct bus *link; |
| 127 | |
| 128 | /* find out which link the VGA card is connected, |
| 129 | * we only deal with the 'first' vga card */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 130 | for (link = dev->link_list ; link ; link = link->next) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 131 | if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) |
| 132 | break; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 133 | |
| 134 | /* no VGA card installed */ |
| 135 | if (link == NULL) |
| 136 | return; |
| 137 | |
Marshall Dawson | e2697de | 2017-09-06 10:46:36 -0600 | [diff] [blame] | 138 | printk(BIOS_DEBUG, "VGA: %s has VGA device\n", dev_path(dev)); |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 139 | /* Route A0000-BFFFF, IO 3B0-3BB 3C0-3DF */ |
Richard Spiegel | 41baf0c | 2018-10-22 13:57:18 -0700 | [diff] [blame] | 140 | pci_write_config32(SOC_ADDR_DEV, D18F1_VGAEN, VGA_ADDR_ENABLE); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 141 | } |
| 142 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 143 | static void set_resources(struct device *dev) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 144 | { |
| 145 | struct bus *bus; |
| 146 | struct resource *res; |
| 147 | |
| 148 | |
| 149 | /* do we need this? */ |
| 150 | create_vga_resource(dev); |
| 151 | |
| 152 | /* Set each resource we have found */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 153 | for (res = dev->resource_list ; res ; res = res->next) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 154 | set_resource(dev, res, 0); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 155 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 156 | for (bus = dev->link_list ; bus ; bus = bus->next) |
| 157 | if (bus->children) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 158 | assign_resources(bus); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static void northbridge_init(struct device *dev) |
| 162 | { |
Marc Jones | d6a8200 | 2018-03-31 22:46:57 -0600 | [diff] [blame] | 163 | setup_ioapic((u8 *)IO_APIC2_ADDR, CONFIG_MAX_CPUS+1); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 164 | } |
| 165 | |
Marshall Dawson | e09caf6 | 2019-05-02 17:58:12 -0600 | [diff] [blame] | 166 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 167 | { |
| 168 | |
| 169 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current, |
| 170 | CONFIG_MMCONF_BASE_ADDRESS, |
| 171 | 0, |
| 172 | 0, |
| 173 | CONFIG_MMCONF_BUS_NUMBER); |
| 174 | |
| 175 | return current; |
| 176 | } |
| 177 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 178 | static unsigned long acpi_fill_hest(acpi_hest_t *hest) |
| 179 | { |
| 180 | void *addr, *current; |
| 181 | |
| 182 | /* Skip the HEST header. */ |
| 183 | current = (void *)(hest + 1); |
| 184 | |
| 185 | addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE); |
| 186 | if (addr != NULL) |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 187 | current += acpi_create_hest_error_source(hest, current, 0, |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 188 | (void *)((u32)addr + 2), *(uint16_t *)addr - 2); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 189 | |
| 190 | addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC); |
| 191 | if (addr != NULL) |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 192 | current += acpi_create_hest_error_source(hest, current, 1, |
Richard Spiegel | 271b8a5 | 2018-11-06 16:32:28 -0700 | [diff] [blame] | 193 | (void *)((u32)addr + 2), *(uint16_t *)addr - 2); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 194 | |
| 195 | return (unsigned long)current; |
| 196 | } |
| 197 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 198 | static void northbridge_fill_ssdt_generator(struct device *device) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 199 | { |
| 200 | msr_t msr; |
| 201 | char pscope[] = "\\_SB.PCI0"; |
| 202 | |
| 203 | acpigen_write_scope(pscope); |
| 204 | msr = rdmsr(TOP_MEM); |
| 205 | acpigen_write_name_dword("TOM1", msr.lo); |
| 206 | msr = rdmsr(TOP_MEM2); |
| 207 | /* |
| 208 | * Since XP only implements parts of ACPI 2.0, we can't use a qword |
| 209 | * here. |
| 210 | * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt |
| 211 | * slide 22ff. |
| 212 | * Shift value right by 20 bit to make it fit into 32bit, |
| 213 | * giving us 1MB granularity and a limit of almost 4Exabyte of memory. |
| 214 | */ |
| 215 | acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20); |
| 216 | acpigen_pop_len(); |
| 217 | } |
| 218 | |
Michał Żygowski | 9550e97 | 2020-03-20 13:56:46 +0100 | [diff] [blame] | 219 | static void patch_ssdt_processor_scope(acpi_header_t *ssdt) |
| 220 | { |
| 221 | unsigned int len = ssdt->length - sizeof(acpi_header_t); |
| 222 | unsigned int i; |
| 223 | |
| 224 | for (i = sizeof(acpi_header_t); i < len; i++) { |
| 225 | /* Search for _PR_ scope and replace it with _SB_ */ |
| 226 | if (*(uint32_t *)((unsigned long)ssdt + i) == 0x5f52505f) |
| 227 | *(uint32_t *)((unsigned long)ssdt + i) = 0x5f42535f; |
| 228 | } |
| 229 | /* Recalculate checksum */ |
| 230 | ssdt->checksum = 0; |
| 231 | ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length); |
| 232 | } |
| 233 | |
| 234 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 235 | static unsigned long agesa_write_acpi_tables(struct device *device, |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 236 | unsigned long current, |
| 237 | acpi_rsdp_t *rsdp) |
| 238 | { |
| 239 | acpi_srat_t *srat; |
| 240 | acpi_slit_t *slit; |
| 241 | acpi_header_t *ssdt; |
| 242 | acpi_header_t *alib; |
| 243 | acpi_header_t *ivrs; |
| 244 | acpi_hest_t *hest; |
Marshall Dawson | 653f760 | 2018-09-04 13:25:39 -0600 | [diff] [blame] | 245 | acpi_bert_t *bert; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 246 | |
| 247 | /* HEST */ |
| 248 | current = ALIGN(current, 8); |
| 249 | hest = (acpi_hest_t *)current; |
Richard Spiegel | 6a9e6cd | 2018-11-30 10:53:40 -0700 | [diff] [blame] | 250 | acpi_write_hest(hest, acpi_fill_hest); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 251 | acpi_add_table(rsdp, (void *)current); |
Richard Spiegel | 6a9e6cd | 2018-11-30 10:53:40 -0700 | [diff] [blame] | 252 | current += hest->header.length; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 253 | |
Marshall Dawson | 653f760 | 2018-09-04 13:25:39 -0600 | [diff] [blame] | 254 | /* BERT */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 255 | if (CONFIG(ACPI_BERT) && bert_errors_present()) { |
Marshall Dawson | 653f760 | 2018-09-04 13:25:39 -0600 | [diff] [blame] | 256 | /* Skip the table if no errors are present. ACPI driver reports |
| 257 | * a table with a 0-length region: |
| 258 | * BERT: [Firmware Bug]: table invalid. |
| 259 | */ |
| 260 | void *rgn; |
| 261 | size_t size; |
| 262 | bert_errors_region(&rgn, &size); |
| 263 | if (!rgn) { |
| 264 | printk(BIOS_ERR, "Error: Can't find BERT storage area\n"); |
| 265 | } else { |
| 266 | current = ALIGN(current, 8); |
| 267 | bert = (acpi_bert_t *)current; |
Richard Spiegel | 6a9e6cd | 2018-11-30 10:53:40 -0700 | [diff] [blame] | 268 | acpi_write_bert(bert, (uintptr_t)rgn, size); |
Marshall Dawson | 653f760 | 2018-09-04 13:25:39 -0600 | [diff] [blame] | 269 | acpi_add_table(rsdp, (void *)current); |
Richard Spiegel | 6a9e6cd | 2018-11-30 10:53:40 -0700 | [diff] [blame] | 270 | current += bert->header.length; |
Marshall Dawson | 653f760 | 2018-09-04 13:25:39 -0600 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 274 | current = ALIGN(current, 8); |
| 275 | printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current); |
| 276 | ivrs = agesawrapper_getlateinitptr(PICK_IVRS); |
| 277 | if (ivrs != NULL) { |
| 278 | memcpy((void *)current, ivrs, ivrs->length); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 279 | ivrs = (acpi_header_t *)current; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 280 | current += ivrs->length; |
| 281 | acpi_add_table(rsdp, ivrs); |
| 282 | } else { |
| 283 | printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n"); |
| 284 | } |
| 285 | |
| 286 | /* SRAT */ |
| 287 | current = ALIGN(current, 8); |
| 288 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 289 | srat = (acpi_srat_t *)agesawrapper_getlateinitptr(PICK_SRAT); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 290 | if (srat != NULL) { |
| 291 | memcpy((void *)current, srat, srat->header.length); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 292 | srat = (acpi_srat_t *)current; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 293 | current += srat->header.length; |
| 294 | acpi_add_table(rsdp, srat); |
| 295 | } else { |
| 296 | printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n"); |
| 297 | } |
| 298 | |
| 299 | /* SLIT */ |
| 300 | current = ALIGN(current, 8); |
| 301 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 302 | slit = (acpi_slit_t *)agesawrapper_getlateinitptr(PICK_SLIT); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 303 | if (slit != NULL) { |
| 304 | memcpy((void *)current, slit, slit->header.length); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 305 | slit = (acpi_slit_t *)current; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 306 | current += slit->header.length; |
| 307 | acpi_add_table(rsdp, slit); |
| 308 | } else { |
| 309 | printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n"); |
| 310 | } |
| 311 | |
| 312 | /* ALIB */ |
| 313 | current = ALIGN(current, 16); |
| 314 | printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 315 | alib = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_ALIB); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 316 | if (alib != NULL) { |
| 317 | memcpy((void *)current, alib, alib->length); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 318 | alib = (acpi_header_t *)current; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 319 | current += alib->length; |
| 320 | acpi_add_table(rsdp, (void *)alib); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 321 | } else { |
| 322 | printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL." |
| 323 | " Skipping.\n"); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 324 | } |
| 325 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 326 | current = ALIGN(current, 16); |
| 327 | printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 328 | ssdt = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_PSTATE); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 329 | if (ssdt != NULL) { |
Michał Żygowski | 9550e97 | 2020-03-20 13:56:46 +0100 | [diff] [blame] | 330 | patch_ssdt_processor_scope(ssdt); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 331 | memcpy((void *)current, ssdt, ssdt->length); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 332 | ssdt = (acpi_header_t *)current; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 333 | current += ssdt->length; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 334 | } else { |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 335 | printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n"); |
| 336 | } |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 337 | acpi_add_table(rsdp, ssdt); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 338 | |
| 339 | printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current); |
| 340 | return current; |
| 341 | } |
| 342 | |
| 343 | static struct device_operations northbridge_operations = { |
| 344 | .read_resources = read_resources, |
| 345 | .set_resources = set_resources, |
| 346 | .enable_resources = pci_dev_enable_resources, |
| 347 | .init = northbridge_init, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 348 | .acpi_fill_ssdt = northbridge_fill_ssdt_generator, |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 349 | .write_acpi_tables = agesa_write_acpi_tables, |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 350 | }; |
| 351 | |
Richard Spiegel | 9247e86 | 2019-06-28 09:18:47 -0700 | [diff] [blame] | 352 | static const unsigned short pci_device_ids[] = { |
| 353 | PCI_DEVICE_ID_AMD_15H_MODEL_606F_NB_HT, |
| 354 | PCI_DEVICE_ID_AMD_15H_MODEL_707F_NB_HT, |
| 355 | 0 }; |
| 356 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 357 | static const struct pci_driver family15_northbridge __pci_driver = { |
| 358 | .ops = &northbridge_operations, |
| 359 | .vendor = PCI_VENDOR_ID_AMD, |
Richard Spiegel | 9247e86 | 2019-06-28 09:18:47 -0700 | [diff] [blame] | 360 | .devices = pci_device_ids, |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 361 | }; |
| 362 | |
Marshall Dawson | 154239a | 2017-11-02 09:49:30 -0600 | [diff] [blame] | 363 | /* |
| 364 | * Enable VGA cycles. Set memory ranges of the FCH legacy devices (TPM, HPET, |
| 365 | * BIOS RAM, Watchdog Timer, IOAPIC and ACPI) as non-posted. Set remaining |
| 366 | * MMIO to posted. Route all I/O to the southbridge. |
| 367 | */ |
| 368 | void amd_initcpuio(void) |
| 369 | { |
| 370 | uintptr_t topmem = bsp_topmem(); |
| 371 | uintptr_t base, limit; |
| 372 | |
| 373 | /* Enable legacy video routing: D18F1xF4 VGA Enable */ |
| 374 | pci_write_config32(SOC_ADDR_DEV, D18F1_VGAEN, VGA_ADDR_ENABLE); |
| 375 | |
| 376 | /* Non-posted: range(HPET-LAPIC) or 0xfed00000 through 0xfee00000-1 */ |
| 377 | base = (HPET_BASE_ADDRESS >> 8) | MMIO_WE | MMIO_RE; |
| 378 | limit = (ALIGN_DOWN(LOCAL_APIC_ADDR - 1, 64 * KiB) >> 8) | MMIO_NP; |
| 379 | pci_write_config32(SOC_ADDR_DEV, NB_MMIO_LIMIT_LO(0), limit); |
| 380 | pci_write_config32(SOC_ADDR_DEV, NB_MMIO_BASE_LO(0), base); |
| 381 | |
| 382 | /* Remaining PCI hole posted MMIO: TOM-HPET (TOM through 0xfed00000-1 */ |
| 383 | base = (topmem >> 8) | MMIO_WE | MMIO_RE; |
| 384 | limit = ALIGN_DOWN(HPET_BASE_ADDRESS - 1, 64 * KiB) >> 8; |
| 385 | pci_write_config32(SOC_ADDR_DEV, NB_MMIO_LIMIT_LO(1), limit); |
| 386 | pci_write_config32(SOC_ADDR_DEV, NB_MMIO_BASE_LO(1), base); |
| 387 | |
| 388 | /* Route all I/O downstream */ |
| 389 | base = 0 | IO_WE | IO_RE; |
| 390 | limit = ALIGN_DOWN(0xffff, 4 * KiB); |
| 391 | pci_write_config32(SOC_ADDR_DEV, NB_IO_LIMIT(0), limit); |
| 392 | pci_write_config32(SOC_ADDR_DEV, NB_IO_BASE(0), base); |
| 393 | } |
| 394 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 395 | void fam15_finalize(void *chip_info) |
| 396 | { |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 397 | u32 value; |
Richard Spiegel | 41baf0c | 2018-10-22 13:57:18 -0700 | [diff] [blame] | 398 | |
| 399 | /* TODO: move IOAPIC code to dsdt.asl */ |
| 400 | pci_write_config32(SOC_GNB_DEV, NB_IOAPIC_INDEX, 0); |
| 401 | pci_write_config32(SOC_GNB_DEV, NB_IOAPIC_DATA, 5); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 402 | |
| 403 | /* disable No Snoop */ |
Richard Spiegel | 41baf0c | 2018-10-22 13:57:18 -0700 | [diff] [blame] | 404 | value = pci_read_config32(SOC_HDA0_DEV, HDA_DEV_CTRL_STATUS); |
Richard Spiegel | 3d34ae3 | 2018-04-13 13:20:08 -0700 | [diff] [blame] | 405 | value &= ~HDA_NO_SNOOP_EN; |
Richard Spiegel | 41baf0c | 2018-10-22 13:57:18 -0700 | [diff] [blame] | 406 | pci_write_config32(SOC_HDA0_DEV, HDA_DEV_CTRL_STATUS, value); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 407 | } |
| 408 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 409 | void domain_enable_resources(struct device *dev) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 410 | { |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 411 | /* Must be called after PCI enumeration and resource allocation */ |
Marshall Dawson | 8f2a7e0 | 2017-11-01 11:44:48 -0600 | [diff] [blame] | 412 | if (!romstage_handoff_is_resume()) |
Kyösti Mälkki | 6e512c4 | 2018-06-14 06:57:05 +0300 | [diff] [blame] | 413 | do_agesawrapper(AMD_INIT_MID, "amdinitmid"); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 414 | } |
| 415 | |
Elyes HAOUAS | 777ccd4 | 2018-05-22 10:52:05 +0200 | [diff] [blame] | 416 | void domain_set_resources(struct device *dev) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 417 | { |
Marc Jones | 5fd1d5a | 2018-02-08 15:41:54 -0700 | [diff] [blame] | 418 | uint64_t uma_base = get_uma_base(); |
| 419 | uint32_t uma_size = get_uma_size(); |
| 420 | uint32_t mem_useable = (uintptr_t)cbmem_top(); |
| 421 | msr_t tom = rdmsr(TOP_MEM); |
| 422 | msr_t high_tom = rdmsr(TOP_MEM2); |
| 423 | uint64_t high_mem_useable; |
| 424 | int idx = 0x10; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 425 | |
Marc Jones | 5fd1d5a | 2018-02-08 15:41:54 -0700 | [diff] [blame] | 426 | /* 0x0 -> 0x9ffff */ |
| 427 | ram_resource(dev, idx++, 0, 0xa0000 / KiB); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 428 | |
Marc Jones | 5fd1d5a | 2018-02-08 15:41:54 -0700 | [diff] [blame] | 429 | /* 0xa0000 -> 0xbffff: legacy VGA */ |
| 430 | mmio_resource(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB); |
| 431 | |
| 432 | /* 0xc0000 -> 0xfffff: Option ROM */ |
| 433 | reserved_ram_resource(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 434 | |
Marshall Dawson | 29f1b74 | 2017-09-06 14:59:45 -0600 | [diff] [blame] | 435 | /* |
Marc Jones | 5fd1d5a | 2018-02-08 15:41:54 -0700 | [diff] [blame] | 436 | * 0x100000 (1MiB) -> low top useable RAM |
| 437 | * cbmem_top() accounts for low UMA and TSEG if they are used. |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 438 | */ |
Marc Jones | 5fd1d5a | 2018-02-08 15:41:54 -0700 | [diff] [blame] | 439 | ram_resource(dev, idx++, (1 * MiB) / KiB, |
| 440 | (mem_useable - (1 * MiB)) / KiB); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 441 | |
Marc Jones | 5fd1d5a | 2018-02-08 15:41:54 -0700 | [diff] [blame] | 442 | /* Low top useable RAM -> Low top RAM (bottom pci mmio hole) */ |
| 443 | reserved_ram_resource(dev, idx++, mem_useable / KiB, |
| 444 | (tom.lo - mem_useable) / KiB); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 445 | |
Marc Jones | 5fd1d5a | 2018-02-08 15:41:54 -0700 | [diff] [blame] | 446 | /* If there is memory above 4GiB */ |
| 447 | if (high_tom.hi) { |
| 448 | /* 4GiB -> high top useable */ |
| 449 | if (uma_base >= (4ull * GiB)) |
| 450 | high_mem_useable = uma_base; |
| 451 | else |
| 452 | high_mem_useable = ((uint64_t)high_tom.lo | |
| 453 | ((uint64_t)high_tom.hi << 32)); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 454 | |
Marc Jones | 5fd1d5a | 2018-02-08 15:41:54 -0700 | [diff] [blame] | 455 | ram_resource(dev, idx++, (4ull * GiB) / KiB, |
| 456 | ((high_mem_useable - (4ull * GiB)) / KiB)); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 457 | |
Marc Jones | 5fd1d5a | 2018-02-08 15:41:54 -0700 | [diff] [blame] | 458 | /* High top useable RAM -> high top RAM */ |
| 459 | if (uma_base >= (4ull * GiB)) { |
| 460 | reserved_ram_resource(dev, idx++, uma_base / KiB, |
| 461 | uma_size / KiB); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 462 | } |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 463 | } |
| 464 | |
Marc Jones | 5fd1d5a | 2018-02-08 15:41:54 -0700 | [diff] [blame] | 465 | assign_resources(dev->link_list); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 466 | } |
| 467 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 468 | /********************************************************************* |
| 469 | * Change the vendor / device IDs to match the generic VBIOS header. * |
| 470 | *********************************************************************/ |
| 471 | u32 map_oprom_vendev(u32 vendev) |
| 472 | { |
| 473 | u32 new_vendev; |
Richard Spiegel | 9247e86 | 2019-06-28 09:18:47 -0700 | [diff] [blame] | 474 | |
| 475 | if ((vendev >= 0x100298e0) && (vendev <= 0x100298ef)) |
| 476 | new_vendev = 0x100298e0; |
| 477 | else if ((vendev >= 0x10029870) && (vendev <= 0x1002987f)) |
| 478 | new_vendev = 0x10029870; |
| 479 | else |
| 480 | new_vendev = vendev; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 481 | |
| 482 | if (vendev != new_vendev) |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 483 | printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", |
| 484 | vendev, new_vendev); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 485 | |
| 486 | return new_vendev; |
| 487 | } |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 488 | |
Richard Spiegel | 2e90ee3 | 2018-07-24 12:08:22 -0700 | [diff] [blame] | 489 | __weak void set_board_env_params(GNB_ENV_CONFIGURATION *params) { } |
| 490 | |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 491 | void SetNbEnvParams(GNB_ENV_CONFIGURATION *params) |
| 492 | { |
Martin Roth | 50f2e4c | 2018-10-29 11:16:53 -0600 | [diff] [blame] | 493 | const struct device *dev = SOC_IOMMU_DEV; |
| 494 | params->IommuSupport = dev && dev->enabled; |
Richard Spiegel | 2e90ee3 | 2018-07-24 12:08:22 -0700 | [diff] [blame] | 495 | set_board_env_params(params); |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | void SetNbMidParams(GNB_MID_CONFIGURATION *params) |
| 499 | { |
| 500 | /* 0=Primary and decode all VGA resources, 1=Secondary - decode none */ |
| 501 | params->iGpuVgaMode = 0; |
| 502 | params->GnbIoapicAddress = IO_APIC2_ADDR; |
| 503 | } |