efiacpi.c revision 1.11 1 /* $NetBSD: efiacpi.c,v 1.11 2021/10/06 10:13:19 jmcneill Exp $ */
2
3 /*-
4 * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jared McNeill <jmcneill (at) invisible.ca>.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "efiboot.h"
33 #include "efiacpi.h"
34 #include "smbios.h"
35
36 struct acpi_rdsp {
37 char signature[8];
38 uint8_t checksum;
39 char oemid[6];
40 uint8_t revision;
41 uint32_t rsdtphys;
42 uint32_t length;
43 uint64_t xsdtphys;
44 uint8_t extcsum;
45 uint8_t reserved[3];
46 };
47
48 static EFI_GUID Acpi20TableGuid = ACPI_20_TABLE_GUID;
49 static EFI_GUID Smbios3TableGuid = SMBIOS3_TABLE_GUID;
50 static EFI_GUID SmbiosTableGuid = SMBIOS_TABLE_GUID;
51
52 static int acpi_enable = 1;
53 static void *acpi_root = NULL;
54 static void *smbios_table = NULL;
55
56 int
57 efi_acpi_probe(void)
58 {
59 EFI_STATUS status;
60
61 status = LibGetSystemConfigurationTable(&Acpi20TableGuid, &acpi_root);
62 if (EFI_ERROR(status))
63 return EIO;
64
65 status = LibGetSystemConfigurationTable(&Smbios3TableGuid, &smbios_table);
66 if (EFI_ERROR(status)) {
67 status = LibGetSystemConfigurationTable(&SmbiosTableGuid, &smbios_table);
68 }
69 if (EFI_ERROR(status)) {
70 smbios_table = NULL;
71 }
72
73 return 0;
74 }
75
76 int
77 efi_acpi_available(void)
78 {
79 return acpi_root != NULL;
80 }
81
82 int
83 efi_acpi_enabled(void)
84 {
85 return acpi_enable;
86 }
87
88 void
89 efi_acpi_enable(int enable)
90 {
91 acpi_enable = enable;
92 }
93
94 void *
95 efi_acpi_root(void)
96 {
97 return acpi_root;
98 }
99
100 void *
101 efi_acpi_smbios(void)
102 {
103 return smbios_table;
104 }
105
106 static char model_buf[128];
107
108 const char *
109 efi_acpi_get_model(void)
110 {
111 struct smbtable smbios;
112 struct smbios_sys *psys;
113 const char *s;
114 char *buf;
115
116 memset(model_buf, 0, sizeof(model_buf));
117
118 if (smbios_table != NULL) {
119 smbios_init(smbios_table);
120
121 buf = model_buf;
122 smbios.cookie = 0;
123 if (smbios_find_table(SMBIOS_TYPE_SYSTEM, &smbios)) {
124 psys = smbios.tblhdr;
125 if ((s = smbios_get_string(&smbios, psys->vendor, buf, 64)) != NULL) {
126 buf += strlen(s);
127 *buf++ = ' ';
128 }
129 smbios_get_string(&smbios, psys->product, buf, 64);
130 }
131 }
132
133 if (model_buf[0] == '\0')
134 strcpy(model_buf, "ACPI");
135
136 return model_buf;
137 }
138
139 void
140 efi_acpi_show(void)
141 {
142 struct acpi_rdsp *rsdp = acpi_root;
143
144 if (!efi_acpi_available())
145 return;
146
147 printf("ACPI: v%02d %c%c%c%c%c%c\n", rsdp->revision,
148 rsdp->oemid[0], rsdp->oemid[1], rsdp->oemid[2],
149 rsdp->oemid[3], rsdp->oemid[4], rsdp->oemid[5]);
150
151 if (smbios_table)
152 printf("SMBIOS: %s\n", efi_acpi_get_model());
153 }
154