xref: /illumos-gate/usr/src/boot/efi/loader/acpi.c (revision f334afcfaebea1b7dc3430015651d8d748fa8a3e)
122028508SToomas Soome /*
222028508SToomas Soome  * This file and its contents are supplied under the terms of the
322028508SToomas Soome  * Common Development and Distribution License ("CDDL"), version 1.0.
422028508SToomas Soome  * You may only use this file in accordance with the terms of version
522028508SToomas Soome  * 1.0 of the CDDL.
622028508SToomas Soome  *
722028508SToomas Soome  * A full copy of the text of the CDDL should have accompanied this
822028508SToomas Soome  * source.  A copy of the CDDL is also available via the Internet at
922028508SToomas Soome  * http://www.illumos.org/license/CDDL.
1022028508SToomas Soome  */
1122028508SToomas Soome 
1222028508SToomas Soome /*
1322028508SToomas Soome  * Copyright 2016 Tooams Soome <tsoome@me.com>
1422028508SToomas Soome  */
1522028508SToomas Soome 
1622028508SToomas Soome #include <sys/cdefs.h>
1722028508SToomas Soome 
1822028508SToomas Soome #include <stand.h>
1922028508SToomas Soome #include <machine/stdarg.h>
2022028508SToomas Soome #include <bootstrap.h>
2122028508SToomas Soome #include <efi.h>
2222028508SToomas Soome #include <efilib.h>
23*f334afcfSToomas Soome #include <Guid/Acpi.h>
2422028508SToomas Soome 
2522028508SToomas Soome #include "platform/acfreebsd.h"
2622028508SToomas Soome #include "acconfig.h"
2722028508SToomas Soome #define	ACPI_SYSTEM_XFACE
2822028508SToomas Soome #include "actypes.h"
2922028508SToomas Soome #include "actbl.h"
3022028508SToomas Soome 
3122028508SToomas Soome ACPI_TABLE_RSDP	*rsdp;
32*f334afcfSToomas Soome EFI_GUID gEfiAcpiTableGuid = ACPI_TABLE_GUID;
33*f334afcfSToomas Soome EFI_GUID gEfiAcpi20TableGuid = EFI_ACPI_TABLE_GUID;
3422028508SToomas Soome 
3522028508SToomas Soome void
acpi_detect(void)3622028508SToomas Soome acpi_detect(void)
3722028508SToomas Soome {
3822028508SToomas Soome 	char		buf[24];
3922028508SToomas Soome 	int		revision;
4022028508SToomas Soome 
41*f334afcfSToomas Soome 	if ((rsdp = efi_get_table(&gEfiAcpi20TableGuid)) == NULL)
42*f334afcfSToomas Soome 		rsdp = efi_get_table(&gEfiAcpiTableGuid);
4322028508SToomas Soome 
4422028508SToomas Soome 	if (rsdp == NULL)
4522028508SToomas Soome 		return;
4622028508SToomas Soome 
4722028508SToomas Soome 	/* export values from the RSDP */
4822028508SToomas Soome #ifdef _LP64
4922028508SToomas Soome 	snprintf(buf, sizeof (buf), "0x%016llx", (unsigned long long)rsdp);
5022028508SToomas Soome #else
5122028508SToomas Soome 	snprintf(buf, sizeof (buf), "0x%08x", (unsigned int)rsdp);
5222028508SToomas Soome #endif
5322028508SToomas Soome 	setenv("acpi.rsdp", buf, 1);
5422028508SToomas Soome 	revision = rsdp->Revision;
5522028508SToomas Soome 	if (revision == 0)
5622028508SToomas Soome 		revision = 1;
5722028508SToomas Soome 	snprintf(buf, sizeof (buf), "%d", revision);
5822028508SToomas Soome 	setenv("acpi.revision", buf, 1);
5922028508SToomas Soome 	strncpy(buf, rsdp->OemId, sizeof (rsdp->OemId));
6022028508SToomas Soome 	buf[sizeof (rsdp->OemId)] = '\0';
6122028508SToomas Soome 	setenv("acpi.oem", buf, 1);
6222028508SToomas Soome #ifdef _LP64
6322028508SToomas Soome 	snprintf(buf, sizeof (buf), "0x%016llx",
6422028508SToomas Soome 	    (unsigned long long)rsdp->RsdtPhysicalAddress);
6522028508SToomas Soome #else
6622028508SToomas Soome 	snprintf(buf, sizeof (buf), "0x%08x", rsdp->RsdtPhysicalAddress);
6722028508SToomas Soome #endif
6822028508SToomas Soome 	setenv("acpi.rsdt", buf, 1);
6922028508SToomas Soome 	if (revision >= 2) {
7022028508SToomas Soome 		snprintf(buf, sizeof (buf), "0x%016llx",
7122028508SToomas Soome 		    (unsigned long long)rsdp->XsdtPhysicalAddress);
7222028508SToomas Soome 		setenv("acpi.xsdt", buf, 1);
7322028508SToomas Soome 		snprintf(buf, sizeof (buf), "%d", rsdp->Length);
7422028508SToomas Soome 		setenv("acpi.xsdt_length", buf, 1);
7522028508SToomas Soome 	}
7622028508SToomas Soome }
77