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