ReactOS  0.4.14-dev-323-g6fe6a88
hwpci.c File Reference
#include "acpi.h"
#include "accommon.h"
Include dependency graph for hwpci.c:

Go to the source code of this file.

Classes

struct  acpi_pci_device
 

Macros

#define _COMPONENT   ACPI_NAMESPACE
 
#define PCI_CFG_HEADER_TYPE_REG   0x0E
 
#define PCI_CFG_PRIMARY_BUS_NUMBER_REG   0x18
 
#define PCI_CFG_SECONDARY_BUS_NUMBER_REG   0x19
 
#define PCI_HEADER_TYPE_MASK   0x7F
 
#define PCI_TYPE_BRIDGE   0x01
 
#define PCI_TYPE_CARDBUS_BRIDGE   0x02
 

Typedefs

typedef struct acpi_pci_device ACPI_PCI_DEVICE
 

Functions

static ACPI_STATUS AcpiHwBuildPciList (ACPI_HANDLE RootPciDevice, ACPI_HANDLE PciRegion, ACPI_PCI_DEVICE **ReturnListHead)
 
static ACPI_STATUS AcpiHwProcessPciList (ACPI_PCI_ID *PciId, ACPI_PCI_DEVICE *ListHead)
 
static void AcpiHwDeletePciList (ACPI_PCI_DEVICE *ListHead)
 
static ACPI_STATUS AcpiHwGetPciDeviceInfo (ACPI_PCI_ID *PciId, ACPI_HANDLE PciDevice, UINT16 *BusNumber, BOOLEAN *IsBridge)
 
ACPI_STATUS AcpiHwDerivePciId (ACPI_PCI_ID *PciId, ACPI_HANDLE RootPciDevice, ACPI_HANDLE PciRegion)
 

Macro Definition Documentation

◆ _COMPONENT

#define _COMPONENT   ACPI_NAMESPACE

Definition at line 48 of file hwpci.c.

◆ PCI_CFG_HEADER_TYPE_REG

#define PCI_CFG_HEADER_TYPE_REG   0x0E

Definition at line 54 of file hwpci.c.

◆ PCI_CFG_PRIMARY_BUS_NUMBER_REG

#define PCI_CFG_PRIMARY_BUS_NUMBER_REG   0x18

Definition at line 55 of file hwpci.c.

◆ PCI_CFG_SECONDARY_BUS_NUMBER_REG

#define PCI_CFG_SECONDARY_BUS_NUMBER_REG   0x19

Definition at line 56 of file hwpci.c.

◆ PCI_HEADER_TYPE_MASK

#define PCI_HEADER_TYPE_MASK   0x7F

Definition at line 60 of file hwpci.c.

◆ PCI_TYPE_BRIDGE

#define PCI_TYPE_BRIDGE   0x01

Definition at line 61 of file hwpci.c.

◆ PCI_TYPE_CARDBUS_BRIDGE

#define PCI_TYPE_CARDBUS_BRIDGE   0x02

Definition at line 62 of file hwpci.c.

Typedef Documentation

◆ ACPI_PCI_DEVICE

Function Documentation

◆ AcpiHwBuildPciList()

static ACPI_STATUS AcpiHwBuildPciList ( ACPI_HANDLE  RootPciDevice,
ACPI_HANDLE  PciRegion,
ACPI_PCI_DEVICE **  ReturnListHead 
)
static

Definition at line 192 of file hwpci.c.

196 {
197  ACPI_HANDLE CurrentDevice;
198  ACPI_HANDLE ParentDevice;
200  ACPI_PCI_DEVICE *ListElement;
201 
202 
203  /*
204  * Ascend namespace branch until the RootPciDevice is reached, building
205  * a list of device nodes. Loop will exit when either the PCI device is
206  * found, or the root of the namespace is reached.
207  */
208  *ReturnListHead = NULL;
209  CurrentDevice = PciRegion;
210  while (1)
211  {
212  Status = AcpiGetParent (CurrentDevice, &ParentDevice);
213  if (ACPI_FAILURE (Status))
214  {
215  /* Must delete the list before exit */
216 
217  AcpiHwDeletePciList (*ReturnListHead);
218  return (Status);
219  }
220 
221  /* Finished when we reach the PCI root device (PNP0A03 or PNP0A08) */
222 
223  if (ParentDevice == RootPciDevice)
224  {
225  return (AE_OK);
226  }
227 
228  ListElement = ACPI_ALLOCATE (sizeof (ACPI_PCI_DEVICE));
229  if (!ListElement)
230  {
231  /* Must delete the list before exit */
232 
233  AcpiHwDeletePciList (*ReturnListHead);
234  return (AE_NO_MEMORY);
235  }
236 
237  /* Put new element at the head of the list */
238 
239  ListElement->Next = *ReturnListHead;
240  ListElement->Device = ParentDevice;
241  *ReturnListHead = ListElement;
242 
243  CurrentDevice = ParentDevice;
244  }
245 }
#define AE_NO_MEMORY
Definition: acexcep.h:112
static void AcpiHwDeletePciList(ACPI_PCI_DEVICE *ListHead)
Definition: hwpci.c:329
ACPI_STATUS AcpiGetParent(ACPI_HANDLE Handle, ACPI_HANDLE *RetHandle)
Definition: nsxfobj.c:131
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define ACPI_ALLOCATE(a)
Definition: actypes.h:384
struct acpi_pci_device * Next
Definition: hwpci.c:67
smooth NULL
Definition: ftsmooth.c:416
Status
Definition: gdiplustypes.h:24
ACPI_HANDLE Device
Definition: hwpci.c:66
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiHwDerivePciId().

