ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

hwpci.c
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Module Name: hwpci - Obtain PCI bus, device, and function numbers
00004  *
00005  ******************************************************************************/
00006 
00007 /******************************************************************************
00008  *
00009  * 1. Copyright Notice
00010  *
00011  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
00012  * All rights reserved.
00013  *
00014  * 2. License
00015  *
00016  * 2.1. This is your license from Intel Corp. under its intellectual property
00017  * rights.  You may have additional license terms from the party that provided
00018  * you this software, covering your right to use that party's intellectual
00019  * property rights.
00020  *
00021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
00022  * copy of the source code appearing in this file ("Covered Code") an
00023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
00024  * base code distributed originally by Intel ("Original Intel Code") to copy,
00025  * make derivatives, distribute, use and display any portion of the Covered
00026  * Code in any form, with the right to sublicense such rights; and
00027  *
00028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
00029  * license (with the right to sublicense), under only those claims of Intel
00030  * patents that are infringed by the Original Intel Code, to make, use, sell,
00031  * offer to sell, and import the Covered Code and derivative works thereof
00032  * solely to the minimum extent necessary to exercise the above copyright
00033  * license, and in no event shall the patent license extend to any additions
00034  * to or modifications of the Original Intel Code.  No other license or right
00035  * is granted directly or by implication, estoppel or otherwise;
00036  *
00037  * The above copyright and patent license is granted only if the following
00038  * conditions are met:
00039  *
00040  * 3. Conditions
00041  *
00042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
00043  * Redistribution of source code of any substantial portion of the Covered
00044  * Code or modification with rights to further distribute source must include
00045  * the above Copyright Notice, the above License, this list of Conditions,
00046  * and the following Disclaimer and Export Compliance provision.  In addition,
00047  * Licensee must cause all Covered Code to which Licensee contributes to
00048  * contain a file documenting the changes Licensee made to create that Covered
00049  * Code and the date of any change.  Licensee must include in that file the
00050  * documentation of any changes made by any predecessor Licensee.  Licensee
00051  * must include a prominent statement that the modification is derived,
00052  * directly or indirectly, from Original Intel Code.
00053  *
00054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
00055  * Redistribution of source code of any substantial portion of the Covered
00056  * Code or modification without rights to further distribute source must
00057  * include the following Disclaimer and Export Compliance provision in the
00058  * documentation and/or other materials provided with distribution.  In
00059  * addition, Licensee may not authorize further sublicense of source of any
00060  * portion of the Covered Code, and must include terms to the effect that the
00061  * license from Licensee to its licensee is limited to the intellectual
00062  * property embodied in the software Licensee provides to its licensee, and
00063  * not to intellectual property embodied in modifications its licensee may
00064  * make.
00065  *
00066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
00067  * substantial portion of the Covered Code or modification must reproduce the
00068  * above Copyright Notice, and the following Disclaimer and Export Compliance
00069  * provision in the documentation and/or other materials provided with the
00070  * distribution.
00071  *
00072  * 3.4. Intel retains all right, title, and interest in and to the Original
00073  * Intel Code.
00074  *
00075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
00076  * Intel shall be used in advertising or otherwise to promote the sale, use or
00077  * other dealings in products derived from or relating to the Covered Code
00078  * without prior written authorization from Intel.
00079  *
00080  * 4. Disclaimer and Export Compliance
00081  *
00082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
00083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
00084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
00085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
00086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
00087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
00088  * PARTICULAR PURPOSE.
00089  *
00090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
00091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
00092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
00093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
00094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
00095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
00096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
00097  * LIMITED REMEDY.
00098  *
00099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
00100  * software or system incorporating such software without first obtaining any
00101  * required license or other approval from the U. S. Department of Commerce or
00102  * any other agency or department of the United States Government.  In the
00103  * event Licensee exports any such software from the United States or
00104  * re-exports any such software from a foreign destination, Licensee shall
00105  * ensure that the distribution and export/re-export of the software is in
00106  * compliance with all laws, regulations, orders, or other restrictions of the
00107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
00108  * any of its subsidiaries will export/re-export any technical data, process,
00109  * software, or service, directly or indirectly, to any country for which the
00110  * United States government or any agency thereof requires an export license,
00111  * other governmental approval, or letter of assurance, without first obtaining
00112  * such license, approval or letter.
00113  *
00114  *****************************************************************************/
00115 
00116 #define __HWPCI_C__
00117 
00118 #include "acpi.h"
00119 #include "accommon.h"
00120 
00121 
00122 #define _COMPONENT          ACPI_NAMESPACE
00123         ACPI_MODULE_NAME    ("hwpci")
00124 
00125 
00126 /* PCI configuration space values */
00127 
00128 #define PCI_CFG_HEADER_TYPE_REG             0x0E
00129 #define PCI_CFG_PRIMARY_BUS_NUMBER_REG      0x18
00130 #define PCI_CFG_SECONDARY_BUS_NUMBER_REG    0x19
00131 
00132 /* PCI header values */
00133 
00134 #define PCI_HEADER_TYPE_MASK                0x7F
00135 #define PCI_TYPE_BRIDGE                     0x01
00136 #define PCI_TYPE_CARDBUS_BRIDGE             0x02
00137 
00138 typedef struct acpi_pci_device
00139 {
00140     ACPI_HANDLE             Device;
00141     struct acpi_pci_device  *Next;
00142 
00143 } ACPI_PCI_DEVICE;
00144 
00145 
00146 /* Local prototypes */
00147 
00148 static ACPI_STATUS
00149 AcpiHwBuildPciList (
00150     ACPI_HANDLE             RootPciDevice,
00151     ACPI_HANDLE             PciRegion,
00152     ACPI_PCI_DEVICE         **ReturnListHead);
00153 
00154 static ACPI_STATUS
00155 AcpiHwProcessPciList (
00156     ACPI_PCI_ID             *PciId,
00157     ACPI_PCI_DEVICE         *ListHead);
00158 
00159 static void
00160 AcpiHwDeletePciList (
00161     ACPI_PCI_DEVICE         *ListHead);
00162 
00163 static ACPI_STATUS
00164 AcpiHwGetPciDeviceInfo (
00165     ACPI_PCI_ID             *PciId,
00166     ACPI_HANDLE             PciDevice,
00167     UINT16                  *BusNumber,
00168     BOOLEAN                 *IsBridge);
00169 
00170 
00171 /*******************************************************************************
00172  *
00173  * FUNCTION:    AcpiHwDerivePciId
00174  *
00175  * PARAMETERS:  PciId               - Initial values for the PCI ID. May be
00176  *                                    modified by this function.
00177  *              RootPciDevice       - A handle to a PCI device object. This
00178  *                                    object must be a PCI Root Bridge having a
00179  *                                    _HID value of either PNP0A03 or PNP0A08
00180  *              PciRegion           - A handle to a PCI configuration space
00181  *                                    Operation Region being initialized
00182  *
00183  * RETURN:      Status
00184  *
00185  * DESCRIPTION: This function derives a full PCI ID for a PCI device,
00186  *              consisting of a Segment number, Bus number, Device number,
00187  *              and function code.
00188  *
00189  *              The PCI hardware dynamically configures PCI bus numbers
00190  *              depending on the bus topology discovered during system
00191  *              initialization. This function is invoked during configuration
00192  *              of a PCI_Config Operation Region in order to (possibly) update
00193  *              the Bus/Device/Function numbers in the PciId with the actual
00194  *              values as determined by the hardware and operating system
00195  *              configuration.
00196  *
00197  *              The PciId parameter is initially populated during the Operation
00198  *              Region initialization. This function is then called, and is
00199  *              will make any necessary modifications to the Bus, Device, or
00200  *              Function number PCI ID subfields as appropriate for the
00201  *              current hardware and OS configuration.
00202  *
00203  * NOTE:        Created 08/2010. Replaces the previous OSL AcpiOsDerivePciId
00204  *              interface since this feature is OS-independent. This module
00205  *              specifically avoids any use of recursion by building a local
00206  *              temporary device list.
00207  *
00208  ******************************************************************************/
00209 
00210 ACPI_STATUS
00211 AcpiHwDerivePciId (
00212     ACPI_PCI_ID             *PciId,
00213     ACPI_HANDLE             RootPciDevice,
00214     ACPI_HANDLE             PciRegion)
00215 {
00216     ACPI_STATUS             Status;
00217     ACPI_PCI_DEVICE         *ListHead = NULL;
00218 
00219 
00220     ACPI_FUNCTION_TRACE (HwDerivePciId);
00221 
00222 
00223     if (!PciId)
00224     {
00225         return_ACPI_STATUS (AE_BAD_PARAMETER);
00226     }
00227 
00228     /* Build a list of PCI devices, from PciRegion up to RootPciDevice */
00229 
00230     Status = AcpiHwBuildPciList (RootPciDevice, PciRegion, &ListHead);
00231     if (ACPI_SUCCESS (Status))
00232     {
00233         /* Walk the list, updating the PCI device/function/bus numbers */
00234 
00235         Status = AcpiHwProcessPciList (PciId, ListHead);
00236     }
00237 
00238     /* Always delete the list */
00239 
00240     AcpiHwDeletePciList (ListHead);
00241     return_ACPI_STATUS (Status);
00242 }
00243 
00244 
00245 /*******************************************************************************
00246  *
00247  * FUNCTION:    AcpiHwBuildPciList
00248  *
00249  * PARAMETERS:  RootPciDevice       - A handle to a PCI device object. This
00250  *                                    object is guaranteed to be a PCI Root
00251  *                                    Bridge having a _HID value of either
00252  *                                    PNP0A03 or PNP0A08
00253  *              PciRegion           - A handle to the PCI configuration space
00254  *                                    Operation Region
00255  *              ReturnListHead      - Where the PCI device list is returned
00256  *
00257  * RETURN:      Status
00258  *
00259  * DESCRIPTION: Builds a list of devices from the input PCI region up to the
00260  *              Root PCI device for this namespace subtree.
00261  *
00262  ******************************************************************************/
00263 
00264 static ACPI_STATUS
00265 AcpiHwBuildPciList (
00266     ACPI_HANDLE             RootPciDevice,
00267     ACPI_HANDLE             PciRegion,
00268     ACPI_PCI_DEVICE         **ReturnListHead)
00269 {
00270     ACPI_HANDLE             CurrentDevice;
00271     ACPI_HANDLE             ParentDevice;
00272     ACPI_STATUS             Status;
00273     ACPI_PCI_DEVICE         *ListElement;
00274     ACPI_PCI_DEVICE         *ListHead = NULL;
00275 
00276 
00277     /*
00278      * Ascend namespace branch until the RootPciDevice is reached, building
00279      * a list of device nodes. Loop will exit when either the PCI device is
00280      * found, or the root of the namespace is reached.
00281      */
00282     CurrentDevice = PciRegion;
00283     while (1)
00284     {
00285         Status = AcpiGetParent (CurrentDevice, &ParentDevice);
00286         if (ACPI_FAILURE (Status))
00287         {
00288             return (Status);
00289         }
00290 
00291         /* Finished when we reach the PCI root device (PNP0A03 or PNP0A08) */
00292 
00293         if (ParentDevice == RootPciDevice)
00294         {
00295             *ReturnListHead = ListHead;
00296             return (AE_OK);
00297         }
00298 
00299         ListElement = ACPI_ALLOCATE (sizeof (ACPI_PCI_DEVICE));
00300         if (!ListElement)
00301         {
00302             return (AE_NO_MEMORY);
00303         }
00304 
00305         /* Put new element at the head of the list */
00306 
00307         ListElement->Next = ListHead;
00308         ListElement->Device = ParentDevice;
00309         ListHead = ListElement;
00310 
00311         CurrentDevice = ParentDevice;
00312     }
00313 }
00314 
00315 
00316 /*******************************************************************************
00317  *
00318  * FUNCTION:    AcpiHwProcessPciList
00319  *
00320  * PARAMETERS:  PciId               - Initial values for the PCI ID. May be
00321  *                                    modified by this function.
00322  *              ListHead            - Device list created by
00323  *                                    AcpiHwBuildPciList
00324  *
00325  * RETURN:      Status
00326  *
00327  * DESCRIPTION: Walk downward through the PCI device list, getting the device
00328  *              info for each, via the PCI configuration space and updating
00329  *              the PCI ID as necessary. Deletes the list during traversal.
00330  *
00331  ******************************************************************************/
00332 
00333 static ACPI_STATUS
00334 AcpiHwProcessPciList (
00335     ACPI_PCI_ID             *PciId,
00336     ACPI_PCI_DEVICE         *ListHead)
00337 {
00338     ACPI_STATUS             Status = AE_OK;
00339     ACPI_PCI_DEVICE         *Info;
00340     UINT16                  BusNumber;
00341     BOOLEAN                 IsBridge = TRUE;
00342 
00343 
00344     ACPI_FUNCTION_NAME (HwProcessPciList);
00345 
00346 
00347     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
00348         "Input PciId:  Seg %4.4X Bus %4.4X Dev %4.4X Func %4.4X\n",
00349         PciId->Segment, PciId->Bus, PciId->Device, PciId->Function));
00350 
00351     BusNumber = PciId->Bus;
00352 
00353     /*
00354      * Descend down the namespace tree, collecting PCI device, function,
00355      * and bus numbers. BusNumber is only important for PCI bridges.
00356      * Algorithm: As we descend the tree, use the last valid PCI device,
00357      * function, and bus numbers that are discovered, and assign them
00358      * to the PCI ID for the target device.
00359      */
00360     Info = ListHead;
00361     while (Info)
00362     {
00363         Status = AcpiHwGetPciDeviceInfo (PciId, Info->Device,
00364             &BusNumber, &IsBridge);
00365         if (ACPI_FAILURE (Status))
00366         {
00367             return_ACPI_STATUS (Status);
00368         }
00369 
00370         Info = Info->Next;
00371     }
00372 
00373     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
00374         "Output PciId: Seg %4.4X Bus %4.4X Dev %4.4X Func %4.4X "
00375         "Status %X BusNumber %X IsBridge %X\n",
00376         PciId->Segment, PciId->Bus, PciId->Device, PciId->Function,
00377         Status, BusNumber, IsBridge));
00378 
00379     return_ACPI_STATUS (AE_OK);
00380 }
00381 
00382 
00383 /*******************************************************************************
00384  *
00385  * FUNCTION:    AcpiHwDeletePciList
00386  *
00387  * PARAMETERS:  ListHead            - Device list created by
00388  *                                    AcpiHwBuildPciList
00389  *
00390  * RETURN:      None
00391  *
00392  * DESCRIPTION: Free the entire PCI list.
00393  *
00394  ******************************************************************************/
00395 
00396 static void
00397 AcpiHwDeletePciList (
00398     ACPI_PCI_DEVICE         *ListHead)
00399 {
00400     ACPI_PCI_DEVICE         *Next;
00401     ACPI_PCI_DEVICE         *Previous;
00402 
00403 
00404     Next = ListHead;
00405     while (Next)
00406     {
00407         Previous = Next;
00408         Next = Previous->Next;
00409         ACPI_FREE (Previous);
00410     }
00411 }
00412 
00413 
00414 /*******************************************************************************
00415  *
00416  * FUNCTION:    AcpiHwGetPciDeviceInfo
00417  *
00418  * PARAMETERS:  PciId               - Initial values for the PCI ID. May be
00419  *                                    modified by this function.
00420  *              PciDevice           - Handle for the PCI device object
00421  *              BusNumber           - Where a PCI bridge bus number is returned
00422  *              IsBridge            - Return value, indicates if this PCI
00423  *                                    device is a PCI bridge
00424  *
00425  * RETURN:      Status
00426  *
00427  * DESCRIPTION: Get the device info for a single PCI device object. Get the
00428  *              _ADR (contains PCI device and function numbers), and for PCI
00429  *              bridge devices, get the bus number from PCI configuration
00430  *              space.
00431  *
00432  ******************************************************************************/
00433 
00434 static ACPI_STATUS
00435 AcpiHwGetPciDeviceInfo (
00436     ACPI_PCI_ID             *PciId,
00437     ACPI_HANDLE             PciDevice,
00438     UINT16                  *BusNumber,
00439     BOOLEAN                 *IsBridge)
00440 {
00441     ACPI_STATUS             Status;
00442     ACPI_OBJECT_TYPE        ObjectType;
00443     UINT64                  ReturnValue;
00444     UINT64                  PciValue;
00445 
00446 
00447     /* We only care about objects of type Device */
00448 
00449     Status = AcpiGetType (PciDevice, &ObjectType);
00450     if (ACPI_FAILURE (Status))
00451     {
00452         return (Status);
00453     }
00454 
00455     if (ObjectType != ACPI_TYPE_DEVICE)
00456     {
00457         return (AE_OK);
00458     }
00459 
00460     /* We need an _ADR. Ignore device if not present */
00461 
00462     Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR,
00463         PciDevice, &ReturnValue);
00464     if (ACPI_FAILURE (Status))
00465     {
00466         return (AE_OK);
00467     }
00468 
00469     /*
00470      * From _ADR, get the PCI Device and Function and
00471      * update the PCI ID.
00472      */
00473     PciId->Device = ACPI_HIWORD (ACPI_LODWORD (ReturnValue));
00474     PciId->Function = ACPI_LOWORD (ACPI_LODWORD (ReturnValue));
00475 
00476     /*
00477      * If the previous device was a bridge, use the previous
00478      * device bus number
00479      */
00480     if (*IsBridge)
00481     {
00482         PciId->Bus = *BusNumber;
00483     }
00484 
00485     /*
00486      * Get the bus numbers from PCI Config space:
00487      *
00488      * First, get the PCI HeaderType
00489      */
00490     *IsBridge = FALSE;
00491     Status = AcpiOsReadPciConfiguration (PciId,
00492         PCI_CFG_HEADER_TYPE_REG, &PciValue, 8);
00493     if (ACPI_FAILURE (Status))
00494     {
00495         return (Status);
00496     }
00497 
00498     /* We only care about bridges (1=PciBridge, 2=CardBusBridge) */
00499 
00500     PciValue &= PCI_HEADER_TYPE_MASK;
00501 
00502     if ((PciValue != PCI_TYPE_BRIDGE) &&
00503         (PciValue != PCI_TYPE_CARDBUS_BRIDGE))
00504     {
00505         return (AE_OK);
00506     }
00507 
00508     /* Bridge: Get the Primary BusNumber */
00509 
00510     Status = AcpiOsReadPciConfiguration (PciId,
00511         PCI_CFG_PRIMARY_BUS_NUMBER_REG, &PciValue, 8);
00512     if (ACPI_FAILURE (Status))
00513     {
00514         return (Status);
00515     }
00516 
00517     *IsBridge = TRUE;
00518     PciId->Bus = (UINT16) PciValue;
00519 
00520     /* Bridge: Get the Secondary BusNumber */
00521 
00522     Status = AcpiOsReadPciConfiguration (PciId,
00523         PCI_CFG_SECONDARY_BUS_NUMBER_REG, &PciValue, 8);
00524     if (ACPI_FAILURE (Status))
00525     {
00526         return (Status);
00527     }
00528 
00529     *BusNumber = (UINT16) PciValue;
00530     return (AE_OK);
00531 }

Generated on Sun May 27 2012 04:19:08 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.