nsconvert.c revision 1.1.1.8 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: nsconvert - Object conversions for objects returned by
4 1.1 christos * predefined methods
5 1.1 christos *
6 1.1 christos *****************************************************************************/
7 1.1 christos
8 1.1 christos /*
9 1.1.1.8 christos * Copyright (C) 2000 - 2017, Intel Corp.
10 1.1 christos * All rights reserved.
11 1.1 christos *
12 1.1 christos * Redistribution and use in source and binary forms, with or without
13 1.1 christos * modification, are permitted provided that the following conditions
14 1.1 christos * are met:
15 1.1 christos * 1. Redistributions of source code must retain the above copyright
16 1.1 christos * notice, this list of conditions, and the following disclaimer,
17 1.1 christos * without modification.
18 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1 christos * including a substantially similar Disclaimer requirement for further
22 1.1 christos * binary redistribution.
23 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1 christos * of any contributors may be used to endorse or promote products derived
25 1.1 christos * from this software without specific prior written permission.
26 1.1 christos *
27 1.1 christos * Alternatively, this software may be distributed under the terms of the
28 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1 christos * Software Foundation.
30 1.1 christos *
31 1.1 christos * NO WARRANTY
32 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
43 1.1 christos */
44 1.1 christos
45 1.1 christos #include "acpi.h"
46 1.1 christos #include "accommon.h"
47 1.1 christos #include "acnamesp.h"
48 1.1 christos #include "acinterp.h"
49 1.1 christos #include "acpredef.h"
50 1.1 christos #include "amlresrc.h"
51 1.1 christos
52 1.1 christos #define _COMPONENT ACPI_NAMESPACE
53 1.1 christos ACPI_MODULE_NAME ("nsconvert")
54 1.1 christos
55 1.1 christos
56 1.1 christos /*******************************************************************************
57 1.1 christos *
58 1.1 christos * FUNCTION: AcpiNsConvertToInteger
59 1.1 christos *
60 1.1 christos * PARAMETERS: OriginalObject - Object to be converted
61 1.1 christos * ReturnObject - Where the new converted object is returned
62 1.1 christos *
63 1.1 christos * RETURN: Status. AE_OK if conversion was successful.
64 1.1 christos *
65 1.1 christos * DESCRIPTION: Attempt to convert a String/Buffer object to an Integer.
66 1.1 christos *
67 1.1 christos ******************************************************************************/
68 1.1 christos
69 1.1 christos ACPI_STATUS
70 1.1 christos AcpiNsConvertToInteger (
71 1.1 christos ACPI_OPERAND_OBJECT *OriginalObject,
72 1.1 christos ACPI_OPERAND_OBJECT **ReturnObject)
73 1.1 christos {
74 1.1 christos ACPI_OPERAND_OBJECT *NewObject;
75 1.1 christos ACPI_STATUS Status;
76 1.1 christos UINT64 Value = 0;
77 1.1 christos UINT32 i;
78 1.1 christos
79 1.1 christos
80 1.1 christos switch (OriginalObject->Common.Type)
81 1.1 christos {
82 1.1 christos case ACPI_TYPE_STRING:
83 1.1 christos
84 1.1 christos /* String-to-Integer conversion */
85 1.1 christos
86 1.1 christos Status = AcpiUtStrtoul64 (OriginalObject->String.Pointer,
87 1.1.1.7 christos AcpiGbl_IntegerByteWidth, &Value);
88 1.1 christos if (ACPI_FAILURE (Status))
89 1.1 christos {
90 1.1 christos return (Status);
91 1.1 christos }
92 1.1 christos break;
93 1.1 christos
94 1.1 christos case ACPI_TYPE_BUFFER:
95 1.1 christos
96 1.1 christos /* Buffer-to-Integer conversion. Max buffer size is 64 bits. */
97 1.1 christos
98 1.1 christos if (OriginalObject->Buffer.Length > 8)
99 1.1 christos {
100 1.1 christos return (AE_AML_OPERAND_TYPE);
101 1.1 christos }
102 1.1 christos
103 1.1 christos /* Extract each buffer byte to create the integer */
104 1.1 christos
105 1.1 christos for (i = 0; i < OriginalObject->Buffer.Length; i++)
106 1.1 christos {
107 1.1.1.5 christos Value |= ((UINT64)
108 1.1.1.5 christos OriginalObject->Buffer.Pointer[i] << (i * 8));
109 1.1 christos }
110 1.1 christos break;
111 1.1 christos
112 1.1 christos default:
113 1.1 christos
114 1.1 christos return (AE_AML_OPERAND_TYPE);
115 1.1 christos }
116 1.1 christos
117 1.1 christos NewObject = AcpiUtCreateIntegerObject (Value);
118 1.1 christos if (!NewObject)
119 1.1 christos {
120 1.1 christos return (AE_NO_MEMORY);
121 1.1 christos }
122 1.1 christos
123 1.1 christos *ReturnObject = NewObject;
124 1.1 christos return (AE_OK);
125 1.1 christos }
126 1.1 christos
127 1.1 christos
128 1.1 christos /*******************************************************************************
129 1.1 christos *
130 1.1 christos * FUNCTION: AcpiNsConvertToString
131 1.1 christos *
132 1.1 christos * PARAMETERS: OriginalObject - Object to be converted
133 1.1 christos * ReturnObject - Where the new converted object is returned
134 1.1 christos *
135 1.1 christos * RETURN: Status. AE_OK if conversion was successful.
136 1.1 christos *
137 1.1 christos * DESCRIPTION: Attempt to convert a Integer/Buffer object to a String.
138 1.1 christos *
139 1.1 christos ******************************************************************************/
140 1.1 christos
141 1.1 christos ACPI_STATUS
142 1.1 christos AcpiNsConvertToString (
143 1.1 christos ACPI_OPERAND_OBJECT *OriginalObject,
144 1.1 christos ACPI_OPERAND_OBJECT **ReturnObject)
145 1.1 christos {
146 1.1 christos ACPI_OPERAND_OBJECT *NewObject;
147 1.1 christos ACPI_SIZE Length;
148 1.1 christos ACPI_STATUS Status;
149 1.1 christos
150 1.1 christos
151 1.1 christos switch (OriginalObject->Common.Type)
152 1.1 christos {
153 1.1 christos case ACPI_TYPE_INTEGER:
154 1.1 christos /*
155 1.1 christos * Integer-to-String conversion. Commonly, convert
156 1.1 christos * an integer of value 0 to a NULL string. The last element of
157 1.1 christos * _BIF and _BIX packages occasionally need this fix.
158 1.1 christos */
159 1.1 christos if (OriginalObject->Integer.Value == 0)
160 1.1 christos {
161 1.1 christos /* Allocate a new NULL string object */
162 1.1 christos
163 1.1 christos NewObject = AcpiUtCreateStringObject (0);
164 1.1 christos if (!NewObject)
165 1.1 christos {
166 1.1 christos return (AE_NO_MEMORY);
167 1.1 christos }
168 1.1 christos }
169 1.1 christos else
170 1.1 christos {
171 1.1.1.5 christos Status = AcpiExConvertToString (OriginalObject,
172 1.1.1.5 christos &NewObject, ACPI_IMPLICIT_CONVERT_HEX);
173 1.1 christos if (ACPI_FAILURE (Status))
174 1.1 christos {
175 1.1 christos return (Status);
176 1.1 christos }
177 1.1 christos }
178 1.1 christos break;
179 1.1 christos
180 1.1 christos case ACPI_TYPE_BUFFER:
181 1.1 christos /*
182 1.1 christos * Buffer-to-String conversion. Use a ToString
183 1.1 christos * conversion, no transform performed on the buffer data. The best
184 1.1 christos * example of this is the _BIF method, where the string data from
185 1.1 christos * the battery is often (incorrectly) returned as buffer object(s).
186 1.1 christos */
187 1.1 christos Length = 0;
188 1.1 christos while ((Length < OriginalObject->Buffer.Length) &&
189 1.1 christos (OriginalObject->Buffer.Pointer[Length]))
190 1.1 christos {
191 1.1 christos Length++;
192 1.1 christos }
193 1.1 christos
194 1.1 christos /* Allocate a new string object */
195 1.1 christos
196 1.1 christos NewObject = AcpiUtCreateStringObject (Length);
197 1.1 christos if (!NewObject)
198 1.1 christos {
199 1.1 christos return (AE_NO_MEMORY);
200 1.1 christos }
201 1.1 christos
202 1.1 christos /*
203 1.1 christos * Copy the raw buffer data with no transform. String is already NULL
204 1.1 christos * terminated at Length+1.
205 1.1 christos */
206 1.1.1.4 christos memcpy (NewObject->String.Pointer,
207 1.1 christos OriginalObject->Buffer.Pointer, Length);
208 1.1 christos break;
209 1.1 christos
210 1.1 christos default:
211 1.1 christos
212 1.1 christos return (AE_AML_OPERAND_TYPE);
213 1.1 christos }
214 1.1 christos
215 1.1 christos *ReturnObject = NewObject;
216 1.1 christos return (AE_OK);
217 1.1 christos }
218 1.1 christos
219 1.1 christos
220 1.1 christos /*******************************************************************************
221 1.1 christos *
222 1.1 christos * FUNCTION: AcpiNsConvertToBuffer
223 1.1 christos *
224 1.1 christos * PARAMETERS: OriginalObject - Object to be converted
225 1.1 christos * ReturnObject - Where the new converted object is returned
226 1.1 christos *
227 1.1 christos * RETURN: Status. AE_OK if conversion was successful.
228 1.1 christos *
229 1.1 christos * DESCRIPTION: Attempt to convert a Integer/String/Package object to a Buffer.
230 1.1 christos *
231 1.1 christos ******************************************************************************/
232 1.1 christos
233 1.1 christos ACPI_STATUS
234 1.1 christos AcpiNsConvertToBuffer (
235 1.1 christos ACPI_OPERAND_OBJECT *OriginalObject,
236 1.1 christos ACPI_OPERAND_OBJECT **ReturnObject)
237 1.1 christos {
238 1.1 christos ACPI_OPERAND_OBJECT *NewObject;
239 1.1 christos ACPI_STATUS Status;
240 1.1 christos ACPI_OPERAND_OBJECT **Elements;
241 1.1 christos UINT32 *DwordBuffer;
242 1.1 christos UINT32 Count;
243 1.1 christos UINT32 i;
244 1.1 christos
245 1.1 christos
246 1.1 christos switch (OriginalObject->Common.Type)
247 1.1 christos {
248 1.1 christos case ACPI_TYPE_INTEGER:
249 1.1 christos /*
250 1.1 christos * Integer-to-Buffer conversion.
251 1.1 christos * Convert the Integer to a packed-byte buffer. _MAT and other
252 1.1 christos * objects need this sometimes, if a read has been performed on a
253 1.1 christos * Field object that is less than or equal to the global integer
254 1.1 christos * size (32 or 64 bits).
255 1.1 christos */
256 1.1 christos Status = AcpiExConvertToBuffer (OriginalObject, &NewObject);
257 1.1 christos if (ACPI_FAILURE (Status))
258 1.1 christos {
259 1.1 christos return (Status);
260 1.1 christos }
261 1.1 christos break;
262 1.1 christos
263 1.1 christos case ACPI_TYPE_STRING:
264 1.1 christos
265 1.1 christos /* String-to-Buffer conversion. Simple data copy */
266 1.1 christos
267 1.1.1.5 christos NewObject = AcpiUtCreateBufferObject
268 1.1.1.5 christos (OriginalObject->String.Length);
269 1.1 christos if (!NewObject)
270 1.1 christos {
271 1.1 christos return (AE_NO_MEMORY);
272 1.1 christos }
273 1.1 christos
274 1.1.1.4 christos memcpy (NewObject->Buffer.Pointer,
275 1.1 christos OriginalObject->String.Pointer, OriginalObject->String.Length);
276 1.1 christos break;
277 1.1 christos
278 1.1 christos case ACPI_TYPE_PACKAGE:
279 1.1 christos /*
280 1.1 christos * This case is often seen for predefined names that must return a
281 1.1 christos * Buffer object with multiple DWORD integers within. For example,
282 1.1 christos * _FDE and _GTM. The Package can be converted to a Buffer.
283 1.1 christos */
284 1.1 christos
285 1.1 christos /* All elements of the Package must be integers */
286 1.1 christos
287 1.1 christos Elements = OriginalObject->Package.Elements;
288 1.1 christos Count = OriginalObject->Package.Count;
289 1.1 christos
290 1.1 christos for (i = 0; i < Count; i++)
291 1.1 christos {
292 1.1 christos if ((!*Elements) ||
293 1.1 christos ((*Elements)->Common.Type != ACPI_TYPE_INTEGER))
294 1.1 christos {
295 1.1 christos return (AE_AML_OPERAND_TYPE);
296 1.1 christos }
297 1.1 christos Elements++;
298 1.1 christos }
299 1.1 christos
300 1.1 christos /* Create the new buffer object to replace the Package */
301 1.1 christos
302 1.1 christos NewObject = AcpiUtCreateBufferObject (ACPI_MUL_4 (Count));
303 1.1 christos if (!NewObject)
304 1.1 christos {
305 1.1 christos return (AE_NO_MEMORY);
306 1.1 christos }
307 1.1 christos
308 1.1 christos /* Copy the package elements (integers) to the buffer as DWORDs */
309 1.1 christos
310 1.1 christos Elements = OriginalObject->Package.Elements;
311 1.1 christos DwordBuffer = ACPI_CAST_PTR (UINT32, NewObject->Buffer.Pointer);
312 1.1 christos
313 1.1 christos for (i = 0; i < Count; i++)
314 1.1 christos {
315 1.1 christos *DwordBuffer = (UINT32) (*Elements)->Integer.Value;
316 1.1 christos DwordBuffer++;
317 1.1 christos Elements++;
318 1.1 christos }
319 1.1 christos break;
320 1.1 christos
321 1.1 christos default:
322 1.1 christos
323 1.1 christos return (AE_AML_OPERAND_TYPE);
324 1.1 christos }
325 1.1 christos
326 1.1 christos *ReturnObject = NewObject;
327 1.1 christos return (AE_OK);
328 1.1 christos }
329 1.1 christos
330 1.1 christos
331 1.1 christos /*******************************************************************************
332 1.1 christos *
333 1.1 christos * FUNCTION: AcpiNsConvertToUnicode
334 1.1 christos *
335 1.1.1.5 christos * PARAMETERS: Scope - Namespace node for the method/object
336 1.1.1.5 christos * OriginalObject - ASCII String Object to be converted
337 1.1 christos * ReturnObject - Where the new converted object is returned
338 1.1 christos *
339 1.1 christos * RETURN: Status. AE_OK if conversion was successful.
340 1.1 christos *
341 1.1 christos * DESCRIPTION: Attempt to convert a String object to a Unicode string Buffer.
342 1.1 christos *
343 1.1 christos ******************************************************************************/
344 1.1 christos
345 1.1 christos ACPI_STATUS
346 1.1 christos AcpiNsConvertToUnicode (
347 1.1.1.5 christos ACPI_NAMESPACE_NODE *Scope,
348 1.1 christos ACPI_OPERAND_OBJECT *OriginalObject,
349 1.1 christos ACPI_OPERAND_OBJECT **ReturnObject)
350 1.1 christos {
351 1.1 christos ACPI_OPERAND_OBJECT *NewObject;
352 1.1 christos char *AsciiString;
353 1.1 christos UINT16 *UnicodeBuffer;
354 1.1 christos UINT32 UnicodeLength;
355 1.1 christos UINT32 i;
356 1.1 christos
357 1.1 christos
358 1.1 christos if (!OriginalObject)
359 1.1 christos {
360 1.1 christos return (AE_OK);
361 1.1 christos }
362 1.1 christos
363 1.1 christos /* If a Buffer was returned, it must be at least two bytes long */
364 1.1 christos
365 1.1 christos if (OriginalObject->Common.Type == ACPI_TYPE_BUFFER)
366 1.1 christos {
367 1.1 christos if (OriginalObject->Buffer.Length < 2)
368 1.1 christos {
369 1.1 christos return (AE_AML_OPERAND_VALUE);
370 1.1 christos }
371 1.1 christos
372 1.1 christos *ReturnObject = NULL;
373 1.1 christos return (AE_OK);
374 1.1 christos }
375 1.1 christos
376 1.1 christos /*
377 1.1 christos * The original object is an ASCII string. Convert this string to
378 1.1 christos * a unicode buffer.
379 1.1 christos */
380 1.1 christos AsciiString = OriginalObject->String.Pointer;
381 1.1 christos UnicodeLength = (OriginalObject->String.Length * 2) + 2;
382 1.1 christos
383 1.1 christos /* Create a new buffer object for the Unicode data */
384 1.1 christos
385 1.1 christos NewObject = AcpiUtCreateBufferObject (UnicodeLength);
386 1.1 christos if (!NewObject)
387 1.1 christos {
388 1.1 christos return (AE_NO_MEMORY);
389 1.1 christos }
390 1.1 christos
391 1.1 christos UnicodeBuffer = ACPI_CAST_PTR (UINT16, NewObject->Buffer.Pointer);
392 1.1 christos
393 1.1 christos /* Convert ASCII to Unicode */
394 1.1 christos
395 1.1 christos for (i = 0; i < OriginalObject->String.Length; i++)
396 1.1 christos {
397 1.1 christos UnicodeBuffer[i] = (UINT16) AsciiString[i];
398 1.1 christos }
399 1.1 christos
400 1.1 christos *ReturnObject = NewObject;
401 1.1 christos return (AE_OK);
402 1.1 christos }
403 1.1 christos
404 1.1 christos
405 1.1 christos /*******************************************************************************
406 1.1 christos *
407 1.1 christos * FUNCTION: AcpiNsConvertToResource
408 1.1 christos *
409 1.1.1.5 christos * PARAMETERS: Scope - Namespace node for the method/object
410 1.1.1.5 christos * OriginalObject - Object to be converted
411 1.1 christos * ReturnObject - Where the new converted object is returned
412 1.1 christos *
413 1.1 christos * RETURN: Status. AE_OK if conversion was successful
414 1.1 christos *
415 1.1 christos * DESCRIPTION: Attempt to convert a Integer object to a ResourceTemplate
416 1.1 christos * Buffer.
417 1.1 christos *
418 1.1 christos ******************************************************************************/
419 1.1 christos
420 1.1 christos ACPI_STATUS
421 1.1 christos AcpiNsConvertToResource (
422 1.1.1.5 christos ACPI_NAMESPACE_NODE *Scope,
423 1.1 christos ACPI_OPERAND_OBJECT *OriginalObject,
424 1.1 christos ACPI_OPERAND_OBJECT **ReturnObject)
425 1.1 christos {
426 1.1 christos ACPI_OPERAND_OBJECT *NewObject;
427 1.1 christos UINT8 *Buffer;
428 1.1 christos
429 1.1 christos
430 1.1 christos /*
431 1.1 christos * We can fix the following cases for an expected resource template:
432 1.1 christos * 1. No return value (interpreter slack mode is disabled)
433 1.1 christos * 2. A "Return (Zero)" statement
434 1.1 christos * 3. A "Return empty buffer" statement
435 1.1 christos *
436 1.1 christos * We will return a buffer containing a single EndTag
437 1.1 christos * resource descriptor.
438 1.1 christos */
439 1.1 christos if (OriginalObject)
440 1.1 christos {
441 1.1 christos switch (OriginalObject->Common.Type)
442 1.1 christos {
443 1.1 christos case ACPI_TYPE_INTEGER:
444 1.1 christos
445 1.1 christos /* We can only repair an Integer==0 */
446 1.1 christos
447 1.1 christos if (OriginalObject->Integer.Value)
448 1.1 christos {
449 1.1 christos return (AE_AML_OPERAND_TYPE);
450 1.1 christos }
451 1.1 christos break;
452 1.1 christos
453 1.1 christos case ACPI_TYPE_BUFFER:
454 1.1 christos
455 1.1 christos if (OriginalObject->Buffer.Length)
456 1.1 christos {
457 1.1 christos /* Additional checks can be added in the future */
458 1.1 christos
459 1.1 christos *ReturnObject = NULL;
460 1.1 christos return (AE_OK);
461 1.1 christos }
462 1.1 christos break;
463 1.1 christos
464 1.1 christos case ACPI_TYPE_STRING:
465 1.1 christos default:
466 1.1 christos
467 1.1 christos return (AE_AML_OPERAND_TYPE);
468 1.1 christos }
469 1.1 christos }
470 1.1 christos
471 1.1 christos /* Create the new buffer object for the resource descriptor */
472 1.1 christos
473 1.1 christos NewObject = AcpiUtCreateBufferObject (2);
474 1.1 christos if (!NewObject)
475 1.1 christos {
476 1.1 christos return (AE_NO_MEMORY);
477 1.1 christos }
478 1.1 christos
479 1.1 christos Buffer = ACPI_CAST_PTR (UINT8, NewObject->Buffer.Pointer);
480 1.1 christos
481 1.1 christos /* Initialize the Buffer with a single EndTag descriptor */
482 1.1 christos
483 1.1 christos Buffer[0] = (ACPI_RESOURCE_NAME_END_TAG | ASL_RDESC_END_TAG_SIZE);
484 1.1 christos Buffer[1] = 0x00;
485 1.1 christos
486 1.1 christos *ReturnObject = NewObject;
487 1.1 christos return (AE_OK);
488 1.1 christos }
489 1.1.1.5 christos
490 1.1.1.5 christos
491 1.1.1.5 christos /*******************************************************************************
492 1.1.1.5 christos *
493 1.1.1.5 christos * FUNCTION: AcpiNsConvertToReference
494 1.1.1.5 christos *
495 1.1.1.5 christos * PARAMETERS: Scope - Namespace node for the method/object
496 1.1.1.5 christos * OriginalObject - Object to be converted
497 1.1.1.5 christos * ReturnObject - Where the new converted object is returned
498 1.1.1.5 christos *
499 1.1.1.5 christos * RETURN: Status. AE_OK if conversion was successful
500 1.1.1.5 christos *
501 1.1.1.5 christos * DESCRIPTION: Attempt to convert a Integer object to a ObjectReference.
502 1.1.1.5 christos * Buffer.
503 1.1.1.5 christos *
504 1.1.1.5 christos ******************************************************************************/
505 1.1.1.5 christos
506 1.1.1.5 christos ACPI_STATUS
507 1.1.1.5 christos AcpiNsConvertToReference (
508 1.1.1.5 christos ACPI_NAMESPACE_NODE *Scope,
509 1.1.1.5 christos ACPI_OPERAND_OBJECT *OriginalObject,
510 1.1.1.5 christos ACPI_OPERAND_OBJECT **ReturnObject)
511 1.1.1.5 christos {
512 1.1.1.5 christos ACPI_OPERAND_OBJECT *NewObject = NULL;
513 1.1.1.5 christos ACPI_STATUS Status;
514 1.1.1.5 christos ACPI_NAMESPACE_NODE *Node;
515 1.1.1.5 christos ACPI_GENERIC_STATE ScopeInfo;
516 1.1.1.5 christos char *Name;
517 1.1.1.5 christos
518 1.1.1.5 christos
519 1.1.1.5 christos ACPI_FUNCTION_NAME (NsConvertToReference);
520 1.1.1.5 christos
521 1.1.1.5 christos
522 1.1.1.5 christos /* Convert path into internal presentation */
523 1.1.1.5 christos
524 1.1.1.5 christos Status = AcpiNsInternalizeName (OriginalObject->String.Pointer, &Name);
525 1.1.1.5 christos if (ACPI_FAILURE (Status))
526 1.1.1.5 christos {
527 1.1.1.5 christos return_ACPI_STATUS (Status);
528 1.1.1.5 christos }
529 1.1.1.5 christos
530 1.1.1.5 christos /* Find the namespace node */
531 1.1.1.5 christos
532 1.1.1.5 christos ScopeInfo.Scope.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Scope);
533 1.1.1.5 christos Status = AcpiNsLookup (&ScopeInfo, Name,
534 1.1.1.5 christos ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
535 1.1.1.5 christos ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
536 1.1.1.5 christos if (ACPI_FAILURE (Status))
537 1.1.1.5 christos {
538 1.1.1.5 christos /* Check if we are resolving a named reference within a package */
539 1.1.1.5 christos
540 1.1.1.5 christos ACPI_ERROR_NAMESPACE (OriginalObject->String.Pointer, Status);
541 1.1.1.5 christos goto ErrorExit;
542 1.1.1.5 christos }
543 1.1.1.5 christos
544 1.1.1.5 christos /* Create and init a new internal ACPI object */
545 1.1.1.5 christos
546 1.1.1.5 christos NewObject = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
547 1.1.1.5 christos if (!NewObject)
548 1.1.1.5 christos {
549 1.1.1.5 christos Status = AE_NO_MEMORY;
550 1.1.1.5 christos goto ErrorExit;
551 1.1.1.5 christos }
552 1.1.1.5 christos NewObject->Reference.Node = Node;
553 1.1.1.5 christos NewObject->Reference.Object = Node->Object;
554 1.1.1.5 christos NewObject->Reference.Class = ACPI_REFCLASS_NAME;
555 1.1.1.5 christos
556 1.1.1.5 christos /*
557 1.1.1.5 christos * Increase reference of the object if needed (the object is likely a
558 1.1.1.5 christos * null for device nodes).
559 1.1.1.5 christos */
560 1.1.1.5 christos AcpiUtAddReference (Node->Object);
561 1.1.1.5 christos
562 1.1.1.5 christos ErrorExit:
563 1.1.1.5 christos ACPI_FREE (Name);
564 1.1.1.5 christos *ReturnObject = NewObject;
565 1.1.1.5 christos return (AE_OK);
566 1.1.1.5 christos }
567