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