1 /******************************************************************************
3 * Module Name: evrgnini- ACPI AddressSpace (OpRegion) init
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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.
49 #define _COMPONENT ACPI_EVENTS
50 ACPI_MODULE_NAME ("evrgnini")
52 /* Local prototypes */
55 AcpiEvIsPciRootBridge (
56 ACPI_NAMESPACE_NODE *Node);
59 /*******************************************************************************
61 * FUNCTION: AcpiEvSystemMemoryRegionSetup
63 * PARAMETERS: Handle - Region we are interested in
64 * Function - Start or stop
65 * HandlerContext - Address space handler context
66 * RegionContext - Region specific context
70 * DESCRIPTION: Setup a SystemMemory operation region
72 ******************************************************************************/
75 AcpiEvSystemMemoryRegionSetup (
81 ACPI_OPERAND_OBJECT *RegionDesc = (ACPI_OPERAND_OBJECT *) Handle;
82 ACPI_MEM_SPACE_CONTEXT *LocalRegionContext;
85 ACPI_FUNCTION_TRACE (EvSystemMemoryRegionSetup);
88 if (Function == ACPI_REGION_DEACTIVATE)
92 LocalRegionContext = (ACPI_MEM_SPACE_CONTEXT *) *RegionContext;
94 /* Delete a cached mapping if present */
96 if (LocalRegionContext->MappedLength)
98 AcpiOsUnmapMemory (LocalRegionContext->MappedLogicalAddress,
99 LocalRegionContext->MappedLength);
101 ACPI_FREE (LocalRegionContext);
102 *RegionContext = NULL;
104 return_ACPI_STATUS (AE_OK);
107 /* Create a new context */
109 LocalRegionContext = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_MEM_SPACE_CONTEXT));
110 if (!(LocalRegionContext))
112 return_ACPI_STATUS (AE_NO_MEMORY);
115 /* Save the region length and address for use in the handler */
117 LocalRegionContext->Length = RegionDesc->Region.Length;
118 LocalRegionContext->Address = RegionDesc->Region.Address;
120 *RegionContext = LocalRegionContext;
121 return_ACPI_STATUS (AE_OK);
125 /*******************************************************************************
127 * FUNCTION: AcpiEvIoSpaceRegionSetup
129 * PARAMETERS: Handle - Region we are interested in
130 * Function - Start or stop
131 * HandlerContext - Address space handler context
132 * RegionContext - Region specific context
136 * DESCRIPTION: Setup a IO operation region
138 ******************************************************************************/
141 AcpiEvIoSpaceRegionSetup (
144 void *HandlerContext,
145 void **RegionContext)
147 ACPI_FUNCTION_TRACE (EvIoSpaceRegionSetup);
150 if (Function == ACPI_REGION_DEACTIVATE)
152 *RegionContext = NULL;
156 *RegionContext = HandlerContext;
159 return_ACPI_STATUS (AE_OK);
163 /*******************************************************************************
165 * FUNCTION: AcpiEvPciConfigRegionSetup
167 * PARAMETERS: Handle - Region we are interested in
168 * Function - Start or stop
169 * HandlerContext - Address space handler context
170 * RegionContext - Region specific context
174 * DESCRIPTION: Setup a PCI_Config operation region
176 * MUTEX: Assumes namespace is not locked
178 ******************************************************************************/
181 AcpiEvPciConfigRegionSetup (
184 void *HandlerContext,
185 void **RegionContext)
187 ACPI_STATUS Status = AE_OK;
189 ACPI_PCI_ID *PciId = *RegionContext;
190 ACPI_OPERAND_OBJECT *HandlerObj;
191 ACPI_NAMESPACE_NODE *ParentNode;
192 ACPI_NAMESPACE_NODE *PciRootNode;
193 ACPI_NAMESPACE_NODE *PciDeviceNode;
194 ACPI_OPERAND_OBJECT *RegionObj = (ACPI_OPERAND_OBJECT *) Handle;
197 ACPI_FUNCTION_TRACE (EvPciConfigRegionSetup);
200 HandlerObj = RegionObj->Region.Handler;
204 * No installed handler. This shouldn't happen because the dispatch
205 * routine checks before we get here, but we check again just in case.
207 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
208 "Attempting to init a region %p, with no handler\n", RegionObj));
209 return_ACPI_STATUS (AE_NOT_EXIST);
212 *RegionContext = NULL;
213 if (Function == ACPI_REGION_DEACTIVATE)
219 return_ACPI_STATUS (Status);
222 ParentNode = RegionObj->Region.Node->Parent;
225 * Get the _SEG and _BBN values from the device upon which the handler
228 * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
229 * This is the device the handler has been registered to handle.
233 * If the AddressSpace.Node is still pointing to the root, we need
234 * to scan upward for a PCI Root bridge and re-associate the OpRegion
235 * handlers with that device.
237 if (HandlerObj->AddressSpace.Node == AcpiGbl_RootNode)
239 /* Start search from the parent object */
241 PciRootNode = ParentNode;
242 while (PciRootNode != AcpiGbl_RootNode)
244 /* Get the _HID/_CID in order to detect a RootBridge */
246 if (AcpiEvIsPciRootBridge (PciRootNode))
248 /* Install a handler for this PCI root bridge */
250 Status = AcpiInstallAddressSpaceHandler (
251 (ACPI_HANDLE) PciRootNode,
252 ACPI_ADR_SPACE_PCI_CONFIG,
253 ACPI_DEFAULT_HANDLER, NULL, NULL);
254 if (ACPI_FAILURE (Status))
256 if (Status == AE_SAME_HANDLER)
259 * It is OK if the handler is already installed on the
260 * root bridge. Still need to return a context object
261 * for the new PCI_Config operation region, however.
267 ACPI_EXCEPTION ((AE_INFO, Status,
268 "Could not install PciConfig handler "
269 "for Root Bridge %4.4s",
270 AcpiUtGetNodeName (PciRootNode)));
276 PciRootNode = PciRootNode->Parent;
279 /* PCI root bridge not found, use namespace root node */
283 PciRootNode = HandlerObj->AddressSpace.Node;
287 * If this region is now initialized, we are done.
288 * (InstallAddressSpaceHandler could have initialized it)
290 if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
292 return_ACPI_STATUS (AE_OK);
295 /* Region is still not initialized. Create a new context */
297 PciId = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PCI_ID));
300 return_ACPI_STATUS (AE_NO_MEMORY);
304 * For PCI_Config space access, we need the segment, bus, device and
305 * function numbers. Acquire them here.
307 * Find the parent device object. (This allows the operation region to be
308 * within a subscope under the device, such as a control method.)
310 PciDeviceNode = RegionObj->Region.Node;
311 while (PciDeviceNode && (PciDeviceNode->Type != ACPI_TYPE_DEVICE))
313 PciDeviceNode = PciDeviceNode->Parent;
319 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
323 * Get the PCI device and function numbers from the _ADR object
324 * contained in the parent's scope.
326 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR,
327 PciDeviceNode, &PciValue);
330 * The default is zero, and since the allocation above zeroed the data,
331 * just do nothing on failure.
333 if (ACPI_SUCCESS (Status))
335 PciId->Device = ACPI_HIWORD (ACPI_LODWORD (PciValue));
336 PciId->Function = ACPI_LOWORD (ACPI_LODWORD (PciValue));
339 /* The PCI segment number comes from the _SEG method */
341 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__SEG,
342 PciRootNode, &PciValue);
343 if (ACPI_SUCCESS (Status))
345 PciId->Segment = ACPI_LOWORD (PciValue);
348 /* The PCI bus number comes from the _BBN method */
350 Status = AcpiUtEvaluateNumericObject (METHOD_NAME__BBN,
351 PciRootNode, &PciValue);
352 if (ACPI_SUCCESS (Status))
354 PciId->Bus = ACPI_LOWORD (PciValue);
357 /* Complete/update the PCI ID for this device */
359 Status = AcpiHwDerivePciId (PciId, PciRootNode, RegionObj->Region.Node);
360 if (ACPI_FAILURE (Status))
363 return_ACPI_STATUS (Status);
366 *RegionContext = PciId;
367 return_ACPI_STATUS (AE_OK);
371 /*******************************************************************************
373 * FUNCTION: AcpiEvIsPciRootBridge
375 * PARAMETERS: Node - Device node being examined
377 * RETURN: TRUE if device is a PCI/PCI-Express Root Bridge
379 * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by
380 * examining the _HID and _CID for the device.
382 ******************************************************************************/
385 AcpiEvIsPciRootBridge (
386 ACPI_NAMESPACE_NODE *Node)
389 ACPI_PNP_DEVICE_ID *Hid;
390 ACPI_PNP_DEVICE_ID_LIST *Cid;
395 /* Get the _HID and check for a PCI Root Bridge */
397 Status = AcpiUtExecute_HID (Node, &Hid);
398 if (ACPI_FAILURE (Status))
403 Match = AcpiUtIsPciRootBridge (Hid->String);
411 /* The _HID did not match. Get the _CID and check for a PCI Root Bridge */
413 Status = AcpiUtExecute_CID (Node, &Cid);
414 if (ACPI_FAILURE (Status))
419 /* Check all _CIDs in the returned list */
421 for (i = 0; i < Cid->Count; i++)
423 if (AcpiUtIsPciRootBridge (Cid->Ids[i].String))
435 /*******************************************************************************
437 * FUNCTION: AcpiEvPciBarRegionSetup
439 * PARAMETERS: Handle - Region we are interested in
440 * Function - Start or stop
441 * HandlerContext - Address space handler context
442 * RegionContext - Region specific context
446 * DESCRIPTION: Setup a PciBAR operation region
448 * MUTEX: Assumes namespace is not locked
450 ******************************************************************************/
453 AcpiEvPciBarRegionSetup (
456 void *HandlerContext,
457 void **RegionContext)
459 ACPI_FUNCTION_TRACE (EvPciBarRegionSetup);
462 return_ACPI_STATUS (AE_OK);
466 /*******************************************************************************
468 * FUNCTION: AcpiEvCmosRegionSetup
470 * PARAMETERS: Handle - Region we are interested in
471 * Function - Start or stop
472 * HandlerContext - Address space handler context
473 * RegionContext - Region specific context
477 * DESCRIPTION: Setup a CMOS operation region
479 * MUTEX: Assumes namespace is not locked
481 ******************************************************************************/
484 AcpiEvCmosRegionSetup (
487 void *HandlerContext,
488 void **RegionContext)
490 ACPI_FUNCTION_TRACE (EvCmosRegionSetup);
493 return_ACPI_STATUS (AE_OK);
497 /*******************************************************************************
499 * FUNCTION: AcpiEvDefaultRegionSetup
501 * PARAMETERS: Handle - Region we are interested in
502 * Function - Start or stop
503 * HandlerContext - Address space handler context
504 * RegionContext - Region specific context
508 * DESCRIPTION: Default region initialization
510 ******************************************************************************/
513 AcpiEvDefaultRegionSetup (
516 void *HandlerContext,
517 void **RegionContext)
519 ACPI_FUNCTION_TRACE (EvDefaultRegionSetup);
522 if (Function == ACPI_REGION_DEACTIVATE)
524 *RegionContext = NULL;
528 *RegionContext = HandlerContext;
531 return_ACPI_STATUS (AE_OK);
535 /*******************************************************************************
537 * FUNCTION: AcpiEvInitializeRegion
539 * PARAMETERS: RegionObj - Region we are initializing
540 * AcpiNsLocked - Is namespace locked?
544 * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
545 * for execution at a later time
547 * Get the appropriate address space handler for a newly
550 * This also performs address space specific initialization. For
551 * example, PCI regions must have an _ADR object that contains
552 * a PCI address in the scope of the definition. This address is
553 * required to perform an access to PCI config space.
555 * MUTEX: Interpreter should be unlocked, because we may run the _REG
556 * method for this region.
558 ******************************************************************************/
561 AcpiEvInitializeRegion (
562 ACPI_OPERAND_OBJECT *RegionObj,
563 BOOLEAN AcpiNsLocked)
565 ACPI_OPERAND_OBJECT *HandlerObj;
566 ACPI_OPERAND_OBJECT *ObjDesc;
567 ACPI_ADR_SPACE_TYPE SpaceId;
568 ACPI_NAMESPACE_NODE *Node;
572 ACPI_FUNCTION_TRACE_U32 (EvInitializeRegion, AcpiNsLocked);
577 return_ACPI_STATUS (AE_BAD_PARAMETER);
580 if (RegionObj->Common.Flags & AOPOBJ_OBJECT_INITIALIZED)
582 return_ACPI_STATUS (AE_OK);
585 RegionObj->Common.Flags |= AOPOBJ_OBJECT_INITIALIZED;
587 Node = RegionObj->Region.Node->Parent;
588 SpaceId = RegionObj->Region.SpaceId;
591 * The following loop depends upon the root Node having no parent
592 * ie: AcpiGbl_RootNode->Parent being set to NULL
596 /* Check to see if a handler exists */
599 ObjDesc = AcpiNsGetAttachedObject (Node);
602 /* Can only be a handler if the object exists */
606 case ACPI_TYPE_DEVICE:
607 case ACPI_TYPE_PROCESSOR:
608 case ACPI_TYPE_THERMAL:
610 HandlerObj = ObjDesc->CommonNotify.Handler;
613 case ACPI_TYPE_METHOD:
615 * If we are executing module level code, the original
616 * Node's object was replaced by this Method object and we
617 * saved the handler in the method object.
619 * See AcpiNsExecModuleCode
621 if (!AcpiGbl_ParseTableAsTermList &&
622 ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL)
624 HandlerObj = ObjDesc->Method.Dispatch.Handler;
630 /* Ignore other objects */
635 HandlerObj = AcpiEvFindRegionHandler (SpaceId, HandlerObj);
638 /* Found correct handler */
640 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
641 "Found handler %p for region %p in obj %p\n",
642 HandlerObj, RegionObj, ObjDesc));
644 Status = AcpiEvAttachRegion (HandlerObj, RegionObj,
648 * Tell all users that this region is usable by
649 * running the _REG method
653 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
654 if (ACPI_FAILURE (Status))
656 return_ACPI_STATUS (Status);
660 Status = AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_CONNECT);
664 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
665 if (ACPI_FAILURE (Status))
667 return_ACPI_STATUS (Status);
671 return_ACPI_STATUS (AE_OK);
675 /* This node does not have the handler we need; Pop up one level */
680 /* If we get here, there is no handler for this region */
682 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
683 "No handler for RegionType %s(%X) (RegionObj %p)\n",
684 AcpiUtGetRegionName (SpaceId), SpaceId, RegionObj));
686 return_ACPI_STATUS (AE_NOT_EXIST);