Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing |
| 4 | * parents and siblings and Scope manipulation |
| 5 | * |
| 6 | *****************************************************************************/ |
| 7 | |
| 8 | /* |
Bob Moore | 7784813 | 2012-01-12 13:27:23 +0800 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2012, 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" |
| 48 | #include "amlcode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | #define _COMPONENT ACPI_NAMESPACE |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | ACPI_MODULE_NAME("nsutils") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 53 | /* Local prototypes */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 54 | static u8 acpi_ns_valid_path_separator(char sep); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 55 | |
| 56 | #ifdef ACPI_OBSOLETE_FUNCTIONS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 57 | acpi_name acpi_ns_find_parent_name(struct acpi_namespace_node *node_to_search); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 58 | #endif |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /******************************************************************************* |
| 61 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * FUNCTION: acpi_ns_print_node_pathname |
| 63 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 64 | * PARAMETERS: node - Object |
| 65 | * message - Prefix message |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | * |
| 67 | * DESCRIPTION: Print an object's full namespace pathname |
| 68 | * Manages allocation/freeing of a pathname buffer |
| 69 | * |
| 70 | ******************************************************************************/ |
| 71 | |
| 72 | void |
Bob Moore | 4b8ed63 | 2008-06-10 13:55:53 +0800 | [diff] [blame] | 73 | acpi_ns_print_node_pathname(struct acpi_namespace_node *node, |
| 74 | const char *message) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 76 | struct acpi_buffer buffer; |
| 77 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | if (!node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | acpi_os_printf("[NULL NAME]"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | return; |
| 82 | } |
| 83 | |
| 84 | /* Convert handle to full pathname and print it (with supplied message) */ |
| 85 | |
| 86 | buffer.length = ACPI_ALLOCATE_LOCAL_BUFFER; |
| 87 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 88 | status = acpi_ns_handle_to_pathname(node, &buffer); |
| 89 | if (ACPI_SUCCESS(status)) { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 90 | if (message) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 91 | acpi_os_printf("%s ", message); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | acpi_os_printf("[%s] (Node %p)", (char *)buffer.pointer, node); |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 95 | ACPI_FREE(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | /******************************************************************************* |
| 100 | * |
| 101 | * FUNCTION: acpi_ns_valid_root_prefix |
| 102 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 103 | * PARAMETERS: prefix - Character to be checked |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | * |
| 105 | * RETURN: TRUE if a valid prefix |
| 106 | * |
| 107 | * DESCRIPTION: Check if a character is a valid ACPI Root prefix |
| 108 | * |
| 109 | ******************************************************************************/ |
| 110 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 111 | u8 acpi_ns_valid_root_prefix(char prefix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
| 113 | |
| 114 | return ((u8) (prefix == '\\')); |
| 115 | } |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | /******************************************************************************* |
| 118 | * |
| 119 | * FUNCTION: acpi_ns_valid_path_separator |
| 120 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 121 | * PARAMETERS: sep - Character to be checked |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | * |
| 123 | * RETURN: TRUE if a valid path separator |
| 124 | * |
| 125 | * DESCRIPTION: Check if a character is a valid ACPI path separator |
| 126 | * |
| 127 | ******************************************************************************/ |
| 128 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 129 | static u8 acpi_ns_valid_path_separator(char sep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
| 131 | |
| 132 | return ((u8) (sep == '.')); |
| 133 | } |
| 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | /******************************************************************************* |
| 136 | * |
| 137 | * FUNCTION: acpi_ns_get_type |
| 138 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 139 | * PARAMETERS: node - Parent Node to be examined |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | * |
| 141 | * RETURN: Type field from Node whose handle is passed |
| 142 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 143 | * DESCRIPTION: Return the type of a Namespace node |
| 144 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | ******************************************************************************/ |
| 146 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | acpi_object_type acpi_ns_get_type(struct acpi_namespace_node * node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 149 | ACPI_FUNCTION_TRACE(ns_get_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | if (!node) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 152 | ACPI_WARNING((AE_INFO, "Null Node parameter")); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 153 | return_UINT32(ACPI_TYPE_ANY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 156 | return_UINT32((acpi_object_type) node->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /******************************************************************************* |
| 160 | * |
| 161 | * FUNCTION: acpi_ns_local |
| 162 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 163 | * PARAMETERS: type - A namespace object type |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | * |
| 165 | * RETURN: LOCAL if names must be found locally in objects of the |
| 166 | * passed type, 0 if enclosing scopes should be searched |
| 167 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 168 | * DESCRIPTION: Returns scope rule for the given object type. |
| 169 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | ******************************************************************************/ |
| 171 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | u32 acpi_ns_local(acpi_object_type type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 174 | ACPI_FUNCTION_TRACE(ns_local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | if (!acpi_ut_valid_object_type(type)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | /* Type code out of range */ |
| 179 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 180 | ACPI_WARNING((AE_INFO, "Invalid Object Type 0x%X", type)); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 181 | return_UINT32(ACPI_NS_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 184 | return_UINT32((u32) acpi_gbl_ns_properties[type] & ACPI_NS_LOCAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | /******************************************************************************* |
| 188 | * |
| 189 | * FUNCTION: acpi_ns_get_internal_name_length |
| 190 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 191 | * PARAMETERS: info - Info struct initialized with the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | * external name pointer. |
| 193 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 194 | * RETURN: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | * |
| 196 | * DESCRIPTION: Calculate the length of the internal (AML) namestring |
| 197 | * corresponding to the external (ASL) namestring. |
| 198 | * |
| 199 | ******************************************************************************/ |
| 200 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | void acpi_ns_get_internal_name_length(struct acpi_namestring_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Bob Moore | 4b8ed63 | 2008-06-10 13:55:53 +0800 | [diff] [blame] | 203 | const char *next_external_char; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | next_external_char = info->external_name; |
| 209 | info->num_carats = 0; |
| 210 | info->num_segments = 0; |
| 211 | info->fully_qualified = FALSE; |
| 212 | |
| 213 | /* |
| 214 | * For the internal name, the required length is 4 bytes per segment, plus |
| 215 | * 1 each for root_prefix, multi_name_prefix_op, segment count, trailing null |
| 216 | * (which is not really needed, but no there's harm in putting it there) |
| 217 | * |
| 218 | * strlen() + 1 covers the first name_seg, which has no path separator |
| 219 | */ |
Lin Ming | d037c5f | 2008-11-13 10:54:39 +0800 | [diff] [blame] | 220 | if (acpi_ns_valid_root_prefix(*next_external_char)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | info->fully_qualified = TRUE; |
| 222 | next_external_char++; |
Lin Ming | d037c5f | 2008-11-13 10:54:39 +0800 | [diff] [blame] | 223 | |
| 224 | /* Skip redundant root_prefix, like \\_SB.PCI0.SBRG.EC0 */ |
| 225 | |
| 226 | while (acpi_ns_valid_root_prefix(*next_external_char)) { |
| 227 | next_external_char++; |
| 228 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 229 | } else { |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 230 | /* Handle Carat prefixes */ |
| 231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | while (*next_external_char == '^') { |
| 233 | info->num_carats++; |
| 234 | next_external_char++; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /* |
| 239 | * Determine the number of ACPI name "segments" by counting the number of |
| 240 | * path separators within the string. Start with one segment since the |
| 241 | * segment count is [(# separators) + 1], and zero separators is ok. |
| 242 | */ |
| 243 | if (*next_external_char) { |
| 244 | info->num_segments = 1; |
| 245 | for (i = 0; next_external_char[i]; i++) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 246 | if (acpi_ns_valid_path_separator(next_external_char[i])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | info->num_segments++; |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | info->length = (ACPI_NAME_SIZE * info->num_segments) + |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | 4 + info->num_carats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | info->next_external_char = next_external_char; |
| 256 | } |
| 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | /******************************************************************************* |
| 259 | * |
| 260 | * FUNCTION: acpi_ns_build_internal_name |
| 261 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 262 | * PARAMETERS: info - Info struct fully initialized |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | * |
| 264 | * RETURN: Status |
| 265 | * |
| 266 | * DESCRIPTION: Construct the internal (AML) namestring |
| 267 | * corresponding to the external (ASL) namestring. |
| 268 | * |
| 269 | ******************************************************************************/ |
| 270 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 273 | u32 num_segments = info->num_segments; |
| 274 | char *internal_name = info->internal_name; |
Bob Moore | 4b8ed63 | 2008-06-10 13:55:53 +0800 | [diff] [blame] | 275 | const char *external_name = info->next_external_char; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 276 | char *result = NULL; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 277 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 279 | ACPI_FUNCTION_TRACE(ns_build_internal_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
| 281 | /* Setup the correct prefixes, counts, and pointers */ |
| 282 | |
| 283 | if (info->fully_qualified) { |
| 284 | internal_name[0] = '\\'; |
| 285 | |
| 286 | if (num_segments <= 1) { |
| 287 | result = &internal_name[1]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 288 | } else if (num_segments == 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | internal_name[1] = AML_DUAL_NAME_PREFIX; |
| 290 | result = &internal_name[2]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | internal_name[1] = AML_MULTI_NAME_PREFIX_OP; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | internal_name[2] = (char)num_segments; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | result = &internal_name[3]; |
| 295 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 296 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | /* |
| 298 | * Not fully qualified. |
| 299 | * Handle Carats first, then append the name segments |
| 300 | */ |
| 301 | i = 0; |
| 302 | if (info->num_carats) { |
| 303 | for (i = 0; i < info->num_carats; i++) { |
| 304 | internal_name[i] = '^'; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | if (num_segments <= 1) { |
| 309 | result = &internal_name[i]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 310 | } else if (num_segments == 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | internal_name[i] = AML_DUAL_NAME_PREFIX; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 312 | result = &internal_name[(acpi_size) i + 1]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 313 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | internal_name[i] = AML_MULTI_NAME_PREFIX_OP; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 315 | internal_name[(acpi_size) i + 1] = (char)num_segments; |
| 316 | result = &internal_name[(acpi_size) i + 2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | /* Build the name (minus path separators) */ |
| 321 | |
| 322 | for (; num_segments; num_segments--) { |
| 323 | for (i = 0; i < ACPI_NAME_SIZE; i++) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 324 | if (acpi_ns_valid_path_separator(*external_name) || |
| 325 | (*external_name == 0)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | /* Pad the segment with underscore(s) if segment is short */ |
| 328 | |
| 329 | result[i] = '_'; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 330 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | /* Convert the character to uppercase and save it */ |
| 332 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | result[i] = |
| 334 | (char)ACPI_TOUPPER((int)*external_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | external_name++; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | /* Now we must have a path separator, or the pathname is bad */ |
| 340 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 341 | if (!acpi_ns_valid_path_separator(*external_name) && |
| 342 | (*external_name != 0)) { |
Bob Moore | a1acd22 | 2012-03-21 09:44:00 +0800 | [diff] [blame] | 343 | return_ACPI_STATUS(AE_BAD_PATHNAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /* Move on the next segment */ |
| 347 | |
| 348 | external_name++; |
| 349 | result += ACPI_NAME_SIZE; |
| 350 | } |
| 351 | |
| 352 | /* Terminate the string */ |
| 353 | |
| 354 | *result = 0; |
| 355 | |
| 356 | if (info->fully_qualified) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 357 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 358 | "Returning [%p] (abs) \"\\%s\"\n", |
| 359 | internal_name, internal_name)); |
| 360 | } else { |
| 361 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Returning [%p] (rel) \"%s\"\n", |
| 362 | internal_name, internal_name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 365 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | /******************************************************************************* |
| 369 | * |
| 370 | * FUNCTION: acpi_ns_internalize_name |
| 371 | * |
| 372 | * PARAMETERS: *external_name - External representation of name |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 373 | * **Converted name - Where to return the resulting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | * internal represention of the name |
| 375 | * |
| 376 | * RETURN: Status |
| 377 | * |
| 378 | * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0") |
| 379 | * to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30) |
| 380 | * |
| 381 | *******************************************************************************/ |
| 382 | |
Bob Moore | 4b8ed63 | 2008-06-10 13:55:53 +0800 | [diff] [blame] | 383 | acpi_status |
| 384 | acpi_ns_internalize_name(const char *external_name, char **converted_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 386 | char *internal_name; |
| 387 | struct acpi_namestring_info info; |
| 388 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 390 | ACPI_FUNCTION_TRACE(ns_internalize_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 392 | if ((!external_name) || (*external_name == 0) || (!converted_name)) { |
| 393 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /* Get the length of the new internal name */ |
| 397 | |
| 398 | info.external_name = external_name; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 399 | acpi_ns_get_internal_name_length(&info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | /* We need a segment to store the internal name */ |
| 402 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 403 | internal_name = ACPI_ALLOCATE_ZEROED(info.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | if (!internal_name) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 405 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | /* Build the name */ |
| 409 | |
| 410 | info.internal_name = internal_name; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 411 | status = acpi_ns_build_internal_name(&info); |
| 412 | if (ACPI_FAILURE(status)) { |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 413 | ACPI_FREE(internal_name); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 414 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | *converted_name = internal_name; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 418 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | /******************************************************************************* |
| 422 | * |
| 423 | * FUNCTION: acpi_ns_externalize_name |
| 424 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 425 | * PARAMETERS: internal_name_length - Lenth of the internal name below |
| 426 | * internal_name - Internal representation of name |
| 427 | * converted_name_length - Where the length is returned |
| 428 | * converted_name - Where the resulting external name |
| 429 | * is returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | * |
| 431 | * RETURN: Status |
| 432 | * |
| 433 | * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30) |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 434 | * to its external (printable) form (e.g. "\_PR_.CPU0") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | * |
| 436 | ******************************************************************************/ |
| 437 | |
| 438 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 439 | acpi_ns_externalize_name(u32 internal_name_length, |
Bob Moore | 4b8ed63 | 2008-06-10 13:55:53 +0800 | [diff] [blame] | 440 | const char *internal_name, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 441 | u32 * converted_name_length, char **converted_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 443 | u32 names_index = 0; |
| 444 | u32 num_segments = 0; |
| 445 | u32 required_length; |
| 446 | u32 prefix_length = 0; |
| 447 | u32 i = 0; |
| 448 | u32 j = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 450 | ACPI_FUNCTION_TRACE(ns_externalize_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 452 | if (!internal_name_length || !internal_name || !converted_name) { |
| 453 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 456 | /* Check for a prefix (one '\' | one or more '^') */ |
| 457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | switch (internal_name[0]) { |
| 459 | case '\\': |
| 460 | prefix_length = 1; |
| 461 | break; |
| 462 | |
| 463 | case '^': |
| 464 | for (i = 0; i < internal_name_length; i++) { |
| 465 | if (internal_name[i] == '^') { |
| 466 | prefix_length = i + 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 467 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | break; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | if (i == internal_name_length) { |
| 473 | prefix_length = i; |
| 474 | } |
| 475 | |
| 476 | break; |
| 477 | |
| 478 | default: |
| 479 | break; |
| 480 | } |
| 481 | |
| 482 | /* |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 483 | * Check for object names. Note that there could be 0-255 of these |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | * 4-byte elements. |
| 485 | */ |
| 486 | if (prefix_length < internal_name_length) { |
| 487 | switch (internal_name[prefix_length]) { |
| 488 | case AML_MULTI_NAME_PREFIX_OP: |
| 489 | |
| 490 | /* <count> 4-byte names */ |
| 491 | |
| 492 | names_index = prefix_length + 2; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 493 | num_segments = (u8) |
| 494 | internal_name[(acpi_size) prefix_length + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | break; |
| 496 | |
| 497 | case AML_DUAL_NAME_PREFIX: |
| 498 | |
| 499 | /* Two 4-byte names */ |
| 500 | |
| 501 | names_index = prefix_length + 1; |
| 502 | num_segments = 2; |
| 503 | break; |
| 504 | |
| 505 | case 0: |
| 506 | |
| 507 | /* null_name */ |
| 508 | |
| 509 | names_index = 0; |
| 510 | num_segments = 0; |
| 511 | break; |
| 512 | |
| 513 | default: |
| 514 | |
| 515 | /* one 4-byte name */ |
| 516 | |
| 517 | names_index = prefix_length; |
| 518 | num_segments = 1; |
| 519 | break; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | * Calculate the length of converted_name, which equals the length |
| 525 | * of the prefix, length of all object names, length of any required |
| 526 | * punctuation ('.') between object names, plus the NULL terminator. |
| 527 | */ |
| 528 | required_length = prefix_length + (4 * num_segments) + |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 529 | ((num_segments > 0) ? (num_segments - 1) : 0) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
| 531 | /* |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 532 | * Check to see if we're still in bounds. If not, there's a problem |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | * with internal_name (invalid format). |
| 534 | */ |
| 535 | if (required_length > internal_name_length) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 536 | ACPI_ERROR((AE_INFO, "Invalid internal name")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 537 | return_ACPI_STATUS(AE_BAD_PATHNAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 540 | /* Build the converted_name */ |
| 541 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 542 | *converted_name = ACPI_ALLOCATE_ZEROED(required_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | if (!(*converted_name)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 544 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | j = 0; |
| 548 | |
| 549 | for (i = 0; i < prefix_length; i++) { |
| 550 | (*converted_name)[j++] = internal_name[i]; |
| 551 | } |
| 552 | |
| 553 | if (num_segments > 0) { |
| 554 | for (i = 0; i < num_segments; i++) { |
| 555 | if (i > 0) { |
| 556 | (*converted_name)[j++] = '.'; |
| 557 | } |
| 558 | |
Bob Moore | 47abd13 | 2012-10-31 02:28:19 +0000 | [diff] [blame] | 559 | /* Copy and validate the 4-char name segment */ |
| 560 | |
| 561 | ACPI_MOVE_NAME(&(*converted_name)[j], |
| 562 | &internal_name[names_index]); |
| 563 | acpi_ut_repair_name(&(*converted_name)[j]); |
Bob Moore | 00eb325 | 2012-10-31 02:27:48 +0000 | [diff] [blame] | 564 | |
| 565 | j += ACPI_NAME_SIZE; |
| 566 | names_index += ACPI_NAME_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
| 570 | if (converted_name_length) { |
| 571 | *converted_name_length = (u32) required_length; |
| 572 | } |
| 573 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 574 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | /******************************************************************************* |
| 578 | * |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 579 | * FUNCTION: acpi_ns_validate_handle |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 581 | * PARAMETERS: handle - Handle to be validated and typecast to a |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 582 | * namespace node. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | * |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 584 | * RETURN: A pointer to a namespace node |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | * |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 586 | * DESCRIPTION: Convert a namespace handle to a namespace node. Handles special |
| 587 | * cases for the root node. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | * |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 589 | * NOTE: Real integer handles would allow for more verification |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 590 | * and keep all pointers within this subsystem - however this introduces |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 591 | * more overhead and has not been necessary to this point. Drivers |
| 592 | * holding handles are typically notified before a node becomes invalid |
| 593 | * due to a table unload. |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 594 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | ******************************************************************************/ |
| 596 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 597 | struct acpi_namespace_node *acpi_ns_validate_handle(acpi_handle handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | { |
| 599 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 600 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
Bob Moore | d4913dc | 2009-03-06 10:05:18 +0800 | [diff] [blame] | 602 | /* Parameter validation */ |
| 603 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 604 | if ((!handle) || (handle == ACPI_ROOT_OBJECT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | return (acpi_gbl_root_node); |
| 606 | } |
| 607 | |
| 608 | /* We can at least attempt to verify the handle */ |
| 609 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 610 | if (ACPI_GET_DESCRIPTOR_TYPE(handle) != ACPI_DESC_TYPE_NAMED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | return (NULL); |
| 612 | } |
| 613 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 614 | return (ACPI_CAST_PTR(struct acpi_namespace_node, handle)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | /******************************************************************************* |
| 618 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | * FUNCTION: acpi_ns_terminate |
| 620 | * |
| 621 | * PARAMETERS: none |
| 622 | * |
| 623 | * RETURN: none |
| 624 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 625 | * DESCRIPTION: free memory allocated for namespace and ACPI table storage. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | * |
| 627 | ******************************************************************************/ |
| 628 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 629 | void acpi_ns_terminate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 631 | union acpi_operand_object *obj_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 633 | ACPI_FUNCTION_TRACE(ns_terminate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
| 635 | /* |
| 636 | * 1) Free the entire namespace -- all nodes and objects |
| 637 | * |
| 638 | * Delete all object descriptors attached to namepsace nodes |
| 639 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 640 | acpi_ns_delete_namespace_subtree(acpi_gbl_root_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
| 642 | /* Detach any objects attached to the root */ |
| 643 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 644 | obj_desc = acpi_ns_get_attached_object(acpi_gbl_root_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | if (obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 646 | acpi_ns_detach_object(acpi_gbl_root_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 649 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Namespace freed\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | return_VOID; |
| 651 | } |
| 652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | /******************************************************************************* |
| 654 | * |
| 655 | * FUNCTION: acpi_ns_opens_scope |
| 656 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 657 | * PARAMETERS: type - A valid namespace type |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | * |
| 659 | * RETURN: NEWSCOPE if the passed type "opens a name scope" according |
| 660 | * to the ACPI specification, else 0 |
| 661 | * |
| 662 | ******************************************************************************/ |
| 663 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 664 | u32 acpi_ns_opens_scope(acpi_object_type type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | { |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 666 | ACPI_FUNCTION_TRACE_STR(ns_opens_scope, acpi_ut_get_type_name(type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 668 | if (!acpi_ut_valid_object_type(type)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | /* type code out of range */ |
| 671 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 672 | ACPI_WARNING((AE_INFO, "Invalid Object Type 0x%X", type)); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 673 | return_UINT32(ACPI_NS_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 676 | return_UINT32(((u32) acpi_gbl_ns_properties[type]) & ACPI_NS_NEWSCOPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | /******************************************************************************* |
| 680 | * |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 681 | * FUNCTION: acpi_ns_get_node |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 683 | * PARAMETERS: *pathname - Name to be found, in external (ASL) format. The |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | * \ (backslash) and ^ (carat) prefixes, and the |
| 685 | * . (period) to separate segments are supported. |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 686 | * prefix_node - Root of subtree to be searched, or NS_ALL for the |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 687 | * root of the name space. If Name is fully |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | * qualified (first s8 is '\'), the passed value |
| 689 | * of Scope will not be accessed. |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 690 | * flags - Used to indicate whether to perform upsearch or |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | * not. |
| 692 | * return_node - Where the Node is returned |
| 693 | * |
| 694 | * DESCRIPTION: Look up a name relative to a given scope and return the |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 695 | * corresponding Node. NOTE: Scope can be null. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | * |
| 697 | * MUTEX: Locks namespace |
| 698 | * |
| 699 | ******************************************************************************/ |
| 700 | |
| 701 | acpi_status |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 702 | acpi_ns_get_node(struct acpi_namespace_node *prefix_node, |
Bob Moore | 4b8ed63 | 2008-06-10 13:55:53 +0800 | [diff] [blame] | 703 | const char *pathname, |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 704 | u32 flags, struct acpi_namespace_node **return_node) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 706 | union acpi_generic_state scope_info; |
| 707 | acpi_status status; |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 708 | char *internal_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
Bob Moore | 5853a9f | 2009-06-02 13:20:00 +0800 | [diff] [blame] | 710 | ACPI_FUNCTION_TRACE_PTR(ns_get_node, ACPI_CAST_PTR(char, pathname)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 712 | if (!pathname) { |
| 713 | *return_node = prefix_node; |
| 714 | if (!prefix_node) { |
| 715 | *return_node = acpi_gbl_root_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 717 | return_ACPI_STATUS(AE_OK); |
| 718 | } |
| 719 | |
| 720 | /* Convert path to internal representation */ |
| 721 | |
| 722 | status = acpi_ns_internalize_name(pathname, &internal_path); |
| 723 | if (ACPI_FAILURE(status)) { |
| 724 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | /* Must lock namespace during lookup */ |
| 728 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 729 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 730 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | goto cleanup; |
| 732 | } |
| 733 | |
| 734 | /* Setup lookup scope (search starting point) */ |
| 735 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 736 | scope_info.scope.node = prefix_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
| 738 | /* Lookup the name in the namespace */ |
| 739 | |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 740 | status = acpi_ns_lookup(&scope_info, internal_path, ACPI_TYPE_ANY, |
| 741 | ACPI_IMODE_EXECUTE, |
| 742 | (flags | ACPI_NS_DONT_OPEN_SCOPE), NULL, |
| 743 | return_node); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 744 | if (ACPI_FAILURE(status)) { |
Bob Moore | 7bcc06e | 2009-02-18 14:58:08 +0800 | [diff] [blame] | 745 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%s, %s\n", |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 746 | pathname, acpi_format_exception(status))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 749 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 751 | cleanup: |
Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 752 | ACPI_FREE(internal_path); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 753 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | } |