ReactOS 0.4.15-dev-6056-gb29b268
utils.c File Reference
#include <precomp.h>
#include <ntstrsafe.h>
#include <debug.h>
Include dependency graph for utils.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define _COMPONENT   ACPI_BUS_COMPONENT
 

Functions

static void acpi_util_eval_error (ACPI_HANDLE h, ACPI_STRING p, ACPI_STATUS s)
 
ACPI_STATUS acpi_extract_package (ACPI_OBJECT *package, ACPI_BUFFER *format, ACPI_BUFFER *buffer)
 
ACPI_STATUS acpi_evaluate_integer (ACPI_HANDLE handle, ACPI_STRING pathname, ACPI_OBJECT_LIST *arguments, unsigned long long *data)
 
ACPI_STATUS acpi_evaluate_reference (ACPI_HANDLE handle, ACPI_STRING pathname, ACPI_OBJECT_LIST *arguments, struct acpi_handle_list *list)
 
NTSTATUS acpi_create_registry_table (HANDLE ParentKeyHandle, ACPI_TABLE_HEADER *OutTable, PCWSTR KeyName)
 
NTSTATUS acpi_create_volatile_registry_tables (void)
 

Macro Definition Documentation

◆ _COMPONENT

#define _COMPONENT   ACPI_BUS_COMPONENT

Definition at line 36 of file utils.c.

◆ NDEBUG

#define NDEBUG

Definition at line 29 of file utils.c.

Function Documentation

◆ acpi_create_registry_table()

NTSTATUS acpi_create_registry_table ( HANDLE  ParentKeyHandle,
ACPI_TABLE_HEADER OutTable,
PCWSTR  KeyName 
)

Definition at line 374 of file utils.c.

