167754Smsmith/****************************************************************************** 267754Smsmith * 369450Smsmith * Module Name: evrgnini- ACPI AddressSpace (OpRegion) init 467754Smsmith * 567754Smsmith *****************************************************************************/ 667754Smsmith 7316303Sjkim/****************************************************************************** 8316303Sjkim * 9316303Sjkim * 1. Copyright Notice 10316303Sjkim * 11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 1270243Smsmith * All rights reserved. 1367754Smsmith * 14316303Sjkim * 2. License 15316303Sjkim * 16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property 17316303Sjkim * rights. You may have additional license terms from the party that provided 18316303Sjkim * you this software, covering your right to use that party's intellectual 19316303Sjkim * property rights. 20316303Sjkim * 21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an 23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy, 25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered 26316303Sjkim * Code in any form, with the right to sublicense such rights; and 27316303Sjkim * 28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29316303Sjkim * license (with the right to sublicense), under only those claims of Intel 30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell, 31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof 32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright 33316303Sjkim * license, and in no event shall the patent license extend to any additions 34316303Sjkim * to or modifications of the Original Intel Code. No other license or right 35316303Sjkim * is granted directly or by implication, estoppel or otherwise; 36316303Sjkim * 37316303Sjkim * The above copyright and patent license is granted only if the following 38316303Sjkim * conditions are met: 39316303Sjkim * 40316303Sjkim * 3. Conditions 41316303Sjkim * 42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43316303Sjkim * Redistribution of source code of any substantial portion of the Covered 44316303Sjkim * Code or modification with rights to further distribute source must include 45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions, 46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition, 47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to 48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered 49316303Sjkim * Code and the date of any change. Licensee must include in that file the 50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee 51316303Sjkim * must include a prominent statement that the modification is derived, 52316303Sjkim * directly or indirectly, from Original Intel Code. 53316303Sjkim * 54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55316303Sjkim * Redistribution of source code of any substantial portion of the Covered 56316303Sjkim * Code or modification without rights to further distribute source must 57316303Sjkim * include the following Disclaimer and Export Compliance provision in the 58316303Sjkim * documentation and/or other materials provided with distribution. In 59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any 60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the 61316303Sjkim * license from Licensee to its licensee is limited to the intellectual 62316303Sjkim * property embodied in the software Licensee provides to its licensee, and 63316303Sjkim * not to intellectual property embodied in modifications its licensee may 64316303Sjkim * make. 65316303Sjkim * 66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any 67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the 68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance 69316303Sjkim * provision in the documentation and/or other materials provided with the 70316303Sjkim * distribution. 71316303Sjkim * 72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original 73316303Sjkim * Intel Code. 74316303Sjkim * 75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or 77316303Sjkim * other dealings in products derived from or relating to the Covered Code 78316303Sjkim * without prior written authorization from Intel. 79316303Sjkim * 80316303Sjkim * 4. Disclaimer and Export Compliance 81316303Sjkim * 82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88316303Sjkim * PARTICULAR PURPOSE. 89316303Sjkim * 90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97316303Sjkim * LIMITED REMEDY. 98316303Sjkim * 99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this 100316303Sjkim * software or system incorporating such software without first obtaining any 101316303Sjkim * required license or other approval from the U. S. Department of Commerce or 102316303Sjkim * any other agency or department of the United States Government. In the 103316303Sjkim * event Licensee exports any such software from the United States or 104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall 105316303Sjkim * ensure that the distribution and export/re-export of the software is in 106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the 107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process, 109316303Sjkim * software, or service, directly or indirectly, to any country for which the 110316303Sjkim * United States government or any agency thereof requires an export license, 111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining 112316303Sjkim * such license, approval or letter. 113316303Sjkim * 114316303Sjkim ***************************************************************************** 115316303Sjkim * 116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 117316303Sjkim * following license: 118316303Sjkim * 119217365Sjkim * Redistribution and use in source and binary forms, with or without 120217365Sjkim * modification, are permitted provided that the following conditions 121217365Sjkim * are met: 122217365Sjkim * 1. Redistributions of source code must retain the above copyright 123217365Sjkim * notice, this list of conditions, and the following disclaimer, 124217365Sjkim * without modification. 125217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 127217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 128217365Sjkim * including a substantially similar Disclaimer requirement for further 129217365Sjkim * binary redistribution. 130217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 131217365Sjkim * of any contributors may be used to endorse or promote products derived 132217365Sjkim * from this software without specific prior written permission. 13367754Smsmith * 134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145316303Sjkim * 146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the 147217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 148217365Sjkim * Software Foundation. 14967754Smsmith * 150316303Sjkim *****************************************************************************/ 15167754Smsmith 152193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 153193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 154193341Sjkim#include <contrib/dev/acpica/include/acevents.h> 155193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 156316303Sjkim#include <contrib/dev/acpica/include/acinterp.h> 15767754Smsmith 15877424Smsmith#define _COMPONENT ACPI_EVENTS 15991116Smsmith ACPI_MODULE_NAME ("evrgnini") 16067754Smsmith 161167802Sjkim/* Local prototypes */ 16267754Smsmith 163167802Sjkimstatic BOOLEAN 164167802SjkimAcpiEvIsPciRootBridge ( 165167802Sjkim ACPI_NAMESPACE_NODE *Node); 166167802Sjkim 167167802Sjkim 16877424Smsmith/******************************************************************************* 16967754Smsmith * 17067754Smsmith * FUNCTION: AcpiEvSystemMemoryRegionSetup 17167754Smsmith * 172138287Smarks * PARAMETERS: Handle - Region we are interested in 17399679Siwasaki * Function - Start or stop 17467754Smsmith * HandlerContext - Address space handler context 17567754Smsmith * RegionContext - Region specific context 17667754Smsmith * 17767754Smsmith * RETURN: Status 17867754Smsmith * 179151937Sjkim * DESCRIPTION: Setup a SystemMemory operation region 18067754Smsmith * 18177424Smsmith ******************************************************************************/ 18267754Smsmith 18367754SmsmithACPI_STATUS 18467754SmsmithAcpiEvSystemMemoryRegionSetup ( 18567754Smsmith ACPI_HANDLE Handle, 18667754Smsmith UINT32 Function, 18767754Smsmith void *HandlerContext, 18867754Smsmith void **RegionContext) 18967754Smsmith{ 19092388Smsmith ACPI_OPERAND_OBJECT *RegionDesc = (ACPI_OPERAND_OBJECT *) Handle; 19192388Smsmith ACPI_MEM_SPACE_CONTEXT *LocalRegionContext; 19292388Smsmith 19399679Siwasaki 194167802Sjkim ACPI_FUNCTION_TRACE (EvSystemMemoryRegionSetup); 19567754Smsmith 19667754Smsmith 19767754Smsmith if (Function == ACPI_REGION_DEACTIVATE) 19867754Smsmith { 19967754Smsmith if (*RegionContext) 20067754Smsmith { 201167802Sjkim LocalRegionContext = (ACPI_MEM_SPACE_CONTEXT *) *RegionContext; 202167802Sjkim 203167802Sjkim /* Delete a cached mapping if present */ 204167802Sjkim 205167802Sjkim if (LocalRegionContext->MappedLength) 206167802Sjkim { 207167802Sjkim AcpiOsUnmapMemory (LocalRegionContext->MappedLogicalAddress, 208167802Sjkim LocalRegionContext->MappedLength); 209167802Sjkim } 210167802Sjkim ACPI_FREE (LocalRegionContext); 21167754Smsmith *RegionContext = NULL; 21267754Smsmith } 21367754Smsmith return_ACPI_STATUS (AE_OK); 21467754Smsmith } 21567754Smsmith 21699679Siwasaki /* Create a new context */ 21767754Smsmith 218167802Sjkim LocalRegionContext = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_MEM_SPACE_CONTEXT)); 21992388Smsmith if (!(LocalRegionContext)) 22067754Smsmith { 22167754Smsmith return_ACPI_STATUS (AE_NO_MEMORY); 22267754Smsmith } 22367754Smsmith 22492388Smsmith /* Save the region length and address for use in the handler */ 22592388Smsmith 22692388Smsmith LocalRegionContext->Length = RegionDesc->Region.Length; 22792388Smsmith LocalRegionContext->Address = RegionDesc->Region.Address; 22892388Smsmith 22992388Smsmith *RegionContext = LocalRegionContext; 23067754Smsmith return_ACPI_STATUS (AE_OK); 23167754Smsmith} 23267754Smsmith 23367754Smsmith 23477424Smsmith/******************************************************************************* 23567754Smsmith * 23667754Smsmith * FUNCTION: AcpiEvIoSpaceRegionSetup 23767754Smsmith * 238138287Smarks * PARAMETERS: Handle - Region we are interested in 23999679Siwasaki * Function - Start or stop 24067754Smsmith * HandlerContext - Address space handler context 24167754Smsmith * RegionContext - Region specific context 24267754Smsmith * 24367754Smsmith * RETURN: Status 24467754Smsmith * 245151937Sjkim * DESCRIPTION: Setup a IO operation region 24667754Smsmith * 24777424Smsmith ******************************************************************************/ 24867754Smsmith 24967754SmsmithACPI_STATUS 25067754SmsmithAcpiEvIoSpaceRegionSetup ( 25167754Smsmith ACPI_HANDLE Handle, 25267754Smsmith UINT32 Function, 25367754Smsmith void *HandlerContext, 25467754Smsmith void **RegionContext) 25567754Smsmith{ 256167802Sjkim ACPI_FUNCTION_TRACE (EvIoSpaceRegionSetup); 25767754Smsmith 25877424Smsmith 25967754Smsmith if (Function == ACPI_REGION_DEACTIVATE) 26067754Smsmith { 26167754Smsmith *RegionContext = NULL; 26267754Smsmith } 26367754Smsmith else 26467754Smsmith { 26567754Smsmith *RegionContext = HandlerContext; 26667754Smsmith } 26767754Smsmith 26867754Smsmith return_ACPI_STATUS (AE_OK); 26967754Smsmith} 27067754Smsmith 27167754Smsmith 27277424Smsmith/******************************************************************************* 27367754Smsmith * 27467754Smsmith * FUNCTION: AcpiEvPciConfigRegionSetup 27567754Smsmith * 276151937Sjkim * PARAMETERS: Handle - Region we are interested in 27799679Siwasaki * Function - Start or stop 27867754Smsmith * HandlerContext - Address space handler context 27967754Smsmith * RegionContext - Region specific context 28067754Smsmith * 28167754Smsmith * RETURN: Status 28267754Smsmith * 283151937Sjkim * DESCRIPTION: Setup a PCI_Config operation region 28467754Smsmith * 28567754Smsmith * MUTEX: Assumes namespace is not locked 28667754Smsmith * 28777424Smsmith ******************************************************************************/ 28867754Smsmith 28967754SmsmithACPI_STATUS 29067754SmsmithAcpiEvPciConfigRegionSetup ( 29167754Smsmith ACPI_HANDLE Handle, 29267754Smsmith UINT32 Function, 29367754Smsmith void *HandlerContext, 29467754Smsmith void **RegionContext) 29567754Smsmith{ 29667754Smsmith ACPI_STATUS Status = AE_OK; 297202771Sjkim UINT64 PciValue; 29880062Smsmith ACPI_PCI_ID *PciId = *RegionContext; 29967754Smsmith ACPI_OPERAND_OBJECT *HandlerObj; 300117521Snjl ACPI_NAMESPACE_NODE *ParentNode; 301117521Snjl ACPI_NAMESPACE_NODE *PciRootNode; 302167802Sjkim ACPI_NAMESPACE_NODE *PciDeviceNode; 30367754Smsmith ACPI_OPERAND_OBJECT *RegionObj = (ACPI_OPERAND_OBJECT *) Handle; 30467754Smsmith 30577424Smsmith 306167802Sjkim ACPI_FUNCTION_TRACE (EvPciConfigRegionSetup); 30767754Smsmith 30877424Smsmith 309123315Snjl HandlerObj = RegionObj->Region.Handler; 31067754Smsmith if (!HandlerObj) 31167754Smsmith { 31267754Smsmith /* 31399679Siwasaki * No installed handler. This shouldn't happen because the dispatch 31499679Siwasaki * routine checks before we get here, but we check again just in case. 31567754Smsmith */ 31682367Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, 31785756Smsmith "Attempting to init a region %p, with no handler\n", RegionObj)); 31877424Smsmith return_ACPI_STATUS (AE_NOT_EXIST); 31967754Smsmith } 32067754Smsmith 321117521Snjl *RegionContext = NULL; 32267754Smsmith if (Function == ACPI_REGION_DEACTIVATE) 32367754Smsmith { 32480062Smsmith if (PciId) 32567754Smsmith { 326167802Sjkim ACPI_FREE (PciId); 32767754Smsmith } 32867754Smsmith return_ACPI_STATUS (Status); 32967754Smsmith } 33067754Smsmith 331209746Sjkim ParentNode = RegionObj->Region.Node->Parent; 33267754Smsmith 33367754Smsmith /* 33499679Siwasaki * Get the _SEG and _BBN values from the device upon which the handler 33599679Siwasaki * is installed. 33667754Smsmith * 33799679Siwasaki * We need to get the _SEG and _BBN objects relative to the PCI BUS device. 33899679Siwasaki * This is the device the handler has been registered to handle. 33967754Smsmith */ 34067754Smsmith 34167754Smsmith /* 342117521Snjl * If the AddressSpace.Node is still pointing to the root, we need 34399679Siwasaki * to scan upward for a PCI Root bridge and re-associate the OpRegion 34499679Siwasaki * handlers with that device. 34567754Smsmith */ 346117521Snjl if (HandlerObj->AddressSpace.Node == AcpiGbl_RootNode) 34767754Smsmith { 348117521Snjl /* Start search from the parent object */ 349117521Snjl 350117521Snjl PciRootNode = ParentNode; 351117521Snjl while (PciRootNode != AcpiGbl_RootNode) 35267754Smsmith { 353167802Sjkim /* Get the _HID/_CID in order to detect a RootBridge */ 354167802Sjkim 355167802Sjkim if (AcpiEvIsPciRootBridge (PciRootNode)) 35667754Smsmith { 357167802Sjkim /* Install a handler for this PCI root bridge */ 358167802Sjkim 359167802Sjkim Status = AcpiInstallAddressSpaceHandler ( 360298714Sjkim (ACPI_HANDLE) PciRootNode, 361298714Sjkim ACPI_ADR_SPACE_PCI_CONFIG, 362298714Sjkim ACPI_DEFAULT_HANDLER, NULL, NULL); 363167802Sjkim if (ACPI_FAILURE (Status)) 36467754Smsmith { 365167802Sjkim if (Status == AE_SAME_HANDLER) 36699679Siwasaki { 367167802Sjkim /* 368193267Sjkim * It is OK if the handler is already installed on the 369193267Sjkim * root bridge. Still need to return a context object 370193267Sjkim * for the new PCI_Config operation region, however. 371167802Sjkim */ 372167802Sjkim Status = AE_OK; 37399679Siwasaki } 374167802Sjkim else 375167802Sjkim { 376167802Sjkim ACPI_EXCEPTION ((AE_INFO, Status, 377193267Sjkim "Could not install PciConfig handler " 378193267Sjkim "for Root Bridge %4.4s", 379167802Sjkim AcpiUtGetNodeName (PciRootNode))); 380167802Sjkim } 38167754Smsmith } 382167802Sjkim break; 38367754Smsmith } 38467754Smsmith 385209746Sjkim PciRootNode = PciRootNode->Parent; 38667754Smsmith } 387117521Snjl 388117521Snjl /* PCI root bridge not found, use namespace root node */ 38967754Smsmith } 39067754Smsmith else 39167754Smsmith { 392117521Snjl PciRootNode = HandlerObj->AddressSpace.Node; 39367754Smsmith } 39469450Smsmith 39580062Smsmith /* 396117521Snjl * If this region is now initialized, we are done. 397117521Snjl * (InstallAddressSpaceHandler could have initialized it) 39880062Smsmith */ 399117521Snjl if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE) 40067754Smsmith { 401117521Snjl return_ACPI_STATUS (AE_OK); 40267754Smsmith } 40367754Smsmith 404117521Snjl /* Region is still not initialized. Create a new context */ 405117521Snjl 406167802Sjkim PciId = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PCI_ID)); 407117521Snjl if (!PciId) 408117521Snjl { 409117521Snjl return_ACPI_STATUS (AE_NO_MEMORY); 410117521Snjl } 411117521Snjl 41280062Smsmith /* 413193267Sjkim * For PCI_Config space access, we need the segment, bus, device and 414193267Sjkim * function numbers. Acquire them here. 415167802Sjkim * 416167802Sjkim * Find the parent device object. (This allows the operation region to be 417167802Sjkim * within a subscope under the device, such as a control method.) 41880062Smsmith */ 419167802Sjkim PciDeviceNode = RegionObj->Region.Node; 420167802Sjkim while (PciDeviceNode && (PciDeviceNode->Type != ACPI_TYPE_DEVICE)) 421167802Sjkim { 422209746Sjkim PciDeviceNode = PciDeviceNode->Parent; 423167802Sjkim } 424117521Snjl 425167802Sjkim if (!PciDeviceNode) 426167802Sjkim { 427193267Sjkim ACPI_FREE (PciId); 428167802Sjkim return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 429167802Sjkim } 430167802Sjkim 431117521Snjl /* 432212761Sjkim * Get the PCI device and function numbers from the _ADR object 433212761Sjkim * contained in the parent's scope. 434117521Snjl */ 435193267Sjkim Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR, 436298714Sjkim PciDeviceNode, &PciValue); 437117521Snjl 438117521Snjl /* 439193267Sjkim * The default is zero, and since the allocation above zeroed the data, 440193267Sjkim * just do nothing on failure. 441117521Snjl */ 44267754Smsmith if (ACPI_SUCCESS (Status)) 44367754Smsmith { 444117521Snjl PciId->Device = ACPI_HIWORD (ACPI_LODWORD (PciValue)); 445117521Snjl PciId->Function = ACPI_LOWORD (ACPI_LODWORD (PciValue)); 44667754Smsmith } 44767754Smsmith 448117521Snjl /* The PCI segment number comes from the _SEG method */ 449114237Snjl 450193267Sjkim Status = AcpiUtEvaluateNumericObject (METHOD_NAME__SEG, 451298714Sjkim PciRootNode, &PciValue); 452117521Snjl if (ACPI_SUCCESS (Status)) 453117521Snjl { 454117521Snjl PciId->Segment = ACPI_LOWORD (PciValue); 455117521Snjl } 456117521Snjl 457117521Snjl /* The PCI bus number comes from the _BBN method */ 458117521Snjl 459193267Sjkim Status = AcpiUtEvaluateNumericObject (METHOD_NAME__BBN, 460298714Sjkim PciRootNode, &PciValue); 461117521Snjl if (ACPI_SUCCESS (Status)) 462117521Snjl { 463117521Snjl PciId->Bus = ACPI_LOWORD (PciValue); 464117521Snjl } 465117521Snjl 466212761Sjkim /* Complete/update the PCI ID for this device */ 467117521Snjl 468212761Sjkim Status = AcpiHwDerivePciId (PciId, PciRootNode, RegionObj->Region.Node); 469212761Sjkim if (ACPI_FAILURE (Status)) 470212761Sjkim { 471212761Sjkim ACPI_FREE (PciId); 472212761Sjkim return_ACPI_STATUS (Status); 473212761Sjkim } 474117521Snjl 47580062Smsmith *RegionContext = PciId; 47667754Smsmith return_ACPI_STATUS (AE_OK); 47767754Smsmith} 47867754Smsmith 47967754Smsmith 48077424Smsmith/******************************************************************************* 48167754Smsmith * 482167802Sjkim * FUNCTION: AcpiEvIsPciRootBridge 483167802Sjkim * 484167802Sjkim * PARAMETERS: Node - Device node being examined 485167802Sjkim * 486167802Sjkim * RETURN: TRUE if device is a PCI/PCI-Express Root Bridge 487167802Sjkim * 488167802Sjkim * DESCRIPTION: Determine if the input device represents a PCI Root Bridge by 489167802Sjkim * examining the _HID and _CID for the device. 490167802Sjkim * 491167802Sjkim ******************************************************************************/ 492167802Sjkim 493167802Sjkimstatic BOOLEAN 494167802SjkimAcpiEvIsPciRootBridge ( 495167802Sjkim ACPI_NAMESPACE_NODE *Node) 496167802Sjkim{ 497167802Sjkim ACPI_STATUS Status; 498241973Sjkim ACPI_PNP_DEVICE_ID *Hid; 499241973Sjkim ACPI_PNP_DEVICE_ID_LIST *Cid; 500193267Sjkim UINT32 i; 501197104Sjkim BOOLEAN Match; 502167802Sjkim 503167802Sjkim 504193267Sjkim /* Get the _HID and check for a PCI Root Bridge */ 505193267Sjkim 506167802Sjkim Status = AcpiUtExecute_HID (Node, &Hid); 507167802Sjkim if (ACPI_FAILURE (Status)) 508167802Sjkim { 509167802Sjkim return (FALSE); 510167802Sjkim } 511167802Sjkim 512197104Sjkim Match = AcpiUtIsPciRootBridge (Hid->String); 513197104Sjkim ACPI_FREE (Hid); 514197104Sjkim 515197104Sjkim if (Match) 516167802Sjkim { 517167802Sjkim return (TRUE); 518167802Sjkim } 519167802Sjkim 520193267Sjkim /* The _HID did not match. Get the _CID and check for a PCI Root Bridge */ 521193267Sjkim 522167802Sjkim Status = AcpiUtExecute_CID (Node, &Cid); 523167802Sjkim if (ACPI_FAILURE (Status)) 524167802Sjkim { 525167802Sjkim return (FALSE); 526167802Sjkim } 527167802Sjkim 528167802Sjkim /* Check all _CIDs in the returned list */ 529167802Sjkim 530167802Sjkim for (i = 0; i < Cid->Count; i++) 531167802Sjkim { 532197104Sjkim if (AcpiUtIsPciRootBridge (Cid->Ids[i].String)) 533167802Sjkim { 534167802Sjkim ACPI_FREE (Cid); 535167802Sjkim return (TRUE); 536167802Sjkim } 537167802Sjkim } 538167802Sjkim 539167802Sjkim ACPI_FREE (Cid); 540167802Sjkim return (FALSE); 541167802Sjkim} 542167802Sjkim 543167802Sjkim 544167802Sjkim/******************************************************************************* 545167802Sjkim * 54684491Smsmith * FUNCTION: AcpiEvPciBarRegionSetup 54784491Smsmith * 548138287Smarks * PARAMETERS: Handle - Region we are interested in 54999679Siwasaki * Function - Start or stop 55084491Smsmith * HandlerContext - Address space handler context 55184491Smsmith * RegionContext - Region specific context 55284491Smsmith * 55384491Smsmith * RETURN: Status 55484491Smsmith * 555151937Sjkim * DESCRIPTION: Setup a PciBAR operation region 55684491Smsmith * 55784491Smsmith * MUTEX: Assumes namespace is not locked 55884491Smsmith * 55984491Smsmith ******************************************************************************/ 56084491Smsmith 56184491SmsmithACPI_STATUS 56284491SmsmithAcpiEvPciBarRegionSetup ( 56384491Smsmith ACPI_HANDLE Handle, 56484491Smsmith UINT32 Function, 56584491Smsmith void *HandlerContext, 56684491Smsmith void **RegionContext) 56784491Smsmith{ 568167802Sjkim ACPI_FUNCTION_TRACE (EvPciBarRegionSetup); 56984491Smsmith 57084491Smsmith 57184491Smsmith return_ACPI_STATUS (AE_OK); 57284491Smsmith} 57384491Smsmith 57484491Smsmith 57584491Smsmith/******************************************************************************* 57684491Smsmith * 57784491Smsmith * FUNCTION: AcpiEvCmosRegionSetup 57884491Smsmith * 579138287Smarks * PARAMETERS: Handle - Region we are interested in 58099679Siwasaki * Function - Start or stop 58184491Smsmith * HandlerContext - Address space handler context 58284491Smsmith * RegionContext - Region specific context 58384491Smsmith * 58484491Smsmith * RETURN: Status 58584491Smsmith * 586151937Sjkim * DESCRIPTION: Setup a CMOS operation region 58784491Smsmith * 58884491Smsmith * MUTEX: Assumes namespace is not locked 58984491Smsmith * 59084491Smsmith ******************************************************************************/ 59184491Smsmith 59284491SmsmithACPI_STATUS 59384491SmsmithAcpiEvCmosRegionSetup ( 59484491Smsmith ACPI_HANDLE Handle, 59584491Smsmith UINT32 Function, 59684491Smsmith void *HandlerContext, 59784491Smsmith void **RegionContext) 59884491Smsmith{ 599167802Sjkim ACPI_FUNCTION_TRACE (EvCmosRegionSetup); 60084491Smsmith 60184491Smsmith 60284491Smsmith return_ACPI_STATUS (AE_OK); 60384491Smsmith} 60484491Smsmith 60584491Smsmith 60684491Smsmith/******************************************************************************* 60784491Smsmith * 60867754Smsmith * FUNCTION: AcpiEvDefaultRegionSetup 60967754Smsmith * 610138287Smarks * PARAMETERS: Handle - Region we are interested in 61199679Siwasaki * Function - Start or stop 61267754Smsmith * HandlerContext - Address space handler context 61367754Smsmith * RegionContext - Region specific context 61467754Smsmith * 61567754Smsmith * RETURN: Status 61667754Smsmith * 617151937Sjkim * DESCRIPTION: Default region initialization 61867754Smsmith * 61977424Smsmith ******************************************************************************/ 62067754Smsmith 62167754SmsmithACPI_STATUS 62267754SmsmithAcpiEvDefaultRegionSetup ( 62367754Smsmith ACPI_HANDLE Handle, 62467754Smsmith UINT32 Function, 62567754Smsmith void *HandlerContext, 62667754Smsmith void **RegionContext) 62767754Smsmith{ 628167802Sjkim ACPI_FUNCTION_TRACE (EvDefaultRegionSetup); 62967754Smsmith 63077424Smsmith 63167754Smsmith if (Function == ACPI_REGION_DEACTIVATE) 63267754Smsmith { 63367754Smsmith *RegionContext = NULL; 63467754Smsmith } 63567754Smsmith else 63667754Smsmith { 63767754Smsmith *RegionContext = HandlerContext; 63867754Smsmith } 63967754Smsmith 64067754Smsmith return_ACPI_STATUS (AE_OK); 64167754Smsmith} 64267754Smsmith 64367754Smsmith 64477424Smsmith/******************************************************************************* 64567754Smsmith * 64667754Smsmith * FUNCTION: AcpiEvInitializeRegion 64767754Smsmith * 64899679Siwasaki * PARAMETERS: RegionObj - Region we are initializing 64967754Smsmith * 65067754Smsmith * RETURN: Status 65167754Smsmith * 65267754Smsmith * DESCRIPTION: Initializes the region, finds any _REG methods and saves them 65367754Smsmith * for execution at a later time 65467754Smsmith * 65567754Smsmith * Get the appropriate address space handler for a newly 65667754Smsmith * created region. 65767754Smsmith * 658193267Sjkim * This also performs address space specific initialization. For 65967754Smsmith * example, PCI regions must have an _ADR object that contains 660193267Sjkim * a PCI address in the scope of the definition. This address is 66167754Smsmith * required to perform an access to PCI config space. 66267754Smsmith * 663167802Sjkim * MUTEX: Interpreter should be unlocked, because we may run the _REG 664167802Sjkim * method for this region. 665167802Sjkim * 666316303Sjkim * NOTE: Possible incompliance: 667316303Sjkim * There is a behavior conflict in automatic _REG execution: 668316303Sjkim * 1. When the interpreter is evaluating a method, we can only 669316303Sjkim * automatically run _REG for the following case: 670316303Sjkim * Method(_REG, 2) {} 671316303Sjkim * OperationRegion (OPR1, 0x80, 0x1000010, 0x4) 672316303Sjkim * 2. When the interpreter is loading a table, we can also 673316303Sjkim * automatically run _REG for the following case: 674316303Sjkim * OperationRegion (OPR1, 0x80, 0x1000010, 0x4) 675316303Sjkim * Method(_REG, 2) {} 676316303Sjkim * Though this may not be compliant to the de-facto standard, the 677316303Sjkim * logic is kept in order not to trigger regressions. And keeping 678316303Sjkim * this logic should be taken care by the caller of this function. 679316303Sjkim * 68067754Smsmith ******************************************************************************/ 68167754Smsmith 68267754SmsmithACPI_STATUS 68367754SmsmithAcpiEvInitializeRegion ( 684316303Sjkim ACPI_OPERAND_OBJECT *RegionObj) 68567754Smsmith{ 68677424Smsmith ACPI_OPERAND_OBJECT *HandlerObj; 68777424Smsmith ACPI_OPERAND_OBJECT *ObjDesc; 68877424Smsmith ACPI_ADR_SPACE_TYPE SpaceId; 68977424Smsmith ACPI_NAMESPACE_NODE *Node; 69067754Smsmith 69167754Smsmith 692316303Sjkim ACPI_FUNCTION_TRACE (EvInitializeRegion); 69367754Smsmith 69467754Smsmith 69567754Smsmith if (!RegionObj) 69667754Smsmith { 69767754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 69867754Smsmith } 69967754Smsmith 70087031Smsmith if (RegionObj->Common.Flags & AOPOBJ_OBJECT_INITIALIZED) 70187031Smsmith { 70287031Smsmith return_ACPI_STATUS (AE_OK); 70387031Smsmith } 70487031Smsmith 705298714Sjkim RegionObj->Common.Flags |= AOPOBJ_OBJECT_INITIALIZED; 70699679Siwasaki 707209746Sjkim Node = RegionObj->Region.Node->Parent; 70867754Smsmith SpaceId = RegionObj->Region.SpaceId; 70967754Smsmith 71067754Smsmith /* 71199679Siwasaki * The following loop depends upon the root Node having no parent 712298714Sjkim * ie: AcpiGbl_RootNode->Parent being set to NULL 71367754Smsmith */ 71467754Smsmith while (Node) 71567754Smsmith { 716117521Snjl /* Check to see if a handler exists */ 717117521Snjl 71867754Smsmith HandlerObj = NULL; 71977424Smsmith ObjDesc = AcpiNsGetAttachedObject (Node); 72067754Smsmith if (ObjDesc) 72167754Smsmith { 722117521Snjl /* Can only be a handler if the object exists */ 723117521Snjl 72467754Smsmith switch (Node->Type) 72567754Smsmith { 72667754Smsmith case ACPI_TYPE_DEVICE: 72767754Smsmith case ACPI_TYPE_PROCESSOR: 72867754Smsmith case ACPI_TYPE_THERMAL: 72967754Smsmith 730298714Sjkim HandlerObj = ObjDesc->CommonNotify.Handler; 73167754Smsmith break; 73299679Siwasaki 733200553Sjkim case ACPI_TYPE_METHOD: 734200553Sjkim /* 735200553Sjkim * If we are executing module level code, the original 736200553Sjkim * Node's object was replaced by this Method object and we 737200553Sjkim * saved the handler in the method object. 738200553Sjkim * 739200553Sjkim * See AcpiNsExecModuleCode 740200553Sjkim */ 741316303Sjkim if (!AcpiGbl_ParseTableAsTermList && 742316303Sjkim ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL) 743200553Sjkim { 744217365Sjkim HandlerObj = ObjDesc->Method.Dispatch.Handler; 745200553Sjkim } 746200553Sjkim break; 747200553Sjkim 74899679Siwasaki default: 749250838Sjkim 75099679Siwasaki /* Ignore other objects */ 751250838Sjkim 75299679Siwasaki break; 75367754Smsmith } 75467754Smsmith 755298714Sjkim HandlerObj = AcpiEvFindRegionHandler (SpaceId, HandlerObj); 756298714Sjkim if (HandlerObj) 75767754Smsmith { 758298714Sjkim /* Found correct handler */ 75999679Siwasaki 760298714Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, 761298714Sjkim "Found handler %p for region %p in obj %p\n", 762298714Sjkim HandlerObj, RegionObj, ObjDesc)); 76399679Siwasaki 764316303Sjkim (void) AcpiEvAttachRegion (HandlerObj, RegionObj, FALSE); 76567754Smsmith 766298714Sjkim /* 767298714Sjkim * Tell all users that this region is usable by 768298714Sjkim * running the _REG method 769298714Sjkim */ 770316303Sjkim AcpiExExitInterpreter (); 771316303Sjkim (void) AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_CONNECT); 772316303Sjkim AcpiExEnterInterpreter (); 773298714Sjkim return_ACPI_STATUS (AE_OK); 77499679Siwasaki } 77567754Smsmith } 77667754Smsmith 777193267Sjkim /* This node does not have the handler we need; Pop up one level */ 778193267Sjkim 779209746Sjkim Node = Node->Parent; 78099679Siwasaki } 78167754Smsmith 782316303Sjkim /* 783316303Sjkim * If we get here, there is no handler for this region. This is not 784316303Sjkim * fatal because many regions get created before a handler is installed 785316303Sjkim * for said region. 786316303Sjkim */ 78782367Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, 78882367Smsmith "No handler for RegionType %s(%X) (RegionObj %p)\n", 78977424Smsmith AcpiUtGetRegionName (SpaceId), SpaceId, RegionObj)); 79067754Smsmith 791316303Sjkim return_ACPI_STATUS (AE_OK); 79267754Smsmith} 793