Home | History | Annotate | Line # | Download | only in namespace
nsxfobj.c revision 1.1.1.3
      1 /*******************************************************************************
      2  *
      3  * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
      4  *                         ACPI Object oriented interfaces
      5  *
      6  ******************************************************************************/
      7 
      8 /*
      9  * Copyright (C) 2000 - 2013, Intel Corp.
     10  * All rights reserved.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions, and the following disclaimer,
     17  *    without modification.
     18  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19  *    substantially similar to the "NO WARRANTY" disclaimer below
     20  *    ("Disclaimer") and any redistribution must be conditioned upon
     21  *    including a substantially similar Disclaimer requirement for further
     22  *    binary redistribution.
     23  * 3. Neither the names of the above-listed copyright holders nor the names
     24  *    of any contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * Alternatively, this software may be distributed under the terms of the
     28  * GNU General Public License ("GPL") version 2 as published by the Free
     29  * Software Foundation.
     30  *
     31  * NO WARRANTY
     32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     35  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42  * POSSIBILITY OF SUCH DAMAGES.
     43  */
     44 
     45 
     46 #define __NSXFOBJ_C__
     47 #define EXPORT_ACPI_INTERFACES
     48 
     49 #include "acpi.h"
     50 #include "accommon.h"
     51 #include "acnamesp.h"
     52 
     53 
     54 #define _COMPONENT          ACPI_NAMESPACE
     55         ACPI_MODULE_NAME    ("nsxfobj")
     56 
     57 /*******************************************************************************
     58  *
     59  * FUNCTION:    AcpiGetType
     60  *
     61  * PARAMETERS:  Handle          - Handle of object whose type is desired
     62  *              RetType         - Where the type will be placed
     63  *
     64  * RETURN:      Status
     65  *
     66  * DESCRIPTION: This routine returns the type associatd with a particular handle
     67  *
     68  ******************************************************************************/
     69 
     70 ACPI_STATUS
     71 AcpiGetType (
     72     ACPI_HANDLE             Handle,
     73     ACPI_OBJECT_TYPE        *RetType)
     74 {
     75     ACPI_NAMESPACE_NODE     *Node;
     76     ACPI_STATUS             Status;
     77 
     78 
     79     /* Parameter Validation */
     80 
     81     if (!RetType)
     82     {
     83         return (AE_BAD_PARAMETER);
     84     }
     85 
     86     /*
     87      * Special case for the predefined Root Node
     88      * (return type ANY)
     89      */
     90     if (Handle == ACPI_ROOT_OBJECT)
     91     {
     92         *RetType = ACPI_TYPE_ANY;
     93         return (AE_OK);
     94     }
     95 
     96     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
     97     if (ACPI_FAILURE (Status))
     98     {
     99         return (Status);
    100     }
    101 
    102     /* Convert and validate the handle */
    103 
    104     Node = AcpiNsValidateHandle (Handle);
    105     if (!Node)
    106     {
    107         (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    108         return (AE_BAD_PARAMETER);
    109     }
    110 
    111     *RetType = Node->Type;
    112 
    113 
    114     Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    115     return (Status);
    116 }
    117 
    118 ACPI_EXPORT_SYMBOL (AcpiGetType)
    119 
    120 
    121 /*******************************************************************************
    122  *
    123  * FUNCTION:    AcpiGetParent
    124  *
    125  * PARAMETERS:  Handle          - Handle of object whose parent is desired
    126  *              RetHandle       - Where the parent handle will be placed
    127  *
    128  * RETURN:      Status
    129  *
    130  * DESCRIPTION: Returns a handle to the parent of the object represented by
    131  *              Handle.
    132  *
    133  ******************************************************************************/
    134 
    135 ACPI_STATUS
    136 AcpiGetParent (
    137     ACPI_HANDLE             Handle,
    138     ACPI_HANDLE             *RetHandle)
    139 {
    140     ACPI_NAMESPACE_NODE     *Node;
    141     ACPI_NAMESPACE_NODE     *ParentNode;
    142     ACPI_STATUS             Status;
    143 
    144 
    145     if (!RetHandle)
    146     {
    147         return (AE_BAD_PARAMETER);
    148     }
    149 
    150     /* Special case for the predefined Root Node (no parent) */
    151 
    152     if (Handle == ACPI_ROOT_OBJECT)
    153     {
    154         return (AE_NULL_ENTRY);
    155     }
    156 
    157     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    158     if (ACPI_FAILURE (Status))
    159     {
    160         return (Status);
    161     }
    162 
    163     /* Convert and validate the handle */
    164 
    165     Node = AcpiNsValidateHandle (Handle);
    166     if (!Node)
    167     {
    168         Status = AE_BAD_PARAMETER;
    169         goto UnlockAndExit;
    170     }
    171 
    172     /* Get the parent entry */
    173 
    174     ParentNode = Node->Parent;
    175     *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, ParentNode);
    176 
    177     /* Return exception if parent is null */
    178 
    179     if (!ParentNode)
    180     {
    181         Status = AE_NULL_ENTRY;
    182     }
    183 
    184 
    185 UnlockAndExit:
    186 
    187     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    188     return (Status);
    189 }
    190 
    191 ACPI_EXPORT_SYMBOL (AcpiGetParent)
    192 
    193 
    194 /*******************************************************************************
    195  *
    196  * FUNCTION:    AcpiGetNextObject
    197  *
    198  * PARAMETERS:  Type            - Type of object to be searched for
    199  *              Parent          - Parent object whose children we are getting
    200  *              LastChild       - Previous child that was found.
    201  *                                The NEXT child will be returned
    202  *              RetHandle       - Where handle to the next object is placed
    203  *
    204  * RETURN:      Status
    205  *
    206  * DESCRIPTION: Return the next peer object within the namespace. If Handle is
    207  *              valid, Scope is ignored. Otherwise, the first object within
    208  *              Scope is returned.
    209  *
    210  ******************************************************************************/
    211 
    212 ACPI_STATUS
    213 AcpiGetNextObject (
    214     ACPI_OBJECT_TYPE        Type,
    215     ACPI_HANDLE             Parent,
    216     ACPI_HANDLE             Child,
    217     ACPI_HANDLE             *RetHandle)
    218 {
    219     ACPI_STATUS             Status;
    220     ACPI_NAMESPACE_NODE     *Node;
    221     ACPI_NAMESPACE_NODE     *ParentNode = NULL;
    222     ACPI_NAMESPACE_NODE     *ChildNode = NULL;
    223 
    224 
    225     /* Parameter validation */
    226 
    227     if (Type > ACPI_TYPE_EXTERNAL_MAX)
    228     {
    229         return (AE_BAD_PARAMETER);
    230     }
    231 
    232     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    233     if (ACPI_FAILURE (Status))
    234     {
    235         return (Status);
    236     }
    237 
    238     /* If null handle, use the parent */
    239 
    240     if (!Child)
    241     {
    242         /* Start search at the beginning of the specified scope */
    243 
    244         ParentNode = AcpiNsValidateHandle (Parent);
    245         if (!ParentNode)
    246         {
    247             Status = AE_BAD_PARAMETER;
    248             goto UnlockAndExit;
    249         }
    250     }
    251     else
    252     {
    253         /* Non-null handle, ignore the parent */
    254         /* Convert and validate the handle */
    255 
    256         ChildNode = AcpiNsValidateHandle (Child);
    257         if (!ChildNode)
    258         {
    259             Status = AE_BAD_PARAMETER;
    260             goto UnlockAndExit;
    261         }
    262     }
    263 
    264     /* Internal function does the real work */
    265 
    266     Node = AcpiNsGetNextNodeTyped (Type, ParentNode, ChildNode);
    267     if (!Node)
    268     {
    269         Status = AE_NOT_FOUND;
    270         goto UnlockAndExit;
    271     }
    272 
    273     if (RetHandle)
    274     {
    275         *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
    276     }
    277 
    278 
    279 UnlockAndExit:
    280 
    281     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    282     return (Status);
    283 }
    284 
    285 ACPI_EXPORT_SYMBOL (AcpiGetNextObject)
    286