ReactOS 0.4.15-dev-8231-g29a56f3
nsconvert.c File Reference
#include "acpi.h"
#include "accommon.h"
#include "acnamesp.h"
#include "acinterp.h"
#include "acpredef.h"
#include "amlresrc.h"
Include dependency graph for nsconvert.c:

Go to the source code of this file.

Macros

#define _COMPONENT   ACPI_NAMESPACE
 

Functions

ACPI_STATUS AcpiNsConvertToInteger (ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject)
 
ACPI_STATUS AcpiNsConvertToString (ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject)
 
ACPI_STATUS AcpiNsConvertToBuffer (ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject)
 
ACPI_STATUS AcpiNsConvertToUnicode (ACPI_NAMESPACE_NODE *Scope, ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject)
 
ACPI_STATUS AcpiNsConvertToResource (ACPI_NAMESPACE_NODE *Scope, ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject)
 
ACPI_STATUS AcpiNsConvertToReference (ACPI_NAMESPACE_NODE *Scope, ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject)
 

Macro Definition Documentation

◆ _COMPONENT

#define _COMPONENT   ACPI_NAMESPACE

Definition at line 52 of file nsconvert.c.

Function Documentation

◆ AcpiNsConvertToBuffer()

ACPI_STATUS AcpiNsConvertToBuffer ( ACPI_OPERAND_OBJECT OriginalObject,
ACPI_OPERAND_OBJECT **  ReturnObject 
)

Definition at line 233 of file nsconvert.c.

236{
239 ACPI_OPERAND_OBJECT **Elements;
240 UINT32 *DwordBuffer;
242 UINT32 i;
243
244
245 switch (OriginalObject->Common.Type)
246 {
248 /*
249 * Integer-to-Buffer conversion.
250 * Convert the Integer to a packed-byte buffer. _MAT and other
251 * objects need this sometimes, if a read has been performed on a
252 * Field object that is less than or equal to the global integer
253 * size (32 or 64 bits).
254 */
255 Status = AcpiExConvertToBuffer (OriginalObject, &NewObject);
256 if (ACPI_FAILURE (Status))
257 {
258 return (Status);
259 }
260 break;
261
262 case ACPI_TYPE_STRING:
263
264 /* String-to-Buffer conversion. Simple data copy */
265
267 (OriginalObject->String.Length);
268 if (!NewObject)
269 {
270 return (AE_NO_MEMORY);
271 }
272
273 memcpy (NewObject->Buffer.Pointer,
274 OriginalObject->String.Pointer, OriginalObject->String.Length);
275 break;
276
278 /*
279 * This case is often seen for predefined names that must return a
280 * Buffer object with multiple DWORD integers within. For example,
281 * _FDE and _GTM. The Package can be converted to a Buffer.
282 */
283
284 /* All elements of the Package must be integers */
285
286 Elements = OriginalObject->Package.Elements;
287 Count = OriginalObject->Package.Count;
288
289 for (i = 0; i < Count; i++)
290 {
291 if ((!*Elements) ||
292 ((*Elements)->Common.Type != ACPI_TYPE_INTEGER))
293 {
294 return (AE_AML_OPERAND_TYPE);
295 }
296 Elements++;
297 }
298
299 /* Create the new buffer object to replace the Package */
300
302 if (!NewObject)
303 {
304 return (AE_NO_MEMORY);
305 }
306
307 /* Copy the package elements (integers) to the buffer as DWORDs */
308
309 Elements = OriginalObject->Package.Elements;
310 DwordBuffer = ACPI_CAST_PTR (UINT32, NewObject->Buffer.Pointer);
311
312 for (i = 0; i < Count; i++)
313 {
314 *DwordBuffer = (UINT32) (*Elements)->Integer.Value;
315 DwordBuffer++;
316 Elements++;
317 }
318 break;
319
320 default:
321
322 return (AE_AML_OPERAND_TYPE);
323 }
324
325 *ReturnObject = NewObject;
326 return (AE_OK);
327}
unsigned int UINT32
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_NO_MEMORY
Definition: acexcep.h:112
#define AE_AML_OPERAND_TYPE
Definition: acexcep.h:182
#define AE_OK
Definition: acexcep.h:97
#define ACPI_MUL_4(a)
Definition: acmacros.h:211
#define ACPI_TYPE_STRING
Definition: actypes.h:689
#define ACPI_TYPE_INTEGER
Definition: actypes.h:688
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_CAST_PTR(t, p)
Definition: actypes.h:544
#define ACPI_TYPE_PACKAGE
Definition: actypes.h:691
ACPI_OPERAND_OBJECT * AcpiUtCreateBufferObject(ACPI_SIZE BufferSize)
Definition: utobject.c:258
ACPI_STATUS AcpiExConvertToBuffer(ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT **ResultDesc)
Definition: exconvrt.c:224
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
int Count
Definition: noreturn.cpp:7
union acpi_operand_object ** Elements
Definition: acobject.h:161
ACPI_OBJECT_COMMON Common
Definition: acobject.h:519
ACPI_OBJECT_PACKAGE Package
Definition: acobject.h:523
ACPI_OBJECT_STRING String
Definition: acobject.h:521
_Inout_opt_ PACCESS_STATE _In_opt_ ACCESS_MASK _In_ ULONG _Out_opt_ PVOID * NewObject
Definition: obfuncs.h:74

