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