1 /* $NetBSD: efiacpi.c,v 1.13 2022/08/14 11:26:41 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 void *acpi_root = NULL; 53 static void *smbios_table = NULL; 54 55 static int acpi_enabled = 1; 56 57 int 58 efi_acpi_probe(void) 59 { 60 EFI_STATUS status; 61 62 status = LibGetSystemConfigurationTable(&Acpi20TableGuid, &acpi_root); 63 if (EFI_ERROR(status)) 64 return EIO; 65 66 status = LibGetSystemConfigurationTable(&Smbios3TableGuid, &smbios_table); 67 if (EFI_ERROR(status)) { 68 status = LibGetSystemConfigurationTable(&SmbiosTableGuid, &smbios_table); 69 } 70 if (EFI_ERROR(status)) { 71 smbios_table = NULL; 72 } 73 74 return 0; 75 } 76 77 int 78 efi_acpi_available(void) 79 { 80 return acpi_root != NULL && acpi_enabled; 81 } 82 83 int 84 efi_acpi_enabled(void) 85 { 86 return acpi_enabled; 87 } 88 89 void * 90 efi_acpi_root(void) 91 { 92 return acpi_root; 93 } 94 95 void * 96 efi_acpi_smbios(void) 97 { 98 return smbios_table; 99 } 100 101 static char model_buf[128]; 102 103 void 104 efi_acpi_enable(int val) 105 { 106 if (acpi_root == NULL) { 107 printf("No ACPI node\n"); 108 } else 109 acpi_enabled = val; 110 } 111 112 const char * 113 efi_acpi_get_model(void) 114 { 115 struct smbtable smbios; 116 struct smbios_sys *psys; 117 const char *s; 118 char *buf; 119 120 memset(model_buf, 0, sizeof(model_buf)); 121 122 if (smbios_table != NULL) { 123 smbios_init(smbios_table); 124 125 buf = model_buf; 126 smbios.cookie = 0; 127 if (smbios_find_table(SMBIOS_TYPE_SYSTEM, &smbios)) { 128 psys = smbios.tblhdr; 129 if ((s = smbios_get_string(&smbios, psys->vendor, buf, 64)) != NULL) { 130 buf += strlen(s); 131 *buf++ = ' '; 132 } 133 smbios_get_string(&smbios, psys->product, buf, 64); 134 } 135 } 136 137 if (model_buf[0] == '\0') 138 strcpy(model_buf, "ACPI"); 139 140 return model_buf; 141 } 142 143 void 144 efi_acpi_show(void) 145 { 146 struct acpi_rdsp *rsdp = acpi_root; 147 148 if (!efi_acpi_available()) { 149 return; 150 } 151 152 command_printtab("ACPI", "v%02d %c%c%c%c%c%c\n", rsdp->revision, 153 rsdp->oemid[0], rsdp->oemid[1], rsdp->oemid[2], 154 rsdp->oemid[3], rsdp->oemid[4], rsdp->oemid[5]); 155 156 if (smbios_table) { 157 command_printtab("SMBIOS", "%s\n", efi_acpi_get_model()); 158 } 159 } 160