blob: 372f19b16d53675d7a9071051669a502f529e6f6 [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>
Simon Glass17968c32020-04-26 09:19:46 -060012#include <version.h>
Simon Glasse9629892020-04-08 16:57:39 -060013
Simon Glasse9629892020-04-08 16:57:39 -060014int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags)
15{
16 struct acpi_table_header *header = &dmar->header;
17 struct cpu_info info;
18 struct udevice *cpu;
19 int ret;
20
21 ret = uclass_first_device(UCLASS_CPU, &cpu);
22 if (ret)
23 return log_msg_ret("cpu", ret);
24 ret = cpu_get_info(cpu, &info);
25 if (ret)
26 return log_msg_ret("info", ret);
27 memset((void *)dmar, 0, sizeof(struct acpi_dmar));
28
29 /* Fill out header fields. */
30 acpi_fill_header(&dmar->header, "DMAR");
31 header->length = sizeof(struct acpi_dmar);
32 header->revision = acpi_get_table_revision(ACPITAB_DMAR);
33
34 dmar->host_address_width = info.address_width - 1;
35 dmar->flags = flags;
36
37 return 0;
38}
Simon Glassb2672ea2020-04-08 16:57:38 -060039
40int acpi_get_table_revision(enum acpi_tables table)
41{
42 switch (table) {
43 case ACPITAB_FADT:
44 return ACPI_FADT_REV_ACPI_3_0;
45 case ACPITAB_MADT:
46 return ACPI_MADT_REV_ACPI_3_0;
47 case ACPITAB_MCFG:
48 return ACPI_MCFG_REV_ACPI_3_0;
49 case ACPITAB_TCPA:
50 /* This version and the rest are open-coded */
51 return 2;
52 case ACPITAB_TPM2:
53 return 4;
54 case ACPITAB_SSDT: /* ACPI 3.0 upto 6.3: 2 */
55 return 2;
56 case ACPITAB_SRAT: /* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 to 6.3: 3 */
57 return 1; /* TODO Should probably be upgraded to 2 */
58 case ACPITAB_DMAR:
59 return 1;
60 case ACPITAB_SLIT: /* ACPI 2.0 upto 6.3: 1 */
61 return 1;
62 case ACPITAB_SPMI: /* IMPI 2.0 */
63 return 5;
64 case ACPITAB_HPET: /* Currently 1. Table added in ACPI 2.0 */
65 return 1;
66 case ACPITAB_VFCT: /* ACPI 2.0/3.0/4.0: 1 */
67 return 1;
68 case ACPITAB_IVRS:
69 return IVRS_FORMAT_FIXED;
70 case ACPITAB_DBG2:
71 return 0;
72 case ACPITAB_FACS: /* ACPI 2.0/3.0: 1, ACPI 4.0 to 6.3: 2 */
73 return 1;
74 case ACPITAB_RSDT: /* ACPI 1.0 upto 6.3: 1 */
75 return 1;
76 case ACPITAB_XSDT: /* ACPI 2.0 upto 6.3: 1 */
77 return 1;
78 case ACPITAB_RSDP: /* ACPI 2.0 upto 6.3: 2 */
79 return 2;
80 case ACPITAB_HEST:
81 return 1;
82 case ACPITAB_NHLT:
83 return 5;
84 case ACPITAB_BERT:
85 return 1;
86 case ACPITAB_SPCR:
87 return 2;
88 default:
89 return -EINVAL;
90 }
91}
Simon Glass17968c32020-04-26 09:19:46 -060092
93void acpi_fill_header(struct acpi_table_header *header, char *signature)
94{
95 memcpy(header->signature, signature, 4);
96 memcpy(header->oem_id, OEM_ID, 6);
97 memcpy(header->oem_table_id, OEM_TABLE_ID, 8);
98 header->oem_revision = U_BOOT_BUILD_DATE;
99 memcpy(header->aslc_id, ASLC_ID, 4);
100}