Referenced by AcpiNsSimpleRepair().

◆ AcpiNsConvertToInteger()

ACPI_STATUS AcpiNsConvertToInteger ( ACPI_OPERAND_OBJECT OriginalObject,
ACPI_OPERAND_OBJECT **  ReturnObject 
)

Definition at line 70 of file nsconvert.c.

73{
76 UINT64 Value = 0;
77 UINT32 i;
78
79
80 switch (OriginalObject->Common.Type)
81 {
83
84 /* String-to-Integer conversion */
85
86 Status = AcpiUtStrtoul64 (OriginalObject->String.Pointer, &Value);
87 if (ACPI_FAILURE (Status))
88 {
89 return (Status);
90 }
91 break;
92
94
95 /* Buffer-to-Integer conversion. Max buffer size is 64 bits. */
96
97 if (OriginalObject->Buffer.Length > 8)
98 {
99 return (AE_AML_OPERAND_TYPE);
100 }
101
102 /* Extract each buffer byte to create the integer */
103
104 for (i = 0; i < OriginalObject->Buffer.Length; i++)
105 {
106 Value |= ((UINT64)
107 OriginalObject->Buffer.Pointer[i] << (i * 8));
108 }
109 break;
110
111 default:
112
113 return (AE_AML_OPERAND_TYPE);
114 }
115
117 if (!NewObject)
118 {
119 return (AE_NO_MEMORY);
120 }
121
122 *ReturnObject = NewObject;
123 return (AE_OK);
124}
unsigned long long UINT64
#define ACPI_TYPE_BUFFER
Definition: actypes.h:690
ACPI_OPERAND_OBJECT * AcpiUtCreateIntegerObject(UINT64 Value)
Definition: utobject.c:223
ACPI_STATUS AcpiUtStrtoul64(char *String, UINT64 *RetInteger)
Definition: utstrtoul64.c:121
ACPI_OBJECT_BUFFER Buffer
Definition: acobject.h:522
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by AcpiNsSimpleRepair().

◆ AcpiNsConvertToReference()

ACPI_STATUS AcpiNsConvertToReference ( ACPI_NAMESPACE_NODE Scope,
ACPI_OPERAND_OBJECT OriginalObject,
ACPI_OPERAND_OBJECT **  ReturnObject 
)

Definition at line 506 of file nsconvert.c.