375{
377 UNICODE_STRING HardwareKeyName, ValueName;
378 ANSI_STRING HardwareKeyNameA;
381 char OemId[7] = { 0 }; /* exactly one byte more than ACPI_TABLE_HEADER->OemId */
382 char OemTableId[9] = { 0 }; /* exactly one byte more than ACPI_TABLE_HEADER->OemTableId */
383 WCHAR OemRevision[9] = { 0 }; /* enough to accept hex DWORD */
384
385 C_ASSERT(sizeof(OemId) == RTL_FIELD_SIZE(ACPI_TABLE_HEADER, OemId) + 1);
386 C_ASSERT(sizeof(OemTableId) == RTL_FIELD_SIZE(ACPI_TABLE_HEADER, OemTableId) + 1);
387 /* Copy OEM data from the table */
388 RtlCopyMemory(OemId, OutTable->OemId, sizeof(OutTable->OemId));
389 RtlCopyMemory(OemTableId, OutTable->OemTableId, sizeof(OutTable->OemTableId));
390 /* Create table subkey */
391 RtlInitUnicodeString(&HardwareKeyName, KeyName);
393 &HardwareKeyName,
395 ParentKeyHandle,
396 NULL);
397 Status = ZwCreateKey(&KeyHandle,
398 KEY_WRITE,
400 0,
401 NULL,
403 NULL);
404 if (!NT_SUCCESS(Status))
405 {
406 DPRINT1("ZwCreateKey() for %ws failed (Status 0x%08lx)\n", KeyName, Status);
407 return Status;
408 }
409
410 if (OutTable->OemRevision != 0)
411 {
412 /* We have OEM info in table, so create other OEM subkeys */
413 RtlInitAnsiString(&HardwareKeyNameA, OemId);
414 Status = RtlAnsiStringToUnicodeString(&HardwareKeyName, &HardwareKeyNameA, TRUE);
415 if (!NT_SUCCESS(Status))
416 {
417 DPRINT1("RtlAnsiStringToUnicodeString() for %s failed (Status 0x%08lx)\n", HardwareKeyNameA, Status);
419 return Status;
420 }
421
423 &HardwareKeyName,
425 KeyHandle,
426 NULL);
427 Status = ZwCreateKey(&SubKeyHandle,
428 KEY_WRITE,
430 0,
431 NULL,
433 NULL);
434 RtlFreeUnicodeString(&HardwareKeyName);
436 if (!NT_SUCCESS(Status))
437 {
438 DPRINT1("ZwCreateKey() for %s failed (Status 0x%08lx)\n", HardwareKeyNameA, Status);
439 return Status;
440 }
442
443 RtlInitAnsiString(&HardwareKeyNameA, OemTableId);
444 Status = RtlAnsiStringToUnicodeString(&HardwareKeyName, &HardwareKeyNameA, TRUE);
445 if (!NT_SUCCESS(Status))
446 {
447 DPRINT1("RtlAnsiStringToUnicodeString() for %s failed (Status 0x%08lx)\n", HardwareKeyNameA, Status);
449 return Status;
450 }
451
453 &HardwareKeyName,
455 KeyHandle,
456 NULL);
457 Status = ZwCreateKey(&SubKeyHandle,
458 KEY_WRITE,
460 0,
461 NULL,
463 NULL);
464 RtlFreeUnicodeString(&HardwareKeyName);
466 if (!NT_SUCCESS(Status))
467 {
468 DPRINT1("ZwCreateKey() for %s failed (Status 0x%08lx)\n", HardwareKeyNameA, Status);
469 return Status;
470 }
472
473 Status = RtlStringCbPrintfW(OemRevision,
474 sizeof(OemRevision),
475 L"%08X",
476 OutTable->OemRevision);
477 if (!NT_SUCCESS(Status))
478 {
479 DPRINT1("RtlStringCbPrintfW() for 0x%08lx failed (Status 0x%08lx)\n", OutTable->OemRevision, Status);
481 return Status;
482 }
483 RtlInitUnicodeString(&HardwareKeyName, OemRevision);
484
486 &HardwareKeyName,
488 KeyHandle,
489 NULL);
490 Status = ZwCreateKey(&SubKeyHandle,
491 KEY_WRITE,
493 0,
494 NULL,
496 NULL);
498 if (!NT_SUCCESS(Status))
499 {
500 DPRINT1("ZwCreateKey() for %ws failed (Status 0x%08lx)\n", KeyName, Status);
501 return Status;
502 }
504 }
505 /* Table reg value name is always '00000000' */
507 L"00000000");
508 Status = ZwSetValueKey(KeyHandle,
509 &ValueName,
510 0,
512 OutTable,
513 OutTable->Length);
515 if (!NT_SUCCESS(Status))
516 {
517 DPRINT1("ZwSetValueKey() failed (Status 0x%08lx)\n", Status);
518 return Status;
519 }
520
521 return STATUS_SUCCESS;
522}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define C_ASSERT(e)
Definition: intsafe.h:73
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:86
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ PNDIS_STRING _Out_ PNDIS_HANDLE SubKeyHandle
Definition: ndis.h:4726
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define REG_BINARY
Definition: nt_native.h:1496
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define KEY_WRITE
Definition: nt_native.h:1031
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
UINT32 OemRevision
Definition: actbl.h:114
char OemTableId[ACPI_OEM_TABLE_ID_SIZE]
Definition: actbl.h:113
char OemId[ACPI_OEM_ID_SIZE]
Definition: actbl.h:112
UINT32 Length
Definition: actbl.h:109
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by acpi_create_volatile_registry_tables().

◆ acpi_create_volatile_registry_tables()

NTSTATUS acpi_create_volatile_registry_tables ( void  )

Definition at line 525 of file utils.c.

