coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
acpi.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * coreboot ACPI Table support
4  */
5 
6 /*
7  * Each system port implementing ACPI has to provide two functions:
8  *
9  * write_acpi_tables()
10  * acpi_dump_apics()
11  *
12  * See Kontron 986LCD-M port for a good example of an ACPI implementation
13  * in coreboot.
14  */
15 
16 #include <acpi/acpi.h>
17 #include <acpi/acpi_ivrs.h>
18 #include <acpi/acpigen.h>
19 #include <arch/hpet.h>
20 #include <cbfs.h>
21 #include <cbmem.h>
22 #include <commonlib/helpers.h>
23 #include <commonlib/sort.h>
24 #include <console/console.h>
25 #include <cpu/cpu.h>
26 #include <device/mmio.h>
27 #include <device/pci.h>
28 #include <pc80/mc146818rtc.h>
29 #include <string.h>
30 #include <types.h>
31 #include <version.h>
32 
33 static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp);
34 
36 {
37  u8 ret = 0;
38  while (length--) {
39  ret += *table;
40  table++;
41  }
42  return -ret;
43 }
44 
45 /**
46  * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length
47  * and checksum.
48  */
49 void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
50 {
51  int i, entries_num;
52  acpi_rsdt_t *rsdt;
53  acpi_xsdt_t *xsdt = NULL;
54 
55  /* The RSDT is mandatory... */
56  rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
57 
58  /* ...while the XSDT is not. */
59  if (rsdp->xsdt_address)
60  xsdt = (acpi_xsdt_t *)((uintptr_t)rsdp->xsdt_address);
61 
62  /* This should always be MAX_ACPI_TABLES. */
63  entries_num = ARRAY_SIZE(rsdt->entry);
64 
65  for (i = 0; i < entries_num; i++) {
66  if (rsdt->entry[i] == 0)
67  break;
68  }
69 
70  if (i >= entries_num) {
71  printk(BIOS_ERR, "ACPI: Error: Could not add ACPI table, "
72  "too many tables.\n");
73  return;
74  }
75 
76  /* Add table to the RSDT. */
77  rsdt->entry[i] = (uintptr_t)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, rsdt->header.length);
85 
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)(uintptr_t)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(BIOS_DEBUG, "ACPI: added table %d/%d, length now %d\n",
105  i + 1, entries_num, rsdt->header.length);
106 }
107 
109  u16 seg_nr, u8 start, u8 end)
110 {
111  memset(mmconfig, 0, sizeof(*mmconfig));
112  mmconfig->base_address = base;
113  mmconfig->base_reserved = 0;
114  mmconfig->pci_segment_group_number = seg_nr;
115  mmconfig->start_bus_number = start;
116  mmconfig->end_bus_number = end;
117 
118  return sizeof(acpi_mcfg_mmconfig_t);
119 }
120 
122 {
123  lapic->type = LOCAL_APIC; /* Local APIC structure */
124  lapic->length = sizeof(acpi_madt_lapic_t);
125  lapic->flags = (1 << 0); /* Processor/LAPIC enabled */
126  lapic->processor_id = cpu;
127  lapic->apic_id = apic;
128 
129  return lapic->length;
130 }
131 
133 {
134  lapic->type = LOCAL_X2APIC; /* Local APIC structure */
135  lapic->reserved = 0;
136  lapic->length = sizeof(acpi_madt_lx2apic_t);
137  lapic->flags = (1 << 0); /* Processor/LAPIC enabled */
138  lapic->processor_id = cpu;
139  lapic->x2apic_id = apic;
140 
141  return lapic->length;
142 }
143 
144 unsigned long acpi_create_madt_lapics(unsigned long current)
145 {
146  struct device *cpu;
147  int index, apic_ids[CONFIG_MAX_CPUS] = {0}, num_cpus = 0;
148 
149  for (cpu = all_devices; cpu; cpu = cpu->next) {
150  if ((cpu->path.type != DEVICE_PATH_APIC) ||
151  (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) {
152  continue;
153  }
154  if (!cpu->enabled)
155  continue;
156  if (num_cpus >= ARRAY_SIZE(apic_ids))
157  break;
158  apic_ids[num_cpus++] = cpu->path.apic.apic_id;
159  }
160  if (num_cpus > 1)
161  bubblesort(apic_ids, num_cpus, NUM_ASCENDING);
162  for (index = 0; index < num_cpus; index++) {
163  if (apic_ids[index] < 0xff)
164  current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current,
165  index, apic_ids[index]);
166  else
167  current += acpi_create_madt_lx2apic((acpi_madt_lx2apic_t *)current,
168  index, apic_ids[index]);
169  }
170 
171  return current;
172 }
173 
175  u32 gsi_base)
176 {
177  ioapic->type = IO_APIC; /* I/O APIC structure */
178  ioapic->length = sizeof(acpi_madt_ioapic_t);
179  ioapic->reserved = 0x00;
180  ioapic->gsi_base = gsi_base;
181  ioapic->ioapic_id = id;
182  ioapic->ioapic_addr = addr;
183 
184  return ioapic->length;
185 }
186 
188  u8 bus, u8 source, u32 gsirq, u16 flags)
189 {
190  irqoverride->type = IRQ_SOURCE_OVERRIDE; /* Interrupt source override */
191  irqoverride->length = sizeof(acpi_madt_irqoverride_t);
192  irqoverride->bus = bus;
193  irqoverride->source = source;
194  irqoverride->gsirq = gsirq;
195  irqoverride->flags = flags;
196 
197  return irqoverride->length;
198 }
199 
201  u16 flags, u8 lint)
202 {
203  lapic_nmi->type = LOCAL_APIC_NMI; /* Local APIC NMI structure */
204  lapic_nmi->length = sizeof(acpi_madt_lapic_nmi_t);
205  lapic_nmi->flags = flags;
206  lapic_nmi->processor_id = cpu;
207  lapic_nmi->lint = lint;
208 
209  return lapic_nmi->length;
210 }
211 
213  u16 flags, u8 lint)
214 {
215  lapic_nmi->type = LOCAL_X2APIC_NMI; /* Local APIC NMI structure */
216  lapic_nmi->length = sizeof(acpi_madt_lx2apic_nmi_t);
217  lapic_nmi->flags = flags;
218  lapic_nmi->processor_id = cpu;
219  lapic_nmi->lint = lint;
220  lapic_nmi->reserved[0] = 0;
221  lapic_nmi->reserved[1] = 0;
222  lapic_nmi->reserved[2] = 0;
223 
224  return lapic_nmi->length;
225 }
226 
228 {
229  acpi_header_t *header = &(madt->header);
230  unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t);
231 
232  memset((void *)madt, 0, sizeof(acpi_madt_t));
233 
234  if (!header)
235  return;
236 
237  /* Fill out header fields. */
238  memcpy(header->signature, "APIC", 4);
239  memcpy(header->oem_id, OEM_ID, 6);
240  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
241  memcpy(header->asl_compiler_id, ASLC, 4);
242 
243  header->asl_compiler_revision = asl_revision;
244  header->length = sizeof(acpi_madt_t);
245  header->revision = get_acpi_table_revision(MADT);
246 
247  madt->lapic_addr = cpu_get_lapic_addr();
248  if (CONFIG(ACPI_HAVE_PCAT_8259))
249  madt->flags |= 1;
250 
251  current = acpi_fill_madt(current);
252 
253  /* (Re)calculate length and checksum. */
254  header->length = current - (unsigned long)madt;
255 
256  header->checksum = acpi_checksum((void *)madt, header->length);
257 }
258 
259 static unsigned long acpi_fill_mcfg(unsigned long current)
260 {
261  current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
262  CONFIG_ECAM_MMCONF_BASE_ADDRESS, 0, 0,
263  CONFIG_ECAM_MMCONF_BUS_NUMBER - 1);
264  return current;
265 }
266 
267 /* MCFG is defined in the PCI Firmware Specification 3.0. */
269 {
270  acpi_header_t *header = &(mcfg->header);
271  unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t);
272 
273  memset((void *)mcfg, 0, sizeof(acpi_mcfg_t));
274 
275  if (!header)
276  return;
277 
278  /* Fill out header fields. */
279  memcpy(header->signature, "MCFG", 4);
280  memcpy(header->oem_id, OEM_ID, 6);
281  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
282  memcpy(header->asl_compiler_id, ASLC, 4);
283 
284  header->asl_compiler_revision = asl_revision;
285  header->length = sizeof(acpi_mcfg_t);
286  header->revision = get_acpi_table_revision(MCFG);
287 
288  if (CONFIG(ECAM_MMCONF_SUPPORT))
289  current = acpi_fill_mcfg(current);
290 
291  /* (Re)calculate length and checksum. */
292  header->length = current - (unsigned long)mcfg;
293  header->checksum = acpi_checksum((void *)mcfg, header->length);
294 }
295 
296 static void *get_tcpa_log(u32 *size)
297 {
298  const struct cbmem_entry *ce;
299  const u32 tcpa_default_log_len = 0x10000;
300  void *lasa;
302  if (ce) {
303  lasa = cbmem_entry_start(ce);
304  *size = cbmem_entry_size(ce);
305  printk(BIOS_DEBUG, "TCPA log found at %p\n", lasa);
306  return lasa;
307  }
308  lasa = cbmem_add(CBMEM_ID_TCPA_TCG_LOG, tcpa_default_log_len);
309  if (!lasa) {
310  printk(BIOS_ERR, "TCPA log creation failed\n");
311  return NULL;
312  }
313 
314  printk(BIOS_DEBUG, "TCPA log created at %p\n", lasa);
315  memset(lasa, 0, tcpa_default_log_len);
316 
317  *size = tcpa_default_log_len;
318  return lasa;
319 }
320 
321 static void acpi_create_tcpa(acpi_tcpa_t *tcpa)
322 {
323  acpi_header_t *header = &(tcpa->header);
324  u32 tcpa_log_len;
325  void *lasa;
326 
327  memset((void *)tcpa, 0, sizeof(acpi_tcpa_t));
328 
329  lasa = get_tcpa_log(&tcpa_log_len);
330  if (!lasa)
331  return;
332 
333  if (!header)
334  return;
335 
336  /* Fill out header fields. */
337  memcpy(header->signature, "TCPA", 4);
338  memcpy(header->oem_id, OEM_ID, 6);
339  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
340  memcpy(header->asl_compiler_id, ASLC, 4);
341 
342  header->asl_compiler_revision = asl_revision;
343  header->length = sizeof(acpi_tcpa_t);
344  header->revision = get_acpi_table_revision(TCPA);
345 
346  tcpa->platform_class = 0;
347  tcpa->laml = tcpa_log_len;
348  tcpa->lasa = (uintptr_t) lasa;
349 
350  /* Calculate checksum. */
351  header->checksum = acpi_checksum((void *)tcpa, header->length);
352 }
353 
354 static void *get_tpm2_log(u32 *size)
355 {
356  const struct cbmem_entry *ce;
357  const u32 tpm2_default_log_len = 0x10000;
358  void *lasa;
360  if (ce) {
361  lasa = cbmem_entry_start(ce);
362  *size = cbmem_entry_size(ce);
363  printk(BIOS_DEBUG, "TPM2 log found at %p\n", lasa);
364  return lasa;
365  }
366  lasa = cbmem_add(CBMEM_ID_TPM2_TCG_LOG, tpm2_default_log_len);
367  if (!lasa) {
368  printk(BIOS_ERR, "TPM2 log creation failed\n");
369  return NULL;
370  }
371 
372  printk(BIOS_DEBUG, "TPM2 log created at %p\n", lasa);
373  memset(lasa, 0, tpm2_default_log_len);
374 
375  *size = tpm2_default_log_len;
376  return lasa;
377 }
378 
379 static void acpi_create_tpm2(acpi_tpm2_t *tpm2)
380 {
381  acpi_header_t *header = &(tpm2->header);
382  u32 tpm2_log_len;
383  void *lasa;
384 
385  memset((void *)tpm2, 0, sizeof(acpi_tpm2_t));
386 
387  /*
388  * Some payloads like SeaBIOS depend on log area to use TPM2.
389  * Get the memory size and address of TPM2 log area or initialize it.
390  */
391  lasa = get_tpm2_log(&tpm2_log_len);
392  if (!lasa)
393  tpm2_log_len = 0;
394 
395  if (!header)
396  return;
397 
398  /* Fill out header fields. */
399  memcpy(header->signature, "TPM2", 4);
400  memcpy(header->oem_id, OEM_ID, 6);
401  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
402  memcpy(header->asl_compiler_id, ASLC, 4);
403 
404  header->asl_compiler_revision = asl_revision;
405  header->length = sizeof(acpi_tpm2_t);
406  header->revision = get_acpi_table_revision(TPM2);
407 
408  /* Hard to detect for coreboot. Just set it to 0 */
409  tpm2->platform_class = 0;
410  if (CONFIG(CRB_TPM)) {
411  /* Must be set to 7 for CRB Support */
412  tpm2->control_area = CONFIG_CRB_TPM_BASE_ADDRESS + 0x40;
413  tpm2->start_method = 7;
414  } else {
415  /* Must be set to 0 for FIFO interface support */
416  tpm2->control_area = 0;
417  tpm2->start_method = 6;
418  }
419  memset(tpm2->msp, 0, sizeof(tpm2->msp));
420 
421  /* Fill the log area size and start address fields. */
422  tpm2->laml = tpm2_log_len;
423  tpm2->lasa = (uintptr_t) lasa;
424 
425  /* Calculate checksum. */
426  header->checksum = acpi_checksum((void *)tpm2, header->length);
427 }
428 
429 static void acpi_ssdt_write_cbtable(void)
430 {
431  const struct cbmem_entry *cbtable;
432  uintptr_t base;
433  uint32_t size;
434 
436  if (!cbtable)
437  return;
438  base = (uintptr_t)cbmem_entry_start(cbtable);
439  size = cbmem_entry_size(cbtable);
440 
441  acpigen_write_device("CTBL");
443  acpigen_write_name_integer("_UID", 0);
445  acpigen_write_name("_CRS");
447  acpigen_write_mem32fixed(0, base, size);
449  acpigen_pop_len();
450 }
451 
452 void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
453 {
454  unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t);
455 
456  memset((void *)ssdt, 0, sizeof(acpi_header_t));
457 
458  memcpy(&ssdt->signature, "SSDT", 4);
460  memcpy(&ssdt->oem_id, OEM_ID, 6);
461  memcpy(&ssdt->oem_table_id, oem_table_id, 8);
462  ssdt->oem_revision = 42;
463  memcpy(&ssdt->asl_compiler_id, ASLC, 4);
465  ssdt->length = sizeof(acpi_header_t);
466 
467  acpigen_set_current((char *) current);
468 
469  /* Write object to declare coreboot tables */
471 
472  {
473  struct device *dev;
474  for (dev = all_devices; dev; dev = dev->next)
475  if (dev->enabled && dev->ops && dev->ops->acpi_fill_ssdt)
476  dev->ops->acpi_fill_ssdt(dev);
477  current = (unsigned long) acpigen_get_current();
478  }
479 
480  /* (Re)calculate length and checksum. */
481  ssdt->length = current - (unsigned long)ssdt;
482  ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
483 }
484 
486 {
487  memset((void *)lapic, 0, sizeof(acpi_srat_lapic_t));
488 
489  lapic->type = 0; /* Processor local APIC/SAPIC affinity structure */
490  lapic->length = sizeof(acpi_srat_lapic_t);
491  lapic->flags = (1 << 0); /* Enabled (the use of this structure). */
492  lapic->proximity_domain_7_0 = node;
493  /* TODO: proximity_domain_31_8, local SAPIC EID, clock domain. */
494  lapic->apic_id = apic;
495 
496  return lapic->length;
497 }
498 
499 int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
500  u32 flags)
501 {
502  mem->type = 1; /* Memory affinity structure */
503  mem->length = sizeof(acpi_srat_mem_t);
504  mem->base_address_low = (basek << 10);
505  mem->base_address_high = (basek >> (32 - 10));
506  mem->length_low = (sizek << 10);
507  mem->length_high = (sizek >> (32 - 10));
508  mem->proximity_domain = node;
509  mem->flags = flags;
510 
511  return mem->length;
512 }
513 
514 int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain,
515  u16 seg, u8 bus, u8 dev, u8 func, u32 flags)
516 {
518  gia->length = sizeof(acpi_srat_gia_t);
519  gia->proximity_domain = proximity_domain;
521  /* First two bytes has segment number */
522  memcpy(gia->dev_handle, &seg, 2);
523  gia->dev_handle[2] = bus; /* Byte 2 has bus number */
524  /* Byte 3 has bits 7:3 for dev, bits 2:0 for func */
525  gia->dev_handle[3] = PCI_SLOT(dev) | PCI_FUNC(func);
526  gia->flags = flags;
527 
528  return gia->length;
529 }
530 
531 /* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */
533  unsigned long (*acpi_fill_srat)(unsigned long current))
534 {
535  acpi_header_t *header = &(srat->header);
536  unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t);
537 
538  memset((void *)srat, 0, sizeof(acpi_srat_t));
539 
540  if (!header)
541  return;
542 
543  /* Fill out header fields. */
544  memcpy(header->signature, "SRAT", 4);
545  memcpy(header->oem_id, OEM_ID, 6);
546  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
547  memcpy(header->asl_compiler_id, ASLC, 4);
548 
549  header->asl_compiler_revision = asl_revision;
550  header->length = sizeof(acpi_srat_t);
551  header->revision = get_acpi_table_revision(SRAT);
552 
553  srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */
554 
555  current = acpi_fill_srat(current);
556 
557  /* (Re)calculate length and checksum. */
558  header->length = current - (unsigned long)srat;
559  header->checksum = acpi_checksum((void *)srat, header->length);
560 }
561 
563 {
564  memset((void *)mpda, 0, sizeof(acpi_hmat_mpda_t));
565 
566  mpda->type = 0; /* Memory Proximity Domain Attributes structure */
567  mpda->length = sizeof(acpi_hmat_mpda_t);
568  /*
569  * Proximity Domain for Attached Initiator field is valid.
570  * Bit 1 and bit 2 are reserved since HMAT revision 2.
571  */
572  mpda->flags = (1 << 0);
573  mpda->proximity_domain_initiator = initiator;
575 
576  return mpda->length;
577 }
578 
580  unsigned long (*acpi_fill_hmat)(unsigned long current))
581 {
582  acpi_header_t *header = &(hmat->header);
583  unsigned long current = (unsigned long)hmat + sizeof(acpi_hmat_t);
584 
585  memset((void *)hmat, 0, sizeof(acpi_hmat_t));
586 
587  if (!header)
588  return;
589 
590  /* Fill out header fields. */
591  memcpy(header->signature, "HMAT", 4);
592  memcpy(header->oem_id, OEM_ID, 6);
593  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
594  memcpy(header->asl_compiler_id, ASLC, 4);
595 
596  header->asl_compiler_revision = asl_revision;
597  header->length = sizeof(acpi_hmat_t);
598  header->revision = get_acpi_table_revision(HMAT);
599 
600  current = acpi_fill_hmat(current);
601 
602  /* (Re)calculate length and checksum. */
603  header->length = current - (unsigned long)hmat;
604  header->checksum = acpi_checksum((void *)hmat, header->length);
605 }
606 
607 void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags,
608  unsigned long (*acpi_fill_dmar)(unsigned long))
609 {
610  acpi_header_t *header = &(dmar->header);
611  unsigned long current = (unsigned long)dmar + sizeof(acpi_dmar_t);
612 
613  memset((void *)dmar, 0, sizeof(acpi_dmar_t));
614 
615  if (!header)
616  return;
617 
618  /* Fill out header fields. */
619  memcpy(header->signature, "DMAR", 4);
620  memcpy(header->oem_id, OEM_ID, 6);
621  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
622  memcpy(header->asl_compiler_id, ASLC, 4);
623 
624  header->asl_compiler_revision = asl_revision;
625  header->length = sizeof(acpi_dmar_t);
626  header->revision = get_acpi_table_revision(DMAR);
627 
628  dmar->host_address_width = cpu_phys_address_size() - 1;
629  dmar->flags = flags;
630 
631  current = acpi_fill_dmar(current);
632 
633  /* (Re)calculate length and checksum. */
634  header->length = current - (unsigned long)dmar;
635  header->checksum = acpi_checksum((void *)dmar, header->length);
636 }
637 
638 unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags,
639  u16 segment, u64 bar)
640 {
641  dmar_entry_t *drhd = (dmar_entry_t *)current;
642  memset(drhd, 0, sizeof(*drhd));
643  drhd->type = DMAR_DRHD;
644  drhd->length = sizeof(*drhd); /* will be fixed up later */
645  drhd->flags = flags;
646  drhd->segment = segment;
647  drhd->bar = bar;
648 
649  return drhd->length;
650 }
651 
652 unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment,
653  u64 bar, u64 limit)
654 {
655  dmar_rmrr_entry_t *rmrr = (dmar_rmrr_entry_t *)current;
656  memset(rmrr, 0, sizeof(*rmrr));
657  rmrr->type = DMAR_RMRR;
658  rmrr->length = sizeof(*rmrr); /* will be fixed up later */
659  rmrr->segment = segment;
660  rmrr->bar = bar;
661  rmrr->limit = limit;
662 
663  return rmrr->length;
664 }
665 
666 unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags,
667  u16 segment)
668 {
669  dmar_atsr_entry_t *atsr = (dmar_atsr_entry_t *)current;
670  memset(atsr, 0, sizeof(*atsr));
671  atsr->type = DMAR_ATSR;
672  atsr->length = sizeof(*atsr); /* will be fixed up later */
673  atsr->flags = flags;
674  atsr->segment = segment;
675 
676  return atsr->length;
677 }
678 
679 unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr,
680  u32 proximity_domain)
681 {
682  dmar_rhsa_entry_t *rhsa = (dmar_rhsa_entry_t *)current;
683  memset(rhsa, 0, sizeof(*rhsa));
684  rhsa->type = DMAR_RHSA;
685  rhsa->length = sizeof(*rhsa);
686  rhsa->base_address = base_addr;
687  rhsa->proximity_domain = proximity_domain;
688 
689  return rhsa->length;
690 }
691 
692 unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number,
693  const char *device_name)
694 {
695  dmar_andd_entry_t *andd = (dmar_andd_entry_t *)current;
696  int andd_len = sizeof(dmar_andd_entry_t) + strlen(device_name) + 1;
697  memset(andd, 0, andd_len);
698  andd->type = DMAR_ANDD;
699  andd->length = andd_len;
700  andd->device_number = device_number;
702 
703  return andd->length;
704 }
705 
706 unsigned long acpi_create_dmar_satc(unsigned long current, u8 flags, u16 segment)
707 {
708  dmar_satc_entry_t *satc = (dmar_satc_entry_t *)current;
709  int satc_len = sizeof(dmar_satc_entry_t);
710  memset(satc, 0, satc_len);
711  satc->type = DMAR_SATC;
712  satc->length = satc_len;
713  satc->flags = flags;
714  satc->segment_number = segment;
715 
716  return satc->length;
717 }
718 
719 void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current)
720 {
721  dmar_entry_t *drhd = (dmar_entry_t *)base;
722  drhd->length = current - base;
723 }
724 
725 void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current)
726 {
728  rmrr->length = current - base;
729 }
730 
731 void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current)
732 {
734  atsr->length = current - base;
735 }
736 
737 void acpi_dmar_satc_fixup(unsigned long base, unsigned long current)
738 {
740  satc->length = current - base;
741 }
742 
743 static unsigned long acpi_create_dmar_ds(unsigned long current,
744  enum dev_scope_type type, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
745 {
746  /* we don't support longer paths yet */
747  const size_t dev_scope_length = sizeof(dev_scope_t) + 2;
748 
749  dev_scope_t *ds = (dev_scope_t *)current;
750  memset(ds, 0, dev_scope_length);
751  ds->type = type;
752  ds->length = dev_scope_length;
753  ds->enumeration = enumeration_id;
754  ds->start_bus = bus;
755  ds->path[0].dev = dev;
756  ds->path[0].fn = fn;
757 
758  return ds->length;
759 }
760 
761 unsigned long acpi_create_dmar_ds_pci_br(unsigned long current, u8 bus,
762  u8 dev, u8 fn)
763 {
764  return acpi_create_dmar_ds(current,
765  SCOPE_PCI_SUB, 0, bus, dev, fn);
766 }
767 
768 unsigned long acpi_create_dmar_ds_pci(unsigned long current, u8 bus,
769  u8 dev, u8 fn)
770 {
771  return acpi_create_dmar_ds(current,
772  SCOPE_PCI_ENDPOINT, 0, bus, dev, fn);
773 }
774 
775 unsigned long acpi_create_dmar_ds_ioapic(unsigned long current,
776  u8 enumeration_id, u8 bus, u8 dev, u8 fn)
777 {
778  return acpi_create_dmar_ds(current,
779  SCOPE_IOAPIC, enumeration_id, bus, dev, fn);
780 }
781 
782 unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current,
783  u8 enumeration_id, u8 bus, u8 dev, u8 fn)
784 {
785  return acpi_create_dmar_ds(current,
786  SCOPE_MSI_HPET, enumeration_id, bus, dev, fn);
787 }
788 
789 /* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */
791  unsigned long (*acpi_fill_slit)(unsigned long current))
792 {
793  acpi_header_t *header = &(slit->header);
794  unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t);
795 
796  memset((void *)slit, 0, sizeof(acpi_slit_t));
797 
798  if (!header)
799  return;
800 
801  /* Fill out header fields. */
802  memcpy(header->signature, "SLIT", 4);
803  memcpy(header->oem_id, OEM_ID, 6);
804  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
805  memcpy(header->asl_compiler_id, ASLC, 4);
806 
807  header->asl_compiler_revision = asl_revision;
808  header->length = sizeof(acpi_slit_t);
809  header->revision = get_acpi_table_revision(SLIT);
810 
811  current = acpi_fill_slit(current);
812 
813  /* (Re)calculate length and checksum. */
814  header->length = current - (unsigned long)slit;
815  header->checksum = acpi_checksum((void *)slit, header->length);
816 }
817 
818 /* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */
820 {
821  acpi_header_t *header = &(hpet->header);
822  acpi_addr_t *addr = &(hpet->addr);
823 
824  memset((void *)hpet, 0, sizeof(acpi_hpet_t));
825 
826  if (!header)
827  return;
828 
829  /* Fill out header fields. */
830  memcpy(header->signature, "HPET", 4);
831  memcpy(header->oem_id, OEM_ID, 6);
832  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
833  memcpy(header->asl_compiler_id, ASLC, 4);
834 
835  header->asl_compiler_revision = asl_revision;
836  header->length = sizeof(acpi_hpet_t);
837  header->revision = get_acpi_table_revision(HPET);
838 
839  /* Fill out HPET address. */
840  addr->space_id = ACPI_ADDRESS_SPACE_MEMORY;
841  addr->bit_width = 64;
842  addr->bit_offset = 0;
843  addr->addrl = HPET_BASE_ADDRESS & 0xffffffff;
844  addr->addrh = ((unsigned long long)HPET_BASE_ADDRESS) >> 32;
845 
846  hpet->id = read32p(HPET_BASE_ADDRESS);
847  hpet->number = 0;
848  hpet->min_tick = CONFIG_HPET_MIN_TICKS;
849 
850  header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t));
851 }
852 
853 /*
854  * This method adds the ACPI error injection capability. It fills the default information.
855  * HW dependent code (caller) can modify the defaults upon return. If no changes are necessary
856  * and the defaults are acceptable then caller can simply add the table (acpi_add_table).
857  * INPUTS:
858  * einj - ptr to the starting location of EINJ table
859  * actions - number of actions to trigger an error (HW dependent)
860  * addr - address of trigger action table. This should be ACPI reserved memory and it will be
861  * shared between OS and FW.
862  */
864 {
865  int i;
866  acpi_header_t *header = &(einj->header);
867  acpi_injection_header_t *inj_header = &(einj->inj_header);
868  acpi_einj_smi_t *einj_smi = (acpi_einj_smi_t *)addr;
870  if (!header)
871  return;
872 
873  printk(BIOS_DEBUG, "%s einj_smi = %p\n", __func__, einj_smi);
874  memset(einj_smi, 0, sizeof(acpi_einj_smi_t));
875  tat = (acpi_einj_trigger_table_t *)(einj_smi + sizeof(acpi_einj_smi_t));
876  tat->header_size = 16;
877  tat->revision = 0;
878  tat->table_size = sizeof(acpi_einj_trigger_table_t) +
879  sizeof(acpi_einj_action_table_t) * actions - 1;
880  tat->entry_count = actions;
881  printk(BIOS_DEBUG, "%s trigger_action_table = %p\n", __func__, tat);
882 
883  for (i = 0; i < actions; i++) {
885  tat->trigger_action[i].instruction = NO_OP;
886  tat->trigger_action[i].flags = FLAG_IGNORE;
888  tat->trigger_action[i].reg.bit_width = 64;
889  tat->trigger_action[i].reg.bit_offset = 0;
891  tat->trigger_action[i].reg.addr = 0;
892  tat->trigger_action[i].value = 0;
893  tat->trigger_action[i].mask = 0xFFFFFFFF;
894  }
895 
896  acpi_einj_action_table_t default_actions[ACTION_COUNT] = {
897  [0] = {
899  .instruction = WRITE_REGISTER_VALUE,
900  .flags = FLAG_PRESERVE,
901  .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_state),
902  .value = 0,
903  .mask = 0xFFFFFFFF
904  },
905  [1] = {
906  .action = GET_TRIGGER_ACTION_TABLE,
907  .instruction = READ_REGISTER,
908  .flags = FLAG_IGNORE,
909  .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->trigger_action_table),
910  .value = 0,
911  .mask = 0xFFFFFFFFFFFFFFFF
912  },
913  [2] = {
914  .action = SET_ERROR_TYPE,
915  .instruction = WRITE_REGISTER,
916  .flags = FLAG_PRESERVE,
917  .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->err_inject[0]),
918  .value = 0,
919  .mask = 0xFFFFFFFF
920  },
921  [3] = {
922  .action = GET_ERROR_TYPE,
923  .instruction = READ_REGISTER,
924  .flags = FLAG_IGNORE,
925  .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->err_inj_cap),
926  .value = 0,
927  .mask = 0xFFFFFFFF
928  },
929  [4] = {
930  .action = END_INJECT_OP,
931  .instruction = WRITE_REGISTER_VALUE,
932  .flags = FLAG_PRESERVE,
933  .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_state),
934  .value = 0,
935  .mask = 0xFFFFFFFF
936 
937  },
938  [5] = {
939  .action = EXECUTE_INJECT_OP,
940  .instruction = WRITE_REGISTER_VALUE,
941  .flags = FLAG_PRESERVE,
942  .reg = EINJ_REG_IO(),
943  .value = 0x9a,
944  .mask = 0xFFFF,
945  },
946  [6] = {
947  .action = CHECK_BUSY_STATUS,
948  .instruction = READ_REGISTER_VALUE,
949  .flags = FLAG_IGNORE,
950  .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_status),
951  .value = 1,
952  .mask = 1,
953  },
954  [7] = {
955  .action = GET_CMD_STATUS,
956  .instruction = READ_REGISTER,
957  .flags = FLAG_PRESERVE,
958  .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->cmd_sts),
959  .value = 0,
960  .mask = 0x1fe,
961  },
962  [8] = {
963  .action = SET_ERROR_TYPE_WITH_ADDRESS,
964  .instruction = WRITE_REGISTER,
965  .flags = FLAG_PRESERVE,
966  .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->setaddrtable),
967  .value = 1,
968  .mask = 0xffffffff
969  }
970  };
971 
973  einj_smi->trigger_action_table = (u64) (uintptr_t)tat;
974 
975  for (i = 0; i < ACTION_COUNT; i++)
976  printk(BIOS_DEBUG, "default_actions[%d].reg.addr is %llx\n", i,
977  default_actions[i].reg.addr);
978 
979  memset((void *)einj, 0, sizeof(*einj));
980 
981  /* Fill out header fields. */
982  memcpy(header->signature, "EINJ", 4);
983  memcpy(header->oem_id, OEM_ID, 6);
984  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
985  memcpy(header->asl_compiler_id, ASLC, 4);
986 
987  header->asl_compiler_revision = asl_revision;
988  header->length = sizeof(acpi_einj_t);
989  header->revision = 1;
990  inj_header->einj_header_size = sizeof(acpi_injection_header_t);
991  inj_header->entry_count = ACTION_COUNT;
992 
993  printk(BIOS_DEBUG, "%s einj->action_table = %p\n",
994  __func__, einj->action_table);
995  memcpy((void *)einj->action_table, (void *)default_actions, sizeof(einj->action_table));
996  header->checksum = acpi_checksum((void *)einj, sizeof(*einj));
997 }
998 
999 void acpi_create_vfct(const struct device *device,
1000  acpi_vfct_t *vfct,
1001  unsigned long (*acpi_fill_vfct)(const struct device *device,
1002  acpi_vfct_t *vfct_struct, unsigned long current))
1003 {
1004  acpi_header_t *header = &(vfct->header);
1005  unsigned long current = (unsigned long)vfct + sizeof(acpi_vfct_t);
1006 
1007  memset((void *)vfct, 0, sizeof(acpi_vfct_t));
1008 
1009  if (!header)
1010  return;
1011 
1012  /* Fill out header fields. */
1013  memcpy(header->signature, "VFCT", 4);
1014  memcpy(header->oem_id, OEM_ID, 6);
1015  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1016  memcpy(header->asl_compiler_id, ASLC, 4);
1017 
1018  header->asl_compiler_revision = asl_revision;
1019  header->revision = get_acpi_table_revision(VFCT);
1020 
1021  current = acpi_fill_vfct(device, vfct, current);
1022 
1023  /* If no BIOS image, return with header->length == 0. */
1024  if (!vfct->VBIOSImageOffset)
1025  return;
1026 
1027  /* (Re)calculate length and checksum. */
1028  header->length = current - (unsigned long)vfct;
1029  header->checksum = acpi_checksum((void *)vfct, header->length);
1030 }
1031 
1032 void acpi_create_ipmi(const struct device *device,
1033  struct acpi_spmi *spmi,
1034  const u16 ipmi_revision,
1035  const acpi_addr_t *addr,
1036  const enum acpi_ipmi_interface_type type,
1037  const s8 gpe_interrupt,
1038  const u32 apic_interrupt,
1039  const u32 uid)
1040 {
1041  acpi_header_t *header = &(spmi->header);
1042  memset((void *)spmi, 0, sizeof(struct acpi_spmi));
1043 
1044  /* Fill out header fields. */
1045  memcpy(header->signature, "SPMI", 4);
1046  memcpy(header->oem_id, OEM_ID, 6);
1047  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1048  memcpy(header->asl_compiler_id, ASLC, 4);
1049 
1050  header->asl_compiler_revision = asl_revision;
1051  header->length = sizeof(struct acpi_spmi);
1052  header->revision = get_acpi_table_revision(SPMI);
1053 
1054  spmi->reserved = 1;
1055 
1056  if (device->path.type == DEVICE_PATH_PCI) {
1058  spmi->pci_bus = device->bus->secondary;
1059  spmi->pci_device = device->path.pci.devfn >> 3;
1060  spmi->pci_function = device->path.pci.devfn & 0x7;
1061  } else if (type != IPMI_INTERFACE_SSIF) {
1062  memcpy(spmi->uid, &uid, sizeof(spmi->uid));
1063  }
1064 
1065  spmi->base_address = *addr;
1066  spmi->specification_revision = ipmi_revision;
1067 
1068  spmi->interface_type = type;
1069 
1070  if (gpe_interrupt >= 0 && gpe_interrupt < 32) {
1071  spmi->gpe = gpe_interrupt;
1073  }
1074  if (apic_interrupt > 0) {
1075  spmi->global_system_interrupt = apic_interrupt;
1077  }
1078 
1079  /* Calculate checksum. */
1080  header->checksum = acpi_checksum((void *)spmi, header->length);
1081 }
1082 
1084  unsigned long (*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct,
1085  unsigned long current))
1086 {
1087  acpi_header_t *header = &(ivrs->header);
1088  unsigned long current = (unsigned long)ivrs + sizeof(acpi_ivrs_t);
1089 
1090  memset((void *)ivrs, 0, sizeof(acpi_ivrs_t));
1091 
1092  if (!header)
1093  return;
1094 
1095  /* Fill out header fields. */
1096  memcpy(header->signature, "IVRS", 4);
1097  memcpy(header->oem_id, OEM_ID, 6);
1098  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1099  memcpy(header->asl_compiler_id, ASLC, 4);
1100 
1101  header->asl_compiler_revision = asl_revision;
1102  header->length = sizeof(acpi_ivrs_t);
1103  header->revision = get_acpi_table_revision(IVRS);
1104 
1105  current = acpi_fill_ivrs(ivrs, current);
1106 
1107  /* (Re)calculate length and checksum. */
1108  header->length = current - (unsigned long)ivrs;
1109  header->checksum = acpi_checksum((void *)ivrs, header->length);
1110 }
1111 
1113  unsigned long (*acpi_fill_crat)(struct acpi_crat_header *crat_struct,
1114  unsigned long current))
1115 {
1116  acpi_header_t *header = &(crat->header);
1117  unsigned long current = (unsigned long)crat + sizeof(struct acpi_crat_header);
1118 
1119  memset((void *)crat, 0, sizeof(struct acpi_crat_header));
1120 
1121  if (!header)
1122  return;
1123 
1124  /* Fill out header fields. */
1125  memcpy(header->signature, "CRAT", 4);
1126  memcpy(header->oem_id, OEM_ID, 6);
1127  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1128  memcpy(header->asl_compiler_id, ASLC, 4);
1129 
1130  header->asl_compiler_revision = asl_revision;
1131  header->length = sizeof(struct acpi_crat_header);
1132  header->revision = get_acpi_table_revision(CRAT);
1133 
1134  current = acpi_fill_crat(crat, current);
1135 
1136  /* (Re)calculate length and checksum. */
1137  header->length = current - (unsigned long)crat;
1138  header->checksum = acpi_checksum((void *)crat, header->length);
1139 }
1140 
1141 unsigned long acpi_write_hpet(const struct device *device, unsigned long current,
1142  acpi_rsdp_t *rsdp)
1143 {
1144  acpi_hpet_t *hpet;
1145 
1146  /*
1147  * We explicitly add these tables later on:
1148  */
1149  printk(BIOS_DEBUG, "ACPI: * HPET\n");
1150 
1151  hpet = (acpi_hpet_t *) current;
1152  current += sizeof(acpi_hpet_t);
1153  current = ALIGN_UP(current, 16);
1154  acpi_create_hpet(hpet);
1155  acpi_add_table(rsdp, hpet);
1156 
1157  return current;
1158 }
1159 
1161  int port_type, int port_subtype,
1162  acpi_addr_t *address, uint32_t address_size,
1163  const char *device_path)
1164 {
1165  uintptr_t current;
1167  uint32_t *dbg2_addr_size;
1169  size_t path_len;
1170  const char *path;
1171  char *namespace;
1172 
1173  /* Fill out header fields. */
1174  current = (uintptr_t)dbg2;
1175  memset(dbg2, 0, sizeof(acpi_dbg2_header_t));
1176  header = &(dbg2->header);
1177 
1178  if (!header)
1179  return;
1180 
1181  header->revision = get_acpi_table_revision(DBG2);
1182  memcpy(header->signature, "DBG2", 4);
1183  memcpy(header->oem_id, OEM_ID, 6);
1184  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1185  memcpy(header->asl_compiler_id, ASLC, 4);
1186  header->asl_compiler_revision = asl_revision;
1187 
1188  /* One debug device defined */
1189  dbg2->devices_offset = sizeof(acpi_dbg2_header_t);
1190  dbg2->devices_count = 1;
1191  current += sizeof(acpi_dbg2_header_t);
1192 
1193  /* Device comes after the header */
1194  device = (acpi_dbg2_device_t *)current;
1195  memset(device, 0, sizeof(acpi_dbg2_device_t));
1196  current += sizeof(acpi_dbg2_device_t);
1197 
1198  device->revision = 0;
1199  device->address_count = 1;
1200  device->port_type = port_type;
1201  device->port_subtype = port_subtype;
1202 
1203  /* Base Address comes after device structure */
1204  memcpy((void *)current, address, sizeof(acpi_addr_t));
1205  device->base_address_offset = current - (uintptr_t)device;
1206  current += sizeof(acpi_addr_t);
1207 
1208  /* Address Size comes after address structure */
1209  dbg2_addr_size = (uint32_t *)current;
1210  device->address_size_offset = current - (uintptr_t)device;
1211  *dbg2_addr_size = address_size;
1212  current += sizeof(uint32_t);
1213 
1214  /* Namespace string comes last, use '.' if not provided */
1215  path = device_path ? : ".";
1216  /* Namespace string length includes NULL terminator */
1217  path_len = strlen(path) + 1;
1218  namespace = (char *)current;
1219  device->namespace_string_length = path_len;
1220  device->namespace_string_offset = current - (uintptr_t)device;
1221  strncpy(namespace, path, path_len);
1222  current += path_len;
1223 
1224  /* Update structure lengths and checksum */
1225  device->length = current - (uintptr_t)device;
1226  header->length = current - (uintptr_t)dbg2;
1227  header->checksum = acpi_checksum((uint8_t *)dbg2, header->length);
1228 }
1229 
1230 unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
1231  const struct device *dev, uint8_t access_size)
1232 {
1233  acpi_dbg2_header_t *dbg2 = (acpi_dbg2_header_t *)current;
1234  struct resource *res;
1236 
1237  if (!dev) {
1238  printk(BIOS_DEBUG, "%s: Device not found\n", __func__);
1239  return current;
1240  }
1241  if (!dev->enabled) {
1242  printk(BIOS_INFO, "%s: Device not enabled\n", __func__);
1243  return current;
1244  }
1245  res = probe_resource(dev, PCI_BASE_ADDRESS_0);
1246  if (!res) {
1247  printk(BIOS_ERR, "%s: Unable to find resource for %s\n",
1248  __func__, dev_path(dev));
1249  return current;
1250  }
1251 
1252  memset(&address, 0, sizeof(address));
1253  if (res->flags & IORESOURCE_IO)
1254  address.space_id = ACPI_ADDRESS_SPACE_IO;
1255  else if (res->flags & IORESOURCE_MEM)
1257  else {
1258  printk(BIOS_ERR, "%s: Unknown address space type\n", __func__);
1259  return current;
1260  }
1261 
1262  address.addrl = (uint32_t)res->base;
1263  address.addrh = (uint32_t)((res->base >> 32) & 0xffffffff);
1264  address.access_size = access_size;
1265 
1266  acpi_create_dbg2(dbg2,
1269  &address, res->size,
1270  acpi_device_path(dev));
1271 
1272  if (dbg2->header.length) {
1273  current += dbg2->header.length;
1274  current = acpi_align_current(current);
1275  acpi_add_table(rsdp, dbg2);
1276  }
1277 
1278  return current;
1279 }
1280 
1282 {
1283  memset((void *)facs, 0, sizeof(acpi_facs_t));
1284 
1285  memcpy(facs->signature, "FACS", 4);
1286  facs->length = sizeof(acpi_facs_t);
1287  facs->hardware_signature = 0;
1288  facs->firmware_waking_vector = 0;
1289  facs->global_lock = 0;
1290  facs->flags = 0;
1291  facs->x_firmware_waking_vector_l = 0;
1292  facs->x_firmware_waking_vector_h = 0;
1294 }
1295 
1296 static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id)
1297 {
1298  acpi_header_t *header = &(rsdt->header);
1299 
1300  if (!header)
1301  return;
1302 
1303  /* Fill out header fields. */
1304  memcpy(header->signature, "RSDT", 4);
1305  memcpy(header->oem_id, oem_id, 6);
1306  memcpy(header->oem_table_id, oem_table_id, 8);
1307  memcpy(header->asl_compiler_id, ASLC, 4);
1308 
1309  header->asl_compiler_revision = asl_revision;
1310  header->length = sizeof(acpi_rsdt_t);
1311  header->revision = get_acpi_table_revision(RSDT);
1312 
1313  /* Entries are filled in later, we come with an empty set. */
1314 
1315  /* Fix checksum. */
1316  header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
1317 }
1318 
1319 static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id)
1320 {
1321  acpi_header_t *header = &(xsdt->header);
1322 
1323  if (!header)
1324  return;
1325 
1326  /* Fill out header fields. */
1327  memcpy(header->signature, "XSDT", 4);
1328  memcpy(header->oem_id, oem_id, 6);
1329  memcpy(header->oem_table_id, oem_table_id, 8);
1330  memcpy(header->asl_compiler_id, ASLC, 4);
1331 
1332  header->asl_compiler_revision = asl_revision;
1333  header->length = sizeof(acpi_xsdt_t);
1334  header->revision = get_acpi_table_revision(XSDT);
1335 
1336  /* Entries are filled in later, we come with an empty set. */
1337 
1338  /* Fix checksum. */
1339  header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t));
1340 }
1341 
1342 static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt,
1343  acpi_xsdt_t *xsdt, char *oem_id)
1344 {
1345  memset(rsdp, 0, sizeof(acpi_rsdp_t));
1346 
1347  memcpy(rsdp->signature, RSDP_SIG, 8);
1348  memcpy(rsdp->oem_id, oem_id, 6);
1349 
1350  rsdp->length = sizeof(acpi_rsdp_t);
1351  rsdp->rsdt_address = (uintptr_t)rsdt;
1352 
1353  /*
1354  * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2.
1355  *
1356  * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
1357  * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
1358  * revision 0).
1359  */
1360  if (xsdt == NULL) {
1361  rsdp->revision = 0;
1362  } else {
1363  rsdp->xsdt_address = (u64)(uintptr_t)xsdt;
1365  }
1366 
1367  /* Calculate checksums. */
1368  rsdp->checksum = acpi_checksum((void *)rsdp, 20);
1369  rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
1370 }
1371 
1373  acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len)
1374 {
1375  acpi_header_t *header = &(hest->header);
1376  acpi_hest_hen_t *hen;
1377  void *pos;
1378  u16 len;
1379 
1380  pos = esd;
1381  memset(pos, 0, sizeof(acpi_hest_esd_t));
1382  len = 0;
1383  esd->type = type; /* MCE */
1384  esd->source_id = hest->error_source_count;
1385  esd->flags = 0; /* FIRMWARE_FIRST */
1386  esd->enabled = 1;
1387  esd->prealloc_erecords = 1;
1388  esd->max_section_per_record = 0x1;
1389 
1390  len += sizeof(acpi_hest_esd_t);
1391  pos = esd + 1;
1392 
1393  switch (type) {
1394  case 0: /* MCE */
1395  break;
1396  case 1: /* CMC */
1397  hen = (acpi_hest_hen_t *) (pos);
1398  memset(pos, 0, sizeof(acpi_hest_hen_t));
1399  hen->type = 3; /* SCI? */
1400  hen->length = sizeof(acpi_hest_hen_t);
1401  hen->conf_we = 0; /* Configuration Write Enable. */
1402  hen->poll_interval = 0;
1403  hen->vector = 0;
1404  hen->sw2poll_threshold_val = 0;
1405  hen->sw2poll_threshold_win = 0;
1406  hen->error_threshold_val = 0;
1407  hen->error_threshold_win = 0;
1408  len += sizeof(acpi_hest_hen_t);
1409  pos = hen + 1;
1410  break;
1411  case 2: /* NMI */
1412  case 6: /* AER Root Port */
1413  case 7: /* AER Endpoint */
1414  case 8: /* AER Bridge */
1415  case 9: /* Generic Hardware Error Source. */
1416  /* TODO: */
1417  break;
1418  default:
1419  printk(BIOS_DEBUG, "Invalid type of Error Source.");
1420  break;
1421  }
1422  hest->error_source_count++;
1423 
1424  memcpy(pos, data, data_len);
1425  len += data_len;
1426  if (header)
1427  header->length += len;
1428 
1429  return len;
1430 }
1431 
1432 /* ACPI 4.0 */
1434  unsigned long (*acpi_fill_hest)(acpi_hest_t *hest))
1435 {
1436  acpi_header_t *header = &(hest->header);
1437 
1438  memset(hest, 0, sizeof(acpi_hest_t));
1439 
1440  if (!header)
1441  return;
1442 
1443  memcpy(header->signature, "HEST", 4);
1444  memcpy(header->oem_id, OEM_ID, 6);
1445  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1446  memcpy(header->asl_compiler_id, ASLC, 4);
1447  header->asl_compiler_revision = asl_revision;
1448  header->length += sizeof(acpi_hest_t);
1449  header->revision = get_acpi_table_revision(HEST);
1450 
1451  acpi_fill_hest(hest);
1452 
1453  /* Calculate checksums. */
1454  header->checksum = acpi_checksum((void *)hest, header->length);
1455 }
1456 
1457 /* ACPI 3.0b */
1459 {
1460  acpi_header_t *header = &(bert->header);
1461 
1462  memset(bert, 0, sizeof(acpi_bert_t));
1463 
1464  if (!header)
1465  return;
1466 
1467  memcpy(header->signature, "BERT", 4);
1468  memcpy(header->oem_id, OEM_ID, 6);
1469  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1470  memcpy(header->asl_compiler_id, ASLC, 4);
1471  header->asl_compiler_revision = asl_revision;
1472  header->length += sizeof(acpi_bert_t);
1473  header->revision = get_acpi_table_revision(BERT);
1474 
1475  bert->error_region = region;
1476  bert->region_length = length;
1477 
1478  /* Calculate checksums. */
1479  header->checksum = acpi_checksum((void *)bert, header->length);
1480 }
1481 
1485 
1486 void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt)
1487 {
1488  acpi_header_t *header = &(fadt->header);
1489 
1490  memset((void *) fadt, 0, sizeof(acpi_fadt_t));
1491 
1492  if (!header)
1493  return;
1494 
1495  memcpy(header->signature, "FACP", 4);
1496  header->length = sizeof(acpi_fadt_t);
1497  header->revision = get_acpi_table_revision(FADT);
1498  memcpy(header->oem_id, OEM_ID, 6);
1499  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1500  memcpy(header->asl_compiler_id, ASLC, 4);
1501  header->asl_compiler_revision = asl_revision;
1502 
1504  fadt->firmware_ctrl = (unsigned long) facs;
1505  fadt->x_firmware_ctl_l = (unsigned long)facs;
1506  fadt->x_firmware_ctl_h = 0;
1507 
1508  fadt->dsdt = (unsigned long) dsdt;
1509  fadt->x_dsdt_l = (unsigned long)dsdt;
1510  fadt->x_dsdt_h = 0;
1511 
1512  /* should be 0 ACPI 3.0 */
1513  fadt->reserved = 0;
1514 
1516 
1517  if (CONFIG(USE_PC_CMOS_ALTCENTURY))
1518  fadt->century = RTC_CLK_ALTCENTURY;
1519 
1520  arch_fill_fadt(fadt);
1521 
1522  acpi_fill_fadt(fadt);
1523 
1524  soc_fill_fadt(fadt);
1525  mainboard_fill_fadt(fadt);
1526 
1527  header->checksum =
1528  acpi_checksum((void *) fadt, header->length);
1529 }
1530 
1532 {
1533  acpi_header_t *header = &(lpit->header);
1534  unsigned long current = (unsigned long)lpit + sizeof(acpi_lpit_t);
1535 
1536  memset((void *)lpit, 0, sizeof(acpi_lpit_t));
1537 
1538  if (!header)
1539  return;
1540 
1541  /* Fill out header fields. */
1542  memcpy(header->signature, "LPIT", 4);
1543  memcpy(header->oem_id, OEM_ID, 6);
1544  memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
1545  memcpy(header->asl_compiler_id, ASLC, 4);
1546 
1547  header->asl_compiler_revision = asl_revision;
1548  header->revision = get_acpi_table_revision(LPIT);
1549  header->oem_revision = 42;
1550  header->length = sizeof(acpi_lpit_t);
1551 
1552  current = acpi_fill_lpit(current);
1553 
1554  /* (Re)calculate length and checksum. */
1555  header->length = current - (unsigned long)lpit;
1556  header->checksum = acpi_checksum((void *)lpit, header->length);
1557 }
1558 
1560 {
1561  memset(lpi_desc, 0, sizeof(acpi_lpi_desc_ncst_t));
1562  lpi_desc->header.length = sizeof(acpi_lpi_desc_ncst_t);
1564  lpi_desc->header.uid = uid;
1565 
1566  return lpi_desc->header.length;
1567 }
1568 
1569 unsigned long __weak fw_cfg_acpi_tables(unsigned long start)
1570 {
1571  return 0;
1572 }
1573 
1575 {
1576  const char *file = CONFIG_CBFS_PREFIX "/dsdt.aml";
1577 
1578  if (!CONFIG(CBFS_PRELOAD))
1579  return;
1580 
1581  printk(BIOS_DEBUG, "Preloading %s\n", file);
1582  cbfs_preload(file);
1583 }
1584 
1586 
1588 {
1589  return coreboot_rsdp;
1590 }
1591 
1592 unsigned long write_acpi_tables(unsigned long start)
1593 {
1594  unsigned long current;
1595  acpi_rsdp_t *rsdp;
1596  acpi_rsdt_t *rsdt;
1597  acpi_xsdt_t *xsdt;
1598  acpi_fadt_t *fadt;
1599  acpi_facs_t *facs;
1600  acpi_header_t *slic_file, *slic;
1601  acpi_header_t *ssdt;
1602  acpi_header_t *dsdt_file, *dsdt;
1603  acpi_mcfg_t *mcfg;
1604  acpi_tcpa_t *tcpa;
1605  acpi_tpm2_t *tpm2;
1606  acpi_madt_t *madt;
1607  acpi_lpit_t *lpit;
1608  acpi_bert_t *bert;
1609  struct device *dev;
1610  unsigned long fw;
1611  size_t slic_size, dsdt_size;
1612  char oem_id[6], oem_table_id[8];
1613 
1614  current = start;
1615 
1616  /* Align ACPI tables to 16byte */
1617  current = acpi_align_current(current);
1618 
1619  /* Special case for qemu */
1620  fw = fw_cfg_acpi_tables(current);
1621  if (fw) {
1622  rsdp = NULL;
1623  /* Find RSDP. */
1624  for (void *p = (void *)current; p < (void *)fw; p += 16) {
1625  if (valid_rsdp((acpi_rsdp_t *)p)) {
1626  rsdp = p;
1627  break;
1628  }
1629  }
1630  if (!rsdp)
1631  return fw;
1632 
1633  /* Add BOOT0000 for Linux google firmware driver */
1634  printk(BIOS_DEBUG, "ACPI: * SSDT\n");
1635  ssdt = (acpi_header_t *)fw;
1636  current = (unsigned long)ssdt + sizeof(acpi_header_t);
1637 
1638  memset((void *)ssdt, 0, sizeof(acpi_header_t));
1639 
1640  memcpy(&ssdt->signature, "SSDT", 4);
1641  ssdt->revision = get_acpi_table_revision(SSDT);
1642  memcpy(&ssdt->oem_id, OEM_ID, 6);
1643  memcpy(&ssdt->oem_table_id, oem_table_id, 8);
1644  ssdt->oem_revision = 42;
1645  memcpy(&ssdt->asl_compiler_id, ASLC, 4);
1646  ssdt->asl_compiler_revision = asl_revision;
1647  ssdt->length = sizeof(acpi_header_t);
1648 
1649  acpigen_set_current((char *) current);
1650 
1651  /* Write object to declare coreboot tables */
1653 
1654  /* (Re)calculate length and checksum. */
1655  ssdt->length = current - (unsigned long)ssdt;
1656  ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
1657 
1659 
1660  acpi_add_table(rsdp, ssdt);
1661 
1662  return fw;
1663  }
1664 
1665  dsdt_file = cbfs_map(CONFIG_CBFS_PREFIX "/dsdt.aml", &dsdt_size);
1666  if (!dsdt_file) {
1667  printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n");
1668  return current;
1669  }
1670 
1671  if (dsdt_file->length > dsdt_size
1672  || dsdt_file->length < sizeof(acpi_header_t)
1673  || memcmp(dsdt_file->signature, "DSDT", 4) != 0) {
1674  printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n");
1675  return current;
1676  }
1677 
1678  slic_file = cbfs_map(CONFIG_CBFS_PREFIX "/slic", &slic_size);
1679  if (slic_file
1680  && (slic_file->length > slic_size
1681  || slic_file->length < sizeof(acpi_header_t)
1682  || (memcmp(slic_file->signature, "SLIC", 4) != 0
1683  && memcmp(slic_file->signature, "MSDM", 4) != 0))) {
1684  slic_file = 0;
1685  }
1686 
1687  if (slic_file) {
1688  memcpy(oem_id, slic_file->oem_id, 6);
1689  memcpy(oem_table_id, slic_file->oem_table_id, 8);
1690  } else {
1691  memcpy(oem_id, OEM_ID, 6);
1692  memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8);
1693  }
1694 
1695  printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
1696 
1697  /* We need at least an RSDP and an RSDT Table */
1698  rsdp = (acpi_rsdp_t *) current;
1699  coreboot_rsdp = (uintptr_t)rsdp;
1700  current += sizeof(acpi_rsdp_t);
1701  current = acpi_align_current(current);
1702  rsdt = (acpi_rsdt_t *) current;
1703  current += sizeof(acpi_rsdt_t);
1704  current = acpi_align_current(current);
1705  xsdt = (acpi_xsdt_t *) current;
1706  current += sizeof(acpi_xsdt_t);
1707  current = acpi_align_current(current);
1708 
1709  /* clear all table memory */
1710  memset((void *) start, 0, current - start);
1711 
1712  acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id);
1713  acpi_write_rsdt(rsdt, oem_id, oem_table_id);
1714  acpi_write_xsdt(xsdt, oem_id, oem_table_id);
1715 
1716  printk(BIOS_DEBUG, "ACPI: * FACS\n");
1717  current = ALIGN_UP(current, 64);
1718  facs = (acpi_facs_t *) current;
1719  current += sizeof(acpi_facs_t);
1720  current = acpi_align_current(current);
1721  acpi_create_facs(facs);
1722 
1723  printk(BIOS_DEBUG, "ACPI: * DSDT\n");
1724  dsdt = (acpi_header_t *) current;
1725  memcpy(dsdt, dsdt_file, sizeof(acpi_header_t));
1726  if (dsdt->length >= sizeof(acpi_header_t)) {
1727  current += sizeof(acpi_header_t);
1728 
1729  acpigen_set_current((char *) current);
1730 
1731  if (CONFIG(ACPI_SOC_NVS))
1732  acpi_fill_gnvs();
1733  if (CONFIG(CHROMEOS_NVS))
1734  acpi_fill_cnvs();
1735 
1736  for (dev = all_devices; dev; dev = dev->next)
1737  if (dev->ops && dev->ops->acpi_inject_dsdt)
1738  dev->ops->acpi_inject_dsdt(dev);
1739  current = (unsigned long) acpigen_get_current();
1740  memcpy((char *)current,
1741  (char *)dsdt_file + sizeof(acpi_header_t),
1742  dsdt->length - sizeof(acpi_header_t));
1743  current += dsdt->length - sizeof(acpi_header_t);
1744 
1745  /* (Re)calculate length and checksum. */
1746  dsdt->length = current - (unsigned long)dsdt;
1747  dsdt->checksum = 0;
1748  dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length);
1749  }
1750 
1751  current = acpi_align_current(current);
1752 
1753  printk(BIOS_DEBUG, "ACPI: * FADT\n");
1754  fadt = (acpi_fadt_t *) current;
1755  current += sizeof(acpi_fadt_t);
1756  current = acpi_align_current(current);
1757 
1758  acpi_create_fadt(fadt, facs, dsdt);
1759  acpi_add_table(rsdp, fadt);
1760 
1761  if (slic_file) {
1762  printk(BIOS_DEBUG, "ACPI: * SLIC\n");
1763  slic = (acpi_header_t *)current;
1764  memcpy(slic, slic_file, slic_file->length);
1765  current += slic_file->length;
1766  current = acpi_align_current(current);
1767  acpi_add_table(rsdp, slic);
1768  }
1769 
1770  printk(BIOS_DEBUG, "ACPI: * SSDT\n");
1771  ssdt = (acpi_header_t *)current;
1773  if (ssdt->length > sizeof(acpi_header_t)) {
1774  current += ssdt->length;
1775  acpi_add_table(rsdp, ssdt);
1776  current = acpi_align_current(current);
1777  }
1778 
1779  printk(BIOS_DEBUG, "ACPI: * MCFG\n");
1780  mcfg = (acpi_mcfg_t *) current;
1781  acpi_create_mcfg(mcfg);
1782  if (mcfg->header.length > sizeof(acpi_mcfg_t)) {
1783  current += mcfg->header.length;
1784  current = acpi_align_current(current);
1785  acpi_add_table(rsdp, mcfg);
1786  }
1787 
1788  if (CONFIG(TPM1)) {
1789  printk(BIOS_DEBUG, "ACPI: * TCPA\n");
1790  tcpa = (acpi_tcpa_t *) current;
1791  acpi_create_tcpa(tcpa);
1792  if (tcpa->header.length >= sizeof(acpi_tcpa_t)) {
1793  current += tcpa->header.length;
1794  current = acpi_align_current(current);
1795  acpi_add_table(rsdp, tcpa);
1796  }
1797  }
1798 
1799  if (CONFIG(TPM2)) {
1800  printk(BIOS_DEBUG, "ACPI: * TPM2\n");
1801  tpm2 = (acpi_tpm2_t *) current;
1802  acpi_create_tpm2(tpm2);
1803  if (tpm2->header.length >= sizeof(acpi_tpm2_t)) {
1804  current += tpm2->header.length;
1805  current = acpi_align_current(current);
1806  acpi_add_table(rsdp, tpm2);
1807  }
1808  }
1809 
1810  if (CONFIG(ACPI_LPIT)) {
1811  printk(BIOS_DEBUG, "ACPI: * LPIT\n");
1812 
1813  lpit = (acpi_lpit_t *)current;
1814  acpi_create_lpit(lpit);
1815  if (lpit->header.length >= sizeof(acpi_lpit_t)) {
1816  current += lpit->header.length;
1817  current = acpi_align_current(current);
1818  acpi_add_table(rsdp, lpit);
1819  }
1820  }
1821 
1822  printk(BIOS_DEBUG, "ACPI: * MADT\n");
1823 
1824  madt = (acpi_madt_t *) current;
1825  acpi_create_madt(madt);
1826  if (madt->header.length > sizeof(acpi_madt_t)) {
1827  current += madt->header.length;
1828  acpi_add_table(rsdp, madt);
1829  }
1830 
1831  current = acpi_align_current(current);
1832 
1833  if (CONFIG(ACPI_BERT)) {
1834  void *region;
1835  size_t size;
1836  bert = (acpi_bert_t *) current;
1837  if (acpi_soc_get_bert_region(&region, &size) == CB_SUCCESS) {
1838  printk(BIOS_DEBUG, "ACPI: * BERT\n");
1839  acpi_write_bert(bert, (uintptr_t)region, size);
1840  if (bert->header.length >= sizeof(acpi_bert_t)) {
1841  current += bert->header.length;
1842  acpi_add_table(rsdp, bert);
1843  }
1844  current = acpi_align_current(current);
1845  }
1846  }
1847 
1848  printk(BIOS_DEBUG, "current = %lx\n", current);
1849 
1850  for (dev = all_devices; dev; dev = dev->next) {
1851  if (dev->ops && dev->ops->write_acpi_tables) {
1852  current = dev->ops->write_acpi_tables(dev, current,
1853  rsdp);
1854  current = acpi_align_current(current);
1855  }
1856  }
1857 
1858  printk(BIOS_INFO, "ACPI: done.\n");
1859  return current;
1860 }
1861 
1863 {
1864  if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
1865  return NULL;
1866 
1867  printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp);
1868 
1869  if (acpi_checksum((void *)rsdp, 20) != 0)
1870  return NULL;
1871  printk(BIOS_DEBUG, "Checksum 1 passed\n");
1872 
1873  if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
1874  rsdp->length) != 0))
1875  return NULL;
1876  printk(BIOS_DEBUG, "Checksum 2 passed all OK\n");
1877 
1878  return rsdp;
1879 }
1880 
1882 {
1883  char *p, *end;
1884  acpi_rsdt_t *rsdt;
1885  acpi_facs_t *facs;
1886  acpi_fadt_t *fadt = NULL;
1887  acpi_rsdp_t *rsdp = NULL;
1888  void *wake_vec;
1889  int i;
1890 
1891  if (!acpi_is_wakeup_s3())
1892  return NULL;
1893 
1894  printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n");
1895 
1896  /* Find RSDP. */
1897  for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) {
1898  rsdp = valid_rsdp((acpi_rsdp_t *)p);
1899  if (rsdp)
1900  break;
1901  }
1902 
1903  if (rsdp == NULL) {
1905  "No RSDP found, wake up from S3 not possible.\n");
1906  return NULL;
1907  }
1908 
1909  printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp);
1910  rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
1911 
1912  end = (char *)rsdt + rsdt->header.length;
1913  printk(BIOS_DEBUG, "RSDT found at %p ends at %p\n", rsdt, end);
1914 
1915  for (i = 0; ((char *)&rsdt->entry[i]) < end; i++) {
1916  fadt = (acpi_fadt_t *)(uintptr_t)rsdt->entry[i];
1917  if (strncmp((char *)fadt, "FACP", 4) == 0)
1918  break;
1919  fadt = NULL;
1920  }
1921 
1922  if (fadt == NULL) {
1924  "No FADT found, wake up from S3 not possible.\n");
1925  return NULL;
1926  }
1927 
1928  printk(BIOS_DEBUG, "FADT found at %p\n", fadt);
1929  facs = (acpi_facs_t *)(uintptr_t)fadt->firmware_ctrl;
1930 
1931  if (facs == NULL) {
1933  "No FACS found, wake up from S3 not possible.\n");
1934  return NULL;
1935  }
1936 
1937  printk(BIOS_DEBUG, "FACS found at %p\n", facs);
1938  wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector;
1939  printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec);
1940 
1941  return wake_vec;
1942 }
1943 
1944 __weak int acpi_get_gpe(int gpe)
1945 {
1946  return -1; /* implemented by SOC */
1947 }
1948 
1950 {
1952 }
1953 
1955 {
1956  switch (table) {
1957  case FADT:
1958  return ACPI_FADT_REV_ACPI_6;
1959  case MADT: /* ACPI 3.0: 2, ACPI 4.0/5.0: 3, ACPI 6.2b/6.3: 5 */
1960  return 3;
1961  case MCFG:
1962  return 1;
1963  case TCPA:
1964  return 2;
1965  case TPM2:
1966  return 4;
1967  case SSDT: /* ACPI 3.0 up to 6.3: 2 */
1968  return 2;
1969  case SRAT: /* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 up to 6.3: 3 */
1970  return 1; /* TODO Should probably be upgraded to 2 */
1971  case HMAT: /* ACPI 6.4: 2 */
1972  return 2;
1973  case DMAR:
1974  return 1;
1975  case SLIT: /* ACPI 2.0 up to 6.3: 1 */
1976  return 1;
1977  case SPMI: /* IMPI 2.0 */
1978  return 5;
1979  case HPET: /* Currently 1. Table added in ACPI 2.0. */
1980  return 1;
1981  case VFCT: /* ACPI 2.0/3.0/4.0: 1 */
1982  return 1;
1983  case IVRS:
1984  return IVRS_FORMAT_MIXED;
1985  case DBG2:
1986  return 0;
1987  case FACS: /* ACPI 2.0/3.0: 1, ACPI 4.0 up to 6.3: 2 */
1988  return 1;
1989  case RSDT: /* ACPI 1.0 up to 6.3: 1 */
1990  return 1;
1991  case XSDT: /* ACPI 2.0 up to 6.3: 1 */
1992  return 1;
1993  case RSDP: /* ACPI 2.0 up to 6.3: 2 */
1994  return 2;
1995  case EINJ:
1996  return 1;
1997  case HEST:
1998  return 1;
1999  case NHLT:
2000  return 5;
2001  case BERT:
2002  return 1;
2003  case CRAT:
2004  return 1;
2005  case LPIT: /* ACPI 5.1 up to 6.3: 0 */
2006  return 0;
2007  default:
2008  return -1;
2009  }
2010  return -1;
2011 }
unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid)
Definition: acpi.c:1559
void acpi_create_madt(acpi_madt_t *madt)
Definition: acpi.c:227
void acpi_create_srat(acpi_srat_t *srat, unsigned long(*acpi_fill_srat)(unsigned long current))
Definition: acpi.c:532
unsigned long write_acpi_tables(unsigned long start)
Definition: acpi.c:1592
static void * get_tcpa_log(u32 *size)
Definition: acpi.c:296
unsigned long acpi_create_dmar_ds_ioapic(unsigned long current, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
Definition: acpi.c:775
__weak void mainboard_fill_fadt(acpi_fadt_t *fadt)
Definition: acpi.c:1484
unsigned long acpi_create_madt_lapics(unsigned long current)
Definition: acpi.c:144
int acpi_create_madt_lx2apic_nmi(acpi_madt_lx2apic_nmi_t *lapic_nmi, u32 cpu, u16 flags, u8 lint)
Definition: acpi.c:212
void acpi_create_lpit(acpi_lpit_t *lpit)
Definition: acpi.c:1531
void acpi_dmar_satc_fixup(unsigned long base, unsigned long current)
Definition: acpi.c:737
unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment, u64 bar, u64 limit)
Definition: acpi.c:652
void acpi_create_ivrs(acpi_ivrs_t *ivrs, unsigned long(*acpi_fill_ivrs)(acpi_ivrs_t *ivrs_struct, unsigned long current))
Definition: acpi.c:1083
static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id)
Definition: acpi.c:1296
void acpi_create_mcfg(acpi_mcfg_t *mcfg)
Definition: acpi.c:268
unsigned long acpi_write_hpet(const struct device *device, unsigned long current, acpi_rsdp_t *rsdp)
Definition: acpi.c:1141
uintptr_t get_coreboot_rsdp(void)
Definition: acpi.c:1587
void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt)
Definition: acpi.c:1486
void acpi_create_facs(acpi_facs_t *facs)
Definition: acpi.c:1281
unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current, const struct device *dev, uint8_t access_size)
Definition: acpi.c:1230
__weak void soc_fill_fadt(acpi_fadt_t *fadt)
Definition: acpi.c:1483
void preload_acpi_dsdt(void)
Definition: acpi.c:1574
void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current)
Definition: acpi.c:719
void acpi_create_ipmi(const struct device *device, struct acpi_spmi *spmi, const u16 ipmi_revision, const acpi_addr_t *addr, const enum acpi_ipmi_interface_type type, const s8 gpe_interrupt, const u32 apic_interrupt, const u32 uid)
Definition: acpi.c:1032
void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
Add an ACPI table to the RSDT (and XSDT) structure, recalculate length and checksum.
Definition: acpi.c:49
static void acpi_ssdt_write_cbtable(void)
Definition: acpi.c:429
void acpi_create_vfct(const struct device *device, acpi_vfct_t *vfct, unsigned long(*acpi_fill_vfct)(const struct device *device, acpi_vfct_t *vfct_struct, unsigned long current))
Definition: acpi.c:999
void acpi_create_slit(acpi_slit_t *slit, unsigned long(*acpi_fill_slit)(unsigned long current))
Definition: acpi.c:790
unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
Definition: acpi.c:782
unsigned long acpi_create_dmar_ds_pci(unsigned long current, u8 bus, u8 dev, u8 fn)
Definition: acpi.c:768
unsigned long acpi_create_dmar_ds_pci_br(unsigned long current, u8 bus, u8 dev, u8 fn)
Definition: acpi.c:761
u8 acpi_checksum(u8 *table, u32 length)
Definition: acpi.c:35
void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags, unsigned long(*acpi_fill_dmar)(unsigned long))
Definition: acpi.c:607
static unsigned long acpi_create_dmar_ds(unsigned long current, enum dev_scope_type type, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
Definition: acpi.c:743
unsigned long __weak fw_cfg_acpi_tables(unsigned long start)
Definition: acpi.c:1569
int acpi_create_madt_lx2apic(acpi_madt_lx2apic_t *lapic, u32 cpu, u32 apic)
Definition: acpi.c:132
void acpi_create_crat(struct acpi_crat_header *crat, unsigned long(*acpi_fill_crat)(struct acpi_crat_header *crat_struct, unsigned long current))
Definition: acpi.c:1112
static unsigned long acpi_fill_mcfg(unsigned long current)
Definition: acpi.c:259
void acpi_write_bert(acpi_bert_t *bert, uintptr_t region, size_t length)
Definition: acpi.c:1458
void * acpi_find_wakeup_vector(void)
Definition: acpi.c:1881
void acpi_create_dbg2(acpi_dbg2_header_t *dbg2, int port_type, int port_subtype, acpi_addr_t *address, uint32_t address_size, const char *device_path)
Definition: acpi.c:1160
int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek, u32 flags)
Definition: acpi.c:499
static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt, acpi_xsdt_t *xsdt, char *oem_id)
Definition: acpi.c:1342
int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic)
Definition: acpi.c:121
void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions)
Definition: acpi.c:863
int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic)
Definition: acpi.c:485
unsigned long acpi_create_dmar_atsr(unsigned long current, u8 flags, u16 segment)
Definition: acpi.c:666
static void acpi_create_tcpa(acpi_tcpa_t *tcpa)
Definition: acpi.c:321
void acpi_create_ssdt_generator(acpi_header_t *ssdt, const char *oem_table_id)
Definition: acpi.c:452
unsigned long acpi_create_hest_error_source(acpi_hest_t *hest, acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len)
Definition: acpi.c:1372
void acpi_create_hpet(acpi_hpet_t *hpet)
Definition: acpi.c:819
int get_acpi_table_revision(enum acpi_tables table)
Definition: acpi.c:1954
static acpi_rsdp_t * valid_rsdp(acpi_rsdp_t *rsdp)
Definition: acpi.c:1862
int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride, u8 bus, u8 source, u32 gsirq, u16 flags)
Definition: acpi.c:187
int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain, u16 seg, u8 bus, u8 dev, u8 func, u32 flags)
Definition: acpi.c:514
int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr, u32 gsi_base)
Definition: acpi.c:174
u8 get_acpi_fadt_minor_version(void)
Definition: acpi.c:1949
void acpi_create_hmat(acpi_hmat_t *hmat, unsigned long(*acpi_fill_hmat)(unsigned long current))
Definition: acpi.c:579
__weak void arch_fill_fadt(acpi_fadt_t *fadt)
Definition: acpi.c:1482
void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current)
Definition: acpi.c:725
void acpi_dmar_atsr_fixup(unsigned long base, unsigned long current)
Definition: acpi.c:731
__weak int acpi_get_gpe(int gpe)
Definition: acpi.c:1944
unsigned long acpi_create_dmar_rhsa(unsigned long current, u64 base_addr, u32 proximity_domain)
Definition: acpi.c:679
static uintptr_t coreboot_rsdp
Definition: acpi.c:1585
int acpi_create_madt_lapic_nmi(acpi_madt_lapic_nmi_t *lapic_nmi, u8 cpu, u16 flags, u8 lint)
Definition: acpi.c:200
unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags, u16 segment, u64 bar)
Definition: acpi.c:638
int acpi_create_hmat_mpda(acpi_hmat_mpda_t *mpda, u32 initiator, u32 memory)
Definition: acpi.c:562
static void acpi_create_tpm2(acpi_tpm2_t *tpm2)
Definition: acpi.c:379
void acpi_write_hest(acpi_hest_t *hest, unsigned long(*acpi_fill_hest)(acpi_hest_t *hest))
Definition: acpi.c:1433
static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id)
Definition: acpi.c:1319
int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base, u16 seg_nr, u8 start, u8 end)
Definition: acpi.c:108
static void * get_tpm2_log(u32 *size)
Definition: acpi.c:354
unsigned long acpi_create_dmar_satc(unsigned long current, u8 flags, u16 segment)
Definition: acpi.c:706
unsigned long acpi_create_dmar_andd(unsigned long current, u8 device_number, const char *device_name)
Definition: acpi.c:692
const char * acpi_device_path(const struct device *dev)
Definition: device.c:144
void acpi_fill_gnvs(void)
Definition: gnvs.c:64
#define IVRS_FORMAT_MIXED
Definition: acpi_ivrs.h:23
uint8_t acpi_get_preferred_pm_profile(void)
Definition: acpi_pm.c:14
void acpigen_pop_len(void)
Definition: acpigen.c:37
void acpigen_write_coreboot_hid(enum coreboot_acpi_ids id)
Definition: acpigen.c:216
void acpigen_write_resourcetemplate_footer(void)
Definition: acpigen.c:1165
void acpigen_write_name_integer(const char *name, uint64_t val)
Definition: acpigen.c:170
void acpigen_write_STA(uint8_t status)
Definition: acpigen.c:783
void acpigen_write_resourcetemplate_header(void)
Definition: acpigen.c:1147
void acpigen_set_current(char *curr)
Definition: acpigen.c:51
void acpigen_write_mem32fixed(int readwrite, u32 base, u32 size)
Definition: acpigen.c:1071
char * acpigen_get_current(void)
Definition: acpigen.c:56
void acpigen_write_device(const char *name)
Definition: acpigen.c:769
void acpigen_write_name(const char *name)
Definition: acpigen.c:320
struct arm64_kernel_header header
Definition: fit_payload.c:30
static int acpi_is_wakeup_s3(void)
Definition: acpi.h:9
#define HPET_BASE_ADDRESS
Definition: hpet.h:6
void * memcpy(void *dest, const void *src, size_t n)
Definition: memcpy.c:7
void * memset(void *dstpp, int c, size_t len)
Definition: memset.c:12
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define ALIGN_UP(x, a)
Definition: helpers.h:17
@ CB_SUCCESS
Call completed successfully.
Definition: cb_err.h:16
static void * cbfs_map(const char *name, size_t *size_out)
Definition: cbfs.h:246
void cbfs_preload(const char *name)
Definition: cbfs.c:299
void * cbmem_entry_start(const struct cbmem_entry *entry)
Definition: imd_cbmem.c:190
const struct cbmem_entry * cbmem_entry_find(u32 id)
Definition: imd_cbmem.c:157
void * cbmem_add(u32 id, u64 size)
Definition: imd_cbmem.c:144
u64 cbmem_entry_size(const struct cbmem_entry *entry)
Definition: imd_cbmem.c:185
#define CBMEM_ID_CBTABLE
Definition: cbmem_id.h:16
#define CBMEM_ID_TPM2_TCG_LOG
Definition: cbmem_id.h:63
#define CBMEM_ID_TCPA_TCG_LOG
Definition: cbmem_id.h:61
static u32 addr
Definition: cirrus.c:14
enum fch_io_device device
Definition: fch.c:74
#define printk(level,...)
Definition: stdlib.h:16
int cpu_phys_address_size(void)
Definition: cpu_common.c:46
DEVTREE_CONST struct device *DEVTREE_CONST all_devices
Linked list of ALL devices.
Definition: device_const.c:13
struct resource * probe_resource(const struct device *dev, unsigned int index)
See if a resource structure already exists for a given index.
Definition: device_util.c:323
const char * dev_path(const struct device *dev)
Definition: device_util.c:149
@ CONFIG
Definition: dsi_common.h:201
uint64_t length
Definition: fw_cfg_if.h:1
uint64_t address
Definition: fw_cfg_if.h:0
struct acpi_madt_lx2apic acpi_madt_lx2apic_t
#define READ_REGISTER
Definition: acpi.h:1131
struct acpi_injection_header acpi_injection_header_t
#define ACTION_COUNT
Definition: acpi.h:1118
struct acpi_einj acpi_einj_t
#define GET_CMD_STATUS
Definition: acpi.h:1126
struct acpi_mcfg acpi_mcfg_t
struct acpi_madt_lx2apic_nmi acpi_madt_lx2apic_nmi_t
static uintptr_t acpi_align_current(uintptr_t current)
Definition: acpi.h:1435
struct acpi_xsdt acpi_xsdt_t
acpi_ipmi_interface_type
Definition: acpi.h:1060
@ IPMI_INTERFACE_SSIF
Definition: acpi.h:1065
@ ACPI_LPI_DESC_TYPE_NATIVE_CSTATE
Definition: acpi.h:375
#define OEM_ID
Definition: acpi.h:35
@ LOCAL_APIC
Definition: acpi.h:589
@ LOCAL_X2APIC
Definition: acpi.h:598
@ IRQ_SOURCE_OVERRIDE
Definition: acpi.h:591
@ LOCAL_APIC_NMI
Definition: acpi.h:593
@ IO_APIC
Definition: acpi.h:590
@ LOCAL_X2APIC_NMI
Definition: acpi.h:599
struct acpi_dmar acpi_dmar_t
struct acpi_madt_lapic_nmi acpi_madt_lapic_nmi_t
#define ACPI_FADT_MINOR_VERSION_0
Definition: acpi.h:785
#define END_INJECT_OP
Definition: acpi.h:1123
struct acpi_dbg2_device acpi_dbg2_device_t
#define FLAG_IGNORE
Definition: acpi.h:1197
struct acpi_hest_hen acpi_hest_hen_t
#define READ_REGISTER_VALUE
Definition: acpi.h:1132
struct acpi_hmat acpi_hmat_t
#define ACPI_IPMI_INT_TYPE_SCI
Definition: acpi.h:1069
struct acpi_lpi_desc_ncst acpi_lpi_desc_ncst_t
#define ACPI_EINJ_DEFAULT_CAP
Definition: acpi.h:1114
struct acpi_gen_regaddr acpi_addr_t
#define RSDP_SIG
Definition: acpi.h:56
#define WRITE_REGISTER_VALUE
Definition: acpi.h:1134
#define FLAG_PRESERVE
Definition: acpi.h:1196
struct acpi_hest_esd acpi_hest_esd_t
struct acpi_mcfg_mmconfig acpi_mcfg_mmconfig_t
#define ACPI_ADDRESS_SPACE_MEMORY
Definition: acpi.h:104
struct dmar_satc_entry dmar_satc_entry_t
#define ASLC
Definition: acpi.h:57
#define ACPI_TABLE_CREATOR
Definition: acpi.h:34
#define EINJ_REG_MEMORY(address)
Definition: acpi.h:1200
#define ACPI_ACCESS_SIZE_QWORD_ACCESS
Definition: acpi.h:130
struct acpi_facs acpi_facs_t
struct acpi_srat_gia acpi_srat_gia_t
struct acpi_hest acpi_hest_t
#define ACPI_DBG2_PORT_SERIAL_16550
Definition: acpi.h:670
#define EXECUTE_INJECT_OP
Definition: acpi.h:1124
struct acpi_srat_mem acpi_srat_mem_t
#define NO_OP
Definition: acpi.h:1135
dmar_flags
Definition: acpi.h:522
@ DMAR_ATSR
Definition: acpi.h:508
@ DMAR_SATC
Definition: acpi.h:511
@ DMAR_ANDD
Definition: acpi.h:510
@ DMAR_RMRR
Definition: acpi.h:507
@ DMAR_RHSA
Definition: acpi.h:509
@ DMAR_DRHD
Definition: acpi.h:506
#define ACPI_IPMI_PCI_DEVICE_FLAG
Definition: acpi.h:1068
#define ACPI_DBG2_PORT_SERIAL
Definition: acpi.h:669
struct acpi_srat_lapic acpi_srat_lapic_t
struct acpi_madt_irqoverride acpi_madt_irqoverride_t
struct acpi_madt_lapic acpi_madt_lapic_t
#define ACPI_SRAT_GIA_DEV_HANDLE_PCI
Definition: acpi.h:343
struct acpi_tpm2 acpi_tpm2_t
struct acpi_table_header acpi_header_t
void acpi_fill_cnvs(void)
struct acpi_rsdt acpi_rsdt_t
struct acpi_madt_ioapic acpi_madt_ioapic_t
#define BEGIN_INJECT_OP
Definition: acpi.h:1119
#define TRIGGER_ERROR
Definition: acpi.h:1128
struct acpi_tcpa acpi_tcpa_t
struct acpi_srat acpi_srat_t
#define WRITE_REGISTER
Definition: acpi.h:1133
struct acpi_einj_trigger_table acpi_einj_trigger_table_t
struct acpi_hmat_mpda acpi_hmat_mpda_t
#define CHECK_BUSY_STATUS
Definition: acpi.h:1125
struct acpi_fadt acpi_fadt_t
struct acpi_bert acpi_bert_t
@ COREBOOT_ACPI_ID_CBTABLE
Definition: acpi.h:69
#define SET_ERROR_TYPE_WITH_ADDRESS
Definition: acpi.h:1127
struct acpi_rsdp acpi_rsdp_t
#define GET_TRIGGER_ACTION_TABLE
Definition: acpi.h:1120
struct dmar_andd_entry dmar_andd_entry_t
acpi_tables
Definition: acpi.h:73
@ SPMI
Definition: acpi.h:78
@ SLIT
Definition: acpi.h:76
@ EINJ
Definition: acpi.h:75
@ XSDT
Definition: acpi.h:76
@ MADT
Definition: acpi.h:75
@ FACS
Definition: acpi.h:75
@ RSDP
Definition: acpi.h:76
@ SSDT
Definition: acpi.h:76
@ TPM2
Definition: acpi.h:76
@ TCPA
Definition: acpi.h:76
@ RSDT
Definition: acpi.h:76
@ HMAT
Definition: acpi.h:75
@ LPIT
Definition: acpi.h:76
@ SRAT
Definition: acpi.h:76
@ VFCT
Definition: acpi.h:78
@ HPET
Definition: acpi.h:75
@ FADT
Definition: acpi.h:75
@ CRAT
Definition: acpi.h:78
@ DMAR
Definition: acpi.h:75
@ HEST
Definition: acpi.h:75
@ DBG2
Definition: acpi.h:75
@ IVRS
Definition: acpi.h:75
@ MCFG
Definition: acpi.h:76
@ NHLT
Definition: acpi.h:78
@ BERT
Definition: acpi.h:75
#define SET_ERROR_TYPE
Definition: acpi.h:1121
enum cb_err acpi_soc_get_bert_region(void **region, size_t *length)
Definition: bert.c:8
struct acpi_dbg2_header acpi_dbg2_header_t
#define ACPI_IPMI_INT_TYPE_APIC
Definition: acpi.h:1070
unsigned long acpi_fill_lpit(unsigned long current)
Definition: lpit.c:8
#define ACPI_SRAT_STRUCTURE_GIA
Definition: acpi.h:299
struct acpi_slit acpi_slit_t
struct acpi_madt acpi_madt_t
#define EINJ_REG_IO()
Definition: acpi.h:1208
#define ACPI_FADT_REV_ACPI_6
Definition: acpi.h:776
#define ACPI_ADDRESS_SPACE_IO
Definition: acpi.h:105
#define GET_ERROR_TYPE
Definition: acpi.h:1122
struct dev_scope dev_scope_t
struct acpi_ivrs acpi_ivrs_t
dev_scope_type
Definition: acpi.h:485
@ SCOPE_MSI_HPET
Definition: acpi.h:489
@ SCOPE_PCI_SUB
Definition: acpi.h:487
@ SCOPE_IOAPIC
Definition: acpi.h:488
@ SCOPE_PCI_ENDPOINT
Definition: acpi.h:486
struct acpi_hpet acpi_hpet_t
struct acpi_lpit acpi_lpit_t
#define ACPI_STATUS_DEVICE_HIDDEN_ON
Definition: acpigen.h:24
static __always_inline uint32_t read32p(const uintptr_t addr)
Definition: mmio.h:220
uintptr_t cpu_get_lapic_addr(void)
Definition: lapic.c:63
unsigned int type
Definition: edid.c:57
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ALERT
BIOS_ALERT - Dying / Unrecoverable.
Definition: loglevel.h:41
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define RTC_CLK_ALTCENTURY
Definition: mc146818rtc.h:94
static unsigned long acpi_fill_srat(unsigned long current)
Definition: nb_acpi.c:102
static unsigned long acpi_fill_slit(unsigned long current)
Definition: nb_acpi.c:125
static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Definition: northbridge.c:666
static unsigned long acpi_fill_ivrs(acpi_ivrs_t *ivrs, unsigned long current)
Definition: northbridge.c:467
static unsigned long acpi_fill_dmar(unsigned long current)
Definition: acpi.c:14
@ DEVICE_PATH_PCI
Definition: path.h:9
@ DEVICE_PATH_CPU_CLUSTER
Definition: path.h:14
@ DEVICE_PATH_APIC
Definition: path.h:12
static const PCI_SUBCLASS memory[]
Definition: pci_class.c:66
#define PCI_FUNC(devfn)
Definition: pci_def.h:550
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
#define PCI_SLOT(devfn)
Definition: pci_def.h:549
static unsigned long acpi_fill_crat(struct acpi_crat_header *crat, unsigned long current)
Definition: agesa_acpi.c:532
#define IORESOURCE_MEM
Definition: resource.h:10
#define IORESOURCE_IO
Definition: resource.h:9
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
void acpi_fill_fadt(acpi_fadt_t *fadt)
Definition: acpi.c:58
unsigned long acpi_fill_madt(unsigned long current)
Definition: acpi.c:24
uintptr_t base
Definition: uart.c:17
void bubblesort(int *v, size_t num_entries, sort_order_t order)
Definition: sort.c:8
@ NUM_ASCENDING
Definition: sort.h:8
#define NULL
Definition: stddef.h:19
unsigned short uint16_t
Definition: stdint.h:11
uint64_t u64
Definition: stdint.h:54
unsigned int uint32_t
Definition: stdint.h:14
uint32_t u32
Definition: stdint.h:51
unsigned long uintptr_t
Definition: stdint.h:21
uint16_t u16
Definition: stdint.h:48
int8_t s8
Definition: stdint.h:44
uint8_t u8
Definition: stdint.h:45
unsigned char uint8_t
Definition: stdint.h:8
char * strncpy(char *to, const char *from, int count)
Definition: string.c:72
int strncmp(const char *s1, const char *s2, int maxlen)
Definition: string.c:114
int memcmp(const void *s1, const void *s2, size_t n)
Definition: memcmp.c:3
size_t strlen(const char *src)
Definition: string.c:42
u64 error_region
Definition: acpi.h:912
acpi_header_t header
Definition: acpi.h:910
u32 region_length
Definition: acpi.h:911
acpi_header_t header
Definition: acpi.h:452
acpi_header_t header
Definition: acpi.h:685
uint32_t devices_offset
Definition: acpi.h:686
uint32_t devices_count
Definition: acpi.h:687
acpi_header_t header
Definition: acpi.h:580
acpi_addr64_t reg
Definition: acpi.h:1151
u64 trigger_action_table
Definition: acpi.h:1184
u64 cmd_sts
Definition: acpi.h:1187
u64 op_state
Definition: acpi.h:1182
u64 err_inj_cap
Definition: acpi.h:1185
u64 op_status
Definition: acpi.h:1186
set_error_type_t setaddrtable
Definition: acpi.h:1190
u64 err_inject[EINJ_PARAM_NUM]
Definition: acpi.h:1183
acpi_einj_action_table_t trigger_action[1]
Definition: acpi.h:1167
acpi_einj_action_table_t action_table[ACTION_COUNT]
Definition: acpi.h:1219
acpi_injection_header_t inj_header
Definition: acpi.h:1218
acpi_header_t header
Definition: acpi.h:1217
u32 hardware_signature
Definition: acpi.h:848
u8 version
Definition: acpi.h:854
char signature[4]
Definition: acpi.h:846
u32 global_lock
Definition: acpi.h:850
u32 length
Definition: acpi.h:847
u32 x_firmware_waking_vector_l
Definition: acpi.h:852
u32 x_firmware_waking_vector_h
Definition: acpi.h:853
u32 flags
Definition: acpi.h:851
u32 firmware_waking_vector
Definition: acpi.h:849
u32 x_firmware_ctl_h
Definition: acpi.h:752
u8 century
Definition: acpi.h:743
acpi_header_t header
Definition: acpi.h:708
u32 dsdt
Definition: acpi.h:710
u8 reserved
Definition: acpi.h:711
u32 x_dsdt_l
Definition: acpi.h:753
u8 preferred_pm_profile
Definition: acpi.h:712
u32 x_firmware_ctl_l
Definition: acpi.h:751
u8 FADT_MinorVersion
Definition: acpi.h:750
u32 firmware_ctrl
Definition: acpi.h:709
u32 x_dsdt_h
Definition: acpi.h:754
u16 type
Definition: acpi.h:884
u32 max_section_per_record
Definition: acpi.h:892
u32 prealloc_erecords
Definition: acpi.h:889
u8 enabled
Definition: acpi.h:888
u16 source_id
Definition: acpi.h:885
u8 flags
Definition: acpi.h:887
u32 error_threshold_val
Definition: acpi.h:904
u8 length
Definition: acpi.h:898
u32 poll_interval
Definition: acpi.h:900
u32 vector
Definition: acpi.h:901
u32 sw2poll_threshold_win
Definition: acpi.h:903
u32 sw2poll_threshold_val
Definition: acpi.h:902
u16 conf_we
Definition: acpi.h:899
u32 error_threshold_win
Definition: acpi.h:905
acpi_header_t header
Definition: acpi.h:877
u32 error_source_count
Definition: acpi.h:878
u32 proximity_domain_initiator
Definition: acpi.h:241
u16 type
Definition: acpi.h:236
u32 length
Definition: acpi.h:238
u16 flags
Definition: acpi.h:239
u32 proximity_domain_memory
Definition: acpi.h:242
acpi_header_t header
Definition: acpi.h:229
u8 number
Definition: acpi.h:186
acpi_header_t header
Definition: acpi.h:183
u32 id
Definition: acpi.h:184
u16 min_tick
Definition: acpi.h:187
acpi_addr_t addr
Definition: acpi.h:185
acpi_header_t header
Definition: acpi.h:444
uint32_t type
Definition: acpi.h:381
uint16_t uid
Definition: acpi.h:383
uint32_t length
Definition: acpi.h:382
acpi_lpi_desc_hdr_t header
Definition: acpi.h:391
acpi_header_t header
Definition: acpi.h:363
u32 gsi_base
Definition: acpi.h:636
u32 ioapic_addr
Definition: acpi.h:635
u8 processor_id
Definition: acpi.h:613
u32 processor_id
Definition: acpi.h:656
u32 lapic_addr
Definition: acpi.h:354
acpi_header_t header
Definition: acpi.h:353
u32 flags
Definition: acpi.h:355
u16 pci_segment_group_number
Definition: acpi.h:218
u32 base_reserved
Definition: acpi.h:217
u8 start_bus_number
Definition: acpi.h:219
u32 base_address
Definition: acpi.h:216
acpi_header_t header
Definition: acpi.h:193
Definition: acpi.h:82
char signature[8]
Definition: acpi.h:83
u8 revision
Definition: acpi.h:86
u8 checksum
Definition: acpi.h:84
u8 ext_checksum
Definition: acpi.h:90
u64 xsdt_address
Definition: acpi.h:89
char oem_id[6]
Definition: acpi.h:85
u32 length
Definition: acpi.h:88
u32 rsdt_address
Definition: acpi.h:87
acpi_header_t header
Definition: acpi.h:171
u32 entry[MAX_ACPI_TABLES]
Definition: acpi.h:172
acpi_header_t header
Definition: acpi.h:347
u8 pci_bus
Definition: acpi.h:1088
u8 interface_type
Definition: acpi.h:1075
u8 pci_function
Definition: acpi.h:1090
u8 pci_device_flag
Definition: acpi.h:1081
u8 reserved
Definition: acpi.h:1076
acpi_addr_t base_address
Definition: acpi.h:1084
u16 specification_revision
Definition: acpi.h:1077
u8 pci_device
Definition: acpi.h:1089
u32 global_system_interrupt
Definition: acpi.h:1083
u8 uid[4]
Definition: acpi.h:1092
u8 interrupt_type
Definition: acpi.h:1078
u8 gpe
Definition: acpi.h:1079
acpi_header_t header
Definition: acpi.h:1074
u8 dev_handle_type
Definition: acpi.h:335
u32 proximity_domain
Definition: acpi.h:336
u32 flags
Definition: acpi.h:338
u8 length
Definition: acpi.h:333
u8 dev_handle[16]
Definition: acpi.h:337
u8 proximity_domain_7_0
Definition: acpi.h:305
u32 length_low
Definition: acpi.h:321
u32 base_address_high
Definition: acpi.h:320
u32 base_address_low
Definition: acpi.h:319
u32 proximity_domain
Definition: acpi.h:317
u8 length
Definition: acpi.h:316
u32 length_high
Definition: acpi.h:322
u32 flags
Definition: acpi.h:324
acpi_header_t header
Definition: acpi.h:291
char signature[4]
Definition: acpi.h:155
u32 asl_compiler_revision
Definition: acpi.h:163
char oem_id[6]
Definition: acpi.h:159
char asl_compiler_id[4]
Definition: acpi.h:162
u32 oem_revision
Definition: acpi.h:161
char oem_table_id[8]
Definition: acpi.h:160
u32 laml
Definition: acpi.h:200
acpi_header_t header
Definition: acpi.h:198
u16 platform_class
Definition: acpi.h:199
u64 lasa
Definition: acpi.h:201
acpi_header_t header
Definition: acpi.h:205
u32 start_method
Definition: acpi.h:209
u8 msp[12]
Definition: acpi.h:210
u64 control_area
Definition: acpi.h:208
u32 laml
Definition: acpi.h:211
u16 platform_class
Definition: acpi.h:206
u64 lasa
Definition: acpi.h:212
acpi_header_t header
Definition: acpi.h:416
acpi_header_t header
Definition: acpi.h:177
u64 entry[MAX_ACPI_TABLES]
Definition: acpi.h:178
unsigned int apic_id
Definition: path.h:72
Definition: device.h:76
DEVTREE_CONST struct device * dev
Definition: device.h:78
uint16_t secondary
Definition: device.h:84
u8 start_bus
Definition: acpi.h:498
u8 type
Definition: acpi.h:494
u8 dev
Definition: acpi.h:500
struct dev_scope::@187 path[0]
u8 fn
Definition: acpi.h:501
u8 length
Definition: acpi.h:495
u8 enumeration
Definition: acpi.h:497
struct apic_path apic
Definition: path.h:119
struct pci_path pci
Definition: path.h:116
enum device_path_type type
Definition: path.h:114
Definition: device.h:107
struct device_path path
Definition: device.h:115
struct device_operations * ops
Definition: device.h:143
DEVTREE_CONST struct bus * bus
Definition: device.h:108
DEVTREE_CONST struct device * next
Definition: device.h:113
unsigned int enabled
Definition: device.h:122
Definition: acpi.h:562
u8 device_name[]
Definition: acpi.h:567
u16 length
Definition: acpi.h:564
u8 device_number
Definition: acpi.h:566
u16 type
Definition: acpi.h:563
Definition: acpi.h:546
u8 flags
Definition: acpi.h:549
u16 segment
Definition: acpi.h:551
u16 type
Definition: acpi.h:547
u16 length
Definition: acpi.h:548
Definition: acpi.h:528
u16 length
Definition: acpi.h:530
u64 bar
Definition: acpi.h:534
u16 type
Definition: acpi.h:529
u8 flags
Definition: acpi.h:531
u16 segment
Definition: acpi.h:533
Definition: acpi.h:554
u16 length
Definition: acpi.h:556
u32 proximity_domain
Definition: acpi.h:559
u16 type
Definition: acpi.h:555
u64 base_address
Definition: acpi.h:558
Definition: acpi.h:537
u16 type
Definition: acpi.h:538
u16 segment
Definition: acpi.h:541
u64 bar
Definition: acpi.h:542
u16 length
Definition: acpi.h:539
u64 limit
Definition: acpi.h:543
Definition: acpi.h:570
u16 length
Definition: acpi.h:572
u8 flags
Definition: acpi.h:573
u16 segment_number
Definition: acpi.h:575
u16 type
Definition: acpi.h:571
Definition: gcov-glue.c:7
unsigned int devfn
Definition: path.h:54
Definition: region.h:76
unsigned long flags
Definition: resource.h:49
resource_t base
Definition: resource.h:45
resource_t size
Definition: resource.h:46
const unsigned int asl_revision
Definition: version.c:47