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