526{
528 UNICODE_STRING HardwareKeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE\\ACPI");
531 ACPI_STATUS AcpiStatus;
532 ACPI_TABLE_HEADER *OutTable;
533 ACPI_PHYSICAL_ADDRESS RsdpAddress;
534 ACPI_TABLE_RSDP *Rsdp;
535 ACPI_PHYSICAL_ADDRESS Address;
536 UINT32 TableEntrySize;
537
538 /* Create Main Hardware ACPI key*/
540 &HardwareKeyName,
542 NULL,
543 NULL);
544 Status = ZwCreateKey(&KeyHandle,
545 KEY_WRITE,
547 0,
548 NULL,
550 NULL);
551 if (!NT_SUCCESS(Status))
552 {
553 DPRINT1("ZwCreateKey() for ACPI failed (Status 0x%08lx)\n", Status);
554 return Status;
555 }
556 /* Read DSDT table */
557 AcpiStatus = AcpiGetTable(ACPI_SIG_DSDT, 0, &OutTable);
558 if (ACPI_FAILURE(AcpiStatus))
559 {
560 DPRINT1("AcpiGetTable() for DSDT failed (Status 0x%08lx)\n", AcpiStatus);
562 goto done;
563 }
564 /* Dump DSDT table */
565 Status = acpi_create_registry_table(KeyHandle, OutTable, L"DSDT");
566 if (!NT_SUCCESS(Status))
567 {
568 DPRINT1("acpi_dump_table_to_registry() for DSDT failed (Status 0x%08lx)\n", Status);
569 goto done;
570 }
571 /* Read FACS table */
572 AcpiStatus = AcpiGetTable(ACPI_SIG_FACS, 0, &OutTable);
573 if (ACPI_FAILURE(AcpiStatus))
574 {
575 DPRINT1("AcpiGetTable() for FACS failed (Status 0x%08lx)\n", AcpiStatus);
577 goto done;
578 }
579 /* Dump FACS table */
580 Status = acpi_create_registry_table(KeyHandle, OutTable, L"FACS");
581 if (!NT_SUCCESS(Status))
582 {
583 DPRINT1("acpi_dump_table_to_registry() for FACS failed (Status 0x%08lx)\n", Status);
584 goto done;
585 }
586 /* Read FACS table */
587 AcpiStatus = AcpiGetTable(ACPI_SIG_FADT, 0, &OutTable);
588 if (ACPI_FAILURE(AcpiStatus))
589 {
590 DPRINT1("AcpiGetTable() for FADT failed (Status 0x%08lx)\n", AcpiStatus);
592 goto done;
593 }
594 /* Dump FADT table */
595 Status = acpi_create_registry_table(KeyHandle, OutTable, L"FADT");
596 if (!NT_SUCCESS(Status))
597 {
598 DPRINT1("acpi_dump_table_to_registry() for FADT failed (Status 0x%08lx)\n", Status);
599 goto done;
600 }
601 /* This is a rough copy from ACPICA reading of RSDT/XSDT and added to avoid patching acpica */
602 RsdpAddress = AcpiOsGetRootPointer();
603 /* Map the entire RSDP and extract the address of the RSDT or XSDT */
604 Rsdp = AcpiOsMapMemory(RsdpAddress, sizeof(ACPI_TABLE_RSDP));
605 if (!Rsdp)
606 {
607 DPRINT1("AcpiOsMapMemory() failed\n");
609 goto done;
610 }
611 /* Use XSDT if present and not overridden. Otherwise, use RSDT */
612 if ((Rsdp->Revision > 1) &&
613 Rsdp->XsdtPhysicalAddress &&
614 !AcpiGbl_DoNotUseXsdt)
615 {
616 /*
617 * RSDP contains an XSDT (64-bit physical addresses). We must use
618 * the XSDT if the revision is > 1 and the XSDT pointer is present,
619 * as per the ACPI specification.
620 */
621 Address = (ACPI_PHYSICAL_ADDRESS)Rsdp->XsdtPhysicalAddress;
622 TableEntrySize = ACPI_XSDT_ENTRY_SIZE;
623 }
624 else
625 {
626 /* Root table is an RSDT (32-bit physical addresses) */
627 Address = (ACPI_PHYSICAL_ADDRESS)Rsdp->RsdtPhysicalAddress;
628 TableEntrySize = ACPI_RSDT_ENTRY_SIZE;
629 }
630 /*
631 * It is not possible to map more than one entry in some environments,
632 * so unmap the RSDP here before mapping other tables
633 */
634 AcpiOsUnmapMemory(Rsdp, sizeof(ACPI_TABLE_RSDP));
635 OutTable = AcpiOsMapMemory(Address, TableEntrySize);
636 if (!OutTable)
637 {
638 DPRINT1("AcpiOsMapMemory() failed\n");
640 goto done;
641 }
642 /* Dump RSDT table */
643 Status = acpi_create_registry_table(KeyHandle, OutTable, L"RSDT");
644 AcpiOsUnmapMemory(OutTable, TableEntrySize);
645 if (!NT_SUCCESS(Status))
646 {
647 DPRINT1("acpi_dump_table_to_registry() for RSDT failed (Status 0x%08lx)\n", Status);
648 }
649
650done:
652 return Status;
653}
unsigned int UINT32
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
void * AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS Where, ACPI_SIZE Length)
Definition: osl.c:108
ACPI_PHYSICAL_ADDRESS AcpiOsGetRootPointer(void)
Definition: osl.c:43
void AcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Size)
Definition: osl.c:128
#define ACPI_SIG_FADT
Definition: actbl.h:68
#define ACPI_SIG_DSDT
Definition: actbl.h:67
#define ACPI_RSDT_ENTRY_SIZE
Definition: actbl.h:208
#define ACPI_XSDT_ENTRY_SIZE
Definition: actbl.h:209
#define ACPI_SIG_FACS
Definition: actbl.h:69
UINT32 ACPI_STATUS
Definition: actypes.h:460
NTSTATUS acpi_create_registry_table(HANDLE ParentKeyHandle, ACPI_TABLE_HEADER *OutTable, PCWSTR KeyName)
Definition: utils.c:374
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
static WCHAR Address[46]
Definition: ping.c:68
UINT8 Revision
Definition: actbl.h:154
UINT64 XsdtPhysicalAddress
Definition: actbl.h:157
UINT32 RsdtPhysicalAddress
Definition: actbl.h:155
ACPI_STATUS AcpiGetTable(char *Signature, UINT32 Instance, ACPI_TABLE_HEADER **OutTable)
Definition: tbxface.c:366
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by Bus_StartFdo().