◆ AcpiHwDeletePciList()

static void AcpiHwDeletePciList ( ACPI_PCI_DEVICE ListHead)
static

Definition at line 329 of file hwpci.c.

331 {
332  ACPI_PCI_DEVICE *Next;
333  ACPI_PCI_DEVICE *Previous;
334 
335 
336  Next = ListHead;
337  while (Next)
338  {
339  Previous = Next;
340  Next = Previous->Next;
341  ACPI_FREE (Previous);
342  }
343 }
#define ACPI_FREE(a)
Definition: actypes.h:386
struct acpi_pci_device * Next
Definition: hwpci.c:67

Referenced by AcpiHwBuildPciList(), and AcpiHwDerivePciId().

◆ AcpiHwDerivePciId()

ACPI_STATUS AcpiHwDerivePciId ( ACPI_PCI_ID PciId,
ACPI_HANDLE  RootPciDevice,
ACPI_HANDLE  PciRegion 
)

Definition at line 137 of file hwpci.c.

141 {
143  ACPI_PCI_DEVICE *ListHead;
144 
145 
146  ACPI_FUNCTION_TRACE (HwDerivePciId);
147 
148 
149  if (!PciId)
150  {
152  }
153 
154  /* Build a list of PCI devices, from PciRegion up to RootPciDevice */
155 
156  Status = AcpiHwBuildPciList (RootPciDevice, PciRegion, &ListHead);
157  if (ACPI_SUCCESS (Status))
158  {
159  /* Walk the list, updating the PCI device/function/bus numbers */
160 
161  Status = AcpiHwProcessPciList (PciId, ListHead);
162 
163  /* Delete the list */
164 
165  AcpiHwDeletePciList (ListHead);
166  }
167 
169 }
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
#define AE_BAD_PARAMETER
Definition: acexcep.h:151
static void AcpiHwDeletePciList(ACPI_PCI_DEVICE *ListHead)
Definition: hwpci.c:329
UINT32 ACPI_STATUS
Definition: actypes.h:460
static ACPI_STATUS AcpiHwProcessPciList(ACPI_PCI_ID *PciId, ACPI_PCI_DEVICE *ListHead)
Definition: hwpci.c:266
static ACPI_STATUS AcpiHwBuildPciList(ACPI_HANDLE RootPciDevice, ACPI_HANDLE PciRegion, ACPI_PCI_DEVICE **ReturnListHead)
Definition: hwpci.c:192
Status
Definition: gdiplustypes.h:24
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480

Referenced by AcpiEvPciConfigRegionSetup().

◆ AcpiHwGetPciDeviceInfo()

static ACPI_STATUS AcpiHwGetPciDeviceInfo ( ACPI_PCI_ID PciId,
ACPI_HANDLE  PciDevice,
UINT16 BusNumber,
BOOLEAN IsBridge 
)
static

Definition at line 367 of file hwpci.c.

