Merge branch 'vendor/OPENSSL'
[dragonfly.git] / sys / contrib / dev / acpica / source / tools / acpiexec / aeexec.c
1 /******************************************************************************
2  *
3  * Module Name: aeexec - Support routines for AcpiExec utility
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2015, 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     ACPI_CHECK_OK (AcpiGetHandle, Status);
162     if (ACPI_FAILURE (Status))
163     {
164         return;
165     }
166
167     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         ACPI_CHECK_OK (AcpiInstallGpeBlock, Status);
185
186         Status = AcpiInstallGpeHandler (Handle, 8,
187             ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
188         ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
189
190         Status = AcpiEnableGpe (Handle, 8);
191         ACPI_CHECK_OK (AcpiEnableGpe, Status);
192
193         Status = AcpiGetGpeDevice (0x30, &GpeDevice);
194         ACPI_CHECK_OK (AcpiGetGpeDevice, Status);
195
196         Status = AcpiGetGpeDevice (0x42, &GpeDevice);
197         ACPI_CHECK_OK (AcpiGetGpeDevice, Status);
198
199         Status = AcpiGetGpeDevice (AcpiCurrentGpeCount-1, &GpeDevice);
200         ACPI_CHECK_OK (AcpiGetGpeDevice, Status);
201
202         Status = AcpiGetGpeDevice (AcpiCurrentGpeCount, &GpeDevice);
203         ACPI_CHECK_STATUS (AcpiGetGpeDevice, Status, AE_NOT_EXIST);
204
205         Status = AcpiRemoveGpeHandler (Handle, 8, AeGpeHandler);
206         ACPI_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         ACPI_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     {
238         0,0,0,0,
239         4,0,0,0,
240         1,2,3,4
241     };
242
243
244     BufArg.Type = ACPI_TYPE_BUFFER;
245     BufArg.Buffer.Length = 12;
246     BufArg.Buffer.Pointer = Buffer;
247
248     Params.Count = 1;
249     Params.Pointer = &BufArg;
250
251     (void) AcpiEvaluateObject (NULL, "\\BUF", &Params, NULL);
252 }
253
254
255 static ACPI_OBJECT                 PkgArg;
256 static ACPI_OBJECT                 PkgElements[5];
257 static ACPI_OBJECT                 Pkg2Elements[5];
258 static ACPI_OBJECT_LIST            Params;
259
260
261 /*
262  * Test using a Package object as an method argument
263  */
264 static void
265 AeTestPackageArgument (
266     void)
267 {
268
269     /* Main package */
270
271     PkgArg.Type = ACPI_TYPE_PACKAGE;
272     PkgArg.Package.Count = 4;
273     PkgArg.Package.Elements = PkgElements;
274
275     /* Main package elements */
276
277     PkgElements[0].Type = ACPI_TYPE_INTEGER;
278     PkgElements[0].Integer.Value = 0x22228888;
279
280     PkgElements[1].Type = ACPI_TYPE_STRING;
281     PkgElements[1].String.Length = sizeof ("Top-level package");
282     PkgElements[1].String.Pointer = "Top-level package";
283
284     PkgElements[2].Type = ACPI_TYPE_BUFFER;
285     PkgElements[2].Buffer.Length = sizeof ("XXXX");
286     PkgElements[2].Buffer.Pointer = (UINT8 *) "XXXX";
287
288     PkgElements[3].Type = ACPI_TYPE_PACKAGE;
289     PkgElements[3].Package.Count = 2;
290     PkgElements[3].Package.Elements = Pkg2Elements;
291
292     /* Subpackage elements */
293
294     Pkg2Elements[0].Type = ACPI_TYPE_INTEGER;
295     Pkg2Elements[0].Integer.Value = 0xAAAABBBB;
296
297     Pkg2Elements[1].Type = ACPI_TYPE_STRING;
298     Pkg2Elements[1].String.Length = sizeof ("Nested Package");
299     Pkg2Elements[1].String.Pointer = "Nested Package";
300
301     /* Parameter object */
302
303     Params.Count = 1;
304     Params.Pointer = &PkgArg;
305
306     (void) AcpiEvaluateObject (NULL, "\\_PKG", &Params, NULL);
307 }
308
309
310 static ACPI_STATUS
311 AeGetDevices (
312     ACPI_HANDLE                     ObjHandle,
313     UINT32                          NestingLevel,
314     void                            *Context,
315     void                            **ReturnValue)
316 {
317
318     return (AE_OK);
319 }
320
321
322 /******************************************************************************
323  *
324  * FUNCTION:    ExecuteOSI
325  *
326  * PARAMETERS:  OsiString           - String passed to _OSI method
327  *              ExpectedResult      - 0 (FALSE) or 0xFFFFFFFF (TRUE)
328  *
329  * RETURN:      Status
330  *
331  * DESCRIPTION: Execute the internally implemented (in ACPICA) _OSI method.
332  *
333  *****************************************************************************/
334
335 static ACPI_STATUS
336 ExecuteOSI (
337     char                    *OsiString,
338     UINT32                  ExpectedResult)
339 {
340     ACPI_STATUS             Status;
341     ACPI_OBJECT_LIST        ArgList;
342     ACPI_OBJECT             Arg[1];
343     ACPI_BUFFER             ReturnValue;
344     ACPI_OBJECT             *Obj;
345
346
347     /* Setup input argument */
348
349     ArgList.Count = 1;
350     ArgList.Pointer = Arg;
351
352     Arg[0].Type = ACPI_TYPE_STRING;
353     Arg[0].String.Pointer = OsiString;
354     Arg[0].String.Length = strlen (Arg[0].String.Pointer);
355
356     /* Ask ACPICA to allocate space for the return object */
357
358     ReturnValue.Length = ACPI_ALLOCATE_BUFFER;
359
360     Status = AcpiEvaluateObject (NULL, "\\_OSI", &ArgList, &ReturnValue);
361
362     if (ACPI_FAILURE (Status))
363     {
364         AcpiOsPrintf (
365             "Could not execute _OSI method, %s\n",
366             AcpiFormatException (Status));
367         return (Status);
368     }
369
370     Status = AE_ERROR;
371
372     if (ReturnValue.Length < sizeof (ACPI_OBJECT))
373     {
374         AcpiOsPrintf (
375             "Return value from _OSI method too small, %.8X\n",
376             ReturnValue.Length);
377         goto ErrorExit;
378     }
379
380     Obj = ReturnValue.Pointer;
381     if (Obj->Type != ACPI_TYPE_INTEGER)
382     {
383         AcpiOsPrintf (
384             "Invalid return type from _OSI method, %.2X\n", Obj->Type);
385         goto ErrorExit;
386     }
387
388     if (Obj->Integer.Value != ExpectedResult)
389     {
390         AcpiOsPrintf (
391             "Invalid return value from _OSI, expected %.8X found %.8X\n",
392             ExpectedResult, (UINT32) Obj->Integer.Value);
393         goto ErrorExit;
394     }
395
396     Status = AE_OK;
397
398     /* Reset the OSI data */
399
400     AcpiGbl_OsiData = 0;
401
402 ErrorExit:
403
404     /* Free a buffer created via ACPI_ALLOCATE_BUFFER */
405
406     AcpiOsFree (ReturnValue.Pointer);
407     return (Status);
408 }
409
410
411 /******************************************************************************
412  *
413  * FUNCTION:    AeGenericRegisters
414  *
415  * DESCRIPTION: Call the AcpiRead/Write interfaces.
416  *
417  *****************************************************************************/
418
419 static ACPI_GENERIC_ADDRESS       GenericRegister;
420
421 static void
422 AeGenericRegisters (
423     void)
424 {
425     ACPI_STATUS             Status;
426     UINT64                  Value;
427
428
429     GenericRegister.Address = 0x1234;
430     GenericRegister.BitWidth = 64;
431     GenericRegister.BitOffset = 0;
432     GenericRegister.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO;
433
434     Status = AcpiRead (&Value, &GenericRegister);
435     ACPI_CHECK_OK (AcpiRead, Status);
436
437     Status = AcpiWrite (Value, &GenericRegister);
438     ACPI_CHECK_OK (AcpiWrite, Status);
439
440     GenericRegister.Address = 0x12345678;
441     GenericRegister.BitOffset = 0;
442     GenericRegister.SpaceId = ACPI_ADR_SPACE_SYSTEM_MEMORY;
443
444     Status = AcpiRead (&Value, &GenericRegister);
445     ACPI_CHECK_OK (AcpiRead, Status);
446
447     Status = AcpiWrite (Value, &GenericRegister);
448     ACPI_CHECK_OK (AcpiWrite, Status);
449 }
450
451
452 /******************************************************************************
453  *
454  * FUNCTION:    AeMutexInterfaces
455  *
456  * DESCRIPTION: Exercise the AML mutex access interfaces
457  *
458  *****************************************************************************/
459
460 static void
461 AeMutexInterfaces (
462     void)
463 {
464     ACPI_STATUS             Status;
465     ACPI_HANDLE             MutexHandle;
466
467
468     /* Get a handle to an AML mutex */
469
470     Status = AcpiGetHandle (NULL, "\\MTX1", &MutexHandle);
471     if (Status == AE_NOT_FOUND)
472     {
473         return;
474     }
475
476     ACPI_CHECK_OK (AcpiGetHandle, Status);
477     if (ACPI_FAILURE (Status))
478     {
479         return;
480     }
481
482     /* Acquire the  mutex */
483
484     Status = AcpiAcquireMutex (NULL, "\\MTX1", 0xFFFF);
485     ACPI_CHECK_OK (AcpiAcquireMutex, Status);
486     if (ACPI_FAILURE (Status))
487     {
488         return;
489     }
490
491     /* Release mutex with different parameters */
492
493     Status = AcpiReleaseMutex (MutexHandle, NULL);
494     ACPI_CHECK_OK (AcpiReleaseMutex, Status);
495 }
496
497
498 /******************************************************************************
499  *
500  * FUNCTION:    AeHardwareInterfaces
501  *
502  * DESCRIPTION: Call various hardware support interfaces
503  *
504  *****************************************************************************/
505
506 static void
507 AeHardwareInterfaces (
508     void)
509 {
510 #if (!ACPI_REDUCED_HARDWARE)
511
512     ACPI_STATUS             Status;
513     UINT32                  Value;
514
515
516     /* If Hardware Reduced flag is set, we are all done */
517
518     if (AcpiGbl_ReducedHardware)
519     {
520         return;
521     }
522
523     Status = AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS, 1);
524     ACPI_CHECK_OK (AcpiWriteBitRegister, Status);
525
526     Status = AcpiWriteBitRegister (ACPI_BITREG_GLOBAL_LOCK_ENABLE, 1);
527     ACPI_CHECK_OK (AcpiWriteBitRegister, Status);
528
529     Status = AcpiWriteBitRegister (ACPI_BITREG_SLEEP_ENABLE, 1);
530     ACPI_CHECK_OK (AcpiWriteBitRegister, Status);
531
532     Status = AcpiWriteBitRegister (ACPI_BITREG_ARB_DISABLE, 1);
533     ACPI_CHECK_OK (AcpiWriteBitRegister, Status);
534
535
536     Status = AcpiReadBitRegister (ACPI_BITREG_WAKE_STATUS, &Value);
537     ACPI_CHECK_OK (AcpiReadBitRegister, Status);
538
539     Status = AcpiReadBitRegister (ACPI_BITREG_GLOBAL_LOCK_ENABLE, &Value);
540     ACPI_CHECK_OK (AcpiReadBitRegister, Status);
541
542     Status = AcpiReadBitRegister (ACPI_BITREG_SLEEP_ENABLE, &Value);
543     ACPI_CHECK_OK (AcpiReadBitRegister, Status);
544
545     Status = AcpiReadBitRegister (ACPI_BITREG_ARB_DISABLE, &Value);
546     ACPI_CHECK_OK (AcpiReadBitRegister, Status);
547
548 #endif /* !ACPI_REDUCED_HARDWARE */
549 }
550
551
552 /******************************************************************************
553  *
554  * FUNCTION:    AeMiscellaneousTests
555  *
556  * DESCRIPTION: Various ACPICA validation tests.
557  *
558  *****************************************************************************/
559
560 void
561 AeMiscellaneousTests (
562     void)
563 {
564     ACPI_BUFFER             ReturnBuf;
565     char                    Buffer[32];
566     ACPI_STATUS             Status;
567     ACPI_STATISTICS         Stats;
568     ACPI_HANDLE             Handle;
569
570 #if (!ACPI_REDUCED_HARDWARE)
571     UINT32                  LockHandle1;
572     UINT32                  LockHandle2;
573     ACPI_VENDOR_UUID        Uuid =
574         {0, {ACPI_INIT_UUID (0,0,0,0,0,0,0,0,0,0,0)}};
575 #endif /* !ACPI_REDUCED_HARDWARE */
576
577
578     Status = AcpiGetHandle (NULL, "\\", &Handle);
579     ACPI_CHECK_OK (AcpiGetHandle, Status);
580
581     if (AcpiGbl_DoInterfaceTests)
582     {
583         /*
584          * Tests for AcpiLoadTable and AcpiUnloadParentTable
585          */
586
587         /* Attempt unload of DSDT, should fail */
588
589         Status = AcpiGetHandle (NULL, "\\_SB_", &Handle);
590         ACPI_CHECK_OK (AcpiGetHandle, Status);
591
592         Status = AcpiUnloadParentTable (Handle);
593         ACPI_CHECK_STATUS (AcpiUnloadParentTable, Status, AE_TYPE);
594
595         /* Load and unload SSDT4 */
596
597         Status = AcpiLoadTable ((ACPI_TABLE_HEADER *) Ssdt4Code);
598         ACPI_CHECK_OK (AcpiLoadTable, Status);
599
600         Status = AcpiGetHandle (NULL, "\\_T96", &Handle);
601         ACPI_CHECK_OK (AcpiGetHandle, Status);
602
603         Status = AcpiUnloadParentTable (Handle);
604         ACPI_CHECK_OK (AcpiUnloadParentTable, Status);
605
606         /* Re-load SSDT4 */
607
608         Status = AcpiLoadTable ((ACPI_TABLE_HEADER *) Ssdt4Code);
609         ACPI_CHECK_OK (AcpiLoadTable, Status);
610
611         /* Unload and re-load SSDT2 (SSDT2 is in the XSDT) */
612
613         Status = AcpiGetHandle (NULL, "\\_T99", &Handle);
614         ACPI_CHECK_OK (AcpiGetHandle, Status);
615
616         Status = AcpiUnloadParentTable (Handle);
617         ACPI_CHECK_OK (AcpiUnloadParentTable, Status);
618
619         Status = AcpiLoadTable ((ACPI_TABLE_HEADER *) Ssdt2Code);
620         ACPI_CHECK_OK (AcpiLoadTable, Status);
621
622         /* Load OEM9 table (causes table override) */
623
624         Status = AcpiLoadTable ((ACPI_TABLE_HEADER *) Ssdt3Code);
625         ACPI_CHECK_OK (AcpiLoadTable, Status);
626     }
627
628     AeHardwareInterfaces ();
629     AeGenericRegisters ();
630     AeSetupConfiguration (Ssdt3Code);
631
632     AeTestBufferArgument();
633     AeTestPackageArgument ();
634     AeMutexInterfaces ();
635
636     /* Test _OSI install/remove */
637
638     Status = AcpiInstallInterface ("");
639     ACPI_CHECK_STATUS (AcpiInstallInterface, Status, AE_BAD_PARAMETER);
640
641     Status = AcpiInstallInterface ("TestString");
642     ACPI_CHECK_OK (AcpiInstallInterface, Status);
643
644     Status = AcpiInstallInterface ("TestString");
645     ACPI_CHECK_STATUS (AcpiInstallInterface, Status, AE_ALREADY_EXISTS);
646
647     Status = AcpiRemoveInterface ("Windows 2006");
648     ACPI_CHECK_OK (AcpiRemoveInterface, Status);
649
650     Status = AcpiRemoveInterface ("TestString");
651     ACPI_CHECK_OK (AcpiRemoveInterface, Status);
652
653     Status = AcpiRemoveInterface ("XXXXXX");
654     ACPI_CHECK_STATUS (AcpiRemoveInterface, Status, AE_NOT_EXIST);
655
656     Status = AcpiInstallInterface ("AnotherTestString");
657     ACPI_CHECK_OK (AcpiInstallInterface, Status);
658
659     /* Test _OSI execution */
660
661     Status = ExecuteOSI ("Extended Address Space Descriptor", 0xFFFFFFFF);
662     ACPI_CHECK_OK (ExecuteOSI, Status);
663
664     Status = ExecuteOSI ("Windows 2001", 0xFFFFFFFF);
665     ACPI_CHECK_OK (ExecuteOSI, Status);
666
667     Status = ExecuteOSI ("MichiganTerminalSystem", 0);
668     ACPI_CHECK_OK (ExecuteOSI, Status);
669
670
671     ReturnBuf.Length = 32;
672     ReturnBuf.Pointer = Buffer;
673
674     Status = AcpiGetName (ACPI_ROOT_OBJECT,
675         ACPI_FULL_PATHNAME_NO_TRAILING, &ReturnBuf);
676     ACPI_CHECK_OK (AcpiGetName, Status);
677
678     /* Get Devices */
679
680     Status = AcpiGetDevices (NULL, AeGetDevices, NULL, NULL);
681     ACPI_CHECK_OK (AcpiGetDevices, Status);
682
683     Status = AcpiGetStatistics (&Stats);
684     ACPI_CHECK_OK (AcpiGetStatistics, Status);
685
686
687 #if (!ACPI_REDUCED_HARDWARE)
688
689     Status = AcpiInstallGlobalEventHandler (AeGlobalEventHandler, NULL);
690     ACPI_CHECK_OK (AcpiInstallGlobalEventHandler, Status);
691
692     /* If Hardware Reduced flag is set, we are all done */
693
694     if (AcpiGbl_ReducedHardware)
695     {
696         return;
697     }
698
699     Status = AcpiEnableEvent (ACPI_EVENT_GLOBAL, 0);
700     ACPI_CHECK_OK (AcpiEnableEvent, Status);
701
702     /*
703      * GPEs: Handlers, enable/disable, etc.
704      */
705     Status = AcpiInstallGpeHandler (NULL, 0,
706         ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
707     ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
708
709     Status = AcpiEnableGpe (NULL, 0);
710     ACPI_CHECK_OK (AcpiEnableGpe, Status);
711
712     Status = AcpiRemoveGpeHandler (NULL, 0, AeGpeHandler);
713     ACPI_CHECK_OK (AcpiRemoveGpeHandler, Status);
714
715     Status = AcpiInstallGpeHandler (NULL, 0,
716         ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
717     ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
718
719     Status = AcpiEnableGpe (NULL, 0);
720     ACPI_CHECK_OK (AcpiEnableGpe, Status);
721
722     Status = AcpiSetGpe (NULL, 0, ACPI_GPE_DISABLE);
723     ACPI_CHECK_OK (AcpiSetGpe, Status);
724
725     Status = AcpiSetGpe (NULL, 0, ACPI_GPE_ENABLE);
726     ACPI_CHECK_OK (AcpiSetGpe, Status);
727
728
729     Status = AcpiInstallGpeHandler (NULL, 1,
730         ACPI_GPE_EDGE_TRIGGERED, AeGpeHandler, NULL);
731     ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
732
733     Status = AcpiEnableGpe (NULL, 1);
734     ACPI_CHECK_OK (AcpiEnableGpe, Status);
735
736
737     Status = AcpiInstallGpeHandler (NULL, 2,
738         ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
739     ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
740
741     Status = AcpiEnableGpe (NULL, 2);
742     ACPI_CHECK_OK (AcpiEnableGpe, Status);
743
744
745     Status = AcpiInstallGpeHandler (NULL, 3,
746         ACPI_GPE_EDGE_TRIGGERED, AeGpeHandler, NULL);
747     ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
748
749     Status = AcpiInstallGpeHandler (NULL, 4,
750         ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
751     ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
752
753     Status = AcpiInstallGpeHandler (NULL, 5,
754         ACPI_GPE_EDGE_TRIGGERED, AeGpeHandler, NULL);
755     ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
756
757     Status = AcpiGetHandle (NULL, "\\_SB", &Handle);
758     ACPI_CHECK_OK (AcpiGetHandle, Status);
759
760     Status = AcpiSetupGpeForWake (Handle, NULL, 5);
761     ACPI_CHECK_OK (AcpiSetupGpeForWake, Status);
762
763     Status = AcpiSetGpeWakeMask (NULL, 5, ACPI_GPE_ENABLE);
764     ACPI_CHECK_OK (AcpiSetGpeWakeMask, Status);
765
766     Status = AcpiSetupGpeForWake (Handle, NULL, 6);
767     ACPI_CHECK_OK (AcpiSetupGpeForWake, Status);
768
769     Status = AcpiSetupGpeForWake (ACPI_ROOT_OBJECT, NULL, 6);
770     ACPI_CHECK_OK (AcpiSetupGpeForWake, Status);
771
772     Status = AcpiSetupGpeForWake (Handle, NULL, 9);
773     ACPI_CHECK_OK (AcpiSetupGpeForWake, Status);
774
775     Status = AcpiInstallGpeHandler (NULL, 0x19,
776         ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
777     ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
778
779     Status = AcpiEnableGpe (NULL, 0x19);
780     ACPI_CHECK_OK (AcpiEnableGpe, Status);
781
782
783     /* GPE block 1 */
784
785     Status = AcpiInstallGpeHandler (NULL, 101,
786         ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL);
787     ACPI_CHECK_OK (AcpiInstallGpeHandler, Status);
788
789     Status = AcpiEnableGpe (NULL, 101);
790     ACPI_CHECK_OK (AcpiEnableGpe, Status);
791
792     Status = AcpiDisableGpe (NULL, 101);
793     ACPI_CHECK_OK (AcpiDisableGpe, Status);
794
795     AfInstallGpeBlock ();
796
797     /* Here is where the GPEs are actually "enabled" */
798
799     Status = AcpiUpdateAllGpes ();
800     ACPI_CHECK_OK (AcpiUpdateAllGpes, Status);
801
802     Status = AcpiGetHandle (NULL, "RSRC", &Handle);
803     if (ACPI_SUCCESS (Status))
804     {
805         ReturnBuf.Length = ACPI_ALLOCATE_BUFFER;
806
807         Status = AcpiGetVendorResource (Handle, "_CRS", &Uuid, &ReturnBuf);
808         if (ACPI_SUCCESS (Status))
809         {
810             AcpiOsFree (ReturnBuf.Pointer);
811         }
812     }
813
814     /* Test global lock */
815
816     Status = AcpiAcquireGlobalLock (0xFFFF, &LockHandle1);
817     ACPI_CHECK_OK (AcpiAcquireGlobalLock, Status);
818
819     Status = AcpiAcquireGlobalLock (0x5, &LockHandle2);
820     ACPI_CHECK_OK (AcpiAcquireGlobalLock, Status);
821
822     Status = AcpiReleaseGlobalLock (LockHandle1);
823     ACPI_CHECK_OK (AcpiReleaseGlobalLock, Status);
824
825     Status = AcpiReleaseGlobalLock (LockHandle2);
826     ACPI_CHECK_OK (AcpiReleaseGlobalLock, Status);
827
828 #endif /* !ACPI_REDUCED_HARDWARE */
829 }