Print this page
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/namespace/nsnames.c
+++ new/usr/src/common/acpica/components/namespace/nsnames.c
1 1 /*******************************************************************************
2 2 *
3 3 * Module Name: nsnames - Name manipulation and search
4 4 *
5 5 ******************************************************************************/
6 6
7 7 /*
8 - * Copyright (C) 2000 - 2011, Intel Corp.
8 + * Copyright (C) 2000 - 2013, Intel Corp.
9 9 * All rights reserved.
10 10 *
11 11 * Redistribution and use in source and binary forms, with or without
12 12 * modification, are permitted provided that the following conditions
13 13 * are met:
14 14 * 1. Redistributions of source code must retain the above copyright
15 15 * notice, this list of conditions, and the following disclaimer,
16 16 * without modification.
17 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 18 * substantially similar to the "NO WARRANTY" disclaimer below
19 19 * ("Disclaimer") and any redistribution must be conditioned upon
20 20 * including a substantially similar Disclaimer requirement for further
21 21 * binary redistribution.
22 22 * 3. Neither the names of the above-listed copyright holders nor the names
23 23 * of any contributors may be used to endorse or promote products derived
24 24 * from this software without specific prior written permission.
25 25 *
26 26 * Alternatively, this software may be distributed under the terms of the
27 27 * GNU General Public License ("GPL") version 2 as published by the Free
28 28 * Software Foundation.
29 29 *
30 30 * NO WARRANTY
31 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 41 * POSSIBILITY OF SUCH DAMAGES.
42 42 */
43 43
44 44 #define __NSNAMES_C__
45 45
46 46 #include "acpi.h"
47 47 #include "accommon.h"
48 48 #include "amlcode.h"
49 49 #include "acnamesp.h"
50 50
51 51
52 52 #define _COMPONENT ACPI_NAMESPACE
53 53 ACPI_MODULE_NAME ("nsnames")
54 54
55 55
56 56 /*******************************************************************************
57 57 *
58 58 * FUNCTION: AcpiNsBuildExternalPath
59 59 *
60 60 * PARAMETERS: Node - NS node whose pathname is needed
61 61 * Size - Size of the pathname
62 62 * *NameBuffer - Where to return the pathname
63 63 *
64 64 * RETURN: Status
65 65 * Places the pathname into the NameBuffer, in external format
66 66 * (name segments separated by path separators)
67 67 *
68 68 * DESCRIPTION: Generate a full pathaname
69 69 *
70 70 ******************************************************************************/
71 71
72 72 ACPI_STATUS
73 73 AcpiNsBuildExternalPath (
74 74 ACPI_NAMESPACE_NODE *Node,
75 75 ACPI_SIZE Size,
76 76 char *NameBuffer)
77 77 {
78 78 ACPI_SIZE Index;
79 79 ACPI_NAMESPACE_NODE *ParentNode;
80 80
81 81
82 82 ACPI_FUNCTION_ENTRY ();
83 83
84 84
85 85 /* Special case for root */
86 86
87 87 Index = Size - 1;
88 88 if (Index < ACPI_NAME_SIZE)
89 89 {
90 90 NameBuffer[0] = AML_ROOT_PREFIX;
91 91 NameBuffer[1] = 0;
92 92 return (AE_OK);
93 93 }
94 94
95 95 /* Store terminator byte, then build name backwards */
96 96
97 97 ParentNode = Node;
98 98 NameBuffer[Index] = 0;
99 99
100 100 while ((Index > ACPI_NAME_SIZE) && (ParentNode != AcpiGbl_RootNode))
101 101 {
102 102 Index -= ACPI_NAME_SIZE;
103 103
104 104 /* Put the name into the buffer */
105 105
106 106 ACPI_MOVE_32_TO_32 ((NameBuffer + Index), &ParentNode->Name);
107 107 ParentNode = ParentNode->Parent;
108 108
109 109 /* Prefix name with the path separator */
110 110
111 111 Index--;
112 112 NameBuffer[Index] = ACPI_PATH_SEPARATOR;
113 113 }
114 114
115 115 /* Overwrite final separator with the root prefix character */
116 116
117 117 NameBuffer[Index] = AML_ROOT_PREFIX;
118 118
119 119 if (Index != 0)
120 120 {
121 121 ACPI_ERROR ((AE_INFO,
122 122 "Could not construct external pathname; index=%u, size=%u, Path=%s",
123 123 (UINT32) Index, (UINT32) Size, &NameBuffer[Size]));
124 124
125 125 return (AE_BAD_PARAMETER);
126 126 }
127 127
128 128 return (AE_OK);
129 129 }
130 130
131 131
132 132 /*******************************************************************************
133 133 *
134 134 * FUNCTION: AcpiNsGetExternalPathname
135 135 *
136 136 * PARAMETERS: Node - Namespace node whose pathname is needed
137 137 *
138 138 * RETURN: Pointer to storage containing the fully qualified name of
139 139 * the node, In external format (name segments separated by path
140 140 * separators.)
141 141 *
142 142 * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
143 143 * for error and debug statements.
144 144 *
145 145 ******************************************************************************/
146 146
147 147 char *
148 148 AcpiNsGetExternalPathname (
149 149 ACPI_NAMESPACE_NODE *Node)
150 150 {
151 151 ACPI_STATUS Status;
152 152 char *NameBuffer;
153 153 ACPI_SIZE Size;
154 154
155 155
156 156 ACPI_FUNCTION_TRACE_PTR (NsGetExternalPathname, Node);
157 157
158 158
159 159 /* Calculate required buffer size based on depth below root */
160 160
161 161 Size = AcpiNsGetPathnameLength (Node);
162 162 if (!Size)
163 163 {
164 164 return_PTR (NULL);
165 165 }
166 166
167 167 /* Allocate a buffer to be returned to caller */
168 168
169 169 NameBuffer = ACPI_ALLOCATE_ZEROED (Size);
170 170 if (!NameBuffer)
171 171 {
172 172 ACPI_ERROR ((AE_INFO, "Could not allocate %u bytes", (UINT32) Size));
173 173 return_PTR (NULL);
174 174 }
175 175
176 176 /* Build the path in the allocated buffer */
177 177
178 178 Status = AcpiNsBuildExternalPath (Node, Size, NameBuffer);
179 179 if (ACPI_FAILURE (Status))
180 180 {
181 181 ACPI_FREE (NameBuffer);
182 182 return_PTR (NULL);
183 183 }
184 184
185 185 return_PTR (NameBuffer);
186 186 }
187 187
188 188
189 189 /*******************************************************************************
190 190 *
191 191 * FUNCTION: AcpiNsGetPathnameLength
192 192 *
193 193 * PARAMETERS: Node - Namespace node
194 194 *
195 195 * RETURN: Length of path, including prefix
196 196 *
197 197 * DESCRIPTION: Get the length of the pathname string for this node
198 198 *
199 199 ******************************************************************************/
200 200
201 201 ACPI_SIZE
202 202 AcpiNsGetPathnameLength (
203 203 ACPI_NAMESPACE_NODE *Node)
204 204 {
205 205 ACPI_SIZE Size;
206 206 ACPI_NAMESPACE_NODE *NextNode;
207 207
208 208
209 209 ACPI_FUNCTION_ENTRY ();
210 210
211 211
212 212 /*
213 213 * Compute length of pathname as 5 * number of name segments.
214 214 * Go back up the parent tree to the root
215 215 */
↓ open down ↓ |
197 lines elided |
↑ open up ↑ |
216 216 Size = 0;
217 217 NextNode = Node;
218 218
219 219 while (NextNode && (NextNode != AcpiGbl_RootNode))
220 220 {
221 221 if (ACPI_GET_DESCRIPTOR_TYPE (NextNode) != ACPI_DESC_TYPE_NAMED)
222 222 {
223 223 ACPI_ERROR ((AE_INFO,
224 224 "Invalid Namespace Node (%p) while traversing namespace",
225 225 NextNode));
226 - return 0;
226 + return (0);
227 227 }
228 228 Size += ACPI_PATH_SEGMENT_LENGTH;
229 229 NextNode = NextNode->Parent;
230 230 }
231 231
232 232 if (!Size)
233 233 {
234 234 Size = 1; /* Root node case */
235 235 }
236 236
237 237 return (Size + 1); /* +1 for null string terminator */
238 238 }
239 239
240 240
241 241 /*******************************************************************************
242 242 *
243 243 * FUNCTION: AcpiNsHandleToPathname
244 244 *
245 245 * PARAMETERS: TargetHandle - Handle of named object whose name is
246 246 * to be found
247 247 * Buffer - Where the pathname is returned
248 248 *
249 249 * RETURN: Status, Buffer is filled with pathname if status is AE_OK
250 250 *
251 251 * DESCRIPTION: Build and return a full namespace pathname
252 252 *
253 253 ******************************************************************************/
254 254
255 255 ACPI_STATUS
256 256 AcpiNsHandleToPathname (
257 257 ACPI_HANDLE TargetHandle,
258 258 ACPI_BUFFER *Buffer)
259 259 {
260 260 ACPI_STATUS Status;
261 261 ACPI_NAMESPACE_NODE *Node;
262 262 ACPI_SIZE RequiredSize;
263 263
264 264
265 265 ACPI_FUNCTION_TRACE_PTR (NsHandleToPathname, TargetHandle);
266 266
267 267
268 268 Node = AcpiNsValidateHandle (TargetHandle);
269 269 if (!Node)
270 270 {
271 271 return_ACPI_STATUS (AE_BAD_PARAMETER);
272 272 }
273 273
274 274 /* Determine size required for the caller buffer */
275 275
276 276 RequiredSize = AcpiNsGetPathnameLength (Node);
277 277 if (!RequiredSize)
278 278 {
279 279 return_ACPI_STATUS (AE_BAD_PARAMETER);
280 280 }
281 281
282 282 /* Validate/Allocate/Clear caller buffer */
283 283
284 284 Status = AcpiUtInitializeBuffer (Buffer, RequiredSize);
285 285 if (ACPI_FAILURE (Status))
286 286 {
287 287 return_ACPI_STATUS (Status);
288 288 }
289 289
290 290 /* Build the path in the caller buffer */
291 291
↓ open down ↓ |
55 lines elided |
↑ open up ↑ |
292 292 Status = AcpiNsBuildExternalPath (Node, RequiredSize, Buffer->Pointer);
293 293 if (ACPI_FAILURE (Status))
294 294 {
295 295 return_ACPI_STATUS (Status);
296 296 }
297 297
298 298 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s [%X]\n",
299 299 (char *) Buffer->Pointer, (UINT32) RequiredSize));
300 300 return_ACPI_STATUS (AE_OK);
301 301 }
302 -
303 -
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX