| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* | 
|  | 2 | * | 
|  | 3 | * Module Name: nsxfobj - Public interfaces to the ACPI subsystem | 
|  | 4 | *                         ACPI Object oriented interfaces | 
|  | 5 | * | 
|  | 6 | ******************************************************************************/ | 
|  | 7 |  | 
|  | 8 | /* | 
| Bob Moore | a8357b0 | 2010-01-22 19:07:36 +0800 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2010, Intel Corp. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> | 
| Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 46 | #include "accommon.h" | 
|  | 47 | #include "acnamesp.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #define _COMPONENT          ACPI_NAMESPACE | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("nsxfobj") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 |  | 
|  | 52 | /******************************************************************************* | 
|  | 53 | * | 
| John Keller | 0f0fe1a | 2006-12-19 12:56:19 -0800 | [diff] [blame] | 54 | * FUNCTION:    acpi_get_id | 
|  | 55 | * | 
|  | 56 | * PARAMETERS:  Handle          - Handle of object whose id is desired | 
|  | 57 | *              ret_id          - Where the id will be placed | 
|  | 58 | * | 
|  | 59 | * RETURN:      Status | 
|  | 60 | * | 
|  | 61 | * DESCRIPTION: This routine returns the owner id associated with a handle | 
|  | 62 | * | 
|  | 63 | ******************************************************************************/ | 
|  | 64 | acpi_status acpi_get_id(acpi_handle handle, acpi_owner_id * ret_id) | 
|  | 65 | { | 
|  | 66 | struct acpi_namespace_node *node; | 
|  | 67 | acpi_status status; | 
|  | 68 |  | 
|  | 69 | /* Parameter Validation */ | 
|  | 70 |  | 
|  | 71 | if (!ret_id) { | 
|  | 72 | return (AE_BAD_PARAMETER); | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 76 | if (ACPI_FAILURE(status)) { | 
|  | 77 | return (status); | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | /* Convert and validate the handle */ | 
|  | 81 |  | 
| Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 82 | node = acpi_ns_validate_handle(handle); | 
| John Keller | 0f0fe1a | 2006-12-19 12:56:19 -0800 | [diff] [blame] | 83 | if (!node) { | 
|  | 84 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
|  | 85 | return (AE_BAD_PARAMETER); | 
|  | 86 | } | 
|  | 87 |  | 
|  | 88 | *ret_id = node->owner_id; | 
|  | 89 |  | 
|  | 90 | status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
|  | 91 | return (status); | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | ACPI_EXPORT_SYMBOL(acpi_get_id) | 
|  | 95 |  | 
|  | 96 | /******************************************************************************* | 
|  | 97 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | * FUNCTION:    acpi_get_type | 
|  | 99 | * | 
|  | 100 | * PARAMETERS:  Handle          - Handle of object whose type is desired | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 101 | *              ret_type        - Where the type will be placed | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | * | 
|  | 103 | * RETURN:      Status | 
|  | 104 | * | 
|  | 105 | * DESCRIPTION: This routine returns the type associatd with a particular handle | 
|  | 106 | * | 
|  | 107 | ******************************************************************************/ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 108 | acpi_status acpi_get_type(acpi_handle handle, acpi_object_type * ret_type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 110 | struct acpi_namespace_node *node; | 
|  | 111 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 |  | 
|  | 113 | /* Parameter Validation */ | 
|  | 114 |  | 
|  | 115 | if (!ret_type) { | 
|  | 116 | return (AE_BAD_PARAMETER); | 
|  | 117 | } | 
|  | 118 |  | 
|  | 119 | /* | 
|  | 120 | * Special case for the predefined Root Node | 
|  | 121 | * (return type ANY) | 
|  | 122 | */ | 
|  | 123 | if (handle == ACPI_ROOT_OBJECT) { | 
|  | 124 | *ret_type = ACPI_TYPE_ANY; | 
|  | 125 | return (AE_OK); | 
|  | 126 | } | 
|  | 127 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 128 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 129 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | return (status); | 
|  | 131 | } | 
|  | 132 |  | 
|  | 133 | /* Convert and validate the handle */ | 
|  | 134 |  | 
| Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 135 | node = acpi_ns_validate_handle(handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | if (!node) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 137 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | return (AE_BAD_PARAMETER); | 
|  | 139 | } | 
|  | 140 |  | 
|  | 141 | *ret_type = node->type; | 
|  | 142 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | return (status); | 
|  | 145 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 147 | ACPI_EXPORT_SYMBOL(acpi_get_type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 |  | 
|  | 149 | /******************************************************************************* | 
|  | 150 | * | 
|  | 151 | * FUNCTION:    acpi_get_parent | 
|  | 152 | * | 
|  | 153 | * PARAMETERS:  Handle          - Handle of object whose parent is desired | 
|  | 154 | *              ret_handle      - Where the parent handle will be placed | 
|  | 155 | * | 
|  | 156 | * RETURN:      Status | 
|  | 157 | * | 
|  | 158 | * DESCRIPTION: Returns a handle to the parent of the object represented by | 
|  | 159 | *              Handle. | 
|  | 160 | * | 
|  | 161 | ******************************************************************************/ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 162 | acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | struct acpi_namespace_node *node; | 
| Alex Chiang | c446eed | 2009-05-21 10:59:15 +0800 | [diff] [blame] | 165 | struct acpi_namespace_node *parent_node; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 166 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 |  | 
|  | 168 | if (!ret_handle) { | 
|  | 169 | return (AE_BAD_PARAMETER); | 
|  | 170 | } | 
|  | 171 |  | 
|  | 172 | /* Special case for the predefined Root Node (no parent) */ | 
|  | 173 |  | 
|  | 174 | if (handle == ACPI_ROOT_OBJECT) { | 
|  | 175 | return (AE_NULL_ENTRY); | 
|  | 176 | } | 
|  | 177 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 178 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 179 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | return (status); | 
|  | 181 | } | 
|  | 182 |  | 
|  | 183 | /* Convert and validate the handle */ | 
|  | 184 |  | 
| Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 185 | node = acpi_ns_validate_handle(handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | if (!node) { | 
|  | 187 | status = AE_BAD_PARAMETER; | 
|  | 188 | goto unlock_and_exit; | 
|  | 189 | } | 
|  | 190 |  | 
|  | 191 | /* Get the parent entry */ | 
|  | 192 |  | 
| Alex Chiang | c446eed | 2009-05-21 10:59:15 +0800 | [diff] [blame] | 193 | parent_node = acpi_ns_get_parent_node(node); | 
| Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 194 | *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 |  | 
|  | 196 | /* Return exception if parent is null */ | 
|  | 197 |  | 
| Alex Chiang | c446eed | 2009-05-21 10:59:15 +0800 | [diff] [blame] | 198 | if (!parent_node) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | status = AE_NULL_ENTRY; | 
|  | 200 | } | 
|  | 201 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | unlock_and_exit: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | return (status); | 
|  | 206 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 208 | ACPI_EXPORT_SYMBOL(acpi_get_parent) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 |  | 
|  | 210 | /******************************************************************************* | 
|  | 211 | * | 
|  | 212 | * FUNCTION:    acpi_get_next_object | 
|  | 213 | * | 
|  | 214 | * PARAMETERS:  Type            - Type of object to be searched for | 
|  | 215 | *              Parent          - Parent object whose children we are getting | 
|  | 216 | *              last_child      - Previous child that was found. | 
|  | 217 | *                                The NEXT child will be returned | 
|  | 218 | *              ret_handle      - Where handle to the next object is placed | 
|  | 219 | * | 
|  | 220 | * RETURN:      Status | 
|  | 221 | * | 
|  | 222 | * DESCRIPTION: Return the next peer object within the namespace.  If Handle is | 
|  | 223 | *              valid, Scope is ignored.  Otherwise, the first object within | 
|  | 224 | *              Scope is returned. | 
|  | 225 | * | 
|  | 226 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 228 | acpi_get_next_object(acpi_object_type type, | 
|  | 229 | acpi_handle parent, | 
|  | 230 | acpi_handle child, acpi_handle * ret_handle) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 232 | acpi_status status; | 
|  | 233 | struct acpi_namespace_node *node; | 
|  | 234 | struct acpi_namespace_node *parent_node = NULL; | 
|  | 235 | struct acpi_namespace_node *child_node = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 |  | 
|  | 237 | /* Parameter validation */ | 
|  | 238 |  | 
|  | 239 | if (type > ACPI_TYPE_EXTERNAL_MAX) { | 
|  | 240 | return (AE_BAD_PARAMETER); | 
|  | 241 | } | 
|  | 242 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 244 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | return (status); | 
|  | 246 | } | 
|  | 247 |  | 
|  | 248 | /* If null handle, use the parent */ | 
|  | 249 |  | 
|  | 250 | if (!child) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 251 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | /* Start search at the beginning of the specified scope */ | 
|  | 253 |  | 
| Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 254 | parent_node = acpi_ns_validate_handle(parent); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | if (!parent_node) { | 
|  | 256 | status = AE_BAD_PARAMETER; | 
|  | 257 | goto unlock_and_exit; | 
|  | 258 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | /* Non-null handle, ignore the parent */ | 
|  | 261 | /* Convert and validate the handle */ | 
|  | 262 |  | 
| Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 263 | child_node = acpi_ns_validate_handle(child); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | if (!child_node) { | 
|  | 265 | status = AE_BAD_PARAMETER; | 
|  | 266 | goto unlock_and_exit; | 
|  | 267 | } | 
|  | 268 | } | 
|  | 269 |  | 
|  | 270 | /* Internal function does the real work */ | 
|  | 271 |  | 
| Bob Moore | 8c725bf | 2009-05-21 10:27:51 +0800 | [diff] [blame] | 272 | node = acpi_ns_get_next_node_typed(type, parent_node, child_node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | if (!node) { | 
|  | 274 | status = AE_NOT_FOUND; | 
|  | 275 | goto unlock_and_exit; | 
|  | 276 | } | 
|  | 277 |  | 
|  | 278 | if (ret_handle) { | 
| Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 279 | *ret_handle = ACPI_CAST_PTR(acpi_handle, node); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } | 
|  | 281 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 282 | unlock_and_exit: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 284 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | return (status); | 
|  | 286 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 288 | ACPI_EXPORT_SYMBOL(acpi_get_next_object) |