xref: /illumos-gate/usr/src/boot/efi/loader/acpi.c (revision d48be21240dfd051b689384ce2b23479d757f2d8)
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 
24 #include "platform/acfreebsd.h"
25 #include "acconfig.h"
26 #define ACPI_SYSTEM_XFACE
27 #include "actypes.h"
28 #include "actbl.h"
29 
30 ACPI_TABLE_RSDP	*rsdp;
31 static EFI_GUID acpi_guid = ACPI_TABLE_GUID;
32 static EFI_GUID acpi20_guid = ACPI_20_TABLE_GUID;
33 
34 void
35 acpi_detect(void)
36 {
37     char		buf[24];
38     int			revision;
39 
40     if ((rsdp = efi_get_table(&acpi20_guid)) == NULL)
41 	rsdp = efi_get_table(&acpi_guid);
42 
43     if (rsdp == NULL)
44 	return;
45 
46     /* export values from the RSDP */
47 #ifdef _LP64
48     snprintf(buf, sizeof (buf), "0x%016llx", (unsigned long long)rsdp);
49 #else
50     snprintf(buf, sizeof (buf), "0x%08x", (unsigned int)rsdp);
51 #endif
52     setenv("acpi.rsdp", buf, 1);
53     revision = rsdp->Revision;
54     if (revision == 0)
55 	revision = 1;
56     snprintf(buf, sizeof (buf), "%d", revision);
57     setenv("acpi.revision", buf, 1);
58     strncpy(buf, rsdp->OemId, sizeof(rsdp->OemId));
59     buf[sizeof(rsdp->OemId)] = '\0';
60     setenv("acpi.oem", buf, 1);
61 #ifdef _LP64
62     snprintf(buf, sizeof (buf), "0x%016llx",
63 	(unsigned long long)rsdp->RsdtPhysicalAddress);
64 #else
65     snprintf(buf, sizeof (buf), "0x%08x", rsdp->RsdtPhysicalAddress);
66 #endif
67     setenv("acpi.rsdt", buf, 1);
68     if (revision >= 2) {
69 	snprintf(buf, sizeof (buf), "0x%016llx",
70 	    (unsigned long long)rsdp->XsdtPhysicalAddress);
71 	setenv("acpi.xsdt", buf, 1);
72 	snprintf(buf, sizeof (buf), "%d", rsdp->Length);
73 	setenv("acpi.xsdt_length", buf, 1);
74     }
75 }
76