ReactOS 0.4.15-dev-7906-g1b85a5f
pciidex.c
Go to the documentation of this file.
1/*
2 * PROJECT: PCI IDE bus driver extension
3 * LICENSE: See COPYING in the top level directory
4 * PURPOSE: Main file
5 * COPYRIGHT: Copyright 2005 Hervé Poussineau <hpoussin@reactos.org>
6 */
7
8#include "pciidex.h"
9
10#define NDEBUG
11#include <debug.h>
12
14
15CODE_SEG("PAGE")
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}
41
42CODE_SEG("PAGE")
43VOID
47{
49
50 PAGED_CODE();
51
52 NOTHING;
53}
54
55static
56CODE_SEG("PAGE")
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}
104
105static
106CODE_SEG("PAGE")
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}
151
152CODE_SEG("PAGE")
154NTAPI
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}
254
255static
256CODE_SEG("PAGE")
257VOID
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}
285
286CODE_SEG("PAGE")
288NTAPI
292 _In_ PCONTROLLER_PROPERTIES HwGetControllerProperties,
293 _In_ ULONG ExtensionSize)
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}
325
326CODE_SEG("PAGE") /* This function is too small to be placed into INIT section */
328NTAPI
332{
335
336 PAGED_CODE();
337
338 return STATUS_SUCCESS;
339}
#define PAGED_CODE()
#define CODE_SEG(...)
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 IRP_MJ_PNP
Definition: cdrw_usr.h:52
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
#define __FUNCTION__
Definition: types.h:116
NTSTATUS NTAPI PciIdeXDispatchPower(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: power.c:56
@ FdoExtension
Definition: precomp.h:48
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
NTSTATUS(NTAPI * PCONTROLLER_PROPERTIES)(_In_ PVOID DeviceExtension, _In_ PIDE_CONTROLLER_PROPERTIES ControllerProperties)
Definition: ide.h:245
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_PERMANENT
Definition: winternl.h:226
#define NOTHING
Definition: input_list.c:10
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
nsresult QueryInterface(nsIIDRef riid, void **result)
#define ASSERT(a)
Definition: mode.c:44
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define _Inout_
Definition: ms_sal.h:378
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI NTSTATUS NTAPI ZwCreateDirectoryObject(_Out_ PHANDLE DirectoryHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
#define FILE_WORD_ALIGNMENT
Definition: nt_native.h:787
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
#define RTL_SIZEOF_THROUGH_FIELD(type, field)
Definition: ntbasedef.h:672
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
@ SynchronizationEvent
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
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
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1826
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 IoCompleteRequest
Definition: irp.c:1240
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
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
NTSTATUS NTAPI PciIdeXInitialize(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath, _In_ PCONTROLLER_PROPERTIES HwGetControllerProperties, _In_ ULONG ExtensionSize)
Definition: pciidex.c:289
static NTSTATUS PciIdeXQueryInterface(_In_ PFDO_DEVICE_EXTENSION FdoExtension, _In_ const GUID *Guid, _Out_ PVOID Interface, _In_ ULONG Size)
Definition: pciidex.c:58
static VOID PciIdeXCreateIdeDirectory(VOID)
Definition: pciidex.c:258
NTSTATUS NTAPI PciIdeXDispatchWmi(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pciidex.c:18
ULONG PciIdeControllerNumber
Definition: pciidex.c:13
#define PCIIDE_PROGIF_SECONDARY_CHANNEL_NATIVE_MODE
Definition: pciidex.h:43
DRIVER_UNLOAD PciIdeXUnload
Definition: pciidex.h:113
DRIVER_ADD_DEVICE PciIdeXAddDevice
Definition: pciidex.h:116
#define IS_FDO(p)
Definition: pciidex.h:21
#define PCIIDE_PROGIF_PRIMARY_CHANNEL_NATIVE_MODE
Definition: pciidex.h:41
#define FILE_DEVICE_BUS_EXTENDER
Definition: winioctl.h:148
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
NTSTATUS NTAPI PciIdeXDispatchPnp(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:840
#define max(a, b)
Definition: svc.c:63
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_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
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_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
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define PCI_WHICHSPACE_CONFIG
Definition: iotypes.h:3644
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_QUERY_INTERFACE
#define PCI_CLASS_MASS_STORAGE_CTLR
Definition: iotypes.h:4104
#define PCI_SUBCLASS_MSC_IDE_CTLR
Definition: iotypes.h:4129
#define IRP_MJ_SYSTEM_CONTROL
struct _PCI_COMMON_HEADER * PPCI_COMMON_HEADER
#define PCI_SUBCLASS_MSC_RAID_CTLR
Definition: iotypes.h:4132
#define IRP_MJ_POWER
@ Executive
Definition: ketypes.h:415
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define const
Definition: zconf.h:233