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