Debian Codegraph @

src/acpi/acpi.c

raw symbols SCIP
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_iort.h>
18 #include <acpi/acpi_ivrs.h>
19 #include <acpi/acpigen.h>
20 #include <cbfs.h>
21 #include <cbmem.h>
22 #include <commonlib/helpers.h>
23 #include <console/console.h>
24 #include <cpu/cpu.h>
25 #include <device/device.h>
26 #include <device/mmio.h>
27 #include <device/pci.h>
28 #include <drivers/crb/tpm.h>
29 #include <drivers/uart/pl011.h>
30 #include <security/tpm/tss.h>
31 #include <string.h>
32 #include <types.h>
33 #include <version.h>
34
35 static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp);
36
37 u8 acpi_checksum(u8 *table, u32 length)
38 {
39 u8 ret = 0;
40 while (length--) {
41 ret += *table;
42 table++;
43 }
44 return -ret;
45 }
46
47 /**
48 * Add an ACPI table to the RSDT (and XSDT) structure, recalculate length
49 * and checksum.
50 */
51 void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
52 {
53 int i, entries_num;
54 acpi_rsdt_t *rsdt;
55 acpi_xsdt_t *xsdt;
56
57 /* The 32bit RSDT may not be valid if tables live above 4GiB */
58 rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
59 xsdt = (acpi_xsdt_t *)(uintptr_t)rsdp->xsdt_address;
60
61 /* This should always be MAX_ACPI_TABLES. */
62 entries_num = ARRAY_SIZE(xsdt->entry);
63
64 for (i = 0; i < entries_num; i++) {
65 if (xsdt->entry[i] == 0)
66 break;
67 }
68
69 if (i >= entries_num) {
70 printk(BIOS_ERR, "ACPI: Error: Could not add ACPI table, "
71 "too many tables.\n");
72 return;
73 }
74
75 /* Add table to the XSDT. */
76 xsdt->entry[i] = (u64)(uintptr_t)table;
77
78 /* Fix XSDT length or the kernel will assume invalid entries. */
79 xsdt->header.length = sizeof(acpi_header_t) + (sizeof(u64) * (i + 1));
80
81 /* Re-calculate checksum. */
82 xsdt->header.checksum = 0; /* Hope this won't get optimized away */
83 xsdt->header.checksum = acpi_checksum((u8 *)xsdt, xsdt->header.length);
84
85 /*
86 * And now the same thing for the RSDT. We use the same index as for
87 * now we want the XSDT and RSDT to always be in sync in coreboot.
88 */
89 if (rsdt && (uintptr_t)table < UINT32_MAX) {
90 /* Add table to the RSDT. */
91 rsdt->entry[i] = (u32)(uintptr_t)table;
92
93 /* Fix RSDT length. */
94 rsdt->header.length = sizeof(acpi_header_t) + (sizeof(u32) * (i + 1));
95
96 /* Re-calculate checksum. */
97 rsdt->header.checksum = 0;
98 rsdt->header.checksum = acpi_checksum((u8 *)rsdt, rsdt->header.length);
99 }
100
101 printk(BIOS_DEBUG, "ACPI: added table %d/%d, length now %d\n",
102 i + 1, entries_num, xsdt->header.length);
103 }
104
105 static enum cb_err acpi_fill_header(acpi_header_t *header, const char name[4],
106 enum acpi_tables table, uint32_t size)
107 {
108 if (!header)
109 return CB_ERR;
110
111 /* Fill out header fields. */
112 memcpy(header->signature, name, 4);
113 memcpy(header->oem_id, OEM_ID, 6);
114 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
115 memcpy(header->asl_compiler_id, ASLC, 4);
116
117 header->asl_compiler_revision = asl_revision;
118 header->revision = get_acpi_table_revision(table);
119 header->length = size;
120
121 return CB_SUCCESS;
122 }
123
124 static int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u64 base,
125 u16 seg_nr, u8 start, u8 end)
126 {
127 memset(mmconfig, 0, sizeof(*mmconfig));
128 mmconfig->base_address = base;
129 mmconfig->pci_segment_group_number = seg_nr;
130 mmconfig->start_bus_number = start;
131 mmconfig->end_bus_number = end;
132
133 return sizeof(acpi_mcfg_mmconfig_t);
134 }
135
136 static void acpi_create_madt(acpi_header_t *header, void *unused)
137 {
138 acpi_madt_t *madt = (acpi_madt_t *)header;
139 unsigned long current = (unsigned long)madt + sizeof(acpi_madt_t);
140
141 memset(madt, 0, sizeof(*madt));
142
143 if (acpi_fill_header(header, "APIC", MADT, sizeof(acpi_madt_t)) != CB_SUCCESS)
144 return;
145
146 current = acpi_arch_fill_madt(madt, current);
147
148 if (CONFIG(ACPI_CUSTOM_MADT))
149 current = acpi_fill_madt(current);
150
151 /* (Re)calculate length . */
152 header->length = current - (unsigned long)madt;
153 }
154
155 static unsigned long acpi_fill_mcfg(unsigned long current)
156 {
157 for (int i = 0; i < PCI_SEGMENT_GROUP_COUNT; i++) {
158 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
159 CONFIG_ECAM_MMCONF_BASE_ADDRESS + i * PCI_PER_SEGMENT_GROUP_ECAM_SIZE,
160 i,
161 0,
162 PCI_BUSES_PER_SEGMENT_GROUP - 1);
163 }
164
165 return current;
166 }
167
168 /* MCFG is defined in the PCI Firmware Specification 3.0. */
169 static void acpi_create_mcfg(acpi_header_t *header, void *unused)
170 {
171 acpi_mcfg_t *mcfg = (acpi_mcfg_t *)header;
172 unsigned long current = (unsigned long)mcfg + sizeof(acpi_mcfg_t);
173
174
175 if (acpi_fill_header(header, "MCFG", MCFG, sizeof(acpi_mcfg_t)) != CB_SUCCESS)
176 return;
177
178 if (CONFIG(ECAM_MMCONF_SUPPORT))
179 current = acpi_fill_mcfg(current);
180
181 /* (Re)calculate length */
182 header->length = current - (unsigned long)mcfg;
183 }
184
185 static void *get_tcpa_log(u32 *size)
186 {
187 const struct cbmem_entry *ce;
188 const u32 tcpa_default_log_len = 0x10000;
189 void *lasa;
190 ce = cbmem_entry_find(CBMEM_ID_TCPA_TCG_LOG);
191 if (ce) {
192 lasa = cbmem_entry_start(ce);
193 *size = cbmem_entry_size(ce);
194 printk(BIOS_DEBUG, "TCPA log found at %p\n", lasa);
195 return lasa;
196 }
197 lasa = cbmem_add(CBMEM_ID_TCPA_TCG_LOG, tcpa_default_log_len);
198 if (!lasa) {
199 printk(BIOS_ERR, "TCPA log creation failed\n");
200 return NULL;
201 }
202
203 printk(BIOS_DEBUG, "TCPA log created at %p\n", lasa);
204 memset(lasa, 0, tcpa_default_log_len);
205
206 *size = tcpa_default_log_len;
207 return lasa;
208 }
209
210 static void acpi_create_tcpa(acpi_header_t *header, void *unused)
211 {
212 if (tlcl_get_family() != TPM_1)
213 return;
214
215 acpi_tcpa_t *tcpa = (acpi_tcpa_t *)header;
216 u32 tcpa_log_len;
217 void *lasa;
218
219 lasa = get_tcpa_log(&tcpa_log_len);
220 if (!lasa)
221 return;
222
223 if (acpi_fill_header(header, "TCPA", TCPA, sizeof(acpi_tcpa_t)) != CB_SUCCESS)
224 return;
225
226 tcpa->platform_class = 0;
227 tcpa->laml = tcpa_log_len;
228 tcpa->lasa = (uintptr_t)lasa;
229 }
230
231 static void *get_tpm2_log(u32 *size)
232 {
233 const struct cbmem_entry *ce;
234 const u32 tpm2_default_log_len = 0x10000;
235 void *lasa;
236 ce = cbmem_entry_find(CBMEM_ID_TPM2_TCG_LOG);
237 if (ce) {
238 lasa = cbmem_entry_start(ce);
239 *size = cbmem_entry_size(ce);
240 printk(BIOS_DEBUG, "TPM2 log found at %p\n", lasa);
241 return lasa;
242 }
243 lasa = cbmem_add(CBMEM_ID_TPM2_TCG_LOG, tpm2_default_log_len);
244 if (!lasa) {
245 printk(BIOS_ERR, "TPM2 log creation failed\n");
246 return NULL;
247 }
248
249 printk(BIOS_DEBUG, "TPM2 log created at %p\n", lasa);
250 memset(lasa, 0, tpm2_default_log_len);
251
252 *size = tpm2_default_log_len;
253 return lasa;
254 }
255
256 static void acpi_create_tpm2(acpi_header_t *header, void *unused)
257 {
258 if (tlcl_get_family() != TPM_2)
259 return;
260
261 if (CONFIG(CRB_TPM) && !(CONFIG(SPI_TPM) || CONFIG(I2C_TPM) || CONFIG(MEMORY_MAPPED_TPM)))
262 if (!crb_tpm_is_active())
263 return;
264
265 acpi_tpm2_t *tpm2 = (acpi_tpm2_t *)header;
266 u32 tpm2_log_len;
267 void *lasa;
268
269 /*
270 * Some payloads like SeaBIOS depend on log area to use TPM2.
271 * Get the memory size and address of TPM2 log area or initialize it.
272 */
273 lasa = get_tpm2_log(&tpm2_log_len);
274 if (!lasa)
275 tpm2_log_len = 0;
276
277 if (acpi_fill_header(header, "TPM2", TPM2, sizeof(acpi_tpm2_t)) != CB_SUCCESS)
278 return;
279
280 /* Hard to detect for coreboot. Just set it to 0 */
281 tpm2->platform_class = 0;
282 if (CONFIG(CRB_TPM)) {
283 /* Must be set to 7 for CRB Support */
284 tpm2->control_area = crb_tpm_base_address() + 0x40;
285 tpm2->start_method = 7;
286 } else {
287 /* Must be set to 0 for FIFO interface support */
288 tpm2->control_area = 0;
289 tpm2->start_method = 6;
290 }
291 memset(tpm2->msp, 0, sizeof(tpm2->msp));
292
293 /* Fill the log area size and start address fields. */
294 tpm2->laml = tpm2_log_len;
295 tpm2->lasa = (uintptr_t)lasa;
296 }
297
298 static void acpi_ssdt_write_cbtable(void)
299 {
300 const struct cbmem_entry *cbtable;
301 uintptr_t base;
302 uint32_t size;
303
304 cbtable = cbmem_entry_find(CBMEM_ID_CBTABLE);
305 if (!cbtable)
306 return;
307 base = (uintptr_t)cbmem_entry_start(cbtable);
308 size = cbmem_entry_size(cbtable);
309
310 acpigen_write_device("CTBL");
311 acpigen_write_coreboot_hid(COREBOOT_ACPI_ID_CBTABLE);
312 acpigen_write_name_integer("_UID", 0);
313 if (CONFIG(EC_GOOGLE_CHROMEEC))
314 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
315 else
316 acpigen_write_STA(ACPI_STATUS_DEVICE_HIDDEN_ON);
317 acpigen_write_name("_CRS");
318 acpigen_write_resourcetemplate_header();
319 acpigen_resource_consumer_mmio(base, base + size - 1,
320 MEM_RSRC_FLAG_MEM_READ_ONLY
321 | MEM_RSRC_FLAG_MEM_ATTR_CACHE);
322 acpigen_write_resourcetemplate_footer();
323 acpigen_pop_len();
324 }
325
326 static void acpi_create_ssdt_generator(acpi_header_t *ssdt, void *unused)
327 {
328 unsigned long current = (unsigned long)ssdt + sizeof(acpi_header_t);
329
330 if (acpi_fill_header(ssdt, "SSDT", SSDT, sizeof(acpi_header_t)) != CB_SUCCESS)
331 return;
332
333 acpigen_set_current((char *)current);
334
335 /* Write object to declare coreboot tables */
336 acpi_ssdt_write_cbtable();
337
338 {
339 struct device *dev;
340 for (dev = all_devices; dev; dev = dev->next)
341 if (dev->enabled && dev->ops && dev->ops->acpi_fill_ssdt)
342 dev->ops->acpi_fill_ssdt(dev);
343 current = (unsigned long)acpigen_get_current();
344 }
345
346 /* (Re)calculate length and checksum. */
347 ssdt->length = current - (unsigned long)ssdt;
348 }
349
350 int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek,
351 u32 flags)
352 {
353 mem->type = 1; /* Memory affinity structure */
354 mem->length = sizeof(acpi_srat_mem_t);
355 mem->base_address_low = (basek << 10);
356 mem->base_address_high = (basek >> (32 - 10));
357 mem->length_low = (sizek << 10);
358 mem->length_high = (sizek >> (32 - 10));
359 mem->proximity_domain = node;
360 mem->flags = flags;
361
362 return mem->length;
363 }
364
365 int acpi_create_srat_gia_pci(acpi_srat_gia_t *gia, u32 proximity_domain,
366 struct device *dev, u32 flags)
367 {
368 /* Only handle PCI devices. */
369 if (dev->path.type != DEVICE_PATH_PCI)
370 return 0;
371
372 gia->type = ACPI_SRAT_STRUCTURE_GIA;
373 gia->length = sizeof(acpi_srat_gia_t);
374 gia->proximity_domain = proximity_domain;
375 gia->dev_handle_type = ACPI_SRAT_GIA_DEV_HANDLE_PCI;
376 /* First two bytes has segment number */
377 gia->dev_handle[0] = dev->upstream->segment_group;
378 gia->dev_handle[1] = 0;
379 gia->dev_handle[2] = dev->upstream->secondary; /* Byte 2 has bus number */
380 /* Byte 3 has bits 7:3 for dev, bits 2:0 for func */
381 gia->dev_handle[3] = dev->path.pci.devfn;
382 gia->flags = flags;
383
384 return gia->length;
385 }
386
387 /* http://www.microsoft.com/whdc/system/sysinternals/sratdwn.mspx */
388 void acpi_create_srat(acpi_srat_t *srat,
389 unsigned long (*acpi_fill_srat_func)(unsigned long current))
390 {
391 acpi_header_t *header = &(srat->header);
392 unsigned long current = (unsigned long)srat + sizeof(acpi_srat_t);
393
394 memset((void *)srat, 0, sizeof(acpi_srat_t));
395
396 if (acpi_fill_header(header, "SRAT", SRAT, sizeof(acpi_srat_t)) != CB_SUCCESS)
397 return;
398
399 srat->resv = 1; /* Spec: Reserved to 1 for backwards compatibility. */
400
401 current = acpi_fill_srat_func(current);
402
403 /* (Re)calculate length and checksum. */
404 header->length = current - (unsigned long)srat;
405 header->checksum = acpi_checksum((void *)srat, header->length);
406 }
407
408 int acpi_create_cedt_chbs(acpi_cedt_chbs_t *chbs, u32 uid, u32 cxl_ver, u64 base)
409 {
410 memset((void *)chbs, 0, sizeof(acpi_cedt_chbs_t));
411
412 chbs->type = ACPI_CEDT_STRUCTURE_CHBS;
413 chbs->length = sizeof(acpi_cedt_chbs_t);
414 chbs->uid = uid;
415 chbs->cxl_ver = cxl_ver;
416 chbs->base = base;
417
418 /*
419 * CXL spec 2.0 section 9.14.1.2 "CXL CHBS"
420 * CXL 1.1 spec compliant host bridge: 8KB
421 * CXL 2.0 spec compliant host bridge: 64KB
422 */
423 if (cxl_ver == ACPI_CEDT_CHBS_CXL_VER_1_1)
424 chbs->len = 8 * KiB;
425 else if (cxl_ver == ACPI_CEDT_CHBS_CXL_VER_2_0)
426 chbs->len = 64 * KiB;
427 else
428 printk(BIOS_ERR, "ACPI(%s:%s): Incorrect CXL version:%d\n", __FILE__, __func__,
429 cxl_ver);
430
431 return chbs->length;
432 }
433
434 int acpi_create_cedt_cfmws(acpi_cedt_cfmws_t *cfmws, u64 base_hpa, u64 window_size, u8 eniw,
435 u32 hbig, u16 restriction, u16 qtg_id, const u32 *interleave_target)
436 {
437 memset((void *)cfmws, 0, sizeof(acpi_cedt_cfmws_t));
438
439 cfmws->type = ACPI_CEDT_STRUCTURE_CFMWS;
440
441 u8 niw = 0;
442 if (eniw >= 8)
443 printk(BIOS_ERR, "ACPI(%s:%s): Incorrect eniw::%d\n", __FILE__, __func__, eniw);
444 else
445 /* NIW = 2 ** ENIW */
446 niw = 0x1 << eniw;
447 /* 36 + 4 * NIW */
448 cfmws->length = sizeof(acpi_cedt_cfmws_t) + 4 * niw;
449
450 cfmws->base_hpa = base_hpa;
451 cfmws->window_size = window_size;
452 cfmws->eniw = eniw;
453
454 // 0: Standard Modulo Arithmetic. Other values reserved.
455 cfmws->interleave_arithmetic = 0;
456
457 cfmws->hbig = hbig;
458 cfmws->restriction = restriction;
459 cfmws->qtg_id = qtg_id;
460 memcpy(&cfmws->interleave_target, interleave_target, 4 * niw);
461
462 return cfmws->length;
463 }
464
465 void acpi_create_cedt(acpi_cedt_t *cedt, unsigned long (*acpi_fill_cedt_func)(unsigned long current))
466 {
467 acpi_header_t *header = &(cedt->header);
468 unsigned long current = (unsigned long)cedt + sizeof(acpi_cedt_t);
469
470 memset((void *)cedt, 0, sizeof(acpi_cedt_t));
471
472 if (acpi_fill_header(header, "CEDT", CEDT, sizeof(acpi_cedt_t)) != CB_SUCCESS)
473 return;
474
475 current = acpi_fill_cedt_func(current);
476
477 /* (Re)calculate length and checksum. */
478 header->length = current - (unsigned long)cedt;
479 header->checksum = acpi_checksum((void *)cedt, header->length);
480 }
481
482 int acpi_create_hmat_mpda(acpi_hmat_mpda_t *mpda, u32 initiator, u32 memory)
483 {
484 memset((void *)mpda, 0, sizeof(acpi_hmat_mpda_t));
485
486 mpda->type = 0; /* Memory Proximity Domain Attributes structure */
487 mpda->length = sizeof(acpi_hmat_mpda_t);
488 /*
489 * Proximity Domain for Attached Initiator field is valid.
490 * Bit 1 and bit 2 are reserved since HMAT revision 2.
491 */
492 mpda->flags = (1 << 0);
493 mpda->proximity_domain_initiator = initiator;
494 mpda->proximity_domain_memory = memory;
495
496 return mpda->length;
497 }
498
499 void acpi_create_hmat(acpi_hmat_t *hmat,
500 unsigned long (*acpi_fill_hmat_func)(unsigned long current))
501 {
502 acpi_header_t *header = &(hmat->header);
503 unsigned long current = (unsigned long)hmat + sizeof(acpi_hmat_t);
504
505 memset((void *)hmat, 0, sizeof(acpi_hmat_t));
506
507 if (acpi_fill_header(header, "HMAT", HMAT, sizeof(acpi_hmat_t)) != CB_SUCCESS)
508 return;
509
510 current = acpi_fill_hmat_func(current);
511
512 /* (Re)calculate length and checksum. */
513 header->length = current - (unsigned long)hmat;
514 header->checksum = acpi_checksum((void *)hmat, header->length);
515 }
516
517 /* http://h21007.www2.hp.com/portal/download/files/unprot/Itanium/slit.pdf */
518 void acpi_create_slit(acpi_slit_t *slit,
519 unsigned long (*acpi_fill_slit_func)(unsigned long current))
520 {
521 acpi_header_t *header = &(slit->header);
522 unsigned long current = (unsigned long)slit + sizeof(acpi_slit_t);
523
524 memset((void *)slit, 0, sizeof(acpi_slit_t));
525
526 if (acpi_fill_header(header, "SLIT", SLIT, sizeof(acpi_slit_t)) != CB_SUCCESS)
527 return;
528
529 current = acpi_fill_slit_func(current);
530
531 /* (Re)calculate length and checksum. */
532 header->length = current - (unsigned long)slit;
533 header->checksum = acpi_checksum((void *)slit, header->length);
534 }
535
536 /*
537 * This method adds the ACPI error injection capability. It fills the default information.
538 * HW dependent code (caller) can modify the defaults upon return. If no changes are necessary
539 * and the defaults are acceptable then caller can simply add the table (acpi_add_table).
540 * INPUTS:
541 * einj - ptr to the starting location of EINJ table
542 * actions - number of actions to trigger an error (HW dependent)
543 * addr - address of trigger action table. This should be ACPI reserved memory and it will be
544 * shared between OS and FW.
545 */
546 void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions)
547 {
548 int i;
549 acpi_header_t *header = &(einj->header);
550 acpi_injection_header_t *inj_header = &(einj->inj_header);
551 acpi_einj_smi_t *einj_smi = (acpi_einj_smi_t *)addr;
552 acpi_einj_trigger_table_t *tat;
553 if (!header)
554 return;
555
556 printk(BIOS_DEBUG, "%s einj_smi = %p\n", __func__, einj_smi);
557 memset(einj_smi, 0, sizeof(acpi_einj_smi_t));
558 tat = (acpi_einj_trigger_table_t *)((uint8_t *)einj_smi + sizeof(acpi_einj_smi_t));
559 tat->header_size = 16;
560 tat->revision = 0;
561 tat->table_size = sizeof(acpi_einj_trigger_table_t) +
562 sizeof(acpi_einj_action_table_t) * actions - 1;
563 tat->entry_count = actions;
564 printk(BIOS_DEBUG, "%s trigger_action_table = %p\n", __func__, tat);
565
566 for (i = 0; i < actions; i++) {
567 tat->trigger_action[i].action = TRIGGER_ERROR;
568 tat->trigger_action[i].instruction = NO_OP;
569 tat->trigger_action[i].flags = FLAG_IGNORE;
570 tat->trigger_action[i].reg.space_id = ACPI_ADDRESS_SPACE_MEMORY;
571 tat->trigger_action[i].reg.bit_width = 64;
572 tat->trigger_action[i].reg.bit_offset = 0;
573 tat->trigger_action[i].reg.access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS;
574 tat->trigger_action[i].reg.addr = 0;
575 tat->trigger_action[i].value = 0;
576 tat->trigger_action[i].mask = 0xFFFFFFFF;
577 }
578
579 acpi_einj_action_table_t default_actions[ACTION_COUNT] = {
580 [0] = {
581 .action = BEGIN_INJECT_OP,
582 .instruction = WRITE_REGISTER_VALUE,
583 .flags = FLAG_PRESERVE,
584 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_state),
585 .value = 0,
586 .mask = 0xFFFFFFFF
587 },
588 [1] = {
589 .action = GET_TRIGGER_ACTION_TABLE,
590 .instruction = READ_REGISTER,
591 .flags = FLAG_IGNORE,
592 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->trigger_action_table),
593 .value = 0,
594 .mask = 0xFFFFFFFFFFFFFFFF
595 },
596 [2] = {
597 .action = SET_ERROR_TYPE,
598 .instruction = WRITE_REGISTER,
599 .flags = FLAG_PRESERVE,
600 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->err_inject[0]),
601 .value = 0,
602 .mask = 0xFFFFFFFF
603 },
604 [3] = {
605 .action = GET_ERROR_TYPE,
606 .instruction = READ_REGISTER,
607 .flags = FLAG_IGNORE,
608 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->err_inj_cap),
609 .value = 0,
610 .mask = 0xFFFFFFFF
611 },
612 [4] = {
613 .action = END_INJECT_OP,
614 .instruction = WRITE_REGISTER_VALUE,
615 .flags = FLAG_PRESERVE,
616 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_state),
617 .value = 0,
618 .mask = 0xFFFFFFFF
619
620 },
621 [5] = {
622 .action = EXECUTE_INJECT_OP,
623 .instruction = WRITE_REGISTER_VALUE,
624 .flags = FLAG_PRESERVE,
625 .reg = EINJ_REG_IO(),
626 .value = 0x9a,
627 .mask = 0xFFFF,
628 },
629 [6] = {
630 .action = CHECK_BUSY_STATUS,
631 .instruction = READ_REGISTER_VALUE,
632 .flags = FLAG_IGNORE,
633 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->op_status),
634 .value = 1,
635 .mask = 1,
636 },
637 [7] = {
638 .action = GET_CMD_STATUS,
639 .instruction = READ_REGISTER,
640 .flags = FLAG_PRESERVE,
641 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->cmd_sts),
642 .value = 0,
643 .mask = 0x1fe,
644 },
645 [8] = {
646 .action = SET_ERROR_TYPE_WITH_ADDRESS,
647 .instruction = WRITE_REGISTER,
648 .flags = FLAG_PRESERVE,
649 .reg = EINJ_REG_MEMORY((u64)(uintptr_t)&einj_smi->setaddrtable),
650 .value = 1,
651 .mask = 0xffffffff
652 }
653 };
654
655 einj_smi->err_inj_cap = ACPI_EINJ_DEFAULT_CAP;
656 einj_smi->trigger_action_table = (u64)(uintptr_t)tat;
657
658 for (i = 0; i < ACTION_COUNT; i++)
659 printk(BIOS_DEBUG, "default_actions[%d].reg.addr is %llx\n", i,
660 default_actions[i].reg.addr);
661
662 memset((void *)einj, 0, sizeof(*einj));
663
664 if (acpi_fill_header(header, "EINJ", EINJ, sizeof(acpi_einj_t)) != CB_SUCCESS)
665 return;
666
667 inj_header->einj_header_size = sizeof(acpi_injection_header_t);
668 inj_header->entry_count = ACTION_COUNT;
669
670 printk(BIOS_DEBUG, "%s einj->action_table = %p\n",
671 __func__, einj->action_table);
672 memcpy((void *)einj->action_table, (void *)default_actions, sizeof(einj->action_table));
673 header->checksum = acpi_checksum((void *)einj, sizeof(*einj));
674 }
675
676 void acpi_create_vfct(const struct device *device,
677 acpi_vfct_t *vfct,
678 unsigned long (*acpi_fill_vfct_func)(const struct device *device,
679 acpi_vfct_t *vfct_struct, unsigned long current))
680 {
681 acpi_header_t *header = &(vfct->header);
682 unsigned long current = (unsigned long)vfct + sizeof(acpi_vfct_t);
683
684 memset((void *)vfct, 0, sizeof(acpi_vfct_t));
685
686 if (acpi_fill_header(header, "VFCT", VFCT, sizeof(acpi_vfct_t)) != CB_SUCCESS)
687 return;
688
689 current = acpi_fill_vfct_func(device, vfct, current);
690
691 /* If no BIOS image, return with header->length == 0. */
692 if (!vfct->VBIOSImageOffset)
693 return;
694
695 /* (Re)calculate length and checksum. */
696 header->length = current - (unsigned long)vfct;
697 header->checksum = acpi_checksum((void *)vfct, header->length);
698 }
699
700 void acpi_create_ipmi(const struct device *device,
701 struct acpi_spmi *spmi,
702 const u16 ipmi_revision,
703 const acpi_addr_t *addr,
704 const enum acpi_ipmi_interface_type type,
705 const s8 gpe_interrupt,
706 const u32 apic_interrupt,
707 const u32 uid)
708 {
709 acpi_header_t *header = &(spmi->header);
710 memset((void *)spmi, 0, sizeof(struct acpi_spmi));
711
712 if (acpi_fill_header(header, "SPMI", SPMI, sizeof(struct acpi_spmi)) != CB_SUCCESS)
713 return;
714
715 spmi->reserved = 1;
716
717 if (device->path.type == DEVICE_PATH_PCI) {
718 spmi->pci_device_flag = ACPI_IPMI_PCI_DEVICE_FLAG;
719 spmi->pci_segment_group = device->upstream->segment_group;
720 spmi->pci_bus = device->upstream->secondary;
721 spmi->pci_device = device->path.pci.devfn >> 3;
722 spmi->pci_function = device->path.pci.devfn & 0x7;
723 } else if (type != IPMI_INTERFACE_SSIF) {
724 memcpy(spmi->uid, &uid, sizeof(spmi->uid));
725 }
726
727 spmi->base_address = *addr;
728 spmi->specification_revision = ipmi_revision;
729
730 spmi->interface_type = type;
731
732 if (gpe_interrupt >= 0 && gpe_interrupt < 32) {
733 spmi->gpe = gpe_interrupt;
734 spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_SCI;
735 }
736 if (apic_interrupt > 0) {
737 spmi->global_system_interrupt = apic_interrupt;
738 spmi->interrupt_type |= ACPI_IPMI_INT_TYPE_APIC;
739 }
740
741 /* Calculate checksum. */
742 header->checksum = acpi_checksum((void *)spmi, header->length);
743 }
744
745 void acpi_create_ivrs(acpi_ivrs_t *ivrs,
746 unsigned long (*acpi_fill_ivrs_func)(acpi_ivrs_t *ivrs_struct,
747 unsigned long current))
748 {
749 acpi_header_t *header = &(ivrs->header);
750 unsigned long current = (unsigned long)ivrs + sizeof(acpi_ivrs_t);
751
752 memset((void *)ivrs, 0, sizeof(acpi_ivrs_t));
753
754 if (acpi_fill_header(header, "IVRS", IVRS, sizeof(acpi_ivrs_t)) != CB_SUCCESS)
755 return;
756
757 current = acpi_fill_ivrs_func(ivrs, current);
758
759 /* (Re)calculate length and checksum. */
760 header->length = current - (unsigned long)ivrs;
761 header->checksum = acpi_checksum((void *)ivrs, header->length);
762 }
763
764 void acpi_create_crat(struct acpi_crat_header *crat,
765 unsigned long (*acpi_fill_crat_func)(struct acpi_crat_header *crat_struct,
766 unsigned long current))
767 {
768 acpi_header_t *header = &(crat->header);
769 unsigned long current = (unsigned long)crat + sizeof(struct acpi_crat_header);
770
771 memset((void *)crat, 0, sizeof(struct acpi_crat_header));
772
773 if (acpi_fill_header(header, "CRAT", CRAT, sizeof(struct acpi_crat_header)) != CB_SUCCESS)
774 return;
775
776 current = acpi_fill_crat_func(crat, current);
777
778 /* (Re)calculate length and checksum. */
779 header->length = current - (unsigned long)crat;
780 header->checksum = acpi_checksum((void *)crat, header->length);
781 }
782
783 static void acpi_create_dbg2(acpi_dbg2_header_t *dbg2,
784 int port_type, int port_subtype,
785 acpi_addr_t *address, uint32_t address_size,
786 const char *device_path)
787 {
788 uintptr_t current;
789 acpi_dbg2_device_t *device;
790 uint32_t *dbg2_addr_size;
791 acpi_header_t *header;
792 size_t path_len;
793 const char *path;
794 char *namespace;
795
796 /* Fill out header fields. */
797 current = (uintptr_t)dbg2;
798 memset(dbg2, 0, sizeof(acpi_dbg2_header_t));
799 header = &(dbg2->header);
800
801 if (acpi_fill_header(header, "DBG2", DBG2, sizeof(acpi_dbg2_header_t)) != CB_SUCCESS)
802 return;
803
804 /* One debug device defined */
805 dbg2->devices_offset = sizeof(acpi_dbg2_header_t);
806 dbg2->devices_count = 1;
807 current += sizeof(acpi_dbg2_header_t);
808
809 /* Device comes after the header */
810 device = (acpi_dbg2_device_t *)current;
811 memset(device, 0, sizeof(acpi_dbg2_device_t));
812 current += sizeof(acpi_dbg2_device_t);
813
814 device->revision = 0;
815 device->address_count = 1;
816 device->port_type = port_type;
817 device->port_subtype = port_subtype;
818
819 /* Base Address comes after device structure */
820 memcpy((void *)current, address, sizeof(acpi_addr_t));
821 device->base_address_offset = current - (uintptr_t)device;
822 current += sizeof(acpi_addr_t);
823
824 /* Address Size comes after address structure */
825 dbg2_addr_size = (uint32_t *)current;
826 device->address_size_offset = current - (uintptr_t)device;
827 *dbg2_addr_size = address_size;
828 current += sizeof(uint32_t);
829
830 /* Namespace string comes last, use '.' if not provided */
831 path = device_path ? : ".";
832 /* Namespace string length includes NULL terminator */
833 path_len = strlen(path) + 1;
834 namespace = (char *)current;
835 device->namespace_string_length = path_len;
836 device->namespace_string_offset = current - (uintptr_t)device;
837 strncpy(namespace, path, path_len);
838 current += path_len;
839
840 /* Update structure lengths and checksum */
841 device->length = current - (uintptr_t)device;
842 header->length = current - (uintptr_t)dbg2;
843 header->checksum = acpi_checksum((uint8_t *)dbg2, header->length);
844 }
845
846 static unsigned long acpi_write_dbg2_uart(acpi_rsdp_t *rsdp, unsigned long current,
847 int space_id, uint64_t base, uint32_t size,
848 int access_size, const char *name)
849 {
850 acpi_dbg2_header_t *dbg2 = (acpi_dbg2_header_t *)current;
851 acpi_addr_t address;
852
853 memset(&address, 0, sizeof(address));
854
855 address.space_id = space_id;
856 address.addrl = (uint32_t)base;
857 address.addrh = (uint32_t)((base >> 32) & 0xffffffff);
858 address.access_size = access_size;
859
860 int subtype;
861 /* 16550-compatible with parameters defined in Generic Address Structure */
862 if (CONFIG(DRIVERS_UART_8250IO) || CONFIG(DRIVERS_UART_8250MEM))
863 subtype = ACPI_DBG2_PORT_SERIAL_16550;
864 else if (CONFIG(DRIVERS_UART_PL011))
865 subtype = ACPI_DBG2_PORT_SERIAL_ARM_PL011;
866 else
867 return current;
868
869 acpi_create_dbg2(dbg2,
870 ACPI_DBG2_PORT_SERIAL,
871 subtype,
872 &address, size,
873 name);
874
875 if (dbg2->header.length) {
876 current += dbg2->header.length;
877 current = acpi_align_current(current);
878 acpi_add_table(rsdp, dbg2);
879 }
880
881 return current;
882 }
883
884 unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
885 const struct device *dev, uint8_t access_size)
886 {
887 struct resource *res;
888
889 if (!dev) {
890 printk(BIOS_DEBUG, "%s: Device not found\n", __func__);
891 return current;
892 }
893 if (!dev->enabled) {
894 printk(BIOS_INFO, "%s: Device not enabled\n", __func__);
895 return current;
896 }
897 res = probe_resource(dev, PCI_BASE_ADDRESS_0);
898 if (!res) {
899 printk(BIOS_ERR, "%s: Unable to find resource for %s\n",
900 __func__, dev_path(dev));
901 return current;
902 }
903
904 int space_id;
905 if (res->flags & IORESOURCE_IO)
906 space_id = ACPI_ADDRESS_SPACE_IO;
907 else if (res->flags & IORESOURCE_MEM)
908 space_id = ACPI_ADDRESS_SPACE_MEMORY;
909 else {
910 printk(BIOS_ERR, "%s: Unknown address space type\n", __func__);
911 return current;
912 }
913
914 return acpi_write_dbg2_uart(rsdp, current, space_id, res->base, res->size, access_size, acpi_device_path(dev));
915 }
916
917 unsigned long acpi_pl011_write_dbg2_uart(acpi_rsdp_t *rsdp, unsigned long current,
918 uint64_t base, const char *name)
919 {
920 return acpi_write_dbg2_uart(rsdp, current, ACPI_ADDRESS_SPACE_MEMORY, base,
921 sizeof(struct pl011_uart), ACPI_ACCESS_SIZE_DWORD_ACCESS,
922 name);
923 }
924
925 unsigned long acpi_16550_mmio32_write_dbg2_uart(acpi_rsdp_t *rsdp, unsigned long current,
926 uint64_t base, const char *name)
927 {
928 return acpi_write_dbg2_uart(rsdp, current, ACPI_ADDRESS_SPACE_MEMORY, base,
929 0x100, ACPI_ACCESS_SIZE_DWORD_ACCESS,
930 name);
931 }
932
933 static void acpi_create_facs(void *header)
934 {
935 acpi_facs_t *facs = header;
936
937 memcpy(facs->signature, "FACS", 4);
938 facs->length = sizeof(acpi_facs_t);
939 facs->hardware_signature = 0;
940 facs->firmware_waking_vector = 0;
941 facs->global_lock = 0;
942 facs->flags = 0;
943 facs->x_firmware_waking_vector_l = 0;
944 facs->x_firmware_waking_vector_h = 0;
945 facs->version = get_acpi_table_revision(FACS);
946 }
947
948 static void acpi_write_rsdt(acpi_rsdt_t *rsdt, char *oem_id, char *oem_table_id)
949 {
950 acpi_header_t *header = &(rsdt->header);
951
952 if (acpi_fill_header(header, "RSDT", RSDT, sizeof(acpi_rsdt_t)) != CB_SUCCESS)
953 return;
954
955 /* Entries are filled in later, we come with an empty set. */
956
957 /* Fix checksum. */
958 header->checksum = acpi_checksum((void *)rsdt, sizeof(acpi_rsdt_t));
959 }
960
961 static void acpi_write_xsdt(acpi_xsdt_t *xsdt, char *oem_id, char *oem_table_id)
962 {
963 acpi_header_t *header = &(xsdt->header);
964
965 if (acpi_fill_header(header, "XSDT", XSDT, sizeof(acpi_xsdt_t)) != CB_SUCCESS)
966 return;
967
968 /* Entries are filled in later, we come with an empty set. */
969
970 /* Fix checksum. */
971 header->checksum = acpi_checksum((void *)xsdt, sizeof(acpi_xsdt_t));
972 }
973
974 static void acpi_write_rsdp(acpi_rsdp_t *rsdp, acpi_rsdt_t *rsdt,
975 acpi_xsdt_t *xsdt, char *oem_id)
976 {
977 memset(rsdp, 0, sizeof(acpi_rsdp_t));
978
979 memcpy(rsdp->signature, RSDP_SIG, 8);
980 memcpy(rsdp->oem_id, oem_id, 6);
981
982 rsdp->length = sizeof(acpi_rsdp_t);
983 rsdp->rsdt_address = (uintptr_t)rsdt;
984
985 /*
986 * Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2.
987 *
988 * Some OSes expect an XSDT to be present for RSD PTR revisions >= 2.
989 * If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR
990 * revision 0).
991 */
992 if (xsdt == NULL) {
993 rsdp->revision = 0;
994 } else {
995 rsdp->xsdt_address = (u64)(uintptr_t)xsdt;
996 rsdp->revision = get_acpi_table_revision(RSDP);
997 }
998
999 /* Calculate checksums. */
1000 rsdp->checksum = acpi_checksum((void *)rsdp, 20);
1001 rsdp->ext_checksum = acpi_checksum((void *)rsdp, sizeof(acpi_rsdp_t));
1002 }
1003
1004 unsigned long acpi_create_hest_error_source(acpi_hest_t *hest,
1005 acpi_hest_esd_t *esd, u16 type, void *data, u16 data_len)
1006 {
1007 acpi_header_t *header = &(hest->header);
1008 acpi_hest_hen_t *hen;
1009 void *pos;
1010 u16 len;
1011
1012 pos = esd;
1013 memset(pos, 0, sizeof(acpi_hest_esd_t));
1014 len = 0;
1015 esd->type = type; /* MCE */
1016 esd->source_id = hest->error_source_count;
1017 esd->flags = 0; /* FIRMWARE_FIRST */
1018 esd->enabled = 1;
1019 esd->prealloc_erecords = 1;
1020 esd->max_section_per_record = 0x1;
1021
1022 len += sizeof(acpi_hest_esd_t);
1023 pos = esd + 1;
1024
1025 switch (type) {
1026 case 0: /* MCE */
1027 break;
1028 case 1: /* CMC */
1029 hen = (acpi_hest_hen_t *)(pos);
1030 memset(pos, 0, sizeof(acpi_hest_hen_t));
1031 hen->type = 3; /* SCI? */
1032 hen->length = sizeof(acpi_hest_hen_t);
1033 hen->conf_we = 0; /* Configuration Write Enable. */
1034 hen->poll_interval = 0;
1035 hen->vector = 0;
1036 hen->sw2poll_threshold_val = 0;
1037 hen->sw2poll_threshold_win = 0;
1038 hen->error_threshold_val = 0;
1039 hen->error_threshold_win = 0;
1040 len += sizeof(acpi_hest_hen_t);
1041 pos = hen + 1;
1042 break;
1043 case 2: /* NMI */
1044 case 6: /* AER Root Port */
1045 case 7: /* AER Endpoint */
1046 case 8: /* AER Bridge */
1047 case 9: /* Generic Hardware Error Source. */
1048 /* TODO: */
1049 break;
1050 default:
1051 printk(BIOS_DEBUG, "Invalid type of Error Source.");
1052 break;
1053 }
1054 hest->error_source_count++;
1055
1056 memcpy(pos, data, data_len);
1057 len += data_len;
1058 if (header)
1059 header->length += len;
1060
1061 return len;
1062 }
1063
1064 /* ACPI 4.0 */
1065 void acpi_write_hest(acpi_hest_t *hest,
1066 unsigned long (*acpi_fill_hest)(acpi_hest_t *hest))
1067 {
1068 acpi_header_t *header = &(hest->header);
1069
1070 memset(hest, 0, sizeof(acpi_hest_t));
1071
1072 if (acpi_fill_header(header, "HEST", HEST, sizeof(acpi_hest_t)) != CB_SUCCESS)
1073 return;
1074
1075 acpi_fill_hest(hest);
1076
1077 /* Calculate checksums. */
1078 header->checksum = acpi_checksum((void *)hest, header->length);
1079 }
1080
1081 /* ACPI 3.0b */
1082 static void acpi_create_bert(acpi_header_t *header, void *unused)
1083 {
1084 if (!CONFIG(ACPI_BERT))
1085 return;
1086
1087 acpi_bert_t *bert = (acpi_bert_t *)header;
1088
1089 void *region;
1090 size_t size;
1091 if (acpi_soc_get_bert_region(&region, &size) != CB_SUCCESS)
1092 return;
1093
1094 if (acpi_fill_header(header, "BERT", BERT, sizeof(acpi_bert_t)) != CB_SUCCESS)
1095 return;
1096
1097 bert->error_region = (uintptr_t)region;
1098 bert->region_length = (size_t)size;
1099 }
1100
1101 __weak void arch_fill_fadt(acpi_fadt_t *fadt) { }
1102 __weak void soc_fill_fadt(acpi_fadt_t *fadt) { }
1103 __weak void mainboard_fill_fadt(acpi_fadt_t *fadt) { }
1104
1105 static acpi_header_t *dsdt;
1106 static void acpi_create_fadt(acpi_header_t *header, void *arg1)
1107 {
1108 acpi_fadt_t *fadt = (acpi_fadt_t *)header;
1109 acpi_facs_t *facs = (acpi_facs_t *)(*(acpi_facs_t **)arg1);
1110
1111 if (acpi_fill_header(header, "FACP", FADT, sizeof(acpi_fadt_t)) != CB_SUCCESS)
1112 return;
1113
1114 fadt->FADT_MinorVersion = get_acpi_fadt_minor_version();
1115 if ((uintptr_t)facs <= UINT32_MAX)
1116 fadt->firmware_ctrl = (uintptr_t)facs;
1117 else
1118 fadt->x_firmware_ctl_h = (uint32_t)((uint64_t)(uintptr_t)facs >> 32);
1119 fadt->x_firmware_ctl_l = (uint32_t)(uintptr_t)facs;
1120
1121 if ((uintptr_t)dsdt <= UINT32_MAX)
1122 fadt->dsdt = (uintptr_t)dsdt;
1123 else
1124 fadt->x_dsdt_h = (uint32_t)((uint64_t)(uintptr_t)dsdt >> 32);
1125 fadt->x_dsdt_l = (uint32_t)(uintptr_t)dsdt;
1126
1127 /* should be 0 ACPI 3.0 */
1128 fadt->reserved = 0;
1129
1130 /* P_LVLx latencies are not used as CPU _CST will override them. */
1131 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
1132 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
1133
1134 /* Use CPU _PTC instead to provide P_CNT details. */
1135 fadt->duty_offset = 0;
1136 fadt->duty_width = 0;
1137
1138 fadt->preferred_pm_profile = acpi_get_preferred_pm_profile();
1139
1140 arch_fill_fadt(fadt);
1141
1142 acpi_fill_fadt(fadt);
1143
1144 soc_fill_fadt(fadt);
1145 mainboard_fill_fadt(fadt);
1146 }
1147
1148 static void acpi_create_lpit(acpi_header_t *header, void *unused)
1149 {
1150 if (!CONFIG(ACPI_LPIT))
1151 return;
1152
1153 acpi_lpit_t *lpit = (acpi_lpit_t *)header;
1154 unsigned long current = (unsigned long)lpit + sizeof(acpi_lpit_t);
1155
1156 if (acpi_fill_header(header, "LPIT", LPIT, sizeof(acpi_lpit_t)) != CB_SUCCESS)
1157 return;
1158
1159 current = acpi_fill_lpit(current);
1160
1161 /* (Re)calculate length. */
1162 header->length = current - (unsigned long)lpit;
1163 }
1164
1165 static void acpi_create_gtdt(acpi_header_t *header, void *unused)
1166 {
1167 if (!CONFIG(ACPI_GTDT))
1168 return;
1169
1170 acpi_gtdt_t *gtdt = (acpi_gtdt_t *)header;
1171 unsigned long current = (unsigned long)gtdt + sizeof(acpi_gtdt_t);
1172
1173 if (acpi_fill_header(header, "GTDT", GTDT, sizeof(acpi_gtdt_t)) != CB_SUCCESS)
1174 return;
1175
1176 /* Fill out header fields. */
1177 gtdt->platform_timer_offset = sizeof(acpi_gtdt_t);
1178
1179 acpi_soc_fill_gtdt(gtdt);
1180 current = acpi_soc_gtdt_add_timers(&gtdt->platform_timer_count, current);
1181
1182 /* (Re)calculate length. */
1183 header->length = current - (unsigned long)gtdt;
1184 }
1185
1186 unsigned long acpi_gtdt_add_timer_block(unsigned long current, const uint64_t address,
1187 struct acpi_gtdt_timer_entry *timers, size_t number)
1188 {
1189 struct acpi_gtdt_timer_block *block = (struct acpi_gtdt_timer_block *)current;
1190 memset(block, 0, sizeof(struct acpi_gtdt_timer_block));
1191
1192 assert(number < 8 && number != 0);
1193 const size_t entries_size = number * sizeof(struct acpi_gtdt_timer_entry);
1194
1195 block->header.type = ACPI_GTDT_TYPE_TIMER_BLOCK;
1196 block->header.length = sizeof(struct acpi_gtdt_timer_block)
1197 + entries_size;
1198 block->block_address = address;
1199 block->timer_count = number;
1200 block->timer_offset = sizeof(struct acpi_gtdt_timer_block);
1201 current += sizeof(struct acpi_gtdt_timer_block);
1202 memcpy((void *)current, timers, entries_size);
1203 current += entries_size;
1204 return current;
1205 }
1206
1207 unsigned long acpi_gtdt_add_watchdog(unsigned long current, uint64_t refresh_frame,
1208 uint64_t control_frame, uint32_t gsiv, uint32_t flags)
1209 {
1210 struct acpi_gtdt_watchdog *wd = (struct acpi_gtdt_watchdog *)current;
1211 memset(wd, 0, sizeof(struct acpi_gtdt_watchdog));
1212
1213 wd->header.type = ACPI_GTDT_TYPE_WATCHDOG;
1214 wd->header.length = sizeof(struct acpi_gtdt_watchdog);
1215 wd->refresh_frame_address = refresh_frame;
1216 wd->control_frame_address = control_frame;
1217 wd->timer_interrupt = gsiv;
1218 wd->timer_flags = flags;
1219
1220 return current + sizeof(struct acpi_gtdt_watchdog);
1221 }
1222
1223 static void acpi_create_iort(acpi_header_t *header, void *unused)
1224 {
1225 if (!CONFIG(ACPI_IORT))
1226 return;
1227
1228 acpi_iort_t *iort = (acpi_iort_t *)header;
1229 unsigned long current = (unsigned long)iort + sizeof(acpi_iort_t);
1230
1231 if (acpi_fill_header(header, "IORT", IORT, sizeof(acpi_iort_t)) != CB_SUCCESS)
1232 return;
1233
1234 iort->node_count = 0;
1235 iort->node_offset = current - (unsigned long)iort;
1236
1237 current = acpi_soc_fill_iort(iort, current);
1238
1239 /* (Re)calculate length */
1240 header->length = current - (unsigned long)iort;
1241 }
1242
1243 static void acpi_create_wdat(acpi_header_t *header, void *unused)
1244 {
1245 if (!CONFIG(ACPI_WDAT_WDT))
1246 return;
1247
1248 acpi_wdat_t *wdat = (acpi_wdat_t *)header;
1249 unsigned long current = (unsigned long)wdat + sizeof(acpi_wdat_t);
1250
1251 memset((void *)wdat, 0, sizeof(acpi_wdat_t));
1252
1253 if (acpi_fill_header(header, "WDAT", WDAT, sizeof(acpi_wdat_t)) != CB_SUCCESS)
1254 return;
1255
1256 current = acpi_soc_fill_wdat(wdat, current);
1257
1258 /* (Re)calculate length. */
1259 header->length = current - (unsigned long)wdat;
1260 }
1261
1262 unsigned long acpi_create_lpi_desc_ncst(acpi_lpi_desc_ncst_t *lpi_desc, uint16_t uid)
1263 {
1264 memset(lpi_desc, 0, sizeof(acpi_lpi_desc_ncst_t));
1265 lpi_desc->header.length = sizeof(acpi_lpi_desc_ncst_t);
1266 lpi_desc->header.type = ACPI_LPI_DESC_TYPE_NATIVE_CSTATE;
1267 lpi_desc->header.uid = uid;
1268
1269 return lpi_desc->header.length;
1270 }
1271
1272 static void acpi_create_pptt(acpi_header_t *header, void *unused)
1273 {
1274 if (!CONFIG(ACPI_PPTT))
1275 return;
1276
1277 if (acpi_fill_header(header, "PPTT", PPTT, sizeof(acpi_pptt_t)) != CB_SUCCESS)
1278 return;
1279
1280 acpi_pptt_t *pptt = (acpi_pptt_t *)header;
1281 acpi_create_pptt_body(pptt);
1282 }
1283
1284 static uint8_t acpi_spcr_type(void)
1285 {
1286 /* 16550-compatible with parameters defined in Generic Address Structure */
1287 if (CONFIG(DRIVERS_UART_8250IO) || CONFIG(DRIVERS_UART_8250MEM))
1288 return 0x12;
1289 if (CONFIG(DRIVERS_UART_PL011))
1290 return 0x3;
1291
1292 printk(BIOS_ERR, "%s: unknown serial type\n", __func__);
1293 return 0xff;
1294 }
1295
1296 static void acpi_create_spcr(acpi_header_t *header, void *unused)
1297 {
1298 acpi_spcr_t *spcr = (acpi_spcr_t *)header;
1299 struct lb_serial serial;
1300
1301 if (!CONFIG(CONSOLE_SERIAL))
1302 return;
1303
1304 if (fill_lb_serial(&serial) != CB_SUCCESS)
1305 return;
1306
1307 if (acpi_fill_header(header, "SPCR", SPCR, sizeof(acpi_spcr_t)) != CB_SUCCESS)
1308 return;
1309
1310 spcr->interface_type = acpi_spcr_type();
1311 assert(serial.type == LB_SERIAL_TYPE_IO_MAPPED
1312 || serial.type == LB_SERIAL_TYPE_MEMORY_MAPPED);
1313 spcr->base_address.space_id = serial.type == LB_SERIAL_TYPE_IO_MAPPED ?
1314 ACPI_ADDRESS_SPACE_IO : ACPI_ADDRESS_SPACE_MEMORY;
1315 spcr->base_address.bit_width = serial.regwidth * 8;
1316 spcr->base_address.bit_offset = 0;
1317 switch (serial.regwidth) {
1318 case 1:
1319 spcr->base_address.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
1320 break;
1321 case 2:
1322 spcr->base_address.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
1323 break;
1324 case 4:
1325 spcr->base_address.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
1326 break;
1327 default:
1328 printk(BIOS_ERR, "%s, Invalid serial regwidth\n", __func__);
1329 }
1330
1331 spcr->base_address.addrl = serial.baseaddr;
1332 spcr->base_address.addrh = 0;
1333 spcr->interrupt_type = 0;
1334 spcr->irq = 0;
1335 spcr->configured_baudrate = 0; /* Have the OS use whatever is currently set */
1336 spcr->parity = 0;
1337 spcr->stop_bits = 1;
1338 spcr->flow_control = 0;
1339 spcr->terminal_type = 2; /* 2 = VT-UTF8 */
1340 spcr->language = 0;
1341 spcr->pci_did = 0xffff;
1342 spcr->pci_vid = 0xffff;
1343
1344 header->checksum = acpi_checksum((void *)spcr, header->length);
1345 }
1346
1347 unsigned long __weak fw_cfg_acpi_tables(unsigned long start)
1348 {
1349 return 0;
1350 }
1351
1352 static void acpi_create_dsdt(acpi_header_t *header, void *dsdt_file_arg)
1353 {
1354 dsdt = header;
1355 acpi_header_t *dsdt_file = *(acpi_header_t **)dsdt_file_arg;
1356 unsigned long current = (unsigned long)header;
1357
1358 dsdt = (acpi_header_t *)current;
1359 memcpy(dsdt, dsdt_file, sizeof(acpi_header_t));
1360 if (dsdt->length >= sizeof(acpi_header_t)) {
1361 current += sizeof(acpi_header_t);
1362
1363 acpigen_set_current((char *)current);
1364
1365 if (CONFIG(ACPI_SOC_NVS))
1366 acpi_fill_gnvs();
1367 if (CONFIG(CHROMEOS_NVS))
1368 acpi_fill_cnvs();
1369
1370 current = (unsigned long)acpigen_get_current();
1371 memcpy((char *)current,
1372 (char *)dsdt_file + sizeof(acpi_header_t),
1373 dsdt->length - sizeof(acpi_header_t));
1374 current += dsdt->length - sizeof(acpi_header_t);
1375
1376 /* (Re)calculate length. */
1377 dsdt->length = current - (unsigned long)dsdt;
1378 }
1379 }
1380
1381 static void acpi_create_slic(acpi_header_t *header, void *slic_file_arg)
1382 {
1383 acpi_header_t *slic_file = *(acpi_header_t **)slic_file_arg;
1384 acpi_header_t *slic = header;
1385 if (slic_file)
1386 memcpy(slic, slic_file, slic_file->length);
1387 }
1388
1389 static uintptr_t coreboot_rsdp;
1390
1391 uintptr_t get_coreboot_rsdp(void)
1392 {
1393 return coreboot_rsdp;
1394 }
1395
1396 static void acpixtract_compatible_hexdump(const void *memory, size_t length)
1397 {
1398 size_t i, j;
1399 uint8_t *line;
1400 size_t num_bytes;
1401
1402 for (i = 0; i < length; i += 16) {
1403 num_bytes = MIN(length - i, 16);
1404 line = ((uint8_t *)memory) + i;
1405
1406 printk(BIOS_SPEW, " %04zX:", i);
1407 for (j = 0; j < num_bytes; j++)
1408 printk(BIOS_SPEW, " %02x", line[j]);
1409 for (; j < 16; j++)
1410 printk(BIOS_SPEW, " ");
1411 printk(BIOS_SPEW, " ");
1412 for (j = 0; j < num_bytes; j++)
1413 printk(BIOS_SPEW, "%c",
1414 isprint(line[j]) ? line[j] : '.');
1415 printk(BIOS_SPEW, "\n");
1416 }
1417 }
1418
1419 static void acpidump_print(void *table_ptr)
1420 {
1421 if (table_ptr == NULL)
1422 return;
1423 const acpi_header_t *header = (acpi_header_t *)table_ptr;
1424 const size_t table_size = header->length;
1425 printk(BIOS_SPEW, "%.4s @ 0x0000000000000000\n", header->signature);
1426 acpixtract_compatible_hexdump(table_ptr, table_size);
1427 printk(BIOS_SPEW, "\n");
1428 }
1429
1430 unsigned long write_acpi_tables(const unsigned long start)
1431 {
1432 unsigned long current;
1433 acpi_rsdp_t *rsdp;
1434 acpi_rsdt_t *rsdt = NULL;
1435 acpi_xsdt_t *xsdt = NULL;
1436 acpi_facs_t *facs = NULL;
1437 acpi_header_t *slic_file;
1438 acpi_header_t *ssdt = NULL;
1439 acpi_header_t *dsdt_file;
1440 struct device *dev;
1441 unsigned long fw;
1442 size_t slic_size, dsdt_size;
1443 char oem_id[6], oem_table_id[8];
1444
1445 const struct acpi_table_generator {
1446 void (*create_table)(acpi_header_t *table, void *arg);
1447 void *args;
1448 size_t min_size;
1449 } tables[] = {
1450 { acpi_create_dsdt, &dsdt_file, sizeof(acpi_header_t) },
1451 { acpi_create_fadt, &facs, sizeof(acpi_fadt_t) },
1452 { acpi_create_slic, &slic_file, sizeof(acpi_header_t) },
1453 { acpi_create_ssdt_generator, NULL, sizeof(acpi_header_t) },
1454 { acpi_create_mcfg, NULL, sizeof(acpi_mcfg_t) },
1455 { acpi_create_tcpa, NULL, sizeof(acpi_tcpa_t) },
1456 { acpi_create_tpm2, NULL, sizeof(acpi_tpm2_t) },
1457 { acpi_create_lpit, NULL, sizeof(acpi_lpit_t) },
1458 { acpi_create_madt, NULL, sizeof(acpi_header_t) },
1459 { acpi_create_bert, NULL, sizeof(acpi_bert_t) },
1460 { acpi_create_spcr, NULL, sizeof(acpi_spcr_t) },
1461 { acpi_create_gtdt, NULL, sizeof(acpi_gtdt_t) },
1462 { acpi_create_pptt, NULL, sizeof(acpi_pptt_t) },
1463 { acpi_create_iort, NULL, sizeof(acpi_iort_t) },
1464 { acpi_create_wdat, NULL, sizeof(acpi_wdat_t) },
1465 };
1466
1467 current = start;
1468
1469 /* Align ACPI tables to 16byte */
1470 current = acpi_align_current(current);
1471
1472 /* Special case for qemu */
1473 fw = fw_cfg_acpi_tables(current);
1474 if (fw) {
1475 rsdp = NULL;
1476 /* Find RSDP. */
1477 for (void *p = (void *)current; p < (void *)fw; p += 16) {
1478 if (valid_rsdp((acpi_rsdp_t *)p)) {
1479 rsdp = p;
1480 coreboot_rsdp = (uintptr_t)rsdp;
1481 break;
1482 }
1483 }
1484 if (!rsdp)
1485 return fw;
1486
1487 current = fw;
1488 current = acpi_align_current(current);
1489 if (rsdp->xsdt_address == 0) {
1490 acpi_rsdt_t *existing_rsdt = (acpi_rsdt_t *)(uintptr_t)rsdp->rsdt_address;
1491
1492 /*
1493 * Qemu only provides a smaller ACPI 1.0 RSDP, thus
1494 * allocate a bigger ACPI 2.0 RSDP structure.
1495 */
1496 rsdp = (acpi_rsdp_t *)current;
1497 current += sizeof(acpi_rsdp_t);
1498 coreboot_rsdp = (uintptr_t)rsdp;
1499
1500 xsdt = (acpi_xsdt_t *)current;
1501 current += sizeof(acpi_xsdt_t);
1502 current = acpi_align_current(current);
1503
1504 /*
1505 * Qemu only creates an RSDT.
1506 * Add an XSDT based on the existing RSDT entries.
1507 */
1508 acpi_write_rsdp(rsdp, existing_rsdt, xsdt, oem_id);
1509 acpi_write_xsdt(xsdt, oem_id, oem_table_id);
1510 /*
1511 * Copy existing entries to the new XSDT. This will override existing
1512 * RSDT entries with the same value.
1513 */
1514 for (int i = 0; existing_rsdt->entry[i]; i++)
1515 acpi_add_table(rsdp, (void *)(uintptr_t)existing_rsdt->entry[i]);
1516 }
1517
1518 /* Add BOOT0000 for Linux google firmware driver */
1519 printk(BIOS_DEBUG, "ACPI: * SSDT\n");
1520 ssdt = (acpi_header_t *)current;
1521 current += sizeof(acpi_header_t);
1522
1523 memset((void *)ssdt, 0, sizeof(acpi_header_t));
1524
1525 memcpy(&ssdt->signature, "SSDT", 4);
1526 ssdt->revision = get_acpi_table_revision(SSDT);
1527 memcpy(&ssdt->oem_id, OEM_ID, 6);
1528 memcpy(&ssdt->oem_table_id, oem_table_id, 8);
1529 ssdt->oem_revision = 42;
1530 memcpy(&ssdt->asl_compiler_id, ASLC, 4);
1531 ssdt->asl_compiler_revision = asl_revision;
1532 ssdt->length = sizeof(acpi_header_t);
1533
1534 acpigen_set_current((char *)current);
1535
1536 /* Write object to declare coreboot tables */
1537 acpi_ssdt_write_cbtable();
1538
1539 /* (Re)calculate length and checksum. */
1540 ssdt->length = current - (unsigned long)ssdt;
1541 ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length);
1542
1543 acpi_create_ssdt_generator(ssdt, NULL);
1544
1545 acpi_add_table(rsdp, ssdt);
1546
1547 return current;
1548 }
1549
1550 dsdt_file = cbfs_map(CONFIG_CBFS_PREFIX "/dsdt.aml", &dsdt_size);
1551 if (!dsdt_file) {
1552 printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n");
1553 return start;
1554 }
1555
1556 if (dsdt_file->length > dsdt_size
1557 || dsdt_file->length < sizeof(acpi_header_t)
1558 || memcmp(dsdt_file->signature, "DSDT", 4) != 0) {
1559 printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n");
1560 cbfs_unmap(dsdt_file);
1561 return start;
1562 }
1563
1564 slic_file = cbfs_map(CONFIG_CBFS_PREFIX "/slic", &slic_size);
1565 if (slic_file
1566 && (slic_file->length > slic_size
1567 || slic_file->length < sizeof(acpi_header_t)
1568 || (memcmp(slic_file->signature, "SLIC", 4) != 0
1569 && memcmp(slic_file->signature, "MSDM", 4) != 0))) {
1570 cbfs_unmap(slic_file);
1571 slic_file = 0;
1572 }
1573
1574 if (slic_file) {
1575 memcpy(oem_id, slic_file->oem_id, 6);
1576 memcpy(oem_table_id, slic_file->oem_table_id, 8);
1577 } else {
1578 memcpy(oem_id, OEM_ID, 6);
1579 memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8);
1580 }
1581
1582 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start);
1583
1584 /* We need at least an RSDP, RSDT for ACPI 1.0 compat, otherwise XSDT */
1585 rsdp = (acpi_rsdp_t *)current;
1586 coreboot_rsdp = (uintptr_t)rsdp;
1587 current += sizeof(acpi_rsdp_t);
1588 current = acpi_align_current(current);
1589 if (current + sizeof(acpi_rsdt_t) - 1 <= UINT32_MAX) {
1590 rsdt = (acpi_rsdt_t *)current;
1591 current += sizeof(acpi_rsdt_t);
1592 current = acpi_align_current(current);
1593 } else {
1594 printk(BIOS_INFO, "Not adding RSDT because tables reside above 4G.");
1595 }
1596
1597 xsdt = (acpi_xsdt_t *)current;
1598 current += sizeof(acpi_xsdt_t);
1599 current = acpi_align_current(current);
1600
1601 /* clear all table memory */
1602 memset((void *)start, 0, current - start);
1603
1604 acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id);
1605 acpi_write_rsdt(rsdt, oem_id, oem_table_id);
1606 acpi_write_xsdt(xsdt, oem_id, oem_table_id);
1607
1608 if (ENV_X86) {
1609 printk(BIOS_DEBUG, "ACPI: * FACS\n");
1610 current = ALIGN_UP(current, 64);
1611 facs = (acpi_facs_t *)current;
1612 current += sizeof(acpi_facs_t);
1613 current = acpi_align_current(current);
1614 acpi_create_facs(facs);
1615 }
1616
1617 for (size_t i = 0; i < ARRAY_SIZE(tables); i++) {
1618 acpi_header_t *header = (acpi_header_t *)current;
1619 memset(header, 0, tables[i].min_size);
1620 tables[i].create_table(header, tables[i].args);
1621 if (header->length < tables[i].min_size)
1622 continue;
1623 header->checksum = 0;
1624 header->checksum = acpi_checksum((void *)header, header->length);
1625 current += header->length;
1626 current = acpi_align_current(current);
1627
1628 if (tables[i].create_table == acpi_create_dsdt)
1629 continue;
1630
1631 printk(BIOS_DEBUG, "ACPI: * %.4s\n", header->signature);
1632 acpi_add_table(rsdp, header);
1633 }
1634
1635 /*
1636 * cbfs_unmap() uses mem_pool_free() which works correctly only
1637 * if freeing is done in reverse order than memory allocation.
1638 * This is why unmapping of dsdt_file must be done after
1639 * unmapping slic file.
1640 */
1641 cbfs_unmap(slic_file);
1642 cbfs_unmap(dsdt_file);
1643
1644 printk(BIOS_DEBUG, "current = %lx\n", current);
1645
1646 for (dev = all_devices; dev; dev = dev->next) {
1647 if (dev->ops && dev->ops->write_acpi_tables) {
1648 current = dev->ops->write_acpi_tables(dev, current,
1649 rsdp);
1650 current = acpi_align_current(current);
1651 }
1652 }
1653
1654 printk(BIOS_INFO, "ACPI: done.\n");
1655
1656 if (CONFIG(DEBUG_ACPICA_COMPATIBLE)) {
1657 printk(BIOS_DEBUG, "Printing ACPI tables in ACPICA compatible format\n");
1658 if (facs)
1659 acpidump_print(facs);
1660 acpidump_print(dsdt);
1661 for (size_t i = 0; xsdt->entry[i] != 0; i++) {
1662 acpidump_print((void *)(uintptr_t)xsdt->entry[i]);
1663 }
1664 printk(BIOS_DEBUG, "Done printing ACPI tables in ACPICA compatible format\n");
1665 }
1666
1667 return current;
1668 }
1669
1670 static acpi_rsdp_t *valid_rsdp(acpi_rsdp_t *rsdp)
1671 {
1672 if (strncmp((char *)rsdp, RSDP_SIG, sizeof(RSDP_SIG) - 1) != 0)
1673 return NULL;
1674
1675 printk(BIOS_DEBUG, "Looking on %p for valid checksum\n", rsdp);
1676
1677 if (acpi_checksum((void *)rsdp, 20) != 0)
1678 return NULL;
1679 printk(BIOS_DEBUG, "Checksum 1 passed\n");
1680
1681 if ((rsdp->revision > 1) && (acpi_checksum((void *)rsdp,
1682 rsdp->length) != 0))
1683 return NULL;
1684 printk(BIOS_DEBUG, "Checksum 2 passed all OK\n");
1685
1686 return rsdp;
1687 }
1688
1689 void *acpi_find_wakeup_vector(void)
1690 {
1691 char *p, *end;
1692 acpi_xsdt_t *xsdt;
1693 acpi_facs_t *facs;
1694 acpi_fadt_t *fadt = NULL;
1695 acpi_rsdp_t *rsdp = NULL;
1696 void *wake_vec;
1697 int i;
1698
1699 if (!acpi_is_wakeup_s3())
1700 return NULL;
1701
1702 printk(BIOS_DEBUG, "Trying to find the wakeup vector...\n");
1703
1704 /* Find RSDP. */
1705 for (p = (char *)0xe0000; p < (char *)0xfffff; p += 16) {
1706 rsdp = valid_rsdp((acpi_rsdp_t *)p);
1707 if (rsdp)
1708 break;
1709 }
1710
1711 if (rsdp == NULL) {
1712 printk(BIOS_ALERT,
1713 "No RSDP found, wake up from S3 not possible.\n");
1714 return NULL;
1715 }
1716
1717 printk(BIOS_DEBUG, "RSDP found at %p\n", rsdp);
1718 xsdt = (acpi_xsdt_t *)(uintptr_t)rsdp->xsdt_address;
1719
1720 end = (char *)xsdt + xsdt->header.length;
1721 printk(BIOS_DEBUG, "XSDT found at %p ends at %p\n", xsdt, end);
1722
1723 for (i = 0; ((char *)&xsdt->entry[i]) < end; i++) {
1724 fadt = (acpi_fadt_t *)(uintptr_t)xsdt->entry[i];
1725 if (strncmp((char *)fadt, "FACP", 4) == 0)
1726 break;
1727 fadt = NULL;
1728 }
1729
1730 if (fadt == NULL) {
1731 printk(BIOS_ALERT,
1732 "No FADT found, wake up from S3 not possible.\n");
1733 return NULL;
1734 }
1735
1736 printk(BIOS_DEBUG, "FADT found at %p\n", fadt);
1737 facs = (acpi_facs_t *)(uintptr_t)((uint64_t)fadt->x_firmware_ctl_l
1738 | (uint64_t)fadt->x_firmware_ctl_h << 32);
1739
1740 if (facs == NULL) {
1741 printk(BIOS_ALERT,
1742 "No FACS found, wake up from S3 not possible.\n");
1743 return NULL;
1744 }
1745
1746 printk(BIOS_DEBUG, "FACS found at %p\n", facs);
1747 wake_vec = (void *)(uintptr_t)facs->firmware_waking_vector;
1748 printk(BIOS_DEBUG, "OS waking vector is %p\n", wake_vec);
1749
1750 return wake_vec;
1751 }
1752
1753 __weak int acpi_get_gpe(int gpe)
1754 {
1755 return -1; /* implemented by SOC */
1756 }
1757
1758 u8 get_acpi_fadt_minor_version(void)
1759 {
1760 return ACPI_FADT_MINOR_VERSION_0;
1761 }
1762
1763 int get_acpi_table_revision(enum acpi_tables table)
1764 {
1765 switch (table) {
1766 case FADT:
1767 return ACPI_FADT_REV_ACPI_6;
1768 case MADT: /* ACPI 3.0: 2, ACPI 4.0/5.0: 3, ACPI 6.2b/6.3: 5 */
1769 return 3;
1770 case MCFG:
1771 return 1;
1772 case TCPA:
1773 return 2;
1774 case TPM2:
1775 return 4;
1776 case SSDT: /* ACPI 3.0 up to 6.3: 2 */
1777 return 2;
1778 case SRAT: /* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 up to 6.4: 3 */
1779 return 3;
1780 case HMAT: /* ACPI 6.4: 2 */
1781 return 2;
1782 case DMAR:
1783 return 1;
1784 case SLIT: /* ACPI 2.0 up to 6.3: 1 */
1785 return 1;
1786 case SPMI: /* IMPI 2.0 */
1787 return 5;
1788 case HPET: /* Currently 1. Table added in ACPI 2.0. */
1789 return 1;
1790 case VFCT: /* ACPI 2.0/3.0/4.0: 1 */
1791 return 1;
1792 case IVRS:
1793 return IVRS_FORMAT_MIXED;
1794 case DBG2:
1795 return 0;
1796 case FACS: /* ACPI 2.0/3.0: 1, ACPI 4.0 up to 6.3: 2 */
1797 return 1;
1798 case RSDT: /* ACPI 1.0 up to 6.3: 1 */
1799 return 1;
1800 case XSDT: /* ACPI 2.0 up to 6.3: 1 */
1801 return 1;
1802 case RSDP: /* ACPI 2.0 up to 6.3: 2 */
1803 return 2;
1804 case EINJ:
1805 return 1;
1806 case HEST:
1807 return 1;
1808 case NHLT:
1809 return 5;
1810 case BERT:
1811 return 1;
1812 case CEDT: /* CXL 3.0 section 9.17.1 */
1813 return 1;
1814 case CRAT:
1815 return 1;
1816 case LPIT: /* ACPI 5.1 up to 6.3: 0 */
1817 return 0;
1818 case SPCR:
1819 return 4;
1820 case GTDT:
1821 return 3;
1822 case PPTT: /* ACPI 6.4 */
1823 return 3;
1824 case IORT: /* IO Remapping Table E.e */
1825 return 6;
1826 case WDAT:
1827 return 1;
1828 default:
1829 return -1;
1830 }
1831 return -1;
1832 }