s390/ptrace: get rid of long longs in psw_bits
[linux/fpc-iii.git] / drivers / acpi / acpica / nsnames.c
blob8934b4eddb731eacd5797e9059f4b49eab65c085
1 /*******************************************************************************
3 * Module Name: nsnames - Name manipulation and search
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2015, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "amlcode.h"
47 #include "acnamesp.h"
49 #define _COMPONENT ACPI_NAMESPACE
50 ACPI_MODULE_NAME("nsnames")
52 /*******************************************************************************
54 * FUNCTION: acpi_ns_get_external_pathname
56 * PARAMETERS: node - Namespace node whose pathname is needed
58 * RETURN: Pointer to storage containing the fully qualified name of
59 * the node, In external format (name segments separated by path
60 * separators.)
62 * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
63 * for error and debug statements.
65 ******************************************************************************/
66 char *acpi_ns_get_external_pathname(struct acpi_namespace_node *node)
68 char *name_buffer;
70 ACPI_FUNCTION_TRACE_PTR(ns_get_external_pathname, node);
72 name_buffer = acpi_ns_get_normalized_pathname(node, FALSE);
74 return_PTR(name_buffer);
77 /*******************************************************************************
79 * FUNCTION: acpi_ns_get_pathname_length
81 * PARAMETERS: node - Namespace node
83 * RETURN: Length of path, including prefix
85 * DESCRIPTION: Get the length of the pathname string for this node
87 ******************************************************************************/
89 acpi_size acpi_ns_get_pathname_length(struct acpi_namespace_node *node)
91 acpi_size size;
93 ACPI_FUNCTION_ENTRY();
95 size = acpi_ns_build_normalized_path(node, NULL, 0, FALSE);
97 return (size);
100 /*******************************************************************************
102 * FUNCTION: acpi_ns_handle_to_pathname
104 * PARAMETERS: target_handle - Handle of named object whose name is
105 * to be found
106 * buffer - Where the pathname is returned
107 * no_trailing - Remove trailing '_' for each name
108 * segment
110 * RETURN: Status, Buffer is filled with pathname if status is AE_OK
112 * DESCRIPTION: Build and return a full namespace pathname
114 ******************************************************************************/
116 acpi_status
117 acpi_ns_handle_to_pathname(acpi_handle target_handle,
118 struct acpi_buffer * buffer, u8 no_trailing)
120 acpi_status status;
121 struct acpi_namespace_node *node;
122 acpi_size required_size;
124 ACPI_FUNCTION_TRACE_PTR(ns_handle_to_pathname, target_handle);
126 node = acpi_ns_validate_handle(target_handle);
127 if (!node) {
128 return_ACPI_STATUS(AE_BAD_PARAMETER);
131 /* Determine size required for the caller buffer */
133 required_size =
134 acpi_ns_build_normalized_path(node, NULL, 0, no_trailing);
135 if (!required_size) {
136 return_ACPI_STATUS(AE_BAD_PARAMETER);
139 /* Validate/Allocate/Clear caller buffer */
141 status = acpi_ut_initialize_buffer(buffer, required_size);
142 if (ACPI_FAILURE(status)) {
143 return_ACPI_STATUS(status);
146 /* Build the path in the caller buffer */
148 (void)acpi_ns_build_normalized_path(node, buffer->pointer,
149 required_size, no_trailing);
150 if (ACPI_FAILURE(status)) {
151 return_ACPI_STATUS(status);
154 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%s [%X]\n",
155 (char *)buffer->pointer, (u32) required_size));
156 return_ACPI_STATUS(AE_OK);
159 /*******************************************************************************
161 * FUNCTION: acpi_ns_build_normalized_path
163 * PARAMETERS: node - Namespace node
164 * full_path - Where the path name is returned
165 * path_size - Size of returned path name buffer
166 * no_trailing - Remove trailing '_' from each name segment
168 * RETURN: Return 1 if the AML path is empty, otherwise returning (length
169 * of pathname + 1) which means the 'FullPath' contains a trailing
170 * null.
172 * DESCRIPTION: Build and return a full namespace pathname.
173 * Note that if the size of 'FullPath' isn't large enough to
174 * contain the namespace node's path name, the actual required
175 * buffer length is returned, and it should be greater than
176 * 'PathSize'. So callers are able to check the returning value
177 * to determine the buffer size of 'FullPath'.
179 ******************************************************************************/
182 acpi_ns_build_normalized_path(struct acpi_namespace_node *node,
183 char *full_path, u32 path_size, u8 no_trailing)
185 u32 length = 0, i;
186 char name[ACPI_NAME_SIZE];
187 u8 do_no_trailing;
188 char c, *left, *right;
189 struct acpi_namespace_node *next_node;
191 ACPI_FUNCTION_TRACE_PTR(ns_build_normalized_path, node);
193 #define ACPI_PATH_PUT8(path, size, byte, length) \
194 do { \
195 if ((length) < (size)) \
197 (path)[(length)] = (byte); \
199 (length)++; \
200 } while (0)
203 * Make sure the path_size is correct, so that we don't need to
204 * validate both full_path and path_size.
206 if (!full_path) {
207 path_size = 0;
210 if (!node) {
211 goto build_trailing_null;
214 next_node = node;
215 while (next_node && next_node != acpi_gbl_root_node) {
216 if (next_node != node) {
217 ACPI_PATH_PUT8(full_path, path_size,
218 AML_DUAL_NAME_PREFIX, length);
220 ACPI_MOVE_32_TO_32(name, &next_node->name);
221 do_no_trailing = no_trailing;
222 for (i = 0; i < 4; i++) {
223 c = name[4 - i - 1];
224 if (do_no_trailing && c != '_') {
225 do_no_trailing = FALSE;
227 if (!do_no_trailing) {
228 ACPI_PATH_PUT8(full_path, path_size, c, length);
231 next_node = next_node->parent;
233 ACPI_PATH_PUT8(full_path, path_size, AML_ROOT_PREFIX, length);
235 /* Reverse the path string */
237 if (length <= path_size) {
238 left = full_path;
239 right = full_path + length - 1;
240 while (left < right) {
241 c = *left;
242 *left++ = *right;
243 *right-- = c;
247 /* Append the trailing null */
249 build_trailing_null:
250 ACPI_PATH_PUT8(full_path, path_size, '\0', length);
252 #undef ACPI_PATH_PUT8
254 return_UINT32(length);
257 /*******************************************************************************
259 * FUNCTION: acpi_ns_get_normalized_pathname
261 * PARAMETERS: node - Namespace node whose pathname is needed
262 * no_trailing - Remove trailing '_' from each name segment
264 * RETURN: Pointer to storage containing the fully qualified name of
265 * the node, In external format (name segments separated by path
266 * separators.)
268 * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
269 * for error and debug statements. All trailing '_' will be
270 * removed from the full pathname if 'NoTrailing' is specified..
272 ******************************************************************************/
274 char *acpi_ns_get_normalized_pathname(struct acpi_namespace_node *node,
275 u8 no_trailing)
277 char *name_buffer;
278 acpi_size size;
280 ACPI_FUNCTION_TRACE_PTR(ns_get_normalized_pathname, node);
282 /* Calculate required buffer size based on depth below root */
284 size = acpi_ns_build_normalized_path(node, NULL, 0, no_trailing);
285 if (!size) {
286 return_PTR(NULL);
289 /* Allocate a buffer to be returned to caller */
291 name_buffer = ACPI_ALLOCATE_ZEROED(size);
292 if (!name_buffer) {
293 ACPI_ERROR((AE_INFO, "Could not allocate %u bytes", (u32)size));
294 return_PTR(NULL);
297 /* Build the path in the allocated buffer */
299 (void)acpi_ns_build_normalized_path(node, name_buffer, size,
300 no_trailing);
302 return_PTR(name_buffer);