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.
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 if (DriverExtension
->InitializationData
.HwResetHw
!= NULL
)
54 if (DriverExtension
->InitializationData
.HwResetHw(
55 &ResetDisplayParametersDeviceExtension
->MiniPortDeviceExtension
,
58 ResetDisplayParametersDeviceExtension
= NULL
;
63 ResetDisplayParametersDeviceExtension
= NULL
;
68 IntVideoPortAddDevice(
69 IN PDRIVER_OBJECT DriverObject
,
70 IN PDEVICE_OBJECT PhysicalDeviceObject
)
72 PVIDEO_PORT_DRIVER_EXTENSION DriverExtension
;
75 * Get the initialization data we saved in VideoPortInitialize.
78 DriverExtension
= IoGetDriverObjectExtension(DriverObject
, DriverObject
);
81 * Use generic routine to find the adapter and create device object.
84 return IntVideoPortFindAdapter(
87 PhysicalDeviceObject
);
91 * IntVideoPortDispatchOpen
93 * Answer requests for Open calls.
100 IntVideoPortDispatchOpen(
101 IN PDEVICE_OBJECT DeviceObject
,
104 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
105 PVIDEO_PORT_DRIVER_EXTENSION DriverExtension
;
107 DPRINT("IntVideoPortDispatchOpen\n");
109 if (CsrssInitialized
== FALSE
)
112 * We know the first open call will be from the CSRSS process
113 * to let us know its handle.
116 DPRINT("Referencing CSRSS\n");
117 Csrss
= PsGetCurrentProcess();
118 DPRINT("Csrss %p\n", Csrss
);
120 CsrssInitialized
= TRUE
;
122 Irp
->IoStatus
.Information
= FILE_OPENED
;
123 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
125 return STATUS_SUCCESS
;
128 DeviceExtension
= (PVIDEO_PORT_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
129 DriverExtension
= DeviceExtension
->DriverExtension
;
131 if (DriverExtension
->InitializationData
.HwInitialize(&DeviceExtension
->MiniPortDeviceExtension
))
133 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
135 InterlockedIncrement((PLONG
)&DeviceExtension
->DeviceOpened
);
138 * Storing the device extension pointer in a static variable is an
139 * ugly hack. Unfortunately, we need it in VideoPortResetDisplayParameters
140 * and HalAcquireDisplayOwnership doesn't allow us to pass a userdata
141 * parameter. On the bright side, the DISPLAY device is opened
142 * exclusively, so there can be only one device extension active at
146 ResetDisplayParametersDeviceExtension
= DeviceExtension
;
147 HalAcquireDisplayOwnership(IntVideoPortResetDisplayParameters
);
151 Irp
->IoStatus
.Status
= STATUS_UNSUCCESSFUL
;
154 Irp
->IoStatus
.Information
= FILE_OPENED
;
155 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
157 return STATUS_SUCCESS
;
161 * IntVideoPortDispatchClose
163 * Answer requests for Close calls.
170 IntVideoPortDispatchClose(
171 IN PDEVICE_OBJECT DeviceObject
,
174 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
176 DPRINT("IntVideoPortDispatchClose\n");
178 DeviceExtension
= (PVIDEO_PORT_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
179 if (DeviceExtension
->DeviceOpened
>= 1 &&
180 InterlockedDecrement((PLONG
)&DeviceExtension
->DeviceOpened
) == 0)
182 ResetDisplayParametersDeviceExtension
= DeviceExtension
;
183 HalReleaseDisplayOwnership();
186 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
187 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
189 return STATUS_SUCCESS
;
193 * IntVideoPortDispatchDeviceControl
195 * Answer requests for device control calls.
202 IntVideoPortDispatchDeviceControl(
203 IN PDEVICE_OBJECT DeviceObject
,
206 PIO_STACK_LOCATION IrpStack
;
207 PVIDEO_PORT_DRIVER_EXTENSION DriverExtension
;
208 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
209 PVIDEO_REQUEST_PACKET vrp
;
212 DPRINT("IntVideoPortDispatchDeviceControl\n");
214 IrpStack
= IoGetCurrentIrpStackLocation(Irp
);
215 DeviceExtension
= DeviceObject
->DeviceExtension
;
216 DriverExtension
= DeviceExtension
->DriverExtension
;
218 /* Translate the IRP to a VRP */
219 vrp
= ExAllocatePool(NonPagedPool
, sizeof(VIDEO_REQUEST_PACKET
));
222 return STATUS_NO_MEMORY
;
225 vrp
->StatusBlock
= (PSTATUS_BLOCK
)&(Irp
->IoStatus
);
226 vrp
->IoControlCode
= IrpStack
->Parameters
.DeviceIoControl
.IoControlCode
;
228 DPRINT("- IoControlCode: %x\n", vrp
->IoControlCode
);
230 /* We're assuming METHOD_BUFFERED */
231 vrp
->InputBuffer
= Irp
->AssociatedIrp
.SystemBuffer
;
232 vrp
->InputBufferLength
= IrpStack
->Parameters
.DeviceIoControl
.InputBufferLength
;
233 vrp
->OutputBuffer
= Irp
->AssociatedIrp
.SystemBuffer
;
234 vrp
->OutputBufferLength
= IrpStack
->Parameters
.DeviceIoControl
.OutputBufferLength
;
236 /* Call the Miniport Driver with the VRP */
237 DriverExtension
->InitializationData
.HwStartIO(
238 &DeviceExtension
->MiniPortDeviceExtension
,
244 DPRINT("- Returned status: %x\n", Irp
->IoStatus
.Status
);
246 if (Irp
->IoStatus
.Status
!= STATUS_SUCCESS
)
248 /* Map from win32 error codes to NT status values. */
249 switch (Irp
->IoStatus
.Status
)
251 case ERROR_NOT_ENOUGH_MEMORY
: Irp
->IoStatus
.Status
= STATUS_INSUFFICIENT_RESOURCES
; break;
252 case ERROR_MORE_DATA
: Irp
->IoStatus
.Status
= STATUS_BUFFER_OVERFLOW
; break;
253 case ERROR_INVALID_FUNCTION
: Irp
->IoStatus
.Status
= STATUS_NOT_IMPLEMENTED
; break;
254 case ERROR_INVALID_PARAMETER
: Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
; break;
255 case ERROR_INSUFFICIENT_BUFFER
: Irp
->IoStatus
.Status
= STATUS_BUFFER_TOO_SMALL
; break;
256 case ERROR_DEV_NOT_EXIST
: Irp
->IoStatus
.Status
= STATUS_DEVICE_DOES_NOT_EXIST
; break;
257 case ERROR_IO_PENDING
: Irp
->IoStatus
.Status
= STATUS_PENDING
; break;
261 Status
= Irp
->IoStatus
.Status
;
262 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
268 IntVideoPortDispatchPnp(
269 IN PDEVICE_OBJECT DeviceObject
,
272 PIO_STACK_LOCATION IrpSp
;
274 IrpSp
= IoGetCurrentIrpStackLocation(Irp
);
276 switch (IrpSp
->MinorFunction
)
278 case IRP_MN_START_DEVICE
:
280 case IRP_MN_REMOVE_DEVICE
:
281 case IRP_MN_QUERY_REMOVE_DEVICE
:
282 case IRP_MN_CANCEL_REMOVE_DEVICE
:
283 case IRP_MN_SURPRISE_REMOVAL
:
285 case IRP_MN_STOP_DEVICE
:
286 case IRP_MN_QUERY_STOP_DEVICE
:
287 case IRP_MN_CANCEL_STOP_DEVICE
:
288 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
289 Irp
->IoStatus
.Information
= 0;
290 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
292 return STATUS_SUCCESS
;
295 return STATUS_NOT_IMPLEMENTED
;
299 IntVideoPortDispatchCleanup(
300 IN PDEVICE_OBJECT DeviceObject
,
303 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
305 DeviceExtension
= DeviceObject
->DeviceExtension
;
306 RtlFreeUnicodeString(&DeviceExtension
->RegistryPath
);
308 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
309 Irp
->IoStatus
.Information
= 0;
310 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
312 return STATUS_SUCCESS
;
316 IntVideoPortDispatchPower(
317 IN PDEVICE_OBJECT DeviceObject
,
320 return STATUS_NOT_IMPLEMENTED
;
324 IntVideoPortUnload(PDRIVER_OBJECT DriverObject
)