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: videoprt.c,v 1.17 2004/03/09 17:28:49 navaraf Exp $
26 BOOLEAN CsrssInitialized
= FALSE
;
27 PEPROCESS Csrss
= NULL
;
28 PVIDEO_PORT_DEVICE_EXTENSION ResetDisplayParametersDeviceExtension
= NULL
;
29 static PVOID RomImageBuffer
= NULL
;
32 VideoPortDeferredRoutine(
34 IN PVOID DeferredContext
,
35 IN PVOID SystemArgument1
,
36 IN PVOID SystemArgument2
39 VideoPortGetProcAddress(IN PVOID HwDeviceExtension
,
40 IN PUCHAR FunctionName
);
42 // ------------------------------------------------------- Public Interface
47 // This function initializes the driver.
53 // IN PDRIVER_OBJECT DriverObject System allocated Driver Object
55 // IN PUNICODE_STRING RegistryPath Name of registry driver service
62 DriverEntry(IN PDRIVER_OBJECT DriverObject
,
63 IN PUNICODE_STRING RegistryPath
)
65 DPRINT("DriverEntry()\n");
66 return(STATUS_SUCCESS
);
73 VideoPortDebugPrint(IN VIDEO_DEBUG_LEVEL DebugPrintLevel
,
74 IN PCHAR DebugMessage
, ...)
80 if (DebugPrintLevel > InternalDebugLevel)
83 va_start (ap
, DebugMessage
);
84 vsprintf (Buffer
, DebugMessage
, ap
);
96 VideoPortFreeDeviceBase(IN PVOID HwDeviceExtension
,
97 IN PVOID MappedAddress
)
99 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
101 DPRINT("VideoPortFreeDeviceBase\n");
103 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
104 VIDEO_PORT_DEVICE_EXTENSION
,
105 MiniPortDeviceExtension
);
107 InternalUnmapMemory(DeviceExtension
, MappedAddress
);
116 VideoPortGetBusData(IN PVOID HwDeviceExtension
,
117 IN BUS_DATA_TYPE BusDataType
,
123 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
125 DPRINT("VideoPortGetBusData\n");
127 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
128 VIDEO_PORT_DEVICE_EXTENSION
,
129 MiniPortDeviceExtension
);
131 return HalGetBusDataByOffset(BusDataType
,
132 DeviceExtension
->SystemIoBusNumber
,
145 VideoPortGetCurrentIrql(VOID
)
147 return KeGetCurrentIrql();
156 VideoPortGetDeviceBase(IN PVOID HwDeviceExtension
,
157 IN PHYSICAL_ADDRESS IoAddress
,
158 IN ULONG NumberOfUchars
,
161 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
163 DPRINT("VideoPortGetDeviceBase\n");
165 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
166 VIDEO_PORT_DEVICE_EXTENSION
,
167 MiniPortDeviceExtension
);
169 return InternalMapMemory(DeviceExtension
, IoAddress
, NumberOfUchars
, InIoSpace
, NULL
);
178 VideoPortGetDeviceData(IN PVOID HwDeviceExtension
,
179 IN VIDEO_DEVICE_DATA_TYPE DeviceDataType
,
180 IN PMINIPORT_QUERY_DEVICE_ROUTINE CallbackRoutine
,
183 DPRINT("VideoPortGetDeviceData\n");
185 return STATUS_NOT_IMPLEMENTED
;
194 VideoPortGetAccessRanges(IN PVOID HwDeviceExtension
,
195 IN ULONG NumRequestedResources
,
196 IN PIO_RESOURCE_DESCRIPTOR RequestedResources OPTIONAL
,
197 IN ULONG NumAccessRanges
,
198 IN PVIDEO_ACCESS_RANGE AccessRanges
,
203 PCI_SLOT_NUMBER PciSlotNumber
;
204 ULONG FunctionNumber
;
205 PCI_COMMON_CONFIG Config
;
206 PCM_RESOURCE_LIST AllocatedResources
;
209 CM_FULL_RESOURCE_DESCRIPTOR
*FullList
;
210 CM_PARTIAL_RESOURCE_DESCRIPTOR
*Descriptor
;
211 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
212 USHORT VendorIdToFind
;
213 USHORT DeviceIdToFind
;
216 DPRINT("VideoPortGetAccessRanges\n");
218 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
219 VIDEO_PORT_DEVICE_EXTENSION
,
220 MiniPortDeviceExtension
);
222 if (0 == NumRequestedResources
&&
223 PCIBus
== DeviceExtension
->AdapterInterfaceType
)
225 VendorIdToFind
= VendorId
!= NULL
? *(PUSHORT
)VendorId
: 0;
226 DeviceIdToFind
= DeviceId
!= NULL
? *(PUSHORT
)DeviceId
: 0;
227 SlotIdToFind
= Slot
!= NULL
? *Slot
: 0;
229 DPRINT("Looking for VendorId 0x%04x DeviceId 0x%04x SlotId 0x%04x\n",
230 VendorIdToFind
, DeviceIdToFind
, SlotIdToFind
);
232 PciSlotNumber
.u
.AsULONG
= SlotIdToFind
;
235 Search for the device id and vendor id on this bus.
237 for (FunctionNumber
= 0; FunctionNumber
< 8; FunctionNumber
++)
239 ULONG ReturnedLength
;
240 DPRINT("- Function number: %d\n", FunctionNumber
);
241 PciSlotNumber
.u
.bits
.FunctionNumber
= FunctionNumber
;
242 ReturnedLength
= HalGetBusData(PCIConfiguration
,
243 DeviceExtension
->SystemIoBusNumber
,
244 PciSlotNumber
.u
.AsULONG
,
246 sizeof(PCI_COMMON_CONFIG
));
247 DPRINT("- Length of data: %x\n", ReturnedLength
);
248 if (sizeof(PCI_COMMON_CONFIG
) == ReturnedLength
)
250 DPRINT("- Slot 0x%02x (Device %d Function %d) VendorId 0x%04x "
252 PciSlotNumber
.u
.AsULONG
,
253 PciSlotNumber
.u
.bits
.DeviceNumber
,
254 PciSlotNumber
.u
.bits
.FunctionNumber
,
258 if ((VendorIdToFind
== 0 || Config
.VendorID
== VendorIdToFind
) &&
259 (DeviceIdToFind
== 0 || Config
.DeviceID
== DeviceIdToFind
))
265 if (FunctionNumber
== 8)
267 DPRINT("Didn't find device.\n");
268 return STATUS_UNSUCCESSFUL
;
271 Status
= HalAssignSlotResources(NULL
, NULL
, NULL
, NULL
,
272 DeviceExtension
->AdapterInterfaceType
,
273 DeviceExtension
->SystemIoBusNumber
,
274 PciSlotNumber
.u
.AsULONG
,
275 &AllocatedResources
);
276 if (! NT_SUCCESS(Status
))
281 for (FullList
= AllocatedResources
->List
;
282 FullList
< AllocatedResources
->List
+ AllocatedResources
->Count
;
285 assert(FullList
->InterfaceType
== PCIBus
&&
286 FullList
->BusNumber
== DeviceExtension
->SystemIoBusNumber
&&
287 1 == FullList
->PartialResourceList
.Version
&&
288 1 == FullList
->PartialResourceList
.Revision
);
289 for (Descriptor
= FullList
->PartialResourceList
.PartialDescriptors
;
290 Descriptor
< FullList
->PartialResourceList
.PartialDescriptors
+ FullList
->PartialResourceList
.Count
;
293 if ((CmResourceTypeMemory
== Descriptor
->Type
294 || CmResourceTypePort
== Descriptor
->Type
)
295 && NumAccessRanges
<= AssignedCount
)
297 DPRINT1("Too many access ranges found\n");
298 ExFreePool(AllocatedResources
);
299 return STATUS_UNSUCCESSFUL
;
301 if (CmResourceTypeMemory
== Descriptor
->Type
)
303 if (NumAccessRanges
<= AssignedCount
)
305 DPRINT1("Too many access ranges found\n");
306 ExFreePool(AllocatedResources
);
307 return STATUS_UNSUCCESSFUL
;
309 DPRINT("Memory range starting at 0x%08x length 0x%08x\n",
310 Descriptor
->u
.Memory
.Start
.u
.LowPart
, Descriptor
->u
.Memory
.Length
);
311 AccessRanges
[AssignedCount
].RangeStart
= Descriptor
->u
.Memory
.Start
;
312 AccessRanges
[AssignedCount
].RangeLength
= Descriptor
->u
.Memory
.Length
;
313 AccessRanges
[AssignedCount
].RangeInIoSpace
= 0;
314 AccessRanges
[AssignedCount
].RangeVisible
= 0; /* FIXME: Just guessing */
315 AccessRanges
[AssignedCount
].RangeShareable
=
316 (CmResourceShareShared
== Descriptor
->ShareDisposition
);
319 else if (CmResourceTypePort
== Descriptor
->Type
)
321 DPRINT("Port range starting at 0x%04x length %d\n",
322 Descriptor
->u
.Memory
.Start
.u
.LowPart
, Descriptor
->u
.Memory
.Length
);
323 AccessRanges
[AssignedCount
].RangeStart
= Descriptor
->u
.Port
.Start
;
324 AccessRanges
[AssignedCount
].RangeLength
= Descriptor
->u
.Port
.Length
;
325 AccessRanges
[AssignedCount
].RangeInIoSpace
= 1;
326 AccessRanges
[AssignedCount
].RangeVisible
= 0; /* FIXME: Just guessing */
327 AccessRanges
[AssignedCount
].RangeShareable
= 0;
330 else if (CmResourceTypeInterrupt
== Descriptor
->Type
)
332 DeviceExtension
->InterruptLevel
= Descriptor
->u
.Interrupt
.Level
;
333 DeviceExtension
->InterruptVector
= Descriptor
->u
.Interrupt
.Vector
;
337 ExFreePool(AllocatedResources
);
344 return STATUS_SUCCESS
;
347 typedef struct QueryRegistryCallbackContext
349 PVOID HwDeviceExtension
;
351 PMINIPORT_GET_REGISTRY_ROUTINE HwGetRegistryRoutine
;
352 } QUERY_REGISTRY_CALLBACK_CONTEXT
, *PQUERY_REGISTRY_CALLBACK_CONTEXT
;
354 static NTSTATUS STDCALL
355 QueryRegistryCallback(IN PWSTR ValueName
,
358 IN ULONG ValueLength
,
360 IN PVOID EntryContext
)
362 PQUERY_REGISTRY_CALLBACK_CONTEXT CallbackContext
= (PQUERY_REGISTRY_CALLBACK_CONTEXT
) Context
;
364 DPRINT("Found registry value for name %S: type %d, length %d\n",
365 ValueName
, ValueType
, ValueLength
);
366 return (*(CallbackContext
->HwGetRegistryRoutine
))(CallbackContext
->HwDeviceExtension
,
367 CallbackContext
->HwContext
,
378 VideoPortGetRegistryParameters(IN PVOID HwDeviceExtension
,
379 IN PWSTR ParameterName
,
380 IN UCHAR IsParameterFileName
,
381 IN PMINIPORT_GET_REGISTRY_ROUTINE GetRegistryRoutine
,
384 RTL_QUERY_REGISTRY_TABLE QueryTable
[2];
385 QUERY_REGISTRY_CALLBACK_CONTEXT Context
;
386 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
388 DPRINT("VideoPortGetRegistryParameters ParameterName %S\n", ParameterName
);
390 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
391 VIDEO_PORT_DEVICE_EXTENSION
,
392 MiniPortDeviceExtension
);
394 if (IsParameterFileName
)
399 Context
.HwDeviceExtension
= HwDeviceExtension
;
400 Context
.HwContext
= HwContext
;
401 Context
.HwGetRegistryRoutine
= GetRegistryRoutine
;
403 QueryTable
[0].QueryRoutine
= QueryRegistryCallback
;
404 QueryTable
[0].Flags
= RTL_QUERY_REGISTRY_REQUIRED
;
405 QueryTable
[0].Name
= ParameterName
;
406 QueryTable
[0].EntryContext
= NULL
;
407 QueryTable
[0].DefaultType
= REG_NONE
;
408 QueryTable
[0].DefaultData
= NULL
;
409 QueryTable
[0].DefaultLength
= 0;
411 QueryTable
[1].QueryRoutine
= NULL
;
412 QueryTable
[1].Name
= NULL
;
414 return NT_SUCCESS(RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE
,
415 DeviceExtension
->RegistryPath
.Buffer
,
416 QueryTable
, &Context
, NULL
))
417 ? ERROR_SUCCESS
: ERROR_INVALID_PARAMETER
;
426 VideoPortGetVgaStatus(IN PVOID HwDeviceExtension
,
427 OUT PULONG VgaStatus
)
429 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
431 DPRINT1("VideoPortGetVgaStatus = %S \n", VgaStatus
);
433 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
434 VIDEO_PORT_DEVICE_EXTENSION
,
435 MiniPortDeviceExtension
);
437 if(KeGetCurrentIrql() == PASSIVE_LEVEL
)
439 DPRINT1("VideoPortGetVgaStatus1 = %S \n", VgaStatus
);
441 if ( PCIBus
== DeviceExtension
->AdapterInterfaceType
)
444 VgaStatus 0 == VGA not enabled, 1 == VGA enabled.
446 DPRINT1("VideoPortGetVgaStatus2 = %S \n", VgaStatus
);
448 /* Assumed for now */
450 VgaStatus
= (PULONG
) 1;
452 return STATUS_SUCCESS
;
455 DPRINT1("VideoPortGetVgaStatus3 = %S \n", VgaStatus
);
457 return ERROR_INVALID_FUNCTION
;
461 VPInterruptRoutine(IN
struct _KINTERRUPT
*Interrupt
,
462 IN PVOID ServiceContext
)
464 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
466 DeviceExtension
= ServiceContext
;
467 assert(NULL
!= DeviceExtension
->HwInterrupt
);
469 return DeviceExtension
->HwInterrupt(&DeviceExtension
->MiniPortDeviceExtension
);
473 VPTimerRoutine(IN PDEVICE_OBJECT DeviceObject
,
476 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
478 DeviceExtension
= Context
;
479 assert(DeviceExtension
== DeviceObject
->DeviceExtension
480 && NULL
!= DeviceExtension
->HwTimer
);
482 DeviceExtension
->HwTimer(&DeviceExtension
->MiniPortDeviceExtension
);
489 VideoPortInitialize(IN PVOID Context1
,
491 IN PVIDEO_HW_INITIALIZATION_DATA HwInitializationData
,
494 PUNICODE_STRING RegistryPath
;
496 WCHAR DeviceBuffer
[20];
497 WCHAR SymlinkBuffer
[20];
498 WCHAR DeviceVideoBuffer
[20];
500 PDRIVER_OBJECT MPDriverObject
= (PDRIVER_OBJECT
) Context1
;
501 PDEVICE_OBJECT MPDeviceObject
;
502 VIDEO_PORT_CONFIG_INFO ConfigInfo
;
503 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
505 UNICODE_STRING DeviceName
;
506 UNICODE_STRING SymlinkName
;
511 ULONG InterruptVector
;
512 OBJECT_ATTRIBUTES Obj
;
515 DPRINT("VideoPortInitialize\n");
517 RegistryPath
= (PUNICODE_STRING
) Context2
;
519 /* Build Dispatch table from passed data */
520 MPDriverObject
->DriverStartIo
= (PDRIVER_STARTIO
) HwInitializationData
->HwStartIO
;
522 /* Find the first free device number */
523 for (DisplayNumber
= 0;;)
525 swprintf(SymlinkBuffer
, L
"\\??\\DISPLAY%lu", DisplayNumber
+ 1);
526 RtlInitUnicodeString(&SymlinkName
, SymlinkBuffer
);
527 InitializeObjectAttributes(&Obj
, &SymlinkName
, 0, NULL
, NULL
);
528 Status
= ZwOpenSymbolicLinkObject(&ObjHandle
, GENERIC_READ
, &Obj
);
529 if (NT_SUCCESS(Status
))
535 else if (Status
== STATUS_NOT_FOUND
|| Status
== STATUS_UNSUCCESSFUL
)
545 DPRINT("- DisplayNumber: %d\n", DisplayNumber
);
551 /* Create a unicode device name. */
552 swprintf(DeviceBuffer
, L
"\\Device\\Video%lu", DisplayNumber
);
553 RtlInitUnicodeString(&DeviceName
, DeviceBuffer
);
555 /* Create the device. */
556 Status
= IoCreateDevice(
558 HwInitializationData
->HwDeviceExtensionSize
+
559 sizeof(VIDEO_PORT_DEVICE_EXTENSION
),
565 if (!NT_SUCCESS(Status
))
567 DPRINT("IoCreateDevice call failed with status 0x%08x\n", Status
);
571 MPDriverObject
->DeviceObject
= MPDeviceObject
;
573 /* Initialize the miniport drivers dispatch table */
574 MPDriverObject
->MajorFunction
[IRP_MJ_CREATE
] = VidDispatchOpen
;
575 MPDriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = VidDispatchClose
;
576 MPDriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = VidDispatchDeviceControl
;
578 /* Initialize our device extension */
580 (PVIDEO_PORT_DEVICE_EXTENSION
) MPDeviceObject
->DeviceExtension
;
581 DeviceExtension
->DeviceObject
= MPDeviceObject
;
582 DeviceExtension
->HwInitialize
= HwInitializationData
->HwInitialize
;
583 DeviceExtension
->HwResetHw
= HwInitializationData
->HwResetHw
;
584 DeviceExtension
->AdapterInterfaceType
= HwInitializationData
->AdapterInterfaceType
;
585 DeviceExtension
->SystemIoBusNumber
= 0;
586 KeInitializeDpc(&DeviceExtension
->DpcObject
, VideoPortDeferredRoutine
,
587 (PVOID
)DeviceExtension
);
588 MaxLen
= (wcslen(RegistryPath
->Buffer
) + 10) * sizeof(WCHAR
);
589 DeviceExtension
->RegistryPath
.MaximumLength
= MaxLen
;
590 DeviceExtension
->RegistryPath
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
593 swprintf(DeviceExtension
->RegistryPath
.Buffer
, L
"%s\\Device0",
594 RegistryPath
->Buffer
);
595 DeviceExtension
->RegistryPath
.Length
= wcslen(DeviceExtension
->RegistryPath
.Buffer
) *
598 MaxBus
= (DeviceExtension
->AdapterInterfaceType
== PCIBus
) ? 8 : 1;
599 DPRINT("MaxBus: %lu\n", MaxBus
);
600 InitializeListHead(&DeviceExtension
->AddressMappingListHead
);
602 /* Set the buffering strategy here... */
603 /* If you change this, remember to change VidDispatchDeviceControl too */
604 MPDeviceObject
->Flags
|= DO_BUFFERED_IO
;
608 RtlZeroMemory(&DeviceExtension
->MiniPortDeviceExtension
,
609 HwInitializationData
->HwDeviceExtensionSize
);
610 DPRINT("Searching on bus %d\n", DeviceExtension
->SystemIoBusNumber
);
611 /* Setup configuration info */
612 RtlZeroMemory(&ConfigInfo
, sizeof(VIDEO_PORT_CONFIG_INFO
));
613 ConfigInfo
.Length
= sizeof(VIDEO_PORT_CONFIG_INFO
);
614 ConfigInfo
.AdapterInterfaceType
= DeviceExtension
->AdapterInterfaceType
;
615 ConfigInfo
.SystemIoBusNumber
= DeviceExtension
->SystemIoBusNumber
;
616 ConfigInfo
.InterruptMode
= (PCIBus
== DeviceExtension
->AdapterInterfaceType
) ?
617 LevelSensitive
: Latched
;
618 ConfigInfo
.DriverRegistryPath
= RegistryPath
->Buffer
;
619 ConfigInfo
.VideoPortGetProcAddress
= VideoPortGetProcAddress
;
621 /* Call HwFindAdapter entry point */
622 /* FIXME: Need to figure out what string to pass as param 3 */
623 DPRINT("FindAdapter %X\n", HwInitializationData
->HwFindAdapter
);
624 Status
= HwInitializationData
->HwFindAdapter(&DeviceExtension
->MiniPortDeviceExtension
,
629 if (NO_ERROR
!= Status
)
631 DPRINT("HwFindAdapter call failed with error %X\n", Status
);
632 DeviceExtension
->SystemIoBusNumber
++;
635 while (NO_ERROR
!= Status
&& DeviceExtension
->SystemIoBusNumber
< MaxBus
);
637 if (NO_ERROR
!= Status
)
639 RtlFreeUnicodeString(&DeviceExtension
->RegistryPath
);
640 IoDeleteDevice(MPDeviceObject
);
644 DPRINT("Found adapter\n");
646 /* create symbolic link "\??\DISPLAYx" */
647 swprintf(SymlinkBuffer
, L
"\\??\\DISPLAY%lu", DisplayNumber
+ 1);
648 RtlInitUnicodeString (&SymlinkName
,
650 IoCreateSymbolicLink (&SymlinkName
,
653 /* Add entry to DEVICEMAP\VIDEO key in registry */
654 swprintf(DeviceVideoBuffer
, L
"\\Device\\Video%d", DisplayNumber
);
655 RtlWriteRegistryValue(RTL_REGISTRY_DEVICEMAP
,
659 DeviceExtension
->RegistryPath
.Buffer
,
660 DeviceExtension
->RegistryPath
.Length
+ sizeof(WCHAR
));
662 /* FIXME: Allocate hardware resources for device */
664 /* Allocate interrupt for device */
665 DeviceExtension
->HwInterrupt
= HwInitializationData
->HwInterrupt
;
666 if (0 == ConfigInfo
.BusInterruptVector
)
668 ConfigInfo
.BusInterruptVector
= DeviceExtension
->InterruptVector
;
670 if (0 == ConfigInfo
.BusInterruptLevel
)
672 ConfigInfo
.BusInterruptLevel
= DeviceExtension
->InterruptLevel
;
674 if (NULL
!= HwInitializationData
->HwInterrupt
)
677 HalGetInterruptVector(ConfigInfo
.AdapterInterfaceType
,
678 ConfigInfo
.SystemIoBusNumber
,
679 ConfigInfo
.BusInterruptLevel
,
680 ConfigInfo
.BusInterruptVector
,
683 if (0 == InterruptVector
)
685 DPRINT1("HalGetInterruptVector failed\n");
686 IoDeleteDevice(MPDeviceObject
);
688 return STATUS_INSUFFICIENT_RESOURCES
;
690 KeInitializeSpinLock(&DeviceExtension
->InterruptSpinLock
);
691 Status
= IoConnectInterrupt(&DeviceExtension
->InterruptObject
,
694 &DeviceExtension
->InterruptSpinLock
,
698 ConfigInfo
.InterruptMode
,
702 if (!NT_SUCCESS(Status
))
704 DPRINT1("IoConnectInterrupt failed with status 0x%08x\n", Status
);
705 IoDeleteDevice(MPDeviceObject
);
714 DeviceExtension
->HwTimer
= HwInitializationData
->HwTimer
;
715 if (HwInitializationData
->HwTimer
!= NULL
)
717 DPRINT("Initializing timer\n");
718 Status
= IoInitializeTimer(MPDeviceObject
,
721 if (!NT_SUCCESS(Status
))
723 DPRINT("IoInitializeTimer failed with status 0x%08x\n", Status
);
725 if (HwInitializationData
->HwInterrupt
!= NULL
)
727 IoDisconnectInterrupt(DeviceExtension
->InterruptObject
);
729 IoDeleteDevice(MPDeviceObject
);
735 return STATUS_SUCCESS
;
743 VideoPortLogError(IN PVOID HwDeviceExtension
,
744 IN PVIDEO_REQUEST_PACKET Vrp OPTIONAL
,
745 IN VP_STATUS ErrorCode
,
748 DPRINT1("VideoPortLogError ErrorCode %d (0x%x) UniqueId %lu (0x%lx)\n",
749 ErrorCode
, ErrorCode
, UniqueId
, UniqueId
);
752 DPRINT1("Vrp->IoControlCode %lu (0x%lx)\n", Vrp
->IoControlCode
, Vrp
->IoControlCode
);
762 VideoPortMapBankedMemory(IN PVOID HwDeviceExtension
,
763 IN PHYSICAL_ADDRESS PhysicalAddress
,
766 OUT PVOID
*VirtualAddress
,
768 IN UCHAR ReadWriteBank
,
769 IN PBANKED_SECTION_ROUTINE BankRoutine
,
772 DPRINT("VideoPortMapBankedMemory\n");
774 return STATUS_NOT_IMPLEMENTED
;
783 VideoPortMapMemory(IN PVOID HwDeviceExtension
,
784 IN PHYSICAL_ADDRESS PhysicalAddress
,
787 OUT PVOID
*VirtualAddress
)
789 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
792 DPRINT("VideoPortMapMemory\n");
794 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
795 VIDEO_PORT_DEVICE_EXTENSION
,
796 MiniPortDeviceExtension
);
797 *VirtualAddress
= InternalMapMemory(DeviceExtension
, PhysicalAddress
,
798 *Length
, *InIoSpace
, &Status
);
809 VideoPortScanRom(IN PVOID HwDeviceExtension
,
816 PUCHAR SearchLocation
;
818 DPRINT("VideoPortScanRom RomBase %p RomLength 0x%x String %s\n", RomBase
, RomLength
, String
);
820 StringLength
= strlen(String
);
822 SearchLocation
= RomBase
;
823 for (SearchLocation
= RomBase
;
824 ! Found
&& SearchLocation
< RomBase
+ RomLength
- StringLength
;
827 Found
= (RtlCompareMemory(SearchLocation
, String
, StringLength
) == StringLength
);
830 DPRINT("Match found at %p\n", SearchLocation
);
843 VideoPortSetBusData(IN PVOID HwDeviceExtension
,
844 IN BUS_DATA_TYPE BusDataType
,
850 DPRINT("VideoPortSetBusData\n");
851 return HalSetBusDataByOffset(BusDataType
,
865 VideoPortSetRegistryParameters(IN PVOID HwDeviceExtension
,
868 IN ULONG ValueLength
)
870 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
872 DPRINT("VideoSetRegistryParameters\n");
874 assert_irql(PASSIVE_LEVEL
);
876 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
877 VIDEO_PORT_DEVICE_EXTENSION
,
878 MiniPortDeviceExtension
);
879 return RtlWriteRegistryValue(RTL_REGISTRY_ABSOLUTE
,
880 DeviceExtension
->RegistryPath
.Buffer
,
893 VideoPortSetTrappedEmulatorPorts(IN PVOID HwDeviceExtension
,
894 IN ULONG NumAccessRanges
,
895 IN PVIDEO_ACCESS_RANGE AccessRange
)
897 DPRINT("VideoPortSetTrappedEmulatorPorts\n");
898 /* Should store the ranges in the device extension for use by ntvdm. */
899 return STATUS_SUCCESS
;
908 VideoPortStartTimer(IN PVOID HwDeviceExtension
)
910 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
912 DPRINT("VideoPortStartTimer\n");
914 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
915 VIDEO_PORT_DEVICE_EXTENSION
,
916 MiniPortDeviceExtension
);
917 IoStartTimer(DeviceExtension
->DeviceObject
);
926 VideoPortStopTimer(IN PVOID HwDeviceExtension
)
928 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
930 DPRINT("VideoPortStopTimer\n");
932 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
933 VIDEO_PORT_DEVICE_EXTENSION
,
934 MiniPortDeviceExtension
);
935 IoStopTimer(DeviceExtension
->DeviceObject
);
944 VideoPortSynchronizeExecution(IN PVOID HwDeviceExtension
,
945 IN VIDEO_SYNCHRONIZE_PRIORITY Priority
,
946 IN PMINIPORT_SYNCHRONIZE_ROUTINE SynchronizeRoutine
,
950 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
956 Ret
= (*SynchronizeRoutine
)(Context
);
958 case VpMediumPriority
:
959 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
960 VIDEO_PORT_DEVICE_EXTENSION
,
961 MiniPortDeviceExtension
);
962 if (NULL
== DeviceExtension
->InterruptObject
)
964 Ret
= (*SynchronizeRoutine
)(Context
);
968 Ret
= KeSynchronizeExecution(DeviceExtension
->InterruptObject
,
974 OldIrql
= KeGetCurrentIrql();
975 if (OldIrql
< SYNCH_LEVEL
)
977 OldIrql
= KfRaiseIrql(SYNCH_LEVEL
);
979 Ret
= (*SynchronizeRoutine
)(Context
);
980 if (OldIrql
< SYNCH_LEVEL
)
982 KfLowerIrql(OldIrql
);
998 VideoPortUnmapMemory(IN PVOID HwDeviceExtension
,
999 IN PVOID VirtualAddress
,
1000 IN HANDLE ProcessHandle
)
1002 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
1004 DPRINT("VideoPortFreeDeviceBase\n");
1006 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
1007 VIDEO_PORT_DEVICE_EXTENSION
,
1008 MiniPortDeviceExtension
);
1010 InternalUnmapMemory(DeviceExtension
, VirtualAddress
);
1012 return STATUS_SUCCESS
;
1021 VideoPortVerifyAccessRanges(IN PVOID HwDeviceExtension
,
1022 IN ULONG NumAccessRanges
,
1023 IN PVIDEO_ACCESS_RANGE AccessRanges
)
1025 DPRINT1("VideoPortVerifyAccessRanges not implemented\n");
1031 * Reset display to blue screen
1033 static BOOLEAN STDCALL
1034 VideoPortResetDisplayParameters(Columns
, Rows
)
1036 if (NULL
== ResetDisplayParametersDeviceExtension
)
1040 if (NULL
== ResetDisplayParametersDeviceExtension
->HwResetHw
)
1044 if (!ResetDisplayParametersDeviceExtension
->HwResetHw(&ResetDisplayParametersDeviceExtension
->MiniPortDeviceExtension
,
1050 ResetDisplayParametersDeviceExtension
= NULL
;
1061 VideoPortAllocatePool(
1062 IN PVOID HwDeviceExtension
,
1063 IN VP_POOL_TYPE PoolType
,
1064 IN SIZE_T NumberOfBytes
,
1067 return ExAllocatePoolWithTag(PoolType
, NumberOfBytes
, Tag
);
1077 IN PVOID HwDeviceExtension
,
1086 // Answer requests for Open calls
1092 // Standard dispatch arguments
1099 VidDispatchOpen(IN PDEVICE_OBJECT pDO
,
1102 PIO_STACK_LOCATION IrpStack
;
1103 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
1105 DPRINT("VidDispatchOpen() called\n");
1107 IrpStack
= IoGetCurrentIrpStackLocation(Irp
);
1109 if (! CsrssInitialized
)
1111 DPRINT("Referencing CSRSS\n");
1112 Csrss
= PsGetCurrentProcess();
1113 DPRINT("Csrss %p\n", Csrss
);
1117 DeviceExtension
= (PVIDEO_PORT_DEVICE_EXTENSION
) pDO
->DeviceExtension
;
1118 if (DeviceExtension
->HwInitialize(&DeviceExtension
->MiniPortDeviceExtension
))
1120 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
1121 /* Storing the device extension pointer in a static variable is an ugly
1122 * hack. Unfortunately, we need it in VideoPortResetDisplayParameters
1123 * and HalAcquireDisplayOwnership doesn't allow us to pass a userdata
1124 * parameter. On the bright side, the DISPLAY device is opened
1125 * exclusively, so there can be only one device extension active at
1126 * any point in time. */
1127 ResetDisplayParametersDeviceExtension
= DeviceExtension
;
1128 HalAcquireDisplayOwnership(VideoPortResetDisplayParameters
);
1132 Irp
->IoStatus
.Status
= STATUS_UNSUCCESSFUL
;
1136 Irp
->IoStatus
.Information
= FILE_OPENED
;
1137 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1139 return STATUS_SUCCESS
;
1145 // Answer requests for Close calls
1151 // Standard dispatch arguments
1158 VidDispatchClose(IN PDEVICE_OBJECT pDO
,
1161 PIO_STACK_LOCATION IrpStack
;
1163 DPRINT("VidDispatchClose() called\n");
1165 IrpStack
= IoGetCurrentIrpStackLocation(Irp
);
1167 if (! CsrssInitialized
)
1169 CsrssInitialized
= TRUE
;
1173 HalReleaseDisplayOwnership();
1176 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
1177 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1179 return STATUS_SUCCESS
;
1182 // VidDispatchDeviceControl
1185 // Answer requests for device control calls
1191 // Standard dispatch arguments
1198 VidDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject
,
1201 PIO_STACK_LOCATION IrpStack
;
1202 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
1203 PVIDEO_REQUEST_PACKET vrp
;
1205 DPRINT("VidDispatchDeviceControl\n");
1206 IrpStack
= IoGetCurrentIrpStackLocation(Irp
);
1207 DeviceExtension
= DeviceObject
->DeviceExtension
;
1209 /* Translate the IRP to a VRP */
1210 vrp
= ExAllocatePool(NonPagedPool
, sizeof(VIDEO_REQUEST_PACKET
));
1213 return STATUS_NO_MEMORY
;
1215 vrp
->StatusBlock
= (PSTATUS_BLOCK
) &(Irp
->IoStatus
);
1216 vrp
->IoControlCode
= IrpStack
->Parameters
.DeviceIoControl
.IoControlCode
;
1218 DPRINT("- IoControlCode: %x\n", vrp
->IoControlCode
);
1220 /* We're assuming METHOD_BUFFERED */
1221 vrp
->InputBuffer
= Irp
->AssociatedIrp
.SystemBuffer
;
1222 vrp
->InputBufferLength
= IrpStack
->Parameters
.DeviceIoControl
.InputBufferLength
;
1223 vrp
->OutputBuffer
= Irp
->AssociatedIrp
.SystemBuffer
;
1224 vrp
->OutputBufferLength
= IrpStack
->Parameters
.DeviceIoControl
.OutputBufferLength
;
1226 /* Call the Miniport Driver with the VRP */
1227 ((PDRIVER_STARTIO
)DeviceObject
->DriverObject
->DriverStartIo
)((PVOID
) &DeviceExtension
->MiniPortDeviceExtension
, (PIRP
)vrp
);
1232 DPRINT("- Returned status: %x\n", Irp
->IoStatus
.Status
);
1234 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1236 return STATUS_SUCCESS
;
1240 InternalMapMemory(IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
,
1241 IN PHYSICAL_ADDRESS IoAddress
,
1242 IN ULONG NumberOfUchars
,
1244 OUT NTSTATUS
*Status
)
1246 PHYSICAL_ADDRESS TranslatedAddress
;
1247 PVIDEO_PORT_ADDRESS_MAPPING AddressMapping
;
1249 PVOID MappedAddress
;
1252 DPRINT("- IoAddress: %lx\n", IoAddress
.u
.LowPart
);
1253 DPRINT("- NumberOfUchars: %lx\n", NumberOfUchars
);
1254 DPRINT("- InIoSpace: %x\n", InIoSpace
);
1255 InIoSpace
&= ~VIDEO_MEMORY_SPACE_DENSE
;
1256 if (0 != (InIoSpace
& VIDEO_MEMORY_SPACE_P6CACHE
))
1258 DPRINT("VIDEO_MEMORY_SPACE_P6CACHE not supported, turning off\n");
1259 InIoSpace
&= ~VIDEO_MEMORY_SPACE_P6CACHE
;
1261 if (! IsListEmpty(&DeviceExtension
->AddressMappingListHead
))
1263 Entry
= DeviceExtension
->AddressMappingListHead
.Flink
;
1264 while (Entry
!= &DeviceExtension
->AddressMappingListHead
)
1266 AddressMapping
= CONTAINING_RECORD(Entry
,
1267 VIDEO_PORT_ADDRESS_MAPPING
,
1269 if (IoAddress
.QuadPart
== AddressMapping
->IoAddress
.QuadPart
&&
1270 NumberOfUchars
<= AddressMapping
->NumberOfUchars
)
1272 AddressMapping
->MappingCount
++;
1275 *Status
= STATUS_SUCCESS
;
1277 return AddressMapping
->MappedAddress
;
1279 Entry
= Entry
->Flink
;
1283 AddressSpace
= (ULONG
)InIoSpace
;
1284 if (HalTranslateBusAddress(DeviceExtension
->AdapterInterfaceType
,
1285 DeviceExtension
->SystemIoBusNumber
,
1288 &TranslatedAddress
) == FALSE
)
1292 *Status
= STATUS_NO_MEMORY
;
1298 if (AddressSpace
!= 0)
1300 assert(0 == TranslatedAddress
.u
.HighPart
);
1303 *Status
= STATUS_SUCCESS
;
1305 return (PVOID
) TranslatedAddress
.u
.LowPart
;
1308 MappedAddress
= MmMapIoSpace(TranslatedAddress
,
1316 *Status
= STATUS_SUCCESS
;
1319 AddressMapping
= ExAllocatePoolWithTag(PagedPool
,
1320 sizeof(VIDEO_PORT_ADDRESS_MAPPING
),
1322 if (AddressMapping
== NULL
)
1323 return MappedAddress
;
1325 AddressMapping
->MappedAddress
= MappedAddress
;
1326 AddressMapping
->NumberOfUchars
= NumberOfUchars
;
1327 AddressMapping
->IoAddress
= IoAddress
;
1328 AddressMapping
->SystemIoBusNumber
= DeviceExtension
->SystemIoBusNumber
;
1329 AddressMapping
->MappingCount
= 1;
1331 InsertHeadList(&DeviceExtension
->AddressMappingListHead
,
1332 &AddressMapping
->List
);
1334 return MappedAddress
;
1340 *Status
= STATUS_NO_MEMORY
;
1348 InternalUnmapMemory(IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
,
1349 IN PVOID MappedAddress
)
1351 PVIDEO_PORT_ADDRESS_MAPPING AddressMapping
;
1354 Entry
= DeviceExtension
->AddressMappingListHead
.Flink
;
1355 while (Entry
!= &DeviceExtension
->AddressMappingListHead
)
1357 AddressMapping
= CONTAINING_RECORD(Entry
,
1358 VIDEO_PORT_ADDRESS_MAPPING
,
1360 if (AddressMapping
->MappedAddress
== MappedAddress
)
1362 assert(0 <= AddressMapping
->MappingCount
);
1363 AddressMapping
->MappingCount
--;
1364 if (0 == AddressMapping
->MappingCount
)
1366 MmUnmapIoSpace(AddressMapping
->MappedAddress
,
1367 AddressMapping
->NumberOfUchars
);
1368 RemoveEntryList(Entry
);
1369 ExFreePool(AddressMapping
);
1375 Entry
= Entry
->Flink
;
1380 VideoPortDDCMonitorHelper(
1381 PVOID HwDeviceExtension
,
1382 /*PI2C_FNC_TABLE*/PVOID I2CFunctions
,
1384 ULONG EdidBufferSize
1387 DPRINT1("VideoPortDDCMonitorHelper() - Unimplemented.\n");
1396 VideoPortAllocateBuffer(IN PVOID HwDeviceExtension
,
1400 DPRINT("VideoPortAllocateBuffer()\n");
1402 Buffer
= ExAllocatePool(PagedPool
, Size
);
1403 return STATUS_SUCCESS
;
1412 VideoPortReleaseBuffer( IN PVOID HwDeviceExtension
,
1415 DPRINT("VideoPortReleaseBuffer()\n");
1423 VideoPortEnumerateChildren ( IN PVOID HwDeviceExtension
,
1426 DPRINT1("VideoPortEnumerateChildren(): Unimplemented.\n");
1427 return STATUS_SUCCESS
;
1432 VideoPortGetRomImage ( IN PVOID HwDeviceExtension
,
1437 DPRINT("VideoPortGetRomImage(HwDeviceExtension 0x%X Length 0x%X)\n",
1438 HwDeviceExtension
, Length
);
1440 /* If the length is zero then free the existing buffer. */
1443 if (RomImageBuffer
!= NULL
)
1445 ExFreePool(RomImageBuffer
);
1446 RomImageBuffer
= NULL
;
1452 PEPROCESS CallingProcess
, PrevAttachedProcess
;
1455 The DDK says we shouldn't use the legacy C000 method but get the
1456 rom base address from the corresponding pci or acpi register but
1457 lets ignore that and use C000 anyway. CSRSS has already mapped the
1458 bios area into memory so we'll copy from there.
1460 CallingProcess
= PsGetCurrentProcess();
1461 if (CallingProcess
!= Csrss
)
1463 if (NULL
!= PsGetCurrentThread()->OldProcess
)
1465 PrevAttachedProcess
= CallingProcess
;
1470 PrevAttachedProcess
= NULL
;
1472 KeAttachProcess(Csrss
);
1478 Length
= min(Length
, 0x10000);
1479 if (RomImageBuffer
!= NULL
)
1481 ExFreePool(RomImageBuffer
);
1483 RomImageBuffer
= ExAllocatePool(PagedPool
, Length
);
1484 if (RomImageBuffer
== NULL
)
1488 RtlCopyMemory(RomImageBuffer
, (PUCHAR
)0xC0000, Length
);
1491 Detach from csrss if we attached.
1493 if (CallingProcess
!= Csrss
)
1496 if (NULL
!= PrevAttachedProcess
)
1498 KeAttachProcess(PrevAttachedProcess
);
1502 return(RomImageBuffer
);
1509 VideoPortDeferredRoutine ( IN PKDPC Dpc
,
1510 IN PVOID DeferredContext
,
1511 IN PVOID SystemArgument1
,
1512 IN PVOID SystemArgument2
)
1514 PVOID HwDeviceExtension
=
1515 ((PVIDEO_PORT_DEVICE_EXTENSION
)DeferredContext
)->MiniPortDeviceExtension
;
1516 ((PMINIPORT_DPC_ROUTINE
)SystemArgument1
)(HwDeviceExtension
, SystemArgument2
);
1521 VideoPortQueueDpc ( IN PVOID HwDeviceExtension
,
1522 IN PMINIPORT_DPC_ROUTINE CallbackRoutine
,
1525 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
1527 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
1528 VIDEO_PORT_DEVICE_EXTENSION
,
1529 MiniPortDeviceExtension
);
1530 return KeInsertQueueDpc(&DeviceExtension
->DpcObject
,
1531 (PVOID
)CallbackRoutine
,
1537 VideoPortGetAssociatedDeviceExtension ( IN PVOID DeviceObject
)
1539 DPRINT1("VideoPortGetAssociatedDeviceExtension(): Unimplemented.\n");
1545 VideoPortAllocateCommonBuffer ( IN PVOID HwDeviceExtension
,
1546 IN PVP_DMA_ADAPTER VpDmaAdapter
,
1547 IN ULONG DesiredLength
,
1548 OUT PPHYSICAL_ADDRESS LogicalAddress
,
1549 IN BOOLEAN CacheEnabled
,
1552 return HalAllocateCommonBuffer((PADAPTER_OBJECT
)VpDmaAdapter
,
1560 VideoPortReleaseCommonBuffer ( IN PVOID HwDeviceExtension
,
1561 IN PVP_DMA_ADAPTER VpDmaAdapter
,
1563 IN PHYSICAL_ADDRESS LogicalAddress
,
1564 IN PVOID VirtualAddress
,
1565 IN BOOLEAN CacheEnabled
)
1567 HalFreeCommonBuffer((PADAPTER_OBJECT
)VpDmaAdapter
,
1576 VideoPortCreateSecondaryDisplay ( IN PVOID HwDeviceExtension
,
1577 IN OUT PVOID
*SecondaryDeviceExtension
,
1580 DPRINT1("VideoPortCreateSecondaryDisplay(): Unimplemented.\n");
1581 return STATUS_UNSUCCESSFUL
;
1586 VideoPortPutDmaAdapter ( IN PVOID HwDeviceExtension
,
1587 IN PVP_DMA_ADAPTER VpDmaAdapter
)
1589 DPRINT("VideoPortPutDmaAdapter(): Unimplemented.\n");
1594 VideoPortGetDmaAdapter ( IN PVOID HwDeviceExtension
,
1595 IN PVP_DEVICE_DESCRIPTION VpDeviceExtension
)
1597 DEVICE_DESCRIPTION DeviceDescription
;
1598 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
;
1599 ULONG NumberOfMapRegisters
;
1600 PVP_DMA_ADAPTER Adapter
;
1602 DeviceExtension
= CONTAINING_RECORD(HwDeviceExtension
,
1603 VIDEO_PORT_DEVICE_EXTENSION
,
1604 MiniPortDeviceExtension
);
1606 DPRINT("VideoPortGetDmaAdapter()\n");
1608 DeviceDescription
.Version
= DEVICE_DESCRIPTION_VERSION
;
1609 DeviceDescription
.Master
= TRUE
/* ?? */;
1610 DeviceDescription
.ScatterGather
= VpDeviceExtension
->ScatterGather
;
1611 DeviceDescription
.DemandMode
= FALSE
/* ?? */;
1612 DeviceDescription
.AutoInitialize
= FALSE
/* ?? */;
1613 DeviceDescription
.Dma32BitAddresses
= VpDeviceExtension
->Dma32BitAddresses
;
1614 DeviceDescription
.IgnoreCount
= FALSE
/* ?? */;
1615 DeviceDescription
.Reserved1
= FALSE
;
1616 DeviceDescription
.BusNumber
= DeviceExtension
->SystemIoBusNumber
;
1617 DeviceDescription
.DmaChannel
= 0 /* ?? */;
1618 DeviceDescription
.InterfaceType
= DeviceExtension
->AdapterInterfaceType
;
1619 DeviceDescription
.DmaWidth
= Width8Bits
;
1620 DeviceDescription
.DmaSpeed
= Compatible
;
1621 DeviceDescription
.MaximumLength
= VpDeviceExtension
->MaximumLength
;
1622 DeviceDescription
.DmaPort
= 0;
1625 (PVP_DMA_ADAPTER
)HalGetAdapter(&DeviceDescription
, &NumberOfMapRegisters
);
1626 DPRINT("Adapter %X\n", Adapter
);
1636 VideoPortGetVersion ( IN PVOID HwDeviceExtension
,
1637 IN OUT PVPOSVERSIONINFO VpOsVersionInfo
)
1639 RTL_OSVERSIONINFOEXW Version
;
1641 Version
.dwOSVersionInfoSize
= sizeof(RTL_OSVERSIONINFOEXW
);
1642 if (VpOsVersionInfo
->Size
>= sizeof(VPOSVERSIONINFO
))
1645 if (NT_SUCCESS(RtlGetVersion((PRTL_OSVERSIONINFOW
)&Version
)))
1647 VpOsVersionInfo
->MajorVersion
= Version
.dwMajorVersion
;
1648 VpOsVersionInfo
->MinorVersion
= Version
.dwMinorVersion
;
1649 VpOsVersionInfo
->BuildNumber
= Version
.dwBuildNumber
;
1650 VpOsVersionInfo
->ServicePackMajor
= Version
.wServicePackMajor
;
1651 VpOsVersionInfo
->ServicePackMinor
= Version
.wServicePackMinor
;
1652 return STATUS_SUCCESS
;
1654 return STATUS_UNSUCCESSFUL
;
1656 VpOsVersionInfo
->MajorVersion
= 5;
1657 VpOsVersionInfo
->MinorVersion
= 0;
1658 VpOsVersionInfo
->BuildNumber
= 2195;
1659 VpOsVersionInfo
->ServicePackMajor
= 4;
1660 VpOsVersionInfo
->ServicePackMinor
= 0;
1661 return(STATUS_SUCCESS
);
1665 return ERROR_INVALID_PARAMETER
;
1670 VideoPortLockBuffer ( IN PVOID HwDeviceExtension
,
1671 IN PVOID BaseAddress
,
1673 IN VP_LOCK_OPERATION Operation
)
1675 DPRINT1("VideoPortLockBuffer(): Unimplemented.\n");
1681 VideoPortUnlockBuffer ( IN PVOID HwDeviceExtension
,
1684 DPRINT1("VideoPortUnlockBuffer(): Unimplemented.\n");
1689 VideoPortCreateEvent ( IN PVOID HwDeviceExtension
,
1695 (*Event
) = ExAllocatePoolWithTag(NonPagedPool
, sizeof(KEVENT
),
1697 if ((*Event
) == NULL
)
1699 return STATUS_NO_MEMORY
;
1701 if (EventFlag
& NOTIFICATION_EVENT
)
1703 Type
= NotificationEvent
;
1707 Type
= SynchronizationEvent
;
1709 KeInitializeEvent((PKEVENT
)*Event
, Type
, EventFlag
& INITIAL_EVENT_SIGNALED
);
1710 return STATUS_SUCCESS
;
1715 VideoPortDeleteEvent ( IN PVOID HwDeviceExtension
,
1719 return STATUS_SUCCESS
;
1724 VideoPortSetEvent ( IN PVOID HwDeviceExtension
,
1727 return KeSetEvent((PKEVENT
)Event
, IO_NO_INCREMENT
, FALSE
);
1732 VideoPortClearEvent ( IN PVOID HwDeviceExtension
,
1735 KeClearEvent((PKEVENT
)Event
);
1740 VideoPortWaitForSingleObject ( IN PVOID HwDeviceExtension
,
1742 IN PLARGE_INTEGER Timeout OPTIONAL
)
1744 return KeWaitForSingleObject(Object
,
1753 VideoPortCheckForDeviceExistence ( IN PVOID HwDeviceExtension
,
1756 IN UCHAR RevisionId
,
1757 IN USHORT SubVendorId
,
1758 IN USHORT SubSystemId
,
1761 DPRINT1("VideoPortCheckForDeviceExistence(): Unimplemented.\n");
1767 VideoPortRegisterBugcheckCallback ( IN PVOID HwDeviceExtension
,
1768 IN ULONG BugcheckCode
,
1770 IN ULONG BugcheckDataSize
)
1772 DPRINT1("VideoPortRegisterBugcheckCallback(): Unimplemented.\n");
1773 return STATUS_UNSUCCESSFUL
;
1778 VideoPortImageDirectoryEntryToData ( PVOID BaseAddress
,
1781 PIMAGE_NT_HEADERS NtHeader
;
1784 NtHeader
= RtlImageNtHeader (BaseAddress
);
1785 if (NtHeader
== NULL
)
1788 if (Directory
>= NtHeader
->OptionalHeader
.NumberOfRvaAndSizes
)
1791 Va
= NtHeader
->OptionalHeader
.DataDirectory
[Directory
].VirtualAddress
;
1795 return (PVOID
)(BaseAddress
+ Va
);
1799 VideoPortGetProcAddress(IN PVOID HwDeviceExtension
,
1800 IN PUCHAR FunctionName
)
1802 SYSTEM_LOAD_IMAGE GdiDriverInfo
;
1804 PIMAGE_EXPORT_DIRECTORY ExportDir
;
1811 DPRINT("VideoPortGetProcAddress(%s)\n", FunctionName
);
1813 RtlInitUnicodeString(&GdiDriverInfo
.ModuleName
, L
"videoprt");
1814 Status
= ZwSetSystemInformation(SystemLoadImage
, &GdiDriverInfo
,
1815 sizeof(SYSTEM_LOAD_IMAGE
));
1816 if (!NT_SUCCESS(Status
))
1818 DPRINT("Couldn't get our own module handle?\n");
1822 BaseAddress
= GdiDriverInfo
.ModuleBase
;
1824 /* Get the pointer to the export directory */
1825 ExportDir
= (PIMAGE_EXPORT_DIRECTORY
)
1826 VideoPortImageDirectoryEntryToData (BaseAddress
,
1827 IMAGE_DIRECTORY_ENTRY_EXPORT
);
1829 /* search by name */
1830 AddressPtr
= (PULONG
)
1831 ((ULONG_PTR
)BaseAddress
+ (ULONG_PTR
)ExportDir
->AddressOfFunctions
);
1832 OrdinalPtr
= (PUSHORT
)
1833 ((ULONG_PTR
)BaseAddress
+ (ULONG_PTR
)ExportDir
->AddressOfNameOrdinals
);
1835 ((ULONG_PTR
)BaseAddress
+ (ULONG_PTR
)ExportDir
->AddressOfNames
);
1836 for (i
= 0; i
< ExportDir
->NumberOfNames
; i
++, NamePtr
++, OrdinalPtr
++)
1838 if (!_strnicmp(FunctionName
, (char*)(BaseAddress
+ *NamePtr
),
1839 strlen(FunctionName
)))
1841 return (PVOID
)((ULONG_PTR
)BaseAddress
+
1842 (ULONG_PTR
)AddressPtr
[*OrdinalPtr
]);
1845 DPRINT("VideoPortGetProcAddress: Can't resolve symbol %s\n", FunctionName
);
1850 VideoPortQueryPerformanceCounter(
1851 IN PVOID HwDeviceExtension
,
1852 OUT PLONGLONG PerformanceFrequency OPTIONAL
)
1854 LARGE_INTEGER Result
;
1856 DPRINT("VideoPortQueryPerformanceCounter\n");
1857 Result
= KeQueryPerformanceCounter((PLARGE_INTEGER
)PerformanceFrequency
);
1858 return Result
.QuadPart
;