372 {
376  UINT64 PciValue;
377 
378 
379  /* We only care about objects of type Device */
380 
381  Status = AcpiGetType (PciDevice, &ObjectType);
382  if (ACPI_FAILURE (Status))
383  {
384  return (Status);
385  }
386 
388  {
389  return (AE_OK);
390  }
391 
392  /* We need an _ADR. Ignore device if not present */
393 
395  PciDevice, &ReturnValue);
396  if (ACPI_FAILURE (Status))
397  {
398  return (AE_OK);
399  }
400 
401  /*
402  * From _ADR, get the PCI Device and Function and
403  * update the PCI ID.
404  */
407 
408  /*
409  * If the previous device was a bridge, use the previous
410  * device bus number
411  */
412  if (*IsBridge)
413  {
414  PciId->Bus = *BusNumber;
415  }
416 
417  /*
418  * Get the bus numbers from PCI Config space:
419  *
420  * First, get the PCI HeaderType
421  */
422  *IsBridge = FALSE;
424  PCI_CFG_HEADER_TYPE_REG, &PciValue, 8);
425  if (ACPI_FAILURE (Status))
426  {
427  return (Status);
428  }
429 
430  /* We only care about bridges (1=PciBridge, 2=CardBusBridge) */
431 
432  PciValue &= PCI_HEADER_TYPE_MASK;
433 
434  if ((PciValue != PCI_TYPE_BRIDGE) &&
435  (PciValue != PCI_TYPE_CARDBUS_BRIDGE))
436  {
437  return (AE_OK);
438  }
439 
440  /* Bridge: Get the Primary BusNumber */
441 
443  PCI_CFG_PRIMARY_BUS_NUMBER_REG, &PciValue, 8);
444  if (ACPI_FAILURE (Status))
445  {
446  return (Status);
447  }
448 
449  *IsBridge = TRUE;
450  PciId->Bus = (UINT16) PciValue;
451 
452  /* Bridge: Get the Secondary BusNumber */
453 
455  PCI_CFG_SECONDARY_BUS_NUMBER_REG, &PciValue, 8);
456  if (ACPI_FAILURE (Status))
457  {
458  return (Status);
459  }
460 
461  *BusNumber = (UINT16) PciValue;
462  return (AE_OK);
463 }
ObjectType
Definition: metafile.c:80
#define ACPI_LODWORD(Integer64)
Definition: actypes.h:530
ACPI_STATUS AcpiOsReadPciConfiguration(ACPI_PCI_ID *PciId, UINT32 Reg, UINT64 *Value, UINT32 Width)
Definition: osl.c:793
#define TRUE
Definition: types.h:120
#define METHOD_NAME__ADR
Definition: acnames.h:49
UINT16 Bus
Definition: actypes.h:1327
#define ACPI_LOWORD(Integer)
Definition: actypes.h:528
ACPI_STATUS AcpiUtEvaluateNumericObject(const char *ObjectName, ACPI_NAMESPACE_NODE *DeviceNode, UINT64 *Value)
Definition: uteval.c:221
UINT16 Device
Definition: actypes.h:1328
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
UINT32 void void ** ReturnValue
Definition: acevents.h:214
UINT32 ACPI_OBJECT_TYPE
Definition: actypes.h:676
#define PCI_CFG_SECONDARY_BUS_NUMBER_REG
Definition: hwpci.c:56
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
#define PCI_TYPE_CARDBUS_BRIDGE
Definition: hwpci.c:62
#define PCI_HEADER_TYPE_MASK
Definition: hwpci.c:60
#define PCI_CFG_PRIMARY_BUS_NUMBER_REG
Definition: hwpci.c:55
#define ACPI_HIWORD(Integer)
Definition: actypes.h:529
#define ACPI_TYPE_DEVICE
Definition: actypes.h:684
Status
Definition: gdiplustypes.h:24
#define PCI_CFG_HEADER_TYPE_REG
Definition: hwpci.c:54
unsigned short UINT16
#define PCI_TYPE_BRIDGE
Definition: hwpci.c:61
ACPI_STATUS AcpiGetType(ACPI_HANDLE Handle, ACPI_OBJECT_TYPE *RetType)
Definition: nsxfobj.c:69
UINT16 Function
Definition: actypes.h:1329
unsigned long long UINT64
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiHwProcessPciList().

◆ AcpiHwProcessPciList()

static ACPI_STATUS AcpiHwProcessPciList ( ACPI_PCI_ID PciId,
ACPI_PCI_DEVICE ListHead 
)
static

Definition at line 266 of file hwpci.c.

269 {
273  BOOLEAN IsBridge = TRUE;
274 
275 
276  ACPI_FUNCTION_NAME (HwProcessPciList);
277 
278 
280  "Input PciId: Seg %4.4X Bus %4.4X Dev %4.4X Func %4.4X\n",
281  PciId->Segment, PciId->Bus, PciId->Device, PciId->Function));
282 
283  BusNumber = PciId->Bus;
284 
285  /*
286  * Descend down the namespace tree, collecting PCI device, function,
287  * and bus numbers. BusNumber is only important for PCI bridges.
288  * Algorithm: As we descend the tree, use the last valid PCI device,
289  * function, and bus numbers that are discovered, and assign them
290  * to the PCI ID for the target device.
291  */
292  Info = ListHead;
293  while (Info)
294  {
295  Status = AcpiHwGetPciDeviceInfo (PciId, Info->Device,
296  &BusNumber, &IsBridge);
297  if (ACPI_FAILURE (Status))
298  {
299  return (Status);
300  }
301 
302  Info = Info->Next;
303  }
304 
306  "Output PciId: Seg %4.4X Bus %4.4X Dev %4.4X Func %4.4X "
307  "Status %X BusNumber %X IsBridge %X\n",
308  PciId->Segment, PciId->Bus, PciId->Device, PciId->Function,
309  Status, BusNumber, IsBridge));
310 
311  return (AE_OK);
312 }
#define TRUE
Definition: types.h:120
UINT16 Bus
Definition: actypes.h:1327
UINT16 Device
Definition: actypes.h:1328
UINT32 ACPI_STATUS
Definition: actypes.h:460
struct TraceInfo Info
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
unsigned char BOOLEAN
#define ACPI_DB_OPREGION
Definition: acoutput.h:167
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
UINT16 Segment
Definition: actypes.h:1326
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
static ACPI_STATUS AcpiHwGetPciDeviceInfo(ACPI_PCI_ID *PciId, ACPI_HANDLE PciDevice, UINT16 *BusNumber, BOOLEAN *IsBridge)
Definition: hwpci.c:367
Status
Definition: gdiplustypes.h:24
unsigned short UINT16
#define ACPI_FUNCTION_NAME(a)
Definition: acoutput.h:479
UINT16 Function
Definition: actypes.h:1329
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiHwDerivePciId().