blob: 4633dcb948883eb8c24e6c7430ed340984b5c834 [file] [log] [blame]
Simon Glassb2672ea2020-04-08 16:57:38 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Generic code used to generate ACPI tables
4 *
5 * Copyright 2019 Google LLC
6 */
7
8#include <common.h>
9#include <acpi/acpi_table.h>
Simon Glasse9629892020-04-08 16:57:39 -060010#include <dm.h>
11#include <cpu.h>
12
13/* Temporary change to ensure bisectability */
14#ifndef CONFIG_SANDBOX
15int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags)
16{
17 struct acpi_table_header *header = &dmar->header;
18 struct cpu_info info;
19 struct udevice *cpu;
20 int ret;
21
22 ret = uclass_first_device(UCLASS_CPU, &cpu);
23 if (ret)
24 return log_msg_ret("cpu", ret);
25 ret = cpu_get_info(cpu, &info);
26 if (ret)
27 return log_msg_ret("info", ret);
28 memset((void *)dmar, 0, sizeof(struct acpi_dmar));
29
30 /* Fill out header fields. */
31 acpi_fill_header(&dmar->header, "DMAR");
32 header->length = sizeof(struct acpi_dmar);
33 header->revision = acpi_get_table_revision(ACPITAB_DMAR);
34
35 dmar->host_address_width = info.address_width - 1;
36 dmar->flags = flags;
37
38 return 0;
39}
40#endif
Simon Glassb2672ea2020-04-08 16:57:38 -060041
42int acpi_get_table_revision(enum acpi_tables table)
43{
44 switch (table) {
45 case ACPITAB_FADT:
46 return ACPI_FADT_REV_ACPI_3_0;
47 case ACPITAB_MADT:
48 return ACPI_MADT_REV_ACPI_3_0;
49 case ACPITAB_MCFG:
50 return ACPI_MCFG_REV_ACPI_3_0;
51 case ACPITAB_TCPA:
52 /* This version and the rest are open-coded */
53 return 2;
54 case ACPITAB_TPM2:
55 return 4;
56 case ACPITAB_SSDT: /* ACPI 3.0 upto 6.3: 2 */
57 return 2;
58 case ACPITAB_SRAT: /* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 to 6.3: 3 */
59 return 1; /* TODO Should probably be upgraded to 2 */
60 case ACPITAB_DMAR:
61 return 1;
62 case ACPITAB_SLIT: /* ACPI 2.0 upto 6.3: 1 */
63 return 1;
64 case ACPITAB_SPMI: /* IMPI 2.0 */
65 return 5;
66 case ACPITAB_HPET: /* Currently 1. Table added in ACPI 2.0 */
67 return 1;
68 case ACPITAB_VFCT: /* ACPI 2.0/3.0/4.0: 1 */
69 return 1;
70 case ACPITAB_IVRS:
71 return IVRS_FORMAT_FIXED;
72 case ACPITAB_DBG2:
73 return 0;
74 case ACPITAB_FACS: /* ACPI 2.0/3.0: 1, ACPI 4.0 to 6.3: 2 */
75 return 1;
76 case ACPITAB_RSDT: /* ACPI 1.0 upto 6.3: 1 */
77 return 1;
78 case ACPITAB_XSDT: /* ACPI 2.0 upto 6.3: 1 */
79 return 1;
80 case ACPITAB_RSDP: /* ACPI 2.0 upto 6.3: 2 */
81 return 2;
82 case ACPITAB_HEST:
83 return 1;
84 case ACPITAB_NHLT:
85 return 5;
86 case ACPITAB_BERT:
87 return 1;
88 case ACPITAB_SPCR:
89 return 2;
90 default:
91 return -EINVAL;
92 }
93}