1 /******************************************************************************
3 * Module Name: evrgnini- ACPI AddressSpace (OpRegion) init
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #define __EVRGNINI_C__
52 #define _COMPONENT ACPI_EVENTS
53 ACPI_MODULE_NAME ("evrgnini")
55 /* Local prototypes */
58 AcpiEvIsPciRootBridge (
59 ACPI_NAMESPACE_NODE *Node);
62 /*******************************************************************************
64 * FUNCTION: AcpiEvSystemMemoryRegionSetup
66 * PARAMETERS: Handle - Region we are interested in
67 * Function - Start or stop
68 * HandlerContext - Address space handler context
69 * RegionContext - Region specific context
73 * DESCRIPTION: Setup a SystemMemory operation region
75 ******************************************************************************/
78 AcpiEvSystemMemoryRegionSetup (
84 ACPI_OPERAND_OBJECT *RegionDesc = (ACPI_OPERAND_OBJECT *) Handle;
85 ACPI_MEM_SPACE_CONTEXT *LocalRegionContext;
88 ACPI_FUNCTION_TRACE (EvSystemMemoryRegionSetup);
91 if (Function == ACPI_REGION_DEACTIVATE)
95 LocalRegionContext = (ACPI_MEM_SPACE_CONTEXT *) *RegionContext;
97 /* Delete a cached mapping if present */
99 if (LocalRegionContext->MappedLength)
101 AcpiOsUnmapMemory (LocalRegionContext->MappedLogicalAddress,
102 LocalRegionContext->MappedLength);
104 ACPI_FREE (LocalRegionContext);
105 *RegionContext = NULL;
107 return_ACPI_STATUS (AE_OK);
110 /* Create a new context */
112 LocalRegionContext = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_MEM_SPACE_CONTEXT));
113 if (!(LocalRegionContext))
115 return_ACPI_STATUS (AE_NO_MEMORY);
118 /* Save the region length and address for use in the handler */
120 LocalRegionContext->Length = RegionDesc->Region.Length;
121 LocalRegionContext->Address = RegionDesc->Region.Address;
123 *RegionContext = LocalRegionContext;
124 return_ACPI_STATUS (AE_OK);
128 /*******************************************************************************
130 * FUNCTION: AcpiEvIoSpaceRegionSetup
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: Setup a IO operation region
141 ******************************************************************************/
144 AcpiEvIoSpaceRegionSetup (
147 void *HandlerContext,
148 void **RegionContext)
150 ACPI_FUNCTION_TRACE (EvIoSpaceRegionSetup);
153 if (Function == ACPI_REGION_DEACTIVATE)
155 *RegionContext = NULL;
159 *RegionContext = HandlerContext;
162 return_ACPI_STATUS (AE_OK);
166 /*******************************************************************************
168 * FUNCTION: AcpiEvPciConfigRegionSetup
170 * PARAMETERS: Handle - Region we are interested in
171 * Function - Start or stop
172 * HandlerContext - Address space handler context
173 * RegionContext - Region specific context
177 * DESCRIPTION: Setup a PCI_Config operation region
179 * MUTEX: Assumes namespace is not locked
181 ******************************************************************************/
184 AcpiEvPciConfigRegionSetup (
187 void *HandlerContext,
188 void **RegionContext)
190 ACPI_STATUS Status = AE_OK;
192 ACPI_PCI_ID *PciId = *RegionContext;
193 ACPI_OPERAND_OBJECT *HandlerObj;
194 ACPI_NAMESPACE_NODE *ParentNode;
195 ACPI_NAMESPACE_NODE *PciRootNode;
196 ACPI_NAMESPACE_NODE *PciDeviceNode;
197 ACPI_OPERAND_OBJECT *RegionObj = (ACPI_OPERAND_OBJECT *) Handle;
200 ACPI_FUNCTION_TRACE (EvPciConfigRegionSetup);
203 HandlerObj = RegionObj->Region.Handler;
207 * No installed handler. This shouldn't happen because the dispatch
208 * routine checks before we get here, but we check again just in case.
210 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
211 "Attempting to init a region %p, with no handler\n", RegionObj));
212 return_ACPI_STATUS (AE_NOT_EXIST);
215 *RegionContext = NULL;
216 if (Function == ACPI_REGION_DEACTIVATE)
222 return_ACPI_STATUS (Status);
225 ParentNode = RegionObj->Region.Node->Parent;
228 * Get the _SEG and _BBN values from the device upon which the handler
231 * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
232 * This is the device the handler has been registered to handle.
236 * If the AddressSpace.Node is still pointing to the root, we need
237 * to scan upward for a PCI Root bridge and re-associate the OpRegion
238 * handlers with that device.
240 if (HandlerObj->AddressSpace.Node == AcpiGbl_RootNode)
242 /* Start search from the parent object */
244 PciRootNode = ParentNode;
245 while (PciRootNode != AcpiGbl_RootNode)
247 /* Get the _HID/_CID in order to detect a RootBridge */
249 if (AcpiEvIsPciRootBridge (PciRootNode))
251 /* Install a handler for this PCI root bridge */
253 Status = AcpiInstallAddressSpaceHandler (
254 (ACPI_HANDLE) PciRootNode,
255 ACPI_ADR_SPACE_PCI_CONFIG,
256 ACPI_DEFAULT_HANDLER, NULL, NULL);
257 if (ACPI_FAILURE (Status))
259 if (Status == AE_SAME_HANDLER)
262 * It is OK if the handler is already installed on the
263 * root bridge. Still need to return a context object
264 * for the new PCI_Config operation region, however.
270 ACPI_EXCEPTION ((AE_INFO, Status,
271 "Could not install PciConfig handler "
272 "for Root Bridge %4.4s",
273 AcpiUtGetNodeName (PciRootNode)));
279 PciRootNode = PciRootNode->Parent;
282 /* PCI root bridge not found, use namespace root node */
286 PciRootNode = HandlerObj->AddressSpace.Node;
290 * If this region is now initialized, we are done.
291 * (InstallAddressSpaceHandler could have initialized it)
293 if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
295 return_ACPI_STATUS (AE_OK);
298 /* Region is still not initialized. Create a new context */
300 PciId = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PCI_ID));
303 return_ACPI_STATUS (AE_NO_MEMORY);
307 * For PCI_Config space access, we need the segment, bus, device and
308 * function numbers. Acquire them here.
310 * Find the parent device object. (This allows the operation region to be
311 * within a subscope under the device, such as a control method.)
313 PciDeviceNode = RegionObj->Region.Node;
314 while (PciDeviceNode && (PciDeviceNode->Type != ACPI_TYPE_DEVICE))
316 PciDeviceNode = PciDeviceNode->Parent;
322 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
326 * Get the PCI device and function numbers from the _ADR object
327 * contained in the parent's scope.
329 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR,
330 PciDeviceNode, &PciValue);
333 * The default is zero, and since the allocation above zeroed the data,
334 * just do nothing on failure.
336 if (ACPI_SUCCESS (Status))
338 PciId->Device = ACPI_HIWORD (ACPI_LODWORD (PciValue));
339 PciId->Function = ACPI_LOWORD (ACPI_LODWORD (PciValue));
342 /* The PCI segment number comes from the _SEG method */
344 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__SEG,
345 PciRootNode, &PciValue);
346 if (ACPI_SUCCESS (Status))
348 PciId->Segment = ACPI_LOWORD (PciValue);
351 /* The PCI bus number comes from the _BBN method */
353 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__BBN,
354 PciRootNode, &PciValue);
355 if (ACPI_SUCCESS (Status))
357 PciId->Bus = ACPI_LOWORD (PciValue);
360 /* Complete/update the PCI ID for this device */
362 Status = AcpiHwDerivePciId (PciId, PciRootNode, RegionObj->Region.Node);
363 if (ACPI_FAILURE (Status))
366 return_ACPI_STATUS (Status);
369 *RegionContext = PciId;
370 return_ACPI_STATUS (AE_OK);
374 /*******************************************************************************
376 * FUNCTION: AcpiEvIsPciRootBridge
378 * PARAMETERS: Node - Device node being examined
380 * RETURN: TRUE if device is a PCI/PCI-Express Root Bridge
382 * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by
383 * examining the _HID and _CID for the device.
385 ******************************************************************************/
388 AcpiEvIsPciRootBridge (
389 ACPI_NAMESPACE_NODE *Node)
393 ACPI_DEVICE_ID_LIST *Cid;
398 /* Get the _HID and check for a PCI Root Bridge */
400 Status = AcpiUtExecute_HID (Node, &Hid);
401 if (ACPI_FAILURE (Status))
406 Match = AcpiUtIsPciRootBridge (Hid->String);
414 /* The _HID did not match. Get the _CID and check for a PCI Root Bridge */
416 Status = AcpiUtExecute_CID (Node, &Cid);
417 if (ACPI_FAILURE (Status))
422 /* Check all _CIDs in the returned list */
424 for (i = 0; i < Cid->Count; i++)
426 if (AcpiUtIsPciRootBridge (Cid->Ids[i].String))
438 /*******************************************************************************
440 * FUNCTION: AcpiEvPciBarRegionSetup
442 * PARAMETERS: Handle - Region we are interested in
443 * Function - Start or stop
444 * HandlerContext - Address space handler context
445 * RegionContext - Region specific context
449 * DESCRIPTION: Setup a PciBAR operation region
451 * MUTEX: Assumes namespace is not locked
453 ******************************************************************************/
456 AcpiEvPciBarRegionSetup (
459 void *HandlerContext,
460 void **RegionContext)
462 ACPI_FUNCTION_TRACE (EvPciBarRegionSetup);
465 return_ACPI_STATUS (AE_OK);
469 /*******************************************************************************
471 * FUNCTION: AcpiEvCmosRegionSetup
473 * PARAMETERS: Handle - Region we are interested in
474 * Function - Start or stop
475 * HandlerContext - Address space handler context
476 * RegionContext - Region specific context
480 * DESCRIPTION: Setup a CMOS operation region
482 * MUTEX: Assumes namespace is not locked
484 ******************************************************************************/
487 AcpiEvCmosRegionSetup (
490 void *HandlerContext,
491 void **RegionContext)
493 ACPI_FUNCTION_TRACE (EvCmosRegionSetup);
496 return_ACPI_STATUS (AE_OK);
500 /*******************************************************************************
502 * FUNCTION: AcpiEvDefaultRegionSetup
504 * PARAMETERS: Handle - Region we are interested in
505 * Function - Start or stop
506 * HandlerContext - Address space handler context
507 * RegionContext - Region specific context
511 * DESCRIPTION: Default region initialization
513 ******************************************************************************/
516 AcpiEvDefaultRegionSetup (
519 void *HandlerContext,
520 void **RegionContext)
522 ACPI_FUNCTION_TRACE (EvDefaultRegionSetup);
525 if (Function == ACPI_REGION_DEACTIVATE)
527 *RegionContext = NULL;
531 *RegionContext = HandlerContext;
534 return_ACPI_STATUS (AE_OK);
538 /*******************************************************************************
540 * FUNCTION: AcpiEvInitializeRegion
542 * PARAMETERS: RegionObj - Region we are initializing
543 * AcpiNsLocked - Is namespace locked?
547 * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
548 * for execution at a later time
550 * Get the appropriate address space handler for a newly
553 * This also performs address space specific initialization. For
554 * example, PCI regions must have an _ADR object that contains
555 * a PCI address in the scope of the definition. This address is
556 * required to perform an access to PCI config space.
558 * MUTEX: Interpreter should be unlocked, because we may run the _REG
559 * method for this region.
561 ******************************************************************************/
564 AcpiEvInitializeRegion (
565 ACPI_OPERAND_OBJECT *RegionObj,
566 BOOLEAN AcpiNsLocked)
568 ACPI_OPERAND_OBJECT *HandlerObj;
569 ACPI_OPERAND_OBJECT *ObjDesc;
570 ACPI_ADR_SPACE_TYPE SpaceId;
571 ACPI_NAMESPACE_NODE *Node;
573 ACPI_NAMESPACE_NODE *MethodNode;
574 ACPI_NAME *RegNamePtr = (ACPI_NAME *) METHOD_NAME__REG;
575 ACPI_OPERAND_OBJECT *RegionObj2;
578 ACPI_FUNCTION_TRACE_U32 (EvInitializeRegion, AcpiNsLocked);
583 return_ACPI_STATUS (AE_BAD_PARAMETER);
586 if (RegionObj->Common.Flags & AOPOBJ_OBJECT_INITIALIZED)
588 return_ACPI_STATUS (AE_OK);
591 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
594 return_ACPI_STATUS (AE_NOT_EXIST);
597 Node = RegionObj->Region.Node->Parent;
598 SpaceId = RegionObj->Region.SpaceId;
602 RegionObj->Region.Handler = NULL;
603 RegionObj2->Extra.Method_REG = NULL;
604 RegionObj->Common.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
605 RegionObj->Common.Flags |= AOPOBJ_OBJECT_INITIALIZED;
607 /* Find any "_REG" method associated with this region definition */
609 Status = AcpiNsSearchOneScope (
610 *RegNamePtr, Node, ACPI_TYPE_METHOD, &MethodNode);
611 if (ACPI_SUCCESS (Status))
614 * The _REG method is optional and there can be only one per region
615 * definition. This will be executed when the handler is attached
618 RegionObj2->Extra.Method_REG = MethodNode;
622 * The following loop depends upon the root Node having no parent
623 * ie: AcpiGbl_RootNode->ParentEntry being set to NULL
627 /* Check to see if a handler exists */
630 ObjDesc = AcpiNsGetAttachedObject (Node);
633 /* Can only be a handler if the object exists */
637 case ACPI_TYPE_DEVICE:
639 HandlerObj = ObjDesc->Device.Handler;
642 case ACPI_TYPE_PROCESSOR:
644 HandlerObj = ObjDesc->Processor.Handler;
647 case ACPI_TYPE_THERMAL:
649 HandlerObj = ObjDesc->ThermalZone.Handler;
652 case ACPI_TYPE_METHOD:
654 * If we are executing module level code, the original
655 * Node's object was replaced by this Method object and we
656 * saved the handler in the method object.
658 * See AcpiNsExecModuleCode
660 if (ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL)
662 HandlerObj = ObjDesc->Method.Dispatch.Handler;
667 /* Ignore other objects */
673 /* Is this handler of the correct type? */
675 if (HandlerObj->AddressSpace.SpaceId == SpaceId)
677 /* Found correct handler */
679 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
680 "Found handler %p for region %p in obj %p\n",
681 HandlerObj, RegionObj, ObjDesc));
683 Status = AcpiEvAttachRegion (HandlerObj, RegionObj,
687 * Tell all users that this region is usable by
688 * running the _REG method
692 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
693 if (ACPI_FAILURE (Status))
695 return_ACPI_STATUS (Status);
699 Status = AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_CONNECT);
703 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
704 if (ACPI_FAILURE (Status))
706 return_ACPI_STATUS (Status);
710 return_ACPI_STATUS (AE_OK);
713 /* Try next handler in the list */
715 HandlerObj = HandlerObj->AddressSpace.Next;
719 /* This node does not have the handler we need; Pop up one level */
724 /* If we get here, there is no handler for this region */
726 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
727 "No handler for RegionType %s(%X) (RegionObj %p)\n",
728 AcpiUtGetRegionName (SpaceId), SpaceId, RegionObj));
730 return_ACPI_STATUS (AE_NOT_EXIST);