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