Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 4 | * coreboot ACPI Table support |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 5 | * written by Stefan Reinauer <stepan@openbios.org> |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 6 | * |
| 7 | * Copyright (C) 2004 SUSE LINUX AG |
| 8 | * Copyright (C) 2005-2009 coresystems GmbH |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 9 | * |
| 10 | * ACPI FADT, FACS, and DSDT table support added by |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 11 | * Nick Barker <nick.barker9@btinternet.com>, and those portions |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 12 | * Copyright (C) 2004 Nick Barker |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 13 | * |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 14 | * Copyright (C) 2005 ADVANCED MICRO DEVICES, INC. All Rights Reserved. |
Stefan Reinauer | d6edf7a | 2006-01-05 00:19:52 +0000 | [diff] [blame] | 15 | * 2005.9 yhlu add SRAT table generation |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | /* |
| 19 | * Each system port implementing ACPI has to provide two functions: |
| 20 | * |
| 21 | * write_acpi_tables() |
| 22 | * acpi_dump_apics() |
| 23 | * |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 24 | * See Kontron 986LCD-M port for a good example of an ACPI implementation |
| 25 | * in coreboot. |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 26 | */ |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 27 | |
| 28 | #include <console/console.h> |
| 29 | #include <string.h> |
| 30 | #include <arch/acpi.h> |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 31 | #include <arch/acpigen.h> |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 32 | #include <device/pci.h> |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 33 | #include <cbmem.h> |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 34 | |
| 35 | u8 acpi_checksum(u8 *table, u32 length) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 36 | { |
| 37 | u8 ret=0; |
| 38 | while (length--) { |
| 39 | ret += *table; |
| 40 | table++; |
| 41 | } |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 42 | return -ret; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 45 | /** |
| 46 | * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length and checksum |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 47 | */ |
| 48 | |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 49 | void acpi_add_table(acpi_rsdp_t *rsdp, void *table) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 50 | { |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 51 | int i, entries_num; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 52 | acpi_rsdt_t *rsdt; |
| 53 | acpi_xsdt_t *xsdt = NULL; |
| 54 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 55 | /* The RSDT is mandatory ... */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 56 | rsdt = (acpi_rsdt_t *)rsdp->rsdt_address; |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 57 | |
| 58 | /* ... while the XSDT is not */ |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 59 | if (rsdp->xsdt_address) { |
| 60 | xsdt = (acpi_xsdt_t *)((u32)rsdp->xsdt_address); |
| 61 | } |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 62 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 63 | /* This should always be MAX_ACPI_TABLES */ |
| 64 | entries_num = ARRAY_SIZE(rsdt->entry); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 65 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 66 | for (i = 0; i < entries_num; i++) { |
| 67 | if(rsdt->entry[i] == 0) |
| 68 | break; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 71 | if (i >= entries_num) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 72 | printk(BIOS_ERR, "ACPI: Error: Could not add ACPI table, too many tables.\n"); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 73 | return; |
| 74 | } |
| 75 | |
| 76 | /* Add table to the RSDT */ |
| 77 | rsdt->entry[i] = (u32)table; |
| 78 | |
| 79 | /* Fix RSDT length or the kernel will assume invalid entries */ |
| 80 | rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i+1)); |
| 81 | |
| 82 | /* Re-calculate checksum */ |
| 83 | rsdt->header.checksum = 0; /* Hope this won't get optimized away */ |
| 84 | rsdt->header.checksum = acpi_checksum((u8 *)rsdt, |
| 85 | rsdt->header.length); |
| 86 | |
| 87 | /* And now the same thing for the XSDT. We use the same index as for |
| 88 | * now we want the XSDT and RSDT to always be in sync in coreboot. |
| 89 | */ |
| 90 | if (xsdt) { |
| 91 | /* Add table to the XSDT */ |
| 92 | xsdt->entry[i]=(u64)(u32)table; |
| 93 | |
| 94 | /* Fix XSDT length */ |
| 95 | xsdt->header.length = sizeof(acpi_header_t) + |
| 96 | (sizeof(u64) * (i+1)); |
| 97 | |
| 98 | /* Re-calculate checksum */ |
| 99 | xsdt->header.checksum=0; |
| 100 | xsdt->header.checksum=acpi_checksum((u8 *)xsdt, |
| 101 | xsdt->header.length); |
| 102 | } |
| 103 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 104 | printk(BIOS_DEBUG, "ACPI: added table %d/%d Length now %d\n", |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 105 | i+1, entries_num, rsdt->header.length); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Stefan Reinauer | 26d431a | 2009-01-20 19:17:51 +0000 | [diff] [blame] | 108 | int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base, u16 seg_nr, u8 start, u8 end) |
| 109 | { |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 110 | mmconfig->base_address = base; |
| 111 | mmconfig->base_reserved = 0; |
| 112 | mmconfig->pci_segment_group_number = seg_nr; |
| 113 | mmconfig->start_bus_number = start; |
| 114 | mmconfig->end_bus_number = end; |
| 115 | return (sizeof(acpi_mcfg_mmconfig_t)); |
| 116 | } |
| 117 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 118 | int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 119 | { |
| 120 | lapic->type=0; |
| 121 | lapic->length=sizeof(acpi_madt_lapic_t); |
| 122 | lapic->flags=1; |
| 123 | |
| 124 | lapic->processor_id=cpu; |
| 125 | lapic->apic_id=apic; |
| 126 | |
| 127 | return(lapic->length); |
| 128 | } |
| 129 | |
Stefan Reinauer | da65fbf | 2009-04-22 08:18:37 +0000 | [diff] [blame] | 130 | unsigned long acpi_create_madt_lapics(unsigned long current) |
| 131 | { |
| 132 | device_t cpu; |
| 133 | int cpu_index = 0; |
| 134 | |
| 135 | for(cpu = all_devices; cpu; cpu = cpu->next) { |
| 136 | if ((cpu->path.type != DEVICE_PATH_APIC) || |
| 137 | (cpu->bus->dev->path.type != DEVICE_PATH_APIC_CLUSTER)) { |
| 138 | continue; |
| 139 | } |
| 140 | if (!cpu->enabled) { |
| 141 | continue; |
| 142 | } |
| 143 | current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, cpu_index, cpu->path.apic.apic_id); |
| 144 | cpu_index++; |
| 145 | } |
| 146 | return current; |
| 147 | } |
| 148 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 149 | int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,u32 gsi_base) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 150 | { |
| 151 | ioapic->type=1; |
| 152 | ioapic->length=sizeof(acpi_madt_ioapic_t); |
| 153 | ioapic->reserved=0x00; |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 154 | ioapic->gsi_base=gsi_base; |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 155 | |
| 156 | ioapic->ioapic_id=id; |
| 157 | ioapic->ioapic_addr=addr; |
| 158 | |
| 159 | return(ioapic->length); |
| 160 | } |
| 161 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 162 | int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride, |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 163 | u8 bus, u8 source, u32 gsirq, u16 flags) |
| 164 | { |
| 165 | irqoverride->type=2; |
| 166 | irqoverride->length=sizeof(acpi_madt_irqoverride_t); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 167 | irqoverride->bus=bus; |
| 168 | irqoverride->source=source; |
| 169 | irqoverride->gsirq=gsirq; |
| 170 | irqoverride->flags=flags; |
| 171 | |
| 172 | return(irqoverride->length); |
| 173 | } |
| 174 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 175 | int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu, |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 176 | u16 flags, u8 lint) |
| 177 | { |
| 178 | lapic_nmi->type=4; |
| 179 | lapic_nmi->length=sizeof(acpi_madt_lapic_nmi_t); |
| 180 | |
| 181 | lapic_nmi->flags=flags; |
| 182 | lapic_nmi->processor_id=cpu; |
| 183 | lapic_nmi->lint=lint; |
| 184 | |
| 185 | return(lapic_nmi->length); |
| 186 | } |
| 187 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 188 | void acpi_create_madt(acpi_madt_t *madt) |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 189 | { |
| 190 | #define LOCAL_APIC_ADDR 0xfee00000ULL |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 191 | |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 192 | acpi_header_t *header=&(madt->header); |
| 193 | unsigned long current=(unsigned long)madt+sizeof(acpi_madt_t); |
| 194 | |
| 195 | memset((void *)madt, 0, sizeof(acpi_madt_t)); |
| 196 | |
| 197 | /* fill out header fields */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 198 | memcpy(header->signature, "APIC", 4); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 199 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 200 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 201 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 202 | |
| 203 | header->length = sizeof(acpi_madt_t); |
| 204 | header->revision = 1; |
| 205 | |
| 206 | madt->lapic_addr= LOCAL_APIC_ADDR; |
| 207 | madt->flags = 0x1; /* PCAT_COMPAT */ |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 208 | |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 209 | current = acpi_fill_madt(current); |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 210 | |
Stefan Reinauer | 06feb88 | 2004-02-03 16:11:35 +0000 | [diff] [blame] | 211 | /* recalculate length */ |
| 212 | header->length= current - (unsigned long)madt; |
| 213 | |
| 214 | header->checksum = acpi_checksum((void *)madt, header->length); |
| 215 | } |
| 216 | |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 217 | void acpi_create_mcfg(acpi_mcfg_t *mcfg) |
| 218 | { |
| 219 | |
| 220 | acpi_header_t *header=&(mcfg->header); |
| 221 | unsigned long current=(unsigned long)mcfg+sizeof(acpi_mcfg_t); |
| 222 | |
| 223 | memset((void *)mcfg, 0, sizeof(acpi_mcfg_t)); |
| 224 | |
| 225 | /* fill out header fields */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 226 | memcpy(header->signature, "MCFG", 4); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 227 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 228 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Rudolf Marek | e6409f2 | 2007-11-03 12:50:26 +0000 | [diff] [blame] | 229 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 230 | |
| 231 | header->length = sizeof(acpi_mcfg_t); |
| 232 | header->revision = 1; |
| 233 | |
| 234 | current = acpi_fill_mcfg(current); |
| 235 | |
| 236 | /* recalculate length */ |
| 237 | header->length= current - (unsigned long)mcfg; |
| 238 | |
| 239 | header->checksum = acpi_checksum((void *)mcfg, header->length); |
| 240 | } |
| 241 | |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 242 | /* this can be overriden by platform ACPI setup code, |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 243 | * if it calls acpi_create_ssdt_generator |
| 244 | */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 245 | unsigned long __attribute__((weak)) acpi_fill_ssdt_generator(unsigned long current, |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 246 | const char *oem_table_id) { |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 247 | return current; |
| 248 | } |
| 249 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 250 | void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 251 | { |
| 252 | unsigned long current=(unsigned long)ssdt+sizeof(acpi_header_t); |
| 253 | memset((void *)ssdt, 0, sizeof(acpi_header_t)); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 254 | memcpy(&ssdt->signature, "SSDT", 4); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 255 | ssdt->revision = 2; |
| 256 | memcpy(&ssdt->oem_id, OEM_ID, 6); |
| 257 | memcpy(&ssdt->oem_table_id, oem_table_id, 8); |
| 258 | ssdt->oem_revision = 42; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 259 | memcpy(&ssdt->asl_compiler_id, "CORE", 4); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 260 | ssdt->asl_compiler_revision = 42; |
| 261 | ssdt->length = sizeof(acpi_header_t); |
| 262 | |
Stefan Reinauer | 8dcd50b | 2009-03-06 17:24:29 +0000 | [diff] [blame] | 263 | acpigen_set_current((char *) current); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 264 | current = acpi_fill_ssdt_generator(current, oem_table_id); |
| 265 | |
| 266 | /* recalculate length */ |
| 267 | ssdt->length = current - (unsigned long)ssdt; |
| 268 | ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length); |
| 269 | } |
| 270 | |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 271 | int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic) |
| 272 | { |
Myles Watson | 0b4c9f0 | 2009-03-10 18:06:47 +0000 | [diff] [blame] | 273 | memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t)); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 274 | lapic->type=0; |
| 275 | lapic->length=sizeof(acpi_srat_lapic_t); |
| 276 | lapic->flags=1; |
| 277 | |
| 278 | lapic->proximity_domain_7_0 = node; |
| 279 | lapic->apic_id=apic; |
| 280 | |
| 281 | return(lapic->length); |
| 282 | } |
| 283 | |
| 284 | int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek,u32 sizek, u32 flags) |
| 285 | { |
| 286 | mem->type=1; |
| 287 | mem->length=sizeof(acpi_srat_mem_t); |
| 288 | |
| 289 | mem->base_address_low = (basek<<10); |
| 290 | mem->base_address_high = (basek>>(32-10)); |
| 291 | |
| 292 | mem->length_low = (sizek<<10); |
| 293 | mem->length_high = (sizek>>(32-10)); |
| 294 | |
| 295 | mem->proximity_domain = node; |
| 296 | |
| 297 | mem->flags = flags; |
| 298 | |
| 299 | return(mem->length); |
| 300 | } |
| 301 | |
| 302 | void acpi_create_srat(acpi_srat_t *srat) |
| 303 | { |
| 304 | |
| 305 | acpi_header_t *header=&(srat->header); |
| 306 | unsigned long current=(unsigned long)srat+sizeof(acpi_srat_t); |
| 307 | |
| 308 | memset((void *)srat, 0, sizeof(acpi_srat_t)); |
| 309 | |
| 310 | /* fill out header fields */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 311 | memcpy(header->signature, "SRAT", 4); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 312 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 313 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 314 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 315 | |
| 316 | header->length = sizeof(acpi_srat_t); |
| 317 | header->revision = 1; |
| 318 | |
| 319 | srat->resv = 0x1; /* BACK COMP */ |
| 320 | |
| 321 | current = acpi_fill_srat(current); |
| 322 | |
| 323 | /* recalculate length */ |
| 324 | header->length= current - (unsigned long)srat; |
| 325 | |
| 326 | header->checksum = acpi_checksum((void *)srat, header->length); |
| 327 | } |
| 328 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 329 | void acpi_create_slit(acpi_slit_t *slit) |
| 330 | { |
| 331 | |
| 332 | acpi_header_t *header=&(slit->header); |
| 333 | unsigned long current=(unsigned long)slit+sizeof(acpi_slit_t); |
| 334 | |
| 335 | memset((void *)slit, 0, sizeof(acpi_slit_t)); |
| 336 | |
| 337 | /* fill out header fields */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 338 | memcpy(header->signature, "SLIT", 4); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 339 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 340 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 341 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 342 | |
| 343 | header->length = sizeof(acpi_slit_t); |
| 344 | header->revision = 1; |
| 345 | |
Myles Watson | 0b4c9f0 | 2009-03-10 18:06:47 +0000 | [diff] [blame] | 346 | current = acpi_fill_slit(current); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 347 | |
| 348 | /* recalculate length */ |
| 349 | header->length= current - (unsigned long)slit; |
| 350 | |
| 351 | header->checksum = acpi_checksum((void *)slit, header->length); |
| 352 | } |
| 353 | |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 354 | void acpi_create_hpet(acpi_hpet_t *hpet) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 355 | { |
| 356 | #define HPET_ADDR 0xfed00000ULL |
| 357 | acpi_header_t *header=&(hpet->header); |
| 358 | acpi_addr_t *addr=&(hpet->addr); |
| 359 | |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 360 | memset((void *)hpet, 0, sizeof(acpi_hpet_t)); |
| 361 | |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 362 | /* fill out header fields */ |
Stefan Reinauer | 4704dc5 | 2009-07-22 01:11:37 +0000 | [diff] [blame] | 363 | memcpy(header->signature, "HPET", 4); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 364 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 365 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 366 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 367 | |
| 368 | header->length = sizeof(acpi_hpet_t); |
| 369 | header->revision = 1; |
| 370 | |
| 371 | /* fill out HPET address */ |
| 372 | addr->space_id = 0; /* Memory */ |
| 373 | addr->bit_width = 64; |
| 374 | addr->bit_offset = 0; |
| 375 | addr->addrl = HPET_ADDR & 0xffffffff; |
| 376 | addr->addrh = HPET_ADDR >> 32; |
| 377 | |
| 378 | hpet->id = 0x102282a0; /* AMD ? */ |
| 379 | hpet->number = 0; |
| 380 | hpet->min_tick = 4096; |
| 381 | |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 382 | header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 383 | } |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 384 | void acpi_create_facs(acpi_facs_t *facs) |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 385 | { |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 386 | |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 387 | memset( (void *)facs,0, sizeof(acpi_facs_t)); |
| 388 | |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 389 | memcpy(facs->signature, "FACS", 4); |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 390 | facs->length = sizeof(acpi_facs_t); |
| 391 | facs->hardware_signature = 0; |
| 392 | facs->firmware_waking_vector = 0; |
| 393 | facs->global_lock = 0; |
| 394 | facs->flags = 0; |
| 395 | facs->x_firmware_waking_vector_l = 0; |
| 396 | facs->x_firmware_waking_vector_h = 0; |
| 397 | facs->version = 1; |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 398 | } |
Stefan Reinauer | 777224c | 2005-01-19 14:06:41 +0000 | [diff] [blame] | 399 | |
| 400 | void acpi_write_rsdt(acpi_rsdt_t *rsdt) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 401 | { |
| 402 | acpi_header_t *header=&(rsdt->header); |
| 403 | |
| 404 | /* fill out header fields */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 405 | memcpy(header->signature, "RSDT", 4); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 406 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 407 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 408 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 409 | |
| 410 | header->length = sizeof(acpi_rsdt_t); |
| 411 | header->revision = 1; |
| 412 | |
| 413 | /* fill out entries */ |
| 414 | |
| 415 | // entries are filled in later, we come with an empty set. |
| 416 | |
| 417 | /* fix checksum */ |
| 418 | |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 419 | header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 422 | void acpi_write_xsdt(acpi_xsdt_t *xsdt) |
| 423 | { |
| 424 | acpi_header_t *header=&(xsdt->header); |
| 425 | |
| 426 | /* fill out header fields */ |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 427 | memcpy(header->signature, "XSDT", 4); |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 428 | memcpy(header->oem_id, OEM_ID, 6); |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 429 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 430 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 431 | |
| 432 | header->length = sizeof(acpi_xsdt_t); |
| 433 | header->revision = 1; |
| 434 | |
| 435 | /* fill out entries */ |
| 436 | |
| 437 | // entries are filled in later, we come with an empty set. |
| 438 | |
| 439 | /* fix checksum */ |
| 440 | |
| 441 | header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t)); |
| 442 | } |
| 443 | |
| 444 | void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt, acpi_xsdt_t *xsdt) |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 445 | { |
Stefan Reinauer | d18faac | 2009-11-05 18:06:43 +0000 | [diff] [blame] | 446 | memset(rsdp, 0, sizeof(acpi_rsdp_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 447 | memcpy(rsdp->signature, RSDP_SIG, 8); |
| 448 | memcpy(rsdp->oem_id, OEM_ID, 6); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 449 | rsdp->length = sizeof(acpi_rsdp_t); |
| 450 | rsdp->rsdt_address = (u32)rsdt; |
Stefan Reinauer | b657a3c | 2009-07-21 21:38:33 +0000 | [diff] [blame] | 451 | /* Some OSes expect an XSDT to be present for RSD PTR |
| 452 | * revisions >= 2. If we don't have an ACPI XSDT, force |
| 453 | * ACPI 1.0 (and thus RSD PTR revision 0) |
| 454 | */ |
| 455 | if (xsdt == NULL) { |
| 456 | rsdp->revision = 0; |
| 457 | } else { |
| 458 | rsdp->xsdt_address = (u64)(u32)xsdt; |
| 459 | rsdp->revision = 2; |
| 460 | } |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 461 | rsdp->checksum = acpi_checksum((void *)rsdp, 20); |
| 462 | rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t)); |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 465 | #if CONFIG_HAVE_ACPI_RESUME == 1 |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 466 | void suspend_resume(void) |
| 467 | { |
| 468 | void *wake_vec; |
| 469 | |
| 470 | #if 0 |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 471 | #if CONFIG_MEM_TRAIN_SEQ != 0 |
| 472 | #error "So far it works on AMD and CONFIG_MEM_TRAIN_SEQ == 0" |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 473 | #endif |
| 474 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 475 | #if CONFIG_RAMBASE < 0x1F00000 |
| 476 | #error "For ACPI RESUME you need to have CONFIG_RAMBASE at least 31MB" |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 477 | #error "Chipset support (S3_NVRAM_EARLY and ACPI_IS_WAKEUP_EARLY functions and memory ctrl)" |
| 478 | #error "And coreboot memory reserved in mainboard.c" |
| 479 | #endif |
| 480 | #endif |
| 481 | /* if we happen to be resuming find wakeup vector and jump to OS */ |
| 482 | wake_vec = acpi_find_wakeup_vector(); |
| 483 | if (wake_vec) |
| 484 | acpi_jump_to_wakeup(wake_vec); |
| 485 | } |
| 486 | |
| 487 | /* this is to be filled by SB code - startup value what was found */ |
| 488 | u8 acpi_slp_type = 0; |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 489 | |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 490 | static int acpi_is_wakeup(void) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 491 | { |
| 492 | return (acpi_slp_type == 3); |
| 493 | } |
| 494 | |
| 495 | static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp) |
| 496 | { |
| 497 | if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0) |
| 498 | return NULL; |
| 499 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 500 | printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 501 | |
| 502 | if (acpi_checksum((void *)rsdp, 20) != 0) |
| 503 | return NULL; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 504 | printk(BIOS_DEBUG, "Checksum 1 passed\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 505 | |
| 506 | if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp, |
| 507 | rsdp->length) != 0)) |
| 508 | return NULL; |
| 509 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 510 | printk(BIOS_DEBUG, "Checksum 2 passed all OK\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 511 | |
| 512 | return rsdp; |
| 513 | } |
| 514 | |
| 515 | static acpi_rsdp_t *rsdp; |
| 516 | |
| 517 | void *acpi_get_wakeup_rsdp(void) |
| 518 | { |
| 519 | return rsdp; |
| 520 | } |
| 521 | |
| 522 | void *acpi_find_wakeup_vector(void) |
| 523 | { |
| 524 | char *p, *end; |
| 525 | |
| 526 | acpi_rsdt_t *rsdt; |
| 527 | acpi_facs_t *facs; |
| 528 | acpi_fadt_t *fadt; |
| 529 | void *wake_vec; |
| 530 | int i; |
| 531 | |
| 532 | rsdp = NULL; |
| 533 | |
| 534 | if (!acpi_is_wakeup()) |
| 535 | return NULL; |
| 536 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 537 | printk(BIOS_DEBUG, "Trying to find the wakeup vector ...\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 538 | |
| 539 | /* find RSDP */ |
| 540 | for (p = (char *) 0xe0000; p < (char *) 0xfffff; p+=16) { |
| 541 | if ((rsdp = valid_rsdp((acpi_rsdp_t *) p))) |
| 542 | break; |
| 543 | } |
| 544 | |
| 545 | if (rsdp == NULL) |
| 546 | return NULL; |
| 547 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 548 | printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 549 | rsdt = (acpi_rsdt_t *) rsdp->rsdt_address; |
| 550 | |
| 551 | end = (char *) rsdt + rsdt->header.length; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 552 | printk(BIOS_DEBUG, "RSDT found at %p ends at %p\n", rsdt, end); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 553 | |
| 554 | for (i = 0; ((char *) &rsdt->entry[i]) < end; i++) { |
| 555 | fadt = (acpi_fadt_t *) rsdt->entry[i]; |
Stefan Reinauer | cdfe376 | 2009-07-21 22:15:43 +0000 | [diff] [blame] | 556 | if (strncmp((char *)fadt, "FACP", 4) == 0) |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 557 | break; |
| 558 | fadt = NULL; |
| 559 | } |
| 560 | |
| 561 | if (fadt == NULL) |
| 562 | return NULL; |
| 563 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 564 | printk(BIOS_DEBUG, "FADT found at %p\n", fadt); |
Stefan Reinauer | 69390db | 2009-05-26 12:33:52 +0000 | [diff] [blame] | 565 | facs = (acpi_facs_t *)fadt->firmware_ctrl; |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 566 | |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 567 | if (facs == NULL) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 568 | printk(BIOS_DEBUG, "No FACS found, wake up from S3 not possible.\n"); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 569 | return NULL; |
Stefan Reinauer | 7e9771c | 2009-04-22 08:17:38 +0000 | [diff] [blame] | 570 | } |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 571 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 572 | printk(BIOS_DEBUG, "FACS found at %p\n", facs); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 573 | wake_vec = (void *) facs->firmware_waking_vector; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 574 | printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 575 | return wake_vec; |
| 576 | } |
| 577 | |
| 578 | extern char *lowmem_backup; |
| 579 | extern char *lowmem_backup_ptr; |
| 580 | extern int lowmem_backup_size; |
| 581 | |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 582 | #define WAKEUP_BASE 0x600 |
| 583 | |
| 584 | void (*acpi_do_wakeup)(u32 vector, u32 backup_source, u32 backup_target, u32 |
| 585 | backup_size) __attribute__((regparm(0))) = (void *)WAKEUP_BASE; |
| 586 | |
| 587 | extern unsigned char __wakeup, __wakeup_size; |
| 588 | |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 589 | void acpi_jump_to_wakeup(void *vector) |
| 590 | { |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 591 | u32 acpi_backup_memory = (u32) cbmem_find(CBMEM_ID_RESUME); |
| 592 | |
| 593 | if (!acpi_backup_memory) { |
| 594 | printk(BIOS_WARNING, "ACPI: Backup memory missing. No S3 Resume.\n"); |
| 595 | return; |
| 596 | } |
| 597 | |
| 598 | // FIXME this should go into the ACPI backup memory, too. No pork saussages. |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 599 | /* just restore the SMP trampoline and continue with wakeup on assembly level */ |
| 600 | memcpy(lowmem_backup_ptr, lowmem_backup, lowmem_backup_size); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 601 | |
| 602 | /* copy wakeup trampoline in place */ |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 603 | memcpy((void *)WAKEUP_BASE, &__wakeup, (size_t)&__wakeup_size); |
Stefan Reinauer | c0ac7e9 | 2009-11-10 22:17:15 +0000 | [diff] [blame] | 604 | |
| 605 | acpi_do_wakeup((u32)vector, acpi_backup_memory, CONFIG_RAMBASE, HIGH_MEMORY_SAVE); |
Rudolf Marek | 33cafe5 | 2009-04-13 18:07:02 +0000 | [diff] [blame] | 606 | } |
| 607 | #endif |