]> Git Repo - J-u-boot.git/blame - lib/acpi/acpi_table.c
acpi: Add a method to write tables for a device
[J-u-boot.git] / lib / acpi / acpi_table.c
CommitLineData
91fe8b79
SG
1// 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>
bfeb5d46
SG
10#include <dm.h>
11#include <cpu.h>
93f7f827 12#include <version.h>
bfeb5d46 13
bfeb5d46
SG
14int 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}
91fe8b79
SG
39
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}
93f7f827
SG
92
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}
This page took 0.03528 seconds and 4 git commands to generate.