1 /******************************************************************************
3 * Module Name: evrgnini- ACPI AddressSpace (OpRegion) init
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
118 #define __EVRGNINI_C__
121 #include "acevents.h"
122 #include "acnamesp.h"
124 #define _COMPONENT ACPI_EVENTS
125 ACPI_MODULE_NAME ("evrgnini")
128 /*******************************************************************************
130 * FUNCTION: AcpiEvSystemMemoryRegionSetup
132 * PARAMETERS: Handle - Region we are interested in
133 * Function - Start or stop
134 * HandlerContext - Address space handler context
135 * RegionContext - Region specific context
139 * DESCRIPTION: Do any prep work for region handling, a nop for now
141 ******************************************************************************/
144 AcpiEvSystemMemoryRegionSetup (
147 void *HandlerContext
,
148 void **RegionContext
)
150 ACPI_OPERAND_OBJECT
*RegionDesc
= (ACPI_OPERAND_OBJECT
*) Handle
;
151 ACPI_MEM_SPACE_CONTEXT
*LocalRegionContext
;
154 ACPI_FUNCTION_TRACE ("EvSystemMemoryRegionSetup");
157 if (Function
== ACPI_REGION_DEACTIVATE
)
161 ACPI_MEM_FREE (*RegionContext
);
162 *RegionContext
= NULL
;
164 return_ACPI_STATUS (AE_OK
);
167 /* Create a new context */
169 LocalRegionContext
= ACPI_MEM_CALLOCATE (sizeof (ACPI_MEM_SPACE_CONTEXT
));
170 if (!(LocalRegionContext
))
172 return_ACPI_STATUS (AE_NO_MEMORY
);
175 /* Save the region length and address for use in the handler */
177 LocalRegionContext
->Length
= RegionDesc
->Region
.Length
;
178 LocalRegionContext
->Address
= RegionDesc
->Region
.Address
;
180 *RegionContext
= LocalRegionContext
;
181 return_ACPI_STATUS (AE_OK
);
185 /*******************************************************************************
187 * FUNCTION: AcpiEvIoSpaceRegionSetup
189 * PARAMETERS: Handle - Region we are interested in
190 * Function - Start or stop
191 * HandlerContext - Address space handler context
192 * RegionContext - Region specific context
196 * DESCRIPTION: Do any prep work for region handling
198 ******************************************************************************/
201 AcpiEvIoSpaceRegionSetup (
204 void *HandlerContext
,
205 void **RegionContext
)
207 ACPI_FUNCTION_TRACE ("EvIoSpaceRegionSetup");
210 if (Function
== ACPI_REGION_DEACTIVATE
)
212 *RegionContext
= NULL
;
216 *RegionContext
= HandlerContext
;
219 return_ACPI_STATUS (AE_OK
);
223 /*******************************************************************************
225 * FUNCTION: AcpiEvPciConfigRegionSetup
227 * PARAMETERS: Handle - Region we are interested in
228 * Function - Start or stop
229 * HandlerContext - Address space handler context
230 * RegionContext - Region specific context
234 * DESCRIPTION: Do any prep work for region handling
236 * MUTEX: Assumes namespace is not locked
238 ******************************************************************************/
241 AcpiEvPciConfigRegionSetup (
244 void *HandlerContext
,
245 void **RegionContext
)
247 ACPI_STATUS Status
= AE_OK
;
248 ACPI_INTEGER PciValue
;
249 ACPI_PCI_ID
*PciId
= *RegionContext
;
250 ACPI_OPERAND_OBJECT
*HandlerObj
;
251 ACPI_NAMESPACE_NODE
*ParentNode
;
252 ACPI_NAMESPACE_NODE
*PciRootNode
;
253 ACPI_OPERAND_OBJECT
*RegionObj
= (ACPI_OPERAND_OBJECT
*) Handle
;
254 ACPI_DEVICE_ID ObjectHID
;
257 ACPI_FUNCTION_TRACE ("EvPciConfigRegionSetup");
260 HandlerObj
= RegionObj
->Region
.Handler
;
264 * No installed handler. This shouldn't happen because the dispatch
265 * routine checks before we get here, but we check again just in case.
267 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
268 "Attempting to init a region %p, with no handler\n", RegionObj
));
269 return_ACPI_STATUS (AE_NOT_EXIST
);
272 *RegionContext
= NULL
;
273 if (Function
== ACPI_REGION_DEACTIVATE
)
277 ACPI_MEM_FREE (PciId
);
279 return_ACPI_STATUS (Status
);
282 ParentNode
= AcpiNsGetParentNode (RegionObj
->Region
.Node
);
285 * Get the _SEG and _BBN values from the device upon which the handler
288 * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
289 * This is the device the handler has been registered to handle.
293 * If the AddressSpace.Node is still pointing to the root, we need
294 * to scan upward for a PCI Root bridge and re-associate the OpRegion
295 * handlers with that device.
297 if (HandlerObj
->AddressSpace
.Node
== AcpiGbl_RootNode
)
299 /* Start search from the parent object */
301 PciRootNode
= ParentNode
;
302 while (PciRootNode
!= AcpiGbl_RootNode
)
304 Status
= AcpiUtExecute_HID (PciRootNode
, &ObjectHID
);
305 if (ACPI_SUCCESS (Status
))
307 /* Got a valid _HID, check if this is a PCI root */
309 if (!(ACPI_STRNCMP (ObjectHID
.Value
, PCI_ROOT_HID_STRING
,
310 sizeof (PCI_ROOT_HID_STRING
))))
312 /* Install a handler for this PCI root bridge */
314 Status
= AcpiInstallAddressSpaceHandler ((ACPI_HANDLE
) PciRootNode
,
315 ACPI_ADR_SPACE_PCI_CONFIG
,
316 ACPI_DEFAULT_HANDLER
, NULL
, NULL
);
317 if (ACPI_FAILURE (Status
))
319 if (Status
== AE_SAME_HANDLER
)
322 * It is OK if the handler is already installed on the root
323 * bridge. Still need to return a context object for the
324 * new PCI_Config operation region, however.
331 "Could not install PciConfig handler for Root Bridge %4.4s, %s\n",
332 AcpiUtGetNodeName (PciRootNode
), AcpiFormatException (Status
)));
339 PciRootNode
= AcpiNsGetParentNode (PciRootNode
);
342 /* PCI root bridge not found, use namespace root node */
346 PciRootNode
= HandlerObj
->AddressSpace
.Node
;
350 * If this region is now initialized, we are done.
351 * (InstallAddressSpaceHandler could have initialized it)
353 if (RegionObj
->Region
.Flags
& AOPOBJ_SETUP_COMPLETE
)
355 return_ACPI_STATUS (AE_OK
);
358 /* Region is still not initialized. Create a new context */
360 PciId
= ACPI_MEM_CALLOCATE (sizeof (ACPI_PCI_ID
));
363 return_ACPI_STATUS (AE_NO_MEMORY
);
367 * For PCI_Config space access, we need the segment, bus,
368 * device and function numbers. Acquire them here.
372 * Get the PCI device and function numbers from the _ADR object
373 * contained in the parent's scope.
375 Status
= AcpiUtEvaluateNumericObject (METHOD_NAME__ADR
, ParentNode
, &PciValue
);
378 * The default is zero, and since the allocation above zeroed
379 * the data, just do nothing on failure.
381 if (ACPI_SUCCESS (Status
))
383 PciId
->Device
= ACPI_HIWORD (ACPI_LODWORD (PciValue
));
384 PciId
->Function
= ACPI_LOWORD (ACPI_LODWORD (PciValue
));
387 /* The PCI segment number comes from the _SEG method */
389 Status
= AcpiUtEvaluateNumericObject (METHOD_NAME__SEG
, PciRootNode
, &PciValue
);
390 if (ACPI_SUCCESS (Status
))
392 PciId
->Segment
= ACPI_LOWORD (PciValue
);
395 /* The PCI bus number comes from the _BBN method */
397 Status
= AcpiUtEvaluateNumericObject (METHOD_NAME__BBN
, PciRootNode
, &PciValue
);
398 if (ACPI_SUCCESS (Status
))
400 PciId
->Bus
= ACPI_LOWORD (PciValue
);
403 /* Complete this device's PciId */
405 AcpiOsDerivePciId (PciRootNode
, RegionObj
->Region
.Node
, &PciId
);
407 *RegionContext
= PciId
;
408 return_ACPI_STATUS (AE_OK
);
412 /*******************************************************************************
414 * FUNCTION: AcpiEvPciBarRegionSetup
416 * PARAMETERS: Handle - Region we are interested in
417 * Function - Start or stop
418 * HandlerContext - Address space handler context
419 * RegionContext - Region specific context
423 * DESCRIPTION: Do any prep work for region handling
425 * MUTEX: Assumes namespace is not locked
427 ******************************************************************************/
430 AcpiEvPciBarRegionSetup (
433 void *HandlerContext
,
434 void **RegionContext
)
436 ACPI_FUNCTION_TRACE ("EvPciBarRegionSetup");
439 return_ACPI_STATUS (AE_OK
);
443 /*******************************************************************************
445 * FUNCTION: AcpiEvCmosRegionSetup
447 * PARAMETERS: Handle - Region we are interested in
448 * Function - Start or stop
449 * HandlerContext - Address space handler context
450 * RegionContext - Region specific context
454 * DESCRIPTION: Do any prep work for region handling
456 * MUTEX: Assumes namespace is not locked
458 ******************************************************************************/
461 AcpiEvCmosRegionSetup (
464 void *HandlerContext
,
465 void **RegionContext
)
467 ACPI_FUNCTION_TRACE ("EvCmosRegionSetup");
470 return_ACPI_STATUS (AE_OK
);
474 /*******************************************************************************
476 * FUNCTION: AcpiEvDefaultRegionSetup
478 * PARAMETERS: Handle - Region we are interested in
479 * Function - Start or stop
480 * HandlerContext - Address space handler context
481 * RegionContext - Region specific context
485 * DESCRIPTION: Do any prep work for region handling
487 ******************************************************************************/
490 AcpiEvDefaultRegionSetup (
493 void *HandlerContext
,
494 void **RegionContext
)
496 ACPI_FUNCTION_TRACE ("EvDefaultRegionSetup");
499 if (Function
== ACPI_REGION_DEACTIVATE
)
501 *RegionContext
= NULL
;
505 *RegionContext
= HandlerContext
;
508 return_ACPI_STATUS (AE_OK
);
512 /*******************************************************************************
514 * FUNCTION: AcpiEvInitializeRegion
516 * PARAMETERS: RegionObj - Region we are initializing
517 * AcpiNsLocked - Is namespace locked?
521 * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
522 * for execution at a later time
524 * Get the appropriate address space handler for a newly
527 * This also performs address space specific initialization. For
528 * example, PCI regions must have an _ADR object that contains
529 * a PCI address in the scope of the definition. This address is
530 * required to perform an access to PCI config space.
532 ******************************************************************************/
535 AcpiEvInitializeRegion (
536 ACPI_OPERAND_OBJECT
*RegionObj
,
537 BOOLEAN AcpiNsLocked
)
539 ACPI_OPERAND_OBJECT
*HandlerObj
;
540 ACPI_OPERAND_OBJECT
*ObjDesc
;
541 ACPI_ADR_SPACE_TYPE SpaceId
;
542 ACPI_NAMESPACE_NODE
*Node
;
544 ACPI_NAMESPACE_NODE
*MethodNode
;
545 ACPI_NAME
*RegNamePtr
= (ACPI_NAME
*) METHOD_NAME__REG
;
546 ACPI_OPERAND_OBJECT
*RegionObj2
;
549 ACPI_FUNCTION_TRACE_U32 ("EvInitializeRegion", AcpiNsLocked
);
554 return_ACPI_STATUS (AE_BAD_PARAMETER
);
557 if (RegionObj
->Common
.Flags
& AOPOBJ_OBJECT_INITIALIZED
)
559 return_ACPI_STATUS (AE_OK
);
562 RegionObj2
= AcpiNsGetSecondaryObject (RegionObj
);
565 return_ACPI_STATUS (AE_NOT_EXIST
);
568 Node
= AcpiNsGetParentNode (RegionObj
->Region
.Node
);
569 SpaceId
= RegionObj
->Region
.SpaceId
;
573 RegionObj
->Region
.Handler
= NULL
;
574 RegionObj2
->Extra
.Method_REG
= NULL
;
575 RegionObj
->Common
.Flags
&= ~(AOPOBJ_SETUP_COMPLETE
);
576 RegionObj
->Common
.Flags
|= AOPOBJ_OBJECT_INITIALIZED
;
578 /* Find any "_REG" method associated with this region definition */
580 Status
= AcpiNsSearchNode (*RegNamePtr
, Node
,
581 ACPI_TYPE_METHOD
, &MethodNode
);
582 if (ACPI_SUCCESS (Status
))
585 * The _REG method is optional and there can be only one per region
586 * definition. This will be executed when the handler is attached
589 RegionObj2
->Extra
.Method_REG
= MethodNode
;
593 * The following loop depends upon the root Node having no parent
594 * ie: AcpiGbl_RootNode->ParentEntry being set to NULL
598 /* Check to see if a handler exists */
601 ObjDesc
= AcpiNsGetAttachedObject (Node
);
604 /* Can only be a handler if the object exists */
608 case ACPI_TYPE_DEVICE
:
610 HandlerObj
= ObjDesc
->Device
.Handler
;
613 case ACPI_TYPE_PROCESSOR
:
615 HandlerObj
= ObjDesc
->Processor
.Handler
;
618 case ACPI_TYPE_THERMAL
:
620 HandlerObj
= ObjDesc
->ThermalZone
.Handler
;
624 /* Ignore other objects */
630 /* Is this handler of the correct type? */
632 if (HandlerObj
->AddressSpace
.SpaceId
== SpaceId
)
634 /* Found correct handler */
636 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
637 "Found handler %p for region %p in obj %p\n",
638 HandlerObj
, RegionObj
, ObjDesc
));
640 Status
= AcpiEvAttachRegion (HandlerObj
, RegionObj
,
644 * Tell all users that this region is usable by running the _REG
649 Status
= AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
650 if (ACPI_FAILURE (Status
))
652 return_ACPI_STATUS (Status
);
656 Status
= AcpiEvExecuteRegMethod (RegionObj
, 1);
660 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
661 if (ACPI_FAILURE (Status
))
663 return_ACPI_STATUS (Status
);
667 return_ACPI_STATUS (AE_OK
);
670 /* Try next handler in the list */
672 HandlerObj
= HandlerObj
->AddressSpace
.Next
;
677 * This node does not have the handler we need;
680 Node
= AcpiNsGetParentNode (Node
);
683 /* If we get here, there is no handler for this region */
685 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION
,
686 "No handler for RegionType %s(%X) (RegionObj %p)\n",
687 AcpiUtGetRegionName (SpaceId
), SpaceId
, RegionObj
));
689 return_ACPI_STATUS (AE_NOT_EXIST
);