Home | History | Annotate | Line # | Download | only in namespace
nsxfobj.c revision 1.1.1.5
      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 - 2015, 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 #define EXPORT_ACPI_INTERFACES
     46 
     47 #include "acpi.h"
     48 #include "accommon.h"
     49 #include "acnamesp.h"
     50 
     51 
     52 #define _COMPONENT          ACPI_NAMESPACE
     53         ACPI_MODULE_NAME    ("nsxfobj")
     54 
     55 /*******************************************************************************
     56  *
     57  * FUNCTION:    AcpiGetType
     58  *
     59  * PARAMETERS:  Handle          - Handle of object whose type is desired
     60  *              RetType         - Where the type will be placed
     61  *
     62  * RETURN:      Status
     63  *
     64  * DESCRIPTION: This routine returns the type associatd with a particular handle
     65  *
     66  ******************************************************************************/
     67 
     68 ACPI_STATUS
     69 AcpiGetType (
     70     ACPI_HANDLE             Handle,
     71     ACPI_OBJECT_TYPE        *RetType)
     72 {
     73     ACPI_NAMESPACE_NODE     *Node;
     74     ACPI_STATUS             Status;
     75 
     76 
     77     /* Parameter Validation */
     78 
     79     if (!RetType)
     80     {
     81         return (AE_BAD_PARAMETER);
     82     }
     83 
     84     /*
     85      * Special case for the predefined Root Node
     86      * (return type ANY)
     87      */
     88     if (Handle == ACPI_ROOT_OBJECT)
     89     {
     90         *RetType = ACPI_TYPE_ANY;
     91         return (AE_OK);
     92     }
     93 
     94     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
     95     if (ACPI_FAILURE (Status))
     96     {
     97         return (Status);
     98     }
     99 
    100     /* Convert and validate the handle */
    101 
    102     Node = AcpiNsValidateHandle (Handle);
    103     if (!Node)
    104     {
    105         (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    106         return (AE_BAD_PARAMETER);
    107     }
    108 
    109     *RetType = Node->Type;
    110 
    111 
    112     Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    113     return (Status);
    114 }
    115 
    116 ACPI_EXPORT_SYMBOL (AcpiGetType)
    117 
    118 
    119 /*******************************************************************************
    120  *
    121  * FUNCTION:    AcpiGetParent
    122  *
    123  * PARAMETERS:  Handle          - Handle of object whose parent is desired
    124  *              RetHandle       - Where the parent handle will be placed
    125  *
    126  * RETURN:      Status
    127  *
    128  * DESCRIPTION: Returns a handle to the parent of the object represented by
    129  *              Handle.
    130  *
    131  ******************************************************************************/
    132 
    133 ACPI_STATUS
    134 AcpiGetParent (
    135     ACPI_HANDLE             Handle,
    136     ACPI_HANDLE             *RetHandle)
    137 {
    138     ACPI_NAMESPACE_NODE     *Node;
    139     ACPI_NAMESPACE_NODE     *ParentNode;
    140     ACPI_STATUS             Status;
    141 
    142 
    143     if (!RetHandle)
    144     {
    145         return (AE_BAD_PARAMETER);
    146     }
    147 
    148     /* Special case for the predefined Root Node (no parent) */
    149 
    150     if (Handle == ACPI_ROOT_OBJECT)
    151     {
    152         return (AE_NULL_ENTRY);
    153     }
    154 
    155     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    156     if (ACPI_FAILURE (Status))
    157     {
    158         return (Status);
    159     }
    160 
    161     /* Convert and validate the handle */
    162 
    163     Node = AcpiNsValidateHandle (Handle);
    164     if (!Node)
    165     {
    166         Status = AE_BAD_PARAMETER;
    167         goto UnlockAndExit;
    168     }
    169 
    170     /* Get the parent entry */
    171 
    172     ParentNode = Node->Parent;
    173     *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, ParentNode);
    174 
    175     /* Return exception if parent is null */
    176 
    177     if (!ParentNode)
    178     {
    179         Status = AE_NULL_ENTRY;
    180     }
    181 
    182 
    183 UnlockAndExit:
    184 
    185     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    186     return (Status);
    187 }
    188 
    189 ACPI_EXPORT_SYMBOL (AcpiGetParent)
    190 
    191 
    192 /*******************************************************************************
    193  *
    194  * FUNCTION:    AcpiGetNextObject
    195  *
    196  * PARAMETERS:  Type            - Type of object to be searched for
    197  *              Parent          - Parent object whose children we are getting
    198  *              LastChild       - Previous child that was found.
    199  *                                The NEXT child will be returned
    200  *              RetHandle       - Where handle to the next object is placed
    201  *
    202  * RETURN:      Status
    203  *
    204  * DESCRIPTION: Return the next peer object within the namespace. If Handle is
    205  *              valid, Scope is ignored. Otherwise, the first object within
    206  *              Scope is returned.
    207  *
    208  ******************************************************************************/
    209 
    210 ACPI_STATUS
    211 AcpiGetNextObject (
    212     ACPI_OBJECT_TYPE        Type,
    213     ACPI_HANDLE             Parent,
    214     ACPI_HANDLE             Child,
    215     ACPI_HANDLE             *RetHandle)
    216 {
    217     ACPI_STATUS             Status;
    218     ACPI_NAMESPACE_NODE     *Node;
    219     ACPI_NAMESPACE_NODE     *ParentNode = NULL;
    220     ACPI_NAMESPACE_NODE     *ChildNode = NULL;
    221 
    222 
    223     /* Parameter validation */
    224 
    225     if (Type > ACPI_TYPE_EXTERNAL_MAX)
    226     {
    227         return (AE_BAD_PARAMETER);
    228     }
    229 
    230     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    231     if (ACPI_FAILURE (Status))
    232     {
    233         return (Status);
    234     }
    235 
    236     /* If null handle, use the parent */
    237 
    238     if (!Child)
    239     {
    240         /* Start search at the beginning of the specified scope */
    241 
    242         ParentNode = AcpiNsValidateHandle (Parent);
    243         if (!ParentNode)
    244         {
    245             Status = AE_BAD_PARAMETER;
    246             goto UnlockAndExit;
    247         }
    248     }
    249     else
    250     {
    251         /* Non-null handle, ignore the parent */
    252         /* Convert and validate the handle */
    253 
    254         ChildNode = AcpiNsValidateHandle (Child);
    255         if (!ChildNode)
    256         {
    257             Status = AE_BAD_PARAMETER;
    258             goto UnlockAndExit;
    259         }
    260     }
    261 
    262     /* Internal function does the real work */
    263 
    264     Node = AcpiNsGetNextNodeTyped (Type, ParentNode, ChildNode);
    265     if (!Node)
    266     {
    267         Status = AE_NOT_FOUND;
    268         goto UnlockAndExit;
    269     }
    270 
    271     if (RetHandle)
    272     {
    273         *RetHandle = ACPI_CAST_PTR (ACPI_HANDLE, Node);
    274     }
    275 
    276 
    277 UnlockAndExit:
    278 
    279     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    280     return (Status);
    281 }
    282 
    283 ACPI_EXPORT_SYMBOL (AcpiGetNextObject)
    284