hwpci.c revision 1.1.1.1.2.2 1 1.1.1.1.2.2 bouyer /*******************************************************************************
2 1.1.1.1.2.2 bouyer *
3 1.1.1.1.2.2 bouyer * Module Name: hwpci - Obtain PCI bus, device, and function numbers
4 1.1.1.1.2.2 bouyer *
5 1.1.1.1.2.2 bouyer ******************************************************************************/
6 1.1.1.1.2.2 bouyer
7 1.1.1.1.2.2 bouyer /*
8 1.1.1.1.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
9 1.1.1.1.2.2 bouyer * All rights reserved.
10 1.1.1.1.2.2 bouyer *
11 1.1.1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.1.1.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.1.1.2.2 bouyer * are met:
14 1.1.1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.1.1.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.1.1.1.2.2 bouyer * without modification.
17 1.1.1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.1.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.1.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.1.2.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.1.1.1.2.2 bouyer * binary redistribution.
22 1.1.1.1.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.1.2.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.1.1.1.2.2 bouyer * from this software without specific prior written permission.
25 1.1.1.1.2.2 bouyer *
26 1.1.1.1.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.1.1.1.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.1.2.2 bouyer * Software Foundation.
29 1.1.1.1.2.2 bouyer *
30 1.1.1.1.2.2 bouyer * NO WARRANTY
31 1.1.1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.1.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.1.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.1.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.1.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.1.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.1.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.1.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.1.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.1.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.1.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.1.2.2 bouyer */
43 1.1.1.1.2.2 bouyer
44 1.1.1.1.2.2 bouyer #define __HWPCI_C__
45 1.1.1.1.2.2 bouyer
46 1.1.1.1.2.2 bouyer #include "acpi.h"
47 1.1.1.1.2.2 bouyer #include "accommon.h"
48 1.1.1.1.2.2 bouyer
49 1.1.1.1.2.2 bouyer
50 1.1.1.1.2.2 bouyer #define _COMPONENT ACPI_NAMESPACE
51 1.1.1.1.2.2 bouyer ACPI_MODULE_NAME ("hwpci")
52 1.1.1.1.2.2 bouyer
53 1.1.1.1.2.2 bouyer
54 1.1.1.1.2.2 bouyer /* PCI configuration space values */
55 1.1.1.1.2.2 bouyer
56 1.1.1.1.2.2 bouyer #define PCI_CFG_HEADER_TYPE_REG 0x0E
57 1.1.1.1.2.2 bouyer #define PCI_CFG_PRIMARY_BUS_NUMBER_REG 0x18
58 1.1.1.1.2.2 bouyer #define PCI_CFG_SECONDARY_BUS_NUMBER_REG 0x19
59 1.1.1.1.2.2 bouyer
60 1.1.1.1.2.2 bouyer /* PCI header values */
61 1.1.1.1.2.2 bouyer
62 1.1.1.1.2.2 bouyer #define PCI_HEADER_TYPE_MASK 0x7F
63 1.1.1.1.2.2 bouyer #define PCI_TYPE_BRIDGE 0x01
64 1.1.1.1.2.2 bouyer #define PCI_TYPE_CARDBUS_BRIDGE 0x02
65 1.1.1.1.2.2 bouyer
66 1.1.1.1.2.2 bouyer typedef struct acpi_pci_device
67 1.1.1.1.2.2 bouyer {
68 1.1.1.1.2.2 bouyer ACPI_HANDLE Device;
69 1.1.1.1.2.2 bouyer struct acpi_pci_device *Next;
70 1.1.1.1.2.2 bouyer
71 1.1.1.1.2.2 bouyer } ACPI_PCI_DEVICE;
72 1.1.1.1.2.2 bouyer
73 1.1.1.1.2.2 bouyer
74 1.1.1.1.2.2 bouyer /* Local prototypes */
75 1.1.1.1.2.2 bouyer
76 1.1.1.1.2.2 bouyer static ACPI_STATUS
77 1.1.1.1.2.2 bouyer AcpiHwBuildPciList (
78 1.1.1.1.2.2 bouyer ACPI_HANDLE RootPciDevice,
79 1.1.1.1.2.2 bouyer ACPI_HANDLE PciRegion,
80 1.1.1.1.2.2 bouyer ACPI_PCI_DEVICE **ReturnListHead);
81 1.1.1.1.2.2 bouyer
82 1.1.1.1.2.2 bouyer static ACPI_STATUS
83 1.1.1.1.2.2 bouyer AcpiHwProcessPciList (
84 1.1.1.1.2.2 bouyer ACPI_PCI_ID *PciId,
85 1.1.1.1.2.2 bouyer ACPI_PCI_DEVICE *ListHead);
86 1.1.1.1.2.2 bouyer
87 1.1.1.1.2.2 bouyer static void
88 1.1.1.1.2.2 bouyer AcpiHwDeletePciList (
89 1.1.1.1.2.2 bouyer ACPI_PCI_DEVICE *ListHead);
90 1.1.1.1.2.2 bouyer
91 1.1.1.1.2.2 bouyer static ACPI_STATUS
92 1.1.1.1.2.2 bouyer AcpiHwGetPciDeviceInfo (
93 1.1.1.1.2.2 bouyer ACPI_PCI_ID *PciId,
94 1.1.1.1.2.2 bouyer ACPI_HANDLE PciDevice,
95 1.1.1.1.2.2 bouyer UINT16 *BusNumber,
96 1.1.1.1.2.2 bouyer BOOLEAN *IsBridge);
97 1.1.1.1.2.2 bouyer
98 1.1.1.1.2.2 bouyer
99 1.1.1.1.2.2 bouyer /*******************************************************************************
100 1.1.1.1.2.2 bouyer *
101 1.1.1.1.2.2 bouyer * FUNCTION: AcpiHwDerivePciId
102 1.1.1.1.2.2 bouyer *
103 1.1.1.1.2.2 bouyer * PARAMETERS: PciId - Initial values for the PCI ID. May be
104 1.1.1.1.2.2 bouyer * modified by this function.
105 1.1.1.1.2.2 bouyer * RootPciDevice - A handle to a PCI device object. This
106 1.1.1.1.2.2 bouyer * object must be a PCI Root Bridge having a
107 1.1.1.1.2.2 bouyer * _HID value of either PNP0A03 or PNP0A08
108 1.1.1.1.2.2 bouyer * PciRegion - A handle to a PCI configuration space
109 1.1.1.1.2.2 bouyer * Operation Region being initialized
110 1.1.1.1.2.2 bouyer *
111 1.1.1.1.2.2 bouyer * RETURN: Status
112 1.1.1.1.2.2 bouyer *
113 1.1.1.1.2.2 bouyer * DESCRIPTION: This function derives a full PCI ID for a PCI device,
114 1.1.1.1.2.2 bouyer * consisting of a Segment number, Bus number, Device number,
115 1.1.1.1.2.2 bouyer * and function code.
116 1.1.1.1.2.2 bouyer *
117 1.1.1.1.2.2 bouyer * The PCI hardware dynamically configures PCI bus numbers
118 1.1.1.1.2.2 bouyer * depending on the bus topology discovered during system
119 1.1.1.1.2.2 bouyer * initialization. This function is invoked during configuration
120 1.1.1.1.2.2 bouyer * of a PCI_Config Operation Region in order to (possibly) update
121 1.1.1.1.2.2 bouyer * the Bus/Device/Function numbers in the PciId with the actual
122 1.1.1.1.2.2 bouyer * values as determined by the hardware and operating system
123 1.1.1.1.2.2 bouyer * configuration.
124 1.1.1.1.2.2 bouyer *
125 1.1.1.1.2.2 bouyer * The PciId parameter is initially populated during the Operation
126 1.1.1.1.2.2 bouyer * Region initialization. This function is then called, and is
127 1.1.1.1.2.2 bouyer * will make any necessary modifications to the Bus, Device, or
128 1.1.1.1.2.2 bouyer * Function number PCI ID subfields as appropriate for the
129 1.1.1.1.2.2 bouyer * current hardware and OS configuration.
130 1.1.1.1.2.2 bouyer *
131 1.1.1.1.2.2 bouyer * NOTE: Created 08/2010. Replaces the previous OSL AcpiOsDerivePciId
132 1.1.1.1.2.2 bouyer * interface since this feature is OS-independent. This module
133 1.1.1.1.2.2 bouyer * specifically avoids any use of recursion by building a local
134 1.1.1.1.2.2 bouyer * temporary device list.
135 1.1.1.1.2.2 bouyer *
136 1.1.1.1.2.2 bouyer ******************************************************************************/
137 1.1.1.1.2.2 bouyer
138 1.1.1.1.2.2 bouyer ACPI_STATUS
139 1.1.1.1.2.2 bouyer AcpiHwDerivePciId (
140 1.1.1.1.2.2 bouyer ACPI_PCI_ID *PciId,
141 1.1.1.1.2.2 bouyer ACPI_HANDLE RootPciDevice,
142 1.1.1.1.2.2 bouyer ACPI_HANDLE PciRegion)
143 1.1.1.1.2.2 bouyer {
144 1.1.1.1.2.2 bouyer ACPI_STATUS Status;
145 1.1.1.1.2.2 bouyer ACPI_PCI_DEVICE *ListHead = NULL;
146 1.1.1.1.2.2 bouyer
147 1.1.1.1.2.2 bouyer
148 1.1.1.1.2.2 bouyer ACPI_FUNCTION_TRACE (HwDerivePciId);
149 1.1.1.1.2.2 bouyer
150 1.1.1.1.2.2 bouyer
151 1.1.1.1.2.2 bouyer if (!PciId)
152 1.1.1.1.2.2 bouyer {
153 1.1.1.1.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
154 1.1.1.1.2.2 bouyer }
155 1.1.1.1.2.2 bouyer
156 1.1.1.1.2.2 bouyer /* Build a list of PCI devices, from PciRegion up to RootPciDevice */
157 1.1.1.1.2.2 bouyer
158 1.1.1.1.2.2 bouyer Status = AcpiHwBuildPciList (RootPciDevice, PciRegion, &ListHead);
159 1.1.1.1.2.2 bouyer if (ACPI_SUCCESS (Status))
160 1.1.1.1.2.2 bouyer {
161 1.1.1.1.2.2 bouyer /* Walk the list, updating the PCI device/function/bus numbers */
162 1.1.1.1.2.2 bouyer
163 1.1.1.1.2.2 bouyer Status = AcpiHwProcessPciList (PciId, ListHead);
164 1.1.1.1.2.2 bouyer }
165 1.1.1.1.2.2 bouyer
166 1.1.1.1.2.2 bouyer /* Always delete the list */
167 1.1.1.1.2.2 bouyer
168 1.1.1.1.2.2 bouyer AcpiHwDeletePciList (ListHead);
169 1.1.1.1.2.2 bouyer return_ACPI_STATUS (Status);
170 1.1.1.1.2.2 bouyer }
171 1.1.1.1.2.2 bouyer
172 1.1.1.1.2.2 bouyer
173 1.1.1.1.2.2 bouyer /*******************************************************************************
174 1.1.1.1.2.2 bouyer *
175 1.1.1.1.2.2 bouyer * FUNCTION: AcpiHwBuildPciList
176 1.1.1.1.2.2 bouyer *
177 1.1.1.1.2.2 bouyer * PARAMETERS: RootPciDevice - A handle to a PCI device object. This
178 1.1.1.1.2.2 bouyer * object is guaranteed to be a PCI Root
179 1.1.1.1.2.2 bouyer * Bridge having a _HID value of either
180 1.1.1.1.2.2 bouyer * PNP0A03 or PNP0A08
181 1.1.1.1.2.2 bouyer * PciRegion - A handle to the PCI configuration space
182 1.1.1.1.2.2 bouyer * Operation Region
183 1.1.1.1.2.2 bouyer * ReturnListHead - Where the PCI device list is returned
184 1.1.1.1.2.2 bouyer *
185 1.1.1.1.2.2 bouyer * RETURN: Status
186 1.1.1.1.2.2 bouyer *
187 1.1.1.1.2.2 bouyer * DESCRIPTION: Builds a list of devices from the input PCI region up to the
188 1.1.1.1.2.2 bouyer * Root PCI device for this namespace subtree.
189 1.1.1.1.2.2 bouyer *
190 1.1.1.1.2.2 bouyer ******************************************************************************/
191 1.1.1.1.2.2 bouyer
192 1.1.1.1.2.2 bouyer static ACPI_STATUS
193 1.1.1.1.2.2 bouyer AcpiHwBuildPciList (
194 1.1.1.1.2.2 bouyer ACPI_HANDLE RootPciDevice,
195 1.1.1.1.2.2 bouyer ACPI_HANDLE PciRegion,
196 1.1.1.1.2.2 bouyer ACPI_PCI_DEVICE **ReturnListHead)
197 1.1.1.1.2.2 bouyer {
198 1.1.1.1.2.2 bouyer ACPI_HANDLE CurrentDevice;
199 1.1.1.1.2.2 bouyer ACPI_HANDLE ParentDevice;
200 1.1.1.1.2.2 bouyer ACPI_STATUS Status;
201 1.1.1.1.2.2 bouyer ACPI_PCI_DEVICE *ListElement;
202 1.1.1.1.2.2 bouyer ACPI_PCI_DEVICE *ListHead = NULL;
203 1.1.1.1.2.2 bouyer
204 1.1.1.1.2.2 bouyer
205 1.1.1.1.2.2 bouyer /*
206 1.1.1.1.2.2 bouyer * Ascend namespace branch until the RootPciDevice is reached, building
207 1.1.1.1.2.2 bouyer * a list of device nodes. Loop will exit when either the PCI device is
208 1.1.1.1.2.2 bouyer * found, or the root of the namespace is reached.
209 1.1.1.1.2.2 bouyer */
210 1.1.1.1.2.2 bouyer CurrentDevice = PciRegion;
211 1.1.1.1.2.2 bouyer while (1)
212 1.1.1.1.2.2 bouyer {
213 1.1.1.1.2.2 bouyer Status = AcpiGetParent (CurrentDevice, &ParentDevice);
214 1.1.1.1.2.2 bouyer if (ACPI_FAILURE (Status))
215 1.1.1.1.2.2 bouyer {
216 1.1.1.1.2.2 bouyer return (Status);
217 1.1.1.1.2.2 bouyer }
218 1.1.1.1.2.2 bouyer
219 1.1.1.1.2.2 bouyer /* Finished when we reach the PCI root device (PNP0A03 or PNP0A08) */
220 1.1.1.1.2.2 bouyer
221 1.1.1.1.2.2 bouyer if (ParentDevice == RootPciDevice)
222 1.1.1.1.2.2 bouyer {
223 1.1.1.1.2.2 bouyer *ReturnListHead = ListHead;
224 1.1.1.1.2.2 bouyer return (AE_OK);
225 1.1.1.1.2.2 bouyer }
226 1.1.1.1.2.2 bouyer
227 1.1.1.1.2.2 bouyer ListElement = ACPI_ALLOCATE (sizeof (ACPI_PCI_DEVICE));
228 1.1.1.1.2.2 bouyer if (!ListElement)
229 1.1.1.1.2.2 bouyer {
230 1.1.1.1.2.2 bouyer return (AE_NO_MEMORY);
231 1.1.1.1.2.2 bouyer }
232 1.1.1.1.2.2 bouyer
233 1.1.1.1.2.2 bouyer /* Put new element at the head of the list */
234 1.1.1.1.2.2 bouyer
235 1.1.1.1.2.2 bouyer ListElement->Next = ListHead;
236 1.1.1.1.2.2 bouyer ListElement->Device = ParentDevice;
237 1.1.1.1.2.2 bouyer ListHead = ListElement;
238 1.1.1.1.2.2 bouyer
239 1.1.1.1.2.2 bouyer CurrentDevice = ParentDevice;
240 1.1.1.1.2.2 bouyer }
241 1.1.1.1.2.2 bouyer }
242 1.1.1.1.2.2 bouyer
243 1.1.1.1.2.2 bouyer
244 1.1.1.1.2.2 bouyer /*******************************************************************************
245 1.1.1.1.2.2 bouyer *
246 1.1.1.1.2.2 bouyer * FUNCTION: AcpiHwProcessPciList
247 1.1.1.1.2.2 bouyer *
248 1.1.1.1.2.2 bouyer * PARAMETERS: PciId - Initial values for the PCI ID. May be
249 1.1.1.1.2.2 bouyer * modified by this function.
250 1.1.1.1.2.2 bouyer * ListHead - Device list created by
251 1.1.1.1.2.2 bouyer * AcpiHwBuildPciList
252 1.1.1.1.2.2 bouyer *
253 1.1.1.1.2.2 bouyer * RETURN: Status
254 1.1.1.1.2.2 bouyer *
255 1.1.1.1.2.2 bouyer * DESCRIPTION: Walk downward through the PCI device list, getting the device
256 1.1.1.1.2.2 bouyer * info for each, via the PCI configuration space and updating
257 1.1.1.1.2.2 bouyer * the PCI ID as necessary. Deletes the list during traversal.
258 1.1.1.1.2.2 bouyer *
259 1.1.1.1.2.2 bouyer ******************************************************************************/
260 1.1.1.1.2.2 bouyer
261 1.1.1.1.2.2 bouyer static ACPI_STATUS
262 1.1.1.1.2.2 bouyer AcpiHwProcessPciList (
263 1.1.1.1.2.2 bouyer ACPI_PCI_ID *PciId,
264 1.1.1.1.2.2 bouyer ACPI_PCI_DEVICE *ListHead)
265 1.1.1.1.2.2 bouyer {
266 1.1.1.1.2.2 bouyer ACPI_STATUS Status = AE_OK;
267 1.1.1.1.2.2 bouyer ACPI_PCI_DEVICE *Info;
268 1.1.1.1.2.2 bouyer UINT16 BusNumber;
269 1.1.1.1.2.2 bouyer BOOLEAN IsBridge = TRUE;
270 1.1.1.1.2.2 bouyer
271 1.1.1.1.2.2 bouyer
272 1.1.1.1.2.2 bouyer ACPI_FUNCTION_NAME (HwProcessPciList);
273 1.1.1.1.2.2 bouyer
274 1.1.1.1.2.2 bouyer
275 1.1.1.1.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
276 1.1.1.1.2.2 bouyer "Input PciId: Seg %4.4X Bus %4.4X Dev %4.4X Func %4.4X\n",
277 1.1.1.1.2.2 bouyer PciId->Segment, PciId->Bus, PciId->Device, PciId->Function));
278 1.1.1.1.2.2 bouyer
279 1.1.1.1.2.2 bouyer BusNumber = PciId->Bus;
280 1.1.1.1.2.2 bouyer
281 1.1.1.1.2.2 bouyer /*
282 1.1.1.1.2.2 bouyer * Descend down the namespace tree, collecting PCI device, function,
283 1.1.1.1.2.2 bouyer * and bus numbers. BusNumber is only important for PCI bridges.
284 1.1.1.1.2.2 bouyer * Algorithm: As we descend the tree, use the last valid PCI device,
285 1.1.1.1.2.2 bouyer * function, and bus numbers that are discovered, and assign them
286 1.1.1.1.2.2 bouyer * to the PCI ID for the target device.
287 1.1.1.1.2.2 bouyer */
288 1.1.1.1.2.2 bouyer Info = ListHead;
289 1.1.1.1.2.2 bouyer while (Info)
290 1.1.1.1.2.2 bouyer {
291 1.1.1.1.2.2 bouyer Status = AcpiHwGetPciDeviceInfo (PciId, Info->Device,
292 1.1.1.1.2.2 bouyer &BusNumber, &IsBridge);
293 1.1.1.1.2.2 bouyer if (ACPI_FAILURE (Status))
294 1.1.1.1.2.2 bouyer {
295 1.1.1.1.2.2 bouyer return_ACPI_STATUS (Status);
296 1.1.1.1.2.2 bouyer }
297 1.1.1.1.2.2 bouyer
298 1.1.1.1.2.2 bouyer Info = Info->Next;
299 1.1.1.1.2.2 bouyer }
300 1.1.1.1.2.2 bouyer
301 1.1.1.1.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
302 1.1.1.1.2.2 bouyer "Output PciId: Seg %4.4X Bus %4.4X Dev %4.4X Func %4.4X "
303 1.1.1.1.2.2 bouyer "Status %X BusNumber %X IsBridge %X\n",
304 1.1.1.1.2.2 bouyer PciId->Segment, PciId->Bus, PciId->Device, PciId->Function,
305 1.1.1.1.2.2 bouyer Status, BusNumber, IsBridge));
306 1.1.1.1.2.2 bouyer
307 1.1.1.1.2.2 bouyer return_ACPI_STATUS (AE_OK);
308 1.1.1.1.2.2 bouyer }
309 1.1.1.1.2.2 bouyer
310 1.1.1.1.2.2 bouyer
311 1.1.1.1.2.2 bouyer /*******************************************************************************
312 1.1.1.1.2.2 bouyer *
313 1.1.1.1.2.2 bouyer * FUNCTION: AcpiHwDeletePciList
314 1.1.1.1.2.2 bouyer *
315 1.1.1.1.2.2 bouyer * PARAMETERS: ListHead - Device list created by
316 1.1.1.1.2.2 bouyer * AcpiHwBuildPciList
317 1.1.1.1.2.2 bouyer *
318 1.1.1.1.2.2 bouyer * RETURN: None
319 1.1.1.1.2.2 bouyer *
320 1.1.1.1.2.2 bouyer * DESCRIPTION: Free the entire PCI list.
321 1.1.1.1.2.2 bouyer *
322 1.1.1.1.2.2 bouyer ******************************************************************************/
323 1.1.1.1.2.2 bouyer
324 1.1.1.1.2.2 bouyer static void
325 1.1.1.1.2.2 bouyer AcpiHwDeletePciList (
326 1.1.1.1.2.2 bouyer ACPI_PCI_DEVICE *ListHead)
327 1.1.1.1.2.2 bouyer {
328 1.1.1.1.2.2 bouyer ACPI_PCI_DEVICE *Next;
329 1.1.1.1.2.2 bouyer ACPI_PCI_DEVICE *Previous;
330 1.1.1.1.2.2 bouyer
331 1.1.1.1.2.2 bouyer
332 1.1.1.1.2.2 bouyer Next = ListHead;
333 1.1.1.1.2.2 bouyer while (Next)
334 1.1.1.1.2.2 bouyer {
335 1.1.1.1.2.2 bouyer Previous = Next;
336 1.1.1.1.2.2 bouyer Next = Previous->Next;
337 1.1.1.1.2.2 bouyer ACPI_FREE (Previous);
338 1.1.1.1.2.2 bouyer }
339 1.1.1.1.2.2 bouyer }
340 1.1.1.1.2.2 bouyer
341 1.1.1.1.2.2 bouyer
342 1.1.1.1.2.2 bouyer /*******************************************************************************
343 1.1.1.1.2.2 bouyer *
344 1.1.1.1.2.2 bouyer * FUNCTION: AcpiHwGetPciDeviceInfo
345 1.1.1.1.2.2 bouyer *
346 1.1.1.1.2.2 bouyer * PARAMETERS: PciId - Initial values for the PCI ID. May be
347 1.1.1.1.2.2 bouyer * modified by this function.
348 1.1.1.1.2.2 bouyer * PciDevice - Handle for the PCI device object
349 1.1.1.1.2.2 bouyer * BusNumber - Where a PCI bridge bus number is returned
350 1.1.1.1.2.2 bouyer * IsBridge - Return value, indicates if this PCI
351 1.1.1.1.2.2 bouyer * device is a PCI bridge
352 1.1.1.1.2.2 bouyer *
353 1.1.1.1.2.2 bouyer * RETURN: Status
354 1.1.1.1.2.2 bouyer *
355 1.1.1.1.2.2 bouyer * DESCRIPTION: Get the device info for a single PCI device object. Get the
356 1.1.1.1.2.2 bouyer * _ADR (contains PCI device and function numbers), and for PCI
357 1.1.1.1.2.2 bouyer * bridge devices, get the bus number from PCI configuration
358 1.1.1.1.2.2 bouyer * space.
359 1.1.1.1.2.2 bouyer *
360 1.1.1.1.2.2 bouyer ******************************************************************************/
361 1.1.1.1.2.2 bouyer
362 1.1.1.1.2.2 bouyer static ACPI_STATUS
363 1.1.1.1.2.2 bouyer AcpiHwGetPciDeviceInfo (
364 1.1.1.1.2.2 bouyer ACPI_PCI_ID *PciId,
365 1.1.1.1.2.2 bouyer ACPI_HANDLE PciDevice,
366 1.1.1.1.2.2 bouyer UINT16 *BusNumber,
367 1.1.1.1.2.2 bouyer BOOLEAN *IsBridge)
368 1.1.1.1.2.2 bouyer {
369 1.1.1.1.2.2 bouyer ACPI_STATUS Status;
370 1.1.1.1.2.2 bouyer ACPI_OBJECT_TYPE ObjectType;
371 1.1.1.1.2.2 bouyer UINT64 ReturnValue;
372 1.1.1.1.2.2 bouyer UINT64 PciValue;
373 1.1.1.1.2.2 bouyer
374 1.1.1.1.2.2 bouyer
375 1.1.1.1.2.2 bouyer /* We only care about objects of type Device */
376 1.1.1.1.2.2 bouyer
377 1.1.1.1.2.2 bouyer Status = AcpiGetType (PciDevice, &ObjectType);
378 1.1.1.1.2.2 bouyer if (ACPI_FAILURE (Status))
379 1.1.1.1.2.2 bouyer {
380 1.1.1.1.2.2 bouyer return (Status);
381 1.1.1.1.2.2 bouyer }
382 1.1.1.1.2.2 bouyer
383 1.1.1.1.2.2 bouyer if (ObjectType != ACPI_TYPE_DEVICE)
384 1.1.1.1.2.2 bouyer {
385 1.1.1.1.2.2 bouyer return (AE_OK);
386 1.1.1.1.2.2 bouyer }
387 1.1.1.1.2.2 bouyer
388 1.1.1.1.2.2 bouyer /* We need an _ADR. Ignore device if not present */
389 1.1.1.1.2.2 bouyer
390 1.1.1.1.2.2 bouyer Status = AcpiUtEvaluateNumericObject (METHOD_NAME__ADR,
391 1.1.1.1.2.2 bouyer PciDevice, &ReturnValue);
392 1.1.1.1.2.2 bouyer if (ACPI_FAILURE (Status))
393 1.1.1.1.2.2 bouyer {
394 1.1.1.1.2.2 bouyer return (AE_OK);
395 1.1.1.1.2.2 bouyer }
396 1.1.1.1.2.2 bouyer
397 1.1.1.1.2.2 bouyer /*
398 1.1.1.1.2.2 bouyer * From _ADR, get the PCI Device and Function and
399 1.1.1.1.2.2 bouyer * update the PCI ID.
400 1.1.1.1.2.2 bouyer */
401 1.1.1.1.2.2 bouyer PciId->Device = ACPI_HIWORD (ACPI_LODWORD (ReturnValue));
402 1.1.1.1.2.2 bouyer PciId->Function = ACPI_LOWORD (ACPI_LODWORD (ReturnValue));
403 1.1.1.1.2.2 bouyer
404 1.1.1.1.2.2 bouyer /*
405 1.1.1.1.2.2 bouyer * If the previous device was a bridge, use the previous
406 1.1.1.1.2.2 bouyer * device bus number
407 1.1.1.1.2.2 bouyer */
408 1.1.1.1.2.2 bouyer if (*IsBridge)
409 1.1.1.1.2.2 bouyer {
410 1.1.1.1.2.2 bouyer PciId->Bus = *BusNumber;
411 1.1.1.1.2.2 bouyer }
412 1.1.1.1.2.2 bouyer
413 1.1.1.1.2.2 bouyer /*
414 1.1.1.1.2.2 bouyer * Get the bus numbers from PCI Config space:
415 1.1.1.1.2.2 bouyer *
416 1.1.1.1.2.2 bouyer * First, get the PCI HeaderType
417 1.1.1.1.2.2 bouyer */
418 1.1.1.1.2.2 bouyer *IsBridge = FALSE;
419 1.1.1.1.2.2 bouyer Status = AcpiOsReadPciConfiguration (PciId,
420 1.1.1.1.2.2 bouyer PCI_CFG_HEADER_TYPE_REG, &PciValue, 8);
421 1.1.1.1.2.2 bouyer if (ACPI_FAILURE (Status))
422 1.1.1.1.2.2 bouyer {
423 1.1.1.1.2.2 bouyer return (Status);
424 1.1.1.1.2.2 bouyer }
425 1.1.1.1.2.2 bouyer
426 1.1.1.1.2.2 bouyer /* We only care about bridges (1=PciBridge, 2=CardBusBridge) */
427 1.1.1.1.2.2 bouyer
428 1.1.1.1.2.2 bouyer PciValue &= PCI_HEADER_TYPE_MASK;
429 1.1.1.1.2.2 bouyer
430 1.1.1.1.2.2 bouyer if ((PciValue != PCI_TYPE_BRIDGE) &&
431 1.1.1.1.2.2 bouyer (PciValue != PCI_TYPE_CARDBUS_BRIDGE))
432 1.1.1.1.2.2 bouyer {
433 1.1.1.1.2.2 bouyer return (AE_OK);
434 1.1.1.1.2.2 bouyer }
435 1.1.1.1.2.2 bouyer
436 1.1.1.1.2.2 bouyer /* Bridge: Get the Primary BusNumber */
437 1.1.1.1.2.2 bouyer
438 1.1.1.1.2.2 bouyer Status = AcpiOsReadPciConfiguration (PciId,
439 1.1.1.1.2.2 bouyer PCI_CFG_PRIMARY_BUS_NUMBER_REG, &PciValue, 8);
440 1.1.1.1.2.2 bouyer if (ACPI_FAILURE (Status))
441 1.1.1.1.2.2 bouyer {
442 1.1.1.1.2.2 bouyer return (Status);
443 1.1.1.1.2.2 bouyer }
444 1.1.1.1.2.2 bouyer
445 1.1.1.1.2.2 bouyer *IsBridge = TRUE;
446 1.1.1.1.2.2 bouyer PciId->Bus = (UINT16) PciValue;
447 1.1.1.1.2.2 bouyer
448 1.1.1.1.2.2 bouyer /* Bridge: Get the Secondary BusNumber */
449 1.1.1.1.2.2 bouyer
450 1.1.1.1.2.2 bouyer Status = AcpiOsReadPciConfiguration (PciId,
451 1.1.1.1.2.2 bouyer PCI_CFG_SECONDARY_BUS_NUMBER_REG, &PciValue, 8);
452 1.1.1.1.2.2 bouyer if (ACPI_FAILURE (Status))
453 1.1.1.1.2.2 bouyer {
454 1.1.1.1.2.2 bouyer return (Status);
455 1.1.1.1.2.2 bouyer }
456 1.1.1.1.2.2 bouyer
457 1.1.1.1.2.2 bouyer *BusNumber = (UINT16) PciValue;
458 1.1.1.1.2.2 bouyer return (AE_OK);
459 1.1.1.1.2.2 bouyer }
460