xref: /reactos/drivers/parallel/parport/misc.c (revision 8a978a17)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         Parallel Port Function Driver
4  * FILE:            drivers/parallel/parport/misc.c
5  * PURPOSE:         Miscellaneous functions
6  */
7 
8 #include "parport.h"
9 
10 
11 static IO_COMPLETION_ROUTINE ForwardIrpAndWaitCompletion;
12 
13 /* FUNCTIONS ****************************************************************/
14 
15 static
16 NTSTATUS
17 NTAPI
18 ForwardIrpAndWaitCompletion(IN PDEVICE_OBJECT DeviceObject,
19                             IN PIRP Irp,
20                             IN PVOID Context)
21 {
22     if (Irp->PendingReturned)
23         KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
24     return STATUS_MORE_PROCESSING_REQUIRED;
25 }
26 
27 
28 NTSTATUS
29 ForwardIrpAndWait(IN PDEVICE_OBJECT DeviceObject,
30                   IN PIRP Irp)
31 {
32     PDEVICE_OBJECT LowerDevice;
33     KEVENT Event;
34     NTSTATUS Status;
35 
36     LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
37     ASSERT(LowerDevice);
38 
39     KeInitializeEvent(&Event, NotificationEvent, FALSE);
40     IoCopyCurrentIrpStackLocationToNext(Irp);
41 
42     DPRINT("Calling lower device %p\n", LowerDevice);
43     IoSetCompletionRoutine(Irp, ForwardIrpAndWaitCompletion, &Event, TRUE, TRUE, TRUE);
44 
45     Status = IoCallDriver(LowerDevice, Irp);
46     if (Status == STATUS_PENDING)
47     {
48         Status = KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
49         if (NT_SUCCESS(Status))
50             Status = Irp->IoStatus.Status;
51     }
52 
53     return Status;
54 }
55 
56 
57 NTSTATUS
58 NTAPI
59 ForwardIrpAndForget(IN PDEVICE_OBJECT DeviceObject,
60                     IN PIRP Irp)
61 {
62     PDEVICE_OBJECT LowerDevice;
63 
64     if (((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->Common.IsFDO)
65         LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
66     else
67         LowerDevice = ((PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->AttachedFdo;
68     ASSERT(LowerDevice);
69 
70     IoSkipCurrentIrpStackLocation(Irp);
71     return IoCallDriver(LowerDevice, Irp);
72 }
73 
74 
75 PVOID
76 GetUserBuffer(IN PIRP Irp)
77 {
78     ASSERT(Irp);
79 
80     if (Irp->MdlAddress)
81         return Irp->MdlAddress;
82     else
83         return Irp->AssociatedIrp.SystemBuffer;
84 }
85 
86 /* EOF */
87