126f3cdf0SGordon Ross /*******************************************************************************
226f3cdf0SGordon Ross *
326f3cdf0SGordon Ross * Module Name: hwpci - Obtain PCI bus, device, and function numbers
426f3cdf0SGordon Ross *
526f3cdf0SGordon Ross ******************************************************************************/
626f3cdf0SGordon Ross
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi *
9*35786f68SRobert Mustacchi * 1. Copyright Notice
10*35786f68SRobert Mustacchi *
11*35786f68SRobert Mustacchi * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
1226f3cdf0SGordon Ross * All rights reserved.
1326f3cdf0SGordon Ross *
14*35786f68SRobert Mustacchi * 2. License
15*35786f68SRobert Mustacchi *
16*35786f68SRobert Mustacchi * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi * property rights.
20*35786f68SRobert Mustacchi *
21*35786f68SRobert Mustacchi * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi *
28*35786f68SRobert Mustacchi * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi *
37*35786f68SRobert Mustacchi * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi * conditions are met:
39*35786f68SRobert Mustacchi *
40*35786f68SRobert Mustacchi * 3. Conditions
41*35786f68SRobert Mustacchi *
42*35786f68SRobert Mustacchi * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi *
54*35786f68SRobert Mustacchi * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi * make.
65*35786f68SRobert Mustacchi *
66*35786f68SRobert Mustacchi * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi * distribution.
71*35786f68SRobert Mustacchi *
72*35786f68SRobert Mustacchi * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi * Intel Code.
74*35786f68SRobert Mustacchi *
75*35786f68SRobert Mustacchi * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi *
80*35786f68SRobert Mustacchi * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi *
82*35786f68SRobert Mustacchi * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi *
90*35786f68SRobert Mustacchi * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi * LIMITED REMEDY.
98*35786f68SRobert Mustacchi *
99*35786f68SRobert Mustacchi * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi * such license, approval or letter.
113*35786f68SRobert Mustacchi *
114*35786f68SRobert Mustacchi *****************************************************************************
115*35786f68SRobert Mustacchi *
116*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi * following license:
118*35786f68SRobert Mustacchi *
11926f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without
12026f3cdf0SGordon Ross * modification, are permitted provided that the following conditions
12126f3cdf0SGordon Ross * are met:
12226f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright
12326f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer,
12426f3cdf0SGordon Ross * without modification.
12526f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12626f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below
12726f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon
12826f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further
12926f3cdf0SGordon Ross * binary redistribution.
13026f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names
13126f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived
13226f3cdf0SGordon Ross * from this software without specific prior written permission.
13326f3cdf0SGordon Ross *
13426f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13526f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13726f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi *
146*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
147*35786f68SRobert Mustacchi * GNU General Public License ("GPL") version 2 as published by the Free
148*35786f68SRobert Mustacchi * Software Foundation.
149*35786f68SRobert Mustacchi *
150*35786f68SRobert Mustacchi *****************************************************************************/
15126f3cdf0SGordon Ross
15226f3cdf0SGordon Ross #include "acpi.h"
15326f3cdf0SGordon Ross #include "accommon.h"
15426f3cdf0SGordon Ross
15526f3cdf0SGordon Ross
15626f3cdf0SGordon Ross #define _COMPONENT ACPI_NAMESPACE
15726f3cdf0SGordon Ross ACPI_MODULE_NAME ("hwpci")
15826f3cdf0SGordon Ross
15926f3cdf0SGordon Ross
16026f3cdf0SGordon Ross /* PCI configuration space values */
16126f3cdf0SGordon Ross
16226f3cdf0SGordon Ross #define PCI_CFG_HEADER_TYPE_REG 0x0E
16326f3cdf0SGordon Ross #define PCI_CFG_PRIMARY_BUS_NUMBER_REG 0x18
16426f3cdf0SGordon Ross #define PCI_CFG_SECONDARY_BUS_NUMBER_REG 0x19
16526f3cdf0SGordon Ross
16626f3cdf0SGordon Ross /* PCI header values */
16726f3cdf0SGordon Ross
16826f3cdf0SGordon Ross #define PCI_HEADER_TYPE_MASK 0x7F
16926f3cdf0SGordon Ross #define PCI_TYPE_BRIDGE 0x01
17026f3cdf0SGordon Ross #define PCI_TYPE_CARDBUS_BRIDGE 0x02
17126f3cdf0SGordon Ross
17226f3cdf0SGordon Ross typedef struct acpi_pci_device
17326f3cdf0SGordon Ross {
17426f3cdf0SGordon Ross ACPI_HANDLE Device;
17526f3cdf0SGordon Ross struct acpi_pci_device *Next;
17626f3cdf0SGordon Ross
17726f3cdf0SGordon Ross } ACPI_PCI_DEVICE;
17826f3cdf0SGordon Ross
17926f3cdf0SGordon Ross
18026f3cdf0SGordon Ross /* Local prototypes */
18126f3cdf0SGordon Ross
18226f3cdf0SGordon Ross static ACPI_STATUS
18326f3cdf0SGordon Ross AcpiHwBuildPciList (
18426f3cdf0SGordon Ross ACPI_HANDLE RootPciDevice,
18526f3cdf0SGordon Ross ACPI_HANDLE PciRegion,
18626f3cdf0SGordon Ross ACPI_PCI_DEVICE **ReturnListHead);
18726f3cdf0SGordon Ross
18826f3cdf0SGordon Ross static ACPI_STATUS
18926f3cdf0SGordon Ross AcpiHwProcessPciList (
19026f3cdf0SGordon Ross ACPI_PCI_ID *PciId,
19126f3cdf0SGordon Ross ACPI_PCI_DEVICE *ListHead);
19226f3cdf0SGordon Ross
19326f3cdf0SGordon Ross static void
19426f3cdf0SGordon Ross AcpiHwDeletePciList (
19526f3cdf0SGordon Ross ACPI_PCI_DEVICE *ListHead);
19626f3cdf0SGordon Ross
19726f3cdf0SGordon Ross static ACPI_STATUS
19826f3cdf0SGordon Ross AcpiHwGetPciDeviceInfo (
19926f3cdf0SGordon Ross ACPI_PCI_ID *PciId,
20026f3cdf0SGordon Ross ACPI_HANDLE PciDevice,
20126f3cdf0SGordon Ross UINT16 *BusNumber,
20226f3cdf0SGordon Ross BOOLEAN *IsBridge);
20326f3cdf0SGordon Ross
20426f3cdf0SGordon Ross
20526f3cdf0SGordon Ross /*******************************************************************************
20626f3cdf0SGordon Ross *
20726f3cdf0SGordon Ross * FUNCTION: AcpiHwDerivePciId
20826f3cdf0SGordon Ross *
20926f3cdf0SGordon Ross * PARAMETERS: PciId - Initial values for the PCI ID. May be
21026f3cdf0SGordon Ross * modified by this function.
21126f3cdf0SGordon Ross * RootPciDevice - A handle to a PCI device object. This
21226f3cdf0SGordon Ross * object must be a PCI Root Bridge having a
21326f3cdf0SGordon Ross * _HID value of either PNP0A03 or PNP0A08
21426f3cdf0SGordon Ross * PciRegion - A handle to a PCI configuration space
21526f3cdf0SGordon Ross * Operation Region being initialized
21626f3cdf0SGordon Ross *
21726f3cdf0SGordon Ross * RETURN: Status
21826f3cdf0SGordon Ross *
21926f3cdf0SGordon Ross * DESCRIPTION: This function derives a full PCI ID for a PCI device,
22026f3cdf0SGordon Ross * consisting of a Segment number, Bus number, Device number,
22126f3cdf0SGordon Ross * and function code.
22226f3cdf0SGordon Ross *
22326f3cdf0SGordon Ross * The PCI hardware dynamically configures PCI bus numbers
22426f3cdf0SGordon Ross * depending on the bus topology discovered during system
22526f3cdf0SGordon Ross * initialization. This function is invoked during configuration
22626f3cdf0SGordon Ross * of a PCI_Config Operation Region in order to (possibly) update
22726f3cdf0SGordon Ross * the Bus/Device/Function numbers in the PciId with the actual
22826f3cdf0SGordon Ross * values as determined by the hardware and operating system
22926f3cdf0SGordon Ross * configuration.
23026f3cdf0SGordon Ross *
23126f3cdf0SGordon Ross * The PciId parameter is initially populated during the Operation
23226f3cdf0SGordon Ross * Region initialization. This function is then called, and is
23326f3cdf0SGordon Ross * will make any necessary modifications to the Bus, Device, or
23426f3cdf0SGordon Ross * Function number PCI ID subfields as appropriate for the
23526f3cdf0SGordon Ross * current hardware and OS configuration.
23626f3cdf0SGordon Ross *
23726f3cdf0SGordon Ross * NOTE: Created 08/2010. Replaces the previous OSL AcpiOsDerivePciId
23826f3cdf0SGordon Ross * interface since this feature is OS-independent. This module
23926f3cdf0SGordon Ross * specifically avoids any use of recursion by building a local
24026f3cdf0SGordon Ross * temporary device list.
24126f3cdf0SGordon Ross *
24226f3cdf0SGordon Ross ******************************************************************************/
24326f3cdf0SGordon Ross
24426f3cdf0SGordon Ross ACPI_STATUS
AcpiHwDerivePciId(ACPI_PCI_ID * PciId,ACPI_HANDLE RootPciDevice,ACPI_HANDLE PciRegion)24526f3cdf0SGordon Ross AcpiHwDerivePciId (
24626f3cdf0SGordon Ross ACPI_PCI_ID *PciId,
24726f3cdf0SGordon Ross ACPI_HANDLE RootPciDevice,
24826f3cdf0SGordon Ross ACPI_HANDLE PciRegion)
24926f3cdf0SGordon Ross {
25026f3cdf0SGordon Ross ACPI_STATUS Status;
2517b1019a6SJerry Jelinek ACPI_PCI_DEVICE *ListHead;
25226f3cdf0SGordon Ross
25326f3cdf0SGordon Ross
25426f3cdf0SGordon Ross ACPI_FUNCTION_TRACE (HwDerivePciId);
25526f3cdf0SGordon Ross
25626f3cdf0SGordon Ross
25726f3cdf0SGordon Ross if (!PciId)
25826f3cdf0SGordon Ross {
25926f3cdf0SGordon Ross return_ACPI_STATUS (AE_BAD_PARAMETER);
26026f3cdf0SGordon Ross }
26126f3cdf0SGordon Ross
26226f3cdf0SGordon Ross /* Build a list of PCI devices, from PciRegion up to RootPciDevice */
26326f3cdf0SGordon Ross
26426f3cdf0SGordon Ross Status = AcpiHwBuildPciList (RootPciDevice, PciRegion, &ListHead);
26526f3cdf0SGordon Ross if (ACPI_SUCCESS (Status))
26626f3cdf0SGordon Ross {
26726f3cdf0SGordon Ross /* Walk the list, updating the PCI device/function/bus numbers */
26826f3cdf0SGordon Ross
26926f3cdf0SGordon Ross Status = AcpiHwProcessPciList (PciId, ListHead);
27026f3cdf0SGordon Ross
2717b1019a6SJerry Jelinek /* Delete the list */
2727b1019a6SJerry Jelinek
2737b1019a6SJerry Jelinek AcpiHwDeletePciList (ListHead);
2747b1019a6SJerry Jelinek }
27526f3cdf0SGordon Ross
27626f3cdf0SGordon Ross return_ACPI_STATUS (Status);
27726f3cdf0SGordon Ross }
27826f3cdf0SGordon Ross
27926f3cdf0SGordon Ross
28026f3cdf0SGordon Ross /*******************************************************************************
28126f3cdf0SGordon Ross *
28226f3cdf0SGordon Ross * FUNCTION: AcpiHwBuildPciList
28326f3cdf0SGordon Ross *
28426f3cdf0SGordon Ross * PARAMETERS: RootPciDevice - A handle to a PCI device object. This
28526f3cdf0SGordon Ross * object is guaranteed to be a PCI Root
28626f3cdf0SGordon Ross * Bridge having a _HID value of either
28726f3cdf0SGordon Ross * PNP0A03 or PNP0A08
28826f3cdf0SGordon Ross * PciRegion - A handle to the PCI configuration space
28926f3cdf0SGordon Ross * Operation Region
29026f3cdf0SGordon Ross * ReturnListHead - Where the PCI device list is returned
29126f3cdf0SGordon Ross *
29226f3cdf0SGordon Ross * RETURN: Status
29326f3cdf0SGordon Ross *
29426f3cdf0SGordon Ross * DESCRIPTION: Builds a list of devices from the input PCI region up to the
29526f3cdf0SGordon Ross * Root PCI device for this namespace subtree.
29626f3cdf0SGordon Ross *
29726f3cdf0SGordon Ross ******************************************************************************/
29826f3cdf0SGordon Ross
29926f3cdf0SGordon Ross static ACPI_STATUS
AcpiHwBuildPciList(ACPI_HANDLE RootPciDevice,ACPI_HANDLE PciRegion,ACPI_PCI_DEVICE ** ReturnListHead)30026f3cdf0SGordon Ross AcpiHwBuildPciList (
30126f3cdf0SGordon Ross ACPI_HANDLE RootPciDevice,
30226f3cdf0SGordon Ross ACPI_HANDLE PciRegion,
30326f3cdf0SGordon Ross ACPI_PCI_DEVICE **ReturnListHead)
30426f3cdf0SGordon Ross {
30526f3cdf0SGordon Ross ACPI_HANDLE CurrentDevice;
30626f3cdf0SGordon Ross ACPI_HANDLE ParentDevice;
30726f3cdf0SGordon Ross ACPI_STATUS Status;
30826f3cdf0SGordon Ross ACPI_PCI_DEVICE *ListElement;
30926f3cdf0SGordon Ross
31026f3cdf0SGordon Ross
31126f3cdf0SGordon Ross /*
31226f3cdf0SGordon Ross * Ascend namespace branch until the RootPciDevice is reached, building
31326f3cdf0SGordon Ross * a list of device nodes. Loop will exit when either the PCI device is
31426f3cdf0SGordon Ross * found, or the root of the namespace is reached.
31526f3cdf0SGordon Ross */
3167b1019a6SJerry Jelinek *ReturnListHead = NULL;
31726f3cdf0SGordon Ross CurrentDevice = PciRegion;
31826f3cdf0SGordon Ross while (1)
31926f3cdf0SGordon Ross {
32026f3cdf0SGordon Ross Status = AcpiGetParent (CurrentDevice, &ParentDevice);
32126f3cdf0SGordon Ross if (ACPI_FAILURE (Status))
32226f3cdf0SGordon Ross {
3237b1019a6SJerry Jelinek /* Must delete the list before exit */
3247b1019a6SJerry Jelinek
3257b1019a6SJerry Jelinek AcpiHwDeletePciList (*ReturnListHead);
32626f3cdf0SGordon Ross return (Status);
32726f3cdf0SGordon Ross }
32826f3cdf0SGordon Ross
32926f3cdf0SGordon Ross /* Finished when we reach the PCI root device (PNP0A03 or PNP0A08) */
33026f3cdf0SGordon Ross
33126f3cdf0SGordon Ross if (ParentDevice == RootPciDevice)
33226f3cdf0SGordon Ross {
33326f3cdf0SGordon Ross return (AE_OK);
33426f3cdf0SGordon Ross }
33526f3cdf0SGordon Ross
33626f3cdf0SGordon Ross ListElement = ACPI_ALLOCATE (sizeof (ACPI_PCI_DEVICE));
33726f3cdf0SGordon Ross if (!ListElement)
33826f3cdf0SGordon Ross {
3397b1019a6SJerry Jelinek /* Must delete the list before exit */
3407b1019a6SJerry Jelinek
3417b1019a6SJerry Jelinek AcpiHwDeletePciList (*ReturnListHead);
34226f3cdf0SGordon Ross return (AE_NO_MEMORY);
34326f3cdf0SGordon Ross }
34426f3cdf0SGordon Ross
34526f3cdf0SGordon Ross /* Put new element at the head of the list */
34626f3cdf0SGordon Ross
3477b1019a6SJerry Jelinek ListElement->Next = *ReturnListHead;
34826f3cdf0SGordon Ross ListElement->Device = ParentDevice;
3497b1019a6SJerry Jelinek *ReturnListHead = ListElement;
35026f3cdf0SGordon Ross
35126f3cdf0SGordon Ross CurrentDevice = ParentDevice;
35226f3cdf0SGordon Ross }
35326f3cdf0SGordon Ross }
35426f3cdf0SGordon Ross
35526f3cdf0SGordon Ross
35626f3cdf0SGordon Ross /*******************************************************************************
35726f3cdf0SGordon Ross *
35826f3cdf0SGordon Ross * FUNCTION: AcpiHwProcessPciList
35926f3cdf0SGordon Ross *
36026f3cdf0SGordon Ross * PARAMETERS: PciId - Initial values for the PCI ID. May be
36126f3cdf0SGordon Ross * modified by this function.
36226f3cdf0SGordon Ross * ListHead - Device list created by
36326f3cdf0SGordon Ross * AcpiHwBuildPciList
36426f3cdf0SGordon Ross *
36526f3cdf0SGordon Ross * RETURN: Status
36626f3cdf0SGordon Ross *
36726f3cdf0SGordon Ross * DESCRIPTION: Walk downward through the PCI device list, getting the device
36826f3cdf0SGordon Ross * info for each, via the PCI configuration space and updating
36926f3cdf0SGordon Ross * the PCI ID as necessary. Deletes the list during traversal.
37026f3cdf0SGordon Ross *
37126f3cdf0SGordon Ross ******************************************************************************/
37226f3cdf0SGordon Ross
37326f3cdf0SGordon Ross static ACPI_STATUS
AcpiHwProcessPciList(ACPI_PCI_ID * PciId,ACPI_PCI_DEVICE * ListHead)37426f3cdf0SGordon Ross AcpiHwProcessPciList (
37526f3cdf0SGordon Ross ACPI_PCI_ID *PciId,
37626f3cdf0SGordon Ross ACPI_PCI_DEVICE *ListHead)
37726f3cdf0SGordon Ross {
37826f3cdf0SGordon Ross ACPI_STATUS Status = AE_OK;
37926f3cdf0SGordon Ross ACPI_PCI_DEVICE *Info;
38026f3cdf0SGordon Ross UINT16 BusNumber;
38126f3cdf0SGordon Ross BOOLEAN IsBridge = TRUE;
38226f3cdf0SGordon Ross
38326f3cdf0SGordon Ross
38426f3cdf0SGordon Ross ACPI_FUNCTION_NAME (HwProcessPciList);
38526f3cdf0SGordon Ross
38626f3cdf0SGordon Ross
38726f3cdf0SGordon Ross ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
38826f3cdf0SGordon Ross "Input PciId: Seg %4.4X Bus %4.4X Dev %4.4X Func %4.4X\n",
38926f3cdf0SGordon Ross PciId->Segment, PciId->Bus, PciId->Device, PciId->Function));
39026f3cdf0SGordon Ross
39126f3cdf0SGordon Ross BusNumber = PciId->Bus;
39226f3cdf0SGordon Ross
39326f3cdf0SGordon Ross /*
39426f3cdf0SGordon Ross * Descend down the namespace tree, collecting PCI device, function,
39526f3cdf0SGordon Ross * and bus numbers. BusNumber is only important for PCI bridges.
39626f3cdf0SGordon Ross * Algorithm: As we descend the tree, use the last valid PCI device,
39726f3cdf0SGordon Ross * function, and bus numbers that are discovered, and assign them
39826f3cdf0SGordon Ross * to the PCI ID for the target device.
39926f3cdf0SGordon Ross */
40026f3cdf0SGordon Ross Info = ListHead;
40126f3cdf0SGordon Ross while (Info)
40226f3cdf0SGordon Ross {
40326f3cdf0SGordon Ross Status = AcpiHwGetPciDeviceInfo (PciId, Info->Device,
40426f3cdf0SGordon Ross &BusNumber, &IsBridge);
40526f3cdf0SGordon Ross if (ACPI_FAILURE (Status))
40626f3cdf0SGordon Ross {
4077b1019a6SJerry Jelinek return (Status);
40826f3cdf0SGordon Ross }
40926f3cdf0SGordon Ross
41026f3cdf0SGordon Ross Info = Info->Next;
41126f3cdf0SGordon Ross }
41226f3cdf0SGordon Ross
41326f3cdf0SGordon Ross ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
41426f3cdf0SGordon Ross "Output PciId: Seg %4.4X Bus %4.4X Dev %4.4X Func %4.4X "
41526f3cdf0SGordon Ross "Status %X BusNumber %X IsBridge %X\n",
41626f3cdf0SGordon Ross PciId->Segment, PciId->Bus, PciId->Device, PciId->Function,
41726f3cdf0SGordon Ross Status, BusNumber, IsBridge));
41826f3cdf0SGordon Ross
4197b1019a6SJerry Jelinek return (AE_OK);
42026f3cdf0SGordon Ross }
42126f3cdf0SGordon Ross
42226f3cdf0SGordon Ross
42326f3cdf0SGordon Ross /*******************************************************************************
42426f3cdf0SGordon Ross *
42526f3cdf0SGordon Ross * FUNCTION: AcpiHwDeletePciList
42626f3cdf0SGordon Ross *
42726f3cdf0SGordon Ross * PARAMETERS: ListHead - Device list created by
42826f3cdf0SGordon Ross * AcpiHwBuildPciList
42926f3cdf0SGordon Ross *
43026f3cdf0SGordon Ross * RETURN: None
43126f3cdf0SGordon Ross *
43226f3cdf0SGordon Ross * DESCRIPTION: Free the entire PCI list.
43326f3cdf0SGordon Ross *
43426f3cdf0SGordon Ross ******************************************************************************/
43526f3cdf0SGordon Ross
43626f3cdf0SGordon Ross static void
AcpiHwDeletePciList(ACPI_PCI_DEVICE * ListHead)43726f3cdf0SGordon Ross AcpiHwDeletePciList (
43826f3cdf0SGordon Ross ACPI_PCI_DEVICE *ListHead)
43926f3cdf0SGordon Ross {
44026f3cdf0SGordon Ross ACPI_PCI_DEVICE *Next;
44126f3cdf0SGordon Ross ACPI_PCI_DEVICE *Previous;
44226f3cdf0SGordon Ross
44326f3cdf0SGordon Ross
44426f3cdf0SGordon Ross Next = ListHead;
44526f3cdf0SGordon Ross while (Next)
44626f3cdf0SGordon Ross {
44726f3cdf0SGordon Ross Previous = Next;
44826f3cdf0SGordon Ross Next = Previous->Next;
44926f3cdf0SGordon Ross ACPI_FREE (Previous);
45026f3cdf0SGordon Ross }
45126f3cdf0SGordon Ross }
45226f3cdf0SGordon Ross
45326f3cdf0SGordon Ross
45426f3cdf0SGordon Ross /*******************************************************************************
45526f3cdf0SGordon Ross *
45626f3cdf0SGordon Ross * FUNCTION: AcpiHwGetPciDeviceInfo
45726f3cdf0SGordon Ross *
45826f3cdf0SGordon Ross * PARAMETERS: PciId - Initial values for the PCI ID. May be
45926f3cdf0SGordon Ross * modified by this function.
46026f3cdf0SGordon Ross * PciDevice - Handle for the PCI device object
46126f3cdf0SGordon Ross * BusNumber - Where a PCI bridge bus number is returned
46226f3cdf0SGordon Ross * IsBridge - Return value, indicates if this PCI
46326f3cdf0SGordon Ross * device is a PCI bridge
46426f3cdf0SGordon Ross *
46526f3cdf0SGordon Ross * RETURN: Status
46626f3cdf0SGordon Ross *
46726f3cdf0SGordon Ross * DESCRIPTION: Get the device info for a single PCI device object. Get the
46826f3cdf0SGordon Ross * _ADR (contains PCI device and function numbers), and for PCI
46926f3cdf0SGordon Ross * bridge devices, get the bus number from PCI configuration
47026f3cdf0SGordon Ross * space.
47126f3cdf0SGordon Ross *
47226f3cdf0SGordon Ross ******************************************************************************/
47326f3cdf0SGordon Ross
47426f3cdf0SGordon Ross static ACPI_STATUS
AcpiHwGetPciDeviceInfo(ACPI_PCI_ID * PciId,ACPI_HANDLE PciDevice,UINT16 * BusNumber,BOOLEAN * IsBridge)47526f3cdf0SGordon Ross AcpiHwGetPciDeviceInfo (
47626f3cdf0SGordon Ross ACPI_PCI_ID *PciId,
47726f3cdf0SGordon Ross ACPI_HANDLE PciDevice,
47826f3cdf0SGordon Ross UINT16 *BusNumber,
47926f3cdf0SGordon Ross BOOLEAN *IsBridge)
48026f3cdf0SGordon Ross {
48126f3cdf0SGordon Ross ACPI_STATUS Status;
48226f3cdf0SGordon Ross ACPI_OBJECT_TYPE ObjectType;
48326f3cdf0SGordon Ross UINT64 ReturnValue;
48426f3cdf0SGordon Ross UINT64 PciValue;
48526f3cdf0SGordon Ross
48626f3cdf0SGordon Ross
48726f3cdf0SGordon Ross /* We only care about objects of type Device */
48826f3cdf0SGordon Ross
48926f3cdf0SGordon Ross Status = AcpiGetType (PciDevice, &ObjectType);
49026f3cdf0SGordon Ross if (ACPI_FAILURE (Status))
49126f3cdf0SGordon Ross {
49226f3cdf0SGordon Ross return (Status);
49326f3cdf0SGordon Ross }
49426f3cdf0SGordon Ross
49526f3cdf0SGordon Ross if (ObjectType != ACPI_TYPE_DEVICE)
49626f3cdf0SGordon Ross {
49726f3cdf0SGordon Ross return (AE_OK);
49826f3cdf0SGordon Ross }
49926f3cdf0SGordon Ross
50026f3cdf0SGordon Ross /* We need an _ADR. Ignore device if not present */
50126f3cdf0SGordon Ross
50226f3cdf0SGordon Ross Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR,
50326f3cdf0SGordon Ross PciDevice, &ReturnValue);
50426f3cdf0SGordon Ross if (ACPI_FAILURE (Status))
50526f3cdf0SGordon Ross {
50626f3cdf0SGordon Ross return (AE_OK);
50726f3cdf0SGordon Ross }
50826f3cdf0SGordon Ross
50926f3cdf0SGordon Ross /*
51026f3cdf0SGordon Ross * From _ADR, get the PCI Device and Function and
51126f3cdf0SGordon Ross * update the PCI ID.
51226f3cdf0SGordon Ross */
51326f3cdf0SGordon Ross PciId->Device = ACPI_HIWORD (ACPI_LODWORD (ReturnValue));
51426f3cdf0SGordon Ross PciId->Function = ACPI_LOWORD (ACPI_LODWORD (ReturnValue));
51526f3cdf0SGordon Ross
51626f3cdf0SGordon Ross /*
51726f3cdf0SGordon Ross * If the previous device was a bridge, use the previous
51826f3cdf0SGordon Ross * device bus number
51926f3cdf0SGordon Ross */
52026f3cdf0SGordon Ross if (*IsBridge)
52126f3cdf0SGordon Ross {
52226f3cdf0SGordon Ross PciId->Bus = *BusNumber;
52326f3cdf0SGordon Ross }
52426f3cdf0SGordon Ross
52526f3cdf0SGordon Ross /*
52626f3cdf0SGordon Ross * Get the bus numbers from PCI Config space:
52726f3cdf0SGordon Ross *
52826f3cdf0SGordon Ross * First, get the PCI HeaderType
52926f3cdf0SGordon Ross */
53026f3cdf0SGordon Ross *IsBridge = FALSE;
53126f3cdf0SGordon Ross Status = AcpiOsReadPciConfiguration (PciId,
53226f3cdf0SGordon Ross PCI_CFG_HEADER_TYPE_REG, &PciValue, 8);
53326f3cdf0SGordon Ross if (ACPI_FAILURE (Status))
53426f3cdf0SGordon Ross {
53526f3cdf0SGordon Ross return (Status);
53626f3cdf0SGordon Ross }
53726f3cdf0SGordon Ross
53826f3cdf0SGordon Ross /* We only care about bridges (1=PciBridge, 2=CardBusBridge) */
53926f3cdf0SGordon Ross
54026f3cdf0SGordon Ross PciValue &= PCI_HEADER_TYPE_MASK;
54126f3cdf0SGordon Ross
54226f3cdf0SGordon Ross if ((PciValue != PCI_TYPE_BRIDGE) &&
54326f3cdf0SGordon Ross (PciValue != PCI_TYPE_CARDBUS_BRIDGE))
54426f3cdf0SGordon Ross {
54526f3cdf0SGordon Ross return (AE_OK);
54626f3cdf0SGordon Ross }
54726f3cdf0SGordon Ross
54826f3cdf0SGordon Ross /* Bridge: Get the Primary BusNumber */
54926f3cdf0SGordon Ross
55026f3cdf0SGordon Ross Status = AcpiOsReadPciConfiguration (PciId,
55126f3cdf0SGordon Ross PCI_CFG_PRIMARY_BUS_NUMBER_REG, &PciValue, 8);
55226f3cdf0SGordon Ross if (ACPI_FAILURE (Status))
55326f3cdf0SGordon Ross {
55426f3cdf0SGordon Ross return (Status);
55526f3cdf0SGordon Ross }
55626f3cdf0SGordon Ross
55726f3cdf0SGordon Ross *IsBridge = TRUE;
55826f3cdf0SGordon Ross PciId->Bus = (UINT16) PciValue;
55926f3cdf0SGordon Ross
56026f3cdf0SGordon Ross /* Bridge: Get the Secondary BusNumber */
56126f3cdf0SGordon Ross
56226f3cdf0SGordon Ross Status = AcpiOsReadPciConfiguration (PciId,
56326f3cdf0SGordon Ross PCI_CFG_SECONDARY_BUS_NUMBER_REG, &PciValue, 8);
56426f3cdf0SGordon Ross if (ACPI_FAILURE (Status))
56526f3cdf0SGordon Ross {
56626f3cdf0SGordon Ross return (Status);
56726f3cdf0SGordon Ross }
56826f3cdf0SGordon Ross
56926f3cdf0SGordon Ross *BusNumber = (UINT16) PciValue;
57026f3cdf0SGordon Ross return (AE_OK);
57126f3cdf0SGordon Ross }
572