1 /******************************************************************************
2  *
3  * Module Name: aeexec - Support routines for AcpiExec utility
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2014, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43 
44 #include "aecommon.h"
45 
46 #define _COMPONENT          ACPI_TOOLS
47         ACPI_MODULE_NAME    ("aeexec")
48 
49 /* Local prototypes */
50 
51 static ACPI_STATUS
52 AeSetupConfiguration (
53     void                    *RegionAddr);
54 
55 static void
56 AeTestBufferArgument (
57     void);
58 
59 static void
60 AeTestPackageArgument (
61     void);
62 
63 static ACPI_STATUS
64 AeGetDevices (
65     ACPI_HANDLE             ObjHandle,
66     UINT32                  NestingLevel,
67     void                    *Context,
68     void                    **ReturnValue);
69 
70 static ACPI_STATUS
71 ExecuteOSI (
72     char                    *OsiString,
73     UINT32                  ExpectedResult);
74 
75 static void
76 AeMutexInterfaces (
77     void);
78 
79 static void
80 AeHardwareInterfaces (
81     void);
82 
83 static void
84 AeGenericRegisters (
85     void);
86 
87 #if (!ACPI_REDUCED_HARDWARE)
88 static void
89 AfInstallGpeBlock (
90     void);
91 #endif /* !ACPI_REDUCED_HARDWARE */
92 
93 extern unsigned char Ssdt2Code[];
94 extern unsigned char Ssdt3Code[];
95 extern unsigned char Ssdt4Code[];
96 
97 
98 /******************************************************************************
99  *
100  * FUNCTION:    AeSetupConfiguration
101  *
102  * PARAMETERS:  RegionAddr          - Address for an ACPI table to be loaded
103  *                                    dynamically. Test purposes only.
104  *
105  * RETURN:      Status
106  *
107  * DESCRIPTION: Call AML _CFG configuration control method
108  *
109  *****************************************************************************/
110 
111 static ACPI_STATUS
112 AeSetupConfiguration (
113     void                    *RegionAddr)
114 {
115     ACPI_OBJECT_LIST        ArgList;
116     ACPI_OBJECT             Arg[3];
117 
118 
119     /*
120      * Invoke _CFG method if present
121      */
122     ArgList.Count = 1;
123     ArgList.Pointer = Arg;
124 
125     Arg[0].Type = ACPI_TYPE_INTEGER;
126     Arg[0].Integer.Value = ACPI_TO_INTEGER (RegionAddr);
127 
128     (void) AcpiEvaluateObject (NULL, "\\_CFG", &ArgList, NULL);
129     return (AE_OK);
130 }
131 
132 
133 #if (!ACPI_REDUCED_HARDWARE)
134 /******************************************************************************
135  *
136  * FUNCTION:    AfInstallGpeBlock
137  *
138  * PARAMETERS:  None
139  *
140  * RETURN:      None
141  *
142  * DESCRIPTION: Test GPE block device initialization. Requires test ASL with
143  *              A \GPE2 device.
144  *
145  *****************************************************************************/
146 
147 static void
148 AfInstallGpeBlock (
149     void)
150 {
151     ACPI_STATUS                 Status;
152     ACPI_HANDLE                 Handle;
153     ACPI_GENERIC_ADDRESS        BlockAddress;
154     ACPI_HANDLE                 GpeDevice;
155     ACPI_OBJECT_TYPE            Type;
156 
157 
158     /* _GPE should always exist */
159 
160     Status = AcpiGetHandle (NULL, "\\_GPE", &Handle);
161     AE_CHECK_OK (AcpiGetHandle, Status);
162     if (ACPI_FAILURE (Status))
163     {
164         return;
165     }
166 
167     ACPI_MEMSET (&BlockAddress, 0, sizeof (ACPI_GENERIC_ADDRESS));
168     BlockAddress.SpaceId = ACPI_ADR_SPACE_SYSTEM_MEMORY;
169     BlockAddress.Address = 0x76540000;
170 
171     /* Attempt to install a GPE block on GPE2 (if present) */
172 
173     Status = AcpiGetHandle (NULL, "\\GPE2", &Handle);
174     if (ACPI_SUCCESS (Status))
175     {
176         Status = AcpiGetType (Handle, &Type);
177         if (ACPI_FAILURE (Status) ||
178            (Type != ACPI_TYPE_DEVICE))
179         {
180             return;
181         }
182 
183         Status = AcpiInstallGpeBlock (Handle, &BlockAddress, 7, 8);
184         AE_CHECK_OK (AcpiInstallGpeBlock, Status);
185 
186         Status = AcpiInstallGpeHandler (Handle, 8,
187             ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
188         AE_CHECK_OK (AcpiInstallGpeHandler, Status);
189 
190         Status = AcpiEnableGpe (Handle, 8);
191         AE_CHECK_OK (AcpiEnableGpe, Status);
192 
193         Status = AcpiGetGpeDevice (0x30, &GpeDevice);
194         AE_CHECK_OK (AcpiGetGpeDevice, Status);
195 
196         Status = AcpiGetGpeDevice (0x42, &GpeDevice);
197         AE_CHECK_OK (AcpiGetGpeDevice, Status);
198 
199         Status = AcpiGetGpeDevice (AcpiCurrentGpeCount-1, &GpeDevice);
200         AE_CHECK_OK (AcpiGetGpeDevice, Status);
201 
202         Status = AcpiGetGpeDevice (AcpiCurrentGpeCount, &GpeDevice);
203         AE_CHECK_STATUS (AcpiGetGpeDevice, Status, AE_NOT_EXIST);
204 
205         Status = AcpiRemoveGpeHandler (Handle, 8, AeGpeHandler);
206         AE_CHECK_OK (AcpiRemoveGpeHandler, Status);
207     }
208 
209     /* Attempt to install a GPE block on GPE3 (if present) */
210 
211     Status = AcpiGetHandle (NULL, "\\GPE3", &Handle);
212     if (ACPI_SUCCESS (Status))
213     {
214         Status = AcpiGetType (Handle, &Type);
215         if (ACPI_FAILURE (Status) ||
216            (Type != ACPI_TYPE_DEVICE))
217         {
218             return;
219         }
220 
221         Status = AcpiInstallGpeBlock (Handle, &BlockAddress, 8, 11);
222         AE_CHECK_OK (AcpiInstallGpeBlock, Status);
223     }
224 }
225 #endif /* !ACPI_REDUCED_HARDWARE */
226 
227 
228 /* Test using a Buffer object as a method argument */
229 
230 static void
231 AeTestBufferArgument (
232     void)
233 {
234     ACPI_OBJECT_LIST        Params;
235     ACPI_OBJECT             BufArg;
236     UINT8                   Buffer[] = {
237         0,0,0,0,
238         4,0,0,0,
239         1,2,3,4};
240 
241 
242     BufArg.Type = ACPI_TYPE_BUFFER;
243     BufArg.Buffer.Length = 12;
244     BufArg.Buffer.Pointer = Buffer;
245 
246     Params.Count = 1;
247     Params.Pointer = &BufArg;
248 
249     (void) AcpiEvaluateObject (NULL, "\\BUF", &Params, NULL);
250 }
251 
252 
253 static ACPI_OBJECT                 PkgArg;
254 static ACPI_OBJECT                 PkgElements[5];
255 static ACPI_OBJECT                 Pkg2Elements[5];
256 static ACPI_OBJECT_LIST            Params;
257 
258 
259 /*
260  * Test using a Package object as an method argument
261  */
262 static void
263 AeTestPackageArgument (
264     void)
265 {
266 
267     /* Main package */
268 
269     PkgArg.Type = ACPI_TYPE_PACKAGE;
270     PkgArg.Package.Count = 4;
271     PkgArg.Package.Elements = PkgElements;
272 
273     /* Main package elements */
274 
275     PkgElements[0].Type = ACPI_TYPE_INTEGER;
276     PkgElements[0].Integer.Value = 0x22228888;
277 
278     PkgElements[1].Type = ACPI_TYPE_STRING;
279     PkgElements[1].String.Length = sizeof ("Top-level package");
280     PkgElements[1].String.Pointer = "Top-level package";
281 
282     PkgElements[2].Type = ACPI_TYPE_BUFFER;
283     PkgElements[2].Buffer.Length = sizeof ("XXXX");
284     PkgElements[2].Buffer.Pointer = (UINT8 *) "XXXX";
285 
286     PkgElements[3].Type = ACPI_TYPE_PACKAGE;
287     PkgElements[3].Package.Count = 2;
288     PkgElements[3].Package.Elements = Pkg2Elements;
289 
290     /* Subpackage elements */
291 
292     Pkg2Elements[0].Type = ACPI_TYPE_INTEGER;
293     Pkg2Elements[0].Integer.Value = 0xAAAABBBB;
294 
295     Pkg2Elements[1].Type = ACPI_TYPE_STRING;
296     Pkg2Elements[1].String.Length = sizeof ("Nested Package");
297     Pkg2Elements[1].String.Pointer = "Nested Package";
298 
299     /* Parameter object */
300 
301     Params.Count = 1;
302     Params.Pointer = &PkgArg;
303 
304     (void) AcpiEvaluateObject (NULL, "\\_PKG", &Params, NULL);
305 }
306 
307 
308 static ACPI_STATUS
309 AeGetDevices (
310     ACPI_HANDLE                     ObjHandle,
311     UINT32                          NestingLevel,
312     void                            *Context,
313     void                            **ReturnValue)
314 {
315 
316     return (AE_OK);
317 }
318 
319 
320 /******************************************************************************
321  *
322  * FUNCTION:    ExecuteOSI
323  *
324  * PARAMETERS:  OsiString           - String passed to _OSI method
325  *              ExpectedResult      - 0 (FALSE) or 0xFFFFFFFF (TRUE)
326  *
327  * RETURN:      Status
328  *
329  * DESCRIPTION: Execute the internally implemented (in ACPICA) _OSI method.
330  *
331  *****************************************************************************/
332 
333 static ACPI_STATUS
334 ExecuteOSI (
335     char                    *OsiString,
336     UINT32                  ExpectedResult)
337 {
338     ACPI_STATUS             Status;
339     ACPI_OBJECT_LIST        ArgList;
340     ACPI_OBJECT             Arg[1];
341     ACPI_BUFFER             ReturnValue;
342     ACPI_OBJECT             *Obj;
343 
344 
345     /* Setup input argument */
346 
347     ArgList.Count = 1;
348     ArgList.Pointer = Arg;
349 
350     Arg[0].Type = ACPI_TYPE_STRING;
351     Arg[0].String.Pointer = OsiString;
352     Arg[0].String.Length = strlen (Arg[0].String.Pointer);
353 
354     /* Ask ACPICA to allocate space for the return object */
355 
356     ReturnValue.Length = ACPI_ALLOCATE_BUFFER;
357 
358     Status = AcpiEvaluateObject (NULL, "\\_OSI", &ArgList, &ReturnValue);
359 
360     if (ACPI_FAILURE (Status))
361     {
362         AcpiOsPrintf ("Could not execute _OSI method, %s\n",
363             AcpiFormatException (Status));
364         return (Status);
365     }
366 
367     Status = AE_ERROR;
368 
369     if (ReturnValue.Length < sizeof (ACPI_OBJECT))
370     {
371         AcpiOsPrintf ("Return value from _OSI method too small, %.8X\n",
372             ReturnValue.Length);
373         goto ErrorExit;
374     }
375 
376     Obj = ReturnValue.Pointer;
377     if (Obj->Type != ACPI_TYPE_INTEGER)
378     {
379         AcpiOsPrintf ("Invalid return type from _OSI method, %.2X\n", Obj->Type);
380         goto ErrorExit;
381     }
382 
383     if (Obj->Integer.Value != ExpectedResult)
384     {
385         AcpiOsPrintf ("Invalid return value from _OSI, expected %.8X found %.8X\n",
386             ExpectedResult, (UINT32) Obj->Integer.Value);
387         goto ErrorExit;
388     }
389 
390     Status = AE_OK;
391 
392     /* Reset the OSI data */
393 
394     AcpiGbl_OsiData = 0;
395 
396 ErrorExit:
397 
398     /* Free a buffer created via ACPI_ALLOCATE_BUFFER */
399 
400     AcpiOsFree (ReturnValue.Pointer);
401 
402     return (Status);
403 }
404 
405 
406 /******************************************************************************
407  *
408  * FUNCTION:    AeGenericRegisters
409  *
410  * DESCRIPTION: Call the AcpiRead/Write interfaces.
411  *
412  *****************************************************************************/
413 
414 static ACPI_GENERIC_ADDRESS       GenericRegister;
415 
416 static void
417 AeGenericRegisters (
418     void)
419 {
420     ACPI_STATUS             Status;
421     UINT64                  Value;
422 
423 
424     GenericRegister.Address = 0x1234;
425     GenericRegister.BitWidth = 64;
426     GenericRegister.BitOffset = 0;
427     GenericRegister.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO;
428 
429     Status = AcpiRead (&Value, &GenericRegister);
430     AE_CHECK_OK (AcpiRead, Status);
431 
432     Status = AcpiWrite (Value, &GenericRegister);
433     AE_CHECK_OK (AcpiWrite, Status);
434 
435     GenericRegister.Address = 0x12345678;
436     GenericRegister.BitOffset = 0;
437     GenericRegister.SpaceId = ACPI_ADR_SPACE_SYSTEM_MEMORY;
438 
439     Status = AcpiRead (&Value, &GenericRegister);
440     AE_CHECK_OK (AcpiRead, Status);
441 
442     Status = AcpiWrite (Value, &GenericRegister);
443     AE_CHECK_OK (AcpiWrite, Status);
444 }
445 
446 
447 /******************************************************************************
448  *
449  * FUNCTION:    AeMutexInterfaces
450  *
451  * DESCRIPTION: Exercise the AML mutex access interfaces
452  *
453  *****************************************************************************/
454 
455 static void
456 AeMutexInterfaces (
457     void)
458 {
459     ACPI_STATUS             Status;
460     ACPI_HANDLE             MutexHandle;
461 
462 
463     /* Get a handle to an AML mutex */
464 
465     Status = AcpiGetHandle (NULL, "\\MTX1", &MutexHandle);
466     if (Status == AE_NOT_FOUND)
467     {
468         return;
469     }
470 
471     AE_CHECK_OK (AcpiGetHandle, Status);
472     if (ACPI_FAILURE (Status))
473     {
474         return;
475     }
476 
477     /* Acquire the  mutex */
478 
479     Status = AcpiAcquireMutex (NULL, "\\MTX1", 0xFFFF);
480     AE_CHECK_OK (AcpiAcquireMutex, Status);
481     if (ACPI_FAILURE (Status))
482     {
483         return;
484     }
485 
486     /* Release mutex with different parameters */
487 
488     Status = AcpiReleaseMutex (MutexHandle, NULL);
489     AE_CHECK_OK (AcpiReleaseMutex, Status);
490 }
491 
492 
493 /******************************************************************************
494  *
495  * FUNCTION:    AeHardwareInterfaces
496  *
497  * DESCRIPTION: Call various hardware support interfaces
498  *
499  *****************************************************************************/
500 
501 static void
502 AeHardwareInterfaces (
503     void)
504 {
505 #if (!ACPI_REDUCED_HARDWARE)
506 
507     ACPI_STATUS             Status;
508     UINT32                  Value;
509 
510 
511     /* If Hardware Reduced flag is set, we are all done */
512 
513     if (AcpiGbl_ReducedHardware)
514     {
515         return;
516     }
517 
518     Status = AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS, 1);
519     AE_CHECK_OK (AcpiWriteBitRegister, Status);
520 
521     Status = AcpiWriteBitRegister (ACPI_BITREG_GLOBAL_LOCK_ENABLE, 1);
522     AE_CHECK_OK (AcpiWriteBitRegister, Status);
523 
524     Status = AcpiWriteBitRegister (ACPI_BITREG_SLEEP_ENABLE, 1);
525     AE_CHECK_OK (AcpiWriteBitRegister, Status);
526 
527     Status = AcpiWriteBitRegister (ACPI_BITREG_ARB_DISABLE, 1);
528     AE_CHECK_OK (AcpiWriteBitRegister, Status);
529 
530 
531     Status = AcpiReadBitRegister (ACPI_BITREG_WAKE_STATUS, &Value);
532     AE_CHECK_OK (AcpiReadBitRegister, Status);
533 
534     Status = AcpiReadBitRegister (ACPI_BITREG_GLOBAL_LOCK_ENABLE, &Value);
535     AE_CHECK_OK (AcpiReadBitRegister, Status);
536 
537     Status = AcpiReadBitRegister (ACPI_BITREG_SLEEP_ENABLE, &Value);
538     AE_CHECK_OK (AcpiReadBitRegister, Status);
539 
540     Status = AcpiReadBitRegister (ACPI_BITREG_ARB_DISABLE, &Value);
541     AE_CHECK_OK (AcpiReadBitRegister, Status);
542 
543 #endif /* !ACPI_REDUCED_HARDWARE */
544 }
545 
546 
547 /******************************************************************************
548  *
549  * FUNCTION:    AeMiscellaneousTests
550  *
551  * DESCRIPTION: Various ACPICA validation tests.
552  *
553  *****************************************************************************/
554 
555 void
556 AeMiscellaneousTests (
557     void)
558 {
559     ACPI_BUFFER             ReturnBuf;
560     char                    Buffer[32];
561     ACPI_STATUS             Status;
562     ACPI_STATISTICS         Stats;
563     ACPI_HANDLE             Handle;
564 
565 #if (!ACPI_REDUCED_HARDWARE)
566     ACPI_VENDOR_UUID        Uuid = {0, {ACPI_INIT_UUID (0,0,0,0,0,0,0,0,0,0,0)}};
567     UINT32                  LockHandle1;
568     UINT32                  LockHandle2;
569 #endif /* !ACPI_REDUCED_HARDWARE */
570 
571 
572     Status = AcpiGetHandle (NULL, "\\", &Handle);
573     AE_CHECK_OK (AcpiGetHandle, Status);
574 
575     if (AcpiGbl_DoInterfaceTests)
576     {
577         /*
578          * Tests for AcpiLoadTable and AcpiUnloadParentTable
579          */
580 
581         /* Attempt unload of DSDT, should fail */
582 
583         Status = AcpiGetHandle (NULL, "\\_SB_", &Handle);
584         AE_CHECK_OK (AcpiGetHandle, Status);
585 
586         Status = AcpiUnloadParentTable (Handle);
587         AE_CHECK_STATUS (AcpiUnloadParentTable, Status, AE_TYPE);
588 
589         /* Load and unload SSDT4 */
590 
591         Status = AcpiLoadTable ((ACPI_TABLE_HEADER *) Ssdt4Code);
592         AE_CHECK_OK (AcpiLoadTable, Status);
593 
594         Status = AcpiGetHandle (NULL, "\\_T96", &Handle);
595         AE_CHECK_OK (AcpiGetHandle, Status);
596 
597         Status = AcpiUnloadParentTable (Handle);
598         AE_CHECK_OK (AcpiUnloadParentTable, Status);
599 
600         /* Re-load SSDT4 */
601 
602         Status = AcpiLoadTable ((ACPI_TABLE_HEADER *) Ssdt4Code);
603         AE_CHECK_OK (AcpiLoadTable, Status);
604 
605         /* Unload and re-load SSDT2 (SSDT2 is in the XSDT) */
606 
607         Status = AcpiGetHandle (NULL, "\\_T99", &Handle);
608         AE_CHECK_OK (AcpiGetHandle, Status);
609 
610         Status = AcpiUnloadParentTable (Handle);
611         AE_CHECK_OK (AcpiUnloadParentTable, Status);
612 
613         Status = AcpiLoadTable ((ACPI_TABLE_HEADER *) Ssdt2Code);
614         AE_CHECK_OK (AcpiLoadTable, Status);
615 
616         /* Load OEM9 table (causes table override) */
617 
618         Status = AcpiLoadTable ((ACPI_TABLE_HEADER *) Ssdt3Code);
619         AE_CHECK_OK (AcpiLoadTable, Status);
620     }
621 
622     AeHardwareInterfaces ();
623     AeGenericRegisters ();
624     AeSetupConfiguration (Ssdt3Code);
625 
626     AeTestBufferArgument();
627     AeTestPackageArgument ();
628     AeMutexInterfaces ();
629 
630     /* Test _OSI install/remove */
631 
632     Status = AcpiInstallInterface ("");
633     AE_CHECK_STATUS (AcpiInstallInterface, Status, AE_BAD_PARAMETER);
634 
635     Status = AcpiInstallInterface ("TestString");
636     AE_CHECK_OK (AcpiInstallInterface, Status);
637 
638     Status = AcpiInstallInterface ("TestString");
639     AE_CHECK_STATUS (AcpiInstallInterface, Status, AE_ALREADY_EXISTS);
640 
641     Status = AcpiRemoveInterface ("Windows 2006");
642     AE_CHECK_OK (AcpiRemoveInterface, Status);
643 
644     Status = AcpiRemoveInterface ("TestString");
645     AE_CHECK_OK (AcpiRemoveInterface, Status);
646 
647     Status = AcpiRemoveInterface ("XXXXXX");
648     AE_CHECK_STATUS (AcpiRemoveInterface, Status, AE_NOT_EXIST);
649 
650     Status = AcpiInstallInterface ("AnotherTestString");
651     AE_CHECK_OK (AcpiInstallInterface, Status);
652 
653     /* Test _OSI execution */
654 
655     Status = ExecuteOSI ("Extended Address Space Descriptor", 0xFFFFFFFF);
656     AE_CHECK_OK (ExecuteOSI, Status);
657 
658     Status = ExecuteOSI ("Windows 2001", 0xFFFFFFFF);
659     AE_CHECK_OK (ExecuteOSI, Status);
660 
661     Status = ExecuteOSI ("MichiganTerminalSystem", 0);
662     AE_CHECK_OK (ExecuteOSI, Status);
663 
664 
665     ReturnBuf.Length = 32;
666     ReturnBuf.Pointer = Buffer;
667 
668     Status = AcpiGetName (ACPI_ROOT_OBJECT, ACPI_FULL_PATHNAME, &ReturnBuf);
669     AE_CHECK_OK (AcpiGetName, Status);
670 
671     /* Get Devices */
672 
673     Status = AcpiGetDevices (NULL, AeGetDevices, NULL, NULL);
674     AE_CHECK_OK (AcpiGetDevices, Status);
675 
676     Status = AcpiGetStatistics (&Stats);
677     AE_CHECK_OK (AcpiGetStatistics, Status);
678 
679 
680 #if (!ACPI_REDUCED_HARDWARE)
681 
682     Status = AcpiInstallGlobalEventHandler (AeGlobalEventHandler, NULL);
683     AE_CHECK_OK (AcpiInstallGlobalEventHandler, Status);
684 
685     /* If Hardware Reduced flag is set, we are all done */
686 
687     if (AcpiGbl_ReducedHardware)
688     {
689         return;
690     }
691 
692     Status = AcpiEnableEvent (ACPI_EVENT_GLOBAL, 0);
693     AE_CHECK_OK (AcpiEnableEvent, Status);
694 
695     /*
696      * GPEs: Handlers, enable/disable, etc.
697      */
698     Status = AcpiInstallGpeHandler (NULL, 0, ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
699     AE_CHECK_OK (AcpiInstallGpeHandler, Status);
700 
701     Status = AcpiEnableGpe (NULL, 0);
702     AE_CHECK_OK (AcpiEnableGpe, Status);
703 
704     Status = AcpiRemoveGpeHandler (NULL, 0, AeGpeHandler);
705     AE_CHECK_OK (AcpiRemoveGpeHandler, Status);
706 
707     Status = AcpiInstallGpeHandler (NULL, 0, ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
708     AE_CHECK_OK (AcpiInstallGpeHandler, Status);
709 
710     Status = AcpiEnableGpe (NULL, 0);
711     AE_CHECK_OK (AcpiEnableGpe, Status);
712 
713     Status = AcpiSetGpe (NULL, 0, ACPI_GPE_DISABLE);
714     AE_CHECK_OK (AcpiSetGpe, Status);
715 
716     Status = AcpiSetGpe (NULL, 0, ACPI_GPE_ENABLE);
717     AE_CHECK_OK (AcpiSetGpe, Status);
718 
719 
720     Status = AcpiInstallGpeHandler (NULL, 1, ACPI_GPE_EDGE_TRIGGERED, AeGpeHandler, NULL);
721     AE_CHECK_OK (AcpiInstallGpeHandler, Status);
722 
723     Status = AcpiEnableGpe (NULL, 1);
724     AE_CHECK_OK (AcpiEnableGpe, Status);
725 
726 
727     Status = AcpiInstallGpeHandler (NULL, 2, ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
728     AE_CHECK_OK (AcpiInstallGpeHandler, Status);
729 
730     Status = AcpiEnableGpe (NULL, 2);
731     AE_CHECK_OK (AcpiEnableGpe, Status);
732 
733 
734     Status = AcpiInstallGpeHandler (NULL, 3, ACPI_GPE_EDGE_TRIGGERED, AeGpeHandler, NULL);
735     AE_CHECK_OK (AcpiInstallGpeHandler, Status);
736 
737     Status = AcpiInstallGpeHandler (NULL, 4, ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
738     AE_CHECK_OK (AcpiInstallGpeHandler, Status);
739 
740     Status = AcpiInstallGpeHandler (NULL, 5, ACPI_GPE_EDGE_TRIGGERED, AeGpeHandler, NULL);
741     AE_CHECK_OK (AcpiInstallGpeHandler, Status);
742 
743     Status = AcpiGetHandle (NULL, "\\_SB", &Handle);
744     AE_CHECK_OK (AcpiGetHandle, Status);
745 
746     Status = AcpiSetupGpeForWake (Handle, NULL, 5);
747     AE_CHECK_OK (AcpiSetupGpeForWake, Status);
748 
749     Status = AcpiSetGpeWakeMask (NULL, 5, ACPI_GPE_ENABLE);
750     AE_CHECK_OK (AcpiSetGpeWakeMask, Status);
751 
752     Status = AcpiSetupGpeForWake (Handle, NULL, 6);
753     AE_CHECK_OK (AcpiSetupGpeForWake, Status);
754 
755     Status = AcpiSetupGpeForWake (ACPI_ROOT_OBJECT, NULL, 6);
756     AE_CHECK_OK (AcpiSetupGpeForWake, Status);
757 
758     Status = AcpiSetupGpeForWake (Handle, NULL, 9);
759     AE_CHECK_OK (AcpiSetupGpeForWake, Status);
760 
761     Status = AcpiInstallGpeHandler (NULL, 0x19, ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
762     AE_CHECK_OK (AcpiInstallGpeHandler, Status);
763 
764     Status = AcpiEnableGpe (NULL, 0x19);
765     AE_CHECK_OK (AcpiEnableGpe, Status);
766 
767 
768     /* GPE block 1 */
769 
770     Status = AcpiInstallGpeHandler (NULL, 101, ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
771     AE_CHECK_OK (AcpiInstallGpeHandler, Status);
772 
773     Status = AcpiEnableGpe (NULL, 101);
774     AE_CHECK_OK (AcpiEnableGpe, Status);
775 
776     Status = AcpiDisableGpe (NULL, 101);
777     AE_CHECK_OK (AcpiDisableGpe, Status);
778 
779     AfInstallGpeBlock ();
780 
781     /* Here is where the GPEs are actually "enabled" */
782 
783     Status = AcpiUpdateAllGpes ();
784     AE_CHECK_OK (AcpiUpdateAllGpes, Status);
785 
786     Status = AcpiGetHandle (NULL, "RSRC", &Handle);
787     if (ACPI_SUCCESS (Status))
788     {
789         ReturnBuf.Length = ACPI_ALLOCATE_BUFFER;
790 
791         Status = AcpiGetVendorResource (Handle, "_CRS", &Uuid, &ReturnBuf);
792         if (ACPI_SUCCESS (Status))
793         {
794             AcpiOsFree (ReturnBuf.Pointer);
795         }
796     }
797 
798     /* Test global lock */
799 
800     Status = AcpiAcquireGlobalLock (0xFFFF, &LockHandle1);
801     AE_CHECK_OK (AcpiAcquireGlobalLock, Status);
802 
803     Status = AcpiAcquireGlobalLock (0x5, &LockHandle2);
804     AE_CHECK_OK (AcpiAcquireGlobalLock, Status);
805 
806     Status = AcpiReleaseGlobalLock (LockHandle1);
807     AE_CHECK_OK (AcpiReleaseGlobalLock, Status);
808 
809     Status = AcpiReleaseGlobalLock (LockHandle2);
810     AE_CHECK_OK (AcpiReleaseGlobalLock, Status);
811 
812 #endif /* !ACPI_REDUCED_HARDWARE */
813 }
814