1 /******************************************************************************
2  *
3  * Module Name: aehandlers - Various handlers for acpiexec
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
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
19  * property rights.
20  *
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
27  *
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;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
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.
53  *
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
64  * make.
65  *
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
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
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.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
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
88  * PARTICULAR PURPOSE.
89  *
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
97  * LIMITED REMEDY.
98  *
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.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include "aecommon.h"
153 
154 #define _COMPONENT          ACPI_TOOLS
155         ACPI_MODULE_NAME    ("aehandlers")
156 
157 
158 /* Local prototypes */
159 
160 static void
161 AeNotifyHandler1 (
162     ACPI_HANDLE             Device,
163     UINT32                  Value,
164     void                    *Context);
165 
166 static void
167 AeNotifyHandler2 (
168     ACPI_HANDLE             Device,
169     UINT32                  Value,
170     void                    *Context);
171 
172 static void
173 AeCommonNotifyHandler (
174     ACPI_HANDLE             Device,
175     UINT32                  Value,
176     UINT32                  HandlerId);
177 
178 static void
179 AeDeviceNotifyHandler (
180     ACPI_HANDLE             Device,
181     UINT32                  Value,
182     void                    *Context);
183 
184 static ACPI_STATUS
185 AeExceptionHandler (
186     ACPI_STATUS             AmlStatus,
187     ACPI_NAME               Name,
188     UINT16                  Opcode,
189     UINT32                  AmlOffset,
190     void                    *Context);
191 
192 static ACPI_STATUS
193 AeTableHandler (
194     UINT32                  Event,
195     void                    *Table,
196     void                    *Context);
197 
198 static void
199 AeAttachedDataHandler (
200     ACPI_HANDLE             Object,
201     void                    *Data);
202 
203 static void
204 AeAttachedDataHandler2 (
205     ACPI_HANDLE             Object,
206     void                    *Data);
207 
208 static UINT32
209 AeInterfaceHandler (
210     ACPI_STRING             InterfaceName,
211     UINT32                  Supported);
212 
213 #if (!ACPI_REDUCED_HARDWARE)
214 static UINT32
215 AeEventHandler (
216     void                    *Context);
217 
218 static UINT32
219 AeSciHandler (
220     void                    *Context);
221 
222 static char                *TableEvents[] =
223 {
224     "LOAD",
225     "UNLOAD",
226     "INSTALL",
227     "UNINSTALL",
228     "UNKNOWN"
229 };
230 #endif /* !ACPI_REDUCED_HARDWARE */
231 
232 
233 static UINT32               SigintCount = 0;
234 static AE_DEBUG_REGIONS     AeRegions;
235 
236 
237 /******************************************************************************
238  *
239  * FUNCTION:    AeCtrlCHandler
240  *
241  * PARAMETERS:  Sig
242  *
243  * RETURN:      none
244  *
245  * DESCRIPTION: Control-C handler. Abort running control method if any.
246  *
247  *****************************************************************************/
248 
249 void ACPI_SYSTEM_XFACE
250 AeCtrlCHandler (
251     int                     Sig)
252 {
253 
254     signal (SIGINT, SIG_IGN);
255     SigintCount++;
256 
257     AcpiOsPrintf ("Caught a ctrl-c (#%u)\n\n", SigintCount);
258 
259     if (AcpiGbl_MethodExecuting)
260     {
261         AcpiGbl_AbortMethod = TRUE;
262         signal (SIGINT, AeCtrlCHandler);
263 
264         if (SigintCount < 10)
265         {
266             return;
267         }
268     }
269 
270     (void) AcpiOsTerminate ();
271     exit (0);
272 }
273 
274 
275 /******************************************************************************
276  *
277  * FUNCTION:    AeNotifyHandler(s)
278  *
279  * PARAMETERS:  Standard notify handler parameters
280  *
281  * RETURN:      Status
282  *
283  * DESCRIPTION: Notify handlers for AcpiExec utility. Used by the ASL
284  *              test suite(s) to communicate errors and other information to
285  *              this utility via the Notify() operator. Tests notify handling
286  *              and multiple notify handler support.
287  *
288  *****************************************************************************/
289 
290 static void
291 AeNotifyHandler1 (
292     ACPI_HANDLE             Device,
293     UINT32                  Value,
294     void                    *Context)
295 {
296     AeCommonNotifyHandler (Device, Value, 1);
297 }
298 
299 static void
300 AeNotifyHandler2 (
301     ACPI_HANDLE             Device,
302     UINT32                  Value,
303     void                    *Context)
304 {
305     AeCommonNotifyHandler (Device, Value, 2);
306 }
307 
308 static void
309 AeCommonNotifyHandler (
310     ACPI_HANDLE             Device,
311     UINT32                  Value,
312     UINT32                  HandlerId)
313 {
314     char                    *Type;
315 
316 
317     Type = "Device";
318     if (Value <= ACPI_MAX_SYS_NOTIFY)
319     {
320         Type = "System";
321     }
322 
323     switch (Value)
324     {
325 #if 0
326     case 0:
327 
328         printf ("[AcpiExec] Method Error 0x%X: Results not equal\n", Value);
329         if (AcpiGbl_DebugFile)
330         {
331             AcpiOsPrintf ("[AcpiExec] Method Error: Results not equal\n");
332         }
333         break;
334 
335     case 1:
336 
337         printf ("[AcpiExec] Method Error: Incorrect numeric result\n");
338         if (AcpiGbl_DebugFile)
339         {
340             AcpiOsPrintf ("[AcpiExec] Method Error: Incorrect numeric result\n");
341         }
342         break;
343 
344     case 2:
345 
346         printf ("[AcpiExec] Method Error: An operand was overwritten\n");
347         if (AcpiGbl_DebugFile)
348         {
349             AcpiOsPrintf ("[AcpiExec] Method Error: An operand was overwritten\n");
350         }
351         break;
352 
353 #endif
354 
355     default:
356 
357         printf ("[AcpiExec] Handler %u: Received a %s Notify on [%4.4s] %p Value 0x%2.2X (%s)\n",
358             HandlerId, Type, AcpiUtGetNodeName (Device), Device, Value,
359             AcpiUtGetNotifyName (Value, ACPI_TYPE_ANY));
360         if (AcpiGbl_DebugFile)
361         {
362             AcpiOsPrintf ("[AcpiExec] Handler %u: Received a %s notify, Value 0x%2.2X\n",
363                 HandlerId, Type, Value);
364         }
365 
366         (void) AcpiEvaluateObject (Device, "_NOT", NULL, NULL);
367         break;
368     }
369 }
370 
371 
372 /******************************************************************************
373  *
374  * FUNCTION:    AeSystemNotifyHandler
375  *
376  * PARAMETERS:  Standard notify handler parameters
377  *
378  * RETURN:      Status
379  *
380  * DESCRIPTION: System notify handler for AcpiExec utility. Used by the ASL
381  *              test suite(s) to communicate errors and other information to
382  *              this utility via the Notify() operator.
383  *
384  *****************************************************************************/
385 
386 static void
387 AeSystemNotifyHandler (
388     ACPI_HANDLE                 Device,
389     UINT32                      Value,
390     void                        *Context)
391 {
392 
393     printf ("[AcpiExec] Global:    Received a System Notify on [%4.4s] %p Value 0x%2.2X (%s)\n",
394         AcpiUtGetNodeName (Device), Device, Value,
395         AcpiUtGetNotifyName (Value, ACPI_TYPE_ANY));
396     if (AcpiGbl_DebugFile)
397     {
398         AcpiOsPrintf ("[AcpiExec] Global:    Received a System Notify, Value 0x%2.2X\n", Value);
399     }
400 
401     (void) AcpiEvaluateObject (Device, "_NOT", NULL, NULL);
402 }
403 
404 
405 /******************************************************************************
406  *
407  * FUNCTION:    AeDeviceNotifyHandler
408  *
409  * PARAMETERS:  Standard notify handler parameters
410  *
411  * RETURN:      Status
412  *
413  * DESCRIPTION: Device notify handler for AcpiExec utility. Used by the ASL
414  *              test suite(s) to communicate errors and other information to
415  *              this utility via the Notify() operator.
416  *
417  *****************************************************************************/
418 
419 static void
420 AeDeviceNotifyHandler (
421     ACPI_HANDLE                 Device,
422     UINT32                      Value,
423     void                        *Context)
424 {
425 
426     printf ("[AcpiExec] Global:    Received a Device Notify on [%4.4s] %p Value 0x%2.2X (%s)\n",
427         AcpiUtGetNodeName (Device), Device, Value,
428         AcpiUtGetNotifyName (Value, ACPI_TYPE_ANY));
429     if (AcpiGbl_DebugFile)
430     {
431         AcpiOsPrintf ("[AcpiExec] Global:    Received a Device Notify, Value 0x%2.2X\n", Value);
432     }
433 
434     (void) AcpiEvaluateObject (Device, "_NOT", NULL, NULL);
435 }
436 
437 
438 /******************************************************************************
439  *
440  * FUNCTION:    AeExceptionHandler
441  *
442  * PARAMETERS:  Standard exception handler parameters
443  *
444  * RETURN:      Status
445  *
446  * DESCRIPTION: System exception handler for AcpiExec utility.
447  *
448  *****************************************************************************/
449 
450 static ACPI_STATUS
451 AeExceptionHandler (
452     ACPI_STATUS             AmlStatus,
453     ACPI_NAME               Name,
454     UINT16                  Opcode,
455     UINT32                  AmlOffset,
456     void                    *Context)
457 {
458     ACPI_STATUS             NewAmlStatus = AmlStatus;
459     ACPI_STATUS             Status;
460     ACPI_BUFFER             ReturnObj;
461     ACPI_OBJECT_LIST        ArgList;
462     ACPI_OBJECT             Arg[3];
463     const char              *Exception;
464 
465 
466     Exception = AcpiFormatException (AmlStatus);
467     AcpiOsPrintf ("[AcpiExec] Exception %s during execution ", Exception);
468     if (Name)
469     {
470         AcpiOsPrintf ("of method [%4.4s]", (char *) &Name);
471     }
472     else
473     {
474         AcpiOsPrintf ("at module level (table load)");
475     }
476 
477     AcpiOsPrintf (" Opcode [%s] @%X\n", AcpiPsGetOpcodeName (Opcode), AmlOffset);
478 
479     /*
480      * Invoke the _ERR method if present
481      *
482      * Setup parameter object
483      */
484     ArgList.Count = 3;
485     ArgList.Pointer = Arg;
486 
487     Arg[0].Type = ACPI_TYPE_INTEGER;
488     Arg[0].Integer.Value = AmlStatus;
489 
490     Arg[1].Type = ACPI_TYPE_STRING;
491     Arg[1].String.Pointer = ACPI_CAST_PTR (char, Exception);
492     Arg[1].String.Length = strlen (Exception);
493 
494     Arg[2].Type = ACPI_TYPE_INTEGER;
495     Arg[2].Integer.Value = AcpiOsGetThreadId();
496 
497     /* Setup return buffer */
498 
499     ReturnObj.Pointer = NULL;
500     ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
501 
502     Status = AcpiEvaluateObject (NULL, "\\_ERR", &ArgList, &ReturnObj);
503     if (ACPI_SUCCESS (Status))
504     {
505         if (ReturnObj.Pointer)
506         {
507             /* Override original status */
508 
509             NewAmlStatus = (ACPI_STATUS)
510                 ((ACPI_OBJECT *) ReturnObj.Pointer)->Integer.Value;
511 
512             /* Free a buffer created via ACPI_ALLOCATE_BUFFER */
513 
514             AcpiOsFree (ReturnObj.Pointer);
515         }
516     }
517     else if (Status != AE_NOT_FOUND)
518     {
519         AcpiOsPrintf ("[AcpiExec] Could not execute _ERR method, %s\n",
520             AcpiFormatException (Status));
521     }
522 
523     /* Global override */
524 
525     if (AcpiGbl_IgnoreErrors)
526     {
527         NewAmlStatus = AE_OK;
528     }
529 
530     if (NewAmlStatus != AmlStatus)
531     {
532         AcpiOsPrintf ("[AcpiExec] Exception override, new status %s\n\n",
533             AcpiFormatException (NewAmlStatus));
534     }
535 
536     return (NewAmlStatus);
537 }
538 
539 
540 /******************************************************************************
541  *
542  * FUNCTION:    AeTableHandler
543  *
544  * PARAMETERS:  Table handler
545  *
546  * RETURN:      Status
547  *
548  * DESCRIPTION: System table handler for AcpiExec utility.
549  *
550  *****************************************************************************/
551 
552 static ACPI_STATUS
553 AeTableHandler (
554     UINT32                  Event,
555     void                    *Table,
556     void                    *Context)
557 {
558 #if (!ACPI_REDUCED_HARDWARE)
559     ACPI_STATUS             Status;
560 #endif /* !ACPI_REDUCED_HARDWARE */
561 
562 
563     if (Event > ACPI_NUM_TABLE_EVENTS)
564     {
565         Event = ACPI_NUM_TABLE_EVENTS;
566     }
567 
568 #if (!ACPI_REDUCED_HARDWARE)
569     /* Enable any GPEs associated with newly-loaded GPE methods */
570 
571     Status = AcpiUpdateAllGpes ();
572     ACPI_CHECK_OK (AcpiUpdateAllGpes, Status);
573 
574     printf ("[AcpiExec] Table Event %s, [%4.4s] %p\n",
575         TableEvents[Event], ((ACPI_TABLE_HEADER *) Table)->Signature, Table);
576 #endif /* !ACPI_REDUCED_HARDWARE */
577 
578     return (AE_OK);
579 }
580 
581 
582 /******************************************************************************
583  *
584  * FUNCTION:    AeGpeHandler
585  *
586  * DESCRIPTION: Common GPE handler for acpiexec
587  *
588  *****************************************************************************/
589 
590 UINT32
591 AeGpeHandler (
592     ACPI_HANDLE             GpeDevice,
593     UINT32                  GpeNumber,
594     void                    *Context)
595 {
596     ACPI_NAMESPACE_NODE     *DeviceNode = (ACPI_NAMESPACE_NODE *) GpeDevice;
597 
598 
599     AcpiOsPrintf ("[AcpiExec] GPE Handler received GPE %02X (GPE block %4.4s)\n",
600         GpeNumber, GpeDevice ? DeviceNode->Name.Ascii : "FADT");
601 
602     return (ACPI_REENABLE_GPE);
603 }
604 
605 
606 /******************************************************************************
607  *
608  * FUNCTION:    AeGlobalEventHandler
609  *
610  * DESCRIPTION: Global GPE/Fixed event handler
611  *
612  *****************************************************************************/
613 
614 void
615 AeGlobalEventHandler (
616     UINT32                  Type,
617     ACPI_HANDLE             Device,
618     UINT32                  EventNumber,
619     void                    *Context)
620 {
621     char                    *TypeName;
622 
623 
624     switch (Type)
625     {
626     case ACPI_EVENT_TYPE_GPE:
627 
628         TypeName = "GPE";
629         break;
630 
631     case ACPI_EVENT_TYPE_FIXED:
632 
633         TypeName = "FixedEvent";
634         break;
635 
636     default:
637 
638         TypeName = "UNKNOWN";
639         break;
640     }
641 
642     AcpiOsPrintf (
643         "[AcpiExec] Global Event Handler received: Type %s Number %.2X Dev %p\n",
644         TypeName, EventNumber, Device);
645 }
646 
647 
648 /******************************************************************************
649  *
650  * FUNCTION:    AeAttachedDataHandler
651  *
652  * DESCRIPTION: Handler for deletion of nodes with attached data (attached via
653  *              AcpiAttachData)
654  *
655  *****************************************************************************/
656 
657 static void
658 AeAttachedDataHandler (
659     ACPI_HANDLE             Object,
660     void                    *Data)
661 {
662     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Data);
663 
664 
665     AcpiOsPrintf ("Received an attached data deletion (1) on %4.4s\n",
666         Node->Name.Ascii);
667 }
668 
669 
670 /******************************************************************************
671  *
672  * FUNCTION:    AeAttachedDataHandler2
673  *
674  * DESCRIPTION: Handler for deletion of nodes with attached data (attached via
675  *              AcpiAttachData)
676  *
677  *****************************************************************************/
678 
679 static void
680 AeAttachedDataHandler2 (
681     ACPI_HANDLE             Object,
682     void                    *Data)
683 {
684     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Data);
685 
686 
687     AcpiOsPrintf ("Received an attached data deletion (2) on %4.4s\n",
688         Node->Name.Ascii);
689 }
690 
691 
692 /******************************************************************************
693  *
694  * FUNCTION:    AeInterfaceHandler
695  *
696  * DESCRIPTION: Handler for _OSI invocations
697  *
698  *****************************************************************************/
699 
700 static UINT32
701 AeInterfaceHandler (
702     ACPI_STRING             InterfaceName,
703     UINT32                  Supported)
704 {
705     ACPI_FUNCTION_NAME (AeInterfaceHandler);
706 
707 
708     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
709         "Received _OSI (\"%s\"), is %ssupported\n",
710         InterfaceName, Supported == 0 ? "not " : ""));
711 
712     return (Supported);
713 }
714 
715 
716 #if (!ACPI_REDUCED_HARDWARE)
717 /******************************************************************************
718  *
719  * FUNCTION:    AeEventHandler, AeSciHandler
720  *
721  * DESCRIPTION: Handler for Fixed Events and SCIs
722  *
723  *****************************************************************************/
724 
725 static UINT32
726 AeEventHandler (
727     void                    *Context)
728 {
729     return (0);
730 }
731 
732 static UINT32
733 AeSciHandler (
734     void                    *Context)
735 {
736 
737     AcpiOsPrintf ("[AcpiExec] Received an SCI at handler\n");
738     return (0);
739 }
740 
741 #endif /* !ACPI_REDUCED_HARDWARE */
742 
743 
744 /*******************************************************************************
745  *
746  * FUNCTION:    AeInstallSciHandler
747  *
748  * PARAMETERS:  None
749  *
750  * RETURN:      Status
751  *
752  * DESCRIPTION: Install handler for SCIs. Exercise the code by doing an
753  *              install/remove/install.
754  *
755  ******************************************************************************/
756 
757 static ACPI_STATUS
758 AeInstallSciHandler (
759     void)
760 {
761     ACPI_STATUS             Status;
762 
763 
764     Status = AcpiInstallSciHandler (AeSciHandler, &AeMyContext);
765     if (ACPI_FAILURE (Status))
766     {
767         ACPI_EXCEPTION ((AE_INFO, Status,
768             "Could not install an SCI handler (1)"));
769     }
770 
771     Status = AcpiRemoveSciHandler (AeSciHandler);
772     if (ACPI_FAILURE (Status))
773     {
774         ACPI_EXCEPTION ((AE_INFO, Status,
775             "Could not remove an SCI handler"));
776     }
777 
778     Status = AcpiInstallSciHandler (AeSciHandler, &AeMyContext);
779     if (ACPI_FAILURE (Status))
780     {
781         ACPI_EXCEPTION ((AE_INFO, Status,
782             "Could not install an SCI handler (2)"));
783     }
784 
785     return (Status);
786 }
787 
788 
789 /******************************************************************************
790  *
791  * FUNCTION:    AeInstallLateHandlers
792  *
793  * PARAMETERS:  None
794  *
795  * RETURN:      Status
796  *
797  * DESCRIPTION: Install handlers for the AcpiExec utility.
798  *
799  *****************************************************************************/
800 
801 ACPI_STATUS
802 AeInstallLateHandlers (
803     void)
804 {
805     ACPI_STATUS             Status;
806     ACPI_HANDLE             Handle;
807 
808 
809     Status = AcpiGetHandle (NULL, "\\_TZ.TZ1", &Handle);
810     if (ACPI_SUCCESS (Status))
811     {
812         Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
813             AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567));
814 
815         Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
816             AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF));
817 
818         Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY,
819             AeNotifyHandler1);
820         Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY,
821             AeNotifyHandler2);
822 
823         Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
824             AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF));
825 
826         Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
827             AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567));
828     }
829 
830     Status = AcpiGetHandle (NULL, "\\_PR.CPU0", &Handle);
831     if (ACPI_SUCCESS (Status))
832     {
833         Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
834             AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567));
835 
836         Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
837             AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF));
838     }
839 
840 #if (!ACPI_REDUCED_HARDWARE)
841     if (!AcpiGbl_ReducedHardware)
842     {
843         /* Install a user SCI handler */
844 
845         Status = AeInstallSciHandler ();
846         ACPI_CHECK_OK (AeInstallSciHandler, Status);
847 
848         /* Install some fixed event handlers */
849 
850         Status = AcpiInstallFixedEventHandler (
851             ACPI_EVENT_GLOBAL, AeEventHandler, NULL);
852         ACPI_CHECK_OK (AcpiInstallFixedEventHandler, Status);
853 
854         Status = AcpiInstallFixedEventHandler (
855             ACPI_EVENT_RTC, AeEventHandler, NULL);
856         ACPI_CHECK_OK (AcpiInstallFixedEventHandler, Status);
857     }
858 #endif /* !ACPI_REDUCED_HARDWARE */
859 
860     AeMyContext.Connection = NULL;
861     AeMyContext.AccessLength = 0xA5;
862 
863     /*
864      * We will install a handler for each EC device, directly under the EC
865      * device definition. This is unlike the other handlers which we install
866      * at the root node. Also install memory and I/O handlers at any PCI
867      * devices.
868      */
869     AeInstallDeviceHandlers ();
870 
871     /*
872      * Install handlers for some of the "device driver" address spaces
873      * such as SMBus, etc.
874      */
875     AeInstallRegionHandlers ();
876     return (AE_OK);
877 }
878 
879 
880 /******************************************************************************
881  *
882  * FUNCTION:    AeInstallEarlyHandlers
883  *
884  * PARAMETERS:  None
885  *
886  * RETURN:      Status
887  *
888  * DESCRIPTION: Install handlers for the AcpiExec utility.
889  *
890  * Notes:       Don't install handler for PCI_Config, we want to use the
891  *              default handler to exercise that code.
892  *
893  *****************************************************************************/
894 
895 ACPI_STATUS
896 AeInstallEarlyHandlers (
897     void)
898 {
899     ACPI_STATUS             Status;
900     ACPI_HANDLE             Handle;
901 
902 
903     ACPI_FUNCTION_ENTRY ();
904 
905 
906     Status = AcpiInstallInterfaceHandler (AeInterfaceHandler);
907     if (ACPI_FAILURE (Status))
908     {
909         printf ("Could not install interface handler, %s\n",
910             AcpiFormatException (Status));
911     }
912 
913     Status = AcpiInstallTableHandler (AeTableHandler, NULL);
914     if (ACPI_FAILURE (Status))
915     {
916         printf ("Could not install table handler, %s\n",
917             AcpiFormatException (Status));
918     }
919 
920     Status = AcpiInstallExceptionHandler (AeExceptionHandler);
921     if (ACPI_FAILURE (Status))
922     {
923         printf ("Could not install exception handler, %s\n",
924             AcpiFormatException (Status));
925     }
926 
927     /* Install global notify handlers */
928 
929     Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
930         AeSystemNotifyHandler, NULL);
931     if (ACPI_FAILURE (Status))
932     {
933         printf ("Could not install a global system notify handler, %s\n",
934             AcpiFormatException (Status));
935     }
936 
937     Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_DEVICE_NOTIFY,
938         AeDeviceNotifyHandler, NULL);
939     if (ACPI_FAILURE (Status))
940     {
941         printf ("Could not install a global notify handler, %s\n",
942             AcpiFormatException (Status));
943     }
944 
945     Status = AcpiGetHandle (NULL, "\\_SB", &Handle);
946     if (ACPI_SUCCESS (Status))
947     {
948         Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
949             AeNotifyHandler1, NULL);
950         if (ACPI_FAILURE (Status))
951         {
952             printf ("Could not install a notify handler, %s\n",
953                 AcpiFormatException (Status));
954         }
955 
956         Status = AcpiRemoveNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
957             AeNotifyHandler1);
958         if (ACPI_FAILURE (Status))
959         {
960             printf ("Could not remove a notify handler, %s\n",
961                 AcpiFormatException (Status));
962         }
963 
964         Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
965             AeNotifyHandler1, NULL);
966         ACPI_CHECK_OK (AcpiInstallNotifyHandler, Status);
967 
968         Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY,
969             AeNotifyHandler1);
970         ACPI_CHECK_OK (AcpiRemoveNotifyHandler, Status);
971 
972 #if 0
973         Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
974             AeNotifyHandler1, NULL);
975         if (ACPI_FAILURE (Status))
976         {
977             printf ("Could not install a notify handler, %s\n",
978                 AcpiFormatException (Status));
979         }
980 #endif
981 
982         /* Install two handlers for _SB_ */
983 
984         Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
985             AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567));
986 
987         Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
988             AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF));
989 
990         /* Attempt duplicate handler installation, should fail */
991 
992         Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
993             AeNotifyHandler1, ACPI_CAST_PTR (void, 0x77777777));
994 
995         Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle);
996         ACPI_CHECK_OK (AcpiAttachData, Status);
997 
998         Status = AcpiDetachData (Handle, AeAttachedDataHandler);
999         ACPI_CHECK_OK (AcpiDetachData, Status);
1000 
1001         /* Test attach data at the root object */
1002 
1003         Status = AcpiAttachData (ACPI_ROOT_OBJECT, AeAttachedDataHandler,
1004             AcpiGbl_RootNode);
1005         ACPI_CHECK_OK (AcpiAttachData, Status);
1006 
1007         Status = AcpiAttachData (ACPI_ROOT_OBJECT, AeAttachedDataHandler2,
1008             AcpiGbl_RootNode);
1009         ACPI_CHECK_OK (AcpiAttachData, Status);
1010 
1011         /* Test support for multiple attaches */
1012 
1013         Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle);
1014         ACPI_CHECK_OK (AcpiAttachData, Status);
1015 
1016         Status = AcpiAttachData (Handle, AeAttachedDataHandler2, Handle);
1017         ACPI_CHECK_OK (AcpiAttachData, Status);
1018     }
1019     else
1020     {
1021         printf ("No _SB_ found, %s\n", AcpiFormatException (Status));
1022     }
1023 
1024     /*
1025      * Install handlers that will override the default handlers for some of
1026      * the space IDs.
1027      */
1028     AeOverrideRegionHandlers ();
1029 
1030     /*
1031      * Initialize the global Region Handler space
1032      * MCW 3/23/00
1033      */
1034     AeRegions.NumberOfRegions = 0;
1035     AeRegions.RegionList = NULL;
1036     return (AE_OK);
1037 }
1038