Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +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 |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +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 <arch/io.h> |
| 26 | #include <device/pci.h> |
| 27 | #include <device/pci_ids.h> |
| 28 | #include <cpu/x86/msr.h> |
| 29 | #include <cpu/amd/mtrr.h> |
| 30 | |
| 31 | #include "agesawrapper.h" |
Bruce Griffith | 93b57c5 | 2013-06-25 19:27:17 -0600 | [diff] [blame] | 32 | #include <cpu/amd/amdfam15.h> |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 33 | |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 34 | extern const unsigned char AmlCode[]; |
| 35 | |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 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 | device_t dev; |
| 45 | u32 dword; |
| 46 | u32 gsi_base = 0; |
| 47 | u32 apicid_sb700; |
| 48 | u32 apicid_rd890; |
| 49 | |
| 50 | /* |
| 51 | * AGESA v5 Apply apic enumeration rules |
| 52 | * For systems with >= 16 APICs, put the IO-APICs at 0..n and |
| 53 | * put the local-APICs at m..z |
| 54 | * For systems with < 16 APICs, put the Local-APICs at 0..n and |
| 55 | * put the IO-APICs at (n + 1)..z |
| 56 | */ |
Kyösti Mälkki | a6c525a | 2014-04-16 09:43:40 +0300 | [diff] [blame] | 57 | if (CONFIG_MAX_CPUS >= 16) |
| 58 | apicid_sb700 = 0x0; |
| 59 | else |
| 60 | apicid_sb700 = CONFIG_MAX_CPUS + 1; |
| 61 | apicid_rd890 = apicid_sb700 + 1; |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 62 | |
| 63 | /* create all subtables for processors */ |
| 64 | current = acpi_create_madt_lapics(current); |
| 65 | |
| 66 | /* Write sb700 IOAPIC, only one */ |
| 67 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, |
| 68 | apicid_sb700, |
| 69 | IO_APIC_ADDR, |
| 70 | 0 |
| 71 | ); |
| 72 | |
| 73 | /* IOAPIC on rs5690 */ |
| 74 | gsi_base += IO_APIC_INTERRUPTS; /* sb700 has 24 IOAPIC entries. */ |
| 75 | dev = dev_find_slot(0, PCI_DEVFN(0, 0)); |
| 76 | if (dev) { |
| 77 | pci_write_config32(dev, 0xF8, 0x1); |
| 78 | dword = pci_read_config32(dev, 0xFC) & 0xfffffff0; |
| 79 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, |
| 80 | apicid_rd890, |
| 81 | dword, |
| 82 | gsi_base |
| 83 | ); |
| 84 | } |
| 85 | |
| 86 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, |
| 87 | 0, //BUS |
| 88 | 0, //SOURCE |
| 89 | 2, //gsirq |
| 90 | 0 //flags |
| 91 | ); |
| 92 | |
| 93 | /* 0: mean bus 0--->ISA */ |
| 94 | /* 0: PIC 0 */ |
| 95 | /* 2: APIC 2 */ |
Kyösti Mälkki | d874757 | 2014-06-26 05:30:54 +0300 | [diff] [blame^] | 96 | /* 5 mean: 0101 --> Edge-triggered, Active high */ |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 97 | |
| 98 | /* create all subtables for processors */ |
| 99 | current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 0, 5, 1); |
| 100 | current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 1, 5, 1); |
| 101 | /* 1: LINT1 connect to NMI */ |
| 102 | |
| 103 | return current; |
| 104 | } |
| 105 | |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 106 | unsigned long acpi_fill_hest(acpi_hest_t *hest) |
| 107 | { |
| 108 | void *addr, *current; |
| 109 | |
| 110 | /* Skip the HEST header. */ |
| 111 | current = (void *)(hest + 1); |
| 112 | |
| 113 | addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE); |
| 114 | if (addr != NULL) |
| 115 | current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
| 116 | |
| 117 | addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC); |
| 118 | if (addr != NULL) |
| 119 | current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
| 120 | |
| 121 | return (unsigned long)current; |
| 122 | } |
| 123 | |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 124 | unsigned long acpi_fill_slit(unsigned long current) |
| 125 | { |
| 126 | // Not implemented |
| 127 | return current; |
| 128 | } |
| 129 | |
| 130 | unsigned long acpi_fill_srat(unsigned long current) |
| 131 | { |
| 132 | /* No NUMA, no SRAT */ |
| 133 | return current; |
| 134 | } |
| 135 | |
| 136 | unsigned long acpi_fill_ssdt_generator(unsigned long current, const char *oem_table_id) |
| 137 | { |
| 138 | int lens; |
| 139 | msr_t msr; |
| 140 | char pscope[] = "\\_SB.PCI0"; |
| 141 | |
| 142 | lens = acpigen_write_scope(pscope); |
| 143 | msr = rdmsr(TOP_MEM); |
| 144 | lens += acpigen_write_name_dword("TOM1", msr.lo); |
| 145 | msr = rdmsr(TOP_MEM2); |
| 146 | /* |
| 147 | * Since XP only implements parts of ACPI 2.0, we can't use a qword |
| 148 | * here. |
| 149 | * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt |
| 150 | * slide 22ff. |
| 151 | * Shift value right by 20 bit to make it fit into 32bit, |
| 152 | * giving us 1MB granularity and a limit of almost 4Exabyte of memory. |
| 153 | */ |
| 154 | lens += acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20); |
| 155 | acpigen_patch_len(lens - 1); |
| 156 | return (unsigned long) (acpigen_get_current()); |
| 157 | } |
| 158 | |
| 159 | unsigned long write_acpi_tables(unsigned long start) |
| 160 | { |
| 161 | unsigned long current; |
| 162 | acpi_rsdp_t *rsdp; |
| 163 | acpi_rsdt_t *rsdt; |
| 164 | //acpi_hpet_t *hpet; |
| 165 | acpi_madt_t *madt; |
| 166 | acpi_srat_t *srat; |
| 167 | acpi_slit_t *slit; |
| 168 | acpi_fadt_t *fadt; |
| 169 | acpi_facs_t *facs; |
| 170 | acpi_header_t *dsdt; |
| 171 | acpi_header_t *ssdt; |
| 172 | acpi_header_t *ssdt2; |
| 173 | acpi_header_t *alib; |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 174 | acpi_hest_t *hest; |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 175 | |
| 176 | get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */ |
| 177 | |
| 178 | /* Align ACPI tables to 16 bytes */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 179 | start = ALIGN(start, 16); |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 180 | current = start; |
| 181 | |
| 182 | printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start); |
| 183 | |
| 184 | /* We need at least an RSDP and an RSDT Table */ |
| 185 | rsdp = (acpi_rsdp_t *) current; |
| 186 | current += sizeof(acpi_rsdp_t); |
| 187 | rsdt = (acpi_rsdt_t *) current; |
| 188 | current += sizeof(acpi_rsdt_t); |
| 189 | |
| 190 | /* clear all table memory */ |
| 191 | memset((void *)start, 0, current - start); |
| 192 | |
| 193 | acpi_write_rsdp(rsdp, rsdt, NULL); |
| 194 | acpi_write_rsdt(rsdt); |
| 195 | |
| 196 | /* FACS */ |
| 197 | printk(BIOS_DEBUG, "ACPI: * FACS\n"); |
| 198 | facs = (acpi_facs_t *) current; |
| 199 | current += sizeof(acpi_facs_t); |
| 200 | acpi_create_facs(facs); |
| 201 | |
| 202 | /* DSDT */ |
| 203 | printk(BIOS_DEBUG, "ACPI: * DSDT\n"); |
| 204 | dsdt = (acpi_header_t *)current; |
| 205 | memcpy(dsdt, &AmlCode, sizeof(acpi_header_t)); |
| 206 | current += dsdt->length; |
| 207 | memcpy(dsdt, &AmlCode, dsdt->length); |
| 208 | printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, dsdt->length); |
| 209 | /* FADT */ |
| 210 | printk(BIOS_DEBUG, "ACPI: * FADT\n"); |
| 211 | fadt = (acpi_fadt_t *) current; |
| 212 | current += sizeof(acpi_fadt_t); |
| 213 | |
| 214 | acpi_create_fadt(fadt, facs, dsdt); |
| 215 | acpi_add_table(rsdp, fadt); |
| 216 | |
| 217 | /* |
| 218 | * We explicitly add these tables later on: |
| 219 | */ |
| 220 | #ifdef UNUSED_CODE // Don't need HPET table. we have one in dsdt |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 221 | current = ALIGN(current, 8); |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 222 | printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current); |
| 223 | hpet = (acpi_hpet_t *) current; |
| 224 | current += sizeof(acpi_hpet_t); |
| 225 | acpi_create_hpet(hpet); |
| 226 | acpi_add_table(rsdp, hpet); |
| 227 | #endif |
| 228 | |
| 229 | /* If we want to use HPET Timers Linux wants an MADT */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 230 | current = ALIGN(current, 8); |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 231 | printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current); |
| 232 | madt = (acpi_madt_t *) current; |
| 233 | acpi_create_madt(madt); |
| 234 | current += madt->header.length; |
| 235 | acpi_add_table(rsdp, madt); |
| 236 | |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 237 | /* HEST */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 238 | current = ALIGN(current, 8); |
zbao | caf494c8 | 2012-04-13 13:57:14 +0800 | [diff] [blame] | 239 | hest = (acpi_hest_t *)current; |
| 240 | acpi_write_hest((void *)current); |
| 241 | acpi_add_table(rsdp, (void *)current); |
| 242 | current += ((acpi_header_t *)current)->length; |
| 243 | |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 244 | /* SRAT */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 245 | current = ALIGN(current, 8); |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 246 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
| 247 | srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT); |
| 248 | if (srat != NULL) { |
| 249 | memcpy((void *)current, srat, srat->header.length); |
| 250 | srat = (acpi_srat_t *) current; |
| 251 | //acpi_create_srat(srat); |
| 252 | current += srat->header.length; |
| 253 | acpi_add_table(rsdp, srat); |
| 254 | } |
| 255 | |
| 256 | /* SLIT */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 257 | current = ALIGN(current, 8); |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 258 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
| 259 | slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT); |
| 260 | if (slit != NULL) { |
| 261 | memcpy((void *)current, slit, slit->header.length); |
| 262 | slit = (acpi_slit_t *) current; |
| 263 | //acpi_create_slit(slit); |
| 264 | current += slit->header.length; |
| 265 | acpi_add_table(rsdp, slit); |
| 266 | } |
| 267 | |
| 268 | /* SSDT */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 269 | current = ALIGN(current, 16); |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 270 | printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current); |
| 271 | alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB); |
| 272 | if (alib != NULL) { |
| 273 | memcpy((void *)current, alib, alib->length); |
zbao | 2132005 | 2012-04-13 13:48:50 +0800 | [diff] [blame] | 274 | alib = (acpi_header_t *) current; |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 275 | current += alib->length; |
zbao | 2132005 | 2012-04-13 13:48:50 +0800 | [diff] [blame] | 276 | acpi_add_table(rsdp, (void *)alib); |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 277 | } else { |
| 278 | printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n"); |
| 279 | } |
| 280 | |
zbao | 585a400 | 2012-04-12 11:27:26 +0800 | [diff] [blame] | 281 | /* The DSDT needs additional work for the AGESA SSDT Pstate table */ |
| 282 | /* Keep the comment for a while. */ |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 283 | current = ALIGN(current, 16); |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 284 | printk(BIOS_DEBUG, "ACPI: * AGESA SSDT Pstate at %lx\n", current); |
| 285 | ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE); |
| 286 | if (ssdt != NULL) { |
| 287 | memcpy((void *)current, ssdt, ssdt->length); |
| 288 | ssdt = (acpi_header_t *) current; |
| 289 | current += ssdt->length; |
zbao | 585a400 | 2012-04-12 11:27:26 +0800 | [diff] [blame] | 290 | acpi_add_table(rsdp,ssdt); |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 291 | } else { |
zbao | 585a400 | 2012-04-12 11:27:26 +0800 | [diff] [blame] | 292 | printk(BIOS_DEBUG, " AGESA SSDT Pstate table NULL. Skipping.\n"); |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 293 | } |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 294 | |
Patrick Georgi | 26b00e6 | 2012-04-20 19:19:47 +0200 | [diff] [blame] | 295 | current = ALIGN(current, 16); |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 296 | printk(BIOS_DEBUG, "ACPI: * coreboot TOM SSDT2 at %lx\n", current); |
| 297 | ssdt2 = (acpi_header_t *) current; |
| 298 | acpi_create_ssdt_generator(ssdt2, ACPI_TABLE_CREATOR); |
| 299 | current += ssdt2->length; |
| 300 | acpi_add_table(rsdp,ssdt2); |
| 301 | |
Kerry Sheh | 6d6d18e | 2012-02-07 20:32:34 +0800 | [diff] [blame] | 302 | printk(BIOS_INFO, "ACPI: done.\n"); |
| 303 | return current; |
| 304 | } |