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