Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 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 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
Alexandru Gagniuc | 1d87dac | 2014-03-28 14:48:13 -0500 | [diff] [blame] | 20 | #include "agesawrapper.h" |
| 21 | |
Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 22 | #include <arch/acpi.h> |
| 23 | #include <arch/acpigen.h> |
| 24 | #include <arch/ioapic.h> |
Alexandru Gagniuc | 1d87dac | 2014-03-28 14:48:13 -0500 | [diff] [blame] | 25 | #include <cpu/amd/amdfam15.h> |
| 26 | #include <console/console.h> |
Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 27 | #include <device/pci.h> |
| 28 | #include <device/pci_ids.h> |
Alexandru Gagniuc | 1d87dac | 2014-03-28 14:48:13 -0500 | [diff] [blame] | 29 | #include <string.h> |
Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 30 | |
Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 31 | extern const unsigned char AmlCode[]; |
| 32 | |
| 33 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 34 | { |
| 35 | /* Just a dummy */ |
| 36 | return current; |
| 37 | } |
| 38 | |
| 39 | unsigned long acpi_fill_madt(unsigned long current) |
| 40 | { |
| 41 | /* create all subtables for processors */ |
| 42 | current = acpi_create_madt_lapics(current); |
| 43 | |
| 44 | /* Write Hudson IOAPIC, only one */ |
| 45 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, CONFIG_MAX_CPUS, |
| 46 | IO_APIC_ADDR, 0); |
| 47 | |
| 48 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 49 | current, 0, 0, 2, 0); |
| 50 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 51 | current, 0, 9, 9, 0xF); |
| 52 | /* 0: mean bus 0--->ISA */ |
| 53 | /* 0: PIC 0 */ |
| 54 | /* 2: APIC 2 */ |
Kyösti Mälkki | d874757 | 2014-06-26 05:30:54 +0300 | [diff] [blame^] | 55 | /* 5 mean: 0101 --> Edge-triggered, Active high */ |
Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 56 | |
| 57 | /* create all subtables for processors */ |
| 58 | current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 0xff, 5, 1); |
| 59 | /* 1: LINT1 connect to NMI */ |
| 60 | |
| 61 | return current; |
| 62 | } |
| 63 | |
| 64 | unsigned long acpi_fill_hest(acpi_hest_t *hest) |
| 65 | { |
| 66 | void *addr, *current; |
| 67 | |
| 68 | /* Skip the HEST header. */ |
| 69 | current = (void *)(hest + 1); |
| 70 | |
| 71 | addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE); |
| 72 | if (addr != NULL) |
| 73 | current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
| 74 | |
| 75 | addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC); |
| 76 | if (addr != NULL) |
| 77 | current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
| 78 | |
| 79 | return (unsigned long)current; |
| 80 | } |
| 81 | |
| 82 | unsigned long acpi_fill_slit(unsigned long current) |
| 83 | { |
| 84 | /* Not implemented */ |
| 85 | return current; |
| 86 | } |
| 87 | |
| 88 | unsigned long acpi_fill_srat(unsigned long current) |
| 89 | { |
| 90 | /* No NUMA, no SRAT */ |
| 91 | return current; |
| 92 | } |
| 93 | |
| 94 | unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) |
| 95 | { |
| 96 | int lens; |
| 97 | msr_t msr; |
| 98 | char pscope[] = "\\_SB.PCI0"; |
| 99 | |
| 100 | lens = acpigen_write_scope(pscope); |
| 101 | msr = rdmsr(TOP_MEM); |
| 102 | lens += acpigen_write_name_dword("TOM1", msr.lo); |
| 103 | msr = rdmsr(TOP_MEM2); |
| 104 | /* |
| 105 | * Since XP only implements parts of ACPI 2.0, we can't use a qword |
| 106 | * here. |
| 107 | * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt |
| 108 | * slide 22ff. |
| 109 | * Shift value right by 20 bit to make it fit into 32bit, |
| 110 | * giving us 1MB granularity and a limit of almost 4Exabyte of memory. |
| 111 | */ |
| 112 | lens += acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20); |
| 113 | acpigen_patch_len(lens - 1); |
| 114 | return (unsigned long) (acpigen_get_current()); |
| 115 | } |
| 116 | |
| 117 | unsigned long write_acpi_tables(unsigned long start) |
| 118 | { |
| 119 | unsigned long current; |
| 120 | acpi_rsdp_t *rsdp; |
| 121 | acpi_rsdt_t *rsdt; |
| 122 | acpi_hpet_t *hpet; |
| 123 | acpi_madt_t *madt; |
| 124 | acpi_srat_t *srat; |
| 125 | acpi_slit_t *slit; |
| 126 | acpi_fadt_t *fadt; |
| 127 | acpi_facs_t *facs; |
| 128 | acpi_header_t *dsdt; |
| 129 | acpi_header_t *ssdt; |
| 130 | acpi_header_t *alib; |
| 131 | acpi_header_t *ivrs; |
| 132 | acpi_hest_t *hest; |
| 133 | |
| 134 | get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */ |
| 135 | |
| 136 | /* Align ACPI tables to 16 bytes */ |
| 137 | start = ALIGN(start, 16); |
| 138 | current = start; |
| 139 | |
| 140 | printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start); |
| 141 | |
| 142 | /* We need at least an RSDP and an RSDT Table */ |
| 143 | rsdp = (acpi_rsdp_t *) current; |
| 144 | current += sizeof(acpi_rsdp_t); |
| 145 | rsdt = (acpi_rsdt_t *) current; |
| 146 | current += sizeof(acpi_rsdt_t); |
| 147 | |
| 148 | /* clear all table memory */ |
| 149 | memset((void *)start, 0, current - start); |
| 150 | |
| 151 | acpi_write_rsdp(rsdp, rsdt, NULL); |
| 152 | acpi_write_rsdt(rsdt); |
| 153 | |
| 154 | /* DSDT */ |
| 155 | current = ALIGN(current, 8); |
| 156 | printk(BIOS_DEBUG, "ACPI: * DSDT at %lx\n", current); |
| 157 | dsdt = (acpi_header_t *)current; /* it will used by fadt */ |
| 158 | memcpy(dsdt, &AmlCode, sizeof(acpi_header_t)); |
| 159 | current += dsdt->length; |
| 160 | memcpy(dsdt, &AmlCode, dsdt->length); |
| 161 | printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length); |
| 162 | |
| 163 | /* FACS */ /* it needs 64 bit alignment */ |
| 164 | current = ALIGN(current, 8); |
| 165 | printk(BIOS_DEBUG, "ACPI: * FACS at %lx\n", current); |
| 166 | facs = (acpi_facs_t *) current; /* it will be used by fadt */ |
| 167 | current += sizeof(acpi_facs_t); |
| 168 | acpi_create_facs(facs); |
| 169 | |
| 170 | /* FADT */ |
| 171 | current = ALIGN(current, 8); |
| 172 | printk(BIOS_DEBUG, "ACPI: * FADT at %lx\n", current); |
| 173 | fadt = (acpi_fadt_t *) current; |
| 174 | current += sizeof(acpi_fadt_t); |
| 175 | |
| 176 | acpi_create_fadt(fadt, facs, dsdt); |
| 177 | acpi_add_table(rsdp, fadt); |
| 178 | |
| 179 | /* |
| 180 | * We explicitly add these tables later on: |
| 181 | */ |
| 182 | current = ALIGN(current, 8); |
| 183 | printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current); |
| 184 | hpet = (acpi_hpet_t *) current; |
| 185 | current += sizeof(acpi_hpet_t); |
| 186 | acpi_create_hpet(hpet); |
| 187 | acpi_add_table(rsdp, hpet); |
| 188 | |
| 189 | /* If we want to use HPET Timers Linux wants an MADT */ |
| 190 | current = ALIGN(current, 8); |
| 191 | printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current); |
| 192 | madt = (acpi_madt_t *) current; |
| 193 | acpi_create_madt(madt); |
| 194 | current += madt->header.length; |
| 195 | acpi_add_table(rsdp, madt); |
| 196 | |
| 197 | /* HEST */ |
| 198 | current = ALIGN(current, 8); |
| 199 | hest = (acpi_hest_t *)current; |
| 200 | acpi_write_hest((void *)current); |
| 201 | acpi_add_table(rsdp, (void *)current); |
| 202 | current += ((acpi_header_t *)current)->length; |
| 203 | |
| 204 | current = ALIGN(current, 8); |
| 205 | printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current); |
| 206 | ivrs = agesawrapper_getlateinitptr(PICK_IVRS); |
| 207 | if (ivrs != NULL) { |
| 208 | memcpy((void *)current, ivrs, ivrs->length); |
| 209 | ivrs = (acpi_header_t *) current; |
| 210 | current += ivrs->length; |
| 211 | acpi_add_table(rsdp, ivrs); |
| 212 | } else { |
| 213 | printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n"); |
| 214 | } |
| 215 | |
| 216 | /* SRAT */ |
| 217 | current = ALIGN(current, 8); |
| 218 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
| 219 | srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT); |
| 220 | if (srat != NULL) { |
| 221 | memcpy((void *)current, srat, srat->header.length); |
| 222 | srat = (acpi_srat_t *) current; |
| 223 | current += srat->header.length; |
| 224 | acpi_add_table(rsdp, srat); |
| 225 | } else { |
| 226 | printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n"); |
| 227 | } |
| 228 | |
| 229 | /* SLIT */ |
| 230 | current = ALIGN(current, 8); |
| 231 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
| 232 | slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT); |
| 233 | if (slit != NULL) { |
| 234 | memcpy((void *)current, slit, slit->header.length); |
| 235 | slit = (acpi_slit_t *) current; |
| 236 | current += slit->header.length; |
| 237 | acpi_add_table(rsdp, slit); |
| 238 | } else { |
| 239 | printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n"); |
| 240 | } |
| 241 | |
| 242 | /* ALIB */ |
| 243 | current = ALIGN(current, 16); |
| 244 | printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current); |
| 245 | alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB); |
| 246 | if (alib != NULL) { |
| 247 | memcpy((void *)current, alib, alib->length); |
| 248 | alib = (acpi_header_t *) current; |
| 249 | current += alib->length; |
| 250 | acpi_add_table(rsdp, (void *)alib); |
| 251 | } |
| 252 | else { |
| 253 | printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n"); |
| 254 | } |
| 255 | |
| 256 | /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */ |
| 257 | /* SSDT */ |
| 258 | current = ALIGN(current, 16); |
| 259 | printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current); |
| 260 | ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE); |
| 261 | if (ssdt != NULL) { |
| 262 | memcpy((void *)current, ssdt, ssdt->length); |
| 263 | ssdt = (acpi_header_t *) current; |
| 264 | current += ssdt->length; |
| 265 | } |
| 266 | else { |
| 267 | printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n"); |
| 268 | } |
| 269 | acpi_add_table(rsdp,ssdt); |
| 270 | |
| 271 | printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current); |
| 272 | |
| 273 | printk(BIOS_DEBUG, "ACPI: * SSDT\n"); |
| 274 | ssdt = (acpi_header_t *)current; |
| 275 | |
| 276 | acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR); |
| 277 | current += ssdt->length; |
| 278 | acpi_add_table(rsdp, ssdt); |
| 279 | |
Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 280 | printk(BIOS_INFO, "ACPI: done.\n"); |
| 281 | return current; |
| 282 | } |