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.
25 #include "internal/ps.h"
27 /* GLOBAL VARIABLES ***********************************************************/
29 ULONG CsrssInitialized
= FALSE
;
30 PEPROCESS Csrss
= NULL
;
32 /* PRIVATE FUNCTIONS **********************************************************/
36 IN PDRIVER_OBJECT DriverObject
,
37 IN PUNICODE_STRING RegistryPath
)
39 return STATUS_SUCCESS
;
43 IntVideoPortImageDirectoryEntryToData(
47 PIMAGE_NT_HEADERS NtHeader
;
50 NtHeader
= RtlImageNtHeader(BaseAddress
);
54 if (Directory
>= NtHeader
->OptionalHeader
.NumberOfRvaAndSizes
)
57 Va
= NtHeader
->OptionalHeader
.DataDirectory
[Directory
].VirtualAddress
;
61 return (PVOID
)(BaseAddress
+ Va
);
65 IntVideoPortGetProcAddress(
66 IN PVOID HwDeviceExtension
,
67 IN PUCHAR FunctionName
)
69 SYSTEM_LOAD_IMAGE GdiDriverInfo
;
71 PIMAGE_EXPORT_DIRECTORY ExportDir
;
78 DPRINT("VideoPortGetProcAddress(%s)\n", FunctionName
);
80 RtlInitUnicodeString(&GdiDriverInfo
.ModuleName
, L
"videoprt");
81 Status
= ZwSetSystemInformation(
84 sizeof(SYSTEM_LOAD_IMAGE
));
85 if (!NT_SUCCESS(Status
))
87 DPRINT("Couldn't get our own module handle?\n");
91 BaseAddress
= GdiDriverInfo
.ModuleBase
;
93 /* Get the pointer to the export directory */
94 ExportDir
= (PIMAGE_EXPORT_DIRECTORY
)IntVideoPortImageDirectoryEntryToData(
96 IMAGE_DIRECTORY_ENTRY_EXPORT
);
100 ((ULONG_PTR
)BaseAddress
+ (ULONG_PTR
)ExportDir
->AddressOfFunctions
);
101 OrdinalPtr
= (PUSHORT
)
102 ((ULONG_PTR
)BaseAddress
+ (ULONG_PTR
)ExportDir
->AddressOfNameOrdinals
);
104 ((ULONG_PTR
)BaseAddress
+ (ULONG_PTR
)ExportDir
->AddressOfNames
);
105 for (i
= 0; i
< ExportDir
->NumberOfNames
; i
++, NamePtr
++, OrdinalPtr
++)
107 if (!_strnicmp((PCHAR
)FunctionName
, (PCHAR
)(BaseAddress
+ *NamePtr
),
108 strlen((PCHAR
)FunctionName
)))
110 return (PVOID
)((ULONG_PTR
)BaseAddress
+
111 (ULONG_PTR
)AddressPtr
[*OrdinalPtr
]);
115 DPRINT("VideoPortGetProcAddress: Can't resolve symbol %s\n", FunctionName
);
121 IntVideoPortDeferredRoutine(
123 IN PVOID DeferredContext
,
124 IN PVOID SystemArgument1
,
125 IN PVOID SystemArgument2
)
127 PVOID HwDeviceExtension
=
128 &((PVIDEO_PORT_DEVICE_EXTENSION
)DeferredContext
)->MiniPortDeviceExtension
;
129 ((PMINIPORT_DPC_ROUTINE
)SystemArgument1
)(HwDeviceExtension
, SystemArgument2
);
133 IntVideoPortAllocateDeviceNumber(VOID
)
137 WCHAR SymlinkBuffer
[20];
138 UNICODE_STRING SymlinkName
;
140 for (DeviceNumber
= 0;;)
142 OBJECT_ATTRIBUTES Obj
;
145 swprintf(SymlinkBuffer
, L
"\\??\\DISPLAY%lu", DeviceNumber
+ 1);
146 RtlInitUnicodeString(&SymlinkName
, SymlinkBuffer
);
147 InitializeObjectAttributes(&Obj
, &SymlinkName
, 0, NULL
, NULL
);
148 Status
= ZwOpenSymbolicLinkObject(&ObjHandle
, GENERIC_READ
, &Obj
);
149 if (NT_SUCCESS(Status
))
155 else if (Status
== STATUS_OBJECT_NAME_NOT_FOUND
)
159 DPRINT1("ZwOpenSymbolicLinkObject() returned unexpected status: 0x%08lx\n", Status
);
168 IntVideoPortCreateAdapterDeviceObject(
169 IN PDRIVER_OBJECT DriverObject
,
170 IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension
,
171 IN PDEVICE_OBJECT PhysicalDeviceObject
,
172 OUT PDEVICE_OBJECT
*DeviceObject OPTIONAL
)
174 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
178 WCHAR DeviceBuffer
[20];
179 UNICODE_STRING DeviceName
;
180 PDEVICE_OBJECT DeviceObject_
;
182 if (DeviceObject
== NULL
)
183 DeviceObject
= &DeviceObject_
;
186 * Find the first free device number that can be used for video device
187 * object names and symlinks.
190 DeviceNumber
= IntVideoPortAllocateDeviceNumber();
191 if (DeviceNumber
== 0xFFFFFFFF)
193 DPRINT("Can't find free device number\n");
194 return STATUS_UNSUCCESSFUL
;
198 * Create the device object.
201 /* Create a unicode device name. */
202 swprintf(DeviceBuffer
, L
"\\Device\\Video%lu", DeviceNumber
);
203 RtlInitUnicodeString(&DeviceName
, DeviceBuffer
);
205 /* Create the device object. */
206 Status
= IoCreateDevice(
208 sizeof(VIDEO_PORT_DEVICE_EXTENSION
) +
209 DriverExtension
->InitializationData
.HwDeviceExtensionSize
,
216 if (!NT_SUCCESS(Status
))
218 DPRINT("IoCreateDevice call failed with status 0x%08x\n", Status
);
223 * Set the buffering strategy here. If you change this, remember
224 * to change VidDispatchDeviceControl too.
227 (*DeviceObject
)->Flags
|= DO_BUFFERED_IO
;
230 * Initialize device extension.
233 DeviceExtension
= (PVIDEO_PORT_DEVICE_EXTENSION
)((*DeviceObject
)->DeviceExtension
);
234 DeviceExtension
->DeviceNumber
= DeviceNumber
;
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
.PhysicalPageSize
;
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(PEPROCESS
*CallingProcess
, PEPROCESS
*PrevAttachedProcess
)
499 *CallingProcess
= PsGetCurrentProcess();
500 if (*CallingProcess
!= Csrss
)
502 if (PsGetCurrentThread()->ThreadsProcess
!= *CallingProcess
)
504 *PrevAttachedProcess
= *CallingProcess
;
509 *PrevAttachedProcess
= NULL
;
511 KeAttachProcess(Csrss
);
516 IntDetachFromCSRSS(PEPROCESS
*CallingProcess
, PEPROCESS
*PrevAttachedProcess
)
518 if (*CallingProcess
!= Csrss
)
521 if (NULL
!= *PrevAttachedProcess
)
523 KeAttachProcess(*PrevAttachedProcess
);
528 /* PUBLIC FUNCTIONS ***********************************************************/
538 IN PVIDEO_HW_INITIALIZATION_DATA HwInitializationData
,
541 PDRIVER_OBJECT DriverObject
= Context1
;
542 PUNICODE_STRING RegistryPath
= Context2
;
544 PVIDEO_PORT_DRIVER_EXTENSION DriverExtension
;
545 BOOL LegacyDetection
= FALSE
;
547 DPRINT("VideoPortInitialize\n");
551 * The driver extension can be already allocated in case that we were
552 * called by legacy driver and failed detecting device. Some miniport
553 * drivers in that case adjust parameters and calls VideoPortInitialize
557 DriverExtension
= IoGetDriverObjectExtension(DriverObject
, DriverObject
);
558 if (DriverExtension
== NULL
)
560 Status
= IoAllocateDriverObjectExtension(
563 sizeof(VIDEO_PORT_DRIVER_EXTENSION
),
564 (PVOID
*)&DriverExtension
);
566 if (!NT_SUCCESS(Status
))
573 * Copy the correct miniport initializtation data to the device extension.
577 &DriverExtension
->InitializationData
,
578 HwInitializationData
,
579 min(sizeof(VIDEO_HW_INITIALIZATION_DATA
),
580 HwInitializationData
->HwInitDataSize
));
581 if (sizeof(VIDEO_HW_INITIALIZATION_DATA
) > HwInitializationData
->HwInitDataSize
)
583 RtlZeroMemory((PVOID
)((ULONG_PTR
)&DriverExtension
->InitializationData
+
584 HwInitializationData
->HwInitDataSize
),
585 sizeof(VIDEO_HW_INITIALIZATION_DATA
) -
586 HwInitializationData
->HwInitDataSize
);
588 DriverExtension
->HwContext
= HwContext
;
590 /* we can't use RtlDuplicateUnicodeString because only ntdll exposes it... */
591 if (RegistryPath
->Length
!= 0)
593 DriverExtension
->RegistryPath
.Length
= 0;
594 DriverExtension
->RegistryPath
.MaximumLength
= RegistryPath
->Length
+ sizeof(UNICODE_NULL
);
595 DriverExtension
->RegistryPath
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
596 DriverExtension
->RegistryPath
.MaximumLength
,
597 TAG('U', 'S', 'T', 'R'));
598 if (DriverExtension
->RegistryPath
.Buffer
== NULL
)
600 RtlInitUnicodeString(&DriverExtension
->RegistryPath
, NULL
);
601 return STATUS_INSUFFICIENT_RESOURCES
;
604 RtlCopyUnicodeString(&DriverExtension
->RegistryPath
, RegistryPath
);
608 RtlInitUnicodeString(&DriverExtension
->RegistryPath
, NULL
);
611 switch (HwInitializationData
->HwInitDataSize
)
614 * NT4 drivers are special case, because we must use legacy method
615 * of detection instead of the Plug & Play one.
618 case SIZE_OF_NT4_VIDEO_HW_INITIALIZATION_DATA
:
619 DPRINT("We were loaded by a Windows NT miniport driver.\n");
620 LegacyDetection
= TRUE
;
623 case SIZE_OF_W2K_VIDEO_HW_INITIALIZATION_DATA
:
624 DPRINT("We were loaded by a Windows 2000 miniport driver.\n");
627 case sizeof(VIDEO_HW_INITIALIZATION_DATA
):
628 DPRINT("We were loaded by a Windows XP or later miniport driver.\n");
632 DPRINT("Invalid HwInitializationData size.\n");
633 return STATUS_UNSUCCESSFUL
;
636 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = IntVideoPortDispatchOpen
;
637 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = IntVideoPortDispatchClose
;
638 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = IntVideoPortDispatchDeviceControl
;
639 DriverObject
->DriverUnload
= IntVideoPortUnload
;
642 * Plug & Play drivers registers the device in AddDevice routine. For
643 * legacy drivers we must do it now.
648 PDEVICE_OBJECT DeviceObject
;
649 Status
= IntVideoPortCreateAdapterDeviceObject(DriverObject
, DriverExtension
,
650 NULL
, &DeviceObject
);
651 DPRINT("IntVideoPortCreateAdapterDeviceObject returned 0x%x\n", Status
);
652 if (!NT_SUCCESS(Status
))
654 Status
= IntVideoPortFindAdapter(DriverObject
, DriverExtension
, DeviceObject
);
655 DPRINT("IntVideoPortFindAdapter returned 0x%x\n", Status
);
660 DriverObject
->DriverExtension
->AddDevice
= IntVideoPortAddDevice
;
661 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = IntVideoPortDispatchPnp
;
662 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = IntVideoPortDispatchPower
;
664 return STATUS_SUCCESS
;
674 IN VIDEO_DEBUG_LEVEL DebugPrintLevel
,
675 IN PCHAR DebugMessage
, ...)
680 va_start(ap
, DebugMessage
);
681 vsprintf(Buffer
, DebugMessage
, ap
);
693 IN PVOID HwDeviceExtension
,
694 IN PVIDEO_REQUEST_PACKET Vrp OPTIONAL
,
695 IN VP_STATUS ErrorCode
,
698 DPRINT1("VideoPortLogError ErrorCode %d (0x%x) UniqueId %lu (0x%lx)\n",
699 ErrorCode
, ErrorCode
, UniqueId
, UniqueId
);
702 DPRINT1("Vrp->IoControlCode %lu (0x%lx)\n", Vrp
->IoControlCode
, Vrp
->IoControlCode
);
711 VideoPortGetCurrentIrql(VOID
)
713 return KeGetCurrentIrql();
716 typedef struct QueryRegistryCallbackContext
718 PVOID HwDeviceExtension
;
720 PMINIPORT_GET_REGISTRY_ROUTINE HwGetRegistryRoutine
;
721 } QUERY_REGISTRY_CALLBACK_CONTEXT
, *PQUERY_REGISTRY_CALLBACK_CONTEXT
;
723 static NTSTATUS STDCALL
724 QueryRegistryCallback(
728 IN ULONG ValueLength
,
730 IN PVOID EntryContext
)
732 PQUERY_REGISTRY_CALLBACK_CONTEXT CallbackContext
= (PQUERY_REGISTRY_CALLBACK_CONTEXT
) Context
;
734 DPRINT("Found registry value for name %S: type %d, length %d\n",
735 ValueName
, ValueType
, ValueLength
);
736 return (*(CallbackContext
->HwGetRegistryRoutine
))(
737 CallbackContext
->HwDeviceExtension
,
738 CallbackContext
->HwContext
,
749 VideoPortGetRegistryParameters(
750 IN PVOID HwDeviceExtension
,
751 IN PWSTR ParameterName
,
752 IN UCHAR IsParameterFileName
,
753 IN PMINIPORT_GET_REGISTRY_ROUTINE GetRegistryRoutine
,
756 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
757 QUERY_REGISTRY_CALLBACK_CONTEXT Context
;
758 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
760 DPRINT("VideoPortGetRegistryParameters ParameterName %S\n", ParameterName
);
762 DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
764 if (IsParameterFileName
)
769 Context
.HwDeviceExtension
= HwDeviceExtension
;
770 Context
.HwContext
= HwContext
;
771 Context
.HwGetRegistryRoutine
= GetRegistryRoutine
;
773 QueryTable
[0].QueryRoutine
= QueryRegistryCallback
;
774 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
;
775 QueryTable
[0].Name
= ParameterName
;
776 QueryTable
[0].EntryContext
= NULL
;
777 QueryTable
[0].DefaultType
= REG_NONE
;
778 QueryTable
[0].DefaultData
= NULL
;
779 QueryTable
[0].DefaultLength
= 0;
781 QueryTable
[1].QueryRoutine
= NULL
;
782 QueryTable
[1].Name
= NULL
;
784 return NT_SUCCESS(RtlQueryRegistryValues(
785 RTL_REGISTRY_ABSOLUTE
,
786 DeviceExtension
->RegistryPath
.Buffer
,
789 NULL
)) ? ERROR_SUCCESS
: ERROR_INVALID_PARAMETER
;
797 VideoPortSetRegistryParameters(
798 IN PVOID HwDeviceExtension
,
801 IN ULONG ValueLength
)
803 DPRINT("VideoPortSetRegistryParameters\n");
804 ASSERT_IRQL(PASSIVE_LEVEL
);
805 return RtlWriteRegistryValue(
806 RTL_REGISTRY_ABSOLUTE
,
807 VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
)->RegistryPath
.Buffer
,
819 VideoPortGetVgaStatus(
820 IN PVOID HwDeviceExtension
,
821 OUT PULONG VgaStatus
)
823 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
825 DPRINT("VideoPortGetVgaStatus\n");
827 DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
828 if (KeGetCurrentIrql() == PASSIVE_LEVEL
)
830 if (DeviceExtension
->AdapterInterfaceType
== PCIBus
)
832 /* VgaStatus: 0 == VGA not enabled, 1 == VGA enabled. */
833 /* Assumed for now */
839 return ERROR_INVALID_FUNCTION
;
847 VideoPortGetRomImage(
848 IN PVOID HwDeviceExtension
,
853 static PVOID RomImageBuffer
= NULL
;
854 PEPROCESS CallingProcess
;
855 PEPROCESS PrevAttachedProcess
;
857 DPRINT("VideoPortGetRomImage(HwDeviceExtension 0x%X Length 0x%X)\n",
858 HwDeviceExtension
, Length
);
860 /* If the length is zero then free the existing buffer. */
863 if (RomImageBuffer
!= NULL
)
865 ExFreePool(RomImageBuffer
);
866 RomImageBuffer
= NULL
;
873 * The DDK says we shouldn't use the legacy C0000 method but get the
874 * rom base address from the corresponding pci or acpi register but
875 * lets ignore that and use C0000 anyway. We have already mapped the
876 * bios area into memory so we'll copy from there.
880 Length
= min(Length
, 0x10000);
881 if (RomImageBuffer
!= NULL
)
883 ExFreePool(RomImageBuffer
);
886 RomImageBuffer
= ExAllocatePool(PagedPool
, Length
);
887 if (RomImageBuffer
== NULL
)
892 IntAttachToCSRSS(&CallingProcess
, &PrevAttachedProcess
);
893 RtlCopyMemory(RomImageBuffer
, (PUCHAR
)0xC0000, Length
);
894 IntDetachFromCSRSS(&CallingProcess
, &PrevAttachedProcess
);
896 return RomImageBuffer
;
906 IN PVOID HwDeviceExtension
,
913 PUCHAR SearchLocation
;
915 DPRINT("VideoPortScanRom RomBase %p RomLength 0x%x String %s\n", RomBase
, RomLength
, String
);
917 StringLength
= strlen((PCHAR
)String
);
919 SearchLocation
= RomBase
;
920 for (SearchLocation
= RomBase
;
921 !Found
&& SearchLocation
< RomBase
+ RomLength
- StringLength
;
924 Found
= (RtlCompareMemory(SearchLocation
, String
, StringLength
) == StringLength
);
927 DPRINT("Match found at %p\n", SearchLocation
);
939 VideoPortSynchronizeExecution(
940 IN PVOID HwDeviceExtension
,
941 IN VIDEO_SYNCHRONIZE_PRIORITY Priority
,
942 IN PMINIPORT_SYNCHRONIZE_ROUTINE SynchronizeRoutine
,
946 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
952 Ret
= (*SynchronizeRoutine
)(Context
);
955 case VpMediumPriority
:
956 DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
957 if (DeviceExtension
->InterruptObject
== NULL
)
958 Ret
= (*SynchronizeRoutine
)(Context
);
960 Ret
= KeSynchronizeExecution(
961 DeviceExtension
->InterruptObject
,
967 OldIrql
= KeGetCurrentIrql();
968 if (OldIrql
< SYNCH_LEVEL
)
969 OldIrql
= KfRaiseIrql(SYNCH_LEVEL
);
971 Ret
= (*SynchronizeRoutine
)(Context
);
973 if (OldIrql
< SYNCH_LEVEL
)
974 KfLowerIrql(OldIrql
);
989 VideoPortEnumerateChildren(
990 IN PVOID HwDeviceExtension
,
993 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
995 VIDEO_CHILD_ENUM_INFO ChildEnumInfo
;
996 VIDEO_CHILD_TYPE ChildType
;
997 UCHAR ChildDescriptor
[256];
1002 DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
1003 if (DeviceExtension
->DriverExtension
->InitializationData
.HwGetVideoChildDescriptor
== NULL
)
1005 DPRINT("Miniport's HwGetVideoChildDescriptor is NULL!\n");
1009 /* Setup the ChildEnumInfo */
1010 ChildEnumInfo
.Size
= sizeof (ChildEnumInfo
);
1011 ChildEnumInfo
.ChildDescriptorSize
= sizeof (ChildDescriptor
);
1012 ChildEnumInfo
.ACPIHwId
= 0;
1013 ChildEnumInfo
.ChildHwDeviceExtension
= NULL
; /* FIXME: must be set to
1014 ChildHwDeviceExtension... */
1016 /* Enumerate the children */
1019 ChildEnumInfo
.ChildIndex
= i
;
1020 RtlZeroMemory(ChildDescriptor
, sizeof(ChildDescriptor
));
1021 Status
= DeviceExtension
->DriverExtension
->InitializationData
.HwGetVideoChildDescriptor(
1028 if (Status
== VIDEO_ENUM_INVALID_DEVICE
)
1030 DPRINT("Child device %d is invalid!\n", ChildEnumInfo
.ChildIndex
);
1033 else if (Status
== VIDEO_ENUM_NO_MORE_DEVICES
)
1035 DPRINT("End of child enumeration! (%d children enumerated)\n", i
- 1);
1038 else if (Status
!= VIDEO_ENUM_MORE_DEVICES
)
1040 DPRINT("HwGetVideoChildDescriptor returned unknown status code 0x%x!\n", Status
);
1045 if (ChildType
== Monitor
)
1048 PUCHAR p
= ChildDescriptor
;
1049 DPRINT("Monitor device enumerated! (ChildId = 0x%x)\n", ChildId
);
1050 for (j
= 0; j
< sizeof (ChildDescriptor
); j
+= 8)
1052 DPRINT("%02x %02x %02x %02x %02x %02x %02x %02x\n",
1053 p
[j
+0], p
[j
+1], p
[j
+2], p
[j
+3],
1054 p
[j
+4], p
[j
+5], p
[j
+6], p
[j
+7]);
1057 else if (ChildType
== Other
)
1059 DPRINT("\"Other\" device enumerated: DeviceId = %S\n", (PWSTR
)ChildDescriptor
);
1063 DPRINT("HwGetVideoChildDescriptor returned unsupported type: %d\n", ChildType
);
1077 VideoPortCreateSecondaryDisplay(
1078 IN PVOID HwDeviceExtension
,
1079 IN OUT PVOID
*SecondaryDeviceExtension
,
1082 DPRINT1("VideoPortCreateSecondaryDisplay: Unimplemented.\n");
1092 IN PVOID HwDeviceExtension
,
1093 IN PMINIPORT_DPC_ROUTINE CallbackRoutine
,
1096 return KeInsertQueueDpc(
1097 &VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
)->DpcObject
,
1098 (PVOID
)CallbackRoutine
,
1107 VideoPortGetAssociatedDeviceExtension(IN PVOID DeviceObject
)
1109 DPRINT1("VideoPortGetAssociatedDeviceExtension: Unimplemented.\n");
1118 VideoPortGetVersion(
1119 IN PVOID HwDeviceExtension
,
1120 IN OUT PVPOSVERSIONINFO VpOsVersionInfo
)
1122 RTL_OSVERSIONINFOEXW Version
;
1124 Version
.dwOSVersionInfoSize
= sizeof(RTL_OSVERSIONINFOEXW
);
1125 if (VpOsVersionInfo
->Size
>= sizeof(VPOSVERSIONINFO
))
1128 if (NT_SUCCESS(RtlGetVersion((PRTL_OSVERSIONINFOW
)&Version
)))
1130 VpOsVersionInfo
->MajorVersion
= Version
.dwMajorVersion
;
1131 VpOsVersionInfo
->MinorVersion
= Version
.dwMinorVersion
;
1132 VpOsVersionInfo
->BuildNumber
= Version
.dwBuildNumber
;
1133 VpOsVersionInfo
->ServicePackMajor
= Version
.wServicePackMajor
;
1134 VpOsVersionInfo
->ServicePackMinor
= Version
.wServicePackMinor
;
1137 return ERROR_INVALID_PARAMETER
;
1139 VpOsVersionInfo
->MajorVersion
= 5;
1140 VpOsVersionInfo
->MinorVersion
= 0;
1141 VpOsVersionInfo
->BuildNumber
= 2195;
1142 VpOsVersionInfo
->ServicePackMajor
= 4;
1143 VpOsVersionInfo
->ServicePackMinor
= 0;
1148 return ERROR_INVALID_PARAMETER
;
1156 VideoPortCheckForDeviceExistence(
1157 IN PVOID HwDeviceExtension
,
1160 IN UCHAR RevisionId
,
1161 IN USHORT SubVendorId
,
1162 IN USHORT SubSystemId
,
1165 DPRINT1("VideoPortCheckForDeviceExistence: Unimplemented.\n");
1174 VideoPortRegisterBugcheckCallback(
1175 IN PVOID HwDeviceExtension
,
1176 IN ULONG BugcheckCode
,
1178 IN ULONG BugcheckDataSize
)
1180 DPRINT1("VideoPortRegisterBugcheckCallback(): Unimplemented.\n");
1189 VideoPortQueryPerformanceCounter(
1190 IN PVOID HwDeviceExtension
,
1191 OUT PLONGLONG PerformanceFrequency OPTIONAL
)
1193 LARGE_INTEGER Result
;
1195 DPRINT("VideoPortQueryPerformanceCounter\n");
1196 Result
= KeQueryPerformanceCounter((PLARGE_INTEGER
)PerformanceFrequency
);
1197 return Result
.QuadPart
;
1205 VideoPortAcquireDeviceLock(
1206 IN PVOID HwDeviceExtension
)
1208 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
1212 DPRINT("VideoPortAcquireDeviceLock\n");
1213 DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
1214 Status
= KeWaitForMutexObject(&DeviceExtension
->DeviceLock
, Executive
,
1215 KernelMode
, FALSE
, NULL
);
1216 ASSERT(Status
== STATUS_SUCCESS
);
1224 VideoPortReleaseDeviceLock(
1225 IN PVOID HwDeviceExtension
)
1227 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
1231 DPRINT("VideoPortReleaseDeviceLock\n");
1232 DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
1233 Status
= KeReleaseMutex(&DeviceExtension
->DeviceLock
, FALSE
);
1234 ASSERT(Status
== 0);