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