Sync usage with man page.
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / events / evregion.c
blob32d7b642f996cbc61b2df66b7de1065e68ea806f
1 /******************************************************************************
3 * Module Name: evregion - ACPI AddressSpace (OpRegion) handler dispatch
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
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
38 * conditions are met:
40 * 3. Conditions
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
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
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
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
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__
119 #include "acpi.h"
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 */
131 static ACPI_STATUS
132 AcpiEvRegRun (
133 ACPI_HANDLE ObjHandle,
134 UINT32 Level,
135 void *Context,
136 void **ReturnValue);
138 static ACPI_STATUS
139 AcpiEvInstallHandler (
140 ACPI_HANDLE ObjHandle,
141 UINT32 Level,
142 void *Context,
143 void **ReturnValue);
145 /* These are the address spaces that will get default handlers */
147 #define ACPI_NUM_DEFAULT_SPACES 4
149 static UINT8 AcpiGbl_DefaultAddressSpaces[ACPI_NUM_DEFAULT_SPACES] =
151 ACPI_ADR_SPACE_SYSTEM_MEMORY,
152 ACPI_ADR_SPACE_SYSTEM_IO,
153 ACPI_ADR_SPACE_PCI_CONFIG,
154 ACPI_ADR_SPACE_DATA_TABLE
158 /*******************************************************************************
160 * FUNCTION: AcpiEvInstallRegionHandlers
162 * PARAMETERS: None
164 * RETURN: Status
166 * DESCRIPTION: Installs the core subsystem default address space handlers.
168 ******************************************************************************/
170 ACPI_STATUS
171 AcpiEvInstallRegionHandlers (
172 void)
174 ACPI_STATUS Status;
175 UINT32 i;
178 ACPI_FUNCTION_TRACE (EvInstallRegionHandlers);
181 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
182 if (ACPI_FAILURE (Status))
184 return_ACPI_STATUS (Status);
188 * All address spaces (PCI Config, EC, SMBus) are scope dependent and
189 * registration must occur for a specific device.
191 * In the case of the system memory and IO address spaces there is
192 * currently no device associated with the address space. For these we
193 * use the root.
195 * We install the default PCI config space handler at the root so that
196 * this space is immediately available even though the we have not
197 * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
198 * specification which states that the PCI config space must be always
199 * available -- even though we are nowhere near ready to find the PCI root
200 * buses at this point.
202 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
203 * has already been installed (via AcpiInstallAddressSpaceHandler).
204 * Similar for AE_SAME_HANDLER.
206 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
208 Status = AcpiEvInstallSpaceHandler (AcpiGbl_RootNode,
209 AcpiGbl_DefaultAddressSpaces[i],
210 ACPI_DEFAULT_HANDLER, NULL, NULL);
211 switch (Status)
213 case AE_OK:
214 case AE_SAME_HANDLER:
215 case AE_ALREADY_EXISTS:
217 /* These exceptions are all OK */
219 Status = AE_OK;
220 break;
222 default:
224 goto UnlockAndExit;
228 UnlockAndExit:
229 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
230 return_ACPI_STATUS (Status);
234 /*******************************************************************************
236 * FUNCTION: AcpiEvInitializeOpRegions
238 * PARAMETERS: None
240 * RETURN: Status
242 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
243 * an installed default region handler.
245 ******************************************************************************/
247 ACPI_STATUS
248 AcpiEvInitializeOpRegions (
249 void)
251 ACPI_STATUS Status;
252 UINT32 i;
255 ACPI_FUNCTION_TRACE (EvInitializeOpRegions);
258 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
259 if (ACPI_FAILURE (Status))
261 return_ACPI_STATUS (Status);
264 /* Run the _REG methods for OpRegions in each default address space */
266 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
269 * TBD: Make sure handler is the DEFAULT handler, otherwise
270 * _REG will have already been run.
272 Status = AcpiEvExecuteRegMethods (AcpiGbl_RootNode,
273 AcpiGbl_DefaultAddressSpaces[i]);
276 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
277 return_ACPI_STATUS (Status);
281 /*******************************************************************************
283 * FUNCTION: AcpiEvExecuteRegMethod
285 * PARAMETERS: RegionObj - Region object
286 * Function - Passed to _REG: On (1) or Off (0)
288 * RETURN: Status
290 * DESCRIPTION: Execute _REG method for a region
292 ******************************************************************************/
294 ACPI_STATUS
295 AcpiEvExecuteRegMethod (
296 ACPI_OPERAND_OBJECT *RegionObj,
297 UINT32 Function)
299 ACPI_EVALUATE_INFO *Info;
300 ACPI_OPERAND_OBJECT *Args[3];
301 ACPI_OPERAND_OBJECT *RegionObj2;
302 ACPI_STATUS Status;
305 ACPI_FUNCTION_TRACE (EvExecuteRegMethod);
308 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
309 if (!RegionObj2)
311 return_ACPI_STATUS (AE_NOT_EXIST);
314 if (RegionObj2->Extra.Method_REG == NULL)
316 return_ACPI_STATUS (AE_OK);
319 /* Allocate and initialize the evaluation information block */
321 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
322 if (!Info)
324 return_ACPI_STATUS (AE_NO_MEMORY);
327 Info->PrefixNode = RegionObj2->Extra.Method_REG;
328 Info->Pathname = NULL;
329 Info->Parameters = Args;
330 Info->Flags = ACPI_IGNORE_RETURN_VALUE;
333 * The _REG method has two arguments:
335 * Arg0 - Integer:
336 * Operation region space ID Same value as RegionObj->Region.SpaceId
338 * Arg1 - Integer:
339 * connection status 1 for connecting the handler, 0 for disconnecting
340 * the handler (Passed as a parameter)
342 Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
343 if (!Args[0])
345 Status = AE_NO_MEMORY;
346 goto Cleanup1;
349 Args[1] = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
350 if (!Args[1])
352 Status = AE_NO_MEMORY;
353 goto Cleanup2;
356 /* Setup the parameter objects */
358 Args[0]->Integer.Value = RegionObj->Region.SpaceId;
359 Args[1]->Integer.Value = Function;
360 Args[2] = NULL;
362 /* Execute the method, no return value */
364 ACPI_DEBUG_EXEC (
365 AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL));
367 Status = AcpiNsEvaluate (Info);
368 AcpiUtRemoveReference (Args[1]);
370 Cleanup2:
371 AcpiUtRemoveReference (Args[0]);
373 Cleanup1:
374 ACPI_FREE (Info);
375 return_ACPI_STATUS (Status);
379 /*******************************************************************************
381 * FUNCTION: AcpiEvAddressSpaceDispatch
383 * PARAMETERS: RegionObj - Internal region object
384 * Function - Read or Write operation
385 * RegionOffset - Where in the region to read or write
386 * BitWidth - Field width in bits (8, 16, 32, or 64)
387 * Value - Pointer to in or out value, must be
388 * full 64-bit ACPI_INTEGER
390 * RETURN: Status
392 * DESCRIPTION: Dispatch an address space or operation region access to
393 * a previously installed handler.
395 ******************************************************************************/
397 ACPI_STATUS
398 AcpiEvAddressSpaceDispatch (
399 ACPI_OPERAND_OBJECT *RegionObj,
400 UINT32 Function,
401 UINT32 RegionOffset,
402 UINT32 BitWidth,
403 ACPI_INTEGER *Value)
405 ACPI_STATUS Status;
406 ACPI_ADR_SPACE_HANDLER Handler;
407 ACPI_ADR_SPACE_SETUP RegionSetup;
408 ACPI_OPERAND_OBJECT *HandlerDesc;
409 ACPI_OPERAND_OBJECT *RegionObj2;
410 void *RegionContext = NULL;
413 ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch);
416 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
417 if (!RegionObj2)
419 return_ACPI_STATUS (AE_NOT_EXIST);
422 /* Ensure that there is a handler associated with this region */
424 HandlerDesc = RegionObj->Region.Handler;
425 if (!HandlerDesc)
427 ACPI_ERROR ((AE_INFO,
428 "No handler for Region [%4.4s] (%p) [%s]",
429 AcpiUtGetNodeName (RegionObj->Region.Node),
430 RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
432 return_ACPI_STATUS (AE_NOT_EXIST);
436 * It may be the case that the region has never been initialized.
437 * Some types of regions require special init code
439 if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
441 /* This region has not been initialized yet, do it */
443 RegionSetup = HandlerDesc->AddressSpace.Setup;
444 if (!RegionSetup)
446 /* No initialization routine, exit with error */
448 ACPI_ERROR ((AE_INFO,
449 "No init routine for region(%p) [%s]",
450 RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
451 return_ACPI_STATUS (AE_NOT_EXIST);
455 * We must exit the interpreter because the region setup will
456 * potentially execute control methods (for example, the _REG method
457 * for this region)
459 AcpiExExitInterpreter ();
461 Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE,
462 HandlerDesc->AddressSpace.Context, &RegionContext);
464 /* Re-enter the interpreter */
466 AcpiExEnterInterpreter ();
468 /* Check for failure of the Region Setup */
470 if (ACPI_FAILURE (Status))
472 ACPI_EXCEPTION ((AE_INFO, Status,
473 "During region initialization: [%s]",
474 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
475 return_ACPI_STATUS (Status);
478 /* Region initialization may have been completed by RegionSetup */
480 if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
482 RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE;
484 if (RegionObj2->Extra.RegionContext)
486 /* The handler for this region was already installed */
488 ACPI_FREE (RegionContext);
490 else
493 * Save the returned context for use in all accesses to
494 * this particular region
496 RegionObj2->Extra.RegionContext = RegionContext;
501 /* We have everything we need, we can invoke the address space handler */
503 Handler = HandlerDesc->AddressSpace.Handler;
505 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
506 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
507 &RegionObj->Region.Handler->AddressSpace, Handler,
508 ACPI_FORMAT_NATIVE_UINT (RegionObj->Region.Address + RegionOffset),
509 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
511 if (!(HandlerDesc->AddressSpace.HandlerFlags &
512 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
515 * For handlers other than the default (supplied) handlers, we must
516 * exit the interpreter because the handler *might* block -- we don't
517 * know what it will do, so we can't hold the lock on the intepreter.
519 AcpiExExitInterpreter();
522 /* Call the handler */
524 Status = Handler (Function,
525 (RegionObj->Region.Address + RegionOffset), BitWidth, Value,
526 HandlerDesc->AddressSpace.Context, RegionObj2->Extra.RegionContext);
528 if (ACPI_FAILURE (Status))
530 ACPI_EXCEPTION ((AE_INFO, Status, "Returned by Handler for [%s]",
531 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
534 if (!(HandlerDesc->AddressSpace.HandlerFlags &
535 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
538 * We just returned from a non-default handler, we must re-enter the
539 * interpreter
541 AcpiExEnterInterpreter ();
544 return_ACPI_STATUS (Status);
548 /*******************************************************************************
550 * FUNCTION: AcpiEvDetachRegion
552 * PARAMETERS: RegionObj - Region Object
553 * AcpiNsIsLocked - Namespace Region Already Locked?
555 * RETURN: None
557 * DESCRIPTION: Break the association between the handler and the region
558 * this is a two way association.
560 ******************************************************************************/
562 void
563 AcpiEvDetachRegion(
564 ACPI_OPERAND_OBJECT *RegionObj,
565 BOOLEAN AcpiNsIsLocked)
567 ACPI_OPERAND_OBJECT *HandlerObj;
568 ACPI_OPERAND_OBJECT *ObjDesc;
569 ACPI_OPERAND_OBJECT **LastObjPtr;
570 ACPI_ADR_SPACE_SETUP RegionSetup;
571 void **RegionContext;
572 ACPI_OPERAND_OBJECT *RegionObj2;
573 ACPI_STATUS Status;
576 ACPI_FUNCTION_TRACE (EvDetachRegion);
579 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
580 if (!RegionObj2)
582 return_VOID;
584 RegionContext = &RegionObj2->Extra.RegionContext;
586 /* Get the address handler from the region object */
588 HandlerObj = RegionObj->Region.Handler;
589 if (!HandlerObj)
591 /* This region has no handler, all done */
593 return_VOID;
596 /* Find this region in the handler's list */
598 ObjDesc = HandlerObj->AddressSpace.RegionList;
599 LastObjPtr = &HandlerObj->AddressSpace.RegionList;
601 while (ObjDesc)
603 /* Is this the correct Region? */
605 if (ObjDesc == RegionObj)
607 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
608 "Removing Region %p from address handler %p\n",
609 RegionObj, HandlerObj));
611 /* This is it, remove it from the handler's list */
613 *LastObjPtr = ObjDesc->Region.Next;
614 ObjDesc->Region.Next = NULL; /* Must clear field */
616 if (AcpiNsIsLocked)
618 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
619 if (ACPI_FAILURE (Status))
621 return_VOID;
625 /* Now stop region accesses by executing the _REG method */
627 Status = AcpiEvExecuteRegMethod (RegionObj, 0);
628 if (ACPI_FAILURE (Status))
630 ACPI_EXCEPTION ((AE_INFO, Status, "from region _REG, [%s]",
631 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
634 if (AcpiNsIsLocked)
636 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
637 if (ACPI_FAILURE (Status))
639 return_VOID;
644 * If the region has been activated, call the setup handler with
645 * the deactivate notification
647 if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
649 RegionSetup = HandlerObj->AddressSpace.Setup;
650 Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE,
651 HandlerObj->AddressSpace.Context, RegionContext);
653 /* Init routine may fail, Just ignore errors */
655 if (ACPI_FAILURE (Status))
657 ACPI_EXCEPTION ((AE_INFO, Status,
658 "from region handler - deactivate, [%s]",
659 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
662 RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
666 * Remove handler reference in the region
668 * NOTE: this doesn't mean that the region goes away, the region
669 * is just inaccessible as indicated to the _REG method
671 * If the region is on the handler's list, this must be the
672 * region's handler
674 RegionObj->Region.Handler = NULL;
675 AcpiUtRemoveReference (HandlerObj);
677 return_VOID;
680 /* Walk the linked list of handlers */
682 LastObjPtr = &ObjDesc->Region.Next;
683 ObjDesc = ObjDesc->Region.Next;
686 /* If we get here, the region was not in the handler's region list */
688 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
689 "Cannot remove region %p from address handler %p\n",
690 RegionObj, HandlerObj));
692 return_VOID;
696 /*******************************************************************************
698 * FUNCTION: AcpiEvAttachRegion
700 * PARAMETERS: HandlerObj - Handler Object
701 * RegionObj - Region Object
702 * AcpiNsIsLocked - Namespace Region Already Locked?
704 * RETURN: None
706 * DESCRIPTION: Create the association between the handler and the region
707 * this is a two way association.
709 ******************************************************************************/
711 ACPI_STATUS
712 AcpiEvAttachRegion (
713 ACPI_OPERAND_OBJECT *HandlerObj,
714 ACPI_OPERAND_OBJECT *RegionObj,
715 BOOLEAN AcpiNsIsLocked)
718 ACPI_FUNCTION_TRACE (EvAttachRegion);
721 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
722 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
723 AcpiUtGetNodeName (RegionObj->Region.Node),
724 RegionObj, HandlerObj,
725 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
727 /* Link this region to the front of the handler's list */
729 RegionObj->Region.Next = HandlerObj->AddressSpace.RegionList;
730 HandlerObj->AddressSpace.RegionList = RegionObj;
732 /* Install the region's handler */
734 if (RegionObj->Region.Handler)
736 return_ACPI_STATUS (AE_ALREADY_EXISTS);
739 RegionObj->Region.Handler = HandlerObj;
740 AcpiUtAddReference (HandlerObj);
742 return_ACPI_STATUS (AE_OK);
746 /*******************************************************************************
748 * FUNCTION: AcpiEvInstallHandler
750 * PARAMETERS: WalkNamespace callback
752 * DESCRIPTION: This routine installs an address handler into objects that are
753 * of type Region or Device.
755 * If the Object is a Device, and the device has a handler of
756 * the same type then the search is terminated in that branch.
758 * This is because the existing handler is closer in proximity
759 * to any more regions than the one we are trying to install.
761 ******************************************************************************/
763 static ACPI_STATUS
764 AcpiEvInstallHandler (
765 ACPI_HANDLE ObjHandle,
766 UINT32 Level,
767 void *Context,
768 void **ReturnValue)
770 ACPI_OPERAND_OBJECT *HandlerObj;
771 ACPI_OPERAND_OBJECT *NextHandlerObj;
772 ACPI_OPERAND_OBJECT *ObjDesc;
773 ACPI_NAMESPACE_NODE *Node;
774 ACPI_STATUS Status;
777 ACPI_FUNCTION_NAME (EvInstallHandler);
780 HandlerObj = (ACPI_OPERAND_OBJECT *) Context;
782 /* Parameter validation */
784 if (!HandlerObj)
786 return (AE_OK);
789 /* Convert and validate the device handle */
791 Node = AcpiNsMapHandleToNode (ObjHandle);
792 if (!Node)
794 return (AE_BAD_PARAMETER);
798 * We only care about regions and objects that are allowed to have
799 * address space handlers
801 if ((Node->Type != ACPI_TYPE_DEVICE) &&
802 (Node->Type != ACPI_TYPE_REGION) &&
803 (Node != AcpiGbl_RootNode))
805 return (AE_OK);
808 /* Check for an existing internal object */
810 ObjDesc = AcpiNsGetAttachedObject (Node);
811 if (!ObjDesc)
813 /* No object, just exit */
815 return (AE_OK);
818 /* Devices are handled different than regions */
820 if (ObjDesc->Common.Type == ACPI_TYPE_DEVICE)
822 /* Check if this Device already has a handler for this address space */
824 NextHandlerObj = ObjDesc->Device.Handler;
825 while (NextHandlerObj)
827 /* Found a handler, is it for the same address space? */
829 if (NextHandlerObj->AddressSpace.SpaceId ==
830 HandlerObj->AddressSpace.SpaceId)
832 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
833 "Found handler for region [%s] in device %p(%p) "
834 "handler %p\n",
835 AcpiUtGetRegionName (HandlerObj->AddressSpace.SpaceId),
836 ObjDesc, NextHandlerObj, HandlerObj));
839 * Since the object we found it on was a device, then it
840 * means that someone has already installed a handler for
841 * the branch of the namespace from this device on. Just
842 * bail out telling the walk routine to not traverse this
843 * branch. This preserves the scoping rule for handlers.
845 return (AE_CTRL_DEPTH);
848 /* Walk the linked list of handlers attached to this device */
850 NextHandlerObj = NextHandlerObj->AddressSpace.Next;
854 * As long as the device didn't have a handler for this space we
855 * don't care about it. We just ignore it and proceed.
857 return (AE_OK);
860 /* Object is a Region */
862 if (ObjDesc->Region.SpaceId != HandlerObj->AddressSpace.SpaceId)
864 /* This region is for a different address space, just ignore it */
866 return (AE_OK);
870 * Now we have a region and it is for the handler's address space type.
872 * First disconnect region for any previous handler (if any)
874 AcpiEvDetachRegion (ObjDesc, FALSE);
876 /* Connect the region to the new handler */
878 Status = AcpiEvAttachRegion (HandlerObj, ObjDesc, FALSE);
879 return (Status);
883 /*******************************************************************************
885 * FUNCTION: AcpiEvInstallSpaceHandler
887 * PARAMETERS: Node - Namespace node for the device
888 * SpaceId - The address space ID
889 * Handler - Address of the handler
890 * Setup - Address of the setup function
891 * Context - Value passed to the handler on each access
893 * RETURN: Status
895 * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
896 * Assumes namespace is locked
898 ******************************************************************************/
900 ACPI_STATUS
901 AcpiEvInstallSpaceHandler (
902 ACPI_NAMESPACE_NODE *Node,
903 ACPI_ADR_SPACE_TYPE SpaceId,
904 ACPI_ADR_SPACE_HANDLER Handler,
905 ACPI_ADR_SPACE_SETUP Setup,
906 void *Context)
908 ACPI_OPERAND_OBJECT *ObjDesc;
909 ACPI_OPERAND_OBJECT *HandlerObj;
910 ACPI_STATUS Status;
911 ACPI_OBJECT_TYPE Type;
912 UINT8 Flags = 0;
915 ACPI_FUNCTION_TRACE (EvInstallSpaceHandler);
919 * This registration is valid for only the types below and the root. This
920 * is where the default handlers get placed.
922 if ((Node->Type != ACPI_TYPE_DEVICE) &&
923 (Node->Type != ACPI_TYPE_PROCESSOR) &&
924 (Node->Type != ACPI_TYPE_THERMAL) &&
925 (Node != AcpiGbl_RootNode))
927 Status = AE_BAD_PARAMETER;
928 goto UnlockAndExit;
931 if (Handler == ACPI_DEFAULT_HANDLER)
933 Flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
935 switch (SpaceId)
937 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
938 Handler = AcpiExSystemMemorySpaceHandler;
939 Setup = AcpiEvSystemMemoryRegionSetup;
940 break;
942 case ACPI_ADR_SPACE_SYSTEM_IO:
943 Handler = AcpiExSystemIoSpaceHandler;
944 Setup = AcpiEvIoSpaceRegionSetup;
945 break;
947 case ACPI_ADR_SPACE_PCI_CONFIG:
948 Handler = AcpiExPciConfigSpaceHandler;
949 Setup = AcpiEvPciConfigRegionSetup;
950 break;
952 case ACPI_ADR_SPACE_CMOS:
953 Handler = AcpiExCmosSpaceHandler;
954 Setup = AcpiEvCmosRegionSetup;
955 break;
957 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
958 Handler = AcpiExPciBarSpaceHandler;
959 Setup = AcpiEvPciBarRegionSetup;
960 break;
962 case ACPI_ADR_SPACE_DATA_TABLE:
963 Handler = AcpiExDataTableSpaceHandler;
964 Setup = NULL;
965 break;
967 default:
968 Status = AE_BAD_PARAMETER;
969 goto UnlockAndExit;
973 /* If the caller hasn't specified a setup routine, use the default */
975 if (!Setup)
977 Setup = AcpiEvDefaultRegionSetup;
980 /* Check for an existing internal object */
982 ObjDesc = AcpiNsGetAttachedObject (Node);
983 if (ObjDesc)
986 * The attached device object already exists. Make sure the handler
987 * is not already installed.
989 HandlerObj = ObjDesc->Device.Handler;
991 /* Walk the handler list for this device */
993 while (HandlerObj)
995 /* Same SpaceId indicates a handler already installed */
997 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
999 if (HandlerObj->AddressSpace.Handler == Handler)
1002 * It is (relatively) OK to attempt to install the SAME
1003 * handler twice. This can easily happen with the
1004 * PCI_Config space.
1006 Status = AE_SAME_HANDLER;
1007 goto UnlockAndExit;
1009 else
1011 /* A handler is already installed */
1013 Status = AE_ALREADY_EXISTS;
1015 goto UnlockAndExit;
1018 /* Walk the linked list of handlers */
1020 HandlerObj = HandlerObj->AddressSpace.Next;
1023 else
1025 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
1026 "Creating object on Device %p while installing handler\n", Node));
1028 /* ObjDesc does not exist, create one */
1030 if (Node->Type == ACPI_TYPE_ANY)
1032 Type = ACPI_TYPE_DEVICE;
1034 else
1036 Type = Node->Type;
1039 ObjDesc = AcpiUtCreateInternalObject (Type);
1040 if (!ObjDesc)
1042 Status = AE_NO_MEMORY;
1043 goto UnlockAndExit;
1046 /* Init new descriptor */
1048 ObjDesc->Common.Type = (UINT8) Type;
1050 /* Attach the new object to the Node */
1052 Status = AcpiNsAttachObject (Node, ObjDesc, Type);
1054 /* Remove local reference to the object */
1056 AcpiUtRemoveReference (ObjDesc);
1058 if (ACPI_FAILURE (Status))
1060 goto UnlockAndExit;
1064 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
1065 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
1066 AcpiUtGetRegionName (SpaceId), SpaceId,
1067 AcpiUtGetNodeName (Node), Node, ObjDesc));
1070 * Install the handler
1072 * At this point there is no existing handler. Just allocate the object
1073 * for the handler and link it into the list.
1075 HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
1076 if (!HandlerObj)
1078 Status = AE_NO_MEMORY;
1079 goto UnlockAndExit;
1082 /* Init handler obj */
1084 HandlerObj->AddressSpace.SpaceId = (UINT8) SpaceId;
1085 HandlerObj->AddressSpace.HandlerFlags = Flags;
1086 HandlerObj->AddressSpace.RegionList = NULL;
1087 HandlerObj->AddressSpace.Node = Node;
1088 HandlerObj->AddressSpace.Handler = Handler;
1089 HandlerObj->AddressSpace.Context = Context;
1090 HandlerObj->AddressSpace.Setup = Setup;
1092 /* Install at head of Device.AddressSpace list */
1094 HandlerObj->AddressSpace.Next = ObjDesc->Device.Handler;
1097 * The Device object is the first reference on the HandlerObj.
1098 * Each region that uses the handler adds a reference.
1100 ObjDesc->Device.Handler = HandlerObj;
1103 * Walk the namespace finding all of the regions this
1104 * handler will manage.
1106 * Start at the device and search the branch toward
1107 * the leaf nodes until either the leaf is encountered or
1108 * a device is detected that has an address handler of the
1109 * same type.
1111 * In either case, back up and search down the remainder
1112 * of the branch
1114 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
1115 ACPI_NS_WALK_UNLOCK, AcpiEvInstallHandler,
1116 HandlerObj, NULL);
1118 UnlockAndExit:
1119 return_ACPI_STATUS (Status);
1123 /*******************************************************************************
1125 * FUNCTION: AcpiEvExecuteRegMethods
1127 * PARAMETERS: Node - Namespace node for the device
1128 * SpaceId - The address space ID
1130 * RETURN: Status
1132 * DESCRIPTION: Run all _REG methods for the input Space ID;
1133 * Note: assumes namespace is locked, or system init time.
1135 ******************************************************************************/
1137 ACPI_STATUS
1138 AcpiEvExecuteRegMethods (
1139 ACPI_NAMESPACE_NODE *Node,
1140 ACPI_ADR_SPACE_TYPE SpaceId)
1142 ACPI_STATUS Status;
1145 ACPI_FUNCTION_TRACE (EvExecuteRegMethods);
1149 * Run all _REG methods for all Operation Regions for this space ID. This
1150 * is a separate walk in order to handle any interdependencies between
1151 * regions and _REG methods. (i.e. handlers must be installed for all
1152 * regions of this Space ID before we can run any _REG methods)
1154 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
1155 ACPI_NS_WALK_UNLOCK, AcpiEvRegRun,
1156 &SpaceId, NULL);
1158 return_ACPI_STATUS (Status);
1162 /*******************************************************************************
1164 * FUNCTION: AcpiEvRegRun
1166 * PARAMETERS: WalkNamespace callback
1168 * DESCRIPTION: Run _REG method for region objects of the requested spaceID
1170 ******************************************************************************/
1172 static ACPI_STATUS
1173 AcpiEvRegRun (
1174 ACPI_HANDLE ObjHandle,
1175 UINT32 Level,
1176 void *Context,
1177 void **ReturnValue)
1179 ACPI_OPERAND_OBJECT *ObjDesc;
1180 ACPI_NAMESPACE_NODE *Node;
1181 ACPI_ADR_SPACE_TYPE SpaceId;
1182 ACPI_STATUS Status;
1185 SpaceId = *ACPI_CAST_PTR (ACPI_ADR_SPACE_TYPE, Context);
1187 /* Convert and validate the device handle */
1189 Node = AcpiNsMapHandleToNode (ObjHandle);
1190 if (!Node)
1192 return (AE_BAD_PARAMETER);
1196 * We only care about regions.and objects that are allowed to have address
1197 * space handlers
1199 if ((Node->Type != ACPI_TYPE_REGION) &&
1200 (Node != AcpiGbl_RootNode))
1202 return (AE_OK);
1205 /* Check for an existing internal object */
1207 ObjDesc = AcpiNsGetAttachedObject (Node);
1208 if (!ObjDesc)
1210 /* No object, just exit */
1212 return (AE_OK);
1215 /* Object is a Region */
1217 if (ObjDesc->Region.SpaceId != SpaceId)
1219 /* This region is for a different address space, just ignore it */
1221 return (AE_OK);
1224 Status = AcpiEvExecuteRegMethod (ObjDesc, 1);
1225 return (Status);