1 /******************************************************************************
3 * Module Name: evregion - ACPI AddressSpace (OpRegion) handler dispatch
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2010, 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 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
338 return_ACPI_STATUS (Status
);
342 /*******************************************************************************
344 * FUNCTION: AcpiEvExecuteRegMethod
346 * PARAMETERS: RegionObj - Region object
347 * Function - Passed to _REG: On (1) or Off (0)
351 * DESCRIPTION: Execute _REG method for a region
353 ******************************************************************************/
356 AcpiEvExecuteRegMethod (
357 ACPI_OPERAND_OBJECT
*RegionObj
,
360 ACPI_EVALUATE_INFO
*Info
;
361 ACPI_OPERAND_OBJECT
*Args
[3];
362 ACPI_OPERAND_OBJECT
*RegionObj2
;
366 ACPI_FUNCTION_TRACE (EvExecuteRegMethod
);
369 RegionObj2
= AcpiNsGetSecondaryObject (RegionObj
);
372 return_ACPI_STATUS (AE_NOT_EXIST
);
375 if (RegionObj2
->Extra
.Method_REG
== NULL
)
377 return_ACPI_STATUS (AE_OK
);
380 /* Allocate and initialize the evaluation information block */
382 Info
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO
));
385 return_ACPI_STATUS (AE_NO_MEMORY
);
388 Info
->PrefixNode
= RegionObj2
->Extra
.Method_REG
;
389 Info
->Pathname
= NULL
;
390 Info
->Parameters
= Args
;
391 Info
->Flags
= ACPI_IGNORE_RETURN_VALUE
;
394 * The _REG method has two arguments:
397 * Operation region space ID Same value as RegionObj->Region.SpaceId
400 * connection status 1 for connecting the handler, 0 for disconnecting
401 * the handler (Passed as a parameter)
403 Args
[0] = AcpiUtCreateIntegerObject ((UINT64
) RegionObj
->Region
.SpaceId
);
406 Status
= AE_NO_MEMORY
;
410 Args
[1] = AcpiUtCreateIntegerObject ((UINT64
) Function
);
413 Status
= AE_NO_MEMORY
;
417 Args
[2] = NULL
; /* Terminate list */
419 /* Execute the method, no return value */
422 AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD
, Info
->PrefixNode
, NULL
));
424 Status
= AcpiNsEvaluate (Info
);
425 AcpiUtRemoveReference (Args
[1]);
428 AcpiUtRemoveReference (Args
[0]);
432 return_ACPI_STATUS (Status
);
436 /*******************************************************************************
438 * FUNCTION: AcpiEvAddressSpaceDispatch
440 * PARAMETERS: RegionObj - Internal region object
441 * Function - Read or Write operation
442 * RegionOffset - Where in the region to read or write
443 * BitWidth - Field width in bits (8, 16, 32, or 64)
444 * Value - Pointer to in or out value, must be
445 * a full 64-bit integer
449 * DESCRIPTION: Dispatch an address space or operation region access to
450 * a previously installed handler.
452 ******************************************************************************/
455 AcpiEvAddressSpaceDispatch (
456 ACPI_OPERAND_OBJECT
*RegionObj
,
463 ACPI_ADR_SPACE_HANDLER Handler
;
464 ACPI_ADR_SPACE_SETUP RegionSetup
;
465 ACPI_OPERAND_OBJECT
*HandlerDesc
;
466 ACPI_OPERAND_OBJECT
*RegionObj2
;
467 void *RegionContext
= NULL
;
470 ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch
);
473 RegionObj2
= AcpiNsGetSecondaryObject (RegionObj
);
476 return_ACPI_STATUS (AE_NOT_EXIST
);
479 /* Ensure that there is a handler associated with this region */
481 HandlerDesc
= RegionObj
->Region
.Handler
;
484 ACPI_ERROR ((AE_INFO
,
485 "No handler for Region [%4.4s] (%p) [%s]",
486 AcpiUtGetNodeName (RegionObj
->Region
.Node
),
487 RegionObj
, AcpiUtGetRegionName (RegionObj
->Region
.SpaceId
)));
489 return_ACPI_STATUS (AE_NOT_EXIST
);
493 * It may be the case that the region has never been initialized.
494 * Some types of regions require special init code
496 if (!(RegionObj
->Region
.Flags
& AOPOBJ_SETUP_COMPLETE
))
498 /* This region has not been initialized yet, do it */
500 RegionSetup
= HandlerDesc
->AddressSpace
.Setup
;
503 /* No initialization routine, exit with error */
505 ACPI_ERROR ((AE_INFO
,
506 "No init routine for region(%p) [%s]",
507 RegionObj
, AcpiUtGetRegionName (RegionObj
->Region
.SpaceId
)));
508 return_ACPI_STATUS (AE_NOT_EXIST
);
512 * We must exit the interpreter because the region setup will
513 * potentially execute control methods (for example, the _REG method
516 AcpiExExitInterpreter ();
518 Status
= RegionSetup (RegionObj
, ACPI_REGION_ACTIVATE
,
519 HandlerDesc
->AddressSpace
.Context
, &RegionContext
);
521 /* Re-enter the interpreter */
523 AcpiExEnterInterpreter ();
525 /* Check for failure of the Region Setup */
527 if (ACPI_FAILURE (Status
))
529 ACPI_EXCEPTION ((AE_INFO
, Status
,
530 "During region initialization: [%s]",
531 AcpiUtGetRegionName (RegionObj
->Region
.SpaceId
)));
532 return_ACPI_STATUS (Status
);
535 /* Region initialization may have been completed by RegionSetup */
537 if (!(RegionObj
->Region
.Flags
& AOPOBJ_SETUP_COMPLETE
))
539 RegionObj
->Region
.Flags
|= AOPOBJ_SETUP_COMPLETE
;
541 if (RegionObj2
->Extra
.RegionContext
)
543 /* The handler for this region was already installed */
545 ACPI_FREE (RegionContext
);
550 * Save the returned context for use in all accesses to
551 * this particular region
553 RegionObj2
->Extra
.RegionContext
= RegionContext
;
558 /* We have everything we need, we can invoke the address space handler */
560 Handler
= HandlerDesc
->AddressSpace
.Handler
;
562 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
563 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
564 &RegionObj
->Region
.Handler
->AddressSpace
, Handler
,
565 ACPI_FORMAT_NATIVE_UINT (RegionObj
->Region
.Address
+ RegionOffset
),
566 AcpiUtGetRegionName (RegionObj
->Region
.SpaceId
)));
568 if (!(HandlerDesc
->AddressSpace
.HandlerFlags
&
569 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED
))
572 * For handlers other than the default (supplied) handlers, we must
573 * exit the interpreter because the handler *might* block -- we don't
574 * know what it will do, so we can't hold the lock on the intepreter.
576 AcpiExExitInterpreter();
579 /* Call the handler */
581 Status
= Handler (Function
,
582 (RegionObj
->Region
.Address
+ RegionOffset
), BitWidth
, Value
,
583 HandlerDesc
->AddressSpace
.Context
, RegionObj2
->Extra
.RegionContext
);
585 if (ACPI_FAILURE (Status
))
587 ACPI_EXCEPTION ((AE_INFO
, Status
, "Returned by Handler for [%s]",
588 AcpiUtGetRegionName (RegionObj
->Region
.SpaceId
)));
591 if (!(HandlerDesc
->AddressSpace
.HandlerFlags
&
592 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED
))
595 * We just returned from a non-default handler, we must re-enter the
598 AcpiExEnterInterpreter ();
601 return_ACPI_STATUS (Status
);
605 /*******************************************************************************
607 * FUNCTION: AcpiEvDetachRegion
609 * PARAMETERS: RegionObj - Region Object
610 * AcpiNsIsLocked - Namespace Region Already Locked?
614 * DESCRIPTION: Break the association between the handler and the region
615 * this is a two way association.
617 ******************************************************************************/
621 ACPI_OPERAND_OBJECT
*RegionObj
,
622 BOOLEAN AcpiNsIsLocked
)
624 ACPI_OPERAND_OBJECT
*HandlerObj
;
625 ACPI_OPERAND_OBJECT
*ObjDesc
;
626 ACPI_OPERAND_OBJECT
**LastObjPtr
;
627 ACPI_ADR_SPACE_SETUP RegionSetup
;
628 void **RegionContext
;
629 ACPI_OPERAND_OBJECT
*RegionObj2
;
633 ACPI_FUNCTION_TRACE (EvDetachRegion
);
636 RegionObj2
= AcpiNsGetSecondaryObject (RegionObj
);
641 RegionContext
= &RegionObj2
->Extra
.RegionContext
;
643 /* Get the address handler from the region object */
645 HandlerObj
= RegionObj
->Region
.Handler
;
648 /* This region has no handler, all done */
653 /* Find this region in the handler's list */
655 ObjDesc
= HandlerObj
->AddressSpace
.RegionList
;
656 LastObjPtr
= &HandlerObj
->AddressSpace
.RegionList
;
660 /* Is this the correct Region? */
662 if (ObjDesc
== RegionObj
)
664 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
665 "Removing Region %p from address handler %p\n",
666 RegionObj
, HandlerObj
));
668 /* This is it, remove it from the handler's list */
670 *LastObjPtr
= ObjDesc
->Region
.Next
;
671 ObjDesc
->Region
.Next
= NULL
; /* Must clear field */
675 Status
= AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
676 if (ACPI_FAILURE (Status
))
682 /* Now stop region accesses by executing the _REG method */
684 Status
= AcpiEvExecuteRegMethod (RegionObj
, 0);
685 if (ACPI_FAILURE (Status
))
687 ACPI_EXCEPTION ((AE_INFO
, Status
, "from region _REG, [%s]",
688 AcpiUtGetRegionName (RegionObj
->Region
.SpaceId
)));
693 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
694 if (ACPI_FAILURE (Status
))
701 * If the region has been activated, call the setup handler with
702 * the deactivate notification
704 if (RegionObj
->Region
.Flags
& AOPOBJ_SETUP_COMPLETE
)
706 RegionSetup
= HandlerObj
->AddressSpace
.Setup
;
707 Status
= RegionSetup (RegionObj
, ACPI_REGION_DEACTIVATE
,
708 HandlerObj
->AddressSpace
.Context
, RegionContext
);
710 /* Init routine may fail, Just ignore errors */
712 if (ACPI_FAILURE (Status
))
714 ACPI_EXCEPTION ((AE_INFO
, Status
,
715 "from region handler - deactivate, [%s]",
716 AcpiUtGetRegionName (RegionObj
->Region
.SpaceId
)));
719 RegionObj
->Region
.Flags
&= ~(AOPOBJ_SETUP_COMPLETE
);
723 * Remove handler reference in the region
725 * NOTE: this doesn't mean that the region goes away, the region
726 * is just inaccessible as indicated to the _REG method
728 * If the region is on the handler's list, this must be the
731 RegionObj
->Region
.Handler
= NULL
;
732 AcpiUtRemoveReference (HandlerObj
);
737 /* Walk the linked list of handlers */
739 LastObjPtr
= &ObjDesc
->Region
.Next
;
740 ObjDesc
= ObjDesc
->Region
.Next
;
743 /* If we get here, the region was not in the handler's region list */
745 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
746 "Cannot remove region %p from address handler %p\n",
747 RegionObj
, HandlerObj
));
753 /*******************************************************************************
755 * FUNCTION: AcpiEvAttachRegion
757 * PARAMETERS: HandlerObj - Handler Object
758 * RegionObj - Region Object
759 * AcpiNsIsLocked - Namespace Region Already Locked?
763 * DESCRIPTION: Create the association between the handler and the region
764 * this is a two way association.
766 ******************************************************************************/
770 ACPI_OPERAND_OBJECT
*HandlerObj
,
771 ACPI_OPERAND_OBJECT
*RegionObj
,
772 BOOLEAN AcpiNsIsLocked
)
775 ACPI_FUNCTION_TRACE (EvAttachRegion
);
778 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
779 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
780 AcpiUtGetNodeName (RegionObj
->Region
.Node
),
781 RegionObj
, HandlerObj
,
782 AcpiUtGetRegionName (RegionObj
->Region
.SpaceId
)));
784 /* Link this region to the front of the handler's list */
786 RegionObj
->Region
.Next
= HandlerObj
->AddressSpace
.RegionList
;
787 HandlerObj
->AddressSpace
.RegionList
= RegionObj
;
789 /* Install the region's handler */
791 if (RegionObj
->Region
.Handler
)
793 return_ACPI_STATUS (AE_ALREADY_EXISTS
);
796 RegionObj
->Region
.Handler
= HandlerObj
;
797 AcpiUtAddReference (HandlerObj
);
799 return_ACPI_STATUS (AE_OK
);
803 /*******************************************************************************
805 * FUNCTION: AcpiEvInstallHandler
807 * PARAMETERS: WalkNamespace callback
809 * DESCRIPTION: This routine installs an address handler into objects that are
810 * of type Region or Device.
812 * If the Object is a Device, and the device has a handler of
813 * the same type then the search is terminated in that branch.
815 * This is because the existing handler is closer in proximity
816 * to any more regions than the one we are trying to install.
818 ******************************************************************************/
821 AcpiEvInstallHandler (
822 ACPI_HANDLE ObjHandle
,
827 ACPI_OPERAND_OBJECT
*HandlerObj
;
828 ACPI_OPERAND_OBJECT
*NextHandlerObj
;
829 ACPI_OPERAND_OBJECT
*ObjDesc
;
830 ACPI_NAMESPACE_NODE
*Node
;
834 ACPI_FUNCTION_NAME (EvInstallHandler
);
837 HandlerObj
= (ACPI_OPERAND_OBJECT
*) Context
;
839 /* Parameter validation */
846 /* Convert and validate the device handle */
848 Node
= AcpiNsValidateHandle (ObjHandle
);
851 return (AE_BAD_PARAMETER
);
855 * We only care about regions and objects that are allowed to have
856 * address space handlers
858 if ((Node
->Type
!= ACPI_TYPE_DEVICE
) &&
859 (Node
->Type
!= ACPI_TYPE_REGION
) &&
860 (Node
!= AcpiGbl_RootNode
))
865 /* Check for an existing internal object */
867 ObjDesc
= AcpiNsGetAttachedObject (Node
);
870 /* No object, just exit */
875 /* Devices are handled different than regions */
877 if (ObjDesc
->Common
.Type
== ACPI_TYPE_DEVICE
)
879 /* Check if this Device already has a handler for this address space */
881 NextHandlerObj
= ObjDesc
->Device
.Handler
;
882 while (NextHandlerObj
)
884 /* Found a handler, is it for the same address space? */
886 if (NextHandlerObj
->AddressSpace
.SpaceId
==
887 HandlerObj
->AddressSpace
.SpaceId
)
889 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
890 "Found handler for region [%s] in device %p(%p) "
892 AcpiUtGetRegionName (HandlerObj
->AddressSpace
.SpaceId
),
893 ObjDesc
, NextHandlerObj
, HandlerObj
));
896 * Since the object we found it on was a device, then it
897 * means that someone has already installed a handler for
898 * the branch of the namespace from this device on. Just
899 * bail out telling the walk routine to not traverse this
900 * branch. This preserves the scoping rule for handlers.
902 return (AE_CTRL_DEPTH
);
905 /* Walk the linked list of handlers attached to this device */
907 NextHandlerObj
= NextHandlerObj
->AddressSpace
.Next
;
911 * As long as the device didn't have a handler for this space we
912 * don't care about it. We just ignore it and proceed.
917 /* Object is a Region */
919 if (ObjDesc
->Region
.SpaceId
!= HandlerObj
->AddressSpace
.SpaceId
)
921 /* This region is for a different address space, just ignore it */
927 * Now we have a region and it is for the handler's address space type.
929 * First disconnect region for any previous handler (if any)
931 AcpiEvDetachRegion (ObjDesc
, FALSE
);
933 /* Connect the region to the new handler */
935 Status
= AcpiEvAttachRegion (HandlerObj
, ObjDesc
, FALSE
);
940 /*******************************************************************************
942 * FUNCTION: AcpiEvInstallSpaceHandler
944 * PARAMETERS: Node - Namespace node for the device
945 * SpaceId - The address space ID
946 * Handler - Address of the handler
947 * Setup - Address of the setup function
948 * Context - Value passed to the handler on each access
952 * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
953 * Assumes namespace is locked
955 ******************************************************************************/
958 AcpiEvInstallSpaceHandler (
959 ACPI_NAMESPACE_NODE
*Node
,
960 ACPI_ADR_SPACE_TYPE SpaceId
,
961 ACPI_ADR_SPACE_HANDLER Handler
,
962 ACPI_ADR_SPACE_SETUP Setup
,
965 ACPI_OPERAND_OBJECT
*ObjDesc
;
966 ACPI_OPERAND_OBJECT
*HandlerObj
;
968 ACPI_OBJECT_TYPE Type
;
972 ACPI_FUNCTION_TRACE (EvInstallSpaceHandler
);
976 * This registration is valid for only the types below and the root. This
977 * is where the default handlers get placed.
979 if ((Node
->Type
!= ACPI_TYPE_DEVICE
) &&
980 (Node
->Type
!= ACPI_TYPE_PROCESSOR
) &&
981 (Node
->Type
!= ACPI_TYPE_THERMAL
) &&
982 (Node
!= AcpiGbl_RootNode
))
984 Status
= AE_BAD_PARAMETER
;
988 if (Handler
== ACPI_DEFAULT_HANDLER
)
990 Flags
= ACPI_ADDR_HANDLER_DEFAULT_INSTALLED
;
994 case ACPI_ADR_SPACE_SYSTEM_MEMORY
:
995 Handler
= AcpiExSystemMemorySpaceHandler
;
996 Setup
= AcpiEvSystemMemoryRegionSetup
;
999 case ACPI_ADR_SPACE_SYSTEM_IO
:
1000 Handler
= AcpiExSystemIoSpaceHandler
;
1001 Setup
= AcpiEvIoSpaceRegionSetup
;
1004 case ACPI_ADR_SPACE_PCI_CONFIG
:
1005 Handler
= AcpiExPciConfigSpaceHandler
;
1006 Setup
= AcpiEvPciConfigRegionSetup
;
1009 case ACPI_ADR_SPACE_CMOS
:
1010 Handler
= AcpiExCmosSpaceHandler
;
1011 Setup
= AcpiEvCmosRegionSetup
;
1014 case ACPI_ADR_SPACE_PCI_BAR_TARGET
:
1015 Handler
= AcpiExPciBarSpaceHandler
;
1016 Setup
= AcpiEvPciBarRegionSetup
;
1019 case ACPI_ADR_SPACE_DATA_TABLE
:
1020 Handler
= AcpiExDataTableSpaceHandler
;
1025 Status
= AE_BAD_PARAMETER
;
1030 /* If the caller hasn't specified a setup routine, use the default */
1034 Setup
= AcpiEvDefaultRegionSetup
;
1037 /* Check for an existing internal object */
1039 ObjDesc
= AcpiNsGetAttachedObject (Node
);
1043 * The attached device object already exists. Make sure the handler
1044 * is not already installed.
1046 HandlerObj
= ObjDesc
->Device
.Handler
;
1048 /* Walk the handler list for this device */
1052 /* Same SpaceId indicates a handler already installed */
1054 if (HandlerObj
->AddressSpace
.SpaceId
== SpaceId
)
1056 if (HandlerObj
->AddressSpace
.Handler
== Handler
)
1059 * It is (relatively) OK to attempt to install the SAME
1060 * handler twice. This can easily happen with the
1063 Status
= AE_SAME_HANDLER
;
1068 /* A handler is already installed */
1070 Status
= AE_ALREADY_EXISTS
;
1075 /* Walk the linked list of handlers */
1077 HandlerObj
= HandlerObj
->AddressSpace
.Next
;
1082 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
1083 "Creating object on Device %p while installing handler\n", Node
));
1085 /* ObjDesc does not exist, create one */
1087 if (Node
->Type
== ACPI_TYPE_ANY
)
1089 Type
= ACPI_TYPE_DEVICE
;
1096 ObjDesc
= AcpiUtCreateInternalObject (Type
);
1099 Status
= AE_NO_MEMORY
;
1103 /* Init new descriptor */
1105 ObjDesc
->Common
.Type
= (UINT8
) Type
;
1107 /* Attach the new object to the Node */
1109 Status
= AcpiNsAttachObject (Node
, ObjDesc
, Type
);
1111 /* Remove local reference to the object */
1113 AcpiUtRemoveReference (ObjDesc
);
1115 if (ACPI_FAILURE (Status
))
1121 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
1122 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
1123 AcpiUtGetRegionName (SpaceId
), SpaceId
,
1124 AcpiUtGetNodeName (Node
), Node
, ObjDesc
));
1127 * Install the handler
1129 * At this point there is no existing handler. Just allocate the object
1130 * for the handler and link it into the list.
1132 HandlerObj
= AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER
);
1135 Status
= AE_NO_MEMORY
;
1139 /* Init handler obj */
1141 HandlerObj
->AddressSpace
.SpaceId
= (UINT8
) SpaceId
;
1142 HandlerObj
->AddressSpace
.HandlerFlags
= Flags
;
1143 HandlerObj
->AddressSpace
.RegionList
= NULL
;
1144 HandlerObj
->AddressSpace
.Node
= Node
;
1145 HandlerObj
->AddressSpace
.Handler
= Handler
;
1146 HandlerObj
->AddressSpace
.Context
= Context
;
1147 HandlerObj
->AddressSpace
.Setup
= Setup
;
1149 /* Install at head of Device.AddressSpace list */
1151 HandlerObj
->AddressSpace
.Next
= ObjDesc
->Device
.Handler
;
1154 * The Device object is the first reference on the HandlerObj.
1155 * Each region that uses the handler adds a reference.
1157 ObjDesc
->Device
.Handler
= HandlerObj
;
1160 * Walk the namespace finding all of the regions this
1161 * handler will manage.
1163 * Start at the device and search the branch toward
1164 * the leaf nodes until either the leaf is encountered or
1165 * a device is detected that has an address handler of the
1168 * In either case, back up and search down the remainder
1171 Status
= AcpiNsWalkNamespace (ACPI_TYPE_ANY
, Node
, ACPI_UINT32_MAX
,
1172 ACPI_NS_WALK_UNLOCK
, AcpiEvInstallHandler
, NULL
,
1176 return_ACPI_STATUS (Status
);
1180 /*******************************************************************************
1182 * FUNCTION: AcpiEvExecuteRegMethods
1184 * PARAMETERS: Node - Namespace node for the device
1185 * SpaceId - The address space ID
1189 * DESCRIPTION: Run all _REG methods for the input Space ID;
1190 * Note: assumes namespace is locked, or system init time.
1192 ******************************************************************************/
1195 AcpiEvExecuteRegMethods (
1196 ACPI_NAMESPACE_NODE
*Node
,
1197 ACPI_ADR_SPACE_TYPE SpaceId
)
1202 ACPI_FUNCTION_TRACE (EvExecuteRegMethods
);
1206 * Run all _REG methods for all Operation Regions for this space ID. This
1207 * is a separate walk in order to handle any interdependencies between
1208 * regions and _REG methods. (i.e. handlers must be installed for all
1209 * regions of this Space ID before we can run any _REG methods)
1211 Status
= AcpiNsWalkNamespace (ACPI_TYPE_ANY
, Node
, ACPI_UINT32_MAX
,
1212 ACPI_NS_WALK_UNLOCK
, AcpiEvRegRun
, NULL
,
1215 return_ACPI_STATUS (Status
);
1219 /*******************************************************************************
1221 * FUNCTION: AcpiEvRegRun
1223 * PARAMETERS: WalkNamespace callback
1225 * DESCRIPTION: Run _REG method for region objects of the requested spaceID
1227 ******************************************************************************/
1231 ACPI_HANDLE ObjHandle
,
1236 ACPI_OPERAND_OBJECT
*ObjDesc
;
1237 ACPI_NAMESPACE_NODE
*Node
;
1238 ACPI_ADR_SPACE_TYPE SpaceId
;
1242 SpaceId
= *ACPI_CAST_PTR (ACPI_ADR_SPACE_TYPE
, Context
);
1244 /* Convert and validate the device handle */
1246 Node
= AcpiNsValidateHandle (ObjHandle
);
1249 return (AE_BAD_PARAMETER
);
1253 * We only care about regions.and objects that are allowed to have address
1256 if ((Node
->Type
!= ACPI_TYPE_REGION
) &&
1257 (Node
!= AcpiGbl_RootNode
))
1262 /* Check for an existing internal object */
1264 ObjDesc
= AcpiNsGetAttachedObject (Node
);
1267 /* No object, just exit */
1272 /* Object is a Region */
1274 if (ObjDesc
->Region
.SpaceId
!= SpaceId
)
1276 /* This region is for a different address space, just ignore it */
1281 Status
= AcpiEvExecuteRegMethod (ObjDesc
, 1);