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