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> |
| 18 | #include <arch/acpi.h> |
| 19 | #include <arch/acpigen.h> |
| 20 | #include <cbmem.h> |
| 21 | #include <chip.h> |
| 22 | #include <console/console.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 23 | #include <cpu/amd/mtrr.h> |
| 24 | #include <cpu/cpu.h> |
| 25 | #include <device/device.h> |
| 26 | #include <device/pci.h> |
| 27 | #include <device/pci_ids.h> |
| 28 | #include <device/hypertransport.h> |
| 29 | #include <lib.h> |
| 30 | #include <agesawrapper.h> |
| 31 | #include <agesawrapper_call.h> |
| 32 | #include <soc/northbridge.h> |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 33 | #include <soc/pci_devs.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 34 | #include <stdint.h> |
| 35 | #include <stdlib.h> |
| 36 | #include <string.h> |
| 37 | |
| 38 | /* |
| 39 | * AMD vendorcode files. Place at the end so coreboot defaults and maintained |
| 40 | * and not set by vendorcode |
| 41 | */ |
| 42 | #include <AGESA.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 43 | #include <FieldAccessors.h> |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 44 | #include <Porting.h> |
| 45 | #include <Topology.h> |
| 46 | |
Martin Roth | 5998198 | 2017-07-13 11:05:35 -0700 | [diff] [blame] | 47 | #if IS_ENABLED(CONFIG_EXT_CONF_SUPPORT) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 48 | #error CONFIG_EXT_CONF_SUPPORT == 1 not support anymore! |
| 49 | #endif |
| 50 | |
| 51 | typedef struct dram_base_mask { |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 52 | u32 base; /* [47:27] at [28:8] */ |
| 53 | u32 mask; /* [47:27] at [28:8] and enable at bit 0 */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 54 | } dram_base_mask_t; |
| 55 | |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 56 | static dram_base_mask_t get_dram_base_mask(void) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 57 | { |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 58 | device_t dev = dev_find_slot(0, ADDR_DEVFN); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 59 | dram_base_mask_t d; |
| 60 | u32 temp; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 61 | |
| 62 | /* [39:24] at [31:16] */ |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 63 | temp = pci_read_config32(dev, 0x44); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 64 | |
| 65 | /* mask out DramMask [26:24] too */ |
| 66 | d.mask = ((temp & 0xfff80000) >> (8 + 3)); |
| 67 | |
| 68 | /* [47:40] at [7:0] */ |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 69 | temp = pci_read_config32(dev, 0x144) & 0xff; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 70 | d.mask |= temp << 21; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 71 | |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 72 | temp = pci_read_config32(dev, 0x40); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 73 | d.mask |= (temp & 1); /* enable bit */ |
| 74 | d.base = ((temp & 0xfff80000) >> (8 + 3)); |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 75 | temp = pci_read_config32(dev, 0x140) & 0xff; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 76 | d.base |= temp << 21; |
| 77 | return d; |
| 78 | } |
| 79 | |
| 80 | static void set_io_addr_reg(device_t dev, u32 nodeid, u32 linkn, u32 reg, |
| 81 | u32 io_min, u32 io_max) |
| 82 | { |
| 83 | u32 tempreg; |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 84 | device_t addr_map = dev_find_slot(0, ADDR_DEVFN); |
| 85 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 86 | /* io range allocation. Limit */ |
| 87 | tempreg = (nodeid & 0xf) | ((nodeid & 0x30) << (8 - 4)) | (linkn << 4) |
| 88 | | ((io_max & 0xf0) << (12 - 4)); |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 89 | pci_write_config32(addr_map, reg + 4, tempreg); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 90 | tempreg = 3 | ((io_min & 0xf0) << (12 - 4)); /* base: ISA and VGA ? */ |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 91 | pci_write_config32(addr_map, reg, tempreg); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 92 | } |
| 93 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 94 | static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, |
| 95 | u32 mmio_min, u32 mmio_max) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 96 | { |
| 97 | u32 tempreg; |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 98 | device_t addr_map = dev_find_slot(0, ADDR_DEVFN); |
| 99 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 100 | /* io range allocation. Limit */ |
| 101 | tempreg = (nodeid & 0xf) | (linkn << 4) | (mmio_max & 0xffffff00); |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 102 | pci_write_config32(addr_map, reg + 4, tempreg); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 103 | tempreg = 3 | (nodeid & 0x30) | (mmio_min & 0xffffff00); |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 104 | pci_write_config32(addr_map, reg, tempreg); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 105 | } |
| 106 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 107 | static void read_resources(device_t dev) |
| 108 | { |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 109 | /* |
| 110 | * This MMCONF resource must be reserved in the PCI domain. |
| 111 | * It is not honored by the coreboot resource allocator if it is in |
| 112 | * the CPU_CLUSTER. |
| 113 | */ |
| 114 | mmconf_resource(dev, 0xc0010058); |
| 115 | } |
| 116 | |
| 117 | static void set_resource(device_t dev, struct resource *resource, u32 nodeid) |
| 118 | { |
| 119 | resource_t rbase, rend; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 120 | unsigned int reg, link_num; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 121 | char buf[50]; |
| 122 | |
| 123 | /* Make certain the resource has actually been set */ |
| 124 | if (!(resource->flags & IORESOURCE_ASSIGNED)) |
| 125 | return; |
| 126 | |
| 127 | /* If I have already stored this resource don't worry about it */ |
| 128 | if (resource->flags & IORESOURCE_STORED) |
| 129 | return; |
| 130 | |
| 131 | /* Only handle PCI memory and IO resources */ |
| 132 | if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO))) |
| 133 | return; |
| 134 | |
| 135 | /* Ensure I am actually looking at a resource of function 1 */ |
| 136 | if ((resource->index & 0xffff) < 0x1000) |
| 137 | return; |
| 138 | |
| 139 | /* Get the base address */ |
| 140 | rbase = resource->base; |
| 141 | |
| 142 | /* Get the limit (rounded up) */ |
| 143 | rend = resource_end(resource); |
| 144 | |
| 145 | /* Get the register and link */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 146 | reg = resource->index & 0xfff; /* 4k */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 147 | link_num = IOINDEX_LINK(resource->index); |
| 148 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 149 | if (resource->flags & IORESOURCE_IO) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 150 | 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] | 151 | else if (resource->flags & IORESOURCE_MEM) |
| 152 | set_mmio_addr_reg(nodeid, link_num, reg, |
| 153 | (resource->index >> 24), rbase >> 8, rend >> 8); |
| 154 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 155 | resource->flags |= IORESOURCE_STORED; |
| 156 | snprintf(buf, sizeof(buf), " <node %x link %x>", |
| 157 | nodeid, link_num); |
| 158 | report_resource_stored(dev, resource, buf); |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * I tried to reuse the resource allocation code in set_resource() |
| 163 | * but it is too difficult to deal with the resource allocation magic. |
| 164 | */ |
| 165 | |
| 166 | static void create_vga_resource(device_t dev) |
| 167 | { |
| 168 | struct bus *link; |
| 169 | |
| 170 | /* find out which link the VGA card is connected, |
| 171 | * we only deal with the 'first' vga card */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 172 | for (link = dev->link_list ; link ; link = link->next) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 173 | if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) |
| 174 | break; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 175 | |
| 176 | /* no VGA card installed */ |
| 177 | if (link == NULL) |
| 178 | return; |
| 179 | |
Marshall Dawson | e2697de | 2017-09-06 10:46:36 -0600 | [diff] [blame] | 180 | printk(BIOS_DEBUG, "VGA: %s has VGA device\n", dev_path(dev)); |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 181 | /* Route A0000-BFFFF, IO 3B0-3BB 3C0-3DF */ |
| 182 | pci_write_config32(dev_find_slot(0, ADDR_DEVFN), 0xf4, 1); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | static void set_resources(device_t dev) |
| 186 | { |
| 187 | struct bus *bus; |
| 188 | struct resource *res; |
| 189 | |
| 190 | |
| 191 | /* do we need this? */ |
| 192 | create_vga_resource(dev); |
| 193 | |
| 194 | /* Set each resource we have found */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 195 | for (res = dev->resource_list ; res ; res = res->next) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 196 | set_resource(dev, res, 0); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 197 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 198 | for (bus = dev->link_list ; bus ; bus = bus->next) |
| 199 | if (bus->children) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 200 | assign_resources(bus); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static void northbridge_init(struct device *dev) |
| 204 | { |
| 205 | } |
| 206 | |
| 207 | static unsigned long acpi_fill_hest(acpi_hest_t *hest) |
| 208 | { |
| 209 | void *addr, *current; |
| 210 | |
| 211 | /* Skip the HEST header. */ |
| 212 | current = (void *)(hest + 1); |
| 213 | |
| 214 | addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE); |
| 215 | if (addr != NULL) |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 216 | current += acpi_create_hest_error_source(hest, current, 0, |
| 217 | (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 218 | |
| 219 | addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC); |
| 220 | if (addr != NULL) |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 221 | current += acpi_create_hest_error_source(hest, current, 1, |
| 222 | (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 223 | |
| 224 | return (unsigned long)current; |
| 225 | } |
| 226 | |
| 227 | static void northbridge_fill_ssdt_generator(device_t device) |
| 228 | { |
| 229 | msr_t msr; |
| 230 | char pscope[] = "\\_SB.PCI0"; |
| 231 | |
| 232 | acpigen_write_scope(pscope); |
| 233 | msr = rdmsr(TOP_MEM); |
| 234 | acpigen_write_name_dword("TOM1", msr.lo); |
| 235 | msr = rdmsr(TOP_MEM2); |
| 236 | /* |
| 237 | * Since XP only implements parts of ACPI 2.0, we can't use a qword |
| 238 | * here. |
| 239 | * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt |
| 240 | * slide 22ff. |
| 241 | * Shift value right by 20 bit to make it fit into 32bit, |
| 242 | * giving us 1MB granularity and a limit of almost 4Exabyte of memory. |
| 243 | */ |
| 244 | acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20); |
| 245 | acpigen_pop_len(); |
| 246 | } |
| 247 | |
| 248 | static unsigned long agesa_write_acpi_tables(device_t device, |
| 249 | unsigned long current, |
| 250 | acpi_rsdp_t *rsdp) |
| 251 | { |
| 252 | acpi_srat_t *srat; |
| 253 | acpi_slit_t *slit; |
| 254 | acpi_header_t *ssdt; |
| 255 | acpi_header_t *alib; |
| 256 | acpi_header_t *ivrs; |
| 257 | acpi_hest_t *hest; |
| 258 | |
| 259 | /* HEST */ |
| 260 | current = ALIGN(current, 8); |
| 261 | hest = (acpi_hest_t *)current; |
| 262 | acpi_write_hest((void *)current, acpi_fill_hest); |
| 263 | acpi_add_table(rsdp, (void *)current); |
| 264 | current += ((acpi_header_t *)current)->length; |
| 265 | |
| 266 | current = ALIGN(current, 8); |
| 267 | printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current); |
| 268 | ivrs = agesawrapper_getlateinitptr(PICK_IVRS); |
| 269 | if (ivrs != NULL) { |
| 270 | memcpy((void *)current, ivrs, ivrs->length); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 271 | ivrs = (acpi_header_t *)current; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 272 | current += ivrs->length; |
| 273 | acpi_add_table(rsdp, ivrs); |
| 274 | } else { |
| 275 | printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n"); |
| 276 | } |
| 277 | |
| 278 | /* SRAT */ |
| 279 | current = ALIGN(current, 8); |
| 280 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 281 | srat = (acpi_srat_t *)agesawrapper_getlateinitptr(PICK_SRAT); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 282 | if (srat != NULL) { |
| 283 | memcpy((void *)current, srat, srat->header.length); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 284 | srat = (acpi_srat_t *)current; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 285 | current += srat->header.length; |
| 286 | acpi_add_table(rsdp, srat); |
| 287 | } else { |
| 288 | printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n"); |
| 289 | } |
| 290 | |
| 291 | /* SLIT */ |
| 292 | current = ALIGN(current, 8); |
| 293 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 294 | slit = (acpi_slit_t *)agesawrapper_getlateinitptr(PICK_SLIT); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 295 | if (slit != NULL) { |
| 296 | memcpy((void *)current, slit, slit->header.length); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 297 | slit = (acpi_slit_t *)current; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 298 | current += slit->header.length; |
| 299 | acpi_add_table(rsdp, slit); |
| 300 | } else { |
| 301 | printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n"); |
| 302 | } |
| 303 | |
| 304 | /* ALIB */ |
| 305 | current = ALIGN(current, 16); |
| 306 | printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 307 | alib = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_ALIB); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 308 | if (alib != NULL) { |
| 309 | memcpy((void *)current, alib, alib->length); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 310 | alib = (acpi_header_t *)current; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 311 | current += alib->length; |
| 312 | acpi_add_table(rsdp, (void *)alib); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 313 | } else { |
| 314 | printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL." |
| 315 | " Skipping.\n"); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 316 | } |
| 317 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 318 | current = ALIGN(current, 16); |
| 319 | printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 320 | ssdt = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_PSTATE); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 321 | if (ssdt != NULL) { |
| 322 | memcpy((void *)current, ssdt, ssdt->length); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 323 | ssdt = (acpi_header_t *)current; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 324 | current += ssdt->length; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 325 | } else { |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 326 | printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n"); |
| 327 | } |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 328 | acpi_add_table(rsdp, ssdt); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 329 | |
| 330 | printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current); |
| 331 | return current; |
| 332 | } |
| 333 | |
| 334 | static struct device_operations northbridge_operations = { |
| 335 | .read_resources = read_resources, |
| 336 | .set_resources = set_resources, |
| 337 | .enable_resources = pci_dev_enable_resources, |
| 338 | .init = northbridge_init, |
| 339 | .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator, |
| 340 | .write_acpi_tables = agesa_write_acpi_tables, |
| 341 | .enable = 0, |
| 342 | .ops_pci = 0, |
| 343 | }; |
| 344 | |
| 345 | static const struct pci_driver family15_northbridge __pci_driver = { |
| 346 | .ops = &northbridge_operations, |
| 347 | .vendor = PCI_VENDOR_ID_AMD, |
| 348 | .device = PCI_DEVICE_ID_AMD_15H_MODEL_707F_NB_HT, |
| 349 | }; |
| 350 | |
| 351 | void fam15_finalize(void *chip_info) |
| 352 | { |
| 353 | device_t dev; |
| 354 | u32 value; |
| 355 | dev = dev_find_slot(0, PCI_DEVFN(0, 0)); /* clear IoapicSbFeatureEn */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 356 | pci_write_config32(dev, 0xf8, 0); |
| 357 | pci_write_config32(dev, 0xfc, 5); /* TODO: move it to dsdt.asl */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 358 | |
| 359 | /* disable No Snoop */ |
| 360 | dev = dev_find_slot(0, PCI_DEVFN(1, 1)); |
| 361 | value = pci_read_config32(dev, 0x60); |
| 362 | value &= ~(1 << 11); |
| 363 | pci_write_config32(dev, 0x60, value); |
| 364 | } |
| 365 | |
| 366 | void domain_read_resources(device_t dev) |
| 367 | { |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 368 | unsigned int reg; |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 369 | device_t addr_map = dev_find_slot(0, ADDR_DEVFN); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 370 | |
| 371 | /* Find the already assigned resource pairs */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 372 | for (reg = 0x80 ; reg <= 0xd8 ; reg += 0x08) { |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 373 | u32 base, limit; |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 374 | base = pci_read_config32(addr_map, reg); |
| 375 | limit = pci_read_config32(addr_map, reg + 4); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 376 | /* Is this register allocated? */ |
| 377 | if ((base & 3) != 0) { |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 378 | unsigned int nodeid, reg_link; |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 379 | device_t reg_dev = dev_find_slot(0, HT_DEVFN); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 380 | if (reg < 0xc0) /* mmio */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 381 | nodeid = (limit & 0xf) + (base & 0x30); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 382 | else /* io */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 383 | nodeid = (limit & 0xf) + ((base >> 4) & 0x30); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 384 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 385 | reg_link = (limit >> 4) & 7; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 386 | if (reg_dev) { |
| 387 | /* Reserve the resource */ |
| 388 | struct resource *res; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 389 | res = new_resource(reg_dev, |
| 390 | IOINDEX(0x1000 + reg, |
| 391 | reg_link)); |
| 392 | if (res) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 393 | res->flags = 1; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | } |
| 397 | /* FIXME: do we need to check extend conf space? |
| 398 | I don't believe that much preset value */ |
| 399 | |
| 400 | pci_domain_read_resources(dev); |
| 401 | } |
| 402 | |
| 403 | void domain_enable_resources(device_t dev) |
| 404 | { |
| 405 | if (acpi_is_wakeup_s3()) |
| 406 | AGESAWRAPPER(fchs3laterestore); |
| 407 | |
| 408 | /* Must be called after PCI enumeration and resource allocation */ |
| 409 | if (!acpi_is_wakeup_s3()) |
| 410 | AGESAWRAPPER(amdinitmid); |
| 411 | |
| 412 | printk(BIOS_DEBUG, " ader - leaving domain_enable_resources.\n"); |
| 413 | } |
| 414 | |
| 415 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 416 | struct hw_mem_hole_info { |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 417 | unsigned int hole_startk; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 418 | int node_id; |
| 419 | }; |
| 420 | |
| 421 | static struct hw_mem_hole_info get_hw_mem_hole_info(void) |
| 422 | { |
| 423 | struct hw_mem_hole_info mem_hole; |
| 424 | mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK; |
| 425 | mem_hole.node_id = -1; |
| 426 | dram_base_mask_t d; |
| 427 | u32 hole; |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 428 | d = get_dram_base_mask(); |
| 429 | hole = pci_read_config32(dev_find_slot(0, ADDR_DEVFN), 0xf0); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 430 | if (hole & 2) { |
| 431 | /* We found the hole */ |
| 432 | mem_hole.hole_startk = (hole & (0xff << 24)) >> 10; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 433 | mem_hole.node_id = 0; /* record the node # with hole */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | return mem_hole; |
| 437 | } |
| 438 | #endif |
| 439 | |
| 440 | void domain_set_resources(device_t dev) |
| 441 | { |
| 442 | unsigned long mmio_basek; |
| 443 | u32 pci_tolm; |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 444 | int idx; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 445 | struct bus *link; |
| 446 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 447 | struct hw_mem_hole_info mem_hole; |
| 448 | u32 reset_memhole = 1; |
| 449 | #endif |
| 450 | |
| 451 | pci_tolm = 0xffffffffUL; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 452 | for (link = dev->link_list ; link ; link = link->next) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 453 | pci_tolm = find_pci_tolm(link); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 454 | |
| 455 | mmio_basek = pci_tolm >> 10; |
| 456 | /* Round mmio_basek to something the processor can support */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 457 | mmio_basek &= ~((1 << 6) - 1); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 458 | |
| 459 | /* FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M |
| 460 | * MMIO hole. If you fix this here, please fix amdk8, too. |
| 461 | */ |
| 462 | /* Round the mmio hole to 64M */ |
| 463 | mmio_basek &= ~((64 * 1024) - 1); |
| 464 | |
| 465 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 466 | /* if the hw mem hole is already set in raminit stage, here we will |
| 467 | * compare mmio_basek and hole_basek. if mmio_basek is bigger that |
| 468 | * hole_basek and will use hole_basek as mmio_basek and we don't need |
| 469 | * to reset hole. Otherwise we reset the hole to the mmio_basek |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 470 | */ |
| 471 | |
| 472 | mem_hole = get_hw_mem_hole_info(); |
| 473 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 474 | /* Use hole_basek as mmio_basek, and no need to reset hole anymore */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 475 | if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) { |
| 476 | mmio_basek = mem_hole.hole_startk; |
| 477 | reset_memhole = 0; |
| 478 | } |
| 479 | #endif |
| 480 | |
| 481 | idx = 0x10; |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 482 | dram_base_mask_t d; |
| 483 | resource_t basek, limitk, sizek; /* 4 1T */ |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 484 | |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 485 | d = get_dram_base_mask(); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 486 | |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 487 | if ((d.mask & 1)) { /* if enabled... */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 488 | /* could overflow, we may lose 6 bit here */ |
| 489 | basek = ((resource_t)(d.base & 0x1fffff00)) << 9; |
| 490 | limitk = ((resource_t)(((d.mask & ~1) + 0x000ff) |
| 491 | & 0x1fffff00)) << 9; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 492 | |
| 493 | sizek = limitk - basek; |
| 494 | |
| 495 | /* see if we need a hole from 0xa0000 to 0xbffff */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 496 | if ((basek < ((8 * 64) + (8 * 16))) && (sizek > ((8 * 64) + |
| 497 | (16 * 16)))) { |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 498 | ram_resource(dev, idx, basek, |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 499 | ((8 * 64) + (8 * 16)) - basek); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 500 | idx += 0x10; |
| 501 | basek = (8 * 64) + (16 * 16); |
| 502 | sizek = limitk - ((8 * 64) + (16 * 16)); |
| 503 | |
| 504 | } |
| 505 | |
| 506 | /* split the region to accommodate pci memory space */ |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 507 | if ((basek < 4 * 1024 * 1024) && (limitk > mmio_basek)) { |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 508 | if (basek <= mmio_basek) { |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 509 | unsigned int pre_sizek; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 510 | pre_sizek = mmio_basek - basek; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 511 | if (pre_sizek > 0) { |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 512 | ram_resource(dev, idx, basek, |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 513 | pre_sizek); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 514 | idx += 0x10; |
| 515 | sizek -= pre_sizek; |
| 516 | } |
| 517 | basek = mmio_basek; |
| 518 | } |
| 519 | if ((basek + sizek) <= 4 * 1024 * 1024) { |
| 520 | sizek = 0; |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 521 | } else { |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 522 | uint64_t topmem2 = bsp_topmem2(); |
| 523 | basek = 4 * 1024 * 1024; |
| 524 | sizek = topmem2 / 1024 - basek; |
| 525 | } |
| 526 | } |
| 527 | |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 528 | ram_resource(dev, idx, basek, sizek); |
| 529 | printk(BIOS_DEBUG, "node 0: mmio_basek=%08lx, basek=%08llx," |
| 530 | " limitk=%08llx\n", mmio_basek, basek, limitk); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | add_uma_resource_below_tolm(dev, 7); |
| 534 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 535 | for (link = dev->link_list ; link ; link = link->next) |
| 536 | if (link->children) |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 537 | assign_resources(link); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 538 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 539 | /* |
| 540 | * Reserve everything between A segment and 1MB: |
| 541 | * |
| 542 | * 0xa0000 - 0xbffff: legacy VGA |
| 543 | * 0xc0000 - 0xfffff: RAM |
| 544 | */ |
| 545 | mmio_resource(dev, 0xa0000, 0xa0000 / KiB, 0x20000 / KiB); |
| 546 | reserved_ram_resource(dev, 0xc0000, 0xc0000 / KiB, 0x40000 / KiB); |
| 547 | } |
| 548 | |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 549 | void cpu_bus_scan(device_t dev) |
| 550 | { |
| 551 | struct bus *cpu_bus; |
| 552 | device_t cpu; |
| 553 | device_t cdb_dev; |
| 554 | device_t dev_mc; |
| 555 | int j; |
| 556 | int core_max; |
| 557 | int core_nums; |
| 558 | int siblings; |
| 559 | int family; |
| 560 | int enable_node; |
| 561 | u32 lapicid_start; |
| 562 | u32 apic_id; |
| 563 | u32 pccount; |
| 564 | |
| 565 | |
| 566 | dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0)); |
| 567 | if (!dev_mc) { |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 568 | printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, |
| 569 | CONFIG_CDB); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 570 | die(""); |
| 571 | } |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 572 | |
| 573 | /* Get max and actual number of cores */ |
Kyösti Mälkki | d41feed | 2017-09-24 16:23:57 +0300 | [diff] [blame] | 574 | pccount = cpuid_ecx(0x80000008); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 575 | core_max = 1 << ((pccount >> 12) & 0xf); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 576 | core_nums = (pccount & 0xF); |
| 577 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 578 | family = (cpuid_eax(1) >> 20) & 0xff; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 579 | |
| 580 | cdb_dev = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 5)); |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 581 | siblings = pci_read_config32(cdb_dev, 0x84) & 0xff; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 582 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 583 | printk(BIOS_SPEW, "%s family%xh, core_max=%d, core_nums=%d," |
| 584 | " siblings=%d\n", dev_path(cdb_dev), 0x0f + family, |
| 585 | core_max, core_nums, siblings); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 586 | |
| 587 | /* |
| 588 | * APIC ID calucation is tightly coupled with AGESA v5 code. |
| 589 | * This calculation MUST match the assignment calculation done |
| 590 | * in LocalApicInitializationAtEarly() function. |
| 591 | * And reference GetLocalApicIdForCore() |
| 592 | * |
| 593 | * Apply apic enumeration rules |
| 594 | * For systems with >= 16 APICs, put the IO-APICs at 0..n and |
| 595 | * put the local-APICs at m..z |
| 596 | * |
| 597 | * This is needed because many IO-APIC devices only have 4 bits |
| 598 | * for their APIC id and therefore must reside at 0..15 |
| 599 | */ |
| 600 | |
| 601 | /* |
| 602 | * While the above statement is true, we know some things about |
| 603 | * this silicon. It is an SOC and can't have >= 16 APICs, but |
| 604 | * we will start numbering at 0x10. We also know there is only |
| 605 | * on physical node (module in AMD speak). |
| 606 | */ |
| 607 | |
| 608 | lapicid_start = 0x10; /* Get this from devicetree? see comment above. */ |
Martin Kepplinger | 9460a98 | 2017-06-29 10:57:55 +0200 | [diff] [blame] | 609 | enable_node = cdb_dev->enabled; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 610 | cpu_bus = dev->link_list; |
| 611 | |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 612 | for (j = 0 ; j <= siblings ; j++) { |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 613 | apic_id = lapicid_start + j; |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 614 | printk(BIOS_SPEW, "lapicid_start 0x%x, core 0x%x," |
| 615 | " apicid=0x%x\n", lapicid_start, j, apic_id); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 616 | |
| 617 | cpu = add_cpu_device(cpu_bus, apic_id, enable_node); |
| 618 | if (cpu) |
Marshall Dawson | 38bded0 | 2017-09-01 09:54:48 -0600 | [diff] [blame] | 619 | amd_cpu_topology(cpu, 1, j); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
| 623 | /********************************************************************* |
| 624 | * Change the vendor / device IDs to match the generic VBIOS header. * |
| 625 | *********************************************************************/ |
| 626 | u32 map_oprom_vendev(u32 vendev) |
| 627 | { |
| 628 | u32 new_vendev; |
| 629 | new_vendev = |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 630 | ((vendev >= 0x100298e0) && (vendev <= 0x100298ef)) ? |
| 631 | 0x100298e0 : vendev; |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 632 | |
| 633 | if (vendev != new_vendev) |
Marshall Dawson | 4e101ad | 2017-06-15 12:17:38 -0600 | [diff] [blame] | 634 | printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", |
| 635 | vendev, new_vendev); |
Marc Jones | 1587dc8 | 2017-05-15 18:55:11 -0600 | [diff] [blame] | 636 | |
| 637 | return new_vendev; |
| 638 | } |