ReactOS  0.4.15-dev-3181-g4acf100
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 
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 
147  DriverObject->DriverExtension->AddDevice = PciIdeXAddDevice;
148 
149  for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
150  DriverObject->MajorFunction[i] = PciIdeXForwardOrIgnore;
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
_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 BytesWritten
Definition: wdfiotarget.h:949
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
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3767
return STATUS_NOT_SUPPORTED
ULONG PciIdeDebug
Global debugging level. Valid values are between 0 (Error) and 3 (Trace).
Definition: miniport.c:15
#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
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1799
#define IRP_MN_QUERY_POWER
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
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
_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:859
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
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
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS(NTAPI * PCONTROLLER_PROPERTIES)(IN PVOID DeviceExtension, IN PIDE_CONTROLLER_PROPERTIES ControllerProperties)
Definition: ide.h:245
DRIVER_ADD_DEVICE PciIdeXAddDevice
Definition: pciidex.h:43
#define _In_
Definition: ms_sal.h:308
#define IoCompleteRequest
Definition: irp.c:1240
char * va_list
Definition: acmsvcex.h:78
#define _In_z_
Definition: ms_sal.h:313
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
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
va_start(ap, x)
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:916
#define PCI_WHICHSPACE_CONFIG
Definition: iotypes.h:3644
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define IRP_MN_SET_POWER
DRIVER_DISPATCH(nfs41_FsdDispatch)
PGET_SET_DEVICE_DATA SetBusData
Definition: iotypes.h:915
NTSTATUS NTAPI PciIdeXFdoPnpDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:402
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
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:746
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
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1697
#define NULL
Definition: types.h:112
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define _Printf_format_string_
Definition: ms_sal.h:561
#define DPRINT1
Definition: precomp.h:8
#define IRP_MJ_CLEANUP
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:31
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
char * cleanup(char *str)
Definition: wpickclick.c:99
static DRIVER_DISPATCH PciIdeXForwardOrIgnore
Definition: miniport.c:17
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
_Dispatch_type_(IRP_MJ_POWER)
Definition: miniport.c:48
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