ReactOS  0.4.13-dev-101-g0ca4b50
intrface.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS PCI Bus Driver
3  * LICENSE: BSD - See COPYING.ARM in the top level directory
4  * FILE: drivers/bus/pci/intrface/intrface.c
5  * PURPOSE: Common Interface Support Routines
6  * PROGRAMMERS: ReactOS Portable Systems Group
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include <pci.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* GLOBALS ********************************************************************/
17 
19 {
29 // &PciNativeIdeInterface,
32  NULL
33 };
34 
36 {
38  NULL
39 };
40 
41 /* FUNCTIONS ******************************************************************/
42 
44 NTAPI
46  IN CONST GUID* InterfaceType,
47  IN ULONG Size,
51  IN BOOLEAN LastChance)
52 {
56  PPCI_INTERFACE PciInterface;
57  RtlStringFromGUID(InterfaceType, &GuidString);
58  DPRINT1("PCI - PciQueryInterface TYPE = %wZ\n", &GuidString);
60  DPRINT1(" Size = %u, Version = %u, InterfaceData = %p, LastChance = %s\n",
61  Size,
62  Version,
64  LastChance ? "TRUE" : "FALSE");
65 
66  /* Loop all the available interfaces */
69  InterfaceList++)
70  {
71  /* Get the current interface */
72  PciInterface = *InterfaceList;
73 
74  /* For debugging, construct the GUID string */
76 
77  /* Check if this is an FDO or PDO */
78  if (DeviceExtension->ExtensionType == PciFdoExtensionType)
79  {
80  /* Check if the interface is for FDOs */
81  if (!(PciInterface->Flags & PCI_INTERFACE_FDO))
82  {
83  /* This interface is not for FDOs, skip it */
84  DPRINT1("PCI - PciQueryInterface: guid = %wZ only for FDOs\n",
85  &GuidString);
87  continue;
88  }
89 
90  /* Check if the interface is for root FDO only */
91  if ((PciInterface->Flags & PCI_INTERFACE_ROOT) &&
92  (!PCI_IS_ROOT_FDO(DeviceExtension)))
93  {
94  /* This FDO isn't the root, skip the interface */
95  DPRINT1("PCI - PciQueryInterface: guid = %wZ only for ROOT\n",
96  &GuidString);
98  continue;
99  }
100  }
101  else
102  {
103  /* This is a PDO, check if the interface is for PDOs too */
104  if (!(PciInterface->Flags & PCI_INTERFACE_PDO))
105  {
106  /* It isn't, skip it */
107  DPRINT1("PCI - PciQueryInterface: guid = %wZ only for PDOs\n",
108  &GuidString);
110  continue;
111  }
112  }
113 
114  /* Print the GUID for debugging, and then free the string */
115  DPRINT1("PCI - PciQueryInterface looking at guid = %wZ\n", &GuidString);
117 
118  /* Check if the GUID, version, and size all match */
119  if ((IsEqualGUIDAligned(PciInterface->InterfaceType, InterfaceType)) &&
120  (Version >= PciInterface->MinVersion) &&
121  (Version <= PciInterface->MaxVersion) &&
122  (Size >= PciInterface->MinSize))
123  {
124  /* Call the interface's constructor */
125  Status = PciInterface->Constructor(DeviceExtension,
126  PciInterface,
128  Version,
129  Size,
130  Interface);
131  if (!NT_SUCCESS(Status))
132  {
133  /* This interface was not initialized correctly, skip it */
134  DPRINT1("PCI - PciQueryInterface - Constructor %p = %08lx\n",
135  PciInterface->Constructor, Status);
136  continue;
137  }
138 
139  /* Reference the interface and return success, all is good */
140  Interface->InterfaceReference(Interface->Context);
141  DPRINT1("PCI - PciQueryInterface returning SUCCESS\n");
142  return Status;
143  }
144  }
145 
146  /* An interface of this type, and for this device, could not be found */
147  DPRINT1("PCI - PciQueryInterface FAILED TO FIND INTERFACE\n");
148  return STATUS_NOT_SUPPORTED;
149 }
150 
151 /* EOF */
static PWSTR GuidString
Definition: apphelp.c:91
#define IN
Definition: typedefs.h:38
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:359
_In_ PUSBD_INTERFACE_LIST_ENTRY InterfaceList
Definition: usbdlib.h:168
PCI_INTERFACE ArbiterInterfaceBusNumber
Definition: ar_busno.c:18
LONG NTSTATUS
Definition: precomp.h:26
CONST GUID * InterfaceType
Definition: pci.h:375
PCI_INTERFACE ArbiterInterfaceIo
Definition: ar_memio.c:31
USHORT Flags
Definition: pci.h:379
#define PCI_INTERFACE_ROOT
Definition: pci.h:57
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:233
#define PCI_INTERFACE_FDO
Definition: pci.h:56
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PCI_INTERFACE ArbiterInterfaceMemory
Definition: ar_memio.c:18
PPCI_INTERFACE PciInterfacesLastResort[]
Definition: intrface.c:35
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
PCI_INTERFACE BusHandlerInterface
Definition: busintrf.c:18
IN PVOID IN PVOID IN USHORT IN USHORT IN PINTERFACE Interface
Definition: pci.h:359
PPCI_INTERFACE PciInterfaces[]
Definition: intrface.c:18
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PCI_INTERFACE TranslatorInterfaceInterrupt
Definition: tr_irq.c:18
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
PCI_INTERFACE PciLegacyDeviceDetectionInterface
Definition: lddintrf.c:18
USHORT MinVersion
Definition: pci.h:377
NTSTATUS NTAPI PciQueryInterface(IN PPCI_FDO_EXTENSION DeviceExtension, IN CONST GUID *InterfaceType, IN ULONG Size, IN ULONG Version, IN PVOID InterfaceData, IN PINTERFACE Interface, IN BOOLEAN LastChance)
Definition: intrface.c:45
PCI_INTERFACE PciLocationInterface
Definition: locintrf.c:18
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
#define PCI_INTERFACE_PDO
Definition: pci.h:55
#define PCI_IS_ROOT_FDO(x)
Definition: pci.h:30
PCI_INTERFACE PciCardbusPrivateInterface
Definition: cardbus.c:18
PCI_INTERFACE_CONSTRUCTOR Constructor
Definition: pci.h:382
PCI_INTERFACE AgpTargetInterface
Definition: agpintrf.c:20
#define DPRINT1
Definition: precomp.h:8
PCI_INTERFACE PciRoutingInterface
Definition: routintf.c:20
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
IN PVOID IN PVOID InterfaceData
Definition: pci.h:359
PCI_INTERFACE PciDevicePresentInterface
Definition: devhere.c:18
#define CONST
Definition: pedump.c:81
USHORT MinSize
Definition: pci.h:376
PCI_INTERFACE PciPmeInterface
Definition: pmeintf.c:18