blob: beef891424d9d6a763228653c4fef8e79aec8180 [file] [log] [blame]
Stefan Reinauer688b3852004-01-28 16:56:14 +00001/*
Stefan Reinauerf8ee1802008-01-18 15:08:58 +00002 * coreboot ACPI Table support
Stefan Reinauer688b3852004-01-28 16:56:14 +00003 * written by Stefan Reinauer <stepan@openbios.org>
Stefan Reinauer7e9771c2009-04-22 08:17:38 +00004 * Copyright (C) 2004 SUSE LINUX AG
5 * Copyright (C) 2005-2009 coresystems GmbH
Stefan Reinauer777224c2005-01-19 14:06:41 +00006 *
7 * ACPI FADT, FACS, and DSDT table support added by
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +00008 * Nick Barker <nick.barker9@btinternet.com>, and those portions
Stefan Reinauer777224c2005-01-19 14:06:41 +00009 * (C) Copyright 2004 Nick Barker
Stefan Reinauerf622d592005-11-26 16:56:05 +000010 *
11 * Copyright 2005 ADVANCED MICRO DEVICES, INC. All Rights Reserved.
Stefan Reinauerd6edf7a2006-01-05 00:19:52 +000012 * 2005.9 yhlu add SRAT table generation
Stefan Reinauer777224c2005-01-19 14:06:41 +000013 */
14
15/*
16 * Each system port implementing ACPI has to provide two functions:
17 *
18 * write_acpi_tables()
19 * acpi_dump_apics()
20 *
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000021 * See Kontron 986LCD-M port for a good example of an ACPI implementation
22 * in coreboot.
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000023 */
Stefan Reinauer688b3852004-01-28 16:56:14 +000024
25#include <console/console.h>
26#include <string.h>
27#include <arch/acpi.h>
Rudolf Marek293b5f52009-02-01 18:35:15 +000028#include <arch/acpigen.h>
Stefan Reinauer777224c2005-01-19 14:06:41 +000029#include <device/pci.h>
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000030#include <cbmem.h>
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000031
32u8 acpi_checksum(u8 *table, u32 length)
Stefan Reinauer688b3852004-01-28 16:56:14 +000033{
34 u8 ret=0;
35 while (length--) {
36 ret += *table;
37 table++;
38 }
Stefan Reinauera7648c22004-01-29 17:31:34 +000039 return -ret;
Stefan Reinauer688b3852004-01-28 16:56:14 +000040}
41
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000042/**
43 * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length and checksum
Stefan Reinauer06feb882004-02-03 16:11:35 +000044 */
45
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000046void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
Stefan Reinauer688b3852004-01-28 16:56:14 +000047{
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000048 int i, entries_num;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000049 acpi_rsdt_t *rsdt;
50 acpi_xsdt_t *xsdt = NULL;
51
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000052 /* The RSDT is mandatory ... */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000053 rsdt = (acpi_rsdt_t *)rsdp->rsdt_address;
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000054
55 /* ... while the XSDT is not */
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000056 if (rsdp->xsdt_address) {
57 xsdt = (acpi_xsdt_t *)((u32)rsdp->xsdt_address);
58 }
Stefan Reinauerf622d592005-11-26 16:56:05 +000059
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000060 /* This should always be MAX_ACPI_TABLES */
61 entries_num = ARRAY_SIZE(rsdt->entry);
Stefan Reinauerf622d592005-11-26 16:56:05 +000062
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000063 for (i = 0; i < entries_num; i++) {
64 if(rsdt->entry[i] == 0)
65 break;
Stefan Reinauer688b3852004-01-28 16:56:14 +000066 }
67
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +000068 if (i >= entries_num) {
69 printk_err("ACPI: Error: Could not add ACPI table, too many tables.\n");
70 return;
71 }
72
73 /* Add table to the RSDT */
74 rsdt->entry[i] = (u32)table;
75
76 /* Fix RSDT length or the kernel will assume invalid entries */
77 rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i+1));
78
79 /* Re-calculate checksum */
80 rsdt->header.checksum = 0; /* Hope this won't get optimized away */
81 rsdt->header.checksum = acpi_checksum((u8 *)rsdt,
82 rsdt->header.length);
83
84 /* And now the same thing for the XSDT. We use the same index as for
85 * now we want the XSDT and RSDT to always be in sync in coreboot.
86 */
87 if (xsdt) {
88 /* Add table to the XSDT */
89 xsdt->entry[i]=(u64)(u32)table;
90
91 /* Fix XSDT length */
92 xsdt->header.length = sizeof(acpi_header_t) +
93 (sizeof(u64) * (i+1));
94
95 /* Re-calculate checksum */
96 xsdt->header.checksum=0;
97 xsdt->header.checksum=acpi_checksum((u8 *)xsdt,
98 xsdt->header.length);
99 }
100
101 printk_debug("ACPI: added table %d/%d Length now %d\n",
102 i+1, entries_num, rsdt->header.length);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000103}
104
Stefan Reinauer26d431a2009-01-20 19:17:51 +0000105int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base, u16 seg_nr, u8 start, u8 end)
106{
Rudolf Mareke6409f22007-11-03 12:50:26 +0000107 mmconfig->base_address = base;
108 mmconfig->base_reserved = 0;
109 mmconfig->pci_segment_group_number = seg_nr;
110 mmconfig->start_bus_number = start;
111 mmconfig->end_bus_number = end;
112 return (sizeof(acpi_mcfg_mmconfig_t));
113}
114
Stefan Reinauer777224c2005-01-19 14:06:41 +0000115int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000116{
117 lapic->type=0;
118 lapic->length=sizeof(acpi_madt_lapic_t);
119 lapic->flags=1;
120
121 lapic->processor_id=cpu;
122 lapic->apic_id=apic;
123
124 return(lapic->length);
125}
126
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000127unsigned long acpi_create_madt_lapics(unsigned long current)
128{
129 device_t cpu;
130 int cpu_index = 0;
131
132 for(cpu = all_devices; cpu; cpu = cpu->next) {
133 if ((cpu->path.type != DEVICE_PATH_APIC) ||
134 (cpu->bus->dev->path.type != DEVICE_PATH_APIC_CLUSTER)) {
135 continue;
136 }
137 if (!cpu->enabled) {
138 continue;
139 }
140 current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, cpu_index, cpu->path.apic.apic_id);
141 cpu_index++;
142 }
143 return current;
144}
145
Stefan Reinauer777224c2005-01-19 14:06:41 +0000146int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,u32 gsi_base)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000147{
148 ioapic->type=1;
149 ioapic->length=sizeof(acpi_madt_ioapic_t);
150 ioapic->reserved=0x00;
Stefan Reinauer777224c2005-01-19 14:06:41 +0000151 ioapic->gsi_base=gsi_base;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000152
153 ioapic->ioapic_id=id;
154 ioapic->ioapic_addr=addr;
155
156 return(ioapic->length);
157}
158
Stefan Reinauer777224c2005-01-19 14:06:41 +0000159int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
Stefan Reinauer06feb882004-02-03 16:11:35 +0000160 u8 bus, u8 source, u32 gsirq, u16 flags)
161{
162 irqoverride->type=2;
163 irqoverride->length=sizeof(acpi_madt_irqoverride_t);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000164 irqoverride->bus=bus;
165 irqoverride->source=source;
166 irqoverride->gsirq=gsirq;
167 irqoverride->flags=flags;
168
169 return(irqoverride->length);
170}
171
Stefan Reinauer777224c2005-01-19 14:06:41 +0000172int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
Stefan Reinauer06feb882004-02-03 16:11:35 +0000173 u16 flags, u8 lint)
174{
175 lapic_nmi->type=4;
176 lapic_nmi->length=sizeof(acpi_madt_lapic_nmi_t);
177
178 lapic_nmi->flags=flags;
179 lapic_nmi->processor_id=cpu;
180 lapic_nmi->lint=lint;
181
182 return(lapic_nmi->length);
183}
184
Stefan Reinauer777224c2005-01-19 14:06:41 +0000185void acpi_create_madt(acpi_madt_t *madt)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000186{
187#define LOCAL_APIC_ADDR 0xfee00000ULL
Stefan Reinauer777224c2005-01-19 14:06:41 +0000188
Stefan Reinauer06feb882004-02-03 16:11:35 +0000189 acpi_header_t *header=&(madt->header);
190 unsigned long current=(unsigned long)madt+sizeof(acpi_madt_t);
191
192 memset((void *)madt, 0, sizeof(acpi_madt_t));
193
194 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000195 memcpy(header->signature, "APIC", 4);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000196 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000197 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000198 memcpy(header->asl_compiler_id, ASLC, 4);
199
200 header->length = sizeof(acpi_madt_t);
201 header->revision = 1;
202
203 madt->lapic_addr= LOCAL_APIC_ADDR;
204 madt->flags = 0x1; /* PCAT_COMPAT */
Stefan Reinauer06feb882004-02-03 16:11:35 +0000205
Stefan Reinauerf622d592005-11-26 16:56:05 +0000206 current = acpi_fill_madt(current);
Stefan Reinauer777224c2005-01-19 14:06:41 +0000207
Stefan Reinauer06feb882004-02-03 16:11:35 +0000208 /* recalculate length */
209 header->length= current - (unsigned long)madt;
210
211 header->checksum = acpi_checksum((void *)madt, header->length);
212}
213
Rudolf Mareke6409f22007-11-03 12:50:26 +0000214void acpi_create_mcfg(acpi_mcfg_t *mcfg)
215{
216
217 acpi_header_t *header=&(mcfg->header);
218 unsigned long current=(unsigned long)mcfg+sizeof(acpi_mcfg_t);
219
220 memset((void *)mcfg, 0, sizeof(acpi_mcfg_t));
221
222 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000223 memcpy(header->signature, "MCFG", 4);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000224 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000225 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000226 memcpy(header->asl_compiler_id, ASLC, 4);
227
228 header->length = sizeof(acpi_mcfg_t);
229 header->revision = 1;
230
231 current = acpi_fill_mcfg(current);
232
233 /* recalculate length */
234 header->length= current - (unsigned long)mcfg;
235
236 header->checksum = acpi_checksum((void *)mcfg, header->length);
237}
238
Rudolf Marek293b5f52009-02-01 18:35:15 +0000239/* this can be overriden by platform ACPI setup code,
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000240 * if it calls acpi_create_ssdt_generator
241 */
Rudolf Marek293b5f52009-02-01 18:35:15 +0000242unsigned long __attribute__((weak)) acpi_fill_ssdt_generator(unsigned long current,
Myles Watson3fe6b702009-10-09 20:13:43 +0000243 const char *oem_table_id) {
Rudolf Marek293b5f52009-02-01 18:35:15 +0000244 return current;
245}
246
Myles Watson3fe6b702009-10-09 20:13:43 +0000247void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
Rudolf Marek293b5f52009-02-01 18:35:15 +0000248{
249 unsigned long current=(unsigned long)ssdt+sizeof(acpi_header_t);
250 memset((void *)ssdt, 0, sizeof(acpi_header_t));
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000251 memcpy(&ssdt->signature, "SSDT", 4);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000252 ssdt->revision = 2;
253 memcpy(&ssdt->oem_id, OEM_ID, 6);
254 memcpy(&ssdt->oem_table_id, oem_table_id, 8);
255 ssdt->oem_revision = 42;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000256 memcpy(&ssdt->asl_compiler_id, "CORE", 4);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000257 ssdt->asl_compiler_revision = 42;
258 ssdt->length = sizeof(acpi_header_t);
259
Stefan Reinauer8dcd50b2009-03-06 17:24:29 +0000260 acpigen_set_current((char *) current);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000261 current = acpi_fill_ssdt_generator(current, oem_table_id);
262
263 /* recalculate length */
264 ssdt->length = current - (unsigned long)ssdt;
265 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
266}
267
Stefan Reinauerf622d592005-11-26 16:56:05 +0000268int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
269{
Myles Watson0b4c9f02009-03-10 18:06:47 +0000270 memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000271 lapic->type=0;
272 lapic->length=sizeof(acpi_srat_lapic_t);
273 lapic->flags=1;
274
275 lapic->proximity_domain_7_0 = node;
276 lapic->apic_id=apic;
277
278 return(lapic->length);
279}
280
281int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek,u32 sizek, u32 flags)
282{
283 mem->type=1;
284 mem->length=sizeof(acpi_srat_mem_t);
285
286 mem->base_address_low = (basek<<10);
287 mem->base_address_high = (basek>>(32-10));
288
289 mem->length_low = (sizek<<10);
290 mem->length_high = (sizek>>(32-10));
291
292 mem->proximity_domain = node;
293
294 mem->flags = flags;
295
296 return(mem->length);
297}
298
299void acpi_create_srat(acpi_srat_t *srat)
300{
301
302 acpi_header_t *header=&(srat->header);
303 unsigned long current=(unsigned long)srat+sizeof(acpi_srat_t);
304
305 memset((void *)srat, 0, sizeof(acpi_srat_t));
306
307 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000308 memcpy(header->signature, "SRAT", 4);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000309 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000310 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000311 memcpy(header->asl_compiler_id, ASLC, 4);
312
313 header->length = sizeof(acpi_srat_t);
314 header->revision = 1;
315
316 srat->resv = 0x1; /* BACK COMP */
317
318 current = acpi_fill_srat(current);
319
320 /* recalculate length */
321 header->length= current - (unsigned long)srat;
322
323 header->checksum = acpi_checksum((void *)srat, header->length);
324}
325
Yinghai Lud4b278c2006-10-04 20:46:15 +0000326void acpi_create_slit(acpi_slit_t *slit)
327{
328
329 acpi_header_t *header=&(slit->header);
330 unsigned long current=(unsigned long)slit+sizeof(acpi_slit_t);
331
332 memset((void *)slit, 0, sizeof(acpi_slit_t));
333
334 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000335 memcpy(header->signature, "SLIT", 4);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000336 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000337 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000338 memcpy(header->asl_compiler_id, ASLC, 4);
339
340 header->length = sizeof(acpi_slit_t);
341 header->revision = 1;
342
Myles Watson0b4c9f02009-03-10 18:06:47 +0000343 current = acpi_fill_slit(current);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000344
345 /* recalculate length */
346 header->length= current - (unsigned long)slit;
347
348 header->checksum = acpi_checksum((void *)slit, header->length);
349}
350
Stefan Reinauer777224c2005-01-19 14:06:41 +0000351void acpi_create_hpet(acpi_hpet_t *hpet)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000352{
353#define HPET_ADDR 0xfed00000ULL
354 acpi_header_t *header=&(hpet->header);
355 acpi_addr_t *addr=&(hpet->addr);
356
Stefan Reinauera7648c22004-01-29 17:31:34 +0000357 memset((void *)hpet, 0, sizeof(acpi_hpet_t));
358
Stefan Reinauer688b3852004-01-28 16:56:14 +0000359 /* fill out header fields */
Stefan Reinauer4704dc52009-07-22 01:11:37 +0000360 memcpy(header->signature, "HPET", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000361 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000362 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000363 memcpy(header->asl_compiler_id, ASLC, 4);
364
365 header->length = sizeof(acpi_hpet_t);
366 header->revision = 1;
367
368 /* fill out HPET address */
369 addr->space_id = 0; /* Memory */
370 addr->bit_width = 64;
371 addr->bit_offset = 0;
372 addr->addrl = HPET_ADDR & 0xffffffff;
373 addr->addrh = HPET_ADDR >> 32;
374
375 hpet->id = 0x102282a0; /* AMD ? */
376 hpet->number = 0;
377 hpet->min_tick = 4096;
378
Stefan Reinauera7648c22004-01-29 17:31:34 +0000379 header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000380}
Stefan Reinauer777224c2005-01-19 14:06:41 +0000381void acpi_create_facs(acpi_facs_t *facs)
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000382{
Rudolf Marek33cafe52009-04-13 18:07:02 +0000383
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000384 memset( (void *)facs,0, sizeof(acpi_facs_t));
385
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000386 memcpy(facs->signature, "FACS", 4);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000387 facs->length = sizeof(acpi_facs_t);
388 facs->hardware_signature = 0;
389 facs->firmware_waking_vector = 0;
390 facs->global_lock = 0;
391 facs->flags = 0;
392 facs->x_firmware_waking_vector_l = 0;
393 facs->x_firmware_waking_vector_h = 0;
394 facs->version = 1;
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000395}
Stefan Reinauer777224c2005-01-19 14:06:41 +0000396
397void acpi_write_rsdt(acpi_rsdt_t *rsdt)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000398{
399 acpi_header_t *header=&(rsdt->header);
400
401 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000402 memcpy(header->signature, "RSDT", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000403 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000404 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000405 memcpy(header->asl_compiler_id, ASLC, 4);
406
407 header->length = sizeof(acpi_rsdt_t);
408 header->revision = 1;
409
410 /* fill out entries */
411
412 // entries are filled in later, we come with an empty set.
413
414 /* fix checksum */
415
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000416 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000417}
418
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000419void acpi_write_xsdt(acpi_xsdt_t *xsdt)
420{
421 acpi_header_t *header=&(xsdt->header);
422
423 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000424 memcpy(header->signature, "XSDT", 4);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000425 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000426 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000427 memcpy(header->asl_compiler_id, ASLC, 4);
428
429 header->length = sizeof(acpi_xsdt_t);
430 header->revision = 1;
431
432 /* fill out entries */
433
434 // entries are filled in later, we come with an empty set.
435
436 /* fix checksum */
437
438 header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t));
439}
440
441void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt, acpi_xsdt_t *xsdt)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000442{
Stefan Reinauerd18faac2009-11-05 18:06:43 +0000443 memset(rsdp, 0, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000444 memcpy(rsdp->signature, RSDP_SIG, 8);
445 memcpy(rsdp->oem_id, OEM_ID, 6);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000446 rsdp->length = sizeof(acpi_rsdp_t);
447 rsdp->rsdt_address = (u32)rsdt;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000448 /* Some OSes expect an XSDT to be present for RSD PTR
449 * revisions >= 2. If we don't have an ACPI XSDT, force
450 * ACPI 1.0 (and thus RSD PTR revision 0)
451 */
452 if (xsdt == NULL) {
453 rsdp->revision = 0;
454 } else {
455 rsdp->xsdt_address = (u64)(u32)xsdt;
456 rsdp->revision = 2;
457 }
Stefan Reinauera7648c22004-01-29 17:31:34 +0000458 rsdp->checksum = acpi_checksum((void *)rsdp, 20);
459 rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000460}
461
Stefan Reinauer08670622009-06-30 15:17:49 +0000462#if CONFIG_HAVE_ACPI_RESUME == 1
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000463void suspend_resume(void)
464{
465 void *wake_vec;
466
467#if 0
Stefan Reinauer08670622009-06-30 15:17:49 +0000468#if CONFIG_MEM_TRAIN_SEQ != 0
469 #error "So far it works on AMD and CONFIG_MEM_TRAIN_SEQ == 0"
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000470#endif
471
Stefan Reinauer08670622009-06-30 15:17:49 +0000472#if CONFIG_RAMBASE < 0x1F00000
473 #error "For ACPI RESUME you need to have CONFIG_RAMBASE at least 31MB"
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000474 #error "Chipset support (S3_NVRAM_EARLY and ACPI_IS_WAKEUP_EARLY functions and memory ctrl)"
475 #error "And coreboot memory reserved in mainboard.c"
476#endif
477#endif
478 /* if we happen to be resuming find wakeup vector and jump to OS */
479 wake_vec = acpi_find_wakeup_vector();
480 if (wake_vec)
481 acpi_jump_to_wakeup(wake_vec);
482}
483
484/* this is to be filled by SB code - startup value what was found */
485u8 acpi_slp_type = 0;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000486
Rudolf Marek33cafe52009-04-13 18:07:02 +0000487int acpi_is_wakeup(void)
488{
489 return (acpi_slp_type == 3);
490}
491
492static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
493{
494 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
495 return NULL;
496
497 printk_debug("Looking on %p for valid checksum\n", rsdp);
498
499 if (acpi_checksum((void *)rsdp, 20) != 0)
500 return NULL;
501 printk_debug("Checksum 1 passed\n");
502
503 if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
504 rsdp->length) != 0))
505 return NULL;
506
507 printk_debug("Checksum 2 passed all OK\n");
508
509 return rsdp;
510}
511
512static acpi_rsdp_t *rsdp;
513
514void *acpi_get_wakeup_rsdp(void)
515{
516 return rsdp;
517}
518
519void *acpi_find_wakeup_vector(void)
520{
521 char *p, *end;
522
523 acpi_rsdt_t *rsdt;
524 acpi_facs_t *facs;
525 acpi_fadt_t *fadt;
526 void *wake_vec;
527 int i;
528
529 rsdp = NULL;
530
531 if (!acpi_is_wakeup())
532 return NULL;
533
534 printk_debug("Trying to find the wakeup vector ...\n");
535
536 /* find RSDP */
537 for (p = (char *) 0xe0000; p < (char *) 0xfffff; p+=16) {
538 if ((rsdp = valid_rsdp((acpi_rsdp_t *) p)))
539 break;
540 }
541
542 if (rsdp == NULL)
543 return NULL;
544
545 printk_debug("RSDP found at %p\n", rsdp);
546 rsdt = (acpi_rsdt_t *) rsdp->rsdt_address;
547
548 end = (char *) rsdt + rsdt->header.length;
549 printk_debug("RSDT found at %p ends at %p\n", rsdt, end);
550
551 for (i = 0; ((char *) &rsdt->entry[i]) < end; i++) {
552 fadt = (acpi_fadt_t *) rsdt->entry[i];
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000553 if (strncmp((char *)fadt, "FACP", 4) == 0)
Rudolf Marek33cafe52009-04-13 18:07:02 +0000554 break;
555 fadt = NULL;
556 }
557
558 if (fadt == NULL)
559 return NULL;
560
561 printk_debug("FADT found at %p\n", fadt);
Stefan Reinauer69390db2009-05-26 12:33:52 +0000562 facs = (acpi_facs_t *)fadt->firmware_ctrl;
Rudolf Marek33cafe52009-04-13 18:07:02 +0000563
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000564 if (facs == NULL) {
565 printk_debug("No FACS found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +0000566 return NULL;
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000567 }
Rudolf Marek33cafe52009-04-13 18:07:02 +0000568
569 printk_debug("FACS found at %p\n", facs);
570 wake_vec = (void *) facs->firmware_waking_vector;
571 printk_debug("OS waking vector is %p\n", wake_vec);
572 return wake_vec;
573}
574
575extern char *lowmem_backup;
576extern char *lowmem_backup_ptr;
577extern int lowmem_backup_size;
578
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000579#define WAKEUP_BASE 0x600
580
581void (*acpi_do_wakeup)(u32 vector, u32 backup_source, u32 backup_target, u32
582 backup_size) __attribute__((regparm(0))) = (void *)WAKEUP_BASE;
583
584extern unsigned char __wakeup, __wakeup_size;
585
Rudolf Marek33cafe52009-04-13 18:07:02 +0000586void acpi_jump_to_wakeup(void *vector)
587{
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000588 u32 acpi_backup_memory = (u32) cbmem_find(CBMEM_ID_RESUME);
589
590 if (!acpi_backup_memory) {
591 printk(BIOS_WARNING, "ACPI: Backup memory missing. No S3 Resume.\n");
592 return;
593 }
594
595 // FIXME this should go into the ACPI backup memory, too. No pork saussages.
Rudolf Marek33cafe52009-04-13 18:07:02 +0000596 /* just restore the SMP trampoline and continue with wakeup on assembly level */
597 memcpy(lowmem_backup_ptr, lowmem_backup, lowmem_backup_size);
Stefan Reinauerc0ac7e92009-11-10 22:17:15 +0000598
599 /* copy wakeup trampoline in place */
600 memcpy(WAKEUP_BASE, &__wakeup, &__wakeup_size);
601
602 acpi_do_wakeup((u32)vector, acpi_backup_memory, CONFIG_RAMBASE, HIGH_MEMORY_SAVE);
Rudolf Marek33cafe52009-04-13 18:07:02 +0000603}
604#endif