*/
#include "videoprt.h"
-#include "internal/ps.h"
+#include <wdmguid.h>
/* GLOBAL VARIABLES ***********************************************************/
ULONG CsrssInitialized = FALSE;
-PEPROCESS Csrss = NULL;
+PKPROCESS Csrss = NULL;
+ULONG VideoPortDeviceNumber = 0;
/* PRIVATE FUNCTIONS **********************************************************/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath)
return STATUS_SUCCESS;
}
-PVOID STDCALL
+PVOID NTAPI
IntVideoPortImageDirectoryEntryToData(
PVOID BaseAddress,
ULONG Directory)
if (Va == 0)
return NULL;
- return (PVOID)(BaseAddress + Va);
+ return (PVOID)((ULONG_PTR)BaseAddress + Va);
}
-PVOID STDCALL
+PVOID NTAPI
IntVideoPortGetProcAddress(
IN PVOID HwDeviceExtension,
IN PUCHAR FunctionName)
{
- SYSTEM_LOAD_IMAGE GdiDriverInfo;
+ SYSTEM_GDI_DRIVER_INFORMATION GdiDriverInfo;
PVOID BaseAddress;
PIMAGE_EXPORT_DIRECTORY ExportDir;
PUSHORT OrdinalPtr;
DPRINT("VideoPortGetProcAddress(%s)\n", FunctionName);
- RtlInitUnicodeString(&GdiDriverInfo.ModuleName, L"videoprt");
+ RtlInitUnicodeString(&GdiDriverInfo.DriverName, L"videoprt");
Status = ZwSetSystemInformation(
- SystemLoadImage,
+ SystemLoadGdiDriverInformation,
&GdiDriverInfo,
- sizeof(SYSTEM_LOAD_IMAGE));
+ sizeof(SYSTEM_GDI_DRIVER_INFORMATION));
if (!NT_SUCCESS(Status))
{
DPRINT("Couldn't get our own module handle?\n");
return NULL;
}
- BaseAddress = GdiDriverInfo.ModuleBase;
+ BaseAddress = GdiDriverInfo.ImageAddress;
/* Get the pointer to the export directory */
ExportDir = (PIMAGE_EXPORT_DIRECTORY)IntVideoPortImageDirectoryEntryToData(
((ULONG_PTR)BaseAddress + (ULONG_PTR)ExportDir->AddressOfNames);
for (i = 0; i < ExportDir->NumberOfNames; i++, NamePtr++, OrdinalPtr++)
{
- if (!_strnicmp((PCHAR)FunctionName, (PCHAR)(BaseAddress + *NamePtr),
+ if (!_strnicmp((PCHAR)FunctionName, (PCHAR)((ULONG_PTR)BaseAddress + *NamePtr),
strlen((PCHAR)FunctionName)))
{
return (PVOID)((ULONG_PTR)BaseAddress +
return NULL;
}
-VOID STDCALL
+VOID NTAPI
IntVideoPortDeferredRoutine(
IN PKDPC Dpc,
IN PVOID DeferredContext,
((PMINIPORT_DPC_ROUTINE)SystemArgument1)(HwDeviceExtension, SystemArgument2);
}
-ULONG STDCALL
-IntVideoPortAllocateDeviceNumber(VOID)
-{
- NTSTATUS Status;
- ULONG DeviceNumber;
- WCHAR SymlinkBuffer[20];
- UNICODE_STRING SymlinkName;
-
- for (DeviceNumber = 0;;)
- {
- OBJECT_ATTRIBUTES Obj;
- HANDLE ObjHandle;
-
- swprintf(SymlinkBuffer, L"\\??\\DISPLAY%lu", DeviceNumber + 1);
- RtlInitUnicodeString(&SymlinkName, SymlinkBuffer);
- InitializeObjectAttributes(&Obj, &SymlinkName, 0, NULL, NULL);
- Status = ZwOpenSymbolicLinkObject(&ObjHandle, GENERIC_READ, &Obj);
- if (NT_SUCCESS(Status))
- {
- ZwClose(ObjHandle);
- DeviceNumber++;
- continue;
- }
- else if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
- break;
- else
- {
- DPRINT1("ZwOpenSymbolicLinkObject() returned unexpected status: 0x%08lx\n", Status);
- return 0xFFFFFFFF;
- }
- }
-
- return DeviceNumber;
-}
-
-NTSTATUS STDCALL
+NTSTATUS NTAPI
IntVideoPortCreateAdapterDeviceObject(
IN PDRIVER_OBJECT DriverObject,
IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension,
* object names and symlinks.
*/
- DeviceNumber = IntVideoPortAllocateDeviceNumber();
+ DeviceNumber = VideoPortDeviceNumber++;
if (DeviceNumber == 0xFFFFFFFF)
{
DPRINT("Can't find free device number\n");
DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)((*DeviceObject)->DeviceExtension);
DeviceExtension->DeviceNumber = DeviceNumber;
+ DeviceExtension->DriverObject = DriverObject;
DeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
DeviceExtension->FunctionalDeviceObject = *DeviceObject;
DeviceExtension->DriverExtension = DriverExtension;
/* FIXME: we have to detach the device object in IntVideoPortFindAdapter if it fails */
-NTSTATUS STDCALL
+NTSTATUS NTAPI
IntVideoPortFindAdapter(
IN PDRIVER_OBJECT DriverObject,
IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension,
{
ConfigInfo.SystemMemorySize =
SystemBasicInfo.NumberOfPhysicalPages *
- SystemBasicInfo.PhysicalPageSize;
+ SystemBasicInfo.PageSize;
}
/*
}
VOID FASTCALL
-IntAttachToCSRSS(PEPROCESS *CallingProcess, PEPROCESS *PrevAttachedProcess)
+IntAttachToCSRSS(PKPROCESS *CallingProcess, PKAPC_STATE ApcState)
{
- *CallingProcess = PsGetCurrentProcess();
+ *CallingProcess = (PKPROCESS)PsGetCurrentProcess();
if (*CallingProcess != Csrss)
{
- if (PsGetCurrentThread()->ThreadsProcess != *CallingProcess)
- {
- *PrevAttachedProcess = *CallingProcess;
- KeDetachProcess();
- }
- else
- {
- *PrevAttachedProcess = NULL;
- }
- KeAttachProcess(Csrss);
+ KeStackAttachProcess(Csrss, ApcState);
}
}
VOID FASTCALL
-IntDetachFromCSRSS(PEPROCESS *CallingProcess, PEPROCESS *PrevAttachedProcess)
+IntDetachFromCSRSS(PKPROCESS *CallingProcess, PKAPC_STATE ApcState)
{
if (*CallingProcess != Csrss)
{
- KeDetachProcess();
- if (NULL != *PrevAttachedProcess)
- {
- KeAttachProcess(*PrevAttachedProcess);
- }
+ KeUnstackDetachProcess(ApcState);
}
}
* @implemented
*/
-ULONG STDCALL
+ULONG NTAPI
VideoPortInitialize(
IN PVOID Context1,
IN PVOID Context2,
DPRINT("VideoPortInitialize\n");
+ /*
+ * As a first thing do parameter checks.
+ */
+
+ if (HwInitializationData->HwInitDataSize > sizeof(VIDEO_HW_INITIALIZATION_DATA))
+ {
+ return STATUS_REVISION_MISMATCH;
+ }
+
+ if (HwInitializationData->HwFindAdapter == NULL ||
+ HwInitializationData->HwInitialize == NULL ||
+ HwInitializationData->HwStartIO == NULL)
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
/*
* NOTE:
* The driver extension can be already allocated in case that we were
* called by legacy driver and failed detecting device. Some miniport
- * drivers in that case adjust parameters and calls VideoPortInitialize
+ * drivers in that case adjust parameters and call VideoPortInitialize
* again.
*/
{
return Status;
}
+
+ /*
+ * Save the registry path. This should be done only once even if
+ * VideoPortInitialize is called multiple times.
+ */
+
+ if (RegistryPath->Length != 0)
+ {
+ DriverExtension->RegistryPath.Length = 0;
+ DriverExtension->RegistryPath.MaximumLength =
+ RegistryPath->Length + sizeof(UNICODE_NULL);
+ DriverExtension->RegistryPath.Buffer =
+ ExAllocatePoolWithTag(
+ PagedPool,
+ DriverExtension->RegistryPath.MaximumLength,
+ TAG('U', 'S', 'T', 'R'));
+ if (DriverExtension->RegistryPath.Buffer == NULL)
+ {
+ RtlInitUnicodeString(&DriverExtension->RegistryPath, NULL);
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ RtlCopyUnicodeString(&DriverExtension->RegistryPath, RegistryPath);
+ }
+ else
+ {
+ RtlInitUnicodeString(&DriverExtension->RegistryPath, NULL);
+ }
}
/*
RtlCopyMemory(
&DriverExtension->InitializationData,
HwInitializationData,
- min(sizeof(VIDEO_HW_INITIALIZATION_DATA),
- HwInitializationData->HwInitDataSize));
- if (sizeof(VIDEO_HW_INITIALIZATION_DATA) > HwInitializationData->HwInitDataSize)
+ HwInitializationData->HwInitDataSize);
+ if (HwInitializationData->HwInitDataSize <
+ sizeof(VIDEO_HW_INITIALIZATION_DATA))
{
RtlZeroMemory((PVOID)((ULONG_PTR)&DriverExtension->InitializationData +
HwInitializationData->HwInitDataSize),
}
DriverExtension->HwContext = HwContext;
- /* we can't use RtlDuplicateUnicodeString because only ntdll exposes it... */
- if (RegistryPath->Length != 0)
- {
- DriverExtension->RegistryPath.Length = 0;
- DriverExtension->RegistryPath.MaximumLength = RegistryPath->Length + sizeof(UNICODE_NULL);
- DriverExtension->RegistryPath.Buffer = ExAllocatePoolWithTag(PagedPool,
- DriverExtension->RegistryPath.MaximumLength,
- TAG('U', 'S', 'T', 'R'));
- if (DriverExtension->RegistryPath.Buffer == NULL)
- {
- RtlInitUnicodeString(&DriverExtension->RegistryPath, NULL);
- return STATUS_INSUFFICIENT_RESOURCES;
- }
-
- RtlCopyUnicodeString(&DriverExtension->RegistryPath, RegistryPath);
- }
- else
- {
- RtlInitUnicodeString(&DriverExtension->RegistryPath, NULL);
- }
-
switch (HwInitializationData->HwInitDataSize)
{
/*
DriverObject->MajorFunction[IRP_MJ_CREATE] = IntVideoPortDispatchOpen;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = IntVideoPortDispatchClose;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = IntVideoPortDispatchDeviceControl;
+ DriverObject->MajorFunction[IRP_MJ_WRITE] = IntVideoPortDispatchWrite;
DriverObject->DriverUnload = IntVideoPortUnload;
/*
vsprintf(Buffer, DebugMessage, ap);
va_end(ap);
- DbgPrint(Buffer);
+ DbgPrintEx(DPFLTR_IHVVIDEO_ID, DebugPrintLevel, Buffer);
}
/*
* @unimplemented
*/
-VOID STDCALL
+VOID NTAPI
VideoPortLogError(
IN PVOID HwDeviceExtension,
IN PVIDEO_REQUEST_PACKET Vrp OPTIONAL,
* @implemented
*/
-UCHAR STDCALL
+UCHAR NTAPI
VideoPortGetCurrentIrql(VOID)
{
return KeGetCurrentIrql();
PMINIPORT_GET_REGISTRY_ROUTINE HwGetRegistryRoutine;
} QUERY_REGISTRY_CALLBACK_CONTEXT, *PQUERY_REGISTRY_CALLBACK_CONTEXT;
-static NTSTATUS STDCALL
+static NTSTATUS NTAPI
QueryRegistryCallback(
IN PWSTR ValueName,
IN ULONG ValueType,
* @unimplemented
*/
-VP_STATUS STDCALL
+VP_STATUS NTAPI
VideoPortGetRegistryParameters(
IN PVOID HwDeviceExtension,
IN PWSTR ParameterName,
DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
- if (IsParameterFileName)
- {
- UNIMPLEMENTED;
- }
-
Context.HwDeviceExtension = HwDeviceExtension;
Context.HwContext = HwContext;
Context.HwGetRegistryRoutine = GetRegistryRoutine;
QueryTable[1].QueryRoutine = NULL;
QueryTable[1].Name = NULL;
- return NT_SUCCESS(RtlQueryRegistryValues(
+ if (!NT_SUCCESS(RtlQueryRegistryValues(
RTL_REGISTRY_ABSOLUTE,
DeviceExtension->RegistryPath.Buffer,
QueryTable,
&Context,
- NULL)) ? ERROR_SUCCESS : ERROR_INVALID_PARAMETER;
+ NULL)))
+ return ERROR_INVALID_PARAMETER;
+
+ if (IsParameterFileName)
+ {
+ /* FIXME: need to read the contents of the file */
+ UNIMPLEMENTED;
+ }
+
+ return ERROR_SUCCESS;
}
/*
* @implemented
*/
-VP_STATUS STDCALL
+VP_STATUS NTAPI
VideoPortSetRegistryParameters(
IN PVOID HwDeviceExtension,
IN PWSTR ValueName,
* @implemented
*/
-VP_STATUS STDCALL
+VP_STATUS NTAPI
VideoPortGetVgaStatus(
IN PVOID HwDeviceExtension,
OUT PULONG VgaStatus)
* @implemented
*/
-PVOID STDCALL
+PVOID NTAPI
VideoPortGetRomImage(
IN PVOID HwDeviceExtension,
IN PVOID Unused1,
IN ULONG Length)
{
static PVOID RomImageBuffer = NULL;
- PEPROCESS CallingProcess;
- PEPROCESS PrevAttachedProcess;
+ PKPROCESS CallingProcess;
+ KAPC_STATE ApcState;
DPRINT("VideoPortGetRomImage(HwDeviceExtension 0x%X Length 0x%X)\n",
HwDeviceExtension, Length);
return NULL;
}
- IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
+ IntAttachToCSRSS(&CallingProcess, &ApcState);
RtlCopyMemory(RomImageBuffer, (PUCHAR)0xC0000, Length);
- IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
+ IntDetachFromCSRSS(&CallingProcess, &ApcState);
return RomImageBuffer;
}
* @implemented
*/
-BOOLEAN STDCALL
+BOOLEAN NTAPI
VideoPortScanRom(
IN PVOID HwDeviceExtension,
IN PUCHAR RomBase,
* @implemented
*/
-BOOLEAN STDCALL
+BOOLEAN NTAPI
VideoPortSynchronizeExecution(
IN PVOID HwDeviceExtension,
IN VIDEO_SYNCHRONIZE_PRIORITY Priority,
* @implemented
*/
-VP_STATUS STDCALL
+VP_STATUS NTAPI
VideoPortEnumerateChildren(
IN PVOID HwDeviceExtension,
IN PVOID Reserved)
* @unimplemented
*/
-VP_STATUS STDCALL
+VP_STATUS NTAPI
VideoPortCreateSecondaryDisplay(
IN PVOID HwDeviceExtension,
IN OUT PVOID *SecondaryDeviceExtension,
* @implemented
*/
-BOOLEAN STDCALL
+BOOLEAN NTAPI
VideoPortQueueDpc(
IN PVOID HwDeviceExtension,
IN PMINIPORT_DPC_ROUTINE CallbackRoutine,
}
/*
- * @unimplemented
+ * @implemented
*/
-PVOID STDCALL
+PVOID NTAPI
VideoPortGetAssociatedDeviceExtension(IN PVOID DeviceObject)
{
- DPRINT1("VideoPortGetAssociatedDeviceExtension: Unimplemented.\n");
- return NULL;
+ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
+
+ DPRINT("VideoPortGetAssociatedDeviceExtension\n");
+ DeviceExtension = ((PDEVICE_OBJECT)DeviceObject)->DeviceExtension;
+ if (!DeviceExtension)
+ return NULL;
+ return DeviceExtension->MiniPortDeviceExtension;
}
/*
* @implemented
*/
-VP_STATUS STDCALL
+VP_STATUS NTAPI
VideoPortGetVersion(
IN PVOID HwDeviceExtension,
IN OUT PVPOSVERSIONINFO VpOsVersionInfo)
}
/*
- * @unimplemented
+ * @implemented
*/
-BOOLEAN STDCALL
+BOOLEAN NTAPI
VideoPortCheckForDeviceExistence(
IN PVOID HwDeviceExtension,
IN USHORT VendorId,
IN USHORT SubSystemId,
IN ULONG Flags)
{
- DPRINT1("VideoPortCheckForDeviceExistence: Unimplemented.\n");
- return TRUE;
+ PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
+ PCI_DEVICE_PRESENT_INTERFACE PciDevicePresentInterface;
+ IO_STATUS_BLOCK IoStatusBlock;
+ IO_STACK_LOCATION IoStack;
+ ULONG PciFlags = 0;
+ NTSTATUS Status;
+ BOOL DevicePresent;
+
+ DPRINT("VideoPortCheckForDeviceExistence\n");
+
+ if (Flags & ~(CDE_USE_REVISION | CDE_USE_SUBSYSTEM_IDS))
+ {
+ DPRINT1("VideoPortCheckForDeviceExistence: Unknown flags 0x%lx\n", Flags & ~(CDE_USE_REVISION | CDE_USE_SUBSYSTEM_IDS));
+ return FALSE;
+ }
+
+ DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
+
+ PciDevicePresentInterface.Size = sizeof(PCI_DEVICE_PRESENT_INTERFACE);
+ PciDevicePresentInterface.Version = 1;
+ IoStack.Parameters.QueryInterface.Size = PciDevicePresentInterface.Size;
+ IoStack.Parameters.QueryInterface.Version = PciDevicePresentInterface.Version;
+ IoStack.Parameters.QueryInterface.Interface = (PINTERFACE)&PciDevicePresentInterface;
+ IoStack.Parameters.QueryInterface.InterfaceType =
+ &GUID_PCI_DEVICE_PRESENT_INTERFACE;
+ Status = IopInitiatePnpIrp(DeviceExtension->NextDeviceObject,
+ &IoStatusBlock, IRP_MN_QUERY_INTERFACE, &IoStack);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("IopInitiatePnpIrp() failed! (Status 0x%lx)\n", Status);
+ return FALSE;
+ }
+
+ if (Flags & CDE_USE_REVISION)
+ PciFlags |= PCI_USE_REVISION;
+ if (Flags & CDE_USE_SUBSYSTEM_IDS)
+ PciFlags |= PCI_USE_SUBSYSTEM_IDS;
+
+ DevicePresent = PciDevicePresentInterface.IsDevicePresent(
+ VendorId, DeviceId, RevisionId,
+ SubVendorId, SubSystemId, PciFlags);
+
+ PciDevicePresentInterface.InterfaceDereference(PciDevicePresentInterface.Context);
+
+ return DevicePresent;
}
/*
* @unimplemented
*/
-VP_STATUS STDCALL
+VP_STATUS NTAPI
VideoPortRegisterBugcheckCallback(
IN PVOID HwDeviceExtension,
IN ULONG BugcheckCode,
* @implemented
*/
-LONGLONG STDCALL
+LONGLONG NTAPI
VideoPortQueryPerformanceCounter(
IN PVOID HwDeviceExtension,
OUT PLONGLONG PerformanceFrequency OPTIONAL)
* @implemented
*/
-VOID STDCALL
+VOID NTAPI
VideoPortAcquireDeviceLock(
IN PVOID HwDeviceExtension)
{
* @implemented
*/
-VOID STDCALL
+VOID NTAPI
VideoPortReleaseDeviceLock(
IN PVOID HwDeviceExtension)
{
ASSERT(Status == 0);
}
+/*
+ * @unimplemented
+ */
+
+VOID NTAPI
+VpNotifyEaData(
+ IN PDEVICE_OBJECT DeviceObject,
+ IN PVOID Data)
+{
+}