1 /******************************************************************************
3 * Module Name: aehandlers - Various handlers for acpiexec
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
46 #define _COMPONENT ACPI_TOOLS
47 ACPI_MODULE_NAME ("aehandlers")
50 /* Local prototypes */
65 AeCommonNotifyHandler (
71 AeDeviceNotifyHandler (
78 ACPI_STATUS AmlStatus,
91 AeAttachedDataHandler (
96 AeAttachedDataHandler2 (
102 ACPI_STRING InterfaceName,
105 #if (!ACPI_REDUCED_HARDWARE)
114 static char *TableEvents[] =
120 #endif /* !ACPI_REDUCED_HARDWARE */
123 static UINT32 SigintCount = 0;
124 static AE_DEBUG_REGIONS AeRegions;
127 /******************************************************************************
129 * FUNCTION: AeCtrlCHandler
135 * DESCRIPTION: Control-C handler. Abort running control method if any.
137 *****************************************************************************/
139 void ACPI_SYSTEM_XFACE
144 signal (SIGINT, SIG_IGN);
147 AcpiOsPrintf ("Caught a ctrl-c (#%u)\n\n", SigintCount);
149 if (AcpiGbl_MethodExecuting)
151 AcpiGbl_AbortMethod = TRUE;
152 signal (SIGINT, AeCtrlCHandler);
154 if (SigintCount < 10)
160 (void) AcpiOsTerminate ();
165 /******************************************************************************
167 * FUNCTION: AeNotifyHandler(s)
169 * PARAMETERS: Standard notify handler parameters
173 * DESCRIPTION: Notify handlers for AcpiExec utility. Used by the ASL
174 * test suite(s) to communicate errors and other information to
175 * this utility via the Notify() operator. Tests notify handling
176 * and multiple notify handler support.
178 *****************************************************************************/
186 AeCommonNotifyHandler (Device, Value, 1);
195 AeCommonNotifyHandler (Device, Value, 2);
199 AeCommonNotifyHandler (
208 if (Value <= ACPI_MAX_SYS_NOTIFY)
218 printf ("[AcpiExec] Method Error 0x%X: Results not equal\n", Value);
219 if (AcpiGbl_DebugFile)
221 AcpiOsPrintf ("[AcpiExec] Method Error: Results not equal\n");
227 printf ("[AcpiExec] Method Error: Incorrect numeric result\n");
228 if (AcpiGbl_DebugFile)
230 AcpiOsPrintf ("[AcpiExec] Method Error: Incorrect numeric result\n");
236 printf ("[AcpiExec] Method Error: An operand was overwritten\n");
237 if (AcpiGbl_DebugFile)
239 AcpiOsPrintf ("[AcpiExec] Method Error: An operand was overwritten\n");
247 printf ("[AcpiExec] Handler %u: Received a %s Notify on [%4.4s] %p Value 0x%2.2X (%s)\n",
248 HandlerId, Type, AcpiUtGetNodeName (Device), Device, Value,
249 AcpiUtGetNotifyName (Value, ACPI_TYPE_ANY));
250 if (AcpiGbl_DebugFile)
252 AcpiOsPrintf ("[AcpiExec] Handler %u: Received a %s notify, Value 0x%2.2X\n",
253 HandlerId, Type, Value);
256 (void) AcpiEvaluateObject (Device, "_NOT", NULL, NULL);
262 /******************************************************************************
264 * FUNCTION: AeSystemNotifyHandler
266 * PARAMETERS: Standard notify handler parameters
270 * DESCRIPTION: System notify handler for AcpiExec utility. Used by the ASL
271 * test suite(s) to communicate errors and other information to
272 * this utility via the Notify() operator.
274 *****************************************************************************/
277 AeSystemNotifyHandler (
283 printf ("[AcpiExec] Global: Received a System Notify on [%4.4s] %p Value 0x%2.2X (%s)\n",
284 AcpiUtGetNodeName (Device), Device, Value,
285 AcpiUtGetNotifyName (Value, ACPI_TYPE_ANY));
286 if (AcpiGbl_DebugFile)
288 AcpiOsPrintf ("[AcpiExec] Global: Received a System Notify, Value 0x%2.2X\n", Value);
291 (void) AcpiEvaluateObject (Device, "_NOT", NULL, NULL);
295 /******************************************************************************
297 * FUNCTION: AeDeviceNotifyHandler
299 * PARAMETERS: Standard notify handler parameters
303 * DESCRIPTION: Device notify handler for AcpiExec utility. Used by the ASL
304 * test suite(s) to communicate errors and other information to
305 * this utility via the Notify() operator.
307 *****************************************************************************/
310 AeDeviceNotifyHandler (
316 printf ("[AcpiExec] Global: Received a Device Notify on [%4.4s] %p Value 0x%2.2X (%s)\n",
317 AcpiUtGetNodeName (Device), Device, Value,
318 AcpiUtGetNotifyName (Value, ACPI_TYPE_ANY));
319 if (AcpiGbl_DebugFile)
321 AcpiOsPrintf ("[AcpiExec] Global: Received a Device Notify, Value 0x%2.2X\n", Value);
324 (void) AcpiEvaluateObject (Device, "_NOT", NULL, NULL);
328 /******************************************************************************
330 * FUNCTION: AeExceptionHandler
332 * PARAMETERS: Standard exception handler parameters
336 * DESCRIPTION: System exception handler for AcpiExec utility.
338 *****************************************************************************/
342 ACPI_STATUS AmlStatus,
348 ACPI_STATUS NewAmlStatus = AmlStatus;
350 ACPI_BUFFER ReturnObj;
351 ACPI_OBJECT_LIST ArgList;
353 const char *Exception;
356 Exception = AcpiFormatException (AmlStatus);
357 AcpiOsPrintf ("[AcpiExec] Exception %s during execution ", Exception);
360 AcpiOsPrintf ("of method [%4.4s]", (char *) &Name);
364 AcpiOsPrintf ("at module level (table load)");
366 AcpiOsPrintf (" Opcode [%s] @%X\n", AcpiPsGetOpcodeName (Opcode), AmlOffset);
369 * Invoke the _ERR method if present
371 * Setup parameter object
374 ArgList.Pointer = Arg;
376 Arg[0].Type = ACPI_TYPE_INTEGER;
377 Arg[0].Integer.Value = AmlStatus;
379 Arg[1].Type = ACPI_TYPE_STRING;
380 Arg[1].String.Pointer = ACPI_CAST_PTR (char, Exception);
381 Arg[1].String.Length = strlen (Exception);
383 Arg[2].Type = ACPI_TYPE_INTEGER;
384 Arg[2].Integer.Value = AcpiOsGetThreadId();
386 /* Setup return buffer */
388 ReturnObj.Pointer = NULL;
389 ReturnObj.Length = ACPI_ALLOCATE_BUFFER;
391 Status = AcpiEvaluateObject (NULL, "\\_ERR", &ArgList, &ReturnObj);
392 if (ACPI_SUCCESS (Status))
394 if (ReturnObj.Pointer)
396 /* Override original status */
398 NewAmlStatus = (ACPI_STATUS)
399 ((ACPI_OBJECT *) ReturnObj.Pointer)->Integer.Value;
401 /* Free a buffer created via ACPI_ALLOCATE_BUFFER */
403 AcpiOsFree (ReturnObj.Pointer);
406 else if (Status != AE_NOT_FOUND)
408 AcpiOsPrintf ("[AcpiExec] Could not execute _ERR method, %s\n",
409 AcpiFormatException (Status));
412 /* Global override */
414 if (AcpiGbl_IgnoreErrors)
416 NewAmlStatus = AE_OK;
419 if (NewAmlStatus != AmlStatus)
421 AcpiOsPrintf ("[AcpiExec] Exception override, new status %s\n\n",
422 AcpiFormatException (NewAmlStatus));
425 return (NewAmlStatus);
429 /******************************************************************************
431 * FUNCTION: AeTableHandler
433 * PARAMETERS: Table handler
437 * DESCRIPTION: System table handler for AcpiExec utility.
439 *****************************************************************************/
447 #if (!ACPI_REDUCED_HARDWARE)
449 #endif /* !ACPI_REDUCED_HARDWARE */
452 if (Event > ACPI_NUM_TABLE_EVENTS)
454 Event = ACPI_NUM_TABLE_EVENTS;
457 #if (!ACPI_REDUCED_HARDWARE)
458 /* Enable any GPEs associated with newly-loaded GPE methods */
460 Status = AcpiUpdateAllGpes ();
461 AE_CHECK_OK (AcpiUpdateAllGpes, Status);
463 printf ("[AcpiExec] Table Event %s, [%4.4s] %p\n",
464 TableEvents[Event], ((ACPI_TABLE_HEADER *) Table)->Signature, Table);
465 #endif /* !ACPI_REDUCED_HARDWARE */
471 /******************************************************************************
473 * FUNCTION: AeGpeHandler
475 * DESCRIPTION: Common GPE handler for acpiexec
477 *****************************************************************************/
481 ACPI_HANDLE GpeDevice,
485 ACPI_NAMESPACE_NODE *DeviceNode = (ACPI_NAMESPACE_NODE *) GpeDevice;
488 AcpiOsPrintf ("[AcpiExec] GPE Handler received GPE %02X (GPE block %4.4s)\n",
489 GpeNumber, GpeDevice ? DeviceNode->Name.Ascii : "FADT");
491 return (ACPI_REENABLE_GPE);
495 /******************************************************************************
497 * FUNCTION: AeGlobalEventHandler
499 * DESCRIPTION: Global GPE/Fixed event handler
501 *****************************************************************************/
504 AeGlobalEventHandler (
515 case ACPI_EVENT_TYPE_GPE:
520 case ACPI_EVENT_TYPE_FIXED:
522 TypeName = "FixedEvent";
527 TypeName = "UNKNOWN";
531 AcpiOsPrintf ("[AcpiExec] Global Event Handler received: Type %s Number %.2X Dev %p\n",
532 TypeName, EventNumber, Device);
536 /******************************************************************************
538 * FUNCTION: AeAttachedDataHandler
540 * DESCRIPTION: Handler for deletion of nodes with attached data (attached via
543 *****************************************************************************/
546 AeAttachedDataHandler (
550 ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Data);
553 AcpiOsPrintf ("Received an attached data deletion (1) on %4.4s\n",
558 /******************************************************************************
560 * FUNCTION: AeAttachedDataHandler2
562 * DESCRIPTION: Handler for deletion of nodes with attached data (attached via
565 *****************************************************************************/
568 AeAttachedDataHandler2 (
572 ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Data);
575 AcpiOsPrintf ("Received an attached data deletion (2) on %4.4s\n",
580 /******************************************************************************
582 * FUNCTION: AeInterfaceHandler
584 * DESCRIPTION: Handler for _OSI invocations
586 *****************************************************************************/
590 ACPI_STRING InterfaceName,
593 ACPI_FUNCTION_NAME (AeInterfaceHandler);
596 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
597 "Received _OSI (\"%s\"), is %ssupported\n",
598 InterfaceName, Supported == 0 ? "not " : ""));
604 #if (!ACPI_REDUCED_HARDWARE)
605 /******************************************************************************
607 * FUNCTION: AeEventHandler, AeSciHandler
609 * DESCRIPTION: Handler for Fixed Events and SCIs
611 *****************************************************************************/
625 AcpiOsPrintf ("[AcpiExec] Received an SCI at handler\n");
629 #endif /* !ACPI_REDUCED_HARDWARE */
632 /*******************************************************************************
634 * FUNCTION: AeInstallSciHandler
640 * DESCRIPTION: Install handler for SCIs. Exercise the code by doing an
641 * install/remove/install.
643 ******************************************************************************/
646 AeInstallSciHandler (
652 Status = AcpiInstallSciHandler (AeSciHandler, &AeMyContext);
653 if (ACPI_FAILURE (Status))
655 ACPI_EXCEPTION ((AE_INFO, Status,
656 "Could not install an SCI handler (1)"));
659 Status = AcpiRemoveSciHandler (AeSciHandler);
660 if (ACPI_FAILURE (Status))
662 ACPI_EXCEPTION ((AE_INFO, Status,
663 "Could not remove an SCI handler"));
666 Status = AcpiInstallSciHandler (AeSciHandler, &AeMyContext);
667 if (ACPI_FAILURE (Status))
669 ACPI_EXCEPTION ((AE_INFO, Status,
670 "Could not install an SCI handler (2)"));
677 /******************************************************************************
679 * FUNCTION: AeInstallLateHandlers
685 * DESCRIPTION: Install handlers for the AcpiExec utility.
687 *****************************************************************************/
690 AeInstallLateHandlers (
696 #if (!ACPI_REDUCED_HARDWARE)
697 if (!AcpiGbl_ReducedHardware)
699 /* Install a user SCI handler */
701 Status = AeInstallSciHandler ();
702 AE_CHECK_OK (AeInstallSciHandler, Status);
704 /* Install some fixed event handlers */
706 Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL, AeEventHandler, NULL);
707 AE_CHECK_OK (AcpiInstallFixedEventHandler, Status);
709 Status = AcpiInstallFixedEventHandler (ACPI_EVENT_RTC, AeEventHandler, NULL);
710 AE_CHECK_OK (AcpiInstallFixedEventHandler, Status);
712 #endif /* !ACPI_REDUCED_HARDWARE */
714 AeMyContext.Connection = NULL;
715 AeMyContext.AccessLength = 0xA5;
718 * We will install a handler for each EC device, directly under the EC
719 * device definition. This is unlike the other handlers which we install
720 * at the root node. Also install memory and I/O handlers at any PCI
723 AeInstallDeviceHandlers ();
726 * Install handlers for some of the "device driver" address spaces
727 * such as SMBus, etc.
729 AeInstallRegionHandlers ();
734 /******************************************************************************
736 * FUNCTION: AeInstallEarlyHandlers
742 * DESCRIPTION: Install handlers for the AcpiExec utility.
744 * Notes: Don't install handler for PCI_Config, we want to use the
745 * default handler to exercise that code.
747 *****************************************************************************/
750 AeInstallEarlyHandlers (
757 ACPI_FUNCTION_ENTRY ();
760 Status = AcpiInstallInterfaceHandler (AeInterfaceHandler);
761 if (ACPI_FAILURE (Status))
763 printf ("Could not install interface handler, %s\n",
764 AcpiFormatException (Status));
767 Status = AcpiInstallTableHandler (AeTableHandler, NULL);
768 if (ACPI_FAILURE (Status))
770 printf ("Could not install table handler, %s\n",
771 AcpiFormatException (Status));
774 Status = AcpiInstallExceptionHandler (AeExceptionHandler);
775 if (ACPI_FAILURE (Status))
777 printf ("Could not install exception handler, %s\n",
778 AcpiFormatException (Status));
781 /* Install global notify handlers */
783 Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
784 AeSystemNotifyHandler, NULL);
785 if (ACPI_FAILURE (Status))
787 printf ("Could not install a global system notify handler, %s\n",
788 AcpiFormatException (Status));
791 Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_DEVICE_NOTIFY,
792 AeDeviceNotifyHandler, NULL);
793 if (ACPI_FAILURE (Status))
795 printf ("Could not install a global notify handler, %s\n",
796 AcpiFormatException (Status));
799 Status = AcpiGetHandle (NULL, "\\_SB", &Handle);
800 if (ACPI_SUCCESS (Status))
802 Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
803 AeNotifyHandler1, NULL);
804 if (ACPI_FAILURE (Status))
806 printf ("Could not install a notify handler, %s\n",
807 AcpiFormatException (Status));
810 Status = AcpiRemoveNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
812 if (ACPI_FAILURE (Status))
814 printf ("Could not remove a notify handler, %s\n",
815 AcpiFormatException (Status));
818 Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
819 AeNotifyHandler1, NULL);
820 AE_CHECK_OK (AcpiInstallNotifyHandler, Status);
822 Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY,
824 AE_CHECK_OK (AcpiRemoveNotifyHandler, Status);
827 Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
828 AeNotifyHandler1, NULL);
829 if (ACPI_FAILURE (Status))
831 printf ("Could not install a notify handler, %s\n",
832 AcpiFormatException (Status));
836 /* Install two handlers for _SB_ */
838 Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
839 AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567));
841 Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
842 AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF));
844 /* Attempt duplicate handler installation, should fail */
846 Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
847 AeNotifyHandler1, ACPI_CAST_PTR (void, 0x77777777));
849 Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle);
850 AE_CHECK_OK (AcpiAttachData, Status);
852 Status = AcpiDetachData (Handle, AeAttachedDataHandler);
853 AE_CHECK_OK (AcpiDetachData, Status);
855 /* Test attach data at the root object */
857 Status = AcpiAttachData (ACPI_ROOT_OBJECT, AeAttachedDataHandler,
859 AE_CHECK_OK (AcpiAttachData, Status);
861 Status = AcpiAttachData (ACPI_ROOT_OBJECT, AeAttachedDataHandler2,
863 AE_CHECK_OK (AcpiAttachData, Status);
865 /* Test support for multiple attaches */
867 Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle);
868 AE_CHECK_OK (AcpiAttachData, Status);
870 Status = AcpiAttachData (Handle, AeAttachedDataHandler2, Handle);
871 AE_CHECK_OK (AcpiAttachData, Status);
875 printf ("No _SB_ found, %s\n", AcpiFormatException (Status));
879 Status = AcpiGetHandle (NULL, "\\_TZ.TZ1", &Handle);
880 if (ACPI_SUCCESS (Status))
882 Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
883 AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567));
885 Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
886 AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF));
888 Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY,
890 Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY,
893 Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
894 AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF));
896 Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
897 AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567));
900 Status = AcpiGetHandle (NULL, "\\_PR.CPU0", &Handle);
901 if (ACPI_SUCCESS (Status))
903 Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY,
904 AeNotifyHandler1, ACPI_CAST_PTR (void, 0x01234567));
906 Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY,
907 AeNotifyHandler2, ACPI_CAST_PTR (void, 0x89ABCDEF));
911 * Install handlers that will override the default handlers for some of
914 AeOverrideRegionHandlers ();
917 * Initialize the global Region Handler space
920 AeRegions.NumberOfRegions = 0;
921 AeRegions.RegionList = NULL;