blob: 515976636d02c4a8170302fee50a36e4cc1b158c [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 Reinauere30042d2005-02-08 09:11:40 +000021 * See AMD Solo, Island Aruma or Via Epia-M port for more details.
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000022 */
Stefan Reinauer688b3852004-01-28 16:56:14 +000023
24#include <console/console.h>
25#include <string.h>
26#include <arch/acpi.h>
Rudolf Marek293b5f52009-02-01 18:35:15 +000027#include <arch/acpigen.h>
Stefan Reinauer777224c2005-01-19 14:06:41 +000028#include <device/pci.h>
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000029
30u8 acpi_checksum(u8 *table, u32 length)
Stefan Reinauer688b3852004-01-28 16:56:14 +000031{
32 u8 ret=0;
33 while (length--) {
34 ret += *table;
35 table++;
36 }
Stefan Reinauera7648c22004-01-29 17:31:34 +000037 return -ret;
Stefan Reinauer688b3852004-01-28 16:56:14 +000038}
39
Stefan Reinauer06feb882004-02-03 16:11:35 +000040/*
41 * add an acpi table to rsdt structure, and recalculate checksum
42 */
43
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000044void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
Stefan Reinauer688b3852004-01-28 16:56:14 +000045{
46 int i;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000047 acpi_rsdt_t *rsdt;
48 acpi_xsdt_t *xsdt = NULL;
49
50 rsdt = (acpi_rsdt_t *)rsdp->rsdt_address;
51 if (rsdp->xsdt_address) {
52 xsdt = (acpi_xsdt_t *)((u32)rsdp->xsdt_address);
53 }
Stefan Reinauerf622d592005-11-26 16:56:05 +000054
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +000055 int entries_num = ARRAY_SIZE(rsdt->entry);
Stefan Reinauerf622d592005-11-26 16:56:05 +000056
57 for (i=0; i<entries_num; i++) {
Stefan Reinauer688b3852004-01-28 16:56:14 +000058 if(rsdt->entry[i]==0) {
59 rsdt->entry[i]=(u32)table;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000060 /* fix length to stop kernel whining about invalid entries */
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +000061 rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i+1));
Stefan Reinauer688b3852004-01-28 16:56:14 +000062 /* fix checksum */
63 /* hope this won't get optimized away */
64 rsdt->header.checksum=0;
65 rsdt->header.checksum=acpi_checksum((u8 *)rsdt,
66 rsdt->header.length);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000067
68 /* And now the same thing for the XSDT. We use the same
69 * index as we want the XSDT and RSDT to always be in
70 * sync in coreboot.
71 */
72 if (xsdt) {
73 xsdt->entry[i]=(u64)(u32)table;
74 xsdt->header.length = sizeof(acpi_header_t) +
75 (sizeof(u64) * (i+1));
76 xsdt->header.checksum=0;
77 xsdt->header.checksum=acpi_checksum((u8 *)xsdt,
78 xsdt->header.length);
79 }
Stefan Reinauer688b3852004-01-28 16:56:14 +000080
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000081 printk_debug("ACPI: added table %d/%d Length now %d\n",
82 i+1, entries_num, rsdt->header.length);
Stefan Reinauer688b3852004-01-28 16:56:14 +000083 return;
84 }
85 }
86
Stefan Reinauerb657a3c2009-07-21 21:38:33 +000087 printk_err("ACPI: Error: Could not add ACPI table, too many tables.\n");
Stefan Reinauer688b3852004-01-28 16:56:14 +000088}
89
Stefan Reinauer26d431a2009-01-20 19:17:51 +000090int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base, u16 seg_nr, u8 start, u8 end)
91{
Rudolf Mareke6409f22007-11-03 12:50:26 +000092 mmconfig->base_address = base;
93 mmconfig->base_reserved = 0;
94 mmconfig->pci_segment_group_number = seg_nr;
95 mmconfig->start_bus_number = start;
96 mmconfig->end_bus_number = end;
97 return (sizeof(acpi_mcfg_mmconfig_t));
98}
99
Stefan Reinauer777224c2005-01-19 14:06:41 +0000100int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000101{
102 lapic->type=0;
103 lapic->length=sizeof(acpi_madt_lapic_t);
104 lapic->flags=1;
105
106 lapic->processor_id=cpu;
107 lapic->apic_id=apic;
108
109 return(lapic->length);
110}
111
Stefan Reinauerda65fbf2009-04-22 08:18:37 +0000112unsigned long acpi_create_madt_lapics(unsigned long current)
113{
114 device_t cpu;
115 int cpu_index = 0;
116
117 for(cpu = all_devices; cpu; cpu = cpu->next) {
118 if ((cpu->path.type != DEVICE_PATH_APIC) ||
119 (cpu->bus->dev->path.type != DEVICE_PATH_APIC_CLUSTER)) {
120 continue;
121 }
122 if (!cpu->enabled) {
123 continue;
124 }
125 current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, cpu_index, cpu->path.apic.apic_id);
126 cpu_index++;
127 }
128 return current;
129}
130
Stefan Reinauer777224c2005-01-19 14:06:41 +0000131int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr,u32 gsi_base)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000132{
133 ioapic->type=1;
134 ioapic->length=sizeof(acpi_madt_ioapic_t);
135 ioapic->reserved=0x00;
Stefan Reinauer777224c2005-01-19 14:06:41 +0000136 ioapic->gsi_base=gsi_base;
Stefan Reinauer06feb882004-02-03 16:11:35 +0000137
138 ioapic->ioapic_id=id;
139 ioapic->ioapic_addr=addr;
140
141 return(ioapic->length);
142}
143
Stefan Reinauer777224c2005-01-19 14:06:41 +0000144int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride,
Stefan Reinauer06feb882004-02-03 16:11:35 +0000145 u8 bus, u8 source, u32 gsirq, u16 flags)
146{
147 irqoverride->type=2;
148 irqoverride->length=sizeof(acpi_madt_irqoverride_t);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000149 irqoverride->bus=bus;
150 irqoverride->source=source;
151 irqoverride->gsirq=gsirq;
152 irqoverride->flags=flags;
153
154 return(irqoverride->length);
155}
156
Stefan Reinauer777224c2005-01-19 14:06:41 +0000157int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu,
Stefan Reinauer06feb882004-02-03 16:11:35 +0000158 u16 flags, u8 lint)
159{
160 lapic_nmi->type=4;
161 lapic_nmi->length=sizeof(acpi_madt_lapic_nmi_t);
162
163 lapic_nmi->flags=flags;
164 lapic_nmi->processor_id=cpu;
165 lapic_nmi->lint=lint;
166
167 return(lapic_nmi->length);
168}
169
Stefan Reinauer777224c2005-01-19 14:06:41 +0000170void acpi_create_madt(acpi_madt_t *madt)
Stefan Reinauer06feb882004-02-03 16:11:35 +0000171{
172#define LOCAL_APIC_ADDR 0xfee00000ULL
Stefan Reinauer777224c2005-01-19 14:06:41 +0000173
Stefan Reinauer06feb882004-02-03 16:11:35 +0000174 acpi_header_t *header=&(madt->header);
175 unsigned long current=(unsigned long)madt+sizeof(acpi_madt_t);
176
177 memset((void *)madt, 0, sizeof(acpi_madt_t));
178
179 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000180 memcpy(header->signature, "APIC", 4);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000181 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000182 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer06feb882004-02-03 16:11:35 +0000183 memcpy(header->asl_compiler_id, ASLC, 4);
184
185 header->length = sizeof(acpi_madt_t);
186 header->revision = 1;
187
188 madt->lapic_addr= LOCAL_APIC_ADDR;
189 madt->flags = 0x1; /* PCAT_COMPAT */
Stefan Reinauer06feb882004-02-03 16:11:35 +0000190
Stefan Reinauerf622d592005-11-26 16:56:05 +0000191 current = acpi_fill_madt(current);
Stefan Reinauer777224c2005-01-19 14:06:41 +0000192
Stefan Reinauer06feb882004-02-03 16:11:35 +0000193 /* recalculate length */
194 header->length= current - (unsigned long)madt;
195
196 header->checksum = acpi_checksum((void *)madt, header->length);
197}
198
Rudolf Mareke6409f22007-11-03 12:50:26 +0000199void acpi_create_mcfg(acpi_mcfg_t *mcfg)
200{
201
202 acpi_header_t *header=&(mcfg->header);
203 unsigned long current=(unsigned long)mcfg+sizeof(acpi_mcfg_t);
204
205 memset((void *)mcfg, 0, sizeof(acpi_mcfg_t));
206
207 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000208 memcpy(header->signature, "MCFG", 4);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000209 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000210 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Rudolf Mareke6409f22007-11-03 12:50:26 +0000211 memcpy(header->asl_compiler_id, ASLC, 4);
212
213 header->length = sizeof(acpi_mcfg_t);
214 header->revision = 1;
215
216 current = acpi_fill_mcfg(current);
217
218 /* recalculate length */
219 header->length= current - (unsigned long)mcfg;
220
221 header->checksum = acpi_checksum((void *)mcfg, header->length);
222}
223
Rudolf Marek293b5f52009-02-01 18:35:15 +0000224/* this can be overriden by platform ACPI setup code,
225 if it calls acpi_create_ssdt_generator */
226unsigned long __attribute__((weak)) acpi_fill_ssdt_generator(unsigned long current,
227 char *oem_table_id) {
228 return current;
229}
230
231void acpi_create_ssdt_generator(acpi_header_t *ssdt, char *oem_table_id)
232{
233 unsigned long current=(unsigned long)ssdt+sizeof(acpi_header_t);
234 memset((void *)ssdt, 0, sizeof(acpi_header_t));
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000235 memcpy(&ssdt->signature, "SSDT", 4);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000236 ssdt->revision = 2;
237 memcpy(&ssdt->oem_id, OEM_ID, 6);
238 memcpy(&ssdt->oem_table_id, oem_table_id, 8);
239 ssdt->oem_revision = 42;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000240 memcpy(&ssdt->asl_compiler_id, "CORE", 4);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000241 ssdt->asl_compiler_revision = 42;
242 ssdt->length = sizeof(acpi_header_t);
243
Stefan Reinauer8dcd50b2009-03-06 17:24:29 +0000244 acpigen_set_current((char *) current);
Rudolf Marek293b5f52009-02-01 18:35:15 +0000245 current = acpi_fill_ssdt_generator(current, oem_table_id);
246
247 /* recalculate length */
248 ssdt->length = current - (unsigned long)ssdt;
249 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
250}
251
Stefan Reinauerf622d592005-11-26 16:56:05 +0000252int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
253{
Myles Watson0b4c9f02009-03-10 18:06:47 +0000254 memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t));
Stefan Reinauerf622d592005-11-26 16:56:05 +0000255 lapic->type=0;
256 lapic->length=sizeof(acpi_srat_lapic_t);
257 lapic->flags=1;
258
259 lapic->proximity_domain_7_0 = node;
260 lapic->apic_id=apic;
261
262 return(lapic->length);
263}
264
265int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek,u32 sizek, u32 flags)
266{
267 mem->type=1;
268 mem->length=sizeof(acpi_srat_mem_t);
269
270 mem->base_address_low = (basek<<10);
271 mem->base_address_high = (basek>>(32-10));
272
273 mem->length_low = (sizek<<10);
274 mem->length_high = (sizek>>(32-10));
275
276 mem->proximity_domain = node;
277
278 mem->flags = flags;
279
280 return(mem->length);
281}
282
283void acpi_create_srat(acpi_srat_t *srat)
284{
285
286 acpi_header_t *header=&(srat->header);
287 unsigned long current=(unsigned long)srat+sizeof(acpi_srat_t);
288
289 memset((void *)srat, 0, sizeof(acpi_srat_t));
290
291 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000292 memcpy(header->signature, "SRAT", 4);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000293 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000294 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauerf622d592005-11-26 16:56:05 +0000295 memcpy(header->asl_compiler_id, ASLC, 4);
296
297 header->length = sizeof(acpi_srat_t);
298 header->revision = 1;
299
300 srat->resv = 0x1; /* BACK COMP */
301
302 current = acpi_fill_srat(current);
303
304 /* recalculate length */
305 header->length= current - (unsigned long)srat;
306
307 header->checksum = acpi_checksum((void *)srat, header->length);
308}
309
Yinghai Lud4b278c2006-10-04 20:46:15 +0000310void acpi_create_slit(acpi_slit_t *slit)
311{
312
313 acpi_header_t *header=&(slit->header);
314 unsigned long current=(unsigned long)slit+sizeof(acpi_slit_t);
315
316 memset((void *)slit, 0, sizeof(acpi_slit_t));
317
318 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000319 memcpy(header->signature, "SLIT", 4);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000320 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000321 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000322 memcpy(header->asl_compiler_id, ASLC, 4);
323
324 header->length = sizeof(acpi_slit_t);
325 header->revision = 1;
326
Myles Watson0b4c9f02009-03-10 18:06:47 +0000327 current = acpi_fill_slit(current);
Yinghai Lud4b278c2006-10-04 20:46:15 +0000328
329 /* recalculate length */
330 header->length= current - (unsigned long)slit;
331
332 header->checksum = acpi_checksum((void *)slit, header->length);
333}
334
Stefan Reinauer777224c2005-01-19 14:06:41 +0000335void acpi_create_hpet(acpi_hpet_t *hpet)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000336{
337#define HPET_ADDR 0xfed00000ULL
338 acpi_header_t *header=&(hpet->header);
339 acpi_addr_t *addr=&(hpet->addr);
340
Stefan Reinauera7648c22004-01-29 17:31:34 +0000341 memset((void *)hpet, 0, sizeof(acpi_hpet_t));
342
Stefan Reinauer688b3852004-01-28 16:56:14 +0000343 /* fill out header fields */
344 memcpy(header->signature, HPET_NAME, 4);
345 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000346 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000347 memcpy(header->asl_compiler_id, ASLC, 4);
348
349 header->length = sizeof(acpi_hpet_t);
350 header->revision = 1;
351
352 /* fill out HPET address */
353 addr->space_id = 0; /* Memory */
354 addr->bit_width = 64;
355 addr->bit_offset = 0;
356 addr->addrl = HPET_ADDR & 0xffffffff;
357 addr->addrh = HPET_ADDR >> 32;
358
359 hpet->id = 0x102282a0; /* AMD ? */
360 hpet->number = 0;
361 hpet->min_tick = 4096;
362
Stefan Reinauera7648c22004-01-29 17:31:34 +0000363 header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000364}
Stefan Reinauer777224c2005-01-19 14:06:41 +0000365void acpi_create_facs(acpi_facs_t *facs)
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000366{
Rudolf Marek33cafe52009-04-13 18:07:02 +0000367
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000368 memset( (void *)facs,0, sizeof(acpi_facs_t));
369
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000370 memcpy(facs->signature, "FACS", 4);
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000371 facs->length = sizeof(acpi_facs_t);
372 facs->hardware_signature = 0;
373 facs->firmware_waking_vector = 0;
374 facs->global_lock = 0;
375 facs->flags = 0;
376 facs->x_firmware_waking_vector_l = 0;
377 facs->x_firmware_waking_vector_h = 0;
378 facs->version = 1;
Ronald G. Minnich02fa3b22004-10-06 17:33:54 +0000379}
Stefan Reinauer777224c2005-01-19 14:06:41 +0000380
381void acpi_write_rsdt(acpi_rsdt_t *rsdt)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000382{
383 acpi_header_t *header=&(rsdt->header);
384
385 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000386 memcpy(header->signature, "RSDT", 4);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000387 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000388 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000389 memcpy(header->asl_compiler_id, ASLC, 4);
390
391 header->length = sizeof(acpi_rsdt_t);
392 header->revision = 1;
393
394 /* fill out entries */
395
396 // entries are filled in later, we come with an empty set.
397
398 /* fix checksum */
399
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000400 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000401}
402
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000403void acpi_write_xsdt(acpi_xsdt_t *xsdt)
404{
405 acpi_header_t *header=&(xsdt->header);
406
407 /* fill out header fields */
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000408 memcpy(header->signature, "XSDT", 4);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000409 memcpy(header->oem_id, OEM_ID, 6);
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000410 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000411 memcpy(header->asl_compiler_id, ASLC, 4);
412
413 header->length = sizeof(acpi_xsdt_t);
414 header->revision = 1;
415
416 /* fill out entries */
417
418 // entries are filled in later, we come with an empty set.
419
420 /* fix checksum */
421
422 header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t));
423}
424
425void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt, acpi_xsdt_t *xsdt)
Stefan Reinauer688b3852004-01-28 16:56:14 +0000426{
427 memcpy(rsdp->signature, RSDP_SIG, 8);
428 memcpy(rsdp->oem_id, OEM_ID, 6);
Stefan Reinauer688b3852004-01-28 16:56:14 +0000429 rsdp->length = sizeof(acpi_rsdp_t);
430 rsdp->rsdt_address = (u32)rsdt;
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000431 /* Some OSes expect an XSDT to be present for RSD PTR
432 * revisions >= 2. If we don't have an ACPI XSDT, force
433 * ACPI 1.0 (and thus RSD PTR revision 0)
434 */
435 if (xsdt == NULL) {
436 rsdp->revision = 0;
437 } else {
438 rsdp->xsdt_address = (u64)(u32)xsdt;
439 rsdp->revision = 2;
440 }
Stefan Reinauera7648c22004-01-29 17:31:34 +0000441 rsdp->checksum = acpi_checksum((void *)rsdp, 20);
442 rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
Stefan Reinauer688b3852004-01-28 16:56:14 +0000443}
444
Stefan Reinauer08670622009-06-30 15:17:49 +0000445#if CONFIG_HAVE_ACPI_RESUME == 1
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000446void suspend_resume(void)
447{
448 void *wake_vec;
449
450#if 0
Stefan Reinauer08670622009-06-30 15:17:49 +0000451#if CONFIG_MEM_TRAIN_SEQ != 0
452 #error "So far it works on AMD and CONFIG_MEM_TRAIN_SEQ == 0"
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000453#endif
454
Stefan Reinauer08670622009-06-30 15:17:49 +0000455#if CONFIG_RAMBASE < 0x1F00000
456 #error "For ACPI RESUME you need to have CONFIG_RAMBASE at least 31MB"
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000457 #error "Chipset support (S3_NVRAM_EARLY and ACPI_IS_WAKEUP_EARLY functions and memory ctrl)"
458 #error "And coreboot memory reserved in mainboard.c"
459#endif
460#endif
461 /* if we happen to be resuming find wakeup vector and jump to OS */
462 wake_vec = acpi_find_wakeup_vector();
463 if (wake_vec)
464 acpi_jump_to_wakeup(wake_vec);
465}
466
467/* this is to be filled by SB code - startup value what was found */
468u8 acpi_slp_type = 0;
Stefan Reinauer688b3852004-01-28 16:56:14 +0000469
Rudolf Marek33cafe52009-04-13 18:07:02 +0000470int acpi_is_wakeup(void)
471{
472 return (acpi_slp_type == 3);
473}
474
475static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
476{
477 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
478 return NULL;
479
480 printk_debug("Looking on %p for valid checksum\n", rsdp);
481
482 if (acpi_checksum((void *)rsdp, 20) != 0)
483 return NULL;
484 printk_debug("Checksum 1 passed\n");
485
486 if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
487 rsdp->length) != 0))
488 return NULL;
489
490 printk_debug("Checksum 2 passed all OK\n");
491
492 return rsdp;
493}
494
495static acpi_rsdp_t *rsdp;
496
497void *acpi_get_wakeup_rsdp(void)
498{
499 return rsdp;
500}
501
502void *acpi_find_wakeup_vector(void)
503{
504 char *p, *end;
505
506 acpi_rsdt_t *rsdt;
507 acpi_facs_t *facs;
508 acpi_fadt_t *fadt;
509 void *wake_vec;
510 int i;
511
512 rsdp = NULL;
513
514 if (!acpi_is_wakeup())
515 return NULL;
516
517 printk_debug("Trying to find the wakeup vector ...\n");
518
519 /* find RSDP */
520 for (p = (char *) 0xe0000; p < (char *) 0xfffff; p+=16) {
521 if ((rsdp = valid_rsdp((acpi_rsdp_t *) p)))
522 break;
523 }
524
525 if (rsdp == NULL)
526 return NULL;
527
528 printk_debug("RSDP found at %p\n", rsdp);
529 rsdt = (acpi_rsdt_t *) rsdp->rsdt_address;
530
531 end = (char *) rsdt + rsdt->header.length;
532 printk_debug("RSDT found at %p ends at %p\n", rsdt, end);
533
534 for (i = 0; ((char *) &rsdt->entry[i]) < end; i++) {
535 fadt = (acpi_fadt_t *) rsdt->entry[i];
Stefan Reinauercdfe3762009-07-21 22:15:43 +0000536 if (strncmp((char *)fadt, "FACP", 4) == 0)
Rudolf Marek33cafe52009-04-13 18:07:02 +0000537 break;
538 fadt = NULL;
539 }
540
541 if (fadt == NULL)
542 return NULL;
543
544 printk_debug("FADT found at %p\n", fadt);
Stefan Reinauer69390db2009-05-26 12:33:52 +0000545 facs = (acpi_facs_t *)fadt->firmware_ctrl;
Rudolf Marek33cafe52009-04-13 18:07:02 +0000546
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000547 if (facs == NULL) {
548 printk_debug("No FACS found, wake up from S3 not possible.\n");
Rudolf Marek33cafe52009-04-13 18:07:02 +0000549 return NULL;
Stefan Reinauer7e9771c2009-04-22 08:17:38 +0000550 }
Rudolf Marek33cafe52009-04-13 18:07:02 +0000551
552 printk_debug("FACS found at %p\n", facs);
553 wake_vec = (void *) facs->firmware_waking_vector;
554 printk_debug("OS waking vector is %p\n", wake_vec);
555 return wake_vec;
556}
557
558extern char *lowmem_backup;
559extern char *lowmem_backup_ptr;
560extern int lowmem_backup_size;
561
562void acpi_jump_to_wakeup(void *vector)
563{
564 /* just restore the SMP trampoline and continue with wakeup on assembly level */
565 memcpy(lowmem_backup_ptr, lowmem_backup, lowmem_backup_size);
566 acpi_jmp_to_realm_wakeup((u32) vector);
567}
568#endif