ReactOS  0.4.15-dev-1636-gf634010
pnp.c File Reference
#include "inport.h"
#include <debug.h>
Include dependency graph for pnp.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI InPortStartDevice (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
NTSTATUS NTAPI InPortRemoveDevice (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
NTSTATUS NTAPI InPortPnp (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file pnp.c.

Function Documentation

◆ InPortPnp()

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

Definition at line 226 of file pnp.c.

229 {
231  PINPORT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
233 
234  PAGED_CODE();
235 
236  DPRINT("%s(%p, %p) %X\n",
238 
239  Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, Irp);
240  if (!NT_SUCCESS(Status))
241  {
242  Irp->IoStatus.Information = 0;
243  Irp->IoStatus.Status = Status;
245 
246  return Status;
247  }
248 
249  switch (IrpSp->MinorFunction)
250  {
251  case IRP_MN_START_DEVICE:
253  break;
254 
257 
259  /* Device cannot work with other resources */
260  Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
262  break;
263 
266  case IRP_MN_STOP_DEVICE:
269  Irp->IoStatus.Status = STATUS_SUCCESS;
271  Status = IoCallDriver(DeviceExtension->Ldo, Irp);
272  break;
273 
274  default:
276  Status = IoCallDriver(DeviceExtension->Ldo, Irp);
277  break;
278  }
279 
280  IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
281 
282  return Status;
283 }
PDEVICE_OBJECT Ldo
Definition: inport.h:44
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define IRP_MN_REMOVE_DEVICE
LONG NTSTATUS
Definition: precomp.h:26
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2760
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_QUERY_REMOVE_DEVICE
#define IoCompleteRequest
Definition: irp.c:1240
NTSTATUS NTAPI InPortRemoveDevice(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pnp.c:183
void DPRINT(...)
Definition: polytest.cpp:61
#define IRP_MN_QUERY_STOP_DEVICE
Status
Definition: gdiplustypes.h:24
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IRP_MN_STOP_DEVICE
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MN_START_DEVICE
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
IO_REMOVE_LOCK RemoveLock
Definition: inport.h:46
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
NTSTATUS NTAPI InPortStartDevice(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pnp.c:27
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_CANCEL_STOP_DEVICE
#define STATUS_SUCCESS
Definition: shellext.h:65
#define __FUNCTION__
Definition: types.h:112
#define IoAcquireRemoveLock(RemoveLock, Tag)
#define PAGED_CODE()

Referenced by DriverEntry().

◆ InPortRemoveDevice()

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

Definition at line 183 of file pnp.c.

186 {
188  BOOLEAN IsStarted;
189  PINPORT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
190 
191  PAGED_CODE();
192 
193  InPortWmiDeRegistration(DeviceExtension);
194 
195  IsStarted = (DeviceExtension->State == dsStarted);
196 
197  DeviceExtension->State = dsRemoved;
198 
199  Irp->IoStatus.Status = STATUS_SUCCESS;
201  Status = IoCallDriver(DeviceExtension->Ldo, Irp);
202 
203  IoReleaseRemoveLockAndWait(&DeviceExtension->RemoveLock, Irp);
204 
205  /* Device is active */
206  if (IsStarted)
207  {
208  KeSynchronizeExecution(DeviceExtension->InterruptObject,
210  DeviceExtension);
211 
212  IoDisconnectInterrupt(DeviceExtension->InterruptObject);
213 
214  /* Flush DPC for ISR */
216  }
217 
218  IoDetachDevice(DeviceExtension->Ldo);
220 
221  return Status;
222 }
Definition: pci.h:35
PDEVICE_OBJECT Ldo
Definition: inport.h:44
INPORT_DEVICE_STATE State
Definition: inport.h:45
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
KSYNCHRONIZE_ROUTINE InPortStopMouse
Definition: inport.h:105
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
unsigned char BOOLEAN
VOID NTAPI IoDisconnectInterrupt(PKINTERRUPT InterruptObject)
Definition: irq.c:140
PKINTERRUPT InterruptObject
Definition: inport.h:52
Status
Definition: gdiplustypes.h:24
IO_REMOVE_LOCK RemoveLock
Definition: inport.h:46
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
BOOLEAN NTAPI KeSynchronizeExecution(IN OUT PKINTERRUPT Interrupt, IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine, IN PVOID SynchronizeContext OPTIONAL)
Definition: interrupt.c:142
#define IoReleaseRemoveLockAndWait(_RemoveLock, _Tag)
Definition: iofuncs.h:2770
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI KeFlushQueuedDpcs(VOID)
Definition: dpc.c:918
NTSTATUS NTAPI InPortWmiDeRegistration(_Inout_ PINPORT_DEVICE_EXTENSION DeviceExtension)
Definition: wmi.c:145
#define PAGED_CODE()

Referenced by InPortPnp().

◆ InPortStartDevice()

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

Definition at line 27 of file pnp.c.

30 {
33  PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor, DescriptorTranslated;
34  ULONG i;
35  ULONG RawVector;
36  BOOLEAN FoundBasePort = FALSE, FoundIrq = FALSE;
37  PINPORT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
39 
40  PAGED_CODE();
41 
42  ASSERT(DeviceExtension->State == dsStopped);
43 
44  if (!IoForwardIrpSynchronously(DeviceExtension->Ldo, Irp))
45  {
47  goto Complete;
48  }
49  Status = Irp->IoStatus.Status;
50  if (!NT_SUCCESS(Status))
51  {
52  DPRINT1("LDO failed to start 0x%X\n", Status);
53  goto Complete;
54  }
55 
56  AllocatedResources = IrpSp->Parameters.StartDevice.AllocatedResources;
57  AllocatedResourcesTranslated = IrpSp->Parameters.StartDevice.AllocatedResourcesTranslated;
59  {
60  DPRINT1("No allocated resources\n");
62  goto Complete;
63  }
64 
65  if (AllocatedResources->Count != 1)
66  DPRINT1("Expected FullList count is 1, got %d\n", AllocatedResources->Count);
67 
68  for (i = 0; i < AllocatedResources->List[0].PartialResourceList.Count; i++)
69  {
70  Descriptor = &AllocatedResources->List[0].PartialResourceList.PartialDescriptors[i];
71  DescriptorTranslated = &AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[i];
72 
73  switch (Descriptor->Type)
74  {
75  case CmResourceTypePort:
76  {
77  DPRINT("[%p:%X:%X] I/O ports at [%p-%p]\n",
78  Descriptor,
79  Descriptor->ShareDisposition,
80  Descriptor->Flags,
81  Descriptor->u.Port.Start.LowPart,
82  Descriptor->u.Port.Start.LowPart + (Descriptor->u.Port.Length - 1));
83 
84  if (!FoundBasePort)
85  {
86  DeviceExtension->IoBase = ULongToPtr(Descriptor->u.Port.Start.u.LowPart);
87 
88  FoundBasePort = TRUE;
89  }
90 
91  break;
92  }
93 
95  {
96  DPRINT("[%p:%X:%X] INT Vec %d Lev %d Aff %IX\n",
97  Descriptor,
98  Descriptor->ShareDisposition,
99  Descriptor->Flags,
100  Descriptor->u.Interrupt.Vector,
101  Descriptor->u.Interrupt.Level,
102  Descriptor->u.Interrupt.Affinity);
103 
104  if (!FoundIrq)
105  {
106  DeviceExtension->InterruptVector = DescriptorTranslated->u.Interrupt.Vector;
107  DeviceExtension->InterruptLevel = (KIRQL)DescriptorTranslated->u.Interrupt.Level;
108  if (DescriptorTranslated->Flags & CM_RESOURCE_INTERRUPT_LATCHED)
109  DeviceExtension->InterruptMode = Latched;
110  else
111  DeviceExtension->InterruptMode = LevelSensitive;
112  DeviceExtension->InterruptShared = (DescriptorTranslated->ShareDisposition == CmResourceShareShared);
113  DeviceExtension->InterruptAffinity = DescriptorTranslated->u.Interrupt.Affinity;
114  RawVector = Descriptor->u.Interrupt.Vector;
115 
116  FoundIrq = TRUE;
117  }
118 
119  break;
120  }
121 
122  default:
123  DPRINT("[%p:%X:%X] Unrecognized resource type %X\n",
124  Descriptor,
125  Descriptor->ShareDisposition,
126  Descriptor->Flags,
127  Descriptor->Type);
128  break;
129  }
130  }
131 
132  if (!FoundBasePort || !FoundIrq)
133  {
134  DPRINT1("The device resources were not found\n");
136  goto Complete;
137  }
138 
139  DPRINT("I/O base at %p\n", DeviceExtension->IoBase);
140  DPRINT("IRQ %d\n", RawVector);
141 
142  Status = InPortWmiRegistration(DeviceExtension);
143  if (!NT_SUCCESS(Status))
144  {
145  DPRINT1("WMI registration failed 0x%X\n", Status);
146  goto Complete;
147  }
148 
149  InPortInitializeMouse(DeviceExtension);
150 
151  Status = IoConnectInterrupt(&DeviceExtension->InterruptObject,
152  InPortIsr,
153  DeviceExtension,
154  NULL,
155  DeviceExtension->InterruptVector,
156  DeviceExtension->InterruptLevel,
157  DeviceExtension->InterruptLevel,
158  DeviceExtension->InterruptMode,
159  DeviceExtension->InterruptShared,
160  DeviceExtension->InterruptAffinity,
161  FALSE);
162  if (!NT_SUCCESS(Status))
163  {
164  DPRINT1("Could not connect to interrupt %d\n", DeviceExtension->InterruptVector);
165  goto Complete;
166  }
167 
168  KeSynchronizeExecution(DeviceExtension->InterruptObject,
170  DeviceExtension);
171 
172  DeviceExtension->State = dsStarted;
173 
174 Complete:
175  Irp->IoStatus.Status = Status;
177 
178  return Status;
179 }
PDEVICE_OBJECT Ldo
Definition: inport.h:44
KSYNCHRONIZE_ROUTINE InPortStartMouse
Definition: inport.h:103
INPORT_DEVICE_STATE State
Definition: inport.h:45
#define ULongToPtr(ul)
Definition: basetsd.h:92
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:339
NTSTATUS NTAPI InPortWmiRegistration(_Inout_ PINPORT_DEVICE_EXTENSION DeviceExtension)
Definition: wmi.c:124
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385::@388 Interrupt
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResources
Definition: ndis.h:4640
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
LONG NTSTATUS
Definition: precomp.h:26
KSERVICE_ROUTINE InPortIsr
Definition: inport.h:99
KINTERRUPT_MODE InterruptMode
Definition: inport.h:55
#define CmResourceTypePort
Definition: hwresource.cpp:123
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@385 u
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
pRequest Complete(RequestStatus)
NTSTATUS NTAPI IoConnectInterrupt(OUT PKINTERRUPT *InterruptObject, IN PKSERVICE_ROUTINE ServiceRoutine, IN PVOID ServiceContext, IN PKSPIN_LOCK SpinLock, IN ULONG Vector, IN KIRQL Irql, IN KIRQL SynchronizeIrql, IN KINTERRUPT_MODE InterruptMode, IN BOOLEAN ShareVector, IN KAFFINITY ProcessorEnableMask, IN BOOLEAN FloatingSave)
Definition: irq.c:22
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResourcesTranslated
Definition: ndis.h:4640
KAFFINITY InterruptAffinity
Definition: inport.h:57
unsigned char BOOLEAN
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI InPortInitializeMouse(_In_ PINPORT_DEVICE_EXTENSION DeviceExtension)
Definition: hardware.c:343
PKINTERRUPT InterruptObject
Definition: inport.h:52
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
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_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define NULL
Definition: types.h:112
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
#define DPRINT1
Definition: precomp.h:8
#define CM_RESOURCE_INTERRUPT_LATCHED
Definition: cmtypes.h:144
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:598
BOOLEAN NTAPI KeSynchronizeExecution(IN OUT PKINTERRUPT Interrupt, IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine, IN PVOID SynchronizeContext OPTIONAL)
Definition: interrupt.c:142
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3124
#define STATUS_DEVICE_CONFIGURATION_ERROR
Definition: ntstatus.h:619
BOOLEAN InterruptShared
Definition: inport.h:56
#define PAGED_CODE()

Referenced by InPortPnp().