510{
514 ACPI_GENERIC_STATE ScopeInfo;
515 char *Name;
516
517
518 ACPI_FUNCTION_NAME (NsConvertToReference);
519
520
521 /* Convert path into internal presentation */
522
523 Status = AcpiNsInternalizeName (OriginalObject->String.Pointer, &Name);
524 if (ACPI_FAILURE (Status))
525 {
527 }
528
529 /* Find the namespace node */
530
531 ScopeInfo.Scope.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Scope);
532 Status = AcpiNsLookup (&ScopeInfo, Name,
535 if (ACPI_FAILURE (Status))
536 {
537 /* Check if we are resolving a named reference within a package */
538
539 ACPI_ERROR_NAMESPACE (&ScopeInfo,
540 OriginalObject->String.Pointer, Status);
541 goto ErrorExit;
542 }
543
544 /* Create and init a new internal ACPI object */
545
547 if (!NewObject)
548 {
550 goto ErrorExit;
551 }
552 NewObject->Reference.Node = Node;
553 NewObject->Reference.Object = Node->Object;
554 NewObject->Reference.Class = ACPI_REFCLASS_NAME;
555
556 /*
557 * Increase reference of the object if needed (the object is likely a
558 * null for device nodes).
559 */
560 AcpiUtAddReference (Node->Object);
561
563 ACPI_FREE (Name);
564 *ReturnObject = NewObject;
565 return (Status);
566}
@ ACPI_IMODE_EXECUTE
Definition: aclocal.h:169
#define ACPI_ERROR_NAMESPACE(s, p, e)
Definition: acmacros.h:462
ACPI_STATUS AcpiNsLookup(ACPI_GENERIC_STATE *ScopeInfo, char *Name, ACPI_OBJECT_TYPE Type, ACPI_INTERPRETER_MODE InterpreterMode, UINT32 Flags, ACPI_WALK_STATE *WalkState, ACPI_NAMESPACE_NODE **RetNode)
Definition: nsaccess.c:328
ACPI_STATUS AcpiNsInternalizeName(const char *DottedName, char **ConvertedName)
Definition: nsutils.c:405
#define ACPI_NS_DONT_OPEN_SCOPE
Definition: acnamesp.h:64
#define ACPI_NS_SEARCH_PARENT
Definition: acnamesp.h:63
@ ACPI_REFCLASS_NAME
Definition: acobject.h:464
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_NAME(a)
Definition: acoutput.h:479
#define ACPI_TYPE_LOCAL_REFERENCE
Definition: actypes.h:719
#define ACPI_FREE(a)
Definition: actypes.h:386
#define ACPI_TYPE_ANY
Definition: actypes.h:687
#define AcpiUtCreateInternalObject(t)
Definition: acutils.h:681
void AcpiUtAddReference(ACPI_OPERAND_OBJECT *Object)
Definition: utdelete.c:752
struct NameRec_ * Name
Definition: cdprocs.h:460
#define NULL
Definition: types.h:112
union node Node
Definition: types.h:1255
ACPI_STATE_COMMON ACPI_NAMESPACE_NODE * Node
Definition: aclocal.h:740
static VOID ErrorExit(LPTSTR lpszMessage)
Definition: telnetd.c:647
ACPI_SCOPE_STATE Scope
Definition: aclocal.h:825
Definition: dlist.c:348

◆ AcpiNsConvertToResource()

ACPI_STATUS AcpiNsConvertToResource ( ACPI_NAMESPACE_NODE Scope,
ACPI_OPERAND_OBJECT OriginalObject,
ACPI_OPERAND_OBJECT **  ReturnObject 
)

Definition at line 420 of file nsconvert.c.

424{
426 UINT8 *Buffer;
427
428
429 /*
430 * We can fix the following cases for an expected resource template:
431 * 1. No return value (interpreter slack mode is disabled)
432 * 2. A "Return (Zero)" statement
433 * 3. A "Return empty buffer" statement
434 *
435 * We will return a buffer containing a single EndTag
436 * resource descriptor.
437 */
438 if (OriginalObject)
439 {
440 switch (OriginalObject->Common.Type)
441 {
443
444 /* We can only repair an Integer==0 */
445
446 if (OriginalObject->Integer.Value)
447 {
448 return (AE_AML_OPERAND_TYPE);
449 }
450 break;
451
452 case ACPI_TYPE_BUFFER:
453
454 if (OriginalObject->Buffer.Length)
455 {
456 /* Additional checks can be added in the future */
457
458 *ReturnObject = NULL;
459 return (AE_OK);
460 }
461 break;
462
463 case ACPI_TYPE_STRING:
464 default:
465
466 return (AE_AML_OPERAND_TYPE);
467 }
468 }
469
470 /* Create the new buffer object for the resource descriptor */
471
473 if (!NewObject)
474 {
475 return (AE_NO_MEMORY);
476 }
477
478 Buffer = ACPI_CAST_PTR (UINT8, NewObject->Buffer.Pointer);
479
480 /* Initialize the Buffer with a single EndTag descriptor */
481
483 Buffer[1] = 0x00;
484
485 *ReturnObject = NewObject;
486 return (AE_OK);
487}
unsigned char UINT8
#define ACPI_RESOURCE_NAME_END_TAG
Definition: aclocal.h:1323
#define ASL_RDESC_END_TAG_SIZE
Definition: amlresrc.h:119
Definition: bufpool.h:45
ACPI_OBJECT_INTEGER Integer
Definition: acobject.h:520

◆ AcpiNsConvertToString()

