ReactOS  0.4.15-dev-1150-g593bcce
miniport.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: PCI IDE bus driver extension
4  * FILE: drivers/storage/pciidex/miniport.c
5  * PURPOSE: Miniport functions
6  * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
7  */
8 
9 #include "pciidex.h"
10 
11 #define NDEBUG
12 #include <debug.h>
13 
16 
18 static NTSTATUS NTAPI
21  IN PIRP Irp)
22 {
23  if (((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO)
25  else
26  {
29 
30  if (MajorFunction == IRP_MJ_CREATE ||
31  MajorFunction == IRP_MJ_CLEANUP ||
32  MajorFunction == IRP_MJ_CLOSE)
33  {
35  }
36  else
37  {
38  DPRINT1("PDO stub for major function 0x%lx\n", MajorFunction);
40  }
41  Irp->IoStatus.Information = 0;
42  Irp->IoStatus.Status = Status;
44  return Status;
45  }
46 }
47 
49 static DRIVER_DISPATCH PciIdeXPowerDispatch;
50 static NTSTATUS NTAPI
51 PciIdeXPowerDispatch(
53  IN PIRP Irp)
54 {
56  PIO_STACK_LOCATION IoStack;
57  PDEVICE_OBJECT LowerDevice;
58 
60  if (((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO)
61  {
62  LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
65  return PoCallDriver(LowerDevice, Irp);
66  }
67  else
68  {
69  switch (IoStack->MinorFunction)
70  {
71  case IRP_MN_SET_POWER:
72  case IRP_MN_QUERY_POWER:
73  Irp->IoStatus.Status = STATUS_SUCCESS;
74  break;
75  }
76  Status = Irp->IoStatus.Status;
79  return Status;
80  }
81 }
82 
84 static DRIVER_DISPATCH PciIdeXPnpDispatch;
85 static NTSTATUS NTAPI
86 PciIdeXPnpDispatch(
88  IN PIRP Irp)
89 {
90  if (((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO)
92  else
94 }
95 
105 VOID
107  _In_ ULONG DebugPrintLevel,
108  _In_z_ _Printf_format_string_ PCCHAR DebugMessage,
109  ...)
110 {
111  va_list ap;
112 
113  /* Check if we can print anything */
114  if (DebugPrintLevel <= PciIdeDebug)
115  DebugPrintLevel = 0;
116 
117  va_start(ap, DebugMessage);
118  vDbgPrintEx(DPFLTR_PCIIDE_ID, DebugPrintLevel, DebugMessage, ap);
119  va_end(ap);
120 }
121 
126  IN PCONTROLLER_PROPERTIES HwGetControllerProperties,
127  IN ULONG ExtensionSize)
128 {
129  ULONG i;
132 
133  DPRINT("PciIdeXInitialize(%p '%wZ' %p 0x%lx)\n",
134  DriverObject, RegistryPath, HwGetControllerProperties, ExtensionSize);
135 
137  DriverObject,
138  DriverObject,
139  sizeof(PCIIDEX_DRIVER_EXTENSION),
141  if (!NT_SUCCESS(Status))
142  return Status;
144  DriverExtension->MiniControllerExtensionSize = ExtensionSize;
145  DriverExtension->HwGetControllerProperties = HwGetControllerProperties;
146 
148 
149  for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
151  DriverObject->MajorFunction[IRP_MJ_POWER] = PciIdeXPowerDispatch;
152  DriverObject->MajorFunction[IRP_MJ_PNP] = PciIdeXPnpDispatch;
153 
154  return STATUS_SUCCESS;
155 }
156 
157 /* May be called at IRQL <= DISPATCH_LEVEL */
160  IN PVOID DeviceExtension,
161  IN PVOID Buffer,
162  IN ULONG ConfigDataOffset,
164 {
165  PFDO_DEVICE_EXTENSION FdoDeviceExtension;
168 
169  DPRINT("PciIdeXGetBusData(%p %p 0x%lx 0x%lx)\n",
170  DeviceExtension, Buffer, ConfigDataOffset, BufferLength);
171 
172  FdoDeviceExtension = CONTAINING_RECORD(DeviceExtension, FDO_DEVICE_EXTENSION, MiniControllerExtension);
173  if (FdoDeviceExtension->BusInterface)
174  {
175  BytesRead = (*FdoDeviceExtension->BusInterface->GetBusData)(
176  FdoDeviceExtension->BusInterface->Context,
178  Buffer,
179  ConfigDataOffset,
180  BufferLength);
181  if (BytesRead == BufferLength)
183  }
184 
185  return Status;
186 }
187 
188 /* May be called at IRQL <= DISPATCH_LEVEL */
191  IN PVOID DeviceExtension,
192  IN PVOID Buffer,
193  IN PVOID DataMask,
194  IN ULONG ConfigDataOffset,
196 {
197  PFDO_DEVICE_EXTENSION FdoDeviceExtension;
201 
202  DPRINT("PciIdeXSetBusData(%p %p %p 0x%lx 0x%lx)\n",
203  DeviceExtension, Buffer, DataMask, ConfigDataOffset, BufferLength);
204 
206  if (!CurrentBuffer)
207  {
209  return Status;
210  }
211 
212  Status = PciIdeXGetBusData(DeviceExtension, Buffer, ConfigDataOffset, BufferLength);
213  if (!NT_SUCCESS(Status))
214  goto cleanup;
215 
216  for (i = 0; i < BufferLength; i++)
217  CurrentBuffer[i] = (CurrentBuffer[i] & ~((PUCHAR)DataMask)[i]) | (((PUCHAR)DataMask)[i] & ((PUCHAR)Buffer)[i]);
218 
219  FdoDeviceExtension = CONTAINING_RECORD(DeviceExtension, FDO_DEVICE_EXTENSION, MiniControllerExtension);
220  if (!FdoDeviceExtension->BusInterface)
221  {
223  goto cleanup;
224  }
225 
226  BytesWritten = (*FdoDeviceExtension->BusInterface->SetBusData)(
227  FdoDeviceExtension->BusInterface->Context,
230  ConfigDataOffset,
231  BufferLength);
232  if (BytesWritten == BufferLength)
234  else
236 
237 cleanup:
239  return Status;
240 }
static ACPI_BUFFER CurrentBuffer
NTSTATUS NTAPI PciIdeXSetBusData(IN PVOID DeviceExtension, IN PVOID Buffer, IN PVOID DataMask, IN ULONG ConfigDataOffset, IN ULONG BufferLength)
Definition: miniport.c:190
VOID PciIdeXDebugPrint(_In_ ULONG DebugPrintLevel, _In_z_ _Printf_format_string_ PCCHAR DebugMessage,...)
Prints the given string with printf-like formatting to the kernel debugger.
Definition: miniport.c:106
#define IN
Definition: typedefs.h:39
NTSTATUS(* PCONTROLLER_PROPERTIES)(IN PVOID DeviceExtension, IN PIDE_CONTROLLER_PROPERTIES ControllerProperties)
Definition: ide.h:377
ULONG PciIdeDebug
Global debugging level. Valid values are between 0 (Error) and 3 (Trace).
Definition: miniport.c:15
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PBUS_INTERFACE_STANDARD BusInterface
Definition: pciidex.h:23
_In_ PSCSI_REQUEST_BLOCK _In_opt_ PVOID _In_ ULONG BufferLength
Definition: cdrom.h:989
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1788
#define IRP_MN_QUERY_POWER
_In_ PIRP Irp
Definition: csq.h:116
unsigned char * PUCHAR
Definition: retypes.h:3
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
DRIVER_DISPATCH ForwardIrpAndForget
Definition: i8042prt.h:341
#define IRP_MJ_MAXIMUM_FUNCTION
LONG NTSTATUS
Definition: precomp.h:26
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define va_end(ap)
Definition: acmsvcex.h:90
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2262
DRIVER_ADD_DEVICE PciIdeXAddDevice
Definition: pciidex.h:43
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
char * va_list
Definition: acmsvcex.h:78
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_In_z_ PWSTR RegistryPath
Definition: classp.h:1930
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI ULONG NTAPI vDbgPrintEx(_In_ ULONG ComponentId, _In_ ULONG Level, _In_z_ PCCH Format, _In_ va_list ap)
PGET_SET_DEVICE_DATA GetBusData
Definition: iotypes.h:899
#define PCI_WHICHSPACE_CONFIG
Definition: iotypes.h:3623
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
Status
Definition: gdiplustypes.h:24
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define IRP_MN_SET_POWER
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
DRIVER_DISPATCH(nfs41_FsdDispatch)
PGET_SET_DEVICE_DATA SetBusData
Definition: iotypes.h:898
NTSTATUS NTAPI PciIdeXFdoPnpDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:402
#define _In_
Definition: no_sal2.h:204
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2200
NTSTATUS NTAPI PciIdeXInitialize(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath, IN PCONTROLLER_PROPERTIES HwGetControllerProperties, IN ULONG ExtensionSize)
Definition: miniport.c:123
NTSTATUS NTAPI PciIdeXPdoPnpDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.c:359
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
#define _In_z_
Definition: no_sal2.h:239
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define DPRINT1
Definition: precomp.h:8
#define IRP_MJ_CLEANUP
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2269
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:581
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
char * cleanup(char *str)
Definition: wpickclick.c:99
static DRIVER_DISPATCH PciIdeXForwardOrIgnore
Definition: miniport.c:17
return STATUS_SUCCESS
Definition: btrfs.c:3014
_Dispatch_type_(IRP_MJ_POWER)
Definition: miniport.c:48
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255
NTSTATUS NTAPI PciIdeXGetBusData(IN PVOID DeviceExtension, IN PVOID Buffer, IN ULONG ConfigDataOffset, IN ULONG BufferLength)
Definition: miniport.c:159
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define _Printf_format_string_
Definition: no_sal2.h:569