1 /******************************************************************************
3 * Module Name: evrgnini- ACPI AddressSpace (OpRegion) init
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2016, 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 #include "accommon.h"
118 #include "acevents.h"
119 #include "acnamesp.h"
121 #define _COMPONENT ACPI_EVENTS
122 ACPI_MODULE_NAME ("evrgnini")
124 /* Local prototypes */
127 AcpiEvIsPciRootBridge (
128 ACPI_NAMESPACE_NODE
*Node
);
131 /*******************************************************************************
133 * FUNCTION: AcpiEvSystemMemoryRegionSetup
135 * PARAMETERS: Handle - Region we are interested in
136 * Function - Start or stop
137 * HandlerContext - Address space handler context
138 * RegionContext - Region specific context
142 * DESCRIPTION: Setup a SystemMemory operation region
144 ******************************************************************************/
147 AcpiEvSystemMemoryRegionSetup (
150 void *HandlerContext
,
151 void **RegionContext
)
153 ACPI_OPERAND_OBJECT
*RegionDesc
= (ACPI_OPERAND_OBJECT
*) Handle
;
154 ACPI_MEM_SPACE_CONTEXT
*LocalRegionContext
;
157 ACPI_FUNCTION_TRACE (EvSystemMemoryRegionSetup
);
160 if (Function
== ACPI_REGION_DEACTIVATE
)
164 LocalRegionContext
= (ACPI_MEM_SPACE_CONTEXT
*) *RegionContext
;
166 /* Delete a cached mapping if present */
168 if (LocalRegionContext
->MappedLength
)
170 AcpiOsUnmapMemory (LocalRegionContext
->MappedLogicalAddress
,
171 LocalRegionContext
->MappedLength
);
173 ACPI_FREE (LocalRegionContext
);
174 *RegionContext
= NULL
;
176 return_ACPI_STATUS (AE_OK
);
179 /* Create a new context */
181 LocalRegionContext
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_MEM_SPACE_CONTEXT
));
182 if (!(LocalRegionContext
))
184 return_ACPI_STATUS (AE_NO_MEMORY
);
187 /* Save the region length and address for use in the handler */
189 LocalRegionContext
->Length
= RegionDesc
->Region
.Length
;
190 LocalRegionContext
->Address
= RegionDesc
->Region
.Address
;
192 *RegionContext
= LocalRegionContext
;
193 return_ACPI_STATUS (AE_OK
);
197 /*******************************************************************************
199 * FUNCTION: AcpiEvIoSpaceRegionSetup
201 * PARAMETERS: Handle - Region we are interested in
202 * Function - Start or stop
203 * HandlerContext - Address space handler context
204 * RegionContext - Region specific context
208 * DESCRIPTION: Setup a IO operation region
210 ******************************************************************************/
213 AcpiEvIoSpaceRegionSetup (
216 void *HandlerContext
,
217 void **RegionContext
)
219 ACPI_FUNCTION_TRACE (EvIoSpaceRegionSetup
);
222 if (Function
== ACPI_REGION_DEACTIVATE
)
224 *RegionContext
= NULL
;
228 *RegionContext
= HandlerContext
;
231 return_ACPI_STATUS (AE_OK
);
235 /*******************************************************************************
237 * FUNCTION: AcpiEvPciConfigRegionSetup
239 * PARAMETERS: Handle - Region we are interested in
240 * Function - Start or stop
241 * HandlerContext - Address space handler context
242 * RegionContext - Region specific context
246 * DESCRIPTION: Setup a PCI_Config operation region
248 * MUTEX: Assumes namespace is not locked
250 ******************************************************************************/
253 AcpiEvPciConfigRegionSetup (
256 void *HandlerContext
,
257 void **RegionContext
)
259 ACPI_STATUS Status
= AE_OK
;
261 ACPI_PCI_ID
*PciId
= *RegionContext
;
262 ACPI_OPERAND_OBJECT
*HandlerObj
;
263 ACPI_NAMESPACE_NODE
*ParentNode
;
264 ACPI_NAMESPACE_NODE
*PciRootNode
;
265 ACPI_NAMESPACE_NODE
*PciDeviceNode
;
266 ACPI_OPERAND_OBJECT
*RegionObj
= (ACPI_OPERAND_OBJECT
*) Handle
;
269 ACPI_FUNCTION_TRACE (EvPciConfigRegionSetup
);
272 HandlerObj
= RegionObj
->Region
.Handler
;
276 * No installed handler. This shouldn't happen because the dispatch
277 * routine checks before we get here, but we check again just in case.
279 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
280 "Attempting to init a region %p, with no handler\n", RegionObj
));
281 return_ACPI_STATUS (AE_NOT_EXIST
);
284 *RegionContext
= NULL
;
285 if (Function
== ACPI_REGION_DEACTIVATE
)
291 return_ACPI_STATUS (Status
);
294 ParentNode
= RegionObj
->Region
.Node
->Parent
;
297 * Get the _SEG and _BBN values from the device upon which the handler
300 * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
301 * This is the device the handler has been registered to handle.
305 * If the AddressSpace.Node is still pointing to the root, we need
306 * to scan upward for a PCI Root bridge and re-associate the OpRegion
307 * handlers with that device.
309 if (HandlerObj
->AddressSpace
.Node
== AcpiGbl_RootNode
)
311 /* Start search from the parent object */
313 PciRootNode
= ParentNode
;
314 while (PciRootNode
!= AcpiGbl_RootNode
)
316 /* Get the _HID/_CID in order to detect a RootBridge */
318 if (AcpiEvIsPciRootBridge (PciRootNode
))
320 /* Install a handler for this PCI root bridge */
322 Status
= AcpiInstallAddressSpaceHandler (
323 (ACPI_HANDLE
) PciRootNode
,
324 ACPI_ADR_SPACE_PCI_CONFIG
,
325 ACPI_DEFAULT_HANDLER
, NULL
, NULL
);
326 if (ACPI_FAILURE (Status
))
328 if (Status
== AE_SAME_HANDLER
)
331 * It is OK if the handler is already installed on the
332 * root bridge. Still need to return a context object
333 * for the new PCI_Config operation region, however.
339 ACPI_EXCEPTION ((AE_INFO
, Status
,
340 "Could not install PciConfig handler "
341 "for Root Bridge %4.4s",
342 AcpiUtGetNodeName (PciRootNode
)));
348 PciRootNode
= PciRootNode
->Parent
;
351 /* PCI root bridge not found, use namespace root node */
355 PciRootNode
= HandlerObj
->AddressSpace
.Node
;
359 * If this region is now initialized, we are done.
360 * (InstallAddressSpaceHandler could have initialized it)
362 if (RegionObj
->Region
.Flags
& AOPOBJ_SETUP_COMPLETE
)
364 return_ACPI_STATUS (AE_OK
);
367 /* Region is still not initialized. Create a new context */
369 PciId
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PCI_ID
));
372 return_ACPI_STATUS (AE_NO_MEMORY
);
376 * For PCI_Config space access, we need the segment, bus, device and
377 * function numbers. Acquire them here.
379 * Find the parent device object. (This allows the operation region to be
380 * within a subscope under the device, such as a control method.)
382 PciDeviceNode
= RegionObj
->Region
.Node
;
383 while (PciDeviceNode
&& (PciDeviceNode
->Type
!= ACPI_TYPE_DEVICE
))
385 PciDeviceNode
= PciDeviceNode
->Parent
;
391 return_ACPI_STATUS (AE_AML_OPERAND_TYPE
);
395 * Get the PCI device and function numbers from the _ADR object
396 * contained in the parent's scope.
398 Status
= AcpiUtEvaluateNumericObject (METHOD_NAME__ADR
,
399 PciDeviceNode
, &PciValue
);
402 * The default is zero, and since the allocation above zeroed the data,
403 * just do nothing on failure.
405 if (ACPI_SUCCESS (Status
))
407 PciId
->Device
= ACPI_HIWORD (ACPI_LODWORD (PciValue
));
408 PciId
->Function
= ACPI_LOWORD (ACPI_LODWORD (PciValue
));
411 /* The PCI segment number comes from the _SEG method */
413 Status
= AcpiUtEvaluateNumericObject (METHOD_NAME__SEG
,
414 PciRootNode
, &PciValue
);
415 if (ACPI_SUCCESS (Status
))
417 PciId
->Segment
= ACPI_LOWORD (PciValue
);
420 /* The PCI bus number comes from the _BBN method */
422 Status
= AcpiUtEvaluateNumericObject (METHOD_NAME__BBN
,
423 PciRootNode
, &PciValue
);
424 if (ACPI_SUCCESS (Status
))
426 PciId
->Bus
= ACPI_LOWORD (PciValue
);
429 /* Complete/update the PCI ID for this device */
431 Status
= AcpiHwDerivePciId (PciId
, PciRootNode
, RegionObj
->Region
.Node
);
432 if (ACPI_FAILURE (Status
))
435 return_ACPI_STATUS (Status
);
438 *RegionContext
= PciId
;
439 return_ACPI_STATUS (AE_OK
);
443 /*******************************************************************************
445 * FUNCTION: AcpiEvIsPciRootBridge
447 * PARAMETERS: Node - Device node being examined
449 * RETURN: TRUE if device is a PCI/PCI-Express Root Bridge
451 * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by
452 * examining the _HID and _CID for the device.
454 ******************************************************************************/
457 AcpiEvIsPciRootBridge (
458 ACPI_NAMESPACE_NODE
*Node
)
461 ACPI_PNP_DEVICE_ID
*Hid
;
462 ACPI_PNP_DEVICE_ID_LIST
*Cid
;
467 /* Get the _HID and check for a PCI Root Bridge */
469 Status
= AcpiUtExecute_HID (Node
, &Hid
);
470 if (ACPI_FAILURE (Status
))
475 Match
= AcpiUtIsPciRootBridge (Hid
->String
);
483 /* The _HID did not match. Get the _CID and check for a PCI Root Bridge */
485 Status
= AcpiUtExecute_CID (Node
, &Cid
);
486 if (ACPI_FAILURE (Status
))
491 /* Check all _CIDs in the returned list */
493 for (i
= 0; i
< Cid
->Count
; i
++)
495 if (AcpiUtIsPciRootBridge (Cid
->Ids
[i
].String
))
507 /*******************************************************************************
509 * FUNCTION: AcpiEvPciBarRegionSetup
511 * PARAMETERS: Handle - Region we are interested in
512 * Function - Start or stop
513 * HandlerContext - Address space handler context
514 * RegionContext - Region specific context
518 * DESCRIPTION: Setup a PciBAR operation region
520 * MUTEX: Assumes namespace is not locked
522 ******************************************************************************/
525 AcpiEvPciBarRegionSetup (
528 void *HandlerContext
,
529 void **RegionContext
)
531 ACPI_FUNCTION_TRACE (EvPciBarRegionSetup
);
534 return_ACPI_STATUS (AE_OK
);
538 /*******************************************************************************
540 * FUNCTION: AcpiEvCmosRegionSetup
542 * PARAMETERS: Handle - Region we are interested in
543 * Function - Start or stop
544 * HandlerContext - Address space handler context
545 * RegionContext - Region specific context
549 * DESCRIPTION: Setup a CMOS operation region
551 * MUTEX: Assumes namespace is not locked
553 ******************************************************************************/
556 AcpiEvCmosRegionSetup (
559 void *HandlerContext
,
560 void **RegionContext
)
562 ACPI_FUNCTION_TRACE (EvCmosRegionSetup
);
565 return_ACPI_STATUS (AE_OK
);
569 /*******************************************************************************
571 * FUNCTION: AcpiEvDefaultRegionSetup
573 * PARAMETERS: Handle - Region we are interested in
574 * Function - Start or stop
575 * HandlerContext - Address space handler context
576 * RegionContext - Region specific context
580 * DESCRIPTION: Default region initialization
582 ******************************************************************************/
585 AcpiEvDefaultRegionSetup (
588 void *HandlerContext
,
589 void **RegionContext
)
591 ACPI_FUNCTION_TRACE (EvDefaultRegionSetup
);
594 if (Function
== ACPI_REGION_DEACTIVATE
)
596 *RegionContext
= NULL
;
600 *RegionContext
= HandlerContext
;
603 return_ACPI_STATUS (AE_OK
);
607 /*******************************************************************************
609 * FUNCTION: AcpiEvInitializeRegion
611 * PARAMETERS: RegionObj - Region we are initializing
612 * AcpiNsLocked - Is namespace locked?
616 * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
617 * for execution at a later time
619 * Get the appropriate address space handler for a newly
622 * This also performs address space specific initialization. For
623 * example, PCI regions must have an _ADR object that contains
624 * a PCI address in the scope of the definition. This address is
625 * required to perform an access to PCI config space.
627 * MUTEX: Interpreter should be unlocked, because we may run the _REG
628 * method for this region.
630 ******************************************************************************/
633 AcpiEvInitializeRegion (
634 ACPI_OPERAND_OBJECT
*RegionObj
,
635 BOOLEAN AcpiNsLocked
)
637 ACPI_OPERAND_OBJECT
*HandlerObj
;
638 ACPI_OPERAND_OBJECT
*ObjDesc
;
639 ACPI_ADR_SPACE_TYPE SpaceId
;
640 ACPI_NAMESPACE_NODE
*Node
;
644 ACPI_FUNCTION_TRACE_U32 (EvInitializeRegion
, AcpiNsLocked
);
649 return_ACPI_STATUS (AE_BAD_PARAMETER
);
652 if (RegionObj
->Common
.Flags
& AOPOBJ_OBJECT_INITIALIZED
)
654 return_ACPI_STATUS (AE_OK
);
657 AcpiEvAssociateRegMethod (RegionObj
);
658 RegionObj
->Common
.Flags
|= AOPOBJ_OBJECT_INITIALIZED
;
660 Node
= RegionObj
->Region
.Node
->Parent
;
661 SpaceId
= RegionObj
->Region
.SpaceId
;
664 * The following loop depends upon the root Node having no parent
665 * ie: AcpiGbl_RootNode->Parent being set to NULL
669 /* Check to see if a handler exists */
672 ObjDesc
= AcpiNsGetAttachedObject (Node
);
675 /* Can only be a handler if the object exists */
679 case ACPI_TYPE_DEVICE
:
680 case ACPI_TYPE_PROCESSOR
:
681 case ACPI_TYPE_THERMAL
:
683 HandlerObj
= ObjDesc
->CommonNotify
.Handler
;
686 case ACPI_TYPE_METHOD
:
688 * If we are executing module level code, the original
689 * Node's object was replaced by this Method object and we
690 * saved the handler in the method object.
692 * See AcpiNsExecModuleCode
694 if (ObjDesc
->Method
.InfoFlags
& ACPI_METHOD_MODULE_LEVEL
)
696 HandlerObj
= ObjDesc
->Method
.Dispatch
.Handler
;
702 /* Ignore other objects */
707 HandlerObj
= AcpiEvFindRegionHandler (SpaceId
, HandlerObj
);
710 /* Found correct handler */
712 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
713 "Found handler %p for region %p in obj %p\n",
714 HandlerObj
, RegionObj
, ObjDesc
));
716 Status
= AcpiEvAttachRegion (HandlerObj
, RegionObj
,
720 * Tell all users that this region is usable by
721 * running the _REG method
725 Status
= AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
726 if (ACPI_FAILURE (Status
))
728 return_ACPI_STATUS (Status
);
732 Status
= AcpiEvExecuteRegMethod (RegionObj
, ACPI_REG_CONNECT
);
736 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
737 if (ACPI_FAILURE (Status
))
739 return_ACPI_STATUS (Status
);
743 return_ACPI_STATUS (AE_OK
);
747 /* This node does not have the handler we need; Pop up one level */
752 /* If we get here, there is no handler for this region */
754 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
755 "No handler for RegionType %s(%X) (RegionObj %p)\n",
756 AcpiUtGetRegionName (SpaceId
), SpaceId
, RegionObj
));
758 return_ACPI_STATUS (AE_NOT_EXIST
);