167760Smsmith/*- 283181Smsmith * Copyright (c) 2000,2001 Michael Smith 367760Smsmith * Copyright (c) 2000 BSDi 467760Smsmith * All rights reserved. 567760Smsmith * 667760Smsmith * Redistribution and use in source and binary forms, with or without 767760Smsmith * modification, are permitted provided that the following conditions 867760Smsmith * are met: 967760Smsmith * 1. Redistributions of source code must retain the above copyright 1067760Smsmith * notice, this list of conditions and the following disclaimer. 1167760Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1267760Smsmith * notice, this list of conditions and the following disclaimer in the 1367760Smsmith * documentation and/or other materials provided with the distribution. 1467760Smsmith * 1567760Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1667760Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1767760Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1867760Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1967760Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2067760Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2167760Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2267760Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2367760Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2467760Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2567760Smsmith * SUCH DAMAGE. 2667760Smsmith */ 2767760Smsmith 28118030Sobrien#include <sys/cdefs.h> 29118030Sobrien__FBSDID("$FreeBSD: stable/11/sys/x86/acpica/OsdEnvironment.c 316303 2017-03-30 20:18:34Z jkim $"); 30118030Sobrien 31298951Sjhb#include <sys/types.h> 32167814Sjkim#include <sys/bus.h> 33297954Simp#include <sys/kernel.h> 34108026Smarcel#include <sys/sysctl.h> 3567760Smsmith 36193530Sjkim#include <contrib/dev/acpica/include/acpi.h> 37316303Sjkim#include <contrib/dev/acpica/include/aclocal.h> 38193530Sjkim#include <contrib/dev/acpica/include/actables.h> 3967760Smsmith 40215023Sjkimstatic u_long acpi_root_phys; 41108026Smarcel 42215023SjkimSYSCTL_ULONG(_machdep, OID_AUTO, acpi_root, CTLFLAG_RD, &acpi_root_phys, 0, 43215023Sjkim "The physical address of the RSDP"); 44108026Smarcel 4567760SmsmithACPI_STATUS 4667760SmsmithAcpiOsInitialize(void) 4767760Smsmith{ 48215023Sjkim 49215023Sjkim return (AE_OK); 5067760Smsmith} 5167760Smsmith 5267760SmsmithACPI_STATUS 5367760SmsmithAcpiOsTerminate(void) 5467760Smsmith{ 55215023Sjkim 56215023Sjkim return (AE_OK); 5767760Smsmith} 5880071Smsmith 59215023Sjkimstatic u_long 60215023Sjkimacpi_get_root_from_loader(void) 61215023Sjkim{ 62215023Sjkim long acpi_root; 63215023Sjkim 64297954Simp if (TUNABLE_ULONG_FETCH("acpi.rsdp", &acpi_root)) 65297954Simp return (acpi_root); 66297954Simp 67297954Simp /* 68297954Simp * The hints mechanism is unreliable (it fails if anybody ever 69297954Simp * compiled in hints to the kernel). It has been replaced 70297954Simp * by the tunable method, but is used here as a fallback to 71297954Simp * retain maximum compatibility between old loaders and new 72297954Simp * kernels. It can be removed after 11.0R. 73297954Simp */ 74215023Sjkim if (resource_long_value("acpi", 0, "rsdp", &acpi_root) == 0) 75215023Sjkim return (acpi_root); 76215023Sjkim 77215023Sjkim return (0); 78215023Sjkim} 79215023Sjkim 80215023Sjkimstatic u_long 81215023Sjkimacpi_get_root_from_memory(void) 82215023Sjkim{ 83281475Sjkim ACPI_PHYSICAL_ADDRESS acpi_root; 84215023Sjkim 85215023Sjkim if (ACPI_SUCCESS(AcpiFindRootPointer(&acpi_root))) 86215023Sjkim return (acpi_root); 87215023Sjkim 88215023Sjkim return (0); 89215023Sjkim} 90215023Sjkim 91167814SjkimACPI_PHYSICAL_ADDRESS 92167814SjkimAcpiOsGetRootPointer(void) 9380071Smsmith{ 94108026Smarcel 95215023Sjkim if (acpi_root_phys == 0) { 96215023Sjkim acpi_root_phys = acpi_get_root_from_loader(); 97215023Sjkim if (acpi_root_phys == 0) 98215023Sjkim acpi_root_phys = acpi_get_root_from_memory(); 99215023Sjkim } 100108026Smarcel 101215023Sjkim return (acpi_root_phys); 10280071Smsmith} 103