Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /*******************************************************************************
0003  *
0004  * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
0005  *                         ACPI Object oriented interfaces
0006  *
0007  ******************************************************************************/
0008 
0009 #define EXPORT_ACPI_INTERFACES
0010 
0011 #include <acpi/acpi.h>
0012 #include "accommon.h"
0013 #include "acnamesp.h"
0014 
0015 #define _COMPONENT          ACPI_NAMESPACE
0016 ACPI_MODULE_NAME("nsxfobj")
0017 
0018 /*******************************************************************************
0019  *
0020  * FUNCTION:    acpi_get_type
0021  *
0022  * PARAMETERS:  handle          - Handle of object whose type is desired
0023  *              ret_type        - Where the type will be placed
0024  *
0025  * RETURN:      Status
0026  *
0027  * DESCRIPTION: This routine returns the type associated with a particular
0028  *              handle
0029  *
0030  ******************************************************************************/
0031 acpi_status acpi_get_type(acpi_handle handle, acpi_object_type *ret_type)
0032 {
0033     struct acpi_namespace_node *node;
0034     acpi_status status;
0035 
0036     /* Parameter Validation */
0037 
0038     if (!ret_type) {
0039         return (AE_BAD_PARAMETER);
0040     }
0041 
0042     /* Special case for the predefined Root Node (return type ANY) */
0043 
0044     if (handle == ACPI_ROOT_OBJECT) {
0045         *ret_type = ACPI_TYPE_ANY;
0046         return (AE_OK);
0047     }
0048 
0049     status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
0050     if (ACPI_FAILURE(status)) {
0051         return (status);
0052     }
0053 
0054     /* Convert and validate the handle */
0055 
0056     node = acpi_ns_validate_handle(handle);
0057     if (!node) {
0058         (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
0059         return (AE_BAD_PARAMETER);
0060     }
0061 
0062     *ret_type = node->type;
0063 
0064     status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
0065     return (status);
0066 }
0067 
0068 ACPI_EXPORT_SYMBOL(acpi_get_type)
0069 
0070 /*******************************************************************************
0071  *
0072  * FUNCTION:    acpi_get_parent
0073  *
0074  * PARAMETERS:  handle          - Handle of object whose parent is desired
0075  *              ret_handle      - Where the parent handle will be placed
0076  *
0077  * RETURN:      Status
0078  *
0079  * DESCRIPTION: Returns a handle to the parent of the object represented by
0080  *              Handle.
0081  *
0082  ******************************************************************************/
0083 acpi_status acpi_get_parent(acpi_handle handle, acpi_handle *ret_handle)
0084 {
0085     struct acpi_namespace_node *node;
0086     struct acpi_namespace_node *parent_node;
0087     acpi_status status;
0088 
0089     if (!ret_handle) {
0090         return (AE_BAD_PARAMETER);
0091     }
0092 
0093     /* Special case for the predefined Root Node (no parent) */
0094 
0095     if (handle == ACPI_ROOT_OBJECT) {
0096         return (AE_NULL_ENTRY);
0097     }
0098 
0099     status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
0100     if (ACPI_FAILURE(status)) {
0101         return (status);
0102     }
0103 
0104     /* Convert and validate the handle */
0105 
0106     node = acpi_ns_validate_handle(handle);
0107     if (!node) {
0108         status = AE_BAD_PARAMETER;
0109         goto unlock_and_exit;
0110     }
0111 
0112     /* Get the parent entry */
0113 
0114     parent_node = node->parent;
0115     *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node);
0116 
0117     /* Return exception if parent is null */
0118 
0119     if (!parent_node) {
0120         status = AE_NULL_ENTRY;
0121     }
0122 
0123 unlock_and_exit:
0124 
0125     (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
0126     return (status);
0127 }
0128 
0129 ACPI_EXPORT_SYMBOL(acpi_get_parent)
0130 
0131 /*******************************************************************************
0132  *
0133  * FUNCTION:    acpi_get_next_object
0134  *
0135  * PARAMETERS:  type            - Type of object to be searched for
0136  *              parent          - Parent object whose children we are getting
0137  *              last_child      - Previous child that was found.
0138  *                                The NEXT child will be returned
0139  *              ret_handle      - Where handle to the next object is placed
0140  *
0141  * RETURN:      Status
0142  *
0143  * DESCRIPTION: Return the next peer object within the namespace. If Handle is
0144  *              valid, Scope is ignored. Otherwise, the first object within
0145  *              Scope is returned.
0146  *
0147  ******************************************************************************/
0148 acpi_status
0149 acpi_get_next_object(acpi_object_type type,
0150              acpi_handle parent,
0151              acpi_handle child, acpi_handle *ret_handle)
0152 {
0153     acpi_status status;
0154     struct acpi_namespace_node *node;
0155     struct acpi_namespace_node *parent_node = NULL;
0156     struct acpi_namespace_node *child_node = NULL;
0157 
0158     /* Parameter validation */
0159 
0160     if (type > ACPI_TYPE_EXTERNAL_MAX) {
0161         return (AE_BAD_PARAMETER);
0162     }
0163 
0164     status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
0165     if (ACPI_FAILURE(status)) {
0166         return (status);
0167     }
0168 
0169     /* If null handle, use the parent */
0170 
0171     if (!child) {
0172 
0173         /* Start search at the beginning of the specified scope */
0174 
0175         parent_node = acpi_ns_validate_handle(parent);
0176         if (!parent_node) {
0177             status = AE_BAD_PARAMETER;
0178             goto unlock_and_exit;
0179         }
0180     } else {
0181         /* Non-null handle, ignore the parent */
0182         /* Convert and validate the handle */
0183 
0184         child_node = acpi_ns_validate_handle(child);
0185         if (!child_node) {
0186             status = AE_BAD_PARAMETER;
0187             goto unlock_and_exit;
0188         }
0189     }
0190 
0191     /* Internal function does the real work */
0192 
0193     node = acpi_ns_get_next_node_typed(type, parent_node, child_node);
0194     if (!node) {
0195         status = AE_NOT_FOUND;
0196         goto unlock_and_exit;
0197     }
0198 
0199     if (ret_handle) {
0200         *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
0201     }
0202 
0203 unlock_and_exit:
0204 
0205     (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
0206     return (status);
0207 }
0208 
0209 ACPI_EXPORT_SYMBOL(acpi_get_next_object)