4 * Copyright (C) 2002, 2003, 2004 ReactOS Team
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; see the file COPYING.LIB.
18 * If not, write to the Free Software Foundation,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * $Id: dispatch.c,v 1.3 2004/04/08 09:43:55 navaraf Exp $
26 /* EXTERNAL FUNCTIONS *********************************************************/
28 typedef PVOID PHAL_RESET_DISPLAY_PARAMETERS
;
29 VOID STDCALL
HalAcquireDisplayOwnership(IN PHAL_RESET_DISPLAY_PARAMETERS ResetDisplayParameters
);
30 VOID STDCALL
HalReleaseDisplayOwnership();
32 /* GLOBAL VARIABLES ***********************************************************/
34 PVIDEO_PORT_DEVICE_EXTENSION ResetDisplayParametersDeviceExtension
= NULL
;
36 /* PRIVATE FUNCTIONS **********************************************************/
39 * Reset display to blue screen
43 IntVideoPortResetDisplayParameters(ULONG Columns
, ULONG Rows
)
45 PVIDEO_PORT_DRIVER_EXTENSION DriverExtension
;
47 if (ResetDisplayParametersDeviceExtension
== NULL
)
50 DriverExtension
= ResetDisplayParametersDeviceExtension
->DriverExtension
;
52 ASSERT(DriverExtension
->InitializationData
.HwResetHw
!= NULL
);
54 if (!DriverExtension
->InitializationData
.HwResetHw(
55 &ResetDisplayParametersDeviceExtension
->MiniPortDeviceExtension
,
58 ResetDisplayParametersDeviceExtension
= NULL
;
62 ResetDisplayParametersDeviceExtension
= NULL
;
67 IntVideoPortAddDevice(
68 IN PDRIVER_OBJECT DriverObject
,
69 IN PDEVICE_OBJECT PhysicalDeviceObject
)
71 PVIDEO_PORT_DRIVER_EXTENSION DriverExtension
;
74 * Get the initialization data we saved in VideoPortInitialize.
77 DriverExtension
= IoGetDriverObjectExtension(DriverObject
, DriverObject
);
80 * Use generic routine to find the adapter and create device object.
83 return IntVideoPortFindAdapter(
86 PhysicalDeviceObject
);
90 * IntVideoPortDispatchOpen
92 * Answer requests for Open calls.
99 IntVideoPortDispatchOpen(
100 IN PDEVICE_OBJECT DeviceObject
,
103 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
104 PVIDEO_PORT_DRIVER_EXTENSION DriverExtension
;
106 DPRINT("IntVideoPortDispatchOpen\n");
108 if (CsrssInitialized
== FALSE
)
111 * We know the first open call will be from the CSRSS process
112 * to let us know its handle.
115 DPRINT("Referencing CSRSS\n");
116 Csrss
= PsGetCurrentProcess();
117 DPRINT("Csrss %p\n", Csrss
);
119 CsrssInitialized
= TRUE
;
121 Irp
->IoStatus
.Information
= FILE_OPENED
;
122 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
124 return STATUS_SUCCESS
;
127 DeviceExtension
= (PVIDEO_PORT_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
128 DriverExtension
= DeviceExtension
->DriverExtension
;
130 if (DriverExtension
->InitializationData
.HwInitialize(&DeviceExtension
->MiniPortDeviceExtension
))
132 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
134 InterlockedIncrement(&DeviceExtension
->DeviceOpened
);
137 * Storing the device extension pointer in a static variable is an
138 * ugly hack. Unfortunately, we need it in VideoPortResetDisplayParameters
139 * and HalAcquireDisplayOwnership doesn't allow us to pass a userdata
140 * parameter. On the bright side, the DISPLAY device is opened
141 * exclusively, so there can be only one device extension active at
145 ResetDisplayParametersDeviceExtension
= DeviceExtension
;
146 HalAcquireDisplayOwnership(IntVideoPortResetDisplayParameters
);
150 Irp
->IoStatus
.Status
= STATUS_UNSUCCESSFUL
;
153 Irp
->IoStatus
.Information
= FILE_OPENED
;
154 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
156 return STATUS_SUCCESS
;
160 * IntVideoPortDispatchClose
162 * Answer requests for Close calls.
169 IntVideoPortDispatchClose(
170 IN PDEVICE_OBJECT DeviceObject
,
173 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
175 DPRINT("IntVideoPortDispatchClose\n");
177 DeviceExtension
= (PVIDEO_PORT_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
178 if (DeviceExtension
->DeviceOpened
> 1 &&
179 InterlockedDecrement(&DeviceExtension
->DeviceOpened
) == 0)
181 ResetDisplayParametersDeviceExtension
= DeviceExtension
;
182 HalReleaseDisplayOwnership();
185 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
186 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
188 return STATUS_SUCCESS
;
192 * IntVideoPortDispatchDeviceControl
194 * Answer requests for device control calls.
201 IntVideoPortDispatchDeviceControl(
202 IN PDEVICE_OBJECT DeviceObject
,
205 PIO_STACK_LOCATION IrpStack
;
206 PVIDEO_PORT_DRIVER_EXTENSION DriverExtension
;
207 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
208 PVIDEO_REQUEST_PACKET vrp
;
211 DPRINT("IntVideoPortDispatchDeviceControl\n");
213 IrpStack
= IoGetCurrentIrpStackLocation(Irp
);
214 DeviceExtension
= DeviceObject
->DeviceExtension
;
215 DriverExtension
= DeviceExtension
->DriverExtension
;
217 /* Translate the IRP to a VRP */
218 vrp
= ExAllocatePool(NonPagedPool
, sizeof(VIDEO_REQUEST_PACKET
));
221 return STATUS_NO_MEMORY
;
224 vrp
->StatusBlock
= (PSTATUS_BLOCK
)&(Irp
->IoStatus
);
225 vrp
->IoControlCode
= IrpStack
->Parameters
.DeviceIoControl
.IoControlCode
;
227 DPRINT("- IoControlCode: %x\n", vrp
->IoControlCode
);
229 /* We're assuming METHOD_BUFFERED */
230 vrp
->InputBuffer
= Irp
->AssociatedIrp
.SystemBuffer
;
231 vrp
->InputBufferLength
= IrpStack
->Parameters
.DeviceIoControl
.InputBufferLength
;
232 vrp
->OutputBuffer
= Irp
->AssociatedIrp
.SystemBuffer
;
233 vrp
->OutputBufferLength
= IrpStack
->Parameters
.DeviceIoControl
.OutputBufferLength
;
235 /* Call the Miniport Driver with the VRP */
236 DriverExtension
->InitializationData
.HwStartIO(
237 &DeviceExtension
->MiniPortDeviceExtension
,
243 DPRINT("- Returned status: %x\n", Irp
->IoStatus
.Status
);
245 if (Irp
->IoStatus
.Status
!= STATUS_SUCCESS
)
247 /* Map from win32 error codes to NT status values. */
248 switch (Irp
->IoStatus
.Status
)
250 case ERROR_NOT_ENOUGH_MEMORY
: Irp
->IoStatus
.Status
= STATUS_INSUFFICIENT_RESOURCES
; break;
251 case ERROR_MORE_DATA
: Irp
->IoStatus
.Status
= STATUS_BUFFER_OVERFLOW
; break;
252 case ERROR_INVALID_FUNCTION
: Irp
->IoStatus
.Status
= STATUS_NOT_IMPLEMENTED
; break;
253 case ERROR_INVALID_PARAMETER
: Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
; break;
254 case ERROR_INSUFFICIENT_BUFFER
: Irp
->IoStatus
.Status
= STATUS_BUFFER_TOO_SMALL
; break;
255 case ERROR_DEV_NOT_EXIST
: Irp
->IoStatus
.Status
= STATUS_DEVICE_DOES_NOT_EXIST
; break;
256 case ERROR_IO_PENDING
: Irp
->IoStatus
.Status
= STATUS_PENDING
; break;
260 Status
= Irp
->IoStatus
.Status
;
261 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
267 IntVideoPortDispatchPnp(
268 IN PDEVICE_OBJECT DeviceObject
,
271 PIO_STACK_LOCATION IrpSp
;
273 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
275 switch (IrpSp
->MinorFunction
)
277 case IRP_MN_START_DEVICE
:
279 case IRP_MN_REMOVE_DEVICE
:
280 case IRP_MN_QUERY_REMOVE_DEVICE
:
281 case IRP_MN_CANCEL_REMOVE_DEVICE
:
282 case IRP_MN_SURPRISE_REMOVAL
:
284 case IRP_MN_STOP_DEVICE
:
285 case IRP_MN_QUERY_STOP_DEVICE
:
286 case IRP_MN_CANCEL_STOP_DEVICE
:
287 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
288 Irp
->IoStatus
.Information
= 0;
289 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
291 return STATUS_SUCCESS
;
294 return STATUS_NOT_IMPLEMENTED
;
298 IntVideoPortDispatchCleanup(
299 IN PDEVICE_OBJECT DeviceObject
,
302 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
304 DeviceExtension
= DeviceObject
->DeviceExtension
;
305 RtlFreeUnicodeString(&DeviceExtension
->RegistryPath
);
307 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
308 Irp
->IoStatus
.Information
= 0;
309 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
311 return STATUS_SUCCESS
;
315 IntVideoPortDispatchPower(
316 IN PDEVICE_OBJECT DeviceObject
,
319 return STATUS_NOT_IMPLEMENTED
;
323 IntVideoPortUnload(PDRIVER_OBJECT DriverObject
)