1 /******************************************************************************
3 * Module Name: evregion - ACPI AddressSpace (OpRegion) handler dispatch
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #define __EVREGION_C__
120 #include "accommon.h"
121 #include "acevents.h"
122 #include "acnamesp.h"
123 #include "acinterp.h"
125 #define _COMPONENT ACPI_EVENTS
126 ACPI_MODULE_NAME ("evregion")
129 /* Local prototypes */
132 AcpiEvHasDefaultHandler (
133 ACPI_NAMESPACE_NODE *Node,
134 ACPI_ADR_SPACE_TYPE SpaceId);
138 ACPI_HANDLE ObjHandle,
144 AcpiEvInstallHandler (
145 ACPI_HANDLE ObjHandle,
150 /* These are the address spaces that will get default handlers */
152 #define ACPI_NUM_DEFAULT_SPACES 4
154 static UINT8 AcpiGbl_DefaultAddressSpaces[ACPI_NUM_DEFAULT_SPACES] =
156 ACPI_ADR_SPACE_SYSTEM_MEMORY,
157 ACPI_ADR_SPACE_SYSTEM_IO,
158 ACPI_ADR_SPACE_PCI_CONFIG,
159 ACPI_ADR_SPACE_DATA_TABLE
163 /*******************************************************************************
165 * FUNCTION: AcpiEvInstallRegionHandlers
171 * DESCRIPTION: Installs the core subsystem default address space handlers.
173 ******************************************************************************/
176 AcpiEvInstallRegionHandlers (
183 ACPI_FUNCTION_TRACE (EvInstallRegionHandlers);
186 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
187 if (ACPI_FAILURE (Status))
189 return_ACPI_STATUS (Status);
193 * All address spaces (PCI Config, EC, SMBus) are scope dependent and
194 * registration must occur for a specific device.
196 * In the case of the system memory and IO address spaces there is
197 * currently no device associated with the address space. For these we
200 * We install the default PCI config space handler at the root so that
201 * this space is immediately available even though the we have not
202 * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
203 * specification which states that the PCI config space must be always
204 * available -- even though we are nowhere near ready to find the PCI root
205 * buses at this point.
207 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
208 * has already been installed (via AcpiInstallAddressSpaceHandler).
209 * Similar for AE_SAME_HANDLER.
211 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
213 Status = AcpiEvInstallSpaceHandler (AcpiGbl_RootNode,
214 AcpiGbl_DefaultAddressSpaces[i],
215 ACPI_DEFAULT_HANDLER, NULL, NULL);
219 case AE_SAME_HANDLER:
220 case AE_ALREADY_EXISTS:
222 /* These exceptions are all OK */
234 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
235 return_ACPI_STATUS (Status);
239 /*******************************************************************************
241 * FUNCTION: AcpiEvHasDefaultHandler
243 * PARAMETERS: Node - Namespace node for the device
244 * SpaceId - The address space ID
246 * RETURN: TRUE if default handler is installed, FALSE otherwise
248 * DESCRIPTION: Check if the default handler is installed for the requested
251 ******************************************************************************/
254 AcpiEvHasDefaultHandler (
255 ACPI_NAMESPACE_NODE *Node,
256 ACPI_ADR_SPACE_TYPE SpaceId)
258 ACPI_OPERAND_OBJECT *ObjDesc;
259 ACPI_OPERAND_OBJECT *HandlerObj;
262 /* Must have an existing internal object */
264 ObjDesc = AcpiNsGetAttachedObject (Node);
267 HandlerObj = ObjDesc->Device.Handler;
269 /* Walk the linked list of handlers for this object */
273 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
275 if (HandlerObj->AddressSpace.HandlerFlags &
276 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
282 HandlerObj = HandlerObj->AddressSpace.Next;
290 /*******************************************************************************
292 * FUNCTION: AcpiEvInitializeOpRegions
298 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
299 * an installed default region handler.
301 ******************************************************************************/
304 AcpiEvInitializeOpRegions (
311 ACPI_FUNCTION_TRACE (EvInitializeOpRegions);
314 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
315 if (ACPI_FAILURE (Status))
317 return_ACPI_STATUS (Status);
320 /* Run the _REG methods for OpRegions in each default address space */
322 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
325 * Make sure the installed handler is the DEFAULT handler. If not the
326 * default, the _REG methods will have already been run (when the
327 * handler was installed)
329 if (AcpiEvHasDefaultHandler (AcpiGbl_RootNode,
330 AcpiGbl_DefaultAddressSpaces[i]))
332 Status = AcpiEvExecuteRegMethods (AcpiGbl_RootNode,
333 AcpiGbl_DefaultAddressSpaces[i]);
337 AcpiGbl_RegMethodsExecuted = TRUE;
339 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
340 return_ACPI_STATUS (Status);
344 /*******************************************************************************
346 * FUNCTION: AcpiEvExecuteRegMethod
348 * PARAMETERS: RegionObj - Region object
349 * Function - Passed to _REG: On (1) or Off (0)
353 * DESCRIPTION: Execute _REG method for a region
355 ******************************************************************************/
358 AcpiEvExecuteRegMethod (
359 ACPI_OPERAND_OBJECT *RegionObj,
362 ACPI_EVALUATE_INFO *Info;
363 ACPI_OPERAND_OBJECT *Args[3];
364 ACPI_OPERAND_OBJECT *RegionObj2;
368 ACPI_FUNCTION_TRACE (EvExecuteRegMethod);
371 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
374 return_ACPI_STATUS (AE_NOT_EXIST);
377 if (RegionObj2->Extra.Method_REG == NULL)
379 return_ACPI_STATUS (AE_OK);
382 /* Allocate and initialize the evaluation information block */
384 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
387 return_ACPI_STATUS (AE_NO_MEMORY);
390 Info->PrefixNode = RegionObj2->Extra.Method_REG;
391 Info->Pathname = NULL;
392 Info->Parameters = Args;
393 Info->Flags = ACPI_IGNORE_RETURN_VALUE;
396 * The _REG method has two arguments:
399 * Operation region space ID Same value as RegionObj->Region.SpaceId
402 * connection status 1 for connecting the handler, 0 for disconnecting
403 * the handler (Passed as a parameter)
405 Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId);
408 Status = AE_NO_MEMORY;
412 Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function);
415 Status = AE_NO_MEMORY;
419 Args[2] = NULL; /* Terminate list */
421 /* Execute the method, no return value */
424 AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL));
426 Status = AcpiNsEvaluate (Info);
427 AcpiUtRemoveReference (Args[1]);
430 AcpiUtRemoveReference (Args[0]);
434 return_ACPI_STATUS (Status);
438 /*******************************************************************************
440 * FUNCTION: AcpiEvAddressSpaceDispatch
442 * PARAMETERS: RegionObj - Internal region object
443 * Function - Read or Write operation
444 * RegionOffset - Where in the region to read or write
445 * BitWidth - Field width in bits (8, 16, 32, or 64)
446 * Value - Pointer to in or out value, must be
447 * a full 64-bit integer
451 * DESCRIPTION: Dispatch an address space or operation region access to
452 * a previously installed handler.
454 ******************************************************************************/
457 AcpiEvAddressSpaceDispatch (
458 ACPI_OPERAND_OBJECT *RegionObj,
465 ACPI_ADR_SPACE_HANDLER Handler;
466 ACPI_ADR_SPACE_SETUP RegionSetup;
467 ACPI_OPERAND_OBJECT *HandlerDesc;
468 ACPI_OPERAND_OBJECT *RegionObj2;
469 void *RegionContext = NULL;
472 ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch);
475 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
478 return_ACPI_STATUS (AE_NOT_EXIST);
481 /* Ensure that there is a handler associated with this region */
483 HandlerDesc = RegionObj->Region.Handler;
486 ACPI_ERROR ((AE_INFO,
487 "No handler for Region [%4.4s] (%p) [%s]",
488 AcpiUtGetNodeName (RegionObj->Region.Node),
489 RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
491 return_ACPI_STATUS (AE_NOT_EXIST);
495 * It may be the case that the region has never been initialized.
496 * Some types of regions require special init code
498 if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
500 /* This region has not been initialized yet, do it */
502 RegionSetup = HandlerDesc->AddressSpace.Setup;
505 /* No initialization routine, exit with error */
507 ACPI_ERROR ((AE_INFO,
508 "No init routine for region(%p) [%s]",
509 RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
510 return_ACPI_STATUS (AE_NOT_EXIST);
514 * We must exit the interpreter because the region setup will
515 * potentially execute control methods (for example, the _REG method
518 AcpiExExitInterpreter ();
520 Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE,
521 HandlerDesc->AddressSpace.Context, &RegionContext);
523 /* Re-enter the interpreter */
525 AcpiExEnterInterpreter ();
527 /* Check for failure of the Region Setup */
529 if (ACPI_FAILURE (Status))
531 ACPI_EXCEPTION ((AE_INFO, Status,
532 "During region initialization: [%s]",
533 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
534 return_ACPI_STATUS (Status);
537 /* Region initialization may have been completed by RegionSetup */
539 if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
541 RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE;
543 if (RegionObj2->Extra.RegionContext)
545 /* The handler for this region was already installed */
547 ACPI_FREE (RegionContext);
552 * Save the returned context for use in all accesses to
553 * this particular region
555 RegionObj2->Extra.RegionContext = RegionContext;
560 /* We have everything we need, we can invoke the address space handler */
562 Handler = HandlerDesc->AddressSpace.Handler;
564 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
565 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
566 &RegionObj->Region.Handler->AddressSpace, Handler,
567 ACPI_FORMAT_NATIVE_UINT (RegionObj->Region.Address + RegionOffset),
568 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
570 if (!(HandlerDesc->AddressSpace.HandlerFlags &
571 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
574 * For handlers other than the default (supplied) handlers, we must
575 * exit the interpreter because the handler *might* block -- we don't
576 * know what it will do, so we can't hold the lock on the intepreter.
578 AcpiExExitInterpreter();
581 /* Call the handler */
583 Status = Handler (Function,
584 (RegionObj->Region.Address + RegionOffset), BitWidth, Value,
585 HandlerDesc->AddressSpace.Context, RegionObj2->Extra.RegionContext);
587 if (ACPI_FAILURE (Status))
589 ACPI_EXCEPTION ((AE_INFO, Status, "Returned by Handler for [%s]",
590 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
593 if (!(HandlerDesc->AddressSpace.HandlerFlags &
594 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
597 * We just returned from a non-default handler, we must re-enter the
600 AcpiExEnterInterpreter ();
603 return_ACPI_STATUS (Status);
607 /*******************************************************************************
609 * FUNCTION: AcpiEvDetachRegion
611 * PARAMETERS: RegionObj - Region Object
612 * AcpiNsIsLocked - Namespace Region Already Locked?
616 * DESCRIPTION: Break the association between the handler and the region
617 * this is a two way association.
619 ******************************************************************************/
623 ACPI_OPERAND_OBJECT *RegionObj,
624 BOOLEAN AcpiNsIsLocked)
626 ACPI_OPERAND_OBJECT *HandlerObj;
627 ACPI_OPERAND_OBJECT *ObjDesc;
628 ACPI_OPERAND_OBJECT **LastObjPtr;
629 ACPI_ADR_SPACE_SETUP RegionSetup;
630 void **RegionContext;
631 ACPI_OPERAND_OBJECT *RegionObj2;
635 ACPI_FUNCTION_TRACE (EvDetachRegion);
638 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
643 RegionContext = &RegionObj2->Extra.RegionContext;
645 /* Get the address handler from the region object */
647 HandlerObj = RegionObj->Region.Handler;
650 /* This region has no handler, all done */
655 /* Find this region in the handler's list */
657 ObjDesc = HandlerObj->AddressSpace.RegionList;
658 LastObjPtr = &HandlerObj->AddressSpace.RegionList;
662 /* Is this the correct Region? */
664 if (ObjDesc == RegionObj)
666 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
667 "Removing Region %p from address handler %p\n",
668 RegionObj, HandlerObj));
670 /* This is it, remove it from the handler's list */
672 *LastObjPtr = ObjDesc->Region.Next;
673 ObjDesc->Region.Next = NULL; /* Must clear field */
677 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
678 if (ACPI_FAILURE (Status))
684 /* Now stop region accesses by executing the _REG method */
686 Status = AcpiEvExecuteRegMethod (RegionObj, 0);
687 if (ACPI_FAILURE (Status))
689 ACPI_EXCEPTION ((AE_INFO, Status, "from region _REG, [%s]",
690 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
695 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
696 if (ACPI_FAILURE (Status))
703 * If the region has been activated, call the setup handler with
704 * the deactivate notification
706 if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
708 RegionSetup = HandlerObj->AddressSpace.Setup;
709 Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE,
710 HandlerObj->AddressSpace.Context, RegionContext);
712 /* Init routine may fail, Just ignore errors */
714 if (ACPI_FAILURE (Status))
716 ACPI_EXCEPTION ((AE_INFO, Status,
717 "from region handler - deactivate, [%s]",
718 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
721 RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
725 * Remove handler reference in the region
727 * NOTE: this doesn't mean that the region goes away, the region
728 * is just inaccessible as indicated to the _REG method
730 * If the region is on the handler's list, this must be the
733 RegionObj->Region.Handler = NULL;
734 AcpiUtRemoveReference (HandlerObj);
739 /* Walk the linked list of handlers */
741 LastObjPtr = &ObjDesc->Region.Next;
742 ObjDesc = ObjDesc->Region.Next;
745 /* If we get here, the region was not in the handler's region list */
747 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
748 "Cannot remove region %p from address handler %p\n",
749 RegionObj, HandlerObj));
755 /*******************************************************************************
757 * FUNCTION: AcpiEvAttachRegion
759 * PARAMETERS: HandlerObj - Handler Object
760 * RegionObj - Region Object
761 * AcpiNsIsLocked - Namespace Region Already Locked?
765 * DESCRIPTION: Create the association between the handler and the region
766 * this is a two way association.
768 ******************************************************************************/
772 ACPI_OPERAND_OBJECT *HandlerObj,
773 ACPI_OPERAND_OBJECT *RegionObj,
774 BOOLEAN AcpiNsIsLocked)
777 ACPI_FUNCTION_TRACE (EvAttachRegion);
780 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
781 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
782 AcpiUtGetNodeName (RegionObj->Region.Node),
783 RegionObj, HandlerObj,
784 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
786 /* Link this region to the front of the handler's list */
788 RegionObj->Region.Next = HandlerObj->AddressSpace.RegionList;
789 HandlerObj->AddressSpace.RegionList = RegionObj;
791 /* Install the region's handler */
793 if (RegionObj->Region.Handler)
795 return_ACPI_STATUS (AE_ALREADY_EXISTS);
798 RegionObj->Region.Handler = HandlerObj;
799 AcpiUtAddReference (HandlerObj);
801 return_ACPI_STATUS (AE_OK);
805 /*******************************************************************************
807 * FUNCTION: AcpiEvInstallHandler
809 * PARAMETERS: WalkNamespace callback
811 * DESCRIPTION: This routine installs an address handler into objects that are
812 * of type Region or Device.
814 * If the Object is a Device, and the device has a handler of
815 * the same type then the search is terminated in that branch.
817 * This is because the existing handler is closer in proximity
818 * to any more regions than the one we are trying to install.
820 ******************************************************************************/
823 AcpiEvInstallHandler (
824 ACPI_HANDLE ObjHandle,
829 ACPI_OPERAND_OBJECT *HandlerObj;
830 ACPI_OPERAND_OBJECT *NextHandlerObj;
831 ACPI_OPERAND_OBJECT *ObjDesc;
832 ACPI_NAMESPACE_NODE *Node;
836 ACPI_FUNCTION_NAME (EvInstallHandler);
839 HandlerObj = (ACPI_OPERAND_OBJECT *) Context;
841 /* Parameter validation */
848 /* Convert and validate the device handle */
850 Node = AcpiNsValidateHandle (ObjHandle);
853 return (AE_BAD_PARAMETER);
857 * We only care about regions and objects that are allowed to have
858 * address space handlers
860 if ((Node->Type != ACPI_TYPE_DEVICE) &&
861 (Node->Type != ACPI_TYPE_REGION) &&
862 (Node != AcpiGbl_RootNode))
867 /* Check for an existing internal object */
869 ObjDesc = AcpiNsGetAttachedObject (Node);
872 /* No object, just exit */
877 /* Devices are handled different than regions */
879 if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE)
881 /* Check if this Device already has a handler for this address space */
883 NextHandlerObj = ObjDesc->Device.Handler;
884 while (NextHandlerObj)
886 /* Found a handler, is it for the same address space? */
888 if (NextHandlerObj->AddressSpace.SpaceId ==
889 HandlerObj->AddressSpace.SpaceId)
891 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
892 "Found handler for region [%s] in device %p(%p) "
894 AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId),
895 ObjDesc, NextHandlerObj, HandlerObj));
898 * Since the object we found it on was a device, then it
899 * means that someone has already installed a handler for
900 * the branch of the namespace from this device on. Just
901 * bail out telling the walk routine to not traverse this
902 * branch. This preserves the scoping rule for handlers.
904 return (AE_CTRL_DEPTH);
907 /* Walk the linked list of handlers attached to this device */
909 NextHandlerObj = NextHandlerObj->AddressSpace.Next;
913 * As long as the device didn't have a handler for this space we
914 * don't care about it. We just ignore it and proceed.
919 /* Object is a Region */
921 if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId)
923 /* This region is for a different address space, just ignore it */
929 * Now we have a region and it is for the handler's address space type.
931 * First disconnect region for any previous handler (if any)
933 AcpiEvDetachRegion (ObjDesc, FALSE);
935 /* Connect the region to the new handler */
937 Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
942 /*******************************************************************************
944 * FUNCTION: AcpiEvInstallSpaceHandler
946 * PARAMETERS: Node - Namespace node for the device
947 * SpaceId - The address space ID
948 * Handler - Address of the handler
949 * Setup - Address of the setup function
950 * Context - Value passed to the handler on each access
954 * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
955 * Assumes namespace is locked
957 ******************************************************************************/
960 AcpiEvInstallSpaceHandler (
961 ACPI_NAMESPACE_NODE *Node,
962 ACPI_ADR_SPACE_TYPE SpaceId,
963 ACPI_ADR_SPACE_HANDLER Handler,
964 ACPI_ADR_SPACE_SETUP Setup,
967 ACPI_OPERAND_OBJECT *ObjDesc;
968 ACPI_OPERAND_OBJECT *HandlerObj;
970 ACPI_OBJECT_TYPE Type;
974 ACPI_FUNCTION_TRACE (EvInstallSpaceHandler);
978 * This registration is valid for only the types below and the root. This
979 * is where the default handlers get placed.
981 if ((Node->Type != ACPI_TYPE_DEVICE) &&
982 (Node->Type != ACPI_TYPE_PROCESSOR) &&
983 (Node->Type != ACPI_TYPE_THERMAL) &&
984 (Node != AcpiGbl_RootNode))
986 Status = AE_BAD_PARAMETER;
990 if (Handler == ACPI_DEFAULT_HANDLER)
992 Flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
996 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
997 Handler = AcpiExSystemMemorySpaceHandler;
998 Setup = AcpiEvSystemMemoryRegionSetup;
1001 case ACPI_ADR_SPACE_SYSTEM_IO:
1002 Handler = AcpiExSystemIoSpaceHandler;
1003 Setup = AcpiEvIoSpaceRegionSetup;
1006 case ACPI_ADR_SPACE_PCI_CONFIG:
1007 Handler = AcpiExPciConfigSpaceHandler;
1008 Setup = AcpiEvPciConfigRegionSetup;
1011 case ACPI_ADR_SPACE_CMOS:
1012 Handler = AcpiExCmosSpaceHandler;
1013 Setup = AcpiEvCmosRegionSetup;
1016 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
1017 Handler = AcpiExPciBarSpaceHandler;
1018 Setup = AcpiEvPciBarRegionSetup;
1021 case ACPI_ADR_SPACE_DATA_TABLE:
1022 Handler = AcpiExDataTableSpaceHandler;
1027 Status = AE_BAD_PARAMETER;
1032 /* If the caller hasn't specified a setup routine, use the default */
1036 Setup = AcpiEvDefaultRegionSetup;
1039 /* Check for an existing internal object */
1041 ObjDesc = AcpiNsGetAttachedObject (Node);
1045 * The attached device object already exists. Make sure the handler
1046 * is not already installed.
1048 HandlerObj = ObjDesc->Device.Handler;
1050 /* Walk the handler list for this device */
1054 /* Same SpaceId indicates a handler already installed */
1056 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
1058 if (HandlerObj->AddressSpace.Handler == Handler)
1061 * It is (relatively) OK to attempt to install the SAME
1062 * handler twice. This can easily happen with the
1065 Status = AE_SAME_HANDLER;
1070 /* A handler is already installed */
1072 Status = AE_ALREADY_EXISTS;
1077 /* Walk the linked list of handlers */
1079 HandlerObj = HandlerObj->AddressSpace.Next;
1084 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
1085 "Creating object on Device %p while installing handler\n", Node));
1087 /* ObjDesc does not exist, create one */
1089 if (Node->Type == ACPI_TYPE_ANY)
1091 Type = ACPI_TYPE_DEVICE;
1098 ObjDesc = AcpiUtCreateInternalObject (Type);
1101 Status = AE_NO_MEMORY;
1105 /* Init new descriptor */
1107 ObjDesc->Common.Type = (UINT8) Type;
1109 /* Attach the new object to the Node */
1111 Status = AcpiNsAttachObject (Node, ObjDesc, Type);
1113 /* Remove local reference to the object */
1115 AcpiUtRemoveReference (ObjDesc);
1117 if (ACPI_FAILURE (Status))
1123 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
1124 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
1125 AcpiUtGetRegionName (SpaceId), SpaceId,
1126 AcpiUtGetNodeName (Node), Node, ObjDesc));
1129 * Install the handler
1131 * At this point there is no existing handler. Just allocate the object
1132 * for the handler and link it into the list.
1134 HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
1137 Status = AE_NO_MEMORY;
1141 /* Init handler obj */
1143 HandlerObj->AddressSpace.SpaceId = (UINT8) SpaceId;
1144 HandlerObj->AddressSpace.HandlerFlags = Flags;
1145 HandlerObj->AddressSpace.RegionList = NULL;
1146 HandlerObj->AddressSpace.Node = Node;
1147 HandlerObj->AddressSpace.Handler = Handler;
1148 HandlerObj->AddressSpace.Context = Context;
1149 HandlerObj->AddressSpace.Setup = Setup;
1151 /* Install at head of Device.AddressSpace list */
1153 HandlerObj->AddressSpace.Next = ObjDesc->Device.Handler;
1156 * The Device object is the first reference on the HandlerObj.
1157 * Each region that uses the handler adds a reference.
1159 ObjDesc->Device.Handler = HandlerObj;
1162 * Walk the namespace finding all of the regions this
1163 * handler will manage.
1165 * Start at the device and search the branch toward
1166 * the leaf nodes until either the leaf is encountered or
1167 * a device is detected that has an address handler of the
1170 * In either case, back up and search down the remainder
1173 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
1174 ACPI_NS_WALK_UNLOCK, AcpiEvInstallHandler, NULL,
1178 return_ACPI_STATUS (Status);
1182 /*******************************************************************************
1184 * FUNCTION: AcpiEvExecuteRegMethods
1186 * PARAMETERS: Node - Namespace node for the device
1187 * SpaceId - The address space ID
1191 * DESCRIPTION: Run all _REG methods for the input Space ID;
1192 * Note: assumes namespace is locked, or system init time.
1194 ******************************************************************************/
1197 AcpiEvExecuteRegMethods (
1198 ACPI_NAMESPACE_NODE *Node,
1199 ACPI_ADR_SPACE_TYPE SpaceId)
1204 ACPI_FUNCTION_TRACE (EvExecuteRegMethods);
1208 * Run all _REG methods for all Operation Regions for this space ID. This
1209 * is a separate walk in order to handle any interdependencies between
1210 * regions and _REG methods. (i.e. handlers must be installed for all
1211 * regions of this Space ID before we can run any _REG methods)
1213 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
1214 ACPI_NS_WALK_UNLOCK, AcpiEvRegRun, NULL,
1217 return_ACPI_STATUS (Status);
1221 /*******************************************************************************
1223 * FUNCTION: AcpiEvRegRun
1225 * PARAMETERS: WalkNamespace callback
1227 * DESCRIPTION: Run _REG method for region objects of the requested spaceID
1229 ******************************************************************************/
1233 ACPI_HANDLE ObjHandle,
1238 ACPI_OPERAND_OBJECT *ObjDesc;
1239 ACPI_NAMESPACE_NODE *Node;
1240 ACPI_ADR_SPACE_TYPE SpaceId;
1244 SpaceId = *ACPI_CAST_PTR (ACPI_ADR_SPACE_TYPE, Context);
1246 /* Convert and validate the device handle */
1248 Node = AcpiNsValidateHandle (ObjHandle);
1251 return (AE_BAD_PARAMETER);
1255 * We only care about regions.and objects that are allowed to have address
1258 if ((Node->Type != ACPI_TYPE_REGION) &&
1259 (Node != AcpiGbl_RootNode))
1264 /* Check for an existing internal object */
1266 ObjDesc = AcpiNsGetAttachedObject (Node);
1269 /* No object, just exit */
1274 /* Object is a Region */
1276 if (ObjDesc->Region.SpaceId != SpaceId)
1278 /* This region is for a different address space, just ignore it */
1283 Status = AcpiEvExecuteRegMethod (ObjDesc, 1);