- Update to r53061
[reactos.git] / drivers / input / sermouse / misc.c
1 /*
2 * PROJECT: ReactOS Serial mouse driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/input/sermouse/fdo.c
5 * PURPOSE: Misceallenous operations
6 * PROGRAMMERS: Copyright 2005-2006 Hervé Poussineau (hpoussin@reactos.org)
7 */
8
9 #include "sermouse.h"
10
11 static IO_COMPLETION_ROUTINE ForwardIrpAndWaitCompletion;
12
13 static NTSTATUS NTAPI
14 ForwardIrpAndWaitCompletion(
15 IN PDEVICE_OBJECT DeviceObject,
16 IN PIRP Irp,
17 IN PVOID Context)
18 {
19 if (Irp->PendingReturned)
20 KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
21 return STATUS_MORE_PROCESSING_REQUIRED;
22 }
23
24 NTSTATUS
25 ForwardIrpAndWait(
26 IN PDEVICE_OBJECT DeviceObject,
27 IN PIRP Irp)
28 {
29 PDEVICE_OBJECT LowerDevice = ((PSERMOUSE_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
30 KEVENT Event;
31 NTSTATUS Status;
32
33 KeInitializeEvent(&Event, NotificationEvent, FALSE);
34 IoCopyCurrentIrpStackLocationToNext(Irp);
35
36 TRACE_(SERMOUSE, "Calling lower device %p\n", LowerDevice);
37 IoSetCompletionRoutine(Irp, ForwardIrpAndWaitCompletion, &Event, TRUE, TRUE, TRUE);
38
39 Status = IoCallDriver(LowerDevice, Irp);
40 if (Status == STATUS_PENDING)
41 {
42 Status = KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
43 if (NT_SUCCESS(Status))
44 Status = Irp->IoStatus.Status;
45 }
46
47 return Status;
48 }
49
50 NTSTATUS NTAPI
51 ForwardIrpAndForget(
52 IN PDEVICE_OBJECT DeviceObject,
53 IN PIRP Irp)
54 {
55 PDEVICE_OBJECT LowerDevice = ((PSERMOUSE_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
56
57 IoSkipCurrentIrpStackLocation(Irp);
58 return IoCallDriver(LowerDevice, Irp);
59 }