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 | /* |
David E. Box | 82a8094 | 2015-02-05 15:20:45 +0800 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2015, 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 | |
Lv Zheng | 839e928 | 2013-10-29 09:29:51 +0800 | [diff] [blame] | 45 | #define EXPORT_ACPI_INTERFACES |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 48 | #include "accommon.h" |
| 49 | #include "acnamesp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define _COMPONENT ACPI_NAMESPACE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | ACPI_MODULE_NAME("nsxfobj") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /******************************************************************************* |
| 55 | * |
| 56 | * FUNCTION: acpi_get_type |
| 57 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 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 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 66 | 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] | 67 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 68 | struct acpi_namespace_node *node; |
| 69 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | /* Parameter Validation */ |
| 72 | |
| 73 | if (!ret_type) { |
| 74 | return (AE_BAD_PARAMETER); |
| 75 | } |
| 76 | |
| 77 | /* |
| 78 | * Special case for the predefined Root Node |
| 79 | * (return type ANY) |
| 80 | */ |
| 81 | if (handle == ACPI_ROOT_OBJECT) { |
| 82 | *ret_type = ACPI_TYPE_ANY; |
| 83 | return (AE_OK); |
| 84 | } |
| 85 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 87 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | return (status); |
| 89 | } |
| 90 | |
| 91 | /* Convert and validate the handle */ |
| 92 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 93 | node = acpi_ns_validate_handle(handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | if (!node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 95 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return (AE_BAD_PARAMETER); |
| 97 | } |
| 98 | |
| 99 | *ret_type = node->type; |
| 100 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 101 | status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | return (status); |
| 103 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 105 | ACPI_EXPORT_SYMBOL(acpi_get_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | /******************************************************************************* |
| 108 | * |
| 109 | * FUNCTION: acpi_get_parent |
| 110 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 111 | * PARAMETERS: handle - Handle of object whose parent is desired |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | * ret_handle - Where the parent handle will be placed |
| 113 | * |
| 114 | * RETURN: Status |
| 115 | * |
| 116 | * DESCRIPTION: Returns a handle to the parent of the object represented by |
| 117 | * Handle. |
| 118 | * |
| 119 | ******************************************************************************/ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 120 | acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 122 | struct acpi_namespace_node *node; |
Alex Chiang | c446eed | 2009-05-21 10:59:15 +0800 | [diff] [blame] | 123 | struct acpi_namespace_node *parent_node; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 124 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
| 126 | if (!ret_handle) { |
| 127 | return (AE_BAD_PARAMETER); |
| 128 | } |
| 129 | |
| 130 | /* Special case for the predefined Root Node (no parent) */ |
| 131 | |
| 132 | if (handle == ACPI_ROOT_OBJECT) { |
| 133 | return (AE_NULL_ENTRY); |
| 134 | } |
| 135 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 136 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 137 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | return (status); |
| 139 | } |
| 140 | |
| 141 | /* Convert and validate the handle */ |
| 142 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 143 | node = acpi_ns_validate_handle(handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | if (!node) { |
| 145 | status = AE_BAD_PARAMETER; |
| 146 | goto unlock_and_exit; |
| 147 | } |
| 148 | |
| 149 | /* Get the parent entry */ |
| 150 | |
Alexey Starikovskiy | c45b5c0 | 2010-05-26 11:53:07 +0800 | [diff] [blame] | 151 | parent_node = node->parent; |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 152 | *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | /* Return exception if parent is null */ |
| 155 | |
Alex Chiang | c446eed | 2009-05-21 10:59:15 +0800 | [diff] [blame] | 156 | if (!parent_node) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | status = AE_NULL_ENTRY; |
| 158 | } |
| 159 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 160 | unlock_and_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 162 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | return (status); |
| 164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 166 | ACPI_EXPORT_SYMBOL(acpi_get_parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | /******************************************************************************* |
| 169 | * |
| 170 | * FUNCTION: acpi_get_next_object |
| 171 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 172 | * PARAMETERS: type - Type of object to be searched for |
| 173 | * parent - Parent object whose children we are getting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | * last_child - Previous child that was found. |
| 175 | * The NEXT child will be returned |
| 176 | * ret_handle - Where handle to the next object is placed |
| 177 | * |
| 178 | * RETURN: Status |
| 179 | * |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 180 | * DESCRIPTION: Return the next peer object within the namespace. If Handle is |
| 181 | * valid, Scope is ignored. Otherwise, the first object within |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | * Scope is returned. |
| 183 | * |
| 184 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 186 | acpi_get_next_object(acpi_object_type type, |
| 187 | acpi_handle parent, |
| 188 | acpi_handle child, acpi_handle * ret_handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 190 | acpi_status status; |
| 191 | struct acpi_namespace_node *node; |
| 192 | struct acpi_namespace_node *parent_node = NULL; |
| 193 | struct acpi_namespace_node *child_node = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | /* Parameter validation */ |
| 196 | |
| 197 | if (type > ACPI_TYPE_EXTERNAL_MAX) { |
| 198 | return (AE_BAD_PARAMETER); |
| 199 | } |
| 200 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 202 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | return (status); |
| 204 | } |
| 205 | |
| 206 | /* If null handle, use the parent */ |
| 207 | |
| 208 | if (!child) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | /* Start search at the beginning of the specified scope */ |
| 211 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 212 | parent_node = acpi_ns_validate_handle(parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | if (!parent_node) { |
| 214 | status = AE_BAD_PARAMETER; |
| 215 | goto unlock_and_exit; |
| 216 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 217 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | /* Non-null handle, ignore the parent */ |
| 219 | /* Convert and validate the handle */ |
| 220 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 221 | child_node = acpi_ns_validate_handle(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | if (!child_node) { |
| 223 | status = AE_BAD_PARAMETER; |
| 224 | goto unlock_and_exit; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | /* Internal function does the real work */ |
| 229 | |
Bob Moore | 8c725bf | 2009-05-21 10:27:51 +0800 | [diff] [blame] | 230 | node = acpi_ns_get_next_node_typed(type, parent_node, child_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | if (!node) { |
| 232 | status = AE_NOT_FOUND; |
| 233 | goto unlock_and_exit; |
| 234 | } |
| 235 | |
| 236 | if (ret_handle) { |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 237 | *ret_handle = ACPI_CAST_PTR(acpi_handle, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Lv Zheng | 10622bf | 2013-10-29 09:30:02 +0800 | [diff] [blame] | 240 | unlock_and_exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 242 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | return (status); |
| 244 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 246 | ACPI_EXPORT_SYMBOL(acpi_get_next_object) |