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