◆ acpi_evaluate_integer()

ACPI_STATUS acpi_evaluate_integer ( ACPI_HANDLE  handle,
ACPI_STRING  pathname,
ACPI_OBJECT_LIST arguments,
unsigned long long data 
)

Definition at line 242 of file utils.c.

247{
251
252 ACPI_FUNCTION_TRACE("acpi_evaluate_integer");
253
254 if (!data)
256
258 if (ACPI_FAILURE(status)) {
261 }
262
263 if (element.Type != ACPI_TYPE_INTEGER) {
266 }
267
268 *data = element.Integer.Value;
269
270 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Return value [%lu]\n", *data));
271
273}
#define AE_BAD_DATA
Definition: acexcep.h:154
#define AE_BAD_PARAMETER
Definition: acexcep.h:151
#define AE_OK
Definition: acexcep.h:97
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define ACPI_DB_INFO
Definition: acoutput.h:153
union acpi_object ACPI_OBJECT
#define ACPI_TYPE_INTEGER
Definition: actypes.h:688
static void acpi_util_eval_error(ACPI_HANDLE h, ACPI_STRING p, ACPI_STATUS s)
Definition: utils.c:40
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint buffer
Definition: glext.h:5915
char pathname[512]
Definition: util.h:13
ACPI_STATUS AcpiEvaluateObject(ACPI_HANDLE Handle, ACPI_STRING Pathname, ACPI_OBJECT_LIST *ExternalParams, ACPI_BUFFER *ReturnBuffer)
Definition: nsxfeval.c:217
Definition: ps.c:97

Referenced by acpi_bus_get_power(), acpi_bus_get_status_handle(), acpi_power_get_state(), and Bus_PDO_QueryResources().

◆ acpi_evaluate_reference()

ACPI_STATUS acpi_evaluate_reference ( ACPI_HANDLE  handle,
ACPI_STRING  pathname,
ACPI_OBJECT_LIST arguments,
struct acpi_handle_list list 
)

Definition at line 277 of file utils.c.