ACPI_STATUS AcpiNsConvertToString ( ACPI_OPERAND_OBJECT OriginalObject,
ACPI_OPERAND_OBJECT **  ReturnObject 
)

Definition at line 141 of file nsconvert.c.

144{
146 ACPI_SIZE Length;
148
149
150 switch (OriginalObject->Common.Type)
151 {
153 /*
154 * Integer-to-String conversion. Commonly, convert
155 * an integer of value 0 to a NULL string. The last element of
156 * _BIF and _BIX packages occasionally need this fix.
157 */
158 if (OriginalObject->Integer.Value == 0)
159 {
160 /* Allocate a new NULL string object */
161
163 if (!NewObject)
164 {
165 return (AE_NO_MEMORY);
166 }
167 }
168 else
169 {
170 Status = AcpiExConvertToString (OriginalObject,
172 if (ACPI_FAILURE (Status))
173 {
174 return (Status);
175 }
176 }
177 break;
178
179 case ACPI_TYPE_BUFFER:
180 /*
181 * Buffer-to-String conversion. Use a ToString
182 * conversion, no transform performed on the buffer data. The best
183 * example of this is the _BIF method, where the string data from
184 * the battery is often (incorrectly) returned as buffer object(s).
185 */
186 Length = 0;
187 while ((Length < OriginalObject->Buffer.Length) &&
188 (OriginalObject->Buffer.Pointer[Length]))
189 {
190 Length++;
191 }
192
193 /* Allocate a new string object */
194
196 if (!NewObject)
197 {
198 return (AE_NO_MEMORY);
199 }
200
201 /*
202 * Copy the raw buffer data with no transform. String is already NULL
203 * terminated at Length+1.
204 */
205 memcpy (NewObject->String.Pointer,
206 OriginalObject->Buffer.Pointer, Length);
207 break;
208
209 default:
210
211 return (AE_AML_OPERAND_TYPE);
212 }
213
214 *ReturnObject = NewObject;
215 return (AE_OK);
216}
#define ACPI_IMPLICIT_CONVERT_HEX
Definition: acinterp.h:126
ACPI_OPERAND_OBJECT * AcpiUtCreateStringObject(ACPI_SIZE StringSize)
Definition: utobject.c:320
ACPI_STATUS AcpiExConvertToString(ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT **ResultDesc, UINT32 Type)
Definition: exconvrt.c:440
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102

Referenced by AcpiNsSimpleRepair().

◆ AcpiNsConvertToUnicode()

ACPI_STATUS AcpiNsConvertToUnicode ( ACPI_NAMESPACE_NODE Scope,
ACPI_OPERAND_OBJECT OriginalObject,
ACPI_OPERAND_OBJECT **  ReturnObject 
)

Definition at line 345 of file nsconvert.c.

349{
351 char *AsciiString;
352 UINT16 *UnicodeBuffer;
353 UINT32 UnicodeLength;
354 UINT32 i;
355
356
357 if (!OriginalObject)
358 {
359 return (AE_OK);
360 }
361
362 /* If a Buffer was returned, it must be at least two bytes long */
363
364 if (OriginalObject->Common.Type == ACPI_TYPE_BUFFER)
365 {
366 if (OriginalObject->Buffer.Length < 2)
367 {
368 return (AE_AML_OPERAND_VALUE);
369 }
370
371 *ReturnObject = NULL;
372 return (AE_OK);
373 }
374
375 /*
376 * The original object is an ASCII string. Convert this string to
377 * a unicode buffer.
378 */
379 AsciiString = OriginalObject->String.Pointer;
380 UnicodeLength = (OriginalObject->String.Length * 2) + 2;
381
382 /* Create a new buffer object for the Unicode data */
383
384 NewObject = AcpiUtCreateBufferObject (UnicodeLength);
385 if (!NewObject)
386 {
387 return (AE_NO_MEMORY);
388 }
389
390 UnicodeBuffer = ACPI_CAST_PTR (UINT16, NewObject->Buffer.Pointer);
391
392 /* Convert ASCII to Unicode */
393
394 for (i = 0; i < OriginalObject->String.Length; i++)
395 {
396 UnicodeBuffer[i] = (UINT16) AsciiString[i];
397 }
398
399 *ReturnObject = NewObject;
400 return (AE_OK);
401}
unsigned short UINT16
#define AE_AML_OPERAND_VALUE
Definition: acexcep.h:183