[BTRFS] Fix booting with runtime checks
[reactos.git] / drivers / parallel / parport / pdo.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: Parallel Port Function Driver
4 * FILE: drivers/parallel/parport/pdo.c
5 * PURPOSE: PDO functions
6 */
7
8 #include "parport.h"
9
10 /* FUNCTIONS ****************************************************************/
11
12 NTSTATUS
13 NTAPI
14 PdoCreate(IN PDEVICE_OBJECT DeviceObject,
15 IN PIRP Irp)
16 {
17 PPDO_DEVICE_EXTENSION DeviceExtension;
18 PIO_STACK_LOCATION Stack;
19 NTSTATUS Status = STATUS_SUCCESS;
20
21 DPRINT("PdoCreate()\n");
22
23 Stack = IoGetCurrentIrpStackLocation(Irp);
24 DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
25
26 if (Stack->Parameters.Create.Options & FILE_DIRECTORY_FILE)
27 {
28 DPRINT1("Not a directory\n");
29 Status = STATUS_NOT_A_DIRECTORY;
30 goto done;
31 }
32
33 DPRINT("Open LPT%lu: successful\n", DeviceExtension->LptPort);
34 DeviceExtension->OpenCount++;
35
36 done:
37 Irp->IoStatus.Status = Status;
38 Irp->IoStatus.Information = 0;
39 IoCompleteRequest(Irp, IO_NO_INCREMENT);
40
41 return Status;
42 }
43
44
45 NTSTATUS
46 NTAPI
47 PdoClose(IN PDEVICE_OBJECT DeviceObject,
48 IN PIRP Irp)
49 {
50 PPDO_DEVICE_EXTENSION pDeviceExtension;
51
52 DPRINT("PdoClose()\n");
53
54 pDeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
55 pDeviceExtension->OpenCount--;
56
57 Irp->IoStatus.Information = 0;
58 Irp->IoStatus.Status = STATUS_SUCCESS;
59 IoCompleteRequest(Irp, IO_NO_INCREMENT);
60
61 return STATUS_SUCCESS;
62 }
63
64
65 NTSTATUS
66 NTAPI
67 PdoCleanup(IN PDEVICE_OBJECT DeviceObject,
68 IN PIRP Irp)
69 {
70 DPRINT("PdoCleanup()\n");
71
72 Irp->IoStatus.Information = 0;
73 Irp->IoStatus.Status = STATUS_SUCCESS;
74 IoCompleteRequest(Irp, IO_NO_INCREMENT);
75 return STATUS_SUCCESS;
76 }
77
78
79 NTSTATUS
80 NTAPI
81 PdoRead(IN PDEVICE_OBJECT DeviceObject,
82 IN PIRP Irp)
83 {
84 DPRINT("PdoRead()\n");
85
86 Irp->IoStatus.Information = 0;
87 Irp->IoStatus.Status = STATUS_SUCCESS;
88 IoCompleteRequest(Irp, IO_NO_INCREMENT);
89 return STATUS_SUCCESS;
90 }
91
92
93 NTSTATUS
94 NTAPI
95 PdoWrite(IN PDEVICE_OBJECT DeviceObject,
96 IN PIRP Irp)
97 {
98 PPDO_DEVICE_EXTENSION PdoDeviceExtension;
99 PFDO_DEVICE_EXTENSION FdoDeviceExtension;
100 PIO_STACK_LOCATION IoStack;
101 PUCHAR Buffer;
102 ULONG i;
103 UCHAR PortStatus;
104 ULONG ulCount;
105
106 DPRINT("PdoWrite()\n");
107
108 PdoDeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
109 FdoDeviceExtension = (PFDO_DEVICE_EXTENSION)PdoDeviceExtension->AttachedFdo->DeviceExtension;
110
111 IoStack = IoGetCurrentIrpStackLocation(Irp);
112
113 Buffer = GetUserBuffer(Irp);
114 DPRINT("Length: %lu\n", IoStack->Parameters.Write.Length);
115 DPRINT("Buffer: %p\n", Buffer);
116
117 for (i = 0; i < IoStack->Parameters.Write.Length; i++)
118 {
119 ulCount = 0;
120
121 do
122 {
123 KeStallExecutionProcessor(10);
124 PortStatus = READ_PORT_UCHAR(UlongToPtr(FdoDeviceExtension->BaseAddress + 1));
125 ulCount++;
126 }
127 while (ulCount < 500000 && !(PortStatus & LP_PBUSY));
128
129 if (ulCount == 500000)
130 {
131 DPRINT("Timed out\n");
132
133 Irp->IoStatus.Information = 0;
134 Irp->IoStatus.Status = STATUS_TIMEOUT;
135 IoCompleteRequest(Irp, IO_NO_INCREMENT);
136
137 return STATUS_TIMEOUT;
138 }
139
140 /* Write character */
141 WRITE_PORT_UCHAR(UlongToPtr(FdoDeviceExtension->BaseAddress), Buffer[i]);
142
143 KeStallExecutionProcessor(10);
144
145 WRITE_PORT_UCHAR(UlongToPtr(FdoDeviceExtension->BaseAddress + 2), (LP_PSELECP | LP_PINITP | LP_PSTROBE));
146
147 KeStallExecutionProcessor(10);
148
149 WRITE_PORT_UCHAR(UlongToPtr(FdoDeviceExtension->BaseAddress + 2), (LP_PSELECP | LP_PINITP));
150 }
151
152 Irp->IoStatus.Information = 0;
153 Irp->IoStatus.Status = STATUS_SUCCESS;
154 IoCompleteRequest(Irp, IO_NO_INCREMENT);
155 return STATUS_SUCCESS;
156 }
157
158
159 NTSTATUS
160 NTAPI
161 PdoPnp(IN PDEVICE_OBJECT DeviceObject,
162 IN PIRP Irp)
163 {
164 NTSTATUS Status;
165 DPRINT("PdoPnp()\n");
166
167 Status = Irp->IoStatus.Status;
168 IoCompleteRequest(Irp, IO_NO_INCREMENT);
169 return Status;
170 }
171
172
173 NTSTATUS
174 NTAPI
175 PdoPower(IN PDEVICE_OBJECT DeviceObject,
176 IN PIRP Irp)
177 {
178 NTSTATUS Status;
179 PIO_STACK_LOCATION IoStack;
180
181 DPRINT("PdoPower()\n");
182
183 IoStack = IoGetCurrentIrpStackLocation(Irp);
184
185 switch (IoStack->MinorFunction)
186 {
187 case IRP_MN_SET_POWER:
188 case IRP_MN_QUERY_POWER:
189 Irp->IoStatus.Status = STATUS_SUCCESS;
190 break;
191 }
192
193 Status = Irp->IoStatus.Status;
194 PoStartNextPowerIrp(Irp);
195 IoCompleteRequest(Irp, IO_NO_INCREMENT);
196 return Status;
197 }
198
199 /* EOF */