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