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