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