167754Smsmith/******************************************************************************* 267754Smsmith * 367754Smsmith * Module Name: nsxfobj - Public interfaces to the ACPI subsystem 467754Smsmith * ACPI Object oriented interfaces 567754Smsmith * 667754Smsmith ******************************************************************************/ 767754Smsmith 8217365Sjkim/* 9281075Sdim * Copyright (C) 2000 - 2015, Intel Corp. 1070243Smsmith * All rights reserved. 1167754Smsmith * 12217365Sjkim * Redistribution and use in source and binary forms, with or without 13217365Sjkim * modification, are permitted provided that the following conditions 14217365Sjkim * are met: 15217365Sjkim * 1. Redistributions of source code must retain the above copyright 16217365Sjkim * notice, this list of conditions, and the following disclaimer, 17217365Sjkim * without modification. 18217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 19217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 20217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 21217365Sjkim * including a substantially similar Disclaimer requirement for further 22217365Sjkim * binary redistribution. 23217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 24217365Sjkim * of any contributors may be used to endorse or promote products derived 25217365Sjkim * from this software without specific prior written permission. 2667754Smsmith * 27217365Sjkim * Alternatively, this software may be distributed under the terms of the 28217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 29217365Sjkim * Software Foundation. 3067754Smsmith * 31217365Sjkim * NO WARRANTY 32217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 33217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 34217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 35217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 36217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 40217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 41217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 42217365Sjkim * POSSIBILITY OF SUCH DAMAGES. 43217365Sjkim */ 4467754Smsmith 45281075Sdim#define EXPORT_ACPI_INTERFACES 4667754Smsmith 47193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 48193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 49193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 5067754Smsmith 5167754Smsmith 5277424Smsmith#define _COMPONENT ACPI_NAMESPACE 5391116Smsmith ACPI_MODULE_NAME ("nsxfobj") 5467754Smsmith 5567754Smsmith/******************************************************************************* 5667754Smsmith * 5767754Smsmith * FUNCTION: AcpiGetType 5867754Smsmith * 5967754Smsmith * PARAMETERS: Handle - Handle of object whose type is desired 60151937Sjkim * RetType - Where the type will be placed 6167754Smsmith * 6267754Smsmith * RETURN: Status 6367754Smsmith * 6467754Smsmith * DESCRIPTION: This routine returns the type associatd with a particular handle 6567754Smsmith * 6667754Smsmith ******************************************************************************/ 6767754Smsmith 6867754SmsmithACPI_STATUS 6967754SmsmithAcpiGetType ( 7067754Smsmith ACPI_HANDLE Handle, 7167754Smsmith ACPI_OBJECT_TYPE *RetType) 7267754Smsmith{ 7367754Smsmith ACPI_NAMESPACE_NODE *Node; 7491116Smsmith ACPI_STATUS Status; 7567754Smsmith 7667754Smsmith 7767754Smsmith /* Parameter Validation */ 7867754Smsmith 7967754Smsmith if (!RetType) 8067754Smsmith { 8167754Smsmith return (AE_BAD_PARAMETER); 8267754Smsmith } 8367754Smsmith 8467754Smsmith /* 8567754Smsmith * Special case for the predefined Root Node 8667754Smsmith * (return type ANY) 8767754Smsmith */ 8867754Smsmith if (Handle == ACPI_ROOT_OBJECT) 8967754Smsmith { 9067754Smsmith *RetType = ACPI_TYPE_ANY; 9167754Smsmith return (AE_OK); 9267754Smsmith } 9367754Smsmith 9491116Smsmith Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 9591116Smsmith if (ACPI_FAILURE (Status)) 9691116Smsmith { 9791116Smsmith return (Status); 9891116Smsmith } 9967754Smsmith 10067754Smsmith /* Convert and validate the handle */ 10167754Smsmith 102200553Sjkim Node = AcpiNsValidateHandle (Handle); 10367754Smsmith if (!Node) 10467754Smsmith { 10591116Smsmith (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 10667754Smsmith return (AE_BAD_PARAMETER); 10767754Smsmith } 10867754Smsmith 10967754Smsmith *RetType = Node->Type; 11067754Smsmith 11167754Smsmith 11291116Smsmith Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 11391116Smsmith return (Status); 11467754Smsmith} 11567754Smsmith 116167802SjkimACPI_EXPORT_SYMBOL (AcpiGetType) 11767754Smsmith 118167802Sjkim 11967754Smsmith/******************************************************************************* 12067754Smsmith * 12167754Smsmith * FUNCTION: AcpiGetParent 12267754Smsmith * 12367754Smsmith * PARAMETERS: Handle - Handle of object whose parent is desired 12467754Smsmith * RetHandle - Where the parent handle will be placed 12567754Smsmith * 12667754Smsmith * RETURN: Status 12767754Smsmith * 12867754Smsmith * DESCRIPTION: Returns a handle to the parent of the object represented by 12967754Smsmith * Handle. 13067754Smsmith * 13167754Smsmith ******************************************************************************/ 13267754Smsmith 13367754SmsmithACPI_STATUS 13467754SmsmithAcpiGetParent ( 13567754Smsmith ACPI_HANDLE Handle, 13667754Smsmith ACPI_HANDLE *RetHandle) 13767754Smsmith{ 13867754Smsmith ACPI_NAMESPACE_NODE *Node; 139193267Sjkim ACPI_NAMESPACE_NODE *ParentNode; 14091116Smsmith ACPI_STATUS Status; 14167754Smsmith 14267754Smsmith 14367754Smsmith if (!RetHandle) 14467754Smsmith { 14567754Smsmith return (AE_BAD_PARAMETER); 14667754Smsmith } 14767754Smsmith 14867754Smsmith /* Special case for the predefined Root Node (no parent) */ 14967754Smsmith 15067754Smsmith if (Handle == ACPI_ROOT_OBJECT) 15167754Smsmith { 15267754Smsmith return (AE_NULL_ENTRY); 15367754Smsmith } 15467754Smsmith 15591116Smsmith Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 15691116Smsmith if (ACPI_FAILURE (Status)) 15791116Smsmith { 15891116Smsmith return (Status); 15991116Smsmith } 16067754Smsmith 16167754Smsmith /* Convert and validate the handle */ 16267754Smsmith 163200553Sjkim Node = AcpiNsValidateHandle (Handle); 16467754Smsmith if (!Node) 16567754Smsmith { 16667754Smsmith Status = AE_BAD_PARAMETER; 16767754Smsmith goto UnlockAndExit; 16867754Smsmith } 16967754Smsmith 17067754Smsmith /* Get the parent entry */ 17167754Smsmith 172209746Sjkim ParentNode = Node->Parent; 173200553Sjkim *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, ParentNode); 17467754Smsmith 175114237Snjl /* Return exception if parent is null */ 17667754Smsmith 177193267Sjkim if (!ParentNode) 17867754Smsmith { 17967754Smsmith Status = AE_NULL_ENTRY; 18067754Smsmith } 18167754Smsmith 18267754Smsmith 18367754SmsmithUnlockAndExit: 18467754Smsmith 18591116Smsmith (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 18667754Smsmith return (Status); 18767754Smsmith} 18867754Smsmith 189167802SjkimACPI_EXPORT_SYMBOL (AcpiGetParent) 19067754Smsmith 191167802Sjkim 19267754Smsmith/******************************************************************************* 19367754Smsmith * 194100966Siwasaki * FUNCTION: AcpiGetNextObject 19567754Smsmith * 196100966Siwasaki * PARAMETERS: Type - Type of object to be searched for 197100966Siwasaki * Parent - Parent object whose children we are getting 198100966Siwasaki * LastChild - Previous child that was found. 199100966Siwasaki * The NEXT child will be returned 200100966Siwasaki * RetHandle - Where handle to the next object is placed 20167754Smsmith * 202100966Siwasaki * RETURN: Status 20367754Smsmith * 204241973Sjkim * DESCRIPTION: Return the next peer object within the namespace. If Handle is 205241973Sjkim * valid, Scope is ignored. Otherwise, the first object within 206100966Siwasaki * Scope is returned. 20767754Smsmith * 20867754Smsmith ******************************************************************************/ 20967754Smsmith 21067754SmsmithACPI_STATUS 211100966SiwasakiAcpiGetNextObject ( 21267754Smsmith ACPI_OBJECT_TYPE Type, 213100966Siwasaki ACPI_HANDLE Parent, 214100966Siwasaki ACPI_HANDLE Child, 215100966Siwasaki ACPI_HANDLE *RetHandle) 21667754Smsmith{ 21767754Smsmith ACPI_STATUS Status; 218100966Siwasaki ACPI_NAMESPACE_NODE *Node; 219100966Siwasaki ACPI_NAMESPACE_NODE *ParentNode = NULL; 220100966Siwasaki ACPI_NAMESPACE_NODE *ChildNode = NULL; 22167754Smsmith 22267754Smsmith 22367754Smsmith /* Parameter validation */ 22467754Smsmith 225107325Siwasaki if (Type > ACPI_TYPE_EXTERNAL_MAX) 22667754Smsmith { 227100966Siwasaki return (AE_BAD_PARAMETER); 22867754Smsmith } 22967754Smsmith 23091116Smsmith Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 23191116Smsmith if (ACPI_FAILURE (Status)) 23291116Smsmith { 23391116Smsmith return (Status); 23491116Smsmith } 23591116Smsmith 236100966Siwasaki /* If null handle, use the parent */ 23773561Smsmith 238100966Siwasaki if (!Child) 23967754Smsmith { 240100966Siwasaki /* Start search at the beginning of the specified scope */ 24167754Smsmith 242200553Sjkim ParentNode = AcpiNsValidateHandle (Parent); 243100966Siwasaki if (!ParentNode) 244100966Siwasaki { 245100966Siwasaki Status = AE_BAD_PARAMETER; 246100966Siwasaki goto UnlockAndExit; 247100966Siwasaki } 24867754Smsmith } 249100966Siwasaki else 25067754Smsmith { 251100966Siwasaki /* Non-null handle, ignore the parent */ 252100966Siwasaki /* Convert and validate the handle */ 25367754Smsmith 254200553Sjkim ChildNode = AcpiNsValidateHandle (Child); 255100966Siwasaki if (!ChildNode) 25667754Smsmith { 257100966Siwasaki Status = AE_BAD_PARAMETER; 258100966Siwasaki goto UnlockAndExit; 25967754Smsmith } 26067754Smsmith } 26167754Smsmith 262100966Siwasaki /* Internal function does the real work */ 26367754Smsmith 264193267Sjkim Node = AcpiNsGetNextNodeTyped (Type, ParentNode, ChildNode); 26587031Smsmith if (!Node) 26687031Smsmith { 267100966Siwasaki Status = AE_NOT_FOUND; 26887031Smsmith goto UnlockAndExit; 26987031Smsmith } 27087031Smsmith 271100966Siwasaki if (RetHandle) 27287031Smsmith { 273200553Sjkim *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node); 27487031Smsmith } 27587031Smsmith 27687031Smsmith 27787031SmsmithUnlockAndExit: 27887031Smsmith 27991116Smsmith (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 28087031Smsmith return (Status); 28187031Smsmith} 28287031Smsmith 283167802SjkimACPI_EXPORT_SYMBOL (AcpiGetNextObject) 284