1 /******************************************************************************
3 * Module Name: evregion - ACPI AddressSpace (OpRegion) handler dispatch
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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.
45 #define __EVREGION_C__
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acevents.h>
50 #include <contrib/dev/acpica/include/acnamesp.h>
51 #include <contrib/dev/acpica/include/acinterp.h>
53 #define _COMPONENT ACPI_EVENTS
54 ACPI_MODULE_NAME ("evregion")
57 /* Local prototypes */
60 AcpiEvHasDefaultHandler (
61 ACPI_NAMESPACE_NODE *Node,
62 ACPI_ADR_SPACE_TYPE SpaceId);
65 AcpiEvOrphanEcRegMethod (
70 ACPI_HANDLE ObjHandle,
76 AcpiEvInstallHandler (
77 ACPI_HANDLE ObjHandle,
82 /* These are the address spaces that will get default handlers */
84 #define ACPI_NUM_DEFAULT_SPACES 4
86 static UINT8 AcpiGbl_DefaultAddressSpaces[ACPI_NUM_DEFAULT_SPACES] =
88 ACPI_ADR_SPACE_SYSTEM_MEMORY,
89 ACPI_ADR_SPACE_SYSTEM_IO,
90 ACPI_ADR_SPACE_PCI_CONFIG,
91 ACPI_ADR_SPACE_DATA_TABLE
95 /*******************************************************************************
97 * FUNCTION: AcpiEvInstallRegionHandlers
103 * DESCRIPTION: Installs the core subsystem default address space handlers.
105 ******************************************************************************/
108 AcpiEvInstallRegionHandlers (
115 ACPI_FUNCTION_TRACE (EvInstallRegionHandlers);
118 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
119 if (ACPI_FAILURE (Status))
121 return_ACPI_STATUS (Status);
125 * All address spaces (PCI Config, EC, SMBus) are scope dependent and
126 * registration must occur for a specific device.
128 * In the case of the system memory and IO address spaces there is
129 * currently no device associated with the address space. For these we
132 * We install the default PCI config space handler at the root so that
133 * this space is immediately available even though the we have not
134 * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
135 * specification which states that the PCI config space must be always
136 * available -- even though we are nowhere near ready to find the PCI root
137 * buses at this point.
139 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
140 * has already been installed (via AcpiInstallAddressSpaceHandler).
141 * Similar for AE_SAME_HANDLER.
143 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
145 Status = AcpiEvInstallSpaceHandler (AcpiGbl_RootNode,
146 AcpiGbl_DefaultAddressSpaces[i],
147 ACPI_DEFAULT_HANDLER, NULL, NULL);
151 case AE_SAME_HANDLER:
152 case AE_ALREADY_EXISTS:
154 /* These exceptions are all OK */
166 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
167 return_ACPI_STATUS (Status);
171 /*******************************************************************************
173 * FUNCTION: AcpiEvHasDefaultHandler
175 * PARAMETERS: Node - Namespace node for the device
176 * SpaceId - The address space ID
178 * RETURN: TRUE if default handler is installed, FALSE otherwise
180 * DESCRIPTION: Check if the default handler is installed for the requested
183 ******************************************************************************/
186 AcpiEvHasDefaultHandler (
187 ACPI_NAMESPACE_NODE *Node,
188 ACPI_ADR_SPACE_TYPE SpaceId)
190 ACPI_OPERAND_OBJECT *ObjDesc;
191 ACPI_OPERAND_OBJECT *HandlerObj;
194 /* Must have an existing internal object */
196 ObjDesc = AcpiNsGetAttachedObject (Node);
199 HandlerObj = ObjDesc->Device.Handler;
201 /* Walk the linked list of handlers for this object */
205 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
207 if (HandlerObj->AddressSpace.HandlerFlags &
208 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
214 HandlerObj = HandlerObj->AddressSpace.Next;
222 /*******************************************************************************
224 * FUNCTION: AcpiEvInitializeOpRegions
230 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
231 * an installed default region handler.
233 ******************************************************************************/
236 AcpiEvInitializeOpRegions (
243 ACPI_FUNCTION_TRACE (EvInitializeOpRegions);
246 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
247 if (ACPI_FAILURE (Status))
249 return_ACPI_STATUS (Status);
252 /* Run the _REG methods for OpRegions in each default address space */
254 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
257 * Make sure the installed handler is the DEFAULT handler. If not the
258 * default, the _REG methods will have already been run (when the
259 * handler was installed)
261 if (AcpiEvHasDefaultHandler (AcpiGbl_RootNode,
262 AcpiGbl_DefaultAddressSpaces[i]))
264 Status = AcpiEvExecuteRegMethods (AcpiGbl_RootNode,
265 AcpiGbl_DefaultAddressSpaces[i]);
269 AcpiGbl_RegMethodsExecuted = TRUE;
271 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
272 return_ACPI_STATUS (Status);
276 /*******************************************************************************
278 * FUNCTION: AcpiEvExecuteRegMethod
280 * PARAMETERS: RegionObj - Region object
281 * Function - Passed to _REG: On (1) or Off (0)
285 * DESCRIPTION: Execute _REG method for a region
287 ******************************************************************************/
290 AcpiEvExecuteRegMethod (
291 ACPI_OPERAND_OBJECT *RegionObj,
294 ACPI_EVALUATE_INFO *Info;
295 ACPI_OPERAND_OBJECT *Args[3];
296 ACPI_OPERAND_OBJECT *RegionObj2;
300 ACPI_FUNCTION_TRACE (EvExecuteRegMethod);
303 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
306 return_ACPI_STATUS (AE_NOT_EXIST);
309 if (RegionObj2->Extra.Method_REG == NULL)
311 return_ACPI_STATUS (AE_OK);
314 /* Allocate and initialize the evaluation information block */
316 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
319 return_ACPI_STATUS (AE_NO_MEMORY);
322 Info->PrefixNode = RegionObj2->Extra.Method_REG;
323 Info->Pathname = NULL;
324 Info->Parameters = Args;
325 Info->Flags = ACPI_IGNORE_RETURN_VALUE;
328 * The _REG method has two arguments:
331 * Operation region space ID Same value as RegionObj->Region.SpaceId
334 * connection status 1 for connecting the handler, 0 for disconnecting
335 * the handler (Passed as a parameter)
337 Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId);
340 Status = AE_NO_MEMORY;
344 Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function);
347 Status = AE_NO_MEMORY;
351 Args[2] = NULL; /* Terminate list */
353 /* Execute the method, no return value */
356 AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL));
358 Status = AcpiNsEvaluate (Info);
359 AcpiUtRemoveReference (Args[1]);
362 AcpiUtRemoveReference (Args[0]);
366 return_ACPI_STATUS (Status);
370 /*******************************************************************************
372 * FUNCTION: AcpiEvAddressSpaceDispatch
374 * PARAMETERS: RegionObj - Internal region object
375 * Function - Read or Write operation
376 * RegionOffset - Where in the region to read or write
377 * BitWidth - Field width in bits (8, 16, 32, or 64)
378 * Value - Pointer to in or out value, must be
379 * a full 64-bit integer
383 * DESCRIPTION: Dispatch an address space or operation region access to
384 * a previously installed handler.
386 ******************************************************************************/
389 AcpiEvAddressSpaceDispatch (
390 ACPI_OPERAND_OBJECT *RegionObj,
397 ACPI_ADR_SPACE_HANDLER Handler;
398 ACPI_ADR_SPACE_SETUP RegionSetup;
399 ACPI_OPERAND_OBJECT *HandlerDesc;
400 ACPI_OPERAND_OBJECT *RegionObj2;
401 void *RegionContext = NULL;
404 ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch);
407 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
410 return_ACPI_STATUS (AE_NOT_EXIST);
413 /* Ensure that there is a handler associated with this region */
415 HandlerDesc = RegionObj->Region.Handler;
418 ACPI_ERROR ((AE_INFO,
419 "No handler for Region [%4.4s] (%p) [%s]",
420 AcpiUtGetNodeName (RegionObj->Region.Node),
421 RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
423 return_ACPI_STATUS (AE_NOT_EXIST);
427 * It may be the case that the region has never been initialized.
428 * Some types of regions require special init code
430 if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
432 /* This region has not been initialized yet, do it */
434 RegionSetup = HandlerDesc->AddressSpace.Setup;
437 /* No initialization routine, exit with error */
439 ACPI_ERROR ((AE_INFO,
440 "No init routine for region(%p) [%s]",
441 RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
442 return_ACPI_STATUS (AE_NOT_EXIST);
446 * We must exit the interpreter because the region setup will
447 * potentially execute control methods (for example, the _REG method
450 AcpiExExitInterpreter ();
452 Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE,
453 HandlerDesc->AddressSpace.Context, &RegionContext);
455 /* Re-enter the interpreter */
457 AcpiExEnterInterpreter ();
459 /* Check for failure of the Region Setup */
461 if (ACPI_FAILURE (Status))
463 ACPI_EXCEPTION ((AE_INFO, Status,
464 "During region initialization: [%s]",
465 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
466 return_ACPI_STATUS (Status);
469 /* Region initialization may have been completed by RegionSetup */
471 if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
473 RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE;
475 if (RegionObj2->Extra.RegionContext)
477 /* The handler for this region was already installed */
479 ACPI_FREE (RegionContext);
484 * Save the returned context for use in all accesses to
485 * this particular region
487 RegionObj2->Extra.RegionContext = RegionContext;
492 /* We have everything we need, we can invoke the address space handler */
494 Handler = HandlerDesc->AddressSpace.Handler;
496 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
497 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
498 &RegionObj->Region.Handler->AddressSpace, Handler,
499 ACPI_FORMAT_NATIVE_UINT (RegionObj->Region.Address + RegionOffset),
500 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
502 if (!(HandlerDesc->AddressSpace.HandlerFlags &
503 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
506 * For handlers other than the default (supplied) handlers, we must
507 * exit the interpreter because the handler *might* block -- we don't
508 * know what it will do, so we can't hold the lock on the intepreter.
510 AcpiExExitInterpreter();
513 /* Call the handler */
515 Status = Handler (Function,
516 (RegionObj->Region.Address + RegionOffset), BitWidth, Value,
517 HandlerDesc->AddressSpace.Context, RegionObj2->Extra.RegionContext);
519 if (ACPI_FAILURE (Status))
521 ACPI_EXCEPTION ((AE_INFO, Status, "Returned by Handler for [%s]",
522 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
525 if (!(HandlerDesc->AddressSpace.HandlerFlags &
526 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
529 * We just returned from a non-default handler, we must re-enter the
532 AcpiExEnterInterpreter ();
535 return_ACPI_STATUS (Status);
539 /*******************************************************************************
541 * FUNCTION: AcpiEvDetachRegion
543 * PARAMETERS: RegionObj - Region Object
544 * AcpiNsIsLocked - Namespace Region Already Locked?
548 * DESCRIPTION: Break the association between the handler and the region
549 * this is a two way association.
551 ******************************************************************************/
555 ACPI_OPERAND_OBJECT *RegionObj,
556 BOOLEAN AcpiNsIsLocked)
558 ACPI_OPERAND_OBJECT *HandlerObj;
559 ACPI_OPERAND_OBJECT *ObjDesc;
560 ACPI_OPERAND_OBJECT **LastObjPtr;
561 ACPI_ADR_SPACE_SETUP RegionSetup;
562 void **RegionContext;
563 ACPI_OPERAND_OBJECT *RegionObj2;
567 ACPI_FUNCTION_TRACE (EvDetachRegion);
570 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
575 RegionContext = &RegionObj2->Extra.RegionContext;
577 /* Get the address handler from the region object */
579 HandlerObj = RegionObj->Region.Handler;
582 /* This region has no handler, all done */
587 /* Find this region in the handler's list */
589 ObjDesc = HandlerObj->AddressSpace.RegionList;
590 LastObjPtr = &HandlerObj->AddressSpace.RegionList;
594 /* Is this the correct Region? */
596 if (ObjDesc == RegionObj)
598 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
599 "Removing Region %p from address handler %p\n",
600 RegionObj, HandlerObj));
602 /* This is it, remove it from the handler's list */
604 *LastObjPtr = ObjDesc->Region.Next;
605 ObjDesc->Region.Next = NULL; /* Must clear field */
609 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
610 if (ACPI_FAILURE (Status))
616 /* Now stop region accesses by executing the _REG method */
618 Status = AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_DISCONNECT);
619 if (ACPI_FAILURE (Status))
621 ACPI_EXCEPTION ((AE_INFO, Status, "from region _REG, [%s]",
622 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
627 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
628 if (ACPI_FAILURE (Status))
635 * If the region has been activated, call the setup handler with
636 * the deactivate notification
638 if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
640 RegionSetup = HandlerObj->AddressSpace.Setup;
641 Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE,
642 HandlerObj->AddressSpace.Context, RegionContext);
644 /* Init routine may fail, Just ignore errors */
646 if (ACPI_FAILURE (Status))
648 ACPI_EXCEPTION ((AE_INFO, Status,
649 "from region handler - deactivate, [%s]",
650 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
653 RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
657 * Remove handler reference in the region
659 * NOTE: this doesn't mean that the region goes away, the region
660 * is just inaccessible as indicated to the _REG method
662 * If the region is on the handler's list, this must be the
665 RegionObj->Region.Handler = NULL;
666 AcpiUtRemoveReference (HandlerObj);
671 /* Walk the linked list of handlers */
673 LastObjPtr = &ObjDesc->Region.Next;
674 ObjDesc = ObjDesc->Region.Next;
677 /* If we get here, the region was not in the handler's region list */
679 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
680 "Cannot remove region %p from address handler %p\n",
681 RegionObj, HandlerObj));
687 /*******************************************************************************
689 * FUNCTION: AcpiEvAttachRegion
691 * PARAMETERS: HandlerObj - Handler Object
692 * RegionObj - Region Object
693 * AcpiNsIsLocked - Namespace Region Already Locked?
697 * DESCRIPTION: Create the association between the handler and the region
698 * this is a two way association.
700 ******************************************************************************/
704 ACPI_OPERAND_OBJECT *HandlerObj,
705 ACPI_OPERAND_OBJECT *RegionObj,
706 BOOLEAN AcpiNsIsLocked)
709 ACPI_FUNCTION_TRACE (EvAttachRegion);
712 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
713 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
714 AcpiUtGetNodeName (RegionObj->Region.Node),
715 RegionObj, HandlerObj,
716 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
718 /* Link this region to the front of the handler's list */
720 RegionObj->Region.Next = HandlerObj->AddressSpace.RegionList;
721 HandlerObj->AddressSpace.RegionList = RegionObj;
723 /* Install the region's handler */
725 if (RegionObj->Region.Handler)
727 return_ACPI_STATUS (AE_ALREADY_EXISTS);
730 RegionObj->Region.Handler = HandlerObj;
731 AcpiUtAddReference (HandlerObj);
733 return_ACPI_STATUS (AE_OK);
737 /*******************************************************************************
739 * FUNCTION: AcpiEvInstallHandler
741 * PARAMETERS: WalkNamespace callback
743 * DESCRIPTION: This routine installs an address handler into objects that are
744 * of type Region or Device.
746 * If the Object is a Device, and the device has a handler of
747 * the same type then the search is terminated in that branch.
749 * This is because the existing handler is closer in proximity
750 * to any more regions than the one we are trying to install.
752 ******************************************************************************/
755 AcpiEvInstallHandler (
756 ACPI_HANDLE ObjHandle,
761 ACPI_OPERAND_OBJECT *HandlerObj;
762 ACPI_OPERAND_OBJECT *NextHandlerObj;
763 ACPI_OPERAND_OBJECT *ObjDesc;
764 ACPI_NAMESPACE_NODE *Node;
768 ACPI_FUNCTION_NAME (EvInstallHandler);
771 HandlerObj = (ACPI_OPERAND_OBJECT *) Context;
773 /* Parameter validation */
780 /* Convert and validate the device handle */
782 Node = AcpiNsValidateHandle (ObjHandle);
785 return (AE_BAD_PARAMETER);
789 * We only care about regions and objects that are allowed to have
790 * address space handlers
792 if ((Node->Type != ACPI_TYPE_DEVICE) &&
793 (Node->Type != ACPI_TYPE_REGION) &&
794 (Node != AcpiGbl_RootNode))
799 /* Check for an existing internal object */
801 ObjDesc = AcpiNsGetAttachedObject (Node);
804 /* No object, just exit */
809 /* Devices are handled different than regions */
811 if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE)
813 /* Check if this Device already has a handler for this address space */
815 NextHandlerObj = ObjDesc->Device.Handler;
816 while (NextHandlerObj)
818 /* Found a handler, is it for the same address space? */
820 if (NextHandlerObj->AddressSpace.SpaceId ==
821 HandlerObj->AddressSpace.SpaceId)
823 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
824 "Found handler for region [%s] in device %p(%p) "
826 AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId),
827 ObjDesc, NextHandlerObj, HandlerObj));
830 * Since the object we found it on was a device, then it
831 * means that someone has already installed a handler for
832 * the branch of the namespace from this device on. Just
833 * bail out telling the walk routine to not traverse this
834 * branch. This preserves the scoping rule for handlers.
836 return (AE_CTRL_DEPTH);
839 /* Walk the linked list of handlers attached to this device */
841 NextHandlerObj = NextHandlerObj->AddressSpace.Next;
845 * As long as the device didn't have a handler for this space we
846 * don't care about it. We just ignore it and proceed.
851 /* Object is a Region */
853 if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId)
855 /* This region is for a different address space, just ignore it */
861 * Now we have a region and it is for the handler's address space type.
863 * First disconnect region for any previous handler (if any)
865 AcpiEvDetachRegion (ObjDesc, FALSE);
867 /* Connect the region to the new handler */
869 Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
874 /*******************************************************************************
876 * FUNCTION: AcpiEvInstallSpaceHandler
878 * PARAMETERS: Node - Namespace node for the device
879 * SpaceId - The address space ID
880 * Handler - Address of the handler
881 * Setup - Address of the setup function
882 * Context - Value passed to the handler on each access
886 * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
887 * Assumes namespace is locked
889 ******************************************************************************/
892 AcpiEvInstallSpaceHandler (
893 ACPI_NAMESPACE_NODE *Node,
894 ACPI_ADR_SPACE_TYPE SpaceId,
895 ACPI_ADR_SPACE_HANDLER Handler,
896 ACPI_ADR_SPACE_SETUP Setup,
899 ACPI_OPERAND_OBJECT *ObjDesc;
900 ACPI_OPERAND_OBJECT *HandlerObj;
902 ACPI_OBJECT_TYPE Type;
906 ACPI_FUNCTION_TRACE (EvInstallSpaceHandler);
910 * This registration is valid for only the types below and the root. This
911 * is where the default handlers get placed.
913 if ((Node->Type != ACPI_TYPE_DEVICE) &&
914 (Node->Type != ACPI_TYPE_PROCESSOR) &&
915 (Node->Type != ACPI_TYPE_THERMAL) &&
916 (Node != AcpiGbl_RootNode))
918 Status = AE_BAD_PARAMETER;
922 if (Handler == ACPI_DEFAULT_HANDLER)
924 Flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
928 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
929 Handler = AcpiExSystemMemorySpaceHandler;
930 Setup = AcpiEvSystemMemoryRegionSetup;
933 case ACPI_ADR_SPACE_SYSTEM_IO:
934 Handler = AcpiExSystemIoSpaceHandler;
935 Setup = AcpiEvIoSpaceRegionSetup;
938 case ACPI_ADR_SPACE_PCI_CONFIG:
939 Handler = AcpiExPciConfigSpaceHandler;
940 Setup = AcpiEvPciConfigRegionSetup;
943 case ACPI_ADR_SPACE_CMOS:
944 Handler = AcpiExCmosSpaceHandler;
945 Setup = AcpiEvCmosRegionSetup;
948 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
949 Handler = AcpiExPciBarSpaceHandler;
950 Setup = AcpiEvPciBarRegionSetup;
953 case ACPI_ADR_SPACE_DATA_TABLE:
954 Handler = AcpiExDataTableSpaceHandler;
959 Status = AE_BAD_PARAMETER;
964 /* If the caller hasn't specified a setup routine, use the default */
968 Setup = AcpiEvDefaultRegionSetup;
971 /* Check for an existing internal object */
973 ObjDesc = AcpiNsGetAttachedObject (Node);
977 * The attached device object already exists. Make sure the handler
978 * is not already installed.
980 HandlerObj = ObjDesc->Device.Handler;
982 /* Walk the handler list for this device */
986 /* Same SpaceId indicates a handler already installed */
988 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
990 if (HandlerObj->AddressSpace.Handler == Handler)
993 * It is (relatively) OK to attempt to install the SAME
994 * handler twice. This can easily happen with the
997 Status = AE_SAME_HANDLER;
1002 /* A handler is already installed */
1004 Status = AE_ALREADY_EXISTS;
1009 /* Walk the linked list of handlers */
1011 HandlerObj = HandlerObj->AddressSpace.Next;
1016 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
1017 "Creating object on Device %p while installing handler\n", Node));
1019 /* ObjDesc does not exist, create one */
1021 if (Node->Type == ACPI_TYPE_ANY)
1023 Type = ACPI_TYPE_DEVICE;
1030 ObjDesc = AcpiUtCreateInternalObject (Type);
1033 Status = AE_NO_MEMORY;
1037 /* Init new descriptor */
1039 ObjDesc->Common.Type = (UINT8) Type;
1041 /* Attach the new object to the Node */
1043 Status = AcpiNsAttachObject (Node, ObjDesc, Type);
1045 /* Remove local reference to the object */
1047 AcpiUtRemoveReference (ObjDesc);
1049 if (ACPI_FAILURE (Status))
1055 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
1056 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
1057 AcpiUtGetRegionName (SpaceId), SpaceId,
1058 AcpiUtGetNodeName (Node), Node, ObjDesc));
1061 * Install the handler
1063 * At this point there is no existing handler. Just allocate the object
1064 * for the handler and link it into the list.
1066 HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
1069 Status = AE_NO_MEMORY;
1073 /* Init handler obj */
1075 HandlerObj->AddressSpace.SpaceId = (UINT8) SpaceId;
1076 HandlerObj->AddressSpace.HandlerFlags = Flags;
1077 HandlerObj->AddressSpace.RegionList = NULL;
1078 HandlerObj->AddressSpace.Node = Node;
1079 HandlerObj->AddressSpace.Handler = Handler;
1080 HandlerObj->AddressSpace.Context = Context;
1081 HandlerObj->AddressSpace.Setup = Setup;
1083 /* Install at head of Device.AddressSpace list */
1085 HandlerObj->AddressSpace.Next = ObjDesc->Device.Handler;
1088 * The Device object is the first reference on the HandlerObj.
1089 * Each region that uses the handler adds a reference.
1091 ObjDesc->Device.Handler = HandlerObj;
1094 * Walk the namespace finding all of the regions this
1095 * handler will manage.
1097 * Start at the device and search the branch toward
1098 * the leaf nodes until either the leaf is encountered or
1099 * a device is detected that has an address handler of the
1102 * In either case, back up and search down the remainder
1105 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
1106 ACPI_NS_WALK_UNLOCK, AcpiEvInstallHandler, NULL,
1110 return_ACPI_STATUS (Status);
1114 /*******************************************************************************
1116 * FUNCTION: AcpiEvExecuteRegMethods
1118 * PARAMETERS: Node - Namespace node for the device
1119 * SpaceId - The address space ID
1123 * DESCRIPTION: Run all _REG methods for the input Space ID;
1124 * Note: assumes namespace is locked, or system init time.
1126 ******************************************************************************/
1129 AcpiEvExecuteRegMethods (
1130 ACPI_NAMESPACE_NODE *Node,
1131 ACPI_ADR_SPACE_TYPE SpaceId)
1136 ACPI_FUNCTION_TRACE (EvExecuteRegMethods);
1140 * Run all _REG methods for all Operation Regions for this space ID. This
1141 * is a separate walk in order to handle any interdependencies between
1142 * regions and _REG methods. (i.e. handlers must be installed for all
1143 * regions of this Space ID before we can run any _REG methods)
1145 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
1146 ACPI_NS_WALK_UNLOCK, AcpiEvRegRun, NULL,
1149 /* Special case for EC: handle "orphan" _REG methods with no region */
1151 if (SpaceId == ACPI_ADR_SPACE_EC)
1153 AcpiEvOrphanEcRegMethod ();
1156 return_ACPI_STATUS (Status);
1160 /*******************************************************************************
1162 * FUNCTION: AcpiEvRegRun
1164 * PARAMETERS: WalkNamespace callback
1166 * DESCRIPTION: Run _REG method for region objects of the requested spaceID
1168 ******************************************************************************/
1172 ACPI_HANDLE ObjHandle,
1177 ACPI_OPERAND_OBJECT *ObjDesc;
1178 ACPI_NAMESPACE_NODE *Node;
1179 ACPI_ADR_SPACE_TYPE SpaceId;
1183 SpaceId = *ACPI_CAST_PTR (ACPI_ADR_SPACE_TYPE, Context);
1185 /* Convert and validate the device handle */
1187 Node = AcpiNsValidateHandle (ObjHandle);
1190 return (AE_BAD_PARAMETER);
1194 * We only care about regions.and objects that are allowed to have address
1197 if ((Node->Type != ACPI_TYPE_REGION) &&
1198 (Node != AcpiGbl_RootNode))
1203 /* Check for an existing internal object */
1205 ObjDesc = AcpiNsGetAttachedObject (Node);
1208 /* No object, just exit */
1213 /* Object is a Region */
1215 if (ObjDesc->Region.SpaceId != SpaceId)
1217 /* This region is for a different address space, just ignore it */
1222 Status = AcpiEvExecuteRegMethod (ObjDesc, ACPI_REG_CONNECT);
1227 /*******************************************************************************
1229 * FUNCTION: AcpiEvOrphanEcRegMethod
1235 * DESCRIPTION: Execute an "orphan" _REG method that appears under the EC
1236 * device. This is a _REG method that has no corresponding region
1237 * within the EC device scope. The orphan _REG method appears to
1238 * have been enabled by the description of the ECDT in the ACPI
1239 * specification: "The availability of the region space can be
1240 * detected by providing a _REG method object underneath the
1241 * Embedded Controller device."
1243 * To quickly access the EC device, we use the EC_ID that appears
1244 * within the ECDT. Otherwise, we would need to perform a time-
1245 * consuming namespace walk, executing _HID methods to find the
1248 ******************************************************************************/
1251 AcpiEvOrphanEcRegMethod (
1254 ACPI_TABLE_ECDT *Table;
1256 ACPI_OBJECT_LIST Args;
1257 ACPI_OBJECT Objects[2];
1258 ACPI_NAMESPACE_NODE *EcDeviceNode;
1259 ACPI_NAMESPACE_NODE *RegMethod;
1260 ACPI_NAMESPACE_NODE *NextNode;
1263 ACPI_FUNCTION_TRACE (EvOrphanEcRegMethod);
1266 /* Get the ECDT (if present in system) */
1268 Status = AcpiGetTable (ACPI_SIG_ECDT, 0,
1269 ACPI_CAST_INDIRECT_PTR (ACPI_TABLE_HEADER, &Table));
1270 if (ACPI_FAILURE (Status))
1275 /* We need a valid EC_ID string */
1282 /* Namespace is currently locked, must release */
1284 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1286 /* Get a handle to the EC device referenced in the ECDT */
1288 Status = AcpiGetHandle (NULL,
1289 ACPI_CAST_PTR (char, Table->Id),
1290 ACPI_CAST_PTR (ACPI_HANDLE, &EcDeviceNode));
1291 if (ACPI_FAILURE (Status))
1296 /* Get a handle to a _REG method immediately under the EC device */
1298 Status = AcpiGetHandle (EcDeviceNode,
1299 METHOD_NAME__REG, ACPI_CAST_PTR (ACPI_HANDLE, &RegMethod));
1300 if (ACPI_FAILURE (Status))
1306 * Execute the _REG method only if there is no Operation Region in
1307 * this scope with the Embedded Controller space ID. Otherwise, it
1308 * will already have been executed. Note, this allows for Regions
1309 * with other space IDs to be present; but the code below will then
1310 * execute the _REG method with the EC space ID argument.
1312 NextNode = AcpiNsGetNextNode (EcDeviceNode, NULL);
1315 if ((NextNode->Type == ACPI_TYPE_REGION) &&
1316 (NextNode->Object) &&
1317 (NextNode->Object->Region.SpaceId == ACPI_ADR_SPACE_EC))
1319 goto Exit; /* Do not execute _REG */
1321 NextNode = AcpiNsGetNextNode (EcDeviceNode, NextNode);
1324 /* Evaluate the _REG(EC,Connect) method */
1327 Args.Pointer = Objects;
1328 Objects[0].Type = ACPI_TYPE_INTEGER;
1329 Objects[0].Integer.Value = ACPI_ADR_SPACE_EC;
1330 Objects[1].Type = ACPI_TYPE_INTEGER;
1331 Objects[1].Integer.Value = ACPI_REG_CONNECT;
1333 Status = AcpiEvaluateObject (RegMethod, NULL, &Args, NULL);
1336 /* We ignore all errors from above, don't care */
1338 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);