ReactOS 0.4.15-dev-7681-g776c3a3
pciidex.c File Reference
#include "pciidex.h"
#include <debug.h>
Include dependency graph for pciidex.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI PciIdeXDispatchWmi (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
VOID NTAPI PciIdeXUnload (_In_ PDRIVER_OBJECT DriverObject)
 
static NTSTATUS PciIdeXQueryInterface (_In_ PFDO_DEVICE_EXTENSION FdoExtension, _In_ const GUID *Guid, _Out_ PVOID Interface, _In_ ULONG Size)
 
static NTSTATUS PciIdeXGetConfigurationInfo (_In_ PFDO_DEVICE_EXTENSION FdoExtension)
 
NTSTATUS NTAPI PciIdeXAddDevice (_In_ PDRIVER_OBJECT DriverObject, _In_ PDEVICE_OBJECT PhysicalDeviceObject)
 
static VOID PciIdeXCreateIdeDirectory (VOID)
 
NTSTATUS NTAPI PciIdeXInitialize (_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath, _In_ PCONTROLLER_PROPERTIES HwGetControllerProperties, _In_ ULONG ExtensionSize)
 
NTSTATUS NTAPI DriverEntry (_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
 

Variables

ULONG PciIdeControllerNumber = 0
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file pciidex.c.

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( _In_ PDRIVER_OBJECT  DriverObject,
_In_ PUNICODE_STRING  RegistryPath 
)

Definition at line 329 of file pciidex.c.

332{
335
336 PAGED_CODE();
337
338 return STATUS_SUCCESS;
339}
#define PAGED_CODE()
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define STATUS_SUCCESS
Definition: shellext.h:65
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213

◆ PciIdeXAddDevice()

NTSTATUS NTAPI PciIdeXAddDevice ( _In_ PDRIVER_OBJECT  DriverObject,
_In_ PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 155 of file pciidex.c.

158{
161 ULONG DeviceExtensionSize;
164 WCHAR DeviceNameBuffer[sizeof("\\Device\\Ide\\PciIde999")];
166
167 PAGED_CODE();
168
169 Status = RtlStringCbPrintfW(DeviceNameBuffer,
170 sizeof(DeviceNameBuffer),
171 L"\\Device\\Ide\\PciIde%u",
174 RtlInitUnicodeString(&DeviceName, DeviceNameBuffer);
175
177
180
181 Status = RtlULongAdd(DriverExtension->MiniControllerExtensionSize,
182 sizeof(FDO_DEVICE_EXTENSION),
183 &DeviceExtensionSize);
184 if (!NT_SUCCESS(Status))
185 {
186 DPRINT1("Invalid miniport extension size %lx\n",
187 DriverExtension->MiniControllerExtensionSize);
188 return Status;
189 }
190
192 DeviceExtensionSize,
193 &DeviceName,
196 FALSE,
197 &Fdo);
198 if (!NT_SUCCESS(Status))
199 {
200 DPRINT1("Failed to create FDO 0x%lx\n", Status);
201 return Status;
202 }
203
204 FdoExtension = Fdo->DeviceExtension;
205
207 FdoExtension->Common.IsFDO = TRUE;
208 FdoExtension->Common.Self = Fdo;
209 FdoExtension->DriverObject = DriverObject;
210 FdoExtension->ControllerNumber = PciIdeControllerNumber++;
211
212 KeInitializeSpinLock(&FdoExtension->BusDataLock);
213 ExInitializeFastMutex(&FdoExtension->DeviceSyncMutex);
214
216 if (!NT_SUCCESS(Status))
217 {
218 DPRINT("Failed to attach FDO 0x%lx\n", Status);
219 goto Failure;
220 }
221
222 /* DMA buffers alignment */
223 Fdo->AlignmentRequirement = max(FdoExtension->Ldo->AlignmentRequirement, FILE_WORD_ALIGNMENT);
224
226 &GUID_BUS_INTERFACE_STANDARD,
227 &FdoExtension->BusInterface,
228 sizeof(BUS_INTERFACE_STANDARD));
229 if (!NT_SUCCESS(Status))
230 {
231 DPRINT1("No bus interface 0x%lx\n", Status);
232 goto Failure;
233 }
234
236 if (!NT_SUCCESS(Status))
237 {
238 DPRINT1("Unable to retrieve the configuration info %lx\n", Status);
239 goto Failure;
240 }
241
242 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
243
244 return STATUS_SUCCESS;
245
246Failure:
247 if (FdoExtension->Ldo)
249
251
252 return Status;
253}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define __FUNCTION__
Definition: types.h:116
@ FdoExtension
Definition: precomp.h:48
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
#define FILE_WORD_ALIGNMENT
Definition: nt_native.h:787
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:980
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1904
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
#define L(x)
Definition: ntvdm.h:50
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:31
static NTSTATUS PciIdeXGetConfigurationInfo(_In_ PFDO_DEVICE_EXTENSION FdoExtension)
Definition: pciidex.c:108
static NTSTATUS PciIdeXQueryInterface(_In_ PFDO_DEVICE_EXTENSION FdoExtension, _In_ const GUID *Guid, _Out_ PVOID Interface, _In_ ULONG Size)
Definition: pciidex.c:58
ULONG PciIdeControllerNumber
Definition: pciidex.c:13
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:148
#define DPRINT
Definition: sndvol32.h:71
#define max(a, b)
Definition: svc.c:63
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ PciIdeXCreateIdeDirectory()

static VOID PciIdeXCreateIdeDirectory ( VOID  )
static

Definition at line 258 of file pciidex.c.

259{
263 UNICODE_STRING DirectoryName = RTL_CONSTANT_STRING(L"\\Device\\Ide");
264
265 PAGED_CODE();
266
268 &DirectoryName,
270 NULL,
271 NULL);
272
274 if (NT_SUCCESS(Status))
275 {
276 /* We don't need a handle for a permanent object */
278 }
279 /*
280 * Ignore directory creation failures (don't report them as a driver initialization error)
281 * as the directory may have already been created by another driver.
282 * We will handle fatal errors later via IoCreateDevice() call.
283 */
284}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
ULONG Handle
Definition: gdb_input.c:15
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_PERMANENT
Definition: winternl.h:226
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI NTSTATUS NTAPI ZwCreateDirectoryObject(_Out_ PHANDLE DirectoryHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by PciIdeXInitialize().

◆ PciIdeXDispatchWmi()

NTSTATUS NTAPI PciIdeXDispatchWmi ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)

Definition at line 18 of file pciidex.c.

21{
23
24 PAGED_CODE();
25
26 if (IS_FDO(DeviceObject->DeviceExtension))
27 {
29
32 }
33 else
34 {
35 Status = Irp->IoStatus.Status;
37 }
38
39 return Status;
40}
_In_ PIRP Irp
Definition: csq.h:116
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCompleteRequest
Definition: irp.c:1240
#define IoCallDriver
Definition: irp.c:1225
#define IS_FDO(p)
Definition: pciidex.h:21
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by PciIdeXInitialize().

◆ PciIdeXGetConfigurationInfo()

static NTSTATUS PciIdeXGetConfigurationInfo ( _In_ PFDO_DEVICE_EXTENSION  FdoExtension)
static

Definition at line 108 of file pciidex.c.

110{
114
115 PAGED_CODE();
116
117 BytesRead = (*FdoExtension->BusInterface.GetBusData)(FdoExtension->BusInterface.Context,
119 Buffer,
120 0,
121 sizeof(Buffer));
122 if (BytesRead != sizeof(Buffer))
124
125 FdoExtension->VendorId = PciConfig->VendorID;
126 FdoExtension->DeviceId = PciConfig->DeviceID;
127
128 if (PciConfig->BaseClass == PCI_CLASS_MASS_STORAGE_CTLR)
129 {
130 if (PciConfig->SubClass == PCI_SUBCLASS_MSC_IDE_CTLR)
131 {
132 /* Both IDE channels in native mode */
133 FdoExtension->InNativeMode =
134 (PciConfig->ProgIf & PCIIDE_PROGIF_PRIMARY_CHANNEL_NATIVE_MODE) &&
136 }
137 else if (PciConfig->SubClass == PCI_SUBCLASS_MSC_RAID_CTLR)
138 {
139 FdoExtension->InNativeMode = TRUE;
140 }
141 }
142
143 DPRINT("Controller %04x:%04x, Interface byte 0x%02x, Native mode %d\n",
144 FdoExtension->VendorId,
145 FdoExtension->DeviceId,
146 PciConfig->ProgIf,
147 FdoExtension->InNativeMode);
148
149 return STATUS_SUCCESS;
150}
Definition: bufpool.h:45
#define RTL_SIZEOF_THROUGH_FIELD(type, field)
Definition: ntbasedef.h:672
#define PCIIDE_PROGIF_SECONDARY_CHANNEL_NATIVE_MODE
Definition: pciidex.h:43
#define PCIIDE_PROGIF_PRIMARY_CHANNEL_NATIVE_MODE
Definition: pciidex.h:41
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
#define PCI_WHICHSPACE_CONFIG
Definition: iotypes.h:3644
#define PCI_CLASS_MASS_STORAGE_CTLR
Definition: iotypes.h:4104
#define PCI_SUBCLASS_MSC_IDE_CTLR
Definition: iotypes.h:4129
struct _PCI_COMMON_HEADER * PPCI_COMMON_HEADER
#define PCI_SUBCLASS_MSC_RAID_CTLR
Definition: iotypes.h:4132
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by PciIdeXAddDevice().

◆ PciIdeXInitialize()

NTSTATUS NTAPI PciIdeXInitialize ( _In_ PDRIVER_OBJECT  DriverObject,
_In_ PUNICODE_STRING  RegistryPath,
_In_ PCONTROLLER_PROPERTIES  HwGetControllerProperties,
_In_ ULONG  ExtensionSize 
)

Definition at line 289 of file pciidex.c.

294{
297
298 PAGED_CODE();
299
300 DPRINT("PciIdeXInitialize(%p '%wZ' %p 0x%lx)\n",
301 DriverObject, RegistryPath, HwGetControllerProperties, ExtensionSize);
302
307 if (!NT_SUCCESS(Status))
308 return Status;
309
311 DriverExtension->MiniControllerExtensionSize = ExtensionSize;
312 DriverExtension->HwGetControllerProperties = HwGetControllerProperties;
313
317 DriverObject->DriverExtension->AddDevice = PciIdeXAddDevice;
318 DriverObject->DriverUnload = PciIdeXUnload;
319
320 /* Create a directory to hold the driver's device objects */
322
323 return STATUS_SUCCESS;
324}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
NTSTATUS NTAPI PciIdeXDispatchPower(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: power.c:56
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1826
static VOID PciIdeXCreateIdeDirectory(VOID)
Definition: pciidex.c:258
NTSTATUS NTAPI PciIdeXDispatchWmi(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pciidex.c:18
DRIVER_UNLOAD PciIdeXUnload
Definition: pciidex.h:113
DRIVER_ADD_DEVICE PciIdeXAddDevice
Definition: pciidex.h:116
NTSTATUS NTAPI PciIdeXDispatchPnp(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:840
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_POWER

Referenced by DriverEntry().

◆ PciIdeXQueryInterface()

static NTSTATUS PciIdeXQueryInterface ( _In_ PFDO_DEVICE_EXTENSION  FdoExtension,
_In_ const GUID Guid,
_Out_ PVOID  Interface,
_In_ ULONG  Size 
)
static

Definition at line 58 of file pciidex.c.

63{
66 PIRP Irp;
69
70 PAGED_CODE();
71
73
75 FdoExtension->Ldo,
76 NULL,
77 0,
78 NULL,
79 &Event,
80 &IoStatus);
81 if (!Irp)
83
84 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
85 Irp->IoStatus.Information = 0;
86
88 Stack->MinorFunction = IRP_MN_QUERY_INTERFACE;
89 Stack->Parameters.QueryInterface.InterfaceType = Guid;
90 Stack->Parameters.QueryInterface.Version = 1;
91 Stack->Parameters.QueryInterface.Size = Size;
92 Stack->Parameters.QueryInterface.Interface = Interface;
93 Stack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
94
97 {
99 Status = IoStatus.Status;
100 }
101
102 return Status;
103}
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
nsresult QueryInterface(nsIIDRef riid, void **result)
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define KernelMode
Definition: asm.h:34
@ SynchronizationEvent
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define IRP_MN_QUERY_INTERFACE
@ Executive
Definition: ketypes.h:415

Referenced by PciIdeXAddDevice().

◆ PciIdeXUnload()

VOID NTAPI PciIdeXUnload ( _In_ PDRIVER_OBJECT  DriverObject)

Definition at line 45 of file pciidex.c.

47{
49
50 PAGED_CODE();
51
52 NOTHING;
53}
#define NOTHING
Definition: input_list.c:10

Variable Documentation

◆ PciIdeControllerNumber

ULONG PciIdeControllerNumber = 0

Definition at line 13 of file pciidex.c.

Referenced by PciIdeXAddDevice().