ReactOS  0.4.13-dev-66-gc714b7f
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 
15 static NTSTATUS NTAPI
18  IN PIRP Irp)
19 {
22  else
23  {
26 
27  if (MajorFunction == IRP_MJ_CREATE ||
28  MajorFunction == IRP_MJ_CLEANUP ||
29  MajorFunction == IRP_MJ_CLOSE)
30  {
32  }
33  else
34  {
35  DPRINT1("PDO stub for major function 0x%lx\n", MajorFunction);
37  }
38  Irp->IoStatus.Information = 0;
39  Irp->IoStatus.Status = Status;
41  return Status;
42  }
43 }
44 
46 static DRIVER_DISPATCH PciIdeXPowerDispatch;
47 static NTSTATUS NTAPI
48 PciIdeXPowerDispatch(
50  IN PIRP Irp)
51 {
53  PIO_STACK_LOCATION IoStack;
54  PDEVICE_OBJECT LowerDevice;
55 
58  {
59  LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
62  return PoCallDriver(LowerDevice, Irp);
63  }
64  else
65  {
66  switch (IoStack->MinorFunction)
67  {
68  case IRP_MN_SET_POWER:
69  case IRP_MN_QUERY_POWER:
70  Irp->IoStatus.Status = STATUS_SUCCESS;
71  break;
72  }
73  Status = Irp->IoStatus.Status;
76  return Status;
77  }
78 }
79 
81 static DRIVER_DISPATCH PciIdeXPnpDispatch;
82 static NTSTATUS NTAPI
83 PciIdeXPnpDispatch(
85  IN PIRP Irp)
86 {
89  else
91 }
92 
97  IN PCONTROLLER_PROPERTIES HwGetControllerProperties,
98  IN ULONG ExtensionSize)
99 {
100  ULONG i;
103 
104  DPRINT("PciIdeXInitialize(%p '%wZ' %p 0x%lx)\n",
105  DriverObject, RegistryPath, HwGetControllerProperties, ExtensionSize);
106 
108  DriverObject,
109  DriverObject,
110  sizeof(PCIIDEX_DRIVER_EXTENSION),
112  if (!NT_SUCCESS(Status))
113  return Status;
115  DriverExtension->MiniControllerExtensionSize = ExtensionSize;
116  DriverExtension->HwGetControllerProperties = HwGetControllerProperties;
117 
119 
120  for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
122  DriverObject->MajorFunction[IRP_MJ_POWER] = PciIdeXPowerDispatch;
123  DriverObject->MajorFunction[IRP_MJ_PNP] = PciIdeXPnpDispatch;
124 
125  return STATUS_SUCCESS;
126 }
127 
128 /* May be called at IRQL <= DISPATCH_LEVEL */
131  IN PVOID DeviceExtension,
132  IN PVOID Buffer,
133  IN ULONG ConfigDataOffset,
135 {
136  PFDO_DEVICE_EXTENSION FdoDeviceExtension;
139 
140  DPRINT("PciIdeXGetBusData(%p %p 0x%lx 0x%lx)\n",
141  DeviceExtension, Buffer, ConfigDataOffset, BufferLength);
142 
143  FdoDeviceExtension = CONTAINING_RECORD(DeviceExtension, FDO_DEVICE_EXTENSION, MiniControllerExtension);
144  if (FdoDeviceExtension->BusInterface)
145  {
146  BytesRead = (*FdoDeviceExtension->BusInterface->GetBusData)(
147  FdoDeviceExtension->BusInterface->Context,
149  Buffer,
150  ConfigDataOffset,
151  BufferLength);
152  if (BytesRead == BufferLength)
154  }
155 
156  return Status;
157 }
158 
159 /* May be called at IRQL <= DISPATCH_LEVEL */
162  IN PVOID DeviceExtension,
163  IN PVOID Buffer,
164  IN PVOID DataMask,
165  IN ULONG ConfigDataOffset,
167 {
168  PFDO_DEVICE_EXTENSION FdoDeviceExtension;
172 
173  DPRINT("PciIdeXSetBusData(%p %p %p 0x%lx 0x%lx)\n",
174  DeviceExtension, Buffer, DataMask, ConfigDataOffset, BufferLength);
175 
177  if (!CurrentBuffer)
178  {
180  return Status;
181  }
182 
183  Status = PciIdeXGetBusData(DeviceExtension, Buffer, ConfigDataOffset, BufferLength);
184  if (!NT_SUCCESS(Status))
185  goto cleanup;
186 
187  for (i = 0; i < BufferLength; i++)
188  CurrentBuffer[i] = (CurrentBuffer[i] & ~((PUCHAR)DataMask)[i]) | (((PUCHAR)DataMask)[i] & ((PUCHAR)Buffer)[i]);
189 
190  FdoDeviceExtension = CONTAINING_RECORD(DeviceExtension, FDO_DEVICE_EXTENSION, MiniControllerExtension);
191  if (!FdoDeviceExtension->BusInterface)
192  {
194  goto cleanup;
195  }
196 
197  BytesWritten = (*FdoDeviceExtension->BusInterface->SetBusData)(
198  FdoDeviceExtension->BusInterface->Context,
201  ConfigDataOffset,
202  BufferLength);
203  if (BytesWritten == BufferLength)
205  else
207 
208 cleanup:
210  return Status;
211 }
NTSTATUS NTAPI PciIdeXSetBusData(IN PVOID DeviceExtension, IN PVOID Buffer, IN PVOID DataMask, IN ULONG ConfigDataOffset, IN ULONG BufferLength)
Definition: miniport.c:161
#define IN
Definition: typedefs.h:38
NTSTATUS(* PCONTROLLER_PROPERTIES)(IN PVOID DeviceExtension, IN PIDE_CONTROLLER_PROPERTIES ControllerProperties)
Definition: ide.h:377
_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
NTSTATUS NTAPI IoAllocateDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress, IN ULONG DriverObjectExtensionSize, OUT PVOID *DriverObjectExtension)
Definition: driver.c:1755
#define IRP_MN_QUERY_POWER
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
_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
_In_ ULONG BufferLength
Definition: usbdlib.h:225
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2173
DRIVER_ADD_DEVICE PciIdeXAddDevice
Definition: pciidex.h:43
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
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
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PGET_SET_DEVICE_DATA GetBusData
Definition: iotypes.h:883
#define PCI_WHICHSPACE_CONFIG
Definition: iotypes.h:3287
#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
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
DRIVER_DISPATCH(nfs41_FsdDispatch)
PGET_SET_DEVICE_DATA SetBusData
Definition: iotypes.h:882
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI PciIdeXFdoPnpDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:402
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2111
NTSTATUS NTAPI PciIdeXInitialize(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath, IN PCONTROLLER_PROPERTIES HwGetControllerProperties, IN ULONG ExtensionSize)
Definition: miniport.c:94
NTSTATUS NTAPI PciIdeXPdoPnpDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.c:359
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:626
static PVOID CurrentBuffer
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define DPRINT1
Definition: precomp.h:8
#define IRP_MJ_CLEANUP
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2180
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
char * cleanup(char *str)
Definition: wpickclick.c:99
static DRIVER_DISPATCH PciIdeXForwardOrIgnore
Definition: miniport.c:14
return STATUS_SUCCESS
Definition: btrfs.c:2725
_Dispatch_type_(IRP_MJ_POWER)
Definition: miniport.c:45
_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:130
#define ExFreePool(addr)
Definition: env_spec_w32.h:352