1 /******************************************************************************
3 * Module Name: evregion - Operation Region support
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2019, 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 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acevents.h>
155 #include <contrib/dev/acpica/include/acnamesp.h>
156 #include <contrib/dev/acpica/include/acinterp.h>
158 #define _COMPONENT ACPI_EVENTS
159 ACPI_MODULE_NAME ("evregion")
162 extern UINT8 AcpiGbl_DefaultAddressSpaces[];
164 /* Local prototypes */
167 AcpiEvOrphanEcRegMethod (
168 ACPI_NAMESPACE_NODE *EcDeviceNode);
172 ACPI_HANDLE ObjHandle,
178 /*******************************************************************************
180 * FUNCTION: AcpiEvInitializeOpRegions
186 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
187 * an installed default region handler.
189 ******************************************************************************/
192 AcpiEvInitializeOpRegions (
199 ACPI_FUNCTION_TRACE (EvInitializeOpRegions);
202 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
203 if (ACPI_FAILURE (Status))
205 return_ACPI_STATUS (Status);
208 /* Run the _REG methods for OpRegions in each default address space */
210 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++)
213 * Make sure the installed handler is the DEFAULT handler. If not the
214 * default, the _REG methods will have already been run (when the
215 * handler was installed)
217 if (AcpiEvHasDefaultHandler (AcpiGbl_RootNode,
218 AcpiGbl_DefaultAddressSpaces[i]))
220 AcpiEvExecuteRegMethods (AcpiGbl_RootNode,
221 AcpiGbl_DefaultAddressSpaces[i], ACPI_REG_CONNECT);
225 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
226 return_ACPI_STATUS (Status);
230 /*******************************************************************************
232 * FUNCTION: AcpiEvAddressSpaceDispatch
234 * PARAMETERS: RegionObj - Internal region object
235 * FieldObj - Corresponding field. Can be NULL.
236 * Function - Read or Write operation
237 * RegionOffset - Where in the region to read or write
238 * BitWidth - Field width in bits (8, 16, 32, or 64)
239 * Value - Pointer to in or out value, must be
240 * a full 64-bit integer
244 * DESCRIPTION: Dispatch an address space or operation region access to
245 * a previously installed handler.
247 * NOTE: During early initialization, we always install the default region
248 * handlers for Memory, I/O and PCI_Config. This ensures that these operation
249 * region address spaces are always available as per the ACPI specification.
250 * This is especially needed in order to support the execution of
251 * module-level AML code during loading of the ACPI tables.
253 ******************************************************************************/
256 AcpiEvAddressSpaceDispatch (
257 ACPI_OPERAND_OBJECT *RegionObj,
258 ACPI_OPERAND_OBJECT *FieldObj,
265 ACPI_ADR_SPACE_HANDLER Handler;
266 ACPI_ADR_SPACE_SETUP RegionSetup;
267 ACPI_OPERAND_OBJECT *HandlerDesc;
268 ACPI_OPERAND_OBJECT *RegionObj2;
269 void *RegionContext = NULL;
270 ACPI_CONNECTION_INFO *Context;
271 ACPI_PHYSICAL_ADDRESS Address;
274 ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch);
277 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
280 return_ACPI_STATUS (AE_NOT_EXIST);
283 /* Ensure that there is a handler associated with this region */
285 HandlerDesc = RegionObj->Region.Handler;
288 ACPI_ERROR ((AE_INFO,
289 "No handler for Region [%4.4s] (%p) [%s]",
290 AcpiUtGetNodeName (RegionObj->Region.Node),
291 RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
293 return_ACPI_STATUS (AE_NOT_EXIST);
296 Context = HandlerDesc->AddressSpace.Context;
299 * It may be the case that the region has never been initialized.
300 * Some types of regions require special init code
302 if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
304 /* This region has not been initialized yet, do it */
306 RegionSetup = HandlerDesc->AddressSpace.Setup;
309 /* No initialization routine, exit with error */
311 ACPI_ERROR ((AE_INFO,
312 "No init routine for region(%p) [%s]",
313 RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
314 return_ACPI_STATUS (AE_NOT_EXIST);
318 * We must exit the interpreter because the region setup will
319 * potentially execute control methods (for example, the _REG method
322 AcpiExExitInterpreter ();
324 Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE,
325 Context, &RegionContext);
327 /* Re-enter the interpreter */
329 AcpiExEnterInterpreter ();
331 /* Check for failure of the Region Setup */
333 if (ACPI_FAILURE (Status))
335 ACPI_EXCEPTION ((AE_INFO, Status,
336 "During region initialization: [%s]",
337 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
338 return_ACPI_STATUS (Status);
341 /* Region initialization may have been completed by RegionSetup */
343 if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE))
345 RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE;
348 * Save the returned context for use in all accesses to
349 * the handler for this particular region
351 if (!(RegionObj2->Extra.RegionContext))
353 RegionObj2->Extra.RegionContext = RegionContext;
358 /* We have everything we need, we can invoke the address space handler */
360 Handler = HandlerDesc->AddressSpace.Handler;
361 Address = (RegionObj->Region.Address + RegionOffset);
364 * Special handling for GenericSerialBus and GeneralPurposeIo:
365 * There are three extra parameters that must be passed to the
366 * handler via the context:
367 * 1) Connection buffer, a resource template from Connection() op
368 * 2) Length of the above buffer
369 * 3) Actual access length from the AccessAs() op
371 * In addition, for GeneralPurposeIo, the Address and BitWidth fields
372 * are defined as follows:
373 * 1) Address is the pin number index of the field (bit offset from
374 * the previous Connection)
375 * 2) BitWidth is the actual bit length of the field (number of pins)
377 if ((RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS) &&
381 /* Get the Connection (ResourceTemplate) buffer */
383 Context->Connection = FieldObj->Field.ResourceBuffer;
384 Context->Length = FieldObj->Field.ResourceLength;
385 Context->AccessLength = FieldObj->Field.AccessLength;
387 if ((RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO) &&
391 /* Get the Connection (ResourceTemplate) buffer */
393 Context->Connection = FieldObj->Field.ResourceBuffer;
394 Context->Length = FieldObj->Field.ResourceLength;
395 Context->AccessLength = FieldObj->Field.AccessLength;
396 Address = FieldObj->Field.PinNumberIndex;
397 BitWidth = FieldObj->Field.BitLength;
400 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
401 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
402 &RegionObj->Region.Handler->AddressSpace, Handler,
403 ACPI_FORMAT_UINT64 (Address),
404 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
406 if (!(HandlerDesc->AddressSpace.HandlerFlags &
407 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
410 * For handlers other than the default (supplied) handlers, we must
411 * exit the interpreter because the handler *might* block -- we don't
412 * know what it will do, so we can't hold the lock on the interpreter.
414 AcpiExExitInterpreter();
417 /* Call the handler */
419 Status = Handler (Function, Address, BitWidth, Value, Context,
420 RegionObj2->Extra.RegionContext);
422 if (ACPI_FAILURE (Status))
424 ACPI_EXCEPTION ((AE_INFO, Status, "Returned by Handler for [%s]",
425 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
428 * Special case for an EC timeout. These are seen so frequently
429 * that an additional error message is helpful
431 if ((RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) &&
434 ACPI_ERROR ((AE_INFO,
435 "Timeout from EC hardware or EC device driver"));
439 if (!(HandlerDesc->AddressSpace.HandlerFlags &
440 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
443 * We just returned from a non-default handler, we must re-enter the
446 AcpiExEnterInterpreter ();
449 return_ACPI_STATUS (Status);
453 /*******************************************************************************
455 * FUNCTION: AcpiEvDetachRegion
457 * PARAMETERS: RegionObj - Region Object
458 * AcpiNsIsLocked - Namespace Region Already Locked?
462 * DESCRIPTION: Break the association between the handler and the region
463 * this is a two way association.
465 ******************************************************************************/
469 ACPI_OPERAND_OBJECT *RegionObj,
470 BOOLEAN AcpiNsIsLocked)
472 ACPI_OPERAND_OBJECT *HandlerObj;
473 ACPI_OPERAND_OBJECT *ObjDesc;
474 ACPI_OPERAND_OBJECT *StartDesc;
475 ACPI_OPERAND_OBJECT **LastObjPtr;
476 ACPI_ADR_SPACE_SETUP RegionSetup;
477 void **RegionContext;
478 ACPI_OPERAND_OBJECT *RegionObj2;
482 ACPI_FUNCTION_TRACE (EvDetachRegion);
485 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
490 RegionContext = &RegionObj2->Extra.RegionContext;
492 /* Get the address handler from the region object */
494 HandlerObj = RegionObj->Region.Handler;
497 /* This region has no handler, all done */
502 /* Find this region in the handler's list */
504 ObjDesc = HandlerObj->AddressSpace.RegionList;
506 LastObjPtr = &HandlerObj->AddressSpace.RegionList;
510 /* Is this the correct Region? */
512 if (ObjDesc == RegionObj)
514 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
515 "Removing Region %p from address handler %p\n",
516 RegionObj, HandlerObj));
518 /* This is it, remove it from the handler's list */
520 *LastObjPtr = ObjDesc->Region.Next;
521 ObjDesc->Region.Next = NULL; /* Must clear field */
525 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
526 if (ACPI_FAILURE (Status))
532 /* Now stop region accesses by executing the _REG method */
534 Status = AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_DISCONNECT);
535 if (ACPI_FAILURE (Status))
537 ACPI_EXCEPTION ((AE_INFO, Status, "from region _REG, [%s]",
538 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
543 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
544 if (ACPI_FAILURE (Status))
551 * If the region has been activated, call the setup handler with
552 * the deactivate notification
554 if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
556 RegionSetup = HandlerObj->AddressSpace.Setup;
557 Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE,
558 HandlerObj->AddressSpace.Context, RegionContext);
561 * RegionContext should have been released by the deactivate
562 * operation. We don't need access to it anymore here.
566 *RegionContext = NULL;
569 /* Init routine may fail, Just ignore errors */
571 if (ACPI_FAILURE (Status))
573 ACPI_EXCEPTION ((AE_INFO, Status,
574 "from region handler - deactivate, [%s]",
575 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
578 RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
582 * Remove handler reference in the region
584 * NOTE: this doesn't mean that the region goes away, the region
585 * is just inaccessible as indicated to the _REG method
587 * If the region is on the handler's list, this must be the
590 RegionObj->Region.Handler = NULL;
591 AcpiUtRemoveReference (HandlerObj);
596 /* Walk the linked list of handlers */
598 LastObjPtr = &ObjDesc->Region.Next;
599 ObjDesc = ObjDesc->Region.Next;
601 /* Prevent infinite loop if list is corrupted */
603 if (ObjDesc == StartDesc)
605 ACPI_ERROR ((AE_INFO,
606 "Circular handler list in region object %p",
612 /* If we get here, the region was not in the handler's region list */
614 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
615 "Cannot remove region %p from address handler %p\n",
616 RegionObj, HandlerObj));
622 /*******************************************************************************
624 * FUNCTION: AcpiEvAttachRegion
626 * PARAMETERS: HandlerObj - Handler Object
627 * RegionObj - Region Object
628 * AcpiNsIsLocked - Namespace Region Already Locked?
632 * DESCRIPTION: Create the association between the handler and the region
633 * this is a two way association.
635 ******************************************************************************/
639 ACPI_OPERAND_OBJECT *HandlerObj,
640 ACPI_OPERAND_OBJECT *RegionObj,
641 BOOLEAN AcpiNsIsLocked)
644 ACPI_FUNCTION_TRACE (EvAttachRegion);
647 /* Install the region's handler */
649 if (RegionObj->Region.Handler)
651 return_ACPI_STATUS (AE_ALREADY_EXISTS);
654 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
655 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
656 AcpiUtGetNodeName (RegionObj->Region.Node),
657 RegionObj, HandlerObj,
658 AcpiUtGetRegionName (RegionObj->Region.SpaceId)));
660 /* Link this region to the front of the handler's list */
662 RegionObj->Region.Next = HandlerObj->AddressSpace.RegionList;
663 HandlerObj->AddressSpace.RegionList = RegionObj;
664 RegionObj->Region.Handler = HandlerObj;
665 AcpiUtAddReference (HandlerObj);
667 return_ACPI_STATUS (AE_OK);
671 /*******************************************************************************
673 * FUNCTION: AcpiEvExecuteRegMethod
675 * PARAMETERS: RegionObj - Region object
676 * Function - Passed to _REG: On (1) or Off (0)
680 * DESCRIPTION: Execute _REG method for a region
682 ******************************************************************************/
685 AcpiEvExecuteRegMethod (
686 ACPI_OPERAND_OBJECT *RegionObj,
689 ACPI_EVALUATE_INFO *Info;
690 ACPI_OPERAND_OBJECT *Args[3];
691 ACPI_OPERAND_OBJECT *RegionObj2;
692 const ACPI_NAME *RegNamePtr = ACPI_CAST_PTR (ACPI_NAME, METHOD_NAME__REG);
693 ACPI_NAMESPACE_NODE *MethodNode;
694 ACPI_NAMESPACE_NODE *Node;
698 ACPI_FUNCTION_TRACE (EvExecuteRegMethod);
701 if (!AcpiGbl_NamespaceInitialized ||
702 RegionObj->Region.Handler == NULL)
704 return_ACPI_STATUS (AE_OK);
707 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
710 return_ACPI_STATUS (AE_NOT_EXIST);
714 * Find any "_REG" method associated with this region definition.
715 * The method should always be updated as this function may be
716 * invoked after a namespace change.
718 Node = RegionObj->Region.Node->Parent;
719 Status = AcpiNsSearchOneScope (
720 *RegNamePtr, Node, ACPI_TYPE_METHOD, &MethodNode);
721 if (ACPI_SUCCESS (Status))
724 * The _REG method is optional and there can be only one per
725 * region definition. This will be executed when the handler is
726 * attached or removed.
728 RegionObj2->Extra.Method_REG = MethodNode;
730 if (RegionObj2->Extra.Method_REG == NULL)
732 return_ACPI_STATUS (AE_OK);
735 /* _REG(DISCONNECT) should be paired with _REG(CONNECT) */
737 if ((Function == ACPI_REG_CONNECT &&
738 RegionObj->Common.Flags & AOPOBJ_REG_CONNECTED) ||
739 (Function == ACPI_REG_DISCONNECT &&
740 !(RegionObj->Common.Flags & AOPOBJ_REG_CONNECTED)))
742 return_ACPI_STATUS (AE_OK);
745 /* Allocate and initialize the evaluation information block */
747 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
750 return_ACPI_STATUS (AE_NO_MEMORY);
753 Info->PrefixNode = RegionObj2->Extra.Method_REG;
754 Info->RelativePathname = NULL;
755 Info->Parameters = Args;
756 Info->Flags = ACPI_IGNORE_RETURN_VALUE;
759 * The _REG method has two arguments:
762 * Operation region space ID Same value as RegionObj->Region.SpaceId
765 * connection status 1 for connecting the handler, 0 for disconnecting
766 * the handler (Passed as a parameter)
768 Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId);
771 Status = AE_NO_MEMORY;
775 Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function);
778 Status = AE_NO_MEMORY;
782 Args[2] = NULL; /* Terminate list */
784 /* Execute the method, no return value */
787 AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL));
789 Status = AcpiNsEvaluate (Info);
790 AcpiUtRemoveReference (Args[1]);
792 if (ACPI_FAILURE (Status))
797 if (Function == ACPI_REG_CONNECT)
799 RegionObj->Common.Flags |= AOPOBJ_REG_CONNECTED;
803 RegionObj->Common.Flags &= ~AOPOBJ_REG_CONNECTED;
807 AcpiUtRemoveReference (Args[0]);
811 return_ACPI_STATUS (Status);
815 /*******************************************************************************
817 * FUNCTION: AcpiEvExecuteRegMethods
819 * PARAMETERS: Node - Namespace node for the device
820 * SpaceId - The address space ID
821 * Function - Passed to _REG: On (1) or Off (0)
825 * DESCRIPTION: Run all _REG methods for the input Space ID;
826 * Note: assumes namespace is locked, or system init time.
828 ******************************************************************************/
831 AcpiEvExecuteRegMethods (
832 ACPI_NAMESPACE_NODE *Node,
833 ACPI_ADR_SPACE_TYPE SpaceId,
836 ACPI_REG_WALK_INFO Info;
839 ACPI_FUNCTION_TRACE (EvExecuteRegMethods);
842 * These address spaces do not need a call to _REG, since the ACPI
843 * specification defines them as: "must always be accessible". Since
844 * they never change state (never become unavailable), no need to ever
845 * call _REG on them. Also, a DataTable is not a "real" address space,
846 * so do not call _REG. September 2018.
848 if ((SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY) ||
849 (SpaceId == ACPI_ADR_SPACE_SYSTEM_IO) ||
850 (SpaceId == ACPI_ADR_SPACE_DATA_TABLE))
855 Info.SpaceId = SpaceId;
856 Info.Function = Function;
857 Info.RegRunCount = 0;
859 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_NAMES,
860 " Running _REG methods for SpaceId %s\n",
861 AcpiUtGetRegionName (Info.SpaceId)));
864 * Run all _REG methods for all Operation Regions for this space ID. This
865 * is a separate walk in order to handle any interdependencies between
866 * regions and _REG methods. (i.e. handlers must be installed for all
867 * regions of this Space ID before we can run any _REG methods)
869 (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX,
870 ACPI_NS_WALK_UNLOCK, AcpiEvRegRun, NULL, &Info, NULL);
872 /* Special case for EC: handle "orphan" _REG methods with no region */
874 if (SpaceId == ACPI_ADR_SPACE_EC)
876 AcpiEvOrphanEcRegMethod (Node);
879 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_NAMES,
880 " Executed %u _REG methods for SpaceId %s\n",
881 Info.RegRunCount, AcpiUtGetRegionName (Info.SpaceId)));
887 /*******************************************************************************
889 * FUNCTION: AcpiEvRegRun
891 * PARAMETERS: WalkNamespace callback
893 * DESCRIPTION: Run _REG method for region objects of the requested spaceID
895 ******************************************************************************/
899 ACPI_HANDLE ObjHandle,
904 ACPI_OPERAND_OBJECT *ObjDesc;
905 ACPI_NAMESPACE_NODE *Node;
907 ACPI_REG_WALK_INFO *Info;
910 Info = ACPI_CAST_PTR (ACPI_REG_WALK_INFO, Context);
912 /* Convert and validate the device handle */
914 Node = AcpiNsValidateHandle (ObjHandle);
917 return (AE_BAD_PARAMETER);
921 * We only care about regions and objects that are allowed to have
922 * address space handlers
924 if ((Node->Type != ACPI_TYPE_REGION) &&
925 (Node != AcpiGbl_RootNode))
930 /* Check for an existing internal object */
932 ObjDesc = AcpiNsGetAttachedObject (Node);
935 /* No object, just exit */
940 /* Object is a Region */
942 if (ObjDesc->Region.SpaceId != Info->SpaceId)
944 /* This region is for a different address space, just ignore it */
950 Status = AcpiEvExecuteRegMethod (ObjDesc, Info->Function);
955 /*******************************************************************************
957 * FUNCTION: AcpiEvOrphanEcRegMethod
959 * PARAMETERS: EcDeviceNode - Namespace node for an EC device
963 * DESCRIPTION: Execute an "orphan" _REG method that appears under the EC
964 * device. This is a _REG method that has no corresponding region
965 * within the EC device scope. The orphan _REG method appears to
966 * have been enabled by the description of the ECDT in the ACPI
967 * specification: "The availability of the region space can be
968 * detected by providing a _REG method object underneath the
969 * Embedded Controller device."
971 * To quickly access the EC device, we use the EcDeviceNode used
972 * during EC handler installation. Otherwise, we would need to
973 * perform a time consuming namespace walk, executing _HID
974 * methods to find the EC device.
976 * MUTEX: Assumes the namespace is locked
978 ******************************************************************************/
981 AcpiEvOrphanEcRegMethod (
982 ACPI_NAMESPACE_NODE *EcDeviceNode)
984 ACPI_HANDLE RegMethod;
985 ACPI_NAMESPACE_NODE *NextNode;
987 ACPI_OBJECT_LIST Args;
988 ACPI_OBJECT Objects[2];
991 ACPI_FUNCTION_TRACE (EvOrphanEcRegMethod);
999 /* Namespace is currently locked, must release */
1001 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1003 /* Get a handle to a _REG method immediately under the EC device */
1005 Status = AcpiGetHandle (EcDeviceNode, METHOD_NAME__REG, &RegMethod);
1006 if (ACPI_FAILURE (Status))
1008 goto Exit; /* There is no _REG method present */
1012 * Execute the _REG method only if there is no Operation Region in
1013 * this scope with the Embedded Controller space ID. Otherwise, it
1014 * will already have been executed. Note, this allows for Regions
1015 * with other space IDs to be present; but the code below will then
1016 * execute the _REG method with the EmbeddedControl SpaceID argument.
1018 NextNode = AcpiNsGetNextNode (EcDeviceNode, NULL);
1021 if ((NextNode->Type == ACPI_TYPE_REGION) &&
1022 (NextNode->Object) &&
1023 (NextNode->Object->Region.SpaceId == ACPI_ADR_SPACE_EC))
1025 goto Exit; /* Do not execute the _REG */
1028 NextNode = AcpiNsGetNextNode (EcDeviceNode, NextNode);
1031 /* Evaluate the _REG(EmbeddedControl,Connect) method */
1034 Args.Pointer = Objects;
1035 Objects[0].Type = ACPI_TYPE_INTEGER;
1036 Objects[0].Integer.Value = ACPI_ADR_SPACE_EC;
1037 Objects[1].Type = ACPI_TYPE_INTEGER;
1038 Objects[1].Integer.Value = ACPI_REG_CONNECT;
1040 Status = AcpiEvaluateObject (RegMethod, NULL, &Args, NULL);
1043 /* We ignore all errors from above, don't care */
1045 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);