blob: 7a6221a2ef1a35a1e241f65eed234d4bed3d4d57 [file] [log] [blame]
Stefan Reinauer688b3852004-01-28 16:56:14 +00001/*
Uwe Hermannc70e9fc2010-02-15 23:10:19 +00002 * This file is part of the coreboot project.
3 *
Stefan Reinauerf8ee1802008-01-18 15:08:58 +00004 * coreboot ACPI Table support
Stefan Reinauer688b3852004-01-28 16:56:14 +00005 * written by Stefan Reinauer <stepan@openbios.org>
Uwe Hermannc70e9fc2010-02-15 23:10:19 +00006 *
7 * Copyright (C) 2004 SUSE LINUX AG
8 * Copyright (C) 2005-2009 coresystems GmbH
Stefan Reinauer777224c2005-01-19 14:06:41 +00009 *
10 * ACPI FADT, FACS, and DSDT table support added by
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000011 * Nick Barker <nick.barker9@btinternet.com>, and those portions
Uwe Hermannc70e9fc2010-02-15 23:10:19 +000012 * Copyright (C) 2004 Nick Barker
Stefan Reinauerf622d592005-11-26 16:56:05 +000013 *
Uwe Hermannc70e9fc2010-02-15 23:10:19 +000014 * Copyright (C) 2005 ADVANCED MICRO DEVICES, INC. All Rights Reserved.
Stefan Reinauerd6edf7a2006-01-05 00:19:52 +000015 * 2005.9 yhlu add SRAT table generation
Stefan Reinauer777224c2005-01-19 14:06:41 +000016 */
17
18/*
19 * Each system port implementing ACPI has to provide two functions:
20 *
21 * write_acpi_tables()
22 * acpi_dump_apics()
23 *
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000024 * See Kontron 986LCD-M port for a good example of an ACPI implementation
25 * in coreboot.
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000026 */
Stefan Reinauer688b3852004-01-28 16:56:14 +000027
28#include <console/console.h>
29#include <string.h>
30#include <arch/acpi.h>
Rudolf Marek293b5f52009-02-01 18:35:15 +000031#include <arch/acpigen.h>
Stefan Reinauer777224c2005-01-19 14:06:41 +000032#include <device/pci.h>
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000033#include <cbmem.h>
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000034
35u8 acpi_checksum(u8 *table, u32 length)
Stefan Reinauer688b3852004-01-28 16:56:14 +000036{
37 u8 ret=0;
38 while (length--) {
39 ret += *table;
40 table++;
41 }
Stefan Reinauera7648c22004-01-29 17:31:34 +000042 return -ret;
Stefan Reinauer688b3852004-01-28 16:56:14 +000043}
44
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000045/**
46 * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length and checksum
Stefan Reinauer06feb882004-02-03 16:11:35 +000047 */
48
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000049void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
Stefan Reinauer688b3852004-01-28 16:56:14 +000050{
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000051 int i, entries_num;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000052 acpi_rsdt_t *rsdt;
53 acpi_xsdt_t *xsdt = NULL;
54
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000055 /* The RSDT is mandatory ... */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000056 rsdt = (acpi_rsdt_t *)rsdp->rsdt_address;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000057
58 /* ... while the XSDT is not */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000059 if (rsdp->xsdt_address) {
60 xsdt = (acpi_xsdt_t *)((u32)rsdp->xsdt_address);
61 }
Stefan Reinauerf622d592005-11-26 16:56:05 +000062
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000063 /* This should always be MAX_ACPI_TABLES */
64 entries_num = ARRAY_SIZE(rsdt->entry);
Stefan Reinauerf622d592005-11-26 16:56:05 +000065
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000066 for (i = 0; i < entries_num; i++) {
67 if(rsdt->entry[i] == 0)
68 break;
Stefan Reinauer688b3852004-01-28 16:56:14 +000069 }
70
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000071 if (i >= entries_num) {
72 printk_err("ACPI: Error: Could not add ACPI table, too many tables.\n");
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
104 printk_debug("ACPI: added table %d/%d Length now %d\n",
105 i+1, entries_num, rsdt->header.length);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000106}
107
Stefan Reinauer26d431a2009-01-20 19:17:51 +0000108int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base, u16 seg_nr, u8 start, u8 end)
109{
Rudolf Mareke6409f22007-11-03 12:50:26 +0000110 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 Reinauer777224c2005-01-19 14:06:41 +0000118int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000119{
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 Reinauerda65fbf2009-04-22 08:18:37 +0000130unsigned 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 Reinauer777224c2005-01-19 14:06:41 +0000149int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,u32 gsi_base)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000150{
151 ioapic->type=1;
152 ioapic->length=sizeof(acpi_madt_ioapic_t);
153 ioapic->reserved=0x00;
Stefan Reinauer777224c2005-01-19 14:06:41 +0000154 ioapic->gsi_base=gsi_base;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000155
156 ioapic->ioapic_id=id;
157 ioapic->ioapic_addr=addr;
158
159 return(ioapic->length);
160}
161
Stefan Reinauer777224c2005-01-19 14:06:41 +0000162int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
Stefan Reinauer06feb882004-02-03 16:11:35 +0000163 u8 bus, u8 source, u32 gsirq, u16 flags)
164{
165 irqoverride->type=2;
166 irqoverride->length=sizeof(acpi_madt_irqoverride_t);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000167 irqoverride->bus=bus;
168 irqoverride->source=source;
169 irqoverride->gsirq=gsirq;
170 irqoverride->flags=flags;
171
172 return(irqoverride->length);
173}
174
Stefan Reinauer777224c2005-01-19 14:06:41 +0000175int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
Stefan Reinauer06feb882004-02-03 16:11:35 +0000176 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 Reinauer777224c2005-01-19 14:06:41 +0000188void acpi_create_madt(acpi_madt_t *madt)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000189{
190#define LOCAL_APIC_ADDR 0xfee00000ULL
Stefan Reinauer777224c2005-01-19 14:06:41 +0000191
Stefan Reinauer06feb882004-02-03 16:11:35 +0000192 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 Reinauercdfe3762009-07-21 22:15:43 +0000198 memcpy(header->signature, "APIC", 4);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000199 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000200 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000201 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 Reinauer06feb882004-02-03 16:11:35 +0000208
Stefan Reinauerf622d592005-11-26 16:56:05 +0000209 current = acpi_fill_madt(current);
Stefan Reinauer777224c2005-01-19 14:06:41 +0000210
Stefan Reinauer06feb882004-02-03 16:11:35 +0000211 /* recalculate length */
212 header->length= current - (unsigned long)madt;
213
214 header->checksum = acpi_checksum((void *)madt, header->length);
215}
216
Rudolf Mareke6409f22007-11-03 12:50:26 +0000217void 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 Reinauercdfe3762009-07-21 22:15:43 +0000226 memcpy(header->signature, "MCFG", 4);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000227 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000228 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000229 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 Marek293b5f52009-02-01 18:35:15 +0000242/* this can be overriden by platform ACPI setup code,
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000243 * if it calls acpi_create_ssdt_generator
244 */
Rudolf Marek293b5f52009-02-01 18:35:15 +0000245unsigned long __attribute__((weak)) acpi_fill_ssdt_generator(unsigned long current,
Myles Watson3fe6b702009-10-09 20:13:43 +0000246 const char *oem_table_id) {
Rudolf Marek293b5f52009-02-01 18:35:15 +0000247 return current;
248}
249
Myles Watson3fe6b702009-10-09 20:13:43 +0000250void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000251{
252 unsigned long current=(unsigned long)ssdt+sizeof(acpi_header_t);
253 memset((void *)ssdt, 0, sizeof(acpi_header_t));
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000254 memcpy(&ssdt->signature, "SSDT", 4);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000255 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 Reinauerb657a3c2009-07-21 21:38:33 +0000259 memcpy(&ssdt->asl_compiler_id, "CORE", 4);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000260 ssdt->asl_compiler_revision = 42;
261 ssdt->length = sizeof(acpi_header_t);
262
Stefan Reinauer8dcd50b2009-03-06 17:24:29 +0000263 acpigen_set_current((char *) current);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000264 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 Reinauerf622d592005-11-26 16:56:05 +0000271int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
272{
Myles Watson0b4c9f02009-03-10 18:06:47 +0000273 memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000274 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
284int 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
302void 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 Reinauercdfe3762009-07-21 22:15:43 +0000311 memcpy(header->signature, "SRAT", 4);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000312 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000313 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000314 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 Lud4b278c2006-10-04 20:46:15 +0000329void 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 Reinauercdfe3762009-07-21 22:15:43 +0000338 memcpy(header->signature, "SLIT", 4);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000339 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000340 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000341 memcpy(header->asl_compiler_id, ASLC, 4);
342
343 header->length = sizeof(acpi_slit_t);
344 header->revision = 1;
345
Myles Watson0b4c9f02009-03-10 18:06:47 +0000346 current = acpi_fill_slit(current);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000347
348 /* recalculate length */
349 header->length= current - (unsigned long)slit;
350
351 header->checksum = acpi_checksum((void *)slit, header->length);
352}
353
Stefan Reinauer777224c2005-01-19 14:06:41 +0000354void acpi_create_hpet(acpi_hpet_t *hpet)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000355{
356#define HPET_ADDR 0xfed00000ULL
357 acpi_header_t *header=&(hpet->header);
358 acpi_addr_t *addr=&(hpet->addr);
359
Stefan Reinauera7648c22004-01-29 17:31:34 +0000360 memset((void *)hpet, 0, sizeof(acpi_hpet_t));
361
Stefan Reinauer688b3852004-01-28 16:56:14 +0000362 /* fill out header fields */
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000363 memcpy(header->signature, "HPET", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000364 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000365 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000366 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 Reinauera7648c22004-01-29 17:31:34 +0000382 header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000383}
Stefan Reinauer777224c2005-01-19 14:06:41 +0000384void acpi_create_facs(acpi_facs_t *facs)
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000385{
Rudolf Marek33cafe52009-04-13 18:07:02 +0000386
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000387 memset( (void *)facs,0, sizeof(acpi_facs_t));
388
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000389 memcpy(facs->signature, "FACS", 4);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000390 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. Minnich02fa3b22004-10-06 17:33:54 +0000398}
Stefan Reinauer777224c2005-01-19 14:06:41 +0000399
400void acpi_write_rsdt(acpi_rsdt_t *rsdt)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000401{
402 acpi_header_t *header=&(rsdt->header);
403
404 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000405 memcpy(header->signature, "RSDT", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000406 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000407 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000408 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 Reinauerb657a3c2009-07-21 21:38:33 +0000419 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000420}
421
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000422void acpi_write_xsdt(acpi_xsdt_t *xsdt)
423{
424 acpi_header_t *header=&(xsdt->header);
425
426 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000427 memcpy(header->signature, "XSDT", 4);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000428 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000429 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000430 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
444void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt, acpi_xsdt_t *xsdt)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000445{
Stefan Reinauerd18faac2009-11-05 18:06:43 +0000446 memset(rsdp, 0, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000447 memcpy(rsdp->signature, RSDP_SIG, 8);
448 memcpy(rsdp->oem_id, OEM_ID, 6);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000449 rsdp->length = sizeof(acpi_rsdp_t);
450 rsdp->rsdt_address = (u32)rsdt;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000451 /* 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 Reinauera7648c22004-01-29 17:31:34 +0000461 rsdp->checksum = acpi_checksum((void *)rsdp, 20);
462 rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000463}
464
Stefan Reinauer08670622009-06-30 15:17:49 +0000465#if CONFIG_HAVE_ACPI_RESUME == 1
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000466void suspend_resume(void)
467{
468 void *wake_vec;
469
470#if 0
Stefan Reinauer08670622009-06-30 15:17:49 +0000471#if CONFIG_MEM_TRAIN_SEQ != 0
472 #error "So far it works on AMD and CONFIG_MEM_TRAIN_SEQ == 0"
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000473#endif
474
Stefan Reinauer08670622009-06-30 15:17:49 +0000475#if CONFIG_RAMBASE < 0x1F00000
476 #error "For ACPI RESUME you need to have CONFIG_RAMBASE at least 31MB"
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000477 #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 */
488u8 acpi_slp_type = 0;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000489
Rudolf Marek33cafe52009-04-13 18:07:02 +0000490int acpi_is_wakeup(void)
491{
492 return (acpi_slp_type == 3);
493}
494
495static 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
500 printk_debug("Looking on %p for valid checksum\n", rsdp);
501
502 if (acpi_checksum((void *)rsdp, 20) != 0)
503 return NULL;
504 printk_debug("Checksum 1 passed\n");
505
506 if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
507 rsdp->length) != 0))
508 return NULL;
509
510 printk_debug("Checksum 2 passed all OK\n");
511
512 return rsdp;
513}
514
515static acpi_rsdp_t *rsdp;
516
517void *acpi_get_wakeup_rsdp(void)
518{
519 return rsdp;
520}
521
522void *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
537 printk_debug("Trying to find the wakeup vector ...\n");
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
548 printk_debug("RSDP found at %p\n", rsdp);
549 rsdt = (acpi_rsdt_t *) rsdp->rsdt_address;
550
551 end = (char *) rsdt + rsdt->header.length;
552 printk_debug("RSDT found at %p ends at %p\n", rsdt, end);
553
554 for (i = 0; ((char *) &rsdt->entry[i]) < end; i++) {
555 fadt = (acpi_fadt_t *) rsdt->entry[i];
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000556 if (strncmp((char *)fadt, "FACP", 4) == 0)
Rudolf Marek33cafe52009-04-13 18:07:02 +0000557 break;
558 fadt = NULL;
559 }
560
561 if (fadt == NULL)
562 return NULL;
563
564 printk_debug("FADT found at %p\n", fadt);
Stefan Reinauer69390db2009-05-26 12:33:52 +0000565 facs = (acpi_facs_t *)fadt->firmware_ctrl;
Rudolf Marek33cafe52009-04-13 18:07:02 +0000566
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000567 if (facs == NULL) {
568 printk_debug("No FACS found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +0000569 return NULL;
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000570 }
Rudolf Marek33cafe52009-04-13 18:07:02 +0000571
572 printk_debug("FACS found at %p\n", facs);
573 wake_vec = (void *) facs->firmware_waking_vector;
574 printk_debug("OS waking vector is %p\n", wake_vec);
575 return wake_vec;
576}
577
578extern char *lowmem_backup;
579extern char *lowmem_backup_ptr;
580extern int lowmem_backup_size;
581
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000582#define WAKEUP_BASE 0x600
583
584void (*acpi_do_wakeup)(u32 vector, u32 backup_source, u32 backup_target, u32
585 backup_size) __attribute__((regparm(0))) = (void *)WAKEUP_BASE;
586
587extern unsigned char __wakeup, __wakeup_size;
588
Rudolf Marek33cafe52009-04-13 18:07:02 +0000589void acpi_jump_to_wakeup(void *vector)
590{
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000591 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 Marek33cafe52009-04-13 18:07:02 +0000599 /* just restore the SMP trampoline and continue with wakeup on assembly level */
600 memcpy(lowmem_backup_ptr, lowmem_backup, lowmem_backup_size);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000601
602 /* copy wakeup trampoline in place */
603 memcpy(WAKEUP_BASE, &__wakeup, &__wakeup_size);
604
605 acpi_do_wakeup((u32)vector, acpi_backup_memory, CONFIG_RAMBASE, HIGH_MEMORY_SAVE);
Rudolf Marek33cafe52009-04-13 18:07:02 +0000606}
607#endif