1 /******************************************************************************
3 * Module Name: aeexec - Support routines for AcpiExec utility
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
116 #include "aecommon.h"
118 #define _COMPONENT ACPI_TOOLS
119 ACPI_MODULE_NAME ("aeexec")
121 /* Local prototypes */
124 AeSetupConfiguration (
132 AeTestBufferArgument (
136 AeTestPackageArgument (
141 ACPI_HANDLE ObjHandle
,
149 UINT32 ExpectedResult
);
152 AeHardwareInterfaces (
159 extern unsigned char Ssdt3Code
[];
162 /******************************************************************************
164 * FUNCTION: AeSetupConfiguration
166 * PARAMETERS: RegionAddr - Address for an ACPI table to be loaded
167 * dynamically. Test purposes only.
171 * DESCRIPTION: Call AML _CFG configuration control method
173 *****************************************************************************/
176 AeSetupConfiguration (
180 ACPI_OBJECT_LIST ArgList
;
185 * Invoke _CFG method if present
188 ArgList
.Pointer
= Arg
;
190 Arg
[0].Type
= ACPI_TYPE_INTEGER
;
191 Arg
[0].Integer
.Value
= ACPI_TO_INTEGER (RegionAddr
);
193 Status
= AcpiEvaluateObject (NULL
, "\\_CFG", &ArgList
, NULL
);
199 /******************************************************************************
201 * FUNCTION: AfInstallGpeBlock
207 * DESCRIPTION: Various GPE initialization
209 *****************************************************************************/
217 ACPI_HANDLE Handle2
= NULL
;
218 ACPI_HANDLE Handle3
= NULL
;
219 ACPI_GENERIC_ADDRESS BlockAddress
;
220 ACPI_HANDLE GpeDevice
;
223 Status
= AcpiGetHandle (NULL
, "\\_GPE", &Handle
);
224 if (ACPI_FAILURE (Status
))
229 BlockAddress
.SpaceId
= 0;
230 BlockAddress
.Address
= 0x76540000;
233 Status
= AcpiInstallGpeBlock (Handle
, &BlockAddress
, 4, 8);
236 /* Above should fail, ignore */
238 Status
= AcpiGetHandle (NULL
, "\\GPE2", &Handle2
);
239 if (ACPI_SUCCESS (Status
))
241 Status
= AcpiInstallGpeBlock (Handle2
, &BlockAddress
, 8, 8);
243 AcpiInstallGpeHandler (Handle2
, 8, ACPI_GPE_LEVEL_TRIGGERED
, AeGpeHandler
, NULL
);
244 AcpiSetGpeType (Handle2
, 8, ACPI_GPE_TYPE_WAKE
);
245 AcpiEnableGpe (Handle2
, 8, 0);
247 Status
= AcpiGetGpeDevice (0x30, &GpeDevice
);
248 Status
= AcpiGetGpeDevice (0x42, &GpeDevice
);
249 Status
= AcpiGetGpeDevice (AcpiCurrentGpeCount
-1, &GpeDevice
);
250 Status
= AcpiGetGpeDevice (AcpiCurrentGpeCount
, &GpeDevice
);
252 AcpiRemoveGpeHandler (Handle2
, 8, AeGpeHandler
);
254 Status
= AcpiRemoveGpeBlock (Handle2
);
257 Status
= AcpiGetHandle (NULL
, "\\GPE3", &Handle3
);
258 if (ACPI_SUCCESS (Status
))
260 Status
= AcpiInstallGpeBlock (Handle3
, &BlockAddress
, 8, 11);
264 Status
= AcpiRemoveGpeBlock (Handle
);
265 Status
= AcpiRemoveGpeBlock (Handle2
);
266 Status
= AcpiRemoveGpeBlock (Handle3
);
271 /* Test using a Buffer object as a method argument */
274 AeTestBufferArgument (
278 ACPI_OBJECT_LIST Params
;
286 BufArg
.Type
= ACPI_TYPE_BUFFER
;
287 BufArg
.Buffer
.Length
= 12;
288 BufArg
.Buffer
.Pointer
= Buffer
;
291 Params
.Pointer
= &BufArg
;
294 Status
= AcpiEvaluateObject (NULL
, "\\BUF", &Params
, NULL
);
299 ACPI_OBJECT PkgElements
[5];
300 ACPI_OBJECT Pkg2Elements
[5];
301 ACPI_OBJECT_LIST Params
;
305 * Test using a Package object as an method argument
308 AeTestPackageArgument (
316 PkgArg
.Type
= ACPI_TYPE_PACKAGE
;
317 PkgArg
.Package
.Count
= 4;
318 PkgArg
.Package
.Elements
= PkgElements
;
320 /* Main package elements */
322 PkgElements
[0].Type
= ACPI_TYPE_INTEGER
;
323 PkgElements
[0].Integer
.Value
= 0x22228888;
325 PkgElements
[1].Type
= ACPI_TYPE_STRING
;
326 PkgElements
[1].String
.Length
= sizeof ("Top-level package");
327 PkgElements
[1].String
.Pointer
= "Top-level package";
329 PkgElements
[2].Type
= ACPI_TYPE_BUFFER
;
330 PkgElements
[2].Buffer
.Length
= sizeof ("XXXX");
331 PkgElements
[2].Buffer
.Pointer
= (UINT8
*) "XXXX";
333 PkgElements
[3].Type
= ACPI_TYPE_PACKAGE
;
334 PkgElements
[3].Package
.Count
= 2;
335 PkgElements
[3].Package
.Elements
= Pkg2Elements
;
337 /* Sub-package elements */
339 Pkg2Elements
[0].Type
= ACPI_TYPE_INTEGER
;
340 Pkg2Elements
[0].Integer
.Value
= 0xAAAABBBB;
342 Pkg2Elements
[1].Type
= ACPI_TYPE_STRING
;
343 Pkg2Elements
[1].String
.Length
= sizeof ("Nested Package");
344 Pkg2Elements
[1].String
.Pointer
= "Nested Package";
346 /* Parameter object */
349 Params
.Pointer
= &PkgArg
;
351 Status
= AcpiEvaluateObject (NULL
, "\\_PKG", &Params
, NULL
);
357 ACPI_HANDLE ObjHandle
,
367 /******************************************************************************
369 * FUNCTION: ExecuteOSI
371 * PARAMETERS: OsiString - String passed to _OSI method
372 * ExpectedResult - 0 (FALSE) or 0xFFFFFFFF (TRUE)
376 * DESCRIPTION: Execute the internally implemented (in ACPICA) _OSI method.
378 *****************************************************************************/
383 UINT32 ExpectedResult
)
386 ACPI_OBJECT_LIST ArgList
;
388 ACPI_BUFFER ReturnValue
;
392 /* Setup input argument */
395 ArgList
.Pointer
= Arg
;
397 Arg
[0].Type
= ACPI_TYPE_STRING
;
398 Arg
[0].String
.Pointer
= OsiString
;
399 Arg
[0].String
.Length
= strlen (Arg
[0].String
.Pointer
);
401 /* Ask ACPICA to allocate space for the return object */
403 ReturnValue
.Length
= ACPI_ALLOCATE_BUFFER
;
405 Status
= AcpiEvaluateObject (NULL
, "\\_OSI", &ArgList
, &ReturnValue
);
407 if (ACPI_FAILURE (Status
))
409 AcpiOsPrintf ("Could not execute _OSI method, %s\n",
410 AcpiFormatException (Status
));
414 if (ReturnValue
.Length
< sizeof (ACPI_OBJECT
))
416 AcpiOsPrintf ("Return value from _OSI method too small, %.8X\n",
421 Obj
= ReturnValue
.Pointer
;
422 if (Obj
->Type
!= ACPI_TYPE_INTEGER
)
424 AcpiOsPrintf ("Invalid return type from _OSI method, %.2X\n", Obj
->Type
);
428 if (Obj
->Integer
.Value
!= ExpectedResult
)
430 AcpiOsPrintf ("Invalid return value from _OSI, expected %.8X found %.8X\n",
431 ExpectedResult
, (UINT32
) Obj
->Integer
.Value
);
435 /* Reset the OSI data */
442 /******************************************************************************
444 * FUNCTION: AeGenericRegisters
446 * DESCRIPTION: Call the AcpiRead/Write interfaces.
448 *****************************************************************************/
450 ACPI_GENERIC_ADDRESS GenericRegister
;
460 GenericRegister
.Address
= 0x1234;
461 GenericRegister
.BitWidth
= 64;
462 GenericRegister
.BitOffset
= 0;
463 GenericRegister
.SpaceId
= ACPI_ADR_SPACE_SYSTEM_IO
;
465 Status
= AcpiRead (&Value
, &GenericRegister
);
466 Status
= AcpiWrite (Value
, &GenericRegister
);
468 GenericRegister
.Address
= 0x12345678;
469 GenericRegister
.BitOffset
= 0;
470 GenericRegister
.SpaceId
= ACPI_ADR_SPACE_SYSTEM_MEMORY
;
472 Status
= AcpiRead (&Value
, &GenericRegister
);
473 Status
= AcpiWrite (Value
, &GenericRegister
);
477 /******************************************************************************
479 * FUNCTION: AeHardwareInterfaces
481 * DESCRIPTION: Call various hardware support interfaces
483 *****************************************************************************/
486 AeHardwareInterfaces (
494 Status
= AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS
, 1);
495 Status
= AcpiWriteBitRegister (ACPI_BITREG_GLOBAL_LOCK_ENABLE
, 1);
496 Status
= AcpiWriteBitRegister (ACPI_BITREG_SLEEP_ENABLE
, 1);
497 Status
= AcpiWriteBitRegister (ACPI_BITREG_ARB_DISABLE
, 1);
499 Status
= AcpiReadBitRegister (ACPI_BITREG_WAKE_STATUS
, &Value
);
500 Status
= AcpiReadBitRegister (ACPI_BITREG_GLOBAL_LOCK_ENABLE
, &Value
);
501 Status
= AcpiReadBitRegister (ACPI_BITREG_SLEEP_ENABLE
, &Value
);
502 Status
= AcpiReadBitRegister (ACPI_BITREG_ARB_DISABLE
, &Value
);
506 /******************************************************************************
508 * FUNCTION: AeMiscellaneousTests
510 * DESCRIPTION: Various ACPICA validation tests.
512 *****************************************************************************/
515 AeMiscellaneousTests (
519 ACPI_BUFFER ReturnBuf
;
521 ACPI_VENDOR_UUID Uuid
= {0, {ACPI_INIT_UUID (0,0,0,0,0,0,0,0,0,0,0)}};
525 ACPI_STATISTICS Stats
;
528 AeHardwareInterfaces ();
529 AeGenericRegisters ();
530 AeSetupConfiguration (Ssdt3Code
);
532 AeTestBufferArgument();
533 AeTestPackageArgument ();
534 ExecuteOSI ("Windows 2001", 0xFFFFFFFF);
535 ExecuteOSI ("MichiganTerminalSystem", 0);
538 ReturnBuf
.Length
= 32;
539 ReturnBuf
.Pointer
= Buffer
;
541 AcpiGetName (AcpiGbl_RootNode
, ACPI_FULL_PATHNAME
, &ReturnBuf
);
542 AcpiEnableEvent (ACPI_EVENT_GLOBAL
, 0);
544 AcpiInstallGpeHandler (NULL
, 0, ACPI_GPE_LEVEL_TRIGGERED
, AeGpeHandler
, NULL
);
545 AcpiSetGpeType (NULL
, 0, ACPI_GPE_TYPE_WAKE_RUN
);
546 AcpiEnableGpe (NULL
, 0, ACPI_NOT_ISR
);
547 AcpiRemoveGpeHandler (NULL
, 0, AeGpeHandler
);
549 AcpiInstallGpeHandler (NULL
, 0, ACPI_GPE_LEVEL_TRIGGERED
, AeGpeHandler
, NULL
);
550 AcpiSetGpeType (NULL
, 0, ACPI_GPE_TYPE_WAKE_RUN
);
551 AcpiEnableGpe (NULL
, 0, ACPI_NOT_ISR
);
553 AcpiInstallGpeHandler (NULL
, 1, ACPI_GPE_EDGE_TRIGGERED
, AeGpeHandler
, NULL
);
554 AcpiSetGpeType (NULL
, 1, ACPI_GPE_TYPE_RUNTIME
);
555 AcpiEnableGpe (NULL
, 1, ACPI_NOT_ISR
);
557 AcpiInstallGpeHandler (NULL
, 2, ACPI_GPE_LEVEL_TRIGGERED
, AeGpeHandler
, NULL
);
558 AcpiSetGpeType (NULL
, 2, ACPI_GPE_TYPE_WAKE
);
559 AcpiEnableGpe (NULL
, 2, ACPI_NOT_ISR
);
561 AcpiInstallGpeHandler (NULL
, 3, ACPI_GPE_EDGE_TRIGGERED
, AeGpeHandler
, NULL
);
562 AcpiSetGpeType (NULL
, 3, ACPI_GPE_TYPE_WAKE_RUN
);
564 AcpiInstallGpeHandler (NULL
, 4, ACPI_GPE_LEVEL_TRIGGERED
, AeGpeHandler
, NULL
);
565 AcpiSetGpeType (NULL
, 4, ACPI_GPE_TYPE_RUNTIME
);
567 AcpiInstallGpeHandler (NULL
, 5, ACPI_GPE_EDGE_TRIGGERED
, AeGpeHandler
, NULL
);
568 AcpiSetGpeType (NULL
, 5, ACPI_GPE_TYPE_WAKE
);
570 AcpiInstallGpeHandler (NULL
, 0x19, ACPI_GPE_LEVEL_TRIGGERED
, AeGpeHandler
, NULL
);
571 AcpiSetGpeType (NULL
, 0x19, ACPI_GPE_TYPE_WAKE_RUN
);
572 AcpiEnableGpe (NULL
, 0x19, ACPI_NOT_ISR
);
574 AfInstallGpeBlock ();
577 Status
= AcpiGetHandle (NULL
, "RSRC", &Handle
);
578 if (ACPI_SUCCESS (Status
))
580 ReturnBuf
.Length
= ACPI_ALLOCATE_BUFFER
;
582 Status
= AcpiGetVendorResource (Handle
, "_CRS", &Uuid
, &ReturnBuf
);
583 if (ACPI_SUCCESS (Status
))
585 AcpiOsFree (ReturnBuf
.Pointer
);
589 /* Test global lock */
591 Status
= AcpiAcquireGlobalLock (0xFFFF, &LockHandle1
);
592 if (ACPI_FAILURE (Status
))
594 AcpiOsPrintf ("Could not get GlobalLock, %X\n", Status
);
597 Status
= AcpiAcquireGlobalLock (0x5, &LockHandle2
);
598 if (ACPI_FAILURE (Status
))
600 AcpiOsPrintf ("Could not get GlobalLock, %X\n", Status
);
603 Status
= AcpiReleaseGlobalLock (LockHandle1
);
604 if (ACPI_FAILURE (Status
))
606 AcpiOsPrintf ("Could not release GlobalLock, %X\n", Status
);
609 Status
= AcpiReleaseGlobalLock (LockHandle2
);
610 if (ACPI_FAILURE (Status
))
612 AcpiOsPrintf ("Could not release GlobalLock, %X\n", Status
);
617 Status
= AcpiGetDevices (NULL
, AeGetDevices
, NULL
, NULL
);
618 if (ACPI_FAILURE (Status
))
620 AcpiOsPrintf ("Could not AcpiGetDevices, %X\n", Status
);
623 Status
= AcpiGetStatistics (&Stats
);
624 if (ACPI_FAILURE (Status
))
626 AcpiOsPrintf ("Could not AcpiGetStatistics, %X\n", Status
);