1 /******************************************************************************
3 * Module Name: evrgnini- ACPI AddressSpace (OpRegion) init
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #define __EVRGNINI_C__
119 #include <contrib/dev/acpica/include/acpi.h>
120 #include <contrib/dev/acpica/include/accommon.h>
121 #include <contrib/dev/acpica/include/acevents.h>
122 #include <contrib/dev/acpica/include/acnamesp.h>
124 #define _COMPONENT ACPI_EVENTS
125 ACPI_MODULE_NAME ("evrgnini")
127 /* Local prototypes */
130 AcpiEvMatchPciRootBridge (
134 AcpiEvIsPciRootBridge (
135 ACPI_NAMESPACE_NODE *Node);
138 /*******************************************************************************
140 * FUNCTION: AcpiEvSystemMemoryRegionSetup
142 * PARAMETERS: Handle - Region we are interested in
143 * Function - Start or stop
144 * HandlerContext - Address space handler context
145 * RegionContext - Region specific context
149 * DESCRIPTION: Setup a SystemMemory operation region
151 ******************************************************************************/
154 AcpiEvSystemMemoryRegionSetup (
157 void *HandlerContext,
158 void **RegionContext)
160 ACPI_OPERAND_OBJECT *RegionDesc = (ACPI_OPERAND_OBJECT *) Handle;
161 ACPI_MEM_SPACE_CONTEXT *LocalRegionContext;
164 ACPI_FUNCTION_TRACE (EvSystemMemoryRegionSetup);
167 if (Function == ACPI_REGION_DEACTIVATE)
171 LocalRegionContext = (ACPI_MEM_SPACE_CONTEXT *) *RegionContext;
173 /* Delete a cached mapping if present */
175 if (LocalRegionContext->MappedLength)
177 AcpiOsUnmapMemory (LocalRegionContext->MappedLogicalAddress,
178 LocalRegionContext->MappedLength);
180 ACPI_FREE (LocalRegionContext);
181 *RegionContext = NULL;
183 return_ACPI_STATUS (AE_OK);
186 /* Create a new context */
188 LocalRegionContext = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_MEM_SPACE_CONTEXT));
189 if (!(LocalRegionContext))
191 return_ACPI_STATUS (AE_NO_MEMORY);
194 /* Save the region length and address for use in the handler */
196 LocalRegionContext->Length = RegionDesc->Region.Length;
197 LocalRegionContext->Address = RegionDesc->Region.Address;
199 *RegionContext = LocalRegionContext;
200 return_ACPI_STATUS (AE_OK);
204 /*******************************************************************************
206 * FUNCTION: AcpiEvIoSpaceRegionSetup
208 * PARAMETERS: Handle - Region we are interested in
209 * Function - Start or stop
210 * HandlerContext - Address space handler context
211 * RegionContext - Region specific context
215 * DESCRIPTION: Setup a IO operation region
217 ******************************************************************************/
220 AcpiEvIoSpaceRegionSetup (
223 void *HandlerContext,
224 void **RegionContext)
226 ACPI_FUNCTION_TRACE (EvIoSpaceRegionSetup);
229 if (Function == ACPI_REGION_DEACTIVATE)
231 *RegionContext = NULL;
235 *RegionContext = HandlerContext;
238 return_ACPI_STATUS (AE_OK);
242 /*******************************************************************************
244 * FUNCTION: AcpiEvPciConfigRegionSetup
246 * PARAMETERS: Handle - Region we are interested in
247 * Function - Start or stop
248 * HandlerContext - Address space handler context
249 * RegionContext - Region specific context
253 * DESCRIPTION: Setup a PCI_Config operation region
255 * MUTEX: Assumes namespace is not locked
257 ******************************************************************************/
260 AcpiEvPciConfigRegionSetup (
263 void *HandlerContext,
264 void **RegionContext)
266 ACPI_STATUS Status = AE_OK;
267 ACPI_INTEGER PciValue;
268 ACPI_PCI_ID *PciId = *RegionContext;
269 ACPI_OPERAND_OBJECT *HandlerObj;
270 ACPI_NAMESPACE_NODE *ParentNode;
271 ACPI_NAMESPACE_NODE *PciRootNode;
272 ACPI_NAMESPACE_NODE *PciDeviceNode;
273 ACPI_OPERAND_OBJECT *RegionObj = (ACPI_OPERAND_OBJECT *) Handle;
276 ACPI_FUNCTION_TRACE (EvPciConfigRegionSetup);
279 HandlerObj = RegionObj->Region.Handler;
283 * No installed handler. This shouldn't happen because the dispatch
284 * routine checks before we get here, but we check again just in case.
286 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
287 "Attempting to init a region %p, with no handler\n", RegionObj));
288 return_ACPI_STATUS (AE_NOT_EXIST);
291 *RegionContext = NULL;
292 if (Function == ACPI_REGION_DEACTIVATE)
298 return_ACPI_STATUS (Status);
301 ParentNode = AcpiNsGetParentNode (RegionObj->Region.Node);
304 * Get the _SEG and _BBN values from the device upon which the handler
307 * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
308 * This is the device the handler has been registered to handle.
312 * If the AddressSpace.Node is still pointing to the root, we need
313 * to scan upward for a PCI Root bridge and re-associate the OpRegion
314 * handlers with that device.
316 if (HandlerObj->AddressSpace.Node == AcpiGbl_RootNode)
318 /* Start search from the parent object */
320 PciRootNode = ParentNode;
321 while (PciRootNode != AcpiGbl_RootNode)
323 /* Get the _HID/_CID in order to detect a RootBridge */
325 if (AcpiEvIsPciRootBridge (PciRootNode))
327 /* Install a handler for this PCI root bridge */
329 Status = AcpiInstallAddressSpaceHandler (
330 (ACPI_HANDLE) PciRootNode,
331 ACPI_ADR_SPACE_PCI_CONFIG,
332 ACPI_DEFAULT_HANDLER, NULL, NULL);
333 if (ACPI_FAILURE (Status))
335 if (Status == AE_SAME_HANDLER)
338 * It is OK if the handler is already installed on the
339 * root bridge. Still need to return a context object
340 * for the new PCI_Config operation region, however.
346 ACPI_EXCEPTION ((AE_INFO, Status,
347 "Could not install PciConfig handler "
348 "for Root Bridge %4.4s",
349 AcpiUtGetNodeName (PciRootNode)));
355 PciRootNode = AcpiNsGetParentNode (PciRootNode);
358 /* PCI root bridge not found, use namespace root node */
362 PciRootNode = HandlerObj->AddressSpace.Node;
366 * If this region is now initialized, we are done.
367 * (InstallAddressSpaceHandler could have initialized it)
369 if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
371 return_ACPI_STATUS (AE_OK);
374 /* Region is still not initialized. Create a new context */
376 PciId = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PCI_ID));
379 return_ACPI_STATUS (AE_NO_MEMORY);
383 * For PCI_Config space access, we need the segment, bus, device and
384 * function numbers. Acquire them here.
386 * Find the parent device object. (This allows the operation region to be
387 * within a subscope under the device, such as a control method.)
389 PciDeviceNode = RegionObj->Region.Node;
390 while (PciDeviceNode && (PciDeviceNode->Type != ACPI_TYPE_DEVICE))
392 PciDeviceNode = AcpiNsGetParentNode (PciDeviceNode);
398 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
402 * Get the PCI device and function numbers from the _ADR object contained
403 * in the parent's scope.
405 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR,
406 PciDeviceNode, &PciValue);
409 * The default is zero, and since the allocation above zeroed the data,
410 * just do nothing on failure.
412 if (ACPI_SUCCESS (Status))
414 PciId->Device = ACPI_HIWORD (ACPI_LODWORD (PciValue));
415 PciId->Function = ACPI_LOWORD (ACPI_LODWORD (PciValue));
418 /* The PCI segment number comes from the _SEG method */
420 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__SEG,
421 PciRootNode, &PciValue);
422 if (ACPI_SUCCESS (Status))
424 PciId->Segment = ACPI_LOWORD (PciValue);
427 /* The PCI bus number comes from the _BBN method */
429 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__BBN,
430 PciRootNode, &PciValue);
431 if (ACPI_SUCCESS (Status))
433 PciId->Bus = ACPI_LOWORD (PciValue);
436 /* Complete this device's PciId */
438 AcpiOsDerivePciId (PciRootNode, RegionObj->Region.Node, &PciId);
440 *RegionContext = PciId;
441 return_ACPI_STATUS (AE_OK);
445 /*******************************************************************************
447 * FUNCTION: AcpiEvMatchPciRootBridge
449 * PARAMETERS: Id - The HID/CID in string format
451 * RETURN: TRUE if the Id is a match for a PCI/PCI-Express Root Bridge
453 * DESCRIPTION: Determine if the input ID is a PCI Root Bridge ID.
455 ******************************************************************************/
458 AcpiEvMatchPciRootBridge (
463 * Check if this is a PCI root.
464 * ACPI 3.0+: check for a PCI Express root also.
466 if (!(ACPI_STRNCMP (Id,
468 sizeof (PCI_ROOT_HID_STRING))) ||
471 PCI_EXPRESS_ROOT_HID_STRING,
472 sizeof (PCI_EXPRESS_ROOT_HID_STRING))))
481 /*******************************************************************************
483 * FUNCTION: AcpiEvIsPciRootBridge
485 * PARAMETERS: Node - Device node being examined
487 * RETURN: TRUE if device is a PCI/PCI-Express Root Bridge
489 * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by
490 * examining the _HID and _CID for the device.
492 ******************************************************************************/
495 AcpiEvIsPciRootBridge (
496 ACPI_NAMESPACE_NODE *Node)
500 ACPI_COMPATIBLE_ID_LIST *Cid;
504 /* Get the _HID and check for a PCI Root Bridge */
506 Status = AcpiUtExecute_HID (Node, &Hid);
507 if (ACPI_FAILURE (Status))
512 if (AcpiEvMatchPciRootBridge (Hid.Value))
517 /* The _HID did not match. Get the _CID and check for a PCI Root Bridge */
519 Status = AcpiUtExecute_CID (Node, &Cid);
520 if (ACPI_FAILURE (Status))
525 /* Check all _CIDs in the returned list */
527 for (i = 0; i < Cid->Count; i++)
529 if (AcpiEvMatchPciRootBridge (Cid->Id[i].Value))
541 /*******************************************************************************
543 * FUNCTION: AcpiEvPciBarRegionSetup
545 * PARAMETERS: Handle - Region we are interested in
546 * Function - Start or stop
547 * HandlerContext - Address space handler context
548 * RegionContext - Region specific context
552 * DESCRIPTION: Setup a PciBAR operation region
554 * MUTEX: Assumes namespace is not locked
556 ******************************************************************************/
559 AcpiEvPciBarRegionSetup (
562 void *HandlerContext,
563 void **RegionContext)
565 ACPI_FUNCTION_TRACE (EvPciBarRegionSetup);
568 return_ACPI_STATUS (AE_OK);
572 /*******************************************************************************
574 * FUNCTION: AcpiEvCmosRegionSetup
576 * PARAMETERS: Handle - Region we are interested in
577 * Function - Start or stop
578 * HandlerContext - Address space handler context
579 * RegionContext - Region specific context
583 * DESCRIPTION: Setup a CMOS operation region
585 * MUTEX: Assumes namespace is not locked
587 ******************************************************************************/
590 AcpiEvCmosRegionSetup (
593 void *HandlerContext,
594 void **RegionContext)
596 ACPI_FUNCTION_TRACE (EvCmosRegionSetup);
599 return_ACPI_STATUS (AE_OK);
603 /*******************************************************************************
605 * FUNCTION: AcpiEvDefaultRegionSetup
607 * PARAMETERS: Handle - Region we are interested in
608 * Function - Start or stop
609 * HandlerContext - Address space handler context
610 * RegionContext - Region specific context
614 * DESCRIPTION: Default region initialization
616 ******************************************************************************/
619 AcpiEvDefaultRegionSetup (
622 void *HandlerContext,
623 void **RegionContext)
625 ACPI_FUNCTION_TRACE (EvDefaultRegionSetup);
628 if (Function == ACPI_REGION_DEACTIVATE)
630 *RegionContext = NULL;
634 *RegionContext = HandlerContext;
637 return_ACPI_STATUS (AE_OK);
641 /*******************************************************************************
643 * FUNCTION: AcpiEvInitializeRegion
645 * PARAMETERS: RegionObj - Region we are initializing
646 * AcpiNsLocked - Is namespace locked?
650 * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
651 * for execution at a later time
653 * Get the appropriate address space handler for a newly
656 * This also performs address space specific initialization. For
657 * example, PCI regions must have an _ADR object that contains
658 * a PCI address in the scope of the definition. This address is
659 * required to perform an access to PCI config space.
661 * MUTEX: Interpreter should be unlocked, because we may run the _REG
662 * method for this region.
664 ******************************************************************************/
667 AcpiEvInitializeRegion (
668 ACPI_OPERAND_OBJECT *RegionObj,
669 BOOLEAN AcpiNsLocked)
671 ACPI_OPERAND_OBJECT *HandlerObj;
672 ACPI_OPERAND_OBJECT *ObjDesc;
673 ACPI_ADR_SPACE_TYPE SpaceId;
674 ACPI_NAMESPACE_NODE *Node;
676 ACPI_NAMESPACE_NODE *MethodNode;
677 ACPI_NAME *RegNamePtr = (ACPI_NAME *) METHOD_NAME__REG;
678 ACPI_OPERAND_OBJECT *RegionObj2;
681 ACPI_FUNCTION_TRACE_U32 (EvInitializeRegion, AcpiNsLocked);
686 return_ACPI_STATUS (AE_BAD_PARAMETER);
689 if (RegionObj->Common.Flags & AOPOBJ_OBJECT_INITIALIZED)
691 return_ACPI_STATUS (AE_OK);
694 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
697 return_ACPI_STATUS (AE_NOT_EXIST);
700 Node = AcpiNsGetParentNode (RegionObj->Region.Node);
701 SpaceId = RegionObj->Region.SpaceId;
705 RegionObj->Region.Handler = NULL;
706 RegionObj2->Extra.Method_REG = NULL;
707 RegionObj->Common.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
708 RegionObj->Common.Flags |= AOPOBJ_OBJECT_INITIALIZED;
710 /* Find any "_REG" method associated with this region definition */
712 Status = AcpiNsSearchOneScope (
713 *RegNamePtr, Node, ACPI_TYPE_METHOD, &MethodNode);
714 if (ACPI_SUCCESS (Status))
717 * The _REG method is optional and there can be only one per region
718 * definition. This will be executed when the handler is attached
721 RegionObj2->Extra.Method_REG = MethodNode;
725 * The following loop depends upon the root Node having no parent
726 * ie: AcpiGbl_RootNode->ParentEntry being set to NULL
730 /* Check to see if a handler exists */
733 ObjDesc = AcpiNsGetAttachedObject (Node);
736 /* Can only be a handler if the object exists */
740 case ACPI_TYPE_DEVICE:
742 HandlerObj = ObjDesc->Device.Handler;
745 case ACPI_TYPE_PROCESSOR:
747 HandlerObj = ObjDesc->Processor.Handler;
750 case ACPI_TYPE_THERMAL:
752 HandlerObj = ObjDesc->ThermalZone.Handler;
756 /* Ignore other objects */
762 /* Is this handler of the correct type? */
764 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
766 /* Found correct handler */
768 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
769 "Found handler %p for region %p in obj %p\n",
770 HandlerObj, RegionObj, ObjDesc));
772 Status = AcpiEvAttachRegion (HandlerObj, RegionObj,
776 * Tell all users that this region is usable by
777 * running the _REG method
781 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
782 if (ACPI_FAILURE (Status))
784 return_ACPI_STATUS (Status);
788 Status = AcpiEvExecuteRegMethod (RegionObj, 1);
792 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
793 if (ACPI_FAILURE (Status))
795 return_ACPI_STATUS (Status);
799 return_ACPI_STATUS (AE_OK);
802 /* Try next handler in the list */
804 HandlerObj = HandlerObj->AddressSpace.Next;
808 /* This node does not have the handler we need; Pop up one level */
810 Node = AcpiNsGetParentNode (Node);
813 /* If we get here, there is no handler for this region */
815 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
816 "No handler for RegionType %s(%X) (RegionObj %p)\n",
817 AcpiUtGetRegionName (SpaceId), SpaceId, RegionObj));
819 return_ACPI_STATUS (AE_NOT_EXIST);