282{
284 ACPI_OBJECT *package = NULL;
287 UINT32 i = 0;
288
289 ACPI_FUNCTION_TRACE("acpi_evaluate_reference");
290
291 if (!list) {
293 }
294
295 /* Evaluate object. */
296
298 if (ACPI_FAILURE(status))
299 goto end;
300
301 package = (ACPI_OBJECT *) buffer.Pointer;
302
303 if ((buffer.Length == 0) || !package) {
304 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
305 "No return object (len %X ptr %p)\n",
306 buffer.Length, package));
309 goto end;
310 }
311 if (package->Type != ACPI_TYPE_PACKAGE) {
312 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
313 "Expecting a [Package], found type %X\n",
314 package->Type));
317 goto end;
318 }
319 if (!package->Package.Count) {
320 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
321 "[Package] has zero elements (%p)\n",
322 package));
325 goto end;
326 }
327
328 if (package->Package.Count > ACPI_MAX_HANDLES) {
329 return AE_NO_MEMORY;
330 }
331 list->count = package->Package.Count;
332
333 /* Extract package data. */
334
335 for (i = 0; i < list->count; i++) {
336
337 element = &(package->Package.Elements[i]);
338
339 if (element->Type != ACPI_TYPE_LOCAL_REFERENCE) {
341 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
342 "Expecting a [Reference] package element, found type %X\n",
343 element->type));
345 break;
346 }
347
348 if (!element->Reference.Handle) {
349 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid reference in"
350 " package %s\n", pathname));
352 break;
353 }
354 /* Get the ACPI_HANDLE. */
355
356 list->handles[i] = element->Reference.Handle;
357 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found reference [%p]\n",
358 list->handles[i]));
359 }
360
361end:
362 if (ACPI_FAILURE(status)) {
363 list->count = 0;
364 //ExFreePool(list->handles);
365 }
366
367 if (buffer.Pointer)
368 AcpiOsFree(buffer.Pointer);
369
371}
#define AE_NULL_ENTRY
Definition: acexcep.h:118
#define AE_NO_MEMORY
Definition: acexcep.h:112
#define ACPI_MAX_HANDLES
Definition: acpi_bus.h:35
void AcpiOsFree(void *Memory)
Definition: osl.c:167
#define ACPI_TYPE_LOCAL_REFERENCE
Definition: actypes.h:719
#define ACPI_ALLOCATE_BUFFER
Definition: actypes.h:1046
#define ACPI_TYPE_PACKAGE
Definition: actypes.h:691
Definition: list.h:37
GLuint GLuint end
Definition: gl.h:1545
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

Referenced by acpi_bus_get_power_flags().

◆ acpi_extract_package()

ACPI_STATUS acpi_extract_package ( ACPI_OBJECT package,
ACPI_BUFFER format,
ACPI_BUFFER buffer 
)

Definition at line 60 of file utils.c.

