OsdEnvironment.c revision 217265
1178476Sjb/*-
2178476Sjb * Copyright (c) 2000,2001 Michael Smith
3178476Sjb * Copyright (c) 2000 BSDi
4178476Sjb * All rights reserved.
5178476Sjb *
6178476Sjb * Redistribution and use in source and binary forms, with or without
7178476Sjb * modification, are permitted provided that the following conditions
8178476Sjb * are met:
9178476Sjb * 1. Redistributions of source code must retain the above copyright
10178476Sjb *    notice, this list of conditions and the following disclaimer.
11178476Sjb * 2. Redistributions in binary form must reproduce the above copyright
12178476Sjb *    notice, this list of conditions and the following disclaimer in the
13178476Sjb *    documentation and/or other materials provided with the distribution.
14178476Sjb *
15178476Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16178476Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17178476Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18178476Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19178476Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20178476Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21178476Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22178476Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23178476Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24178476Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25178476Sjb * SUCH DAMAGE.
26178476Sjb */
27178476Sjb
28178476Sjb#include <sys/cdefs.h>
29178476Sjb__FBSDID("$FreeBSD: head/sys/x86/acpica/OsdEnvironment.c 217265 2011-01-11 13:59:06Z jhb $");
30178476Sjb
31178476Sjb#include <sys/types.h>
32178476Sjb#include <sys/bus.h>
33178476Sjb#include <sys/sysctl.h>
34178476Sjb
35178476Sjb#include <contrib/dev/acpica/include/acpi.h>
36178476Sjb#include <contrib/dev/acpica/include/actables.h>
37178476Sjb
38178476Sjbstatic u_long acpi_root_phys;
39178476Sjb
40178476SjbSYSCTL_ULONG(_machdep, OID_AUTO, acpi_root, CTLFLAG_RD, &acpi_root_phys, 0,
41178476Sjb    "The physical address of the RSDP");
42178476Sjb
43178476SjbACPI_STATUS
44178476SjbAcpiOsInitialize(void)
45178476Sjb{
46178476Sjb
47178476Sjb	return (AE_OK);
48178476Sjb}
49178476Sjb
50178476SjbACPI_STATUS
51AcpiOsTerminate(void)
52{
53
54	return (AE_OK);
55}
56
57static u_long
58acpi_get_root_from_loader(void)
59{
60	long acpi_root;
61
62	if (resource_long_value("acpi", 0, "rsdp", &acpi_root) == 0)
63		return (acpi_root);
64
65	return (0);
66}
67
68static u_long
69acpi_get_root_from_memory(void)
70{
71	ACPI_SIZE acpi_root;
72
73	if (ACPI_SUCCESS(AcpiFindRootPointer(&acpi_root)))
74		return (acpi_root);
75
76	return (0);
77}
78
79ACPI_PHYSICAL_ADDRESS
80AcpiOsGetRootPointer(void)
81{
82
83	if (acpi_root_phys == 0) {
84		acpi_root_phys = acpi_get_root_from_loader();
85		if (acpi_root_phys == 0)
86			acpi_root_phys = acpi_get_root_from_memory();
87	}
88
89	return (acpi_root_phys);
90}
91