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