Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 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 | |
| 20 | #include <console/console.h> |
| 21 | #include <string.h> |
| 22 | #include <arch/acpi.h> |
| 23 | #include <arch/ioapic.h> |
| 24 | #include <device/pci.h> |
| 25 | #include <device/pci_ids.h> |
| 26 | #include <cpu/x86/msr.h> |
| 27 | #include <cpu/amd/mtrr.h> |
| 28 | //#include <cpu/amd/amdfam10_sysconf.h> |
| 29 | |
| 30 | //#include "mb_sysconf.h" |
| 31 | #include "agesawrapper.h" |
| 32 | |
| 33 | #define DUMP_ACPI_TABLES 0 |
| 34 | |
| 35 | #if DUMP_ACPI_TABLES == 1 |
| 36 | |
| 37 | static void dump_mem(u32 start, u32 end) |
| 38 | { |
| 39 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 40 | u32 i; |
| 41 | print_debug("dump_mem:"); |
| 42 | for (i = start; i < end; i++) { |
| 43 | if ((i & 0xf) == 0) { |
| 44 | printk(BIOS_DEBUG, "\n%08x:", i); |
| 45 | } |
| 46 | printk(BIOS_DEBUG, " %02x", (u8)*((u8 *)i)); |
| 47 | } |
| 48 | print_debug("\n"); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 49 | } |
| 50 | #endif |
| 51 | |
| 52 | extern const unsigned char AmlCode[]; |
| 53 | extern const unsigned char AmlCode_ssdt[]; |
| 54 | |
| 55 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 56 | { |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 57 | /* Just a dummy */ |
| 58 | return current; |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | unsigned long acpi_fill_madt(unsigned long current) |
| 62 | { |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 63 | /* create all subtables for processors */ |
| 64 | current = acpi_create_madt_lapics(current); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 65 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 66 | /* Write SB800 IOAPIC, only one */ |
| 67 | current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, |
| 68 | CONFIG_MAX_CPUS, IO_APIC_ADDR, 0); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 69 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 70 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 71 | current, 0, 0, 2, 0); |
| 72 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) |
| 73 | current, 0, 9, 9, 0xF); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 74 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 75 | /* 0: mean bus 0--->ISA */ |
| 76 | /* 0: PIC 0 */ |
| 77 | /* 2: APIC 2 */ |
| 78 | /* 5 mean: 0101 --> Edige-triggered, Active high */ |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 79 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 80 | /* create all subtables for processors */ |
| 81 | /* current = acpi_create_madt_lapic_nmis(current, 5, 1); */ |
| 82 | /* 1: LINT1 connect to NMI */ |
| 83 | |
| 84 | return current; |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | unsigned long acpi_fill_slit(unsigned long current) |
| 88 | { |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 89 | // Not implemented |
| 90 | return current; |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | unsigned long acpi_fill_srat(unsigned long current) |
| 94 | { |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 95 | /* No NUMA, no SRAT */ |
| 96 | return current; |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | unsigned long write_acpi_tables(unsigned long start) |
| 100 | { |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 101 | unsigned long current; |
| 102 | acpi_rsdp_t *rsdp; |
| 103 | acpi_rsdt_t *rsdt; |
| 104 | acpi_hpet_t *hpet; |
| 105 | acpi_madt_t *madt; |
| 106 | acpi_srat_t *srat; |
| 107 | acpi_slit_t *slit; |
| 108 | acpi_fadt_t *fadt; |
| 109 | acpi_facs_t *facs; |
| 110 | acpi_header_t *dsdt; |
| 111 | acpi_header_t *ssdt; |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 112 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 113 | get_bus_conf(); /* it will get sblk, pci1234, hcdn, and sbdn */ |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 114 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 115 | /* Align ACPI tables to 16 bytes */ |
| 116 | start = (start + 0x0f) & -0x10; |
| 117 | current = start; |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 118 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 119 | printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx...\n", start); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 120 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 121 | /* We need at least an RSDP and an RSDT Table */ |
| 122 | rsdp = (acpi_rsdp_t *) current; |
| 123 | current += sizeof(acpi_rsdp_t); |
| 124 | rsdt = (acpi_rsdt_t *) current; |
| 125 | current += sizeof(acpi_rsdt_t); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 126 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 127 | /* clear all table memory */ |
| 128 | memset((void *)start, 0, current - start); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 129 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 130 | acpi_write_rsdp(rsdp, rsdt, NULL); |
| 131 | acpi_write_rsdt(rsdt); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 132 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 133 | /* |
| 134 | * We explicitly add these tables later on: |
| 135 | */ |
| 136 | current = ( current + 0x07) & -0x08; |
| 137 | printk(BIOS_DEBUG, "ACPI: * HPET at %lx\n", current); |
| 138 | hpet = (acpi_hpet_t *) current; |
| 139 | current += sizeof(acpi_hpet_t); |
| 140 | acpi_create_hpet(hpet); |
| 141 | acpi_add_table(rsdp, hpet); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 142 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 143 | /* If we want to use HPET Timers Linux wants an MADT */ |
| 144 | current = ( current + 0x07) & -0x08; |
| 145 | printk(BIOS_DEBUG, "ACPI: * MADT at %lx\n",current); |
| 146 | madt = (acpi_madt_t *) current; |
| 147 | acpi_create_madt(madt); |
| 148 | current += madt->header.length; |
| 149 | acpi_add_table(rsdp, madt); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 150 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 151 | /* SRAT */ |
| 152 | current = ( current + 0x07) & -0x08; |
| 153 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
| 154 | srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT); |
| 155 | if (srat != NULL) { |
| 156 | memcpy(current, srat, srat->header.length); |
| 157 | srat = (acpi_srat_t *) current; |
| 158 | //acpi_create_srat(srat); |
| 159 | current += srat->header.length; |
| 160 | acpi_add_table(rsdp, srat); |
| 161 | } |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 162 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 163 | /* SLIT */ |
| 164 | current = ( current + 0x07) & -0x08; |
| 165 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
| 166 | slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT); |
| 167 | if (slit != NULL) { |
| 168 | memcpy(current, slit, slit->header.length); |
| 169 | slit = (acpi_slit_t *) current; |
| 170 | //acpi_create_slit(slit); |
| 171 | current += slit->header.length; |
| 172 | acpi_add_table(rsdp, slit); |
| 173 | } |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 174 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 175 | /* SSDT */ |
| 176 | current = ( current + 0x0f) & -0x10; |
| 177 | printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current); |
| 178 | ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE); |
| 179 | if (ssdt != NULL) { |
| 180 | memcpy(current, ssdt, ssdt->length); |
| 181 | ssdt = (acpi_header_t *) current; |
| 182 | current += ssdt->length; |
| 183 | } |
| 184 | else { |
| 185 | ssdt = (acpi_header_t *) current; |
| 186 | memcpy(ssdt, &AmlCode_ssdt, sizeof(acpi_header_t)); |
| 187 | current += ssdt->length; |
| 188 | memcpy(ssdt, &AmlCode_ssdt, ssdt->length); |
Scott Duplichan | 7d6f0bf | 2011-07-09 20:14:20 -0500 | [diff] [blame] | 189 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 190 | char *position = ssdt; |
| 191 | if (memcmp (position + 50, "TOM1", 4) == 0) |
| 192 | *(u32 *) (position + 55) = __readmsr (0xc001001a); |
Scott Duplichan | 7d6f0bf | 2011-07-09 20:14:20 -0500 | [diff] [blame] | 193 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 194 | /* recalculate checksum */ |
| 195 | ssdt->checksum = 0; |
| 196 | ssdt->checksum = acpi_checksum((unsigned char *)ssdt,ssdt->length); |
| 197 | } |
| 198 | acpi_add_table(rsdp,ssdt); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 199 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 200 | printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 201 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 202 | /* DSDT */ |
| 203 | current = ( current + 0x07) & -0x08; |
| 204 | printk(BIOS_DEBUG, "ACPI: * DSDT at %lx\n", current); |
| 205 | dsdt = (acpi_header_t *)current; // it will used by fadt |
| 206 | memcpy(dsdt, &AmlCode, sizeof(acpi_header_t)); |
| 207 | current += dsdt->length; |
| 208 | memcpy(dsdt, &AmlCode, dsdt->length); |
| 209 | printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n",dsdt,dsdt->length); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 210 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 211 | /* FACS */ // it needs 64 bit alignment |
| 212 | current = ( current + 0x07) & -0x08; |
| 213 | printk(BIOS_DEBUG, "ACPI: * FACS at %lx\n", current); |
| 214 | facs = (acpi_facs_t *) current; // it will be used by fadt |
| 215 | current += sizeof(acpi_facs_t); |
| 216 | acpi_create_facs(facs); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 217 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 218 | /* FDAT */ |
| 219 | current = ( current + 0x07) & -0x08; |
| 220 | printk(BIOS_DEBUG, "ACPI: * FADT at %lx\n", current); |
| 221 | fadt = (acpi_fadt_t *) current; |
| 222 | current += sizeof(acpi_fadt_t); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 223 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 224 | acpi_create_fadt(fadt, facs, dsdt); |
| 225 | acpi_add_table(rsdp, fadt); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 226 | |
| 227 | #if DUMP_ACPI_TABLES == 1 |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 228 | printk(BIOS_DEBUG, "rsdp\n"); |
| 229 | dump_mem(rsdp, ((void *)rsdp) + sizeof(acpi_rsdp_t)); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 230 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 231 | printk(BIOS_DEBUG, "rsdt\n"); |
| 232 | dump_mem(rsdt, ((void *)rsdt) + sizeof(acpi_rsdt_t)); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 233 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 234 | printk(BIOS_DEBUG, "madt\n"); |
| 235 | dump_mem(madt, ((void *)madt) + madt->header.length); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 236 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 237 | printk(BIOS_DEBUG, "srat\n"); |
| 238 | dump_mem(srat, ((void *)srat) + srat->header.length); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 239 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 240 | printk(BIOS_DEBUG, "slit\n"); |
| 241 | dump_mem(slit, ((void *)slit) + slit->header.length); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 242 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 243 | printk(BIOS_DEBUG, "ssdt\n"); |
| 244 | dump_mem(ssdt, ((void *)ssdt) + ssdt->length); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 245 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 246 | printk(BIOS_DEBUG, "fadt\n"); |
| 247 | dump_mem(fadt, ((void *)fadt) + fadt->header.length); |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 248 | #endif |
| 249 | |
Marc Jones | 522ba28 | 2012-01-03 16:02:07 -0700 | [diff] [blame^] | 250 | printk(BIOS_INFO, "ACPI: done.\n"); |
| 251 | return current; |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 252 | } |