xref: /illumos-gate/usr/src/boot/efi/loader/acpi.c (revision 8c0e49e07bbdf2f210e329cb5044fa436481e710)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2016 Tooams Soome <tsoome@me.com>
14  */
15 
16 #include <sys/cdefs.h>
17 
18 #include <stand.h>
19 #include <machine/stdarg.h>
20 #include <bootstrap.h>
21 #include <efi.h>
22 #include <efilib.h>
23 #include <Guid/Acpi.h>
24 
25 #include "platform/acfreebsd.h"
26 #include "acconfig.h"
27 #define	ACPI_SYSTEM_XFACE
28 #include "actypes.h"
29 #include "actbl.h"
30 
31 ACPI_TABLE_RSDP	*rsdp;
32 EFI_GUID gEfiAcpiTableGuid = ACPI_TABLE_GUID;
33 EFI_GUID gEfiAcpi20TableGuid = EFI_ACPI_TABLE_GUID;
34 
35 void
36 acpi_detect(void)
37 {
38 	char		buf[24];
39 	int		revision;
40 
41 	if ((rsdp = efi_get_table(&gEfiAcpi20TableGuid)) == NULL)
42 		rsdp = efi_get_table(&gEfiAcpiTableGuid);
43 
44 	if (rsdp == NULL)
45 		return;
46 
47 	/* export values from the RSDP */
48 #ifdef _LP64
49 	snprintf(buf, sizeof (buf), "0x%016llx", (unsigned long long)rsdp);
50 #else
51 	snprintf(buf, sizeof (buf), "0x%08x", (unsigned int)rsdp);
52 #endif
53 	setenv("acpi.rsdp", buf, 1);
54 	revision = rsdp->Revision;
55 	if (revision == 0)
56 		revision = 1;
57 	snprintf(buf, sizeof (buf), "%d", revision);
58 	setenv("acpi.revision", buf, 1);
59 	strncpy(buf, rsdp->OemId, sizeof (rsdp->OemId));
60 	buf[sizeof (rsdp->OemId)] = '\0';
61 	setenv("acpi.oem", buf, 1);
62 #ifdef _LP64
63 	snprintf(buf, sizeof (buf), "0x%016llx",
64 	    (unsigned long long)rsdp->RsdtPhysicalAddress);
65 #else
66 	snprintf(buf, sizeof (buf), "0x%08x", rsdp->RsdtPhysicalAddress);
67 #endif
68 	setenv("acpi.rsdt", buf, 1);
69 	if (revision >= 2) {
70 		snprintf(buf, sizeof (buf), "0x%016llx",
71 		    (unsigned long long)rsdp->XsdtPhysicalAddress);
72 		setenv("acpi.xsdt", buf, 1);
73 		snprintf(buf, sizeof (buf), "%d", rsdp->Length);
74 		setenv("acpi.xsdt_length", buf, 1);
75 	}
76 }
77