64{
65 UINT32 size_required = 0;
66 UINT32 tail_offset = 0;
67 char *format_string = NULL;
68 UINT32 format_count = 0;
69 UINT32 i = 0;
70 UINT8 *head = NULL;
71 UINT8 *tail = NULL;
72
73 if (!package || (package->Type != ACPI_TYPE_PACKAGE) || (package->Package.Count < 1)) {
74 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid 'package' argument\n"));
76 }
77
78 if (!format || !format->Pointer || (format->Length < 1)) {
79 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid 'format' argument\n"));
81 }
82
83 if (!buffer) {
84 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid 'buffer' argument\n"));
86 }
87
88 format_count = (format->Length/sizeof(char)) - 1;
89 if (format_count > package->Package.Count) {
90 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Format specifies more objects [%d] than exist in package [%d].", format_count, package->package.count));
92 }
93
94 format_string = format->Pointer;
95
96 /*
97 * Calculate size_required.
98 */
99 for (i=0; i<format_count; i++) {
100
101 ACPI_OBJECT *element = &(package->Package.Elements[i]);
102
103 if (!element) {
105 }
106
107 switch (element->Type) {
108
110 switch (format_string[i]) {
111 case 'N':
112 size_required += sizeof(ACPI_INTEGER);
113 tail_offset += sizeof(ACPI_INTEGER);
114 break;
115 case 'S':
116 size_required += sizeof(char*) + sizeof(ACPI_INTEGER) + sizeof(char);
117 tail_offset += sizeof(char*);
118 break;
119 default:
120 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid package element [%d]: got number, expecting [%c].\n", i, format_string[i]));
122 break;
123 }
124 break;
125
126 case ACPI_TYPE_STRING:
127 case ACPI_TYPE_BUFFER:
128 switch (format_string[i]) {
129 case 'S':
130 size_required += sizeof(char*) + (element->String.Length * sizeof(char)) + sizeof(char);
131 tail_offset += sizeof(char*);
132 break;
133 case 'B':
134 size_required += sizeof(UINT8*) + (element->Buffer.Length * sizeof(UINT8));
135 tail_offset += sizeof(UINT8*);
136 break;
137 default:
138 ACPI_DEBUG_PRINT((ACPI_DB_WARN, "Invalid package element [%d] got string/buffer, expecting [%c].\n", i, format_string[i]));
140 break;
141 }
142 break;
143
145 default:
146 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unsupported element at index=%d\n", i));
147 /* TBD: handle nested packages... */
149 break;
150 }
151 }
152
153 /*
154 * Validate output buffer.
155 */
156 if (buffer->Length < size_required) {
157 buffer->Length = size_required;
159 }
160 else if (buffer->Length != size_required || !buffer->Pointer) {
162 }
163
164 head = buffer->Pointer;
165 tail = ((PUCHAR)buffer->Pointer) + tail_offset;
166
167 /*
168 * Extract package data.
169 */
170 for (i=0; i<format_count; i++) {
171
172 UINT8 **pointer = NULL;
173 ACPI_OBJECT *element = &(package->Package.Elements[i]);
174
175 if (!element) {
177 }
178
179 switch (element->Type) {
180
182 switch (format_string[i]) {
183 case 'N':
184 *((ACPI_INTEGER*)head) = element->Integer.Value;
185 head += sizeof(ACPI_INTEGER);
186 break;
187 case 'S':
188 pointer = (UINT8**)head;
189 *pointer = tail;
190 *((ACPI_INTEGER*)tail) = element->Integer.Value;
191 head += sizeof(ACPI_INTEGER*);
192 tail += sizeof(ACPI_INTEGER);
193 /* NULL terminate string */
194 *tail = (char)0;
195 tail += sizeof(char);
196 break;
197 default:
198 /* Should never get here */
199 break;
200 }
201 break;
202
203 case ACPI_TYPE_STRING:
204 case ACPI_TYPE_BUFFER:
205 switch (format_string[i]) {
206 case 'S':
207 pointer = (UINT8**)head;
208 *pointer = tail;
209 memcpy(tail, element->String.Pointer, element->String.Length);
210 head += sizeof(char*);
211 tail += element->String.Length * sizeof(char);
212 /* NULL terminate string */
213 *tail = (char)0;
214 tail += sizeof(char);
215 break;
216 case 'B':
217 pointer = (UINT8**)head;
218 *pointer = tail;
219 memcpy(tail, element->Buffer.Pointer, element->Buffer.Length);
220 head += sizeof(UINT8*);
221 tail += element->Buffer.Length * sizeof(UINT8);
222 break;
223 default:
224 /* Should never get here */
225 break;
226 }
227 break;
228
230 /* TBD: handle nested packages... */
231 default:
232 /* Should never get here */
233 break;
234 }
235 }
236
238}
unsigned char UINT8
#define AE_SUPPORT
Definition: acexcep.h:123
#define AE_BUFFER_OVERFLOW
Definition: acexcep.h:119
UINT64 ACPI_INTEGER
Definition: actypes.h:514
#define ACPI_TYPE_STRING
Definition: actypes.h:689
#define ACPI_TYPE_BUFFER
Definition: actypes.h:690
struct outqueuenode * tail
Definition: adnsresfilter.c:66
struct outqueuenode * head
Definition: adnsresfilter.c:66
unsigned char
Definition: typeof.h:29
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLsizei const GLvoid * pointer
Definition: glext.h:5848
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
const char * format_string(const WAVEFORMATEX *wfx)
Definition: capture.c:84
unsigned char * PUCHAR
Definition: typedefs.h:53
ACPI_OBJECT_TYPE Type
Definition: actypes.h:970
struct acpi_object::@603 Package

◆ acpi_util_eval_error()

static void acpi_util_eval_error ( ACPI_HANDLE  h,
ACPI_STRING  p,
ACPI_STATUS  s 
)
static

Definition at line 40 of file utils.c.

41{
42#ifdef ACPI_DEBUG_OUTPUT
43 char prefix[80] = {'\0'};
44 ACPI_BUFFER buffer = {sizeof(prefix), prefix};
46 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluate [%s.%s]: %s\n",
47 (char *) prefix, p, AcpiFormatException(s)));
48#else
49 return;
50#endif
51}
#define ACPI_FULL_PATHNAME
Definition: actypes.h:1062
GLdouble s
Definition: gl.h:2039
GLfloat GLfloat p
Definition: glext.h:8902
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
ACPI_STATUS AcpiGetName(ACPI_HANDLE Handle, UINT32 NameType, ACPI_BUFFER *Buffer)
Definition: nsxfname.c:173
const char * AcpiFormatException(ACPI_STATUS Status)
Definition: utexcep.c:70

Referenced by acpi_evaluate_integer(), and acpi_evaluate_reference().