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 /* GLOBAL VARIABLES ***********************************************************/
28 ULONG CsrssInitialized
= FALSE
;
29 PKPROCESS Csrss
= NULL
;
31 /* PRIVATE FUNCTIONS **********************************************************/
35 IN PDRIVER_OBJECT DriverObject
,
36 IN PUNICODE_STRING RegistryPath
)
38 return STATUS_SUCCESS
;
42 IntVideoPortImageDirectoryEntryToData(
46 PIMAGE_NT_HEADERS NtHeader
;
49 NtHeader
= RtlImageNtHeader(BaseAddress
);
53 if (Directory
>= NtHeader
->OptionalHeader
.NumberOfRvaAndSizes
)
56 Va
= NtHeader
->OptionalHeader
.DataDirectory
[Directory
].VirtualAddress
;
60 return (PVOID
)((ULONG_PTR
)BaseAddress
+ Va
);
64 IntVideoPortGetProcAddress(
65 IN PVOID HwDeviceExtension
,
66 IN PUCHAR FunctionName
)
68 SYSTEM_GDI_DRIVER_INFORMATION GdiDriverInfo
;
70 PIMAGE_EXPORT_DIRECTORY ExportDir
;
77 DPRINT("VideoPortGetProcAddress(%s)\n", FunctionName
);
79 RtlInitUnicodeString(&GdiDriverInfo
.DriverName
, L
"videoprt");
80 Status
= ZwSetSystemInformation(
81 SystemLoadGdiDriverInformation
,
83 sizeof(SYSTEM_GDI_DRIVER_INFORMATION
));
84 if (!NT_SUCCESS(Status
))
86 DPRINT("Couldn't get our own module handle?\n");
90 BaseAddress
= GdiDriverInfo
.ImageAddress
;
92 /* Get the pointer to the export directory */
93 ExportDir
= (PIMAGE_EXPORT_DIRECTORY
)IntVideoPortImageDirectoryEntryToData(
95 IMAGE_DIRECTORY_ENTRY_EXPORT
);
99 ((ULONG_PTR
)BaseAddress
+ (ULONG_PTR
)ExportDir
->AddressOfFunctions
);
100 OrdinalPtr
= (PUSHORT
)
101 ((ULONG_PTR
)BaseAddress
+ (ULONG_PTR
)ExportDir
->AddressOfNameOrdinals
);
103 ((ULONG_PTR
)BaseAddress
+ (ULONG_PTR
)ExportDir
->AddressOfNames
);
104 for (i
= 0; i
< ExportDir
->NumberOfNames
; i
++, NamePtr
++, OrdinalPtr
++)
106 if (!_strnicmp((PCHAR
)FunctionName
, (PCHAR
)((ULONG_PTR
)BaseAddress
+ *NamePtr
),
107 strlen((PCHAR
)FunctionName
)))
109 return (PVOID
)((ULONG_PTR
)BaseAddress
+
110 (ULONG_PTR
)AddressPtr
[*OrdinalPtr
]);
114 DPRINT("VideoPortGetProcAddress: Can't resolve symbol %s\n", FunctionName
);
120 IntVideoPortDeferredRoutine(
122 IN PVOID DeferredContext
,
123 IN PVOID SystemArgument1
,
124 IN PVOID SystemArgument2
)
126 PVOID HwDeviceExtension
=
127 &((PVIDEO_PORT_DEVICE_EXTENSION
)DeferredContext
)->MiniPortDeviceExtension
;
128 ((PMINIPORT_DPC_ROUTINE
)SystemArgument1
)(HwDeviceExtension
, SystemArgument2
);
132 IntVideoPortAllocateDeviceNumber(VOID
)
136 WCHAR SymlinkBuffer
[20];
137 UNICODE_STRING SymlinkName
;
139 for (DeviceNumber
= 0;;)
141 OBJECT_ATTRIBUTES Obj
;
144 swprintf(SymlinkBuffer
, L
"\\??\\DISPLAY%lu", DeviceNumber
+ 1);
145 RtlInitUnicodeString(&SymlinkName
, SymlinkBuffer
);
146 InitializeObjectAttributes(&Obj
, &SymlinkName
, 0, NULL
, NULL
);
147 Status
= ZwOpenSymbolicLinkObject(&ObjHandle
, GENERIC_READ
, &Obj
);
148 if (NT_SUCCESS(Status
))
154 else if (Status
== STATUS_OBJECT_NAME_NOT_FOUND
)
158 DPRINT1("ZwOpenSymbolicLinkObject() returned unexpected status: 0x%08lx\n", Status
);
167 IntVideoPortCreateAdapterDeviceObject(
168 IN PDRIVER_OBJECT DriverObject
,
169 IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension
,
170 IN PDEVICE_OBJECT PhysicalDeviceObject
,
171 OUT PDEVICE_OBJECT
*DeviceObject OPTIONAL
)
173 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
177 WCHAR DeviceBuffer
[20];
178 UNICODE_STRING DeviceName
;
179 PDEVICE_OBJECT DeviceObject_
;
181 if (DeviceObject
== NULL
)
182 DeviceObject
= &DeviceObject_
;
185 * Find the first free device number that can be used for video device
186 * object names and symlinks.
189 DeviceNumber
= IntVideoPortAllocateDeviceNumber();
190 if (DeviceNumber
== 0xFFFFFFFF)
192 DPRINT("Can't find free device number\n");
193 return STATUS_UNSUCCESSFUL
;
197 * Create the device object.
200 /* Create a unicode device name. */
201 swprintf(DeviceBuffer
, L
"\\Device\\Video%lu", DeviceNumber
);
202 RtlInitUnicodeString(&DeviceName
, DeviceBuffer
);
204 /* Create the device object. */
205 Status
= IoCreateDevice(
207 sizeof(VIDEO_PORT_DEVICE_EXTENSION
) +
208 DriverExtension
->InitializationData
.HwDeviceExtensionSize
,
215 if (!NT_SUCCESS(Status
))
217 DPRINT("IoCreateDevice call failed with status 0x%08x\n", Status
);
222 * Set the buffering strategy here. If you change this, remember
223 * to change VidDispatchDeviceControl too.
226 (*DeviceObject
)->Flags
|= DO_BUFFERED_IO
;
229 * Initialize device extension.
232 DeviceExtension
= (PVIDEO_PORT_DEVICE_EXTENSION
)((*DeviceObject
)->DeviceExtension
);
233 DeviceExtension
->DeviceNumber
= DeviceNumber
;
234 DeviceExtension
->DriverObject
= DriverObject
;
235 DeviceExtension
->PhysicalDeviceObject
= PhysicalDeviceObject
;
236 DeviceExtension
->FunctionalDeviceObject
= *DeviceObject
;
237 DeviceExtension
->DriverExtension
= DriverExtension
;
239 DeviceExtension
->RegistryPath
.Length
=
240 DeviceExtension
->RegistryPath
.MaximumLength
=
241 DriverExtension
->RegistryPath
.Length
+ (9 * sizeof(WCHAR
));
242 DeviceExtension
->RegistryPath
.Length
-= sizeof(WCHAR
);
243 DeviceExtension
->RegistryPath
.Buffer
= ExAllocatePoolWithTag(
245 DeviceExtension
->RegistryPath
.MaximumLength
,
247 swprintf(DeviceExtension
->RegistryPath
.Buffer
, L
"%s\\Device0",
248 DriverExtension
->RegistryPath
.Buffer
);
250 if (PhysicalDeviceObject
!= NULL
)
252 /* Get bus number from the upper level bus driver. */
253 Size
= sizeof(ULONG
);
254 Status
= IoGetDeviceProperty(
255 PhysicalDeviceObject
,
256 DevicePropertyBusNumber
,
258 &DeviceExtension
->SystemIoBusNumber
,
260 if (!NT_SUCCESS(Status
))
262 DPRINT("Couldn't get an information from bus driver. We will try to\n"
263 "use legacy detection method, but even that doesn't mean that\n"
265 DeviceExtension
->PhysicalDeviceObject
= NULL
;
269 DeviceExtension
->AdapterInterfaceType
=
270 DriverExtension
->InitializationData
.AdapterInterfaceType
;
272 if (PhysicalDeviceObject
!= NULL
)
274 /* Get bus type from the upper level bus driver. */
275 Size
= sizeof(ULONG
);
277 PhysicalDeviceObject
,
278 DevicePropertyLegacyBusType
,
280 &DeviceExtension
->AdapterInterfaceType
,
283 /* Get bus device address from the upper level bus driver. */
284 Size
= sizeof(ULONG
);
286 PhysicalDeviceObject
,
287 DevicePropertyAddress
,
289 &DeviceExtension
->SystemIoSlotNumber
,
293 InitializeListHead(&DeviceExtension
->AddressMappingListHead
);
295 &DeviceExtension
->DpcObject
,
296 IntVideoPortDeferredRoutine
,
299 KeInitializeMutex(&DeviceExtension
->DeviceLock
, 0);
301 /* Attach the device. */
302 if (PhysicalDeviceObject
!= NULL
)
303 DeviceExtension
->NextDeviceObject
= IoAttachDeviceToDeviceStack(
304 *DeviceObject
, PhysicalDeviceObject
);
306 return STATUS_SUCCESS
;
310 /* FIXME: we have to detach the device object in IntVideoPortFindAdapter if it fails */
312 IntVideoPortFindAdapter(
313 IN PDRIVER_OBJECT DriverObject
,
314 IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension
,
315 IN PDEVICE_OBJECT DeviceObject
)
317 WCHAR DeviceVideoBuffer
[20];
318 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
321 VIDEO_PORT_CONFIG_INFO ConfigInfo
;
322 SYSTEM_BASIC_INFORMATION SystemBasicInfo
;
324 WCHAR DeviceBuffer
[20];
325 UNICODE_STRING DeviceName
;
326 WCHAR SymlinkBuffer
[20];
327 UNICODE_STRING SymlinkName
;
328 BOOL LegacyDetection
= FALSE
;
331 DeviceExtension
= (PVIDEO_PORT_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
332 DeviceNumber
= DeviceExtension
->DeviceNumber
;
335 * Setup a ConfigInfo structure that we will pass to HwFindAdapter.
338 RtlZeroMemory(&ConfigInfo
, sizeof(VIDEO_PORT_CONFIG_INFO
));
339 ConfigInfo
.Length
= sizeof(VIDEO_PORT_CONFIG_INFO
);
340 ConfigInfo
.AdapterInterfaceType
= DeviceExtension
->AdapterInterfaceType
;
341 if (ConfigInfo
.AdapterInterfaceType
== PCIBus
)
342 ConfigInfo
.InterruptMode
= LevelSensitive
;
344 ConfigInfo
.InterruptMode
= Latched
;
345 ConfigInfo
.DriverRegistryPath
= DriverExtension
->RegistryPath
.Buffer
;
346 ConfigInfo
.VideoPortGetProcAddress
= IntVideoPortGetProcAddress
;
347 ConfigInfo
.SystemIoBusNumber
= DeviceExtension
->SystemIoBusNumber
;
348 ConfigInfo
.BusInterruptLevel
= DeviceExtension
->InterruptLevel
;
349 ConfigInfo
.BusInterruptVector
= DeviceExtension
->InterruptVector
;
351 Size
= sizeof(SystemBasicInfo
);
352 Status
= ZwQuerySystemInformation(
353 SystemBasicInformation
,
358 if (NT_SUCCESS(Status
))
360 ConfigInfo
.SystemMemorySize
=
361 SystemBasicInfo
.NumberOfPhysicalPages
*
362 SystemBasicInfo
.PageSize
;
366 * Call miniport HwVidFindAdapter entry point to detect if
367 * particular device is present. There are two possible code
368 * paths. The first one is for Legacy drivers (NT4) and cases
369 * when we don't have information about what bus we're on. The
370 * second case is the standard one for Plug & Play drivers.
372 if (DeviceExtension
->PhysicalDeviceObject
== NULL
)
374 LegacyDetection
= TRUE
;
379 ULONG BusNumber
, MaxBuses
;
381 MaxBuses
= DeviceExtension
->AdapterInterfaceType
== PCIBus
? 8 : 1;
383 for (BusNumber
= 0; BusNumber
< MaxBuses
; BusNumber
++)
385 DeviceExtension
->SystemIoBusNumber
=
386 ConfigInfo
.SystemIoBusNumber
= BusNumber
;
388 RtlZeroMemory(&DeviceExtension
->MiniPortDeviceExtension
,
389 DriverExtension
->InitializationData
.HwDeviceExtensionSize
);
391 /* FIXME: Need to figure out what string to pass as param 3. */
392 Status
= DriverExtension
->InitializationData
.HwFindAdapter(
393 &DeviceExtension
->MiniPortDeviceExtension
,
394 DriverExtension
->HwContext
,
399 if (Status
== ERROR_DEV_NOT_EXIST
)
403 else if (Status
== NO_ERROR
)
409 DPRINT("HwFindAdapter call failed with error 0x%X\n", Status
);
410 RtlFreeUnicodeString(&DeviceExtension
->RegistryPath
);
411 IoDeleteDevice(DeviceObject
);
419 /* FIXME: Need to figure out what string to pass as param 3. */
420 Status
= DriverExtension
->InitializationData
.HwFindAdapter(
421 &DeviceExtension
->MiniPortDeviceExtension
,
422 DriverExtension
->HwContext
,
428 if (Status
!= NO_ERROR
)
430 DPRINT("HwFindAdapter call failed with error 0x%X\n", Status
);
431 RtlFreeUnicodeString(&DeviceExtension
->RegistryPath
);
432 IoDeleteDevice(DeviceObject
);
437 * Now we know the device is present, so let's do all additional tasks
438 * such as creating symlinks or setting up interrupts and timer.
441 /* Create a unicode device name. */
442 swprintf(DeviceBuffer
, L
"\\Device\\Video%lu", DeviceNumber
);
443 RtlInitUnicodeString(&DeviceName
, DeviceBuffer
);
445 /* Create symbolic link "\??\DISPLAYx" */
446 swprintf(SymlinkBuffer
, L
"\\??\\DISPLAY%lu", DeviceNumber
+ 1);
447 RtlInitUnicodeString(&SymlinkName
, SymlinkBuffer
);
448 IoCreateSymbolicLink(&SymlinkName
, &DeviceName
);
450 /* Add entry to DEVICEMAP\VIDEO key in registry. */
451 swprintf(DeviceVideoBuffer
, L
"\\Device\\Video%d", DeviceNumber
);
452 RtlWriteRegistryValue(
453 RTL_REGISTRY_DEVICEMAP
,
457 DeviceExtension
->RegistryPath
.Buffer
,
458 DeviceExtension
->RegistryPath
.MaximumLength
);
460 /* FIXME: Allocate hardware resources for device. */
463 * Allocate interrupt for device.
466 if (!IntVideoPortSetupInterrupt(DeviceObject
, DriverExtension
, &ConfigInfo
))
468 RtlFreeUnicodeString(&DeviceExtension
->RegistryPath
);
469 IoDeleteDevice(DeviceObject
);
470 return STATUS_INSUFFICIENT_RESOURCES
;
474 * Allocate timer for device.
477 if (!IntVideoPortSetupTimer(DeviceObject
, DriverExtension
))
479 if (DeviceExtension
->InterruptObject
!= NULL
)
480 IoDisconnectInterrupt(DeviceExtension
->InterruptObject
);
481 RtlFreeUnicodeString(&DeviceExtension
->RegistryPath
);
482 IoDeleteDevice(DeviceObject
);
483 DPRINT("STATUS_INSUFFICIENT_RESOURCES\n");
484 return STATUS_INSUFFICIENT_RESOURCES
;
488 * Query children of the device.
490 VideoPortEnumerateChildren(&DeviceExtension
->MiniPortDeviceExtension
, NULL
);
492 DPRINT("STATUS_SUCCESS\n");
493 return STATUS_SUCCESS
;
497 IntAttachToCSRSS(PKPROCESS
*CallingProcess
, PKAPC_STATE ApcState
)
499 *CallingProcess
= (PKPROCESS
)PsGetCurrentProcess();
500 if (*CallingProcess
!= Csrss
)
502 KeStackAttachProcess(Csrss
, ApcState
);
507 IntDetachFromCSRSS(PKPROCESS
*CallingProcess
, PKAPC_STATE ApcState
)
509 if (*CallingProcess
!= Csrss
)
511 KeUnstackDetachProcess(ApcState
);
515 /* PUBLIC FUNCTIONS ***********************************************************/
525 IN PVIDEO_HW_INITIALIZATION_DATA HwInitializationData
,
528 PDRIVER_OBJECT DriverObject
= Context1
;
529 PUNICODE_STRING RegistryPath
= Context2
;
531 PVIDEO_PORT_DRIVER_EXTENSION DriverExtension
;
532 BOOL LegacyDetection
= FALSE
;
534 DPRINT("VideoPortInitialize\n");
538 * The driver extension can be already allocated in case that we were
539 * called by legacy driver and failed detecting device. Some miniport
540 * drivers in that case adjust parameters and calls VideoPortInitialize
544 DriverExtension
= IoGetDriverObjectExtension(DriverObject
, DriverObject
);
545 if (DriverExtension
== NULL
)
547 Status
= IoAllocateDriverObjectExtension(
550 sizeof(VIDEO_PORT_DRIVER_EXTENSION
),
551 (PVOID
*)&DriverExtension
);
553 if (!NT_SUCCESS(Status
))
560 * Copy the correct miniport initializtation data to the device extension.
564 &DriverExtension
->InitializationData
,
565 HwInitializationData
,
566 min(sizeof(VIDEO_HW_INITIALIZATION_DATA
),
567 HwInitializationData
->HwInitDataSize
));
568 if (sizeof(VIDEO_HW_INITIALIZATION_DATA
) > HwInitializationData
->HwInitDataSize
)
570 RtlZeroMemory((PVOID
)((ULONG_PTR
)&DriverExtension
->InitializationData
+
571 HwInitializationData
->HwInitDataSize
),
572 sizeof(VIDEO_HW_INITIALIZATION_DATA
) -
573 HwInitializationData
->HwInitDataSize
);
575 DriverExtension
->HwContext
= HwContext
;
577 /* we can't use RtlDuplicateUnicodeString because only ntdll exposes it... */
578 if (RegistryPath
->Length
!= 0)
580 DriverExtension
->RegistryPath
.Length
= 0;
581 DriverExtension
->RegistryPath
.MaximumLength
= RegistryPath
->Length
+ sizeof(UNICODE_NULL
);
582 DriverExtension
->RegistryPath
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
583 DriverExtension
->RegistryPath
.MaximumLength
,
584 TAG('U', 'S', 'T', 'R'));
585 if (DriverExtension
->RegistryPath
.Buffer
== NULL
)
587 RtlInitUnicodeString(&DriverExtension
->RegistryPath
, NULL
);
588 return STATUS_INSUFFICIENT_RESOURCES
;
591 RtlCopyUnicodeString(&DriverExtension
->RegistryPath
, RegistryPath
);
595 RtlInitUnicodeString(&DriverExtension
->RegistryPath
, NULL
);
598 switch (HwInitializationData
->HwInitDataSize
)
601 * NT4 drivers are special case, because we must use legacy method
602 * of detection instead of the Plug & Play one.
605 case SIZE_OF_NT4_VIDEO_HW_INITIALIZATION_DATA
:
606 DPRINT("We were loaded by a Windows NT miniport driver.\n");
607 LegacyDetection
= TRUE
;
610 case SIZE_OF_W2K_VIDEO_HW_INITIALIZATION_DATA
:
611 DPRINT("We were loaded by a Windows 2000 miniport driver.\n");
614 case sizeof(VIDEO_HW_INITIALIZATION_DATA
):
615 DPRINT("We were loaded by a Windows XP or later miniport driver.\n");
619 DPRINT("Invalid HwInitializationData size.\n");
620 return STATUS_UNSUCCESSFUL
;
623 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = IntVideoPortDispatchOpen
;
624 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = IntVideoPortDispatchClose
;
625 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = IntVideoPortDispatchDeviceControl
;
626 DriverObject
->DriverUnload
= IntVideoPortUnload
;
629 * Plug & Play drivers registers the device in AddDevice routine. For
630 * legacy drivers we must do it now.
635 PDEVICE_OBJECT DeviceObject
;
636 Status
= IntVideoPortCreateAdapterDeviceObject(DriverObject
, DriverExtension
,
637 NULL
, &DeviceObject
);
638 DPRINT("IntVideoPortCreateAdapterDeviceObject returned 0x%x\n", Status
);
639 if (!NT_SUCCESS(Status
))
641 Status
= IntVideoPortFindAdapter(DriverObject
, DriverExtension
, DeviceObject
);
642 DPRINT("IntVideoPortFindAdapter returned 0x%x\n", Status
);
647 DriverObject
->DriverExtension
->AddDevice
= IntVideoPortAddDevice
;
648 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = IntVideoPortDispatchPnp
;
649 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = IntVideoPortDispatchPower
;
651 return STATUS_SUCCESS
;
661 IN VIDEO_DEBUG_LEVEL DebugPrintLevel
,
662 IN PCHAR DebugMessage
, ...)
667 va_start(ap
, DebugMessage
);
668 vsprintf(Buffer
, DebugMessage
, ap
);
680 IN PVOID HwDeviceExtension
,
681 IN PVIDEO_REQUEST_PACKET Vrp OPTIONAL
,
682 IN VP_STATUS ErrorCode
,
685 DPRINT1("VideoPortLogError ErrorCode %d (0x%x) UniqueId %lu (0x%lx)\n",
686 ErrorCode
, ErrorCode
, UniqueId
, UniqueId
);
689 DPRINT1("Vrp->IoControlCode %lu (0x%lx)\n", Vrp
->IoControlCode
, Vrp
->IoControlCode
);
698 VideoPortGetCurrentIrql(VOID
)
700 return KeGetCurrentIrql();
703 typedef struct QueryRegistryCallbackContext
705 PVOID HwDeviceExtension
;
707 PMINIPORT_GET_REGISTRY_ROUTINE HwGetRegistryRoutine
;
708 } QUERY_REGISTRY_CALLBACK_CONTEXT
, *PQUERY_REGISTRY_CALLBACK_CONTEXT
;
710 static NTSTATUS STDCALL
711 QueryRegistryCallback(
715 IN ULONG ValueLength
,
717 IN PVOID EntryContext
)
719 PQUERY_REGISTRY_CALLBACK_CONTEXT CallbackContext
= (PQUERY_REGISTRY_CALLBACK_CONTEXT
) Context
;
721 DPRINT("Found registry value for name %S: type %d, length %d\n",
722 ValueName
, ValueType
, ValueLength
);
723 return (*(CallbackContext
->HwGetRegistryRoutine
))(
724 CallbackContext
->HwDeviceExtension
,
725 CallbackContext
->HwContext
,
736 VideoPortGetRegistryParameters(
737 IN PVOID HwDeviceExtension
,
738 IN PWSTR ParameterName
,
739 IN UCHAR IsParameterFileName
,
740 IN PMINIPORT_GET_REGISTRY_ROUTINE GetRegistryRoutine
,
743 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
744 QUERY_REGISTRY_CALLBACK_CONTEXT Context
;
745 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
747 DPRINT("VideoPortGetRegistryParameters ParameterName %S\n", ParameterName
);
749 DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
751 if (IsParameterFileName
)
756 Context
.HwDeviceExtension
= HwDeviceExtension
;
757 Context
.HwContext
= HwContext
;
758 Context
.HwGetRegistryRoutine
= GetRegistryRoutine
;
760 QueryTable
[0].QueryRoutine
= QueryRegistryCallback
;
761 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
;
762 QueryTable
[0].Name
= ParameterName
;
763 QueryTable
[0].EntryContext
= NULL
;
764 QueryTable
[0].DefaultType
= REG_NONE
;
765 QueryTable
[0].DefaultData
= NULL
;
766 QueryTable
[0].DefaultLength
= 0;
768 QueryTable
[1].QueryRoutine
= NULL
;
769 QueryTable
[1].Name
= NULL
;
771 return NT_SUCCESS(RtlQueryRegistryValues(
772 RTL_REGISTRY_ABSOLUTE
,
773 DeviceExtension
->RegistryPath
.Buffer
,
776 NULL
)) ? ERROR_SUCCESS
: ERROR_INVALID_PARAMETER
;
784 VideoPortSetRegistryParameters(
785 IN PVOID HwDeviceExtension
,
788 IN ULONG ValueLength
)
790 DPRINT("VideoPortSetRegistryParameters\n");
791 ASSERT_IRQL(PASSIVE_LEVEL
);
792 return RtlWriteRegistryValue(
793 RTL_REGISTRY_ABSOLUTE
,
794 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
)->RegistryPath
.Buffer
,
806 VideoPortGetVgaStatus(
807 IN PVOID HwDeviceExtension
,
808 OUT PULONG VgaStatus
)
810 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
812 DPRINT("VideoPortGetVgaStatus\n");
814 DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
815 if (KeGetCurrentIrql() == PASSIVE_LEVEL
)
817 if (DeviceExtension
->AdapterInterfaceType
== PCIBus
)
819 /* VgaStatus: 0 == VGA not enabled, 1 == VGA enabled. */
820 /* Assumed for now */
826 return ERROR_INVALID_FUNCTION
;
834 VideoPortGetRomImage(
835 IN PVOID HwDeviceExtension
,
840 static PVOID RomImageBuffer
= NULL
;
841 PKPROCESS CallingProcess
;
844 DPRINT("VideoPortGetRomImage(HwDeviceExtension 0x%X Length 0x%X)\n",
845 HwDeviceExtension
, Length
);
847 /* If the length is zero then free the existing buffer. */
850 if (RomImageBuffer
!= NULL
)
852 ExFreePool(RomImageBuffer
);
853 RomImageBuffer
= NULL
;
860 * The DDK says we shouldn't use the legacy C0000 method but get the
861 * rom base address from the corresponding pci or acpi register but
862 * lets ignore that and use C0000 anyway. We have already mapped the
863 * bios area into memory so we'll copy from there.
867 Length
= min(Length
, 0x10000);
868 if (RomImageBuffer
!= NULL
)
870 ExFreePool(RomImageBuffer
);
873 RomImageBuffer
= ExAllocatePool(PagedPool
, Length
);
874 if (RomImageBuffer
== NULL
)
879 IntAttachToCSRSS(&CallingProcess
, &ApcState
);
880 RtlCopyMemory(RomImageBuffer
, (PUCHAR
)0xC0000, Length
);
881 IntDetachFromCSRSS(&CallingProcess
, &ApcState
);
883 return RomImageBuffer
;
893 IN PVOID HwDeviceExtension
,
900 PUCHAR SearchLocation
;
902 DPRINT("VideoPortScanRom RomBase %p RomLength 0x%x String %s\n", RomBase
, RomLength
, String
);
904 StringLength
= strlen((PCHAR
)String
);
906 SearchLocation
= RomBase
;
907 for (SearchLocation
= RomBase
;
908 !Found
&& SearchLocation
< RomBase
+ RomLength
- StringLength
;
911 Found
= (RtlCompareMemory(SearchLocation
, String
, StringLength
) == StringLength
);
914 DPRINT("Match found at %p\n", SearchLocation
);
926 VideoPortSynchronizeExecution(
927 IN PVOID HwDeviceExtension
,
928 IN VIDEO_SYNCHRONIZE_PRIORITY Priority
,
929 IN PMINIPORT_SYNCHRONIZE_ROUTINE SynchronizeRoutine
,
933 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
939 Ret
= (*SynchronizeRoutine
)(Context
);
942 case VpMediumPriority
:
943 DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
944 if (DeviceExtension
->InterruptObject
== NULL
)
945 Ret
= (*SynchronizeRoutine
)(Context
);
947 Ret
= KeSynchronizeExecution(
948 DeviceExtension
->InterruptObject
,
954 OldIrql
= KeGetCurrentIrql();
955 if (OldIrql
< SYNCH_LEVEL
)
956 OldIrql
= KfRaiseIrql(SYNCH_LEVEL
);
958 Ret
= (*SynchronizeRoutine
)(Context
);
960 if (OldIrql
< SYNCH_LEVEL
)
961 KfLowerIrql(OldIrql
);
976 VideoPortEnumerateChildren(
977 IN PVOID HwDeviceExtension
,
980 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
982 VIDEO_CHILD_ENUM_INFO ChildEnumInfo
;
983 VIDEO_CHILD_TYPE ChildType
;
984 UCHAR ChildDescriptor
[256];
989 DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
990 if (DeviceExtension
->DriverExtension
->InitializationData
.HwGetVideoChildDescriptor
== NULL
)
992 DPRINT("Miniport's HwGetVideoChildDescriptor is NULL!\n");
996 /* Setup the ChildEnumInfo */
997 ChildEnumInfo
.Size
= sizeof (ChildEnumInfo
);
998 ChildEnumInfo
.ChildDescriptorSize
= sizeof (ChildDescriptor
);
999 ChildEnumInfo
.ACPIHwId
= 0;
1000 ChildEnumInfo
.ChildHwDeviceExtension
= NULL
; /* FIXME: must be set to
1001 ChildHwDeviceExtension... */
1003 /* Enumerate the children */
1006 ChildEnumInfo
.ChildIndex
= i
;
1007 RtlZeroMemory(ChildDescriptor
, sizeof(ChildDescriptor
));
1008 Status
= DeviceExtension
->DriverExtension
->InitializationData
.HwGetVideoChildDescriptor(
1015 if (Status
== VIDEO_ENUM_INVALID_DEVICE
)
1017 DPRINT("Child device %d is invalid!\n", ChildEnumInfo
.ChildIndex
);
1020 else if (Status
== VIDEO_ENUM_NO_MORE_DEVICES
)
1022 DPRINT("End of child enumeration! (%d children enumerated)\n", i
- 1);
1025 else if (Status
!= VIDEO_ENUM_MORE_DEVICES
)
1027 DPRINT("HwGetVideoChildDescriptor returned unknown status code 0x%x!\n", Status
);
1032 if (ChildType
== Monitor
)
1035 PUCHAR p
= ChildDescriptor
;
1036 DPRINT("Monitor device enumerated! (ChildId = 0x%x)\n", ChildId
);
1037 for (j
= 0; j
< sizeof (ChildDescriptor
); j
+= 8)
1039 DPRINT("%02x %02x %02x %02x %02x %02x %02x %02x\n",
1040 p
[j
+0], p
[j
+1], p
[j
+2], p
[j
+3],
1041 p
[j
+4], p
[j
+5], p
[j
+6], p
[j
+7]);
1044 else if (ChildType
== Other
)
1046 DPRINT("\"Other\" device enumerated: DeviceId = %S\n", (PWSTR
)ChildDescriptor
);
1050 DPRINT("HwGetVideoChildDescriptor returned unsupported type: %d\n", ChildType
);
1064 VideoPortCreateSecondaryDisplay(
1065 IN PVOID HwDeviceExtension
,
1066 IN OUT PVOID
*SecondaryDeviceExtension
,
1069 DPRINT1("VideoPortCreateSecondaryDisplay: Unimplemented.\n");
1079 IN PVOID HwDeviceExtension
,
1080 IN PMINIPORT_DPC_ROUTINE CallbackRoutine
,
1083 return KeInsertQueueDpc(
1084 &VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
)->DpcObject
,
1085 (PVOID
)CallbackRoutine
,
1094 VideoPortGetAssociatedDeviceExtension(IN PVOID DeviceObject
)
1096 DPRINT1("VideoPortGetAssociatedDeviceExtension: Unimplemented.\n");
1105 VideoPortGetVersion(
1106 IN PVOID HwDeviceExtension
,
1107 IN OUT PVPOSVERSIONINFO VpOsVersionInfo
)
1109 RTL_OSVERSIONINFOEXW Version
;
1111 Version
.dwOSVersionInfoSize
= sizeof(RTL_OSVERSIONINFOEXW
);
1112 if (VpOsVersionInfo
->Size
>= sizeof(VPOSVERSIONINFO
))
1115 if (NT_SUCCESS(RtlGetVersion((PRTL_OSVERSIONINFOW
)&Version
)))
1117 VpOsVersionInfo
->MajorVersion
= Version
.dwMajorVersion
;
1118 VpOsVersionInfo
->MinorVersion
= Version
.dwMinorVersion
;
1119 VpOsVersionInfo
->BuildNumber
= Version
.dwBuildNumber
;
1120 VpOsVersionInfo
->ServicePackMajor
= Version
.wServicePackMajor
;
1121 VpOsVersionInfo
->ServicePackMinor
= Version
.wServicePackMinor
;
1124 return ERROR_INVALID_PARAMETER
;
1126 VpOsVersionInfo
->MajorVersion
= 5;
1127 VpOsVersionInfo
->MinorVersion
= 0;
1128 VpOsVersionInfo
->BuildNumber
= 2195;
1129 VpOsVersionInfo
->ServicePackMajor
= 4;
1130 VpOsVersionInfo
->ServicePackMinor
= 0;
1135 return ERROR_INVALID_PARAMETER
;
1143 VideoPortCheckForDeviceExistence(
1144 IN PVOID HwDeviceExtension
,
1147 IN UCHAR RevisionId
,
1148 IN USHORT SubVendorId
,
1149 IN USHORT SubSystemId
,
1152 DPRINT1("VideoPortCheckForDeviceExistence: Unimplemented.\n");
1161 VideoPortRegisterBugcheckCallback(
1162 IN PVOID HwDeviceExtension
,
1163 IN ULONG BugcheckCode
,
1165 IN ULONG BugcheckDataSize
)
1167 DPRINT1("VideoPortRegisterBugcheckCallback(): Unimplemented.\n");
1176 VideoPortQueryPerformanceCounter(
1177 IN PVOID HwDeviceExtension
,
1178 OUT PLONGLONG PerformanceFrequency OPTIONAL
)
1180 LARGE_INTEGER Result
;
1182 DPRINT("VideoPortQueryPerformanceCounter\n");
1183 Result
= KeQueryPerformanceCounter((PLARGE_INTEGER
)PerformanceFrequency
);
1184 return Result
.QuadPart
;
1192 VideoPortAcquireDeviceLock(
1193 IN PVOID HwDeviceExtension
)
1195 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
1199 DPRINT("VideoPortAcquireDeviceLock\n");
1200 DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
1201 Status
= KeWaitForMutexObject(&DeviceExtension
->DeviceLock
, Executive
,
1202 KernelMode
, FALSE
, NULL
);
1203 ASSERT(Status
== STATUS_SUCCESS
);
1211 VideoPortReleaseDeviceLock(
1212 IN PVOID HwDeviceExtension
)
1214 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
1218 DPRINT("VideoPortReleaseDeviceLock\n");
1219 DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
1220 Status
= KeReleaseMutex(&DeviceExtension
->DeviceLock
, FALSE
);
1221 ASSERT(Status
== 0);
1230 IN PDEVICE_OBJECT DeviceObject
,