ReactOS 0.4.17-dev-1190-g4c812f4
devhere.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/devhere.c
5 * PURPOSE: Device Presence Interface
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{
20 &GUID_PCI_DEVICE_PRESENT_INTERFACE,
25 0,
29};
30
31/* FUNCTIONS ******************************************************************/
32
36{
38 /* PnP Interfaces don't get Initialized */
39 ASSERTMSG("PCI devpresent_Initializer, unexpected call.\n", FALSE);
41}
42
43static
44VOID
48{
50
51 InterlockedIncrement(&PdoExtension->BusInterfaceReferenceCount);
52}
53
54static
55VOID
59{
61
62 InterlockedDecrement(&PdoExtension->BusInterfaceReferenceCount);
63}
64
68static
74{
75 ULONG Flags = Parameters->Flags;
76
77 /* The PDO stays on the list after its function leaves the slot */
78 if (PdoExtension->ReportedMissing)
79 return FALSE;
80
81 if ((Flags & PCI_USE_VENDEV_IDS) &&
82 ((PdoExtension->VendorId != Parameters->VendorID) ||
83 (PdoExtension->DeviceId != Parameters->DeviceID)))
84 {
85 return FALSE;
86 }
87
89 ((PdoExtension->SubsystemVendorId != Parameters->SubVendorID) ||
90 (PdoExtension->SubsystemId != Parameters->SubSystemID)))
91 {
92 return FALSE;
93 }
94
95 if ((Flags & PCI_USE_REVISION) &&
96 (PdoExtension->RevisionId != Parameters->RevisionID))
97 {
98 return FALSE;
99 }
100
102 ((PdoExtension->BaseClass != Parameters->BaseClass) ||
103 (PdoExtension->SubClass != Parameters->SubClass)))
104 {
105 return FALSE;
106 }
107
108 if ((Flags & PCI_USE_PROGIF) &&
109 (PdoExtension->ProgIf != Parameters->ProgIf))
110 {
111 return FALSE;
112 }
113
114 return TRUE;
115}
116
121static
123NTAPI
128{
130 PAGED_CODE();
131
134
135 for (Child = FdoExtension->ChildPdoList; Child; Child = Child->Next)
136 {
137 if (Slot && (Child->Slot.u.bits.DeviceNumber != Slot->u.bits.DeviceNumber))
138 continue;
139
141 break;
142 }
143
144 KeSetEvent(&FdoExtension->ChildListLock, IO_NO_INCREMENT, FALSE);
146
147 return (Child != NULL);
148}
149
153static
155NTAPI
158{
161 PAGED_CODE();
162
165
168 {
171 }
172
175
176 return Found;
177}
178
179static
181NTAPI
189{
191 PAGED_CODE();
192
194 Parameters.Size = sizeof(Parameters);
195 Parameters.VendorID = VendorID;
196 Parameters.DeviceID = DeviceID;
197 Parameters.RevisionID = RevisionID;
198 Parameters.SubVendorID = SubVendorID;
199 Parameters.SubSystemID = SubSystemID;
200
201 /* The first version always matches the IDs and only knows these two flags */
204
206}
207
212static
214NTAPI
217{
218 ULONG Needed = 0;
219
221 Needed |= PCI_USE_VENDEV_IDS;
222 if (Flags & PCI_USE_PROGIF)
223 Needed |= PCI_USE_CLASS_SUBCLASS;
224
225 return ((Flags & (PCI_USE_VENDEV_IDS | PCI_USE_CLASS_SUBCLASS)) != 0) &&
226 ((Flags & Needed) == Needed);
227}
228
229static
231NTAPI
235{
237 PPCI_SLOT_NUMBER Slot = NULL;
238 PAGED_CODE();
239
240 if (!Parameters ||
241 (Parameters->Size < sizeof(*Parameters)) ||
243 {
244 return FALSE;
245 }
246
248 {
249 case 0:
251
253 break;
254
255 default:
256 if (PdoExtension)
257 Slot = &PdoExtension->Slot;
258 break;
259 }
260
261 /* A local search is relative to the device that was asked */
262 if (!PdoExtension)
263 return FALSE;
264
265 return devpresent_SearchBus(PdoExtension->ParentFdoExtension, Slot, Parameters);
266}
267
269NTAPI
272 IN PVOID InterfaceData,
274 IN USHORT Size,
276{
278 BOOLEAN HasEx;
279 PAGED_CODE();
280
282 UNREFERENCED_PARAMETER(InterfaceData);
284
285 /* Callers built before IsDevicePresentEx existed pass the shorter size */
286 HasEx = (Size >= sizeof(*PresentInterface));
287
289 if (HasEx)
291
292 PresentInterface->InterfaceReference = devpresent_Reference;
294 PresentInterface->Context = DeviceExtension;
296 PresentInterface->Size = (USHORT)(HasEx ? sizeof(*PresentInterface) :
297 FIELD_OFFSET(PCI_DEVICE_PRESENT_INTERFACE, IsDevicePresentEx));
298
299 return STATUS_SUCCESS;
300}
301
302/* EOF */
#define PAGED_CODE()
unsigned char BOOLEAN
Definition: actypes.h:127
USHORT VendorID
Definition: ahci_generic.c:17
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
LONG NTSTATUS
Definition: precomp.h:26
SINGLE_LIST_ENTRY PciFdoExtensionListHead
Definition: fdo.c:18
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
return Found
Definition: dirsup.c:1270
_In_ HANDLE _In_ CONST PDXGKMDT_OPM_GET_INFO_PARAMETERS Parameters
Definition: dispmprt.h:321
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
KEVENT PciGlobalLock
Definition: init.c:20
#define PCI_INTERFACE_PDO
Definition: pci.h:67
struct _PCI_FDO_EXTENSION * PPCI_FDO_EXTENSION
@ PciInterface_DevicePresent
Definition: pci.h:145
@ PdoExtension
Definition: precomp.h:61
@ FdoExtension
Definition: precomp.h:60
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
PCI_INTERFACE PciDevicePresentInterface
Definition: devhere.c:18
NTSTATUS NTAPI devpresent_Constructor(IN PVOID DeviceExtension, IN PVOID Instance, IN PVOID InterfaceData, IN USHORT Version, IN USHORT Size, IN PINTERFACE Interface)
Definition: devhere.c:270
static BOOLEAN NTAPI devpresent_IsDevicePresent(_In_ USHORT VendorID, _In_ USHORT DeviceID, _In_ UCHAR RevisionID, _In_ USHORT SubVendorID, _In_ USHORT SubSystemID, _In_ ULONG Flags)
Definition: devhere.c:182
static VOID NTAPI devpresent_Dereference(_In_ PVOID Context)
Definition: devhere.c:57
static BOOLEAN NTAPI devpresent_IsDevicePresentEx(_In_ PVOID Context, _In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters)
Definition: devhere.c:232
static BOOLEAN NTAPI devpresent_SearchBus(_In_ PPCI_FDO_EXTENSION FdoExtension, _In_opt_ PPCI_SLOT_NUMBER Slot, _In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters)
Searches the children of one bus.
Definition: devhere.c:124
static BOOLEAN NTAPI devpresent_FlagsValid(_In_ ULONG Flags)
Checks that the search flags name the device by IDs, class, or both. Subsystem and revision refine an...
Definition: devhere.c:215
static VOID NTAPI devpresent_Reference(_In_ PVOID Context)
Definition: devhere.c:46
static BOOLEAN NTAPI devpresent_IsMatch(_In_ PPCI_PDO_EXTENSION PdoExtension, _In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters)
Compares one child against the fields selected by the search flags.
Definition: devhere.c:71
static BOOLEAN NTAPI devpresent_SearchAllBuses(_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters)
Searches every PCI bus in the machine.
Definition: devhere.c:156
NTSTATUS NTAPI devpresent_Initializer(IN PVOID Instance)
Definition: devhere.c:35
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_ PVOID Context
Definition: kse.h:81
#define KernelMode
Definition: asm.h:38
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
PINTERFACE_REFERENCE InterfaceReference
Definition: iotypes.h:923
PINTERFACE_DEREFERENCE InterfaceDereference
Definition: iotypes.h:924
PPCI_IS_DEVICE_PRESENT_EX IsDevicePresentEx
Definition: iotypes.h:926
PPCI_IS_DEVICE_PRESENT IsDevicePresent
Definition: iotypes.h:925
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:641
unsigned char UCHAR
Definition: typedefs.h:53
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
_In_ UCXUSBDEVICE _In_ ULONG Interface
Definition: ucxusbdevice.h:428
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFDEVICE Child
Definition: wdffdo.h:536
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING DeviceID
Definition: wdfpdo.h:278
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_INSTANCE_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_opt_ WDFWMIINSTANCE * Instance
Definition: wdfwmi.h:481
#define PCI_USE_PROGIF
Definition: iotypes.h:870
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define PCI_USE_VENDEV_IDS
Definition: iotypes.h:868
#define PCI_DEVICE_PRESENT_INTERFACE_VERSION
Definition: iotypes.h:863
#define PCI_USE_CLASS_SUBCLASS
Definition: iotypes.h:869
struct _PCI_DEVICE_PRESENT_INTERFACE * PPCI_DEVICE_PRESENT_INTERFACE
#define PCI_USE_REVISION
Definition: iotypes.h:867
_In_ USHORT _In_ UCHAR _In_ USHORT _In_ USHORT SubSystemID
Definition: iotypes.h:895
#define PCI_USE_LOCAL_DEVICE
Definition: iotypes.h:872
_In_ USHORT _In_ UCHAR RevisionID
Definition: iotypes.h:893
#define PCI_USE_LOCAL_BUS
Definition: iotypes.h:871
#define PCI_USE_SUBSYSTEM_IDS
Definition: iotypes.h:866
_In_ USHORT _In_ UCHAR _In_ USHORT SubVendorID
Definition: iotypes.h:894
@ Executive
Definition: ketypes.h:467