13446Smrj /******************************************************************************
23446Smrj *
33446Smrj * Module Name: evrgnini- ACPI AddressSpace (OpRegion) init
43446Smrj *
53446Smrj *****************************************************************************/
63446Smrj
73446Smrj /******************************************************************************
83446Smrj *
93446Smrj * 1. Copyright Notice
103446Smrj *
119980SDana.Myers@Sun.COM * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj * All rights reserved.
133446Smrj *
143446Smrj * 2. License
153446Smrj *
163446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj * rights. You may have additional license terms from the party that provided
183446Smrj * you this software, covering your right to use that party's intellectual
193446Smrj * property rights.
203446Smrj *
213446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj * copy of the source code appearing in this file ("Covered Code") an
233446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj * make derivatives, distribute, use and display any portion of the Covered
263446Smrj * Code in any form, with the right to sublicense such rights; and
273446Smrj *
283446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj * license (with the right to sublicense), under only those claims of Intel
303446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj * solely to the minimum extent necessary to exercise the above copyright
333446Smrj * license, and in no event shall the patent license extend to any additions
343446Smrj * to or modifications of the Original Intel Code. No other license or right
353446Smrj * is granted directly or by implication, estoppel or otherwise;
363446Smrj *
373446Smrj * The above copyright and patent license is granted only if the following
383446Smrj * conditions are met:
393446Smrj *
403446Smrj * 3. Conditions
413446Smrj *
423446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj * Redistribution of source code of any substantial portion of the Covered
443446Smrj * Code or modification with rights to further distribute source must include
453446Smrj * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj * and the following Disclaimer and Export Compliance provision. In addition,
473446Smrj * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj * contain a file documenting the changes Licensee made to create that Covered
493446Smrj * Code and the date of any change. Licensee must include in that file the
503446Smrj * documentation of any changes made by any predecessor Licensee. Licensee
513446Smrj * must include a prominent statement that the modification is derived,
523446Smrj * directly or indirectly, from Original Intel Code.
533446Smrj *
543446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj * Redistribution of source code of any substantial portion of the Covered
563446Smrj * Code or modification without rights to further distribute source must
573446Smrj * include the following Disclaimer and Export Compliance provision in the
583446Smrj * documentation and/or other materials provided with distribution. In
593446Smrj * addition, Licensee may not authorize further sublicense of source of any
603446Smrj * portion of the Covered Code, and must include terms to the effect that the
613446Smrj * license from Licensee to its licensee is limited to the intellectual
623446Smrj * property embodied in the software Licensee provides to its licensee, and
633446Smrj * not to intellectual property embodied in modifications its licensee may
643446Smrj * make.
653446Smrj *
663446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj * substantial portion of the Covered Code or modification must reproduce the
683446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj * provision in the documentation and/or other materials provided with the
703446Smrj * distribution.
713446Smrj *
723446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj * Intel Code.
743446Smrj *
753446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj * other dealings in products derived from or relating to the Covered Code
783446Smrj * without prior written authorization from Intel.
793446Smrj *
803446Smrj * 4. Disclaimer and Export Compliance
813446Smrj *
823446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
853446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
863446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj * PARTICULAR PURPOSE.
893446Smrj *
903446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
963446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj * LIMITED REMEDY.
983446Smrj *
993446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj * software or system incorporating such software without first obtaining any
1013446Smrj * required license or other approval from the U. S. Department of Commerce or
1023446Smrj * any other agency or department of the United States Government. In the
1033446Smrj * event Licensee exports any such software from the United States or
1043446Smrj * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj * ensure that the distribution and export/re-export of the software is in
1063446Smrj * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj * software, or service, directly or indirectly, to any country for which the
1103446Smrj * United States government or any agency thereof requires an export license,
1113446Smrj * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj * such license, approval or letter.
1133446Smrj *
1143446Smrj *****************************************************************************/
1153446Smrj
1163446Smrj
1173446Smrj #define __EVRGNINI_C__
1183446Smrj
1193446Smrj #include "acpi.h"
1209980SDana.Myers@Sun.COM #include "accommon.h"
1213446Smrj #include "acevents.h"
1223446Smrj #include "acnamesp.h"
1233446Smrj
1243446Smrj #define _COMPONENT ACPI_EVENTS
1253446Smrj ACPI_MODULE_NAME ("evrgnini")
1263446Smrj
1277851SDana.Myers@Sun.COM /* Local prototypes */
1287851SDana.Myers@Sun.COM
1297851SDana.Myers@Sun.COM static BOOLEAN
1307851SDana.Myers@Sun.COM AcpiEvIsPciRootBridge (
1317851SDana.Myers@Sun.COM ACPI_NAMESPACE_NODE *Node);
1327851SDana.Myers@Sun.COM
1333446Smrj
1343446Smrj /*******************************************************************************
1353446Smrj *
1363446Smrj * FUNCTION: AcpiEvSystemMemoryRegionSetup
1373446Smrj *
1383446Smrj * PARAMETERS: Handle - Region we are interested in
1393446Smrj * Function - Start or stop
1403446Smrj * HandlerContext - Address space handler context
1413446Smrj * RegionContext - Region specific context
1423446Smrj *
1433446Smrj * RETURN: Status
1443446Smrj *
1453446Smrj * DESCRIPTION: Setup a SystemMemory operation region
1463446Smrj *
1473446Smrj ******************************************************************************/
1483446Smrj
1493446Smrj ACPI_STATUS
AcpiEvSystemMemoryRegionSetup(ACPI_HANDLE Handle,UINT32 Function,void * HandlerContext,void ** RegionContext)1503446Smrj AcpiEvSystemMemoryRegionSetup (
1513446Smrj ACPI_HANDLE Handle,
1523446Smrj UINT32 Function,
1533446Smrj void *HandlerContext,
1543446Smrj void **RegionContext)
1553446Smrj {
1563446Smrj ACPI_OPERAND_OBJECT *RegionDesc = (ACPI_OPERAND_OBJECT *) Handle;
1573446Smrj ACPI_MEM_SPACE_CONTEXT *LocalRegionContext;
1583446Smrj
1593446Smrj
1603446Smrj ACPI_FUNCTION_TRACE (EvSystemMemoryRegionSetup);
1613446Smrj
1623446Smrj
1633446Smrj if (Function == ACPI_REGION_DEACTIVATE)
1643446Smrj {
1653446Smrj if (*RegionContext)
1663446Smrj {
1673446Smrj LocalRegionContext = (ACPI_MEM_SPACE_CONTEXT *) *RegionContext;
1683446Smrj
1693446Smrj /* Delete a cached mapping if present */
1703446Smrj
1713446Smrj if (LocalRegionContext->MappedLength)
1723446Smrj {
1733446Smrj AcpiOsUnmapMemory (LocalRegionContext->MappedLogicalAddress,
1743446Smrj LocalRegionContext->MappedLength);
1753446Smrj }
1763446Smrj ACPI_FREE (LocalRegionContext);
1773446Smrj *RegionContext = NULL;
1783446Smrj }
1793446Smrj return_ACPI_STATUS (AE_OK);
1803446Smrj }
1813446Smrj
1823446Smrj /* Create a new context */
1833446Smrj
1843446Smrj LocalRegionContext = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_MEM_SPACE_CONTEXT));
1853446Smrj if (!(LocalRegionContext))
1863446Smrj {
1873446Smrj return_ACPI_STATUS (AE_NO_MEMORY);
1883446Smrj }
1893446Smrj
1903446Smrj /* Save the region length and address for use in the handler */
1913446Smrj
1923446Smrj LocalRegionContext->Length = RegionDesc->Region.Length;
1933446Smrj LocalRegionContext->Address = RegionDesc->Region.Address;
1943446Smrj
1953446Smrj *RegionContext = LocalRegionContext;
1963446Smrj return_ACPI_STATUS (AE_OK);
1973446Smrj }
1983446Smrj
1993446Smrj
2003446Smrj /*******************************************************************************
2013446Smrj *
2023446Smrj * FUNCTION: AcpiEvIoSpaceRegionSetup
2033446Smrj *
2043446Smrj * PARAMETERS: Handle - Region we are interested in
2053446Smrj * Function - Start or stop
2063446Smrj * HandlerContext - Address space handler context
2073446Smrj * RegionContext - Region specific context
2083446Smrj *
2093446Smrj * RETURN: Status
2103446Smrj *
2113446Smrj * DESCRIPTION: Setup a IO operation region
2123446Smrj *
2133446Smrj ******************************************************************************/
2143446Smrj
2153446Smrj ACPI_STATUS
AcpiEvIoSpaceRegionSetup(ACPI_HANDLE Handle,UINT32 Function,void * HandlerContext,void ** RegionContext)2163446Smrj AcpiEvIoSpaceRegionSetup (
2173446Smrj ACPI_HANDLE Handle,
2183446Smrj UINT32 Function,
2193446Smrj void *HandlerContext,
2203446Smrj void **RegionContext)
2213446Smrj {
2223446Smrj ACPI_FUNCTION_TRACE (EvIoSpaceRegionSetup);
2233446Smrj
2243446Smrj
2253446Smrj if (Function == ACPI_REGION_DEACTIVATE)
2263446Smrj {
2273446Smrj *RegionContext = NULL;
2283446Smrj }
2293446Smrj else
2303446Smrj {
2313446Smrj *RegionContext = HandlerContext;
2323446Smrj }
2333446Smrj
2343446Smrj return_ACPI_STATUS (AE_OK);
2353446Smrj }
2363446Smrj
2373446Smrj
2383446Smrj /*******************************************************************************
2393446Smrj *
2403446Smrj * FUNCTION: AcpiEvPciConfigRegionSetup
2413446Smrj *
2423446Smrj * PARAMETERS: Handle - Region we are interested in
2433446Smrj * Function - Start or stop
2443446Smrj * HandlerContext - Address space handler context
2453446Smrj * RegionContext - Region specific context
2463446Smrj *
2473446Smrj * RETURN: Status
2483446Smrj *
2493446Smrj * DESCRIPTION: Setup a PCI_Config operation region
2503446Smrj *
2513446Smrj * MUTEX: Assumes namespace is not locked
2523446Smrj *
2533446Smrj ******************************************************************************/
2543446Smrj
2553446Smrj ACPI_STATUS
AcpiEvPciConfigRegionSetup(ACPI_HANDLE Handle,UINT32 Function,void * HandlerContext,void ** RegionContext)2563446Smrj AcpiEvPciConfigRegionSetup (
2573446Smrj ACPI_HANDLE Handle,
2583446Smrj UINT32 Function,
2593446Smrj void *HandlerContext,
2603446Smrj void **RegionContext)
2613446Smrj {
2623446Smrj ACPI_STATUS Status = AE_OK;
2633446Smrj ACPI_INTEGER PciValue;
2643446Smrj ACPI_PCI_ID *PciId = *RegionContext;
2653446Smrj ACPI_OPERAND_OBJECT *HandlerObj;
2663446Smrj ACPI_NAMESPACE_NODE *ParentNode;
2673446Smrj ACPI_NAMESPACE_NODE *PciRootNode;
2687851SDana.Myers@Sun.COM ACPI_NAMESPACE_NODE *PciDeviceNode;
2693446Smrj ACPI_OPERAND_OBJECT *RegionObj = (ACPI_OPERAND_OBJECT *) Handle;
2703446Smrj
2713446Smrj
2723446Smrj ACPI_FUNCTION_TRACE (EvPciConfigRegionSetup);
2733446Smrj
2743446Smrj
2753446Smrj HandlerObj = RegionObj->Region.Handler;
2763446Smrj if (!HandlerObj)
2773446Smrj {
2783446Smrj /*
2793446Smrj * No installed handler. This shouldn't happen because the dispatch
2803446Smrj * routine checks before we get here, but we check again just in case.
2813446Smrj */
2823446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
2833446Smrj "Attempting to init a region %p, with no handler\n", RegionObj));
2843446Smrj return_ACPI_STATUS (AE_NOT_EXIST);
2853446Smrj }
2863446Smrj
2873446Smrj *RegionContext = NULL;
2883446Smrj if (Function == ACPI_REGION_DEACTIVATE)
2893446Smrj {
2903446Smrj if (PciId)
2913446Smrj {
2923446Smrj ACPI_FREE (PciId);
2933446Smrj }
2943446Smrj return_ACPI_STATUS (Status);
2953446Smrj }
2963446Smrj
2973446Smrj ParentNode = AcpiNsGetParentNode (RegionObj->Region.Node);
2983446Smrj
2993446Smrj /*
3003446Smrj * Get the _SEG and _BBN values from the device upon which the handler
3013446Smrj * is installed.
3023446Smrj *
3033446Smrj * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
3043446Smrj * This is the device the handler has been registered to handle.
3053446Smrj */
3063446Smrj
3073446Smrj /*
3083446Smrj * If the AddressSpace.Node is still pointing to the root, we need
3093446Smrj * to scan upward for a PCI Root bridge and re-associate the OpRegion
3103446Smrj * handlers with that device.
3113446Smrj */
3123446Smrj if (HandlerObj->AddressSpace.Node == AcpiGbl_RootNode)
3133446Smrj {
3143446Smrj /* Start search from the parent object */
3153446Smrj
3163446Smrj PciRootNode = ParentNode;
3173446Smrj while (PciRootNode != AcpiGbl_RootNode)
3183446Smrj {
3197851SDana.Myers@Sun.COM /* Get the _HID/_CID in order to detect a RootBridge */
3207851SDana.Myers@Sun.COM
3217851SDana.Myers@Sun.COM if (AcpiEvIsPciRootBridge (PciRootNode))
3223446Smrj {
3237851SDana.Myers@Sun.COM /* Install a handler for this PCI root bridge */
3247851SDana.Myers@Sun.COM
3257851SDana.Myers@Sun.COM Status = AcpiInstallAddressSpaceHandler (
3267851SDana.Myers@Sun.COM (ACPI_HANDLE) PciRootNode,
3277851SDana.Myers@Sun.COM ACPI_ADR_SPACE_PCI_CONFIG,
3287851SDana.Myers@Sun.COM ACPI_DEFAULT_HANDLER, NULL, NULL);
3297851SDana.Myers@Sun.COM if (ACPI_FAILURE (Status))
3303446Smrj {
3317851SDana.Myers@Sun.COM if (Status == AE_SAME_HANDLER)
3323446Smrj {
3337851SDana.Myers@Sun.COM /*
3349980SDana.Myers@Sun.COM * It is OK if the handler is already installed on the
3359980SDana.Myers@Sun.COM * root bridge. Still need to return a context object
3369980SDana.Myers@Sun.COM * for the new PCI_Config operation region, however.
3377851SDana.Myers@Sun.COM */
3387851SDana.Myers@Sun.COM Status = AE_OK;
3393446Smrj }
3407851SDana.Myers@Sun.COM else
3417851SDana.Myers@Sun.COM {
3427851SDana.Myers@Sun.COM ACPI_EXCEPTION ((AE_INFO, Status,
3439980SDana.Myers@Sun.COM "Could not install PciConfig handler "
3449980SDana.Myers@Sun.COM "for Root Bridge %4.4s",
3457851SDana.Myers@Sun.COM AcpiUtGetNodeName (PciRootNode)));
3467851SDana.Myers@Sun.COM }
3473446Smrj }
3487851SDana.Myers@Sun.COM break;
3493446Smrj }
3503446Smrj
3513446Smrj PciRootNode = AcpiNsGetParentNode (PciRootNode);
3523446Smrj }
3533446Smrj
3543446Smrj /* PCI root bridge not found, use namespace root node */
3553446Smrj }
3563446Smrj else
3573446Smrj {
3583446Smrj PciRootNode = HandlerObj->AddressSpace.Node;
3593446Smrj }
3603446Smrj
3613446Smrj /*
3623446Smrj * If this region is now initialized, we are done.
3633446Smrj * (InstallAddressSpaceHandler could have initialized it)
3643446Smrj */
3653446Smrj if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)
3663446Smrj {
3673446Smrj return_ACPI_STATUS (AE_OK);
3683446Smrj }
3693446Smrj
3703446Smrj /* Region is still not initialized. Create a new context */
3713446Smrj
3723446Smrj PciId = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PCI_ID));
3733446Smrj if (!PciId)
3743446Smrj {
3753446Smrj return_ACPI_STATUS (AE_NO_MEMORY);
3763446Smrj }
3773446Smrj
3783446Smrj /*
3799980SDana.Myers@Sun.COM * For PCI_Config space access, we need the segment, bus, device and
3809980SDana.Myers@Sun.COM * function numbers. Acquire them here.
3817851SDana.Myers@Sun.COM *
3827851SDana.Myers@Sun.COM * Find the parent device object. (This allows the operation region to be
3837851SDana.Myers@Sun.COM * within a subscope under the device, such as a control method.)
3843446Smrj */
3857851SDana.Myers@Sun.COM PciDeviceNode = RegionObj->Region.Node;
3867851SDana.Myers@Sun.COM while (PciDeviceNode && (PciDeviceNode->Type != ACPI_TYPE_DEVICE))
3877851SDana.Myers@Sun.COM {
3887851SDana.Myers@Sun.COM PciDeviceNode = AcpiNsGetParentNode (PciDeviceNode);
3897851SDana.Myers@Sun.COM }
3907851SDana.Myers@Sun.COM
3917851SDana.Myers@Sun.COM if (!PciDeviceNode)
3927851SDana.Myers@Sun.COM {
3937851SDana.Myers@Sun.COM ACPI_FREE (PciId);
3947851SDana.Myers@Sun.COM return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
3957851SDana.Myers@Sun.COM }
3963446Smrj
3973446Smrj /*
3989980SDana.Myers@Sun.COM * Get the PCI device and function numbers from the _ADR object contained
3999980SDana.Myers@Sun.COM * in the parent's scope.
4003446Smrj */
4019980SDana.Myers@Sun.COM Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR,
4029980SDana.Myers@Sun.COM PciDeviceNode, &PciValue);
4033446Smrj
4043446Smrj /*
4059980SDana.Myers@Sun.COM * The default is zero, and since the allocation above zeroed the data,
4069980SDana.Myers@Sun.COM * just do nothing on failure.
4073446Smrj */
4083446Smrj if (ACPI_SUCCESS (Status))
4093446Smrj {
4103446Smrj PciId->Device = ACPI_HIWORD (ACPI_LODWORD (PciValue));
4113446Smrj PciId->Function = ACPI_LOWORD (ACPI_LODWORD (PciValue));
4123446Smrj }
4133446Smrj
4143446Smrj /* The PCI segment number comes from the _SEG method */
4153446Smrj
4169980SDana.Myers@Sun.COM Status = AcpiUtEvaluateNumericObject (METHOD_NAME__SEG,
4179980SDana.Myers@Sun.COM PciRootNode, &PciValue);
4183446Smrj if (ACPI_SUCCESS (Status))
4193446Smrj {
4203446Smrj PciId->Segment = ACPI_LOWORD (PciValue);
4213446Smrj }
4223446Smrj
4233446Smrj /* The PCI bus number comes from the _BBN method */
4243446Smrj
4259980SDana.Myers@Sun.COM Status = AcpiUtEvaluateNumericObject (METHOD_NAME__BBN,
4269980SDana.Myers@Sun.COM PciRootNode, &PciValue);
4273446Smrj if (ACPI_SUCCESS (Status))
4283446Smrj {
4293446Smrj PciId->Bus = ACPI_LOWORD (PciValue);
4303446Smrj }
4313446Smrj
4323446Smrj /* Complete this device's PciId */
4333446Smrj
4343446Smrj AcpiOsDerivePciId (PciRootNode, RegionObj->Region.Node, &PciId);
4353446Smrj
4363446Smrj *RegionContext = PciId;
4373446Smrj return_ACPI_STATUS (AE_OK);
4383446Smrj }
4393446Smrj
4403446Smrj
4413446Smrj /*******************************************************************************
4423446Smrj *
4437851SDana.Myers@Sun.COM * FUNCTION: AcpiEvIsPciRootBridge
4447851SDana.Myers@Sun.COM *
4457851SDana.Myers@Sun.COM * PARAMETERS: Node - Device node being examined
4467851SDana.Myers@Sun.COM *
4477851SDana.Myers@Sun.COM * RETURN: TRUE if device is a PCI/PCI-Express Root Bridge
4487851SDana.Myers@Sun.COM *
4497851SDana.Myers@Sun.COM * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by
4507851SDana.Myers@Sun.COM * examining the _HID and _CID for the device.
4517851SDana.Myers@Sun.COM *
4527851SDana.Myers@Sun.COM ******************************************************************************/
4537851SDana.Myers@Sun.COM
4547851SDana.Myers@Sun.COM static BOOLEAN
AcpiEvIsPciRootBridge(ACPI_NAMESPACE_NODE * Node)4557851SDana.Myers@Sun.COM AcpiEvIsPciRootBridge (
4567851SDana.Myers@Sun.COM ACPI_NAMESPACE_NODE *Node)
4577851SDana.Myers@Sun.COM {
4587851SDana.Myers@Sun.COM ACPI_STATUS Status;
459*11225SDana.Myers@Sun.COM ACPI_DEVICE_ID *Hid;
460*11225SDana.Myers@Sun.COM ACPI_DEVICE_ID_LIST *Cid;
4617851SDana.Myers@Sun.COM UINT32 i;
462*11225SDana.Myers@Sun.COM BOOLEAN Match;
4637851SDana.Myers@Sun.COM
4647851SDana.Myers@Sun.COM
4659980SDana.Myers@Sun.COM /* Get the _HID and check for a PCI Root Bridge */
4669980SDana.Myers@Sun.COM
4677851SDana.Myers@Sun.COM Status = AcpiUtExecute_HID (Node, &Hid);
4687851SDana.Myers@Sun.COM if (ACPI_FAILURE (Status))
4697851SDana.Myers@Sun.COM {
4707851SDana.Myers@Sun.COM return (FALSE);
4717851SDana.Myers@Sun.COM }
4727851SDana.Myers@Sun.COM
473*11225SDana.Myers@Sun.COM Match = AcpiUtIsPciRootBridge (Hid->String);
474*11225SDana.Myers@Sun.COM ACPI_FREE (Hid);
475*11225SDana.Myers@Sun.COM
476*11225SDana.Myers@Sun.COM if (Match)
4777851SDana.Myers@Sun.COM {
4787851SDana.Myers@Sun.COM return (TRUE);
4797851SDana.Myers@Sun.COM }
4807851SDana.Myers@Sun.COM
4819980SDana.Myers@Sun.COM /* The _HID did not match. Get the _CID and check for a PCI Root Bridge */
4829980SDana.Myers@Sun.COM
4837851SDana.Myers@Sun.COM Status = AcpiUtExecute_CID (Node, &Cid);
4847851SDana.Myers@Sun.COM if (ACPI_FAILURE (Status))
4857851SDana.Myers@Sun.COM {
4867851SDana.Myers@Sun.COM return (FALSE);
4877851SDana.Myers@Sun.COM }
4887851SDana.Myers@Sun.COM
4897851SDana.Myers@Sun.COM /* Check all _CIDs in the returned list */
4907851SDana.Myers@Sun.COM
4917851SDana.Myers@Sun.COM for (i = 0; i < Cid->Count; i++)
4927851SDana.Myers@Sun.COM {
493*11225SDana.Myers@Sun.COM if (AcpiUtIsPciRootBridge (Cid->Ids[i].String))
4947851SDana.Myers@Sun.COM {
4957851SDana.Myers@Sun.COM ACPI_FREE (Cid);
4967851SDana.Myers@Sun.COM return (TRUE);
4977851SDana.Myers@Sun.COM }
4987851SDana.Myers@Sun.COM }
4997851SDana.Myers@Sun.COM
5007851SDana.Myers@Sun.COM ACPI_FREE (Cid);
5017851SDana.Myers@Sun.COM return (FALSE);
5027851SDana.Myers@Sun.COM }
5037851SDana.Myers@Sun.COM
5047851SDana.Myers@Sun.COM
5057851SDana.Myers@Sun.COM /*******************************************************************************
5067851SDana.Myers@Sun.COM *
5073446Smrj * FUNCTION: AcpiEvPciBarRegionSetup
5083446Smrj *
5093446Smrj * PARAMETERS: Handle - Region we are interested in
5103446Smrj * Function - Start or stop
5113446Smrj * HandlerContext - Address space handler context
5123446Smrj * RegionContext - Region specific context
5133446Smrj *
5143446Smrj * RETURN: Status
5153446Smrj *
5163446Smrj * DESCRIPTION: Setup a PciBAR operation region
5173446Smrj *
5183446Smrj * MUTEX: Assumes namespace is not locked
5193446Smrj *
5203446Smrj ******************************************************************************/
5213446Smrj
5223446Smrj ACPI_STATUS
AcpiEvPciBarRegionSetup(ACPI_HANDLE Handle,UINT32 Function,void * HandlerContext,void ** RegionContext)5233446Smrj AcpiEvPciBarRegionSetup (
5243446Smrj ACPI_HANDLE Handle,
5253446Smrj UINT32 Function,
5263446Smrj void *HandlerContext,
5273446Smrj void **RegionContext)
5283446Smrj {
5293446Smrj ACPI_FUNCTION_TRACE (EvPciBarRegionSetup);
5303446Smrj
5313446Smrj
5323446Smrj return_ACPI_STATUS (AE_OK);
5333446Smrj }
5343446Smrj
5353446Smrj
5363446Smrj /*******************************************************************************
5373446Smrj *
5383446Smrj * FUNCTION: AcpiEvCmosRegionSetup
5393446Smrj *
5403446Smrj * PARAMETERS: Handle - Region we are interested in
5413446Smrj * Function - Start or stop
5423446Smrj * HandlerContext - Address space handler context
5433446Smrj * RegionContext - Region specific context
5443446Smrj *
5453446Smrj * RETURN: Status
5463446Smrj *
5473446Smrj * DESCRIPTION: Setup a CMOS operation region
5483446Smrj *
5493446Smrj * MUTEX: Assumes namespace is not locked
5503446Smrj *
5513446Smrj ******************************************************************************/
5523446Smrj
5533446Smrj ACPI_STATUS
AcpiEvCmosRegionSetup(ACPI_HANDLE Handle,UINT32 Function,void * HandlerContext,void ** RegionContext)5543446Smrj AcpiEvCmosRegionSetup (
5553446Smrj ACPI_HANDLE Handle,
5563446Smrj UINT32 Function,
5573446Smrj void *HandlerContext,
5583446Smrj void **RegionContext)
5593446Smrj {
5603446Smrj ACPI_FUNCTION_TRACE (EvCmosRegionSetup);
5613446Smrj
5623446Smrj
5633446Smrj return_ACPI_STATUS (AE_OK);
5643446Smrj }
5653446Smrj
5663446Smrj
5673446Smrj /*******************************************************************************
5683446Smrj *
5693446Smrj * FUNCTION: AcpiEvDefaultRegionSetup
5703446Smrj *
5713446Smrj * PARAMETERS: Handle - Region we are interested in
5723446Smrj * Function - Start or stop
5733446Smrj * HandlerContext - Address space handler context
5743446Smrj * RegionContext - Region specific context
5753446Smrj *
5763446Smrj * RETURN: Status
5773446Smrj *
5783446Smrj * DESCRIPTION: Default region initialization
5793446Smrj *
5803446Smrj ******************************************************************************/
5813446Smrj
5823446Smrj ACPI_STATUS
AcpiEvDefaultRegionSetup(ACPI_HANDLE Handle,UINT32 Function,void * HandlerContext,void ** RegionContext)5833446Smrj AcpiEvDefaultRegionSetup (
5843446Smrj ACPI_HANDLE Handle,
5853446Smrj UINT32 Function,
5863446Smrj void *HandlerContext,
5873446Smrj void **RegionContext)
5883446Smrj {
5893446Smrj ACPI_FUNCTION_TRACE (EvDefaultRegionSetup);
5903446Smrj
5913446Smrj
5923446Smrj if (Function == ACPI_REGION_DEACTIVATE)
5933446Smrj {
5943446Smrj *RegionContext = NULL;
5953446Smrj }
5963446Smrj else
5973446Smrj {
5983446Smrj *RegionContext = HandlerContext;
5993446Smrj }
6003446Smrj
6013446Smrj return_ACPI_STATUS (AE_OK);
6023446Smrj }
6033446Smrj
6043446Smrj
6053446Smrj /*******************************************************************************
6063446Smrj *
6073446Smrj * FUNCTION: AcpiEvInitializeRegion
6083446Smrj *
6093446Smrj * PARAMETERS: RegionObj - Region we are initializing
6103446Smrj * AcpiNsLocked - Is namespace locked?
6113446Smrj *
6123446Smrj * RETURN: Status
6133446Smrj *
6143446Smrj * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
6153446Smrj * for execution at a later time
6163446Smrj *
6173446Smrj * Get the appropriate address space handler for a newly
6183446Smrj * created region.
6193446Smrj *
6209980SDana.Myers@Sun.COM * This also performs address space specific initialization. For
6213446Smrj * example, PCI regions must have an _ADR object that contains
6229980SDana.Myers@Sun.COM * a PCI address in the scope of the definition. This address is
6233446Smrj * required to perform an access to PCI config space.
6243446Smrj *
6253446Smrj * MUTEX: Interpreter should be unlocked, because we may run the _REG
6263446Smrj * method for this region.
6273446Smrj *
6283446Smrj ******************************************************************************/
6293446Smrj
6303446Smrj ACPI_STATUS
AcpiEvInitializeRegion(ACPI_OPERAND_OBJECT * RegionObj,BOOLEAN AcpiNsLocked)6313446Smrj AcpiEvInitializeRegion (
6323446Smrj ACPI_OPERAND_OBJECT *RegionObj,
6333446Smrj BOOLEAN AcpiNsLocked)
6343446Smrj {
6353446Smrj ACPI_OPERAND_OBJECT *HandlerObj;
6363446Smrj ACPI_OPERAND_OBJECT *ObjDesc;
6373446Smrj ACPI_ADR_SPACE_TYPE SpaceId;
6383446Smrj ACPI_NAMESPACE_NODE *Node;
6393446Smrj ACPI_STATUS Status;
6403446Smrj ACPI_NAMESPACE_NODE *MethodNode;
6413446Smrj ACPI_NAME *RegNamePtr = (ACPI_NAME *) METHOD_NAME__REG;
6423446Smrj ACPI_OPERAND_OBJECT *RegionObj2;
6433446Smrj
6443446Smrj
6453446Smrj ACPI_FUNCTION_TRACE_U32 (EvInitializeRegion, AcpiNsLocked);
6463446Smrj
6473446Smrj
6483446Smrj if (!RegionObj)
6493446Smrj {
6503446Smrj return_ACPI_STATUS (AE_BAD_PARAMETER);
6513446Smrj }
6523446Smrj
6533446Smrj if (RegionObj->Common.Flags & AOPOBJ_OBJECT_INITIALIZED)
6543446Smrj {
6553446Smrj return_ACPI_STATUS (AE_OK);
6563446Smrj }
6573446Smrj
6583446Smrj RegionObj2 = AcpiNsGetSecondaryObject (RegionObj);
6593446Smrj if (!RegionObj2)
6603446Smrj {
6613446Smrj return_ACPI_STATUS (AE_NOT_EXIST);
6623446Smrj }
6633446Smrj
6643446Smrj Node = AcpiNsGetParentNode (RegionObj->Region.Node);
6653446Smrj SpaceId = RegionObj->Region.SpaceId;
6663446Smrj
6673446Smrj /* Setup defaults */
6683446Smrj
6693446Smrj RegionObj->Region.Handler = NULL;
6703446Smrj RegionObj2->Extra.Method_REG = NULL;
6713446Smrj RegionObj->Common.Flags &= ~(AOPOBJ_SETUP_COMPLETE);
6723446Smrj RegionObj->Common.Flags |= AOPOBJ_OBJECT_INITIALIZED;
6733446Smrj
6743446Smrj /* Find any "_REG" method associated with this region definition */
6753446Smrj
6763446Smrj Status = AcpiNsSearchOneScope (
6773446Smrj *RegNamePtr, Node, ACPI_TYPE_METHOD, &MethodNode);
6783446Smrj if (ACPI_SUCCESS (Status))
6793446Smrj {
6803446Smrj /*
6813446Smrj * The _REG method is optional and there can be only one per region
6829980SDana.Myers@Sun.COM * definition. This will be executed when the handler is attached
6833446Smrj * or removed
6843446Smrj */
6853446Smrj RegionObj2->Extra.Method_REG = MethodNode;
6863446Smrj }
6873446Smrj
6883446Smrj /*
6893446Smrj * The following loop depends upon the root Node having no parent
6903446Smrj * ie: AcpiGbl_RootNode->ParentEntry being set to NULL
6913446Smrj */
6923446Smrj while (Node)
6933446Smrj {
6943446Smrj /* Check to see if a handler exists */
6953446Smrj
6963446Smrj HandlerObj = NULL;
6973446Smrj ObjDesc = AcpiNsGetAttachedObject (Node);
6983446Smrj if (ObjDesc)
6993446Smrj {
7003446Smrj /* Can only be a handler if the object exists */
7013446Smrj
7023446Smrj switch (Node->Type)
7033446Smrj {
7043446Smrj case ACPI_TYPE_DEVICE:
7053446Smrj
7063446Smrj HandlerObj = ObjDesc->Device.Handler;
7073446Smrj break;
7083446Smrj
7093446Smrj case ACPI_TYPE_PROCESSOR:
7103446Smrj
7113446Smrj HandlerObj = ObjDesc->Processor.Handler;
7123446Smrj break;
7133446Smrj
7143446Smrj case ACPI_TYPE_THERMAL:
7153446Smrj
7163446Smrj HandlerObj = ObjDesc->ThermalZone.Handler;
7173446Smrj break;
7183446Smrj
7193446Smrj default:
7203446Smrj /* Ignore other objects */
7213446Smrj break;
7223446Smrj }
7233446Smrj
7243446Smrj while (HandlerObj)
7253446Smrj {
7263446Smrj /* Is this handler of the correct type? */
7273446Smrj
7283446Smrj if (HandlerObj->AddressSpace.SpaceId == SpaceId)
7293446Smrj {
7303446Smrj /* Found correct handler */
7313446Smrj
7323446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
7333446Smrj "Found handler %p for region %p in obj %p\n",
7343446Smrj HandlerObj, RegionObj, ObjDesc));
7353446Smrj
7363446Smrj Status = AcpiEvAttachRegion (HandlerObj, RegionObj,
7373446Smrj AcpiNsLocked);
7383446Smrj
7393446Smrj /*
7409980SDana.Myers@Sun.COM * Tell all users that this region is usable by
7419980SDana.Myers@Sun.COM * running the _REG method
7423446Smrj */
7433446Smrj if (AcpiNsLocked)
7443446Smrj {
7453446Smrj Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
7463446Smrj if (ACPI_FAILURE (Status))
7473446Smrj {
7483446Smrj return_ACPI_STATUS (Status);
7493446Smrj }
7503446Smrj }
7513446Smrj
7523446Smrj Status = AcpiEvExecuteRegMethod (RegionObj, 1);
7533446Smrj
7543446Smrj if (AcpiNsLocked)
7553446Smrj {
7563446Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
7573446Smrj if (ACPI_FAILURE (Status))
7583446Smrj {
7593446Smrj return_ACPI_STATUS (Status);
7603446Smrj }
7613446Smrj }
7623446Smrj
7633446Smrj return_ACPI_STATUS (AE_OK);
7643446Smrj }
7653446Smrj
7663446Smrj /* Try next handler in the list */
7673446Smrj
7683446Smrj HandlerObj = HandlerObj->AddressSpace.Next;
7693446Smrj }
7703446Smrj }
7713446Smrj
7729980SDana.Myers@Sun.COM /* This node does not have the handler we need; Pop up one level */
7739980SDana.Myers@Sun.COM
7743446Smrj Node = AcpiNsGetParentNode (Node);
7753446Smrj }
7763446Smrj
7773446Smrj /* If we get here, there is no handler for this region */
7783446Smrj
7793446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
7803446Smrj "No handler for RegionType %s(%X) (RegionObj %p)\n",
7813446Smrj AcpiUtGetRegionName (SpaceId), SpaceId, RegionObj));
7823446Smrj
7833446Smrj return_ACPI_STATUS (AE_NOT_EXIST);
7843446Smrj }
7853446Smrj
786