Commit in reactos/drivers/video/videoprt on videoprt_pnp_14032004
dispatch.c+515added 1.1.2.1
dma.c+119added 1.1.2.1
event.c+111added 1.1.2.1
resource.c+709added 1.1.2.1
timer.c+69added 1.1.2.1
Makefile+8-21.3 -> 1.3.2.1
int10.c+42-1031.4 -> 1.4.2.1
interrupt.c+25-31.1 -> 1.1.2.1
services.c+12-151.2 -> 1.2.2.1
spinlock.c+4-41.1 -> 1.1.2.1
videoprt.c+491-16491.21 -> 1.21.2.1
videoprt.h+89-371.6 -> 1.6.2.1
videoprt.rc+2-21.1 -> 1.1.4.1
+2196-1815
5 added + 8 modified, total 13 files
- Started work on converting the VideoPort driver to PnP model.
- Separated the driver into more files.
- Fixed a few bugs.

reactos/drivers/video/videoprt
dispatch.c added at 1.1.2.1
diff -N dispatch.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ dispatch.c	14 Mar 2004 17:16:28 -0000	1.1.2.1
@@ -0,0 +1,515 @@
+/*
+ * VideoPort driver
+ *
+ * Copyright (C) 2002, 2003, 2004 ReactOS Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; see the file COPYING.LIB.
+ * If not, write to the Free Software Foundation,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id: dispatch.c,v 1.1.2.1 2004/03/14 17:16:28 navaraf Exp $
+ */
+
+#include "videoprt.h"
+
+/* GLOBAL VARIABLES ***********************************************************/
+
+PVIDEO_PORT_DEVICE_EXTENSION ResetDisplayParametersDeviceExtension = NULL;
+
+/* PRIVATE FUNCTIONS **********************************************************/
+
+VOID STDCALL
+VideoPortDeferredRoutine(
+   IN PKDPC Dpc,
+   IN PVOID DeferredContext,
+   IN PVOID SystemArgument1,
+   IN PVOID SystemArgument2)
+{
+   PVOID HwDeviceExtension = 
+      ((PVIDEO_PORT_DEVICE_EXTENSION)DeferredContext)->MiniPortDeviceExtension;
+   ((PMINIPORT_DPC_ROUTINE)SystemArgument1)(HwDeviceExtension, SystemArgument2);
+}
+
+/*
+ * Reset display to blue screen
+ */
+
+BOOLEAN STDCALL
+VideoPortResetDisplayParameters(ULONG Columns, ULONG Rows)
+{
+   PVIDEO_PORT_DRIVER_EXTENSION DriverExtension;
+
+   if (ResetDisplayParametersDeviceExtension == NULL)
+      return FALSE;
+
+   DriverExtension = IoGetDriverObjectExtension(
+      ResetDisplayParametersDeviceExtension->FunctionalDeviceObject->DriverObject,
+      ResetDisplayParametersDeviceExtension->FunctionalDeviceObject->DriverObject);
+
+   ASSERT(DriverExtension->InitializationData.HwResetHw != NULL);
+
+   if (!DriverExtension->InitializationData.HwResetHw(
+          ResetDisplayParametersDeviceExtension->MiniPortDeviceExtension,
+          Columns, Rows))
+   {
+      return FALSE;
+   }
+
+   ResetDisplayParametersDeviceExtension = NULL;
+
+   return TRUE;
+}
+
+NTSTATUS STDCALL
+VideoPortAddDevice(
+   IN PDRIVER_OBJECT DriverObject,
+   IN PDEVICE_OBJECT PhysicalDeviceObject)
+{
+   PVIDEO_PORT_DRIVER_EXTENSION DriverExtension;
+   ULONG DeviceNumber;
+   ULONG Size;
+   NTSTATUS Status;
+   VIDEO_PORT_CONFIG_INFO ConfigInfo;
+   SYSTEM_BASIC_INFORMATION SystemBasicInfo;
+   UCHAR Again = FALSE;
+   WCHAR DeviceBuffer[20];
+   UNICODE_STRING DeviceName;
+   WCHAR SymlinkBuffer[20];
+   UNICODE_STRING SymlinkName;
+   PDEVICE_OBJECT DeviceObject;
+   WCHAR DeviceVideoBuffer[20];
+   PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
+
+   /*
+    * Get the initialization data we saved in VideoPortInitialize.
+    */
+
+   DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
+
+   /*
+    * Find the first free device number that can be used for video device
+    * object names and symlinks.
+    */
+
+   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_NOT_FOUND || Status == STATUS_UNSUCCESSFUL)
+         break;
+      else
+         return Status;
+   }
+
+   /*
+    * Initialize the configuration information structures passed
+    * to miniport HwVidFindAdapter.
+    */
+
+   RtlZeroMemory(&ConfigInfo, sizeof(VIDEO_PORT_CONFIG_INFO));
+   ConfigInfo.Length = sizeof(VIDEO_PORT_CONFIG_INFO);
+
+   ConfigInfo.AdapterInterfaceType = 
+      DriverExtension->InitializationData.AdapterInterfaceType;
+
+   if (ConfigInfo.AdapterInterfaceType == PCIBus)
+      ConfigInfo.InterruptMode = LevelSensitive;
+   else
+      ConfigInfo.InterruptMode = Latched;
+
+   ConfigInfo.DriverRegistryPath = DriverExtension->RegistryPath.Buffer;
+   ConfigInfo.VideoPortGetProcAddress = VideoPortGetProcAddress;
+
+   /* Get bus number from the upper level bus driver. */
+   Size = sizeof(ULONG);
+   IoGetDeviceProperty(
+      PhysicalDeviceObject,
+      DevicePropertyBusNumber,
+      Size,
+      &ConfigInfo.SystemIoBusNumber,
+      &Size);
+
+   Size = sizeof(SystemBasicInfo);
+   Status = ZwQuerySystemInformation(
+      SystemBasicInformation,
+      &SystemBasicInfo,
+      Size,
+      &Size);
+
+   if (NT_SUCCESS(Status))
+   {
+      ConfigInfo.SystemMemorySize =
+         SystemBasicInfo.NumberOfPhysicalPages * 
+         SystemBasicInfo.PhysicalPageSize;
+   }
+   
+   /*
+    * The device was found, create the Io device object, symlinks, ...
+    */
+
+   /* Create a unicode device name. */
+   swprintf(DeviceBuffer, L"\\Device\\Video%lu", DeviceNumber);
+   RtlInitUnicodeString(&DeviceName, DeviceBuffer);
+
+   /* Create the device object. */
+   Status = IoCreateDevice(
+      DriverObject,
+      sizeof(VIDEO_PORT_DEVICE_EXTENSION) +
+      DriverExtension->InitializationData.HwDeviceExtensionSize,
+      &DeviceName,
+      FILE_DEVICE_VIDEO,
+      0,
+      TRUE,
+      &DeviceObject);
+
+   if (!NT_SUCCESS(Status))
+   {
+      DPRINT("IoCreateDevice call failed with status 0x%08x\n", Status);
+      return Status;
+   }
+
+   DriverObject->DeviceObject = DeviceObject;
+
+   /* 
+    * Set the buffering strategy here. If you change this, remember
+    * to change VidDispatchDeviceControl too.
+    */
+
+   DeviceObject->Flags |= DO_BUFFERED_IO;
+
+   /*
+    * Initialize device extension.
+    */
+
+   DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+   DeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
+   DeviceExtension->FunctionalDeviceObject = DeviceObject;
+   DeviceExtension->SystemIoBusNumber = ConfigInfo.SystemIoBusNumber;
+   DeviceExtension->AdapterInterfaceType = 
+      DriverExtension->InitializationData.AdapterInterfaceType;
+
+   /* Get bus device address from the upper level bus driver. */
+   Size = sizeof(ULONG);
+   IoGetDeviceProperty(
+      PhysicalDeviceObject,
+      DevicePropertyAddress,
+      Size,
+      &DeviceExtension->SystemIoSlotNumber,
+      &Size);   
+
+   InitializeListHead(&DeviceExtension->AddressMappingListHead);
+   KeInitializeDpc(
+      &DeviceExtension->DpcObject,
+      VideoPortDeferredRoutine,
+      DeviceExtension);
+
+   DeviceExtension->RegistryPath.Length = 
+   DeviceExtension->RegistryPath.MaximumLength = 
+      DriverExtension->RegistryPath.Length + (8 * sizeof(WCHAR));
+   DeviceExtension->RegistryPath.Buffer = ExAllocatePoolWithTag(
+      PagedPool,
+      DeviceExtension->RegistryPath.MaximumLength,
+      TAG_VIDEO_PORT);      
+   swprintf(DeviceExtension->RegistryPath.Buffer, L"%s\\Device0",
+      DriverExtension->RegistryPath.Buffer);
+
+   /*
+    * Call miniport HwVidFindAdapter entry point to detect if
+    * particular device is present.
+    */
+    
+   /* FIXME: Need to figure out what string to pass as param 3. */
+   Status = DriverExtension->InitializationData.HwFindAdapter(
+      &DeviceExtension->MiniPortDeviceExtension,
+      DriverExtension->HwContext,
+      NULL,
+      &ConfigInfo,
+      &Again);
+
+   if (Status != NO_ERROR)
+   {
+      DPRINT("HwFindAdapter call failed with error %X\n", Status);
+      IoDeleteDevice(DeviceObject);
+
+      return Status;
+   }
+
+   /* Create symbolic link "\??\DISPLAYx" */
+   swprintf(SymlinkBuffer, L"\\??\\DISPLAY%lu", DeviceNumber + 1);
+   RtlInitUnicodeString(&SymlinkName, SymlinkBuffer);
+   IoCreateSymbolicLink(&SymlinkName, &DeviceName);
+
+   /* Add entry to DEVICEMAP\VIDEO key in registry. */
+   swprintf(DeviceVideoBuffer, L"\\Device\\Video%d", DeviceNumber);
+   RtlWriteRegistryValue(
+      RTL_REGISTRY_DEVICEMAP,
+      L"VIDEO",
+      DeviceVideoBuffer,
+      REG_SZ,
+      DeviceExtension->RegistryPath.Buffer,
+      DeviceExtension->RegistryPath.Length + sizeof(WCHAR));
+
+   /* FIXME: Allocate hardware resources for device. */
+
+   /*
+    * Allocate interrupt for device.
+    */
+
+   if ((ConfigInfo.BusInterruptVector != 0 ||
+        ConfigInfo.BusInterruptLevel != 0) &&
+       DriverExtension->InitializationData.HwInterrupt != NULL)
+   {
+      ULONG InterruptVector;
+      KIRQL Irql;
+      KAFFINITY Affinity;
+
+      if (ConfigInfo.BusInterruptVector != 0)
+         DeviceExtension->InterruptVector = ConfigInfo.BusInterruptVector;
+
+      if (ConfigInfo.BusInterruptLevel != 0)
+         DeviceExtension->InterruptLevel = ConfigInfo.BusInterruptLevel;
+
+      InterruptVector = HalGetInterruptVector(
+         ConfigInfo.AdapterInterfaceType,
+         ConfigInfo.SystemIoBusNumber,
+         ConfigInfo.BusInterruptLevel,
+         ConfigInfo.BusInterruptVector,
+         &Irql,
+         &Affinity);
+
+      if (InterruptVector == 0)
+      {
+         DPRINT("HalGetInterruptVector failed\n");
+         IoDeleteDevice(DeviceObject);
+         return STATUS_INSUFFICIENT_RESOURCES;
+      }
+
+      KeInitializeSpinLock(&DeviceExtension->InterruptSpinLock);
+      Status = IoConnectInterrupt(
+         &DeviceExtension->InterruptObject,
+         VideoPortInterruptRoutine,
+         DeviceExtension,
+         &DeviceExtension->InterruptSpinLock,
+         InterruptVector,
+         Irql,
+         Irql,
+         ConfigInfo.InterruptMode,
+         FALSE,
+         Affinity,
+         FALSE);
+
+      if (!NT_SUCCESS(Status))
+      {
+         DPRINT("IoConnectInterrupt failed with status 0x%08x\n", Status);
+         IoDeleteDevice(DeviceObject);
+              
+         return Status;
+      }
+   }
+
+   /*
+    * Allocate timer for device.
+    */
+
+   if (DriverExtension->InitializationData.HwTimer != NULL)
+   {
+      DPRINT("Initializing timer\n");
+
+      Status = IoInitializeTimer(
+         DeviceObject,
+         VideoPortTimerRoutine,
+         DeviceExtension);
+
+      if (!NT_SUCCESS(Status))
+      {
+         DPRINT("IoInitializeTimer failed with status 0x%08x\n", Status);
+          
+         if (DriverExtension->InitializationData.HwInterrupt != NULL)
+            IoDisconnectInterrupt(DeviceExtension->InterruptObject);
+
+         IoDeleteDevice(DeviceObject);
+         return Status;
+      }
+   }
+
+   IoAttachDeviceToDeviceStack(DeviceObject, PhysicalDeviceObject);
+
+   return STATUS_SUCCESS;
+}
+
+/*
+ * VideoPortDispatchOpen
+ *
+ * Answer requests for Open calls.
+ *
+ * Run Level
+ *    PASSIVE_LEVEL
+ */
+
+NTSTATUS STDCALL
+VideoPortDispatchOpen(
+   IN PDEVICE_OBJECT DeviceObject,
+   IN PIRP Irp)
+{
+   PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
+   PVIDEO_PORT_DRIVER_EXTENSION DriverExtension;
+
+   DPRINT("VidDispatchOpen\n");
+
+   DriverExtension = IoGetDriverObjectExtension(
+      DeviceObject->DriverObject,
+      DeviceObject->DriverObject);
+   DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+   if (DriverExtension->InitializationData.HwInitialize(DeviceExtension->MiniPortDeviceExtension))
+   {
+      Irp->IoStatus.Status = STATUS_SUCCESS;
+
+      /*
+       * Storing the device extension pointer in a static variable is an
+       * ugly hack. Unfortunately, we need it in VideoPortResetDisplayParameters
+       * and HalAcquireDisplayOwnership doesn't allow us to pass a userdata
+       * parameter. On the bright side, the DISPLAY device is opened
+       * exclusively, so there can be only one device extension active at
+       * any point in time.
+       */
+
+      ResetDisplayParametersDeviceExtension = DeviceExtension;
+      HalAcquireDisplayOwnership(VideoPortResetDisplayParameters);
+   }
+   else
+   {
+      Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
+   }
+
+   Irp->IoStatus.Information = FILE_OPENED;
+   IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+   return STATUS_SUCCESS;
+}
+
+/*
+ * VideoPortDispatchClose
+ *
+ * Answer requests for Close calls.
+ *
+ * Run Level
+ *    PASSIVE_LEVEL
+ */
+
+NTSTATUS STDCALL
+VideoPortDispatchClose(
+   IN PDEVICE_OBJECT DeviceObject,
+   IN PIRP Irp)
+{
+   DPRINT("VidDispatchClose\n");
+
+   HalReleaseDisplayOwnership();
+
+   Irp->IoStatus.Status = STATUS_SUCCESS;
+   IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+   return STATUS_SUCCESS;
+}
+
+/*
+ * VidDispatchDeviceControl
+ *
+ * Answer requests for device control calls.
+ *
+ * Run Level
+ *    PASSIVE_LEVEL
+ */
+
+NTSTATUS STDCALL
+VideoPortDispatchDeviceControl(
+   IN PDEVICE_OBJECT DeviceObject,
+   IN PIRP Irp)
+{
+   PIO_STACK_LOCATION IrpStack;
+   PVIDEO_PORT_DRIVER_EXTENSION DriverExtension;
+   PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
+   PVIDEO_REQUEST_PACKET vrp;
+
+   DPRINT("VidDispatchDeviceControl\n");
+   IrpStack = IoGetCurrentIrpStackLocation(Irp);
+   DeviceExtension = DeviceObject->DeviceExtension;
+   DriverExtension = IoGetDriverObjectExtension(
+      DeviceObject->DriverObject,
+      DeviceObject->DriverObject);
+
+   /* Translate the IRP to a VRP */
+   vrp = ExAllocatePool(NonPagedPool, sizeof(VIDEO_REQUEST_PACKET));
+   if (NULL == vrp)
+   {
+      return STATUS_NO_MEMORY;
+   }
+
+   vrp->StatusBlock = (PSTATUS_BLOCK) &(Irp->IoStatus);
+   vrp->IoControlCode = IrpStack->Parameters.DeviceIoControl.IoControlCode;
+
+   DPRINT("- IoControlCode: %x\n", vrp->IoControlCode);
+
+   /* We're assuming METHOD_BUFFERED */
+   vrp->InputBuffer = Irp->AssociatedIrp.SystemBuffer;
+   vrp->InputBufferLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength;
+   vrp->OutputBuffer = Irp->AssociatedIrp.SystemBuffer;
+   vrp->OutputBufferLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength;
+
+   /* Call the Miniport Driver with the VRP */
+   DriverExtension->InitializationData.HwStartIO(
+      (PVOID)&DeviceExtension->MiniPortDeviceExtension,
+      vrp);
+
+   /* Free the VRP */
+   ExFreePool(vrp);
+
+   DPRINT("- Returned status: %x\n", Irp->IoStatus.Status);
+
+   IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+   return STATUS_SUCCESS;
+}
+
+NTSTATUS STDCALL
+VideoPortDispatchPnp(
+   IN PDEVICE_OBJECT DeviceObject,
+   IN PIRP Irp)
+{
+   return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS STDCALL
+VideoPortDispatchPower(
+   IN PDEVICE_OBJECT DeviceObject,
+   IN PIRP Irp)
+{
+   return STATUS_NOT_IMPLEMENTED;
+}
+
+VOID STDCALL
+VideoPortUnload(PDRIVER_OBJECT DriverObject)
+{
+   UnmapVideoAddressSpace();
+}

reactos/drivers/video/videoprt
dma.c added at 1.1.2.1
diff -N dma.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ dma.c	14 Mar 2004 17:16:28 -0000	1.1.2.1
@@ -0,0 +1,119 @@
+/*
+ * VideoPort driver
+ *
+ * Copyright (C) 2002, 2003, 2004 ReactOS Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; see the file COPYING.LIB.
+ * If not, write to the Free Software Foundation,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id: dma.c,v 1.1.2.1 2004/03/14 17:16:28 navaraf Exp $
+ */
+
+#include "videoprt.h"
+
+/* PUBLIC FUNCTIONS ***********************************************************/
+
+/*
+ * @implemented
+ */
+
+PVOID STDCALL
+VideoPortAllocateCommonBuffer(
+   IN PVOID HwDeviceExtension,
+   IN PVP_DMA_ADAPTER VpDmaAdapter,
+   IN ULONG DesiredLength,
+   OUT PPHYSICAL_ADDRESS LogicalAddress,
+   IN BOOLEAN CacheEnabled,
+   PVOID Reserved)
+{
+   return HalAllocateCommonBuffer(
+      (PADAPTER_OBJECT)VpDmaAdapter,
+      DesiredLength,
+      LogicalAddress,
+      CacheEnabled);
+}
+
+/*
+ * @implemented
+ */
+
+VOID STDCALL
+VideoPortReleaseCommonBuffer(
+   IN PVOID HwDeviceExtension,
+   IN PVP_DMA_ADAPTER VpDmaAdapter,
+   IN ULONG Length,
+   IN PHYSICAL_ADDRESS LogicalAddress,
+   IN PVOID VirtualAddress,
+   IN BOOLEAN CacheEnabled)
+{
+   HalFreeCommonBuffer(
+      (PADAPTER_OBJECT)VpDmaAdapter,
+      Length,
+      LogicalAddress,
+      VirtualAddress,
+      CacheEnabled);
+}
+
+/*
+ * @unimplemented
+ */
+
+VOID STDCALL
+VideoPortPutDmaAdapter(
+   IN PVOID HwDeviceExtension,
+   IN PVP_DMA_ADAPTER VpDmaAdapter)
+{
+   DPRINT("VideoPortPutDmaAdapter: Unimplemented.\n");
+}
+
+/*
+ * @unimplemented
+ */
+
+PVP_DMA_ADAPTER STDCALL
+VideoPortGetDmaAdapter(
+   IN PVOID HwDeviceExtension,
+   IN PVP_DEVICE_DESCRIPTION VpDeviceExtension)
+{
+   DEVICE_DESCRIPTION DeviceDescription;
+   PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
+   ULONG NumberOfMapRegisters;
+   PVP_DMA_ADAPTER Adapter;
+
+   DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
+
+   DPRINT("VideoPortGetDmaAdapter\n");
+  
+   DeviceDescription.Version = DEVICE_DESCRIPTION_VERSION;
+   DeviceDescription.Master = TRUE /* ?? */;
+   DeviceDescription.ScatterGather = VpDeviceExtension->ScatterGather;
+   DeviceDescription.DemandMode = FALSE /* ?? */;
+   DeviceDescription.AutoInitialize = FALSE /* ?? */;
+   DeviceDescription.Dma32BitAddresses = VpDeviceExtension->Dma32BitAddresses;
+   DeviceDescription.IgnoreCount = FALSE /* ?? */;
+   DeviceDescription.Reserved1 = FALSE;
+   DeviceDescription.BusNumber = DeviceExtension->SystemIoBusNumber;
+   DeviceDescription.DmaChannel = 0 /* ?? */;
+   DeviceDescription.InterfaceType = DeviceExtension->AdapterInterfaceType;
+   DeviceDescription.DmaWidth = Width8Bits;
+   DeviceDescription.DmaSpeed = Compatible;
+   DeviceDescription.MaximumLength = VpDeviceExtension->MaximumLength;
+   DeviceDescription.DmaPort = 0;
+
+   Adapter = 
+      (PVP_DMA_ADAPTER)HalGetAdapter(&DeviceDescription, &NumberOfMapRegisters);
+   DPRINT("Adapter %X\n", Adapter);
+   return(Adapter);
+}

reactos/drivers/video/videoprt
event.c added at 1.1.2.1
diff -N event.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ event.c	14 Mar 2004 17:16:28 -0000	1.1.2.1
@@ -0,0 +1,111 @@
+/*
+ * VideoPort driver
+ *
+ * Copyright (C) 2002, 2003, 2004 ReactOS Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; see the file COPYING.LIB.
+ * If not, write to the Free Software Foundation,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id: event.c,v 1.1.2.1 2004/03/14 17:16:28 navaraf Exp $
+ */
+
+#include "videoprt.h"
+
+/* PUBLIC FUNCTIONS ***********************************************************/
+
+/*
+ * @implemented
+ */
+
+VP_STATUS STDCALL
+VideoPortCreateEvent(
+   IN PVOID HwDeviceExtension,
+   IN ULONG EventFlag,
+   IN PVOID Unused,
+   OUT PEVENT *Event)
+{
+   EVENT_TYPE Type;
+ 
+   (*Event) = ExAllocatePoolWithTag(
+      NonPagedPool,
+      sizeof(KEVENT), 
+      TAG_VIDEO_PORT);
+
+   if ((*Event) == NULL)
+      return ERROR_NOT_ENOUGH_MEMORY;
+
+   if (EventFlag & NOTIFICATION_EVENT)
+      Type = NotificationEvent;
+   else
+      Type = SynchronizationEvent;
+
+   KeInitializeEvent((PKEVENT)*Event, Type, EventFlag & INITIAL_EVENT_SIGNALED);
+   return NO_ERROR;
+}
+
+/*
+ * @implemented
+ */
+
+VP_STATUS STDCALL
+VideoPortDeleteEvent(
+   IN PVOID HwDeviceExtension,
+   IN PEVENT Event)
+{
+   ExFreePool(Event);
+   return NO_ERROR;
+}
+
+/*
+ * @implemented
+ */
+
+LONG STDCALL
+VideoPortSetEvent(
+   IN PVOID HwDeviceExtension,
+   IN PEVENT Event)
+{
+   return KeSetEvent((PKEVENT)Event, IO_NO_INCREMENT, FALSE);
+}
+
+/*
+ * @implemented
+ */
+
+VOID STDCALL
+VideoPortClearEvent(
+   IN PVOID HwDeviceExtension,
+   IN PEVENT Event)
+{
+   KeClearEvent((PKEVENT)Event);
+}
+
+/*
+ * @implemented
+ */
+
+VP_STATUS STDCALL
+VideoPortWaitForSingleObject(
+   IN PVOID HwDeviceExtension,
+   IN PVOID Object,
+   IN PLARGE_INTEGER Timeout OPTIONAL)
+{
+   return KeWaitForSingleObject(
+      Object,
+      Executive,
+      KernelMode,
+      FALSE,
+      Timeout);
+}

reactos/drivers/video/videoprt
resource.c added at 1.1.2.1
diff -N resource.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ resource.c	14 Mar 2004 17:16:28 -0000	1.1.2.1
@@ -0,0 +1,709 @@
+/*
+ * VideoPort driver
+ *
+ * Copyright (C) 2002, 2003, 2004 ReactOS Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; see the file COPYING.LIB.
+ * If not, write to the Free Software Foundation,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id: resource.c,v 1.1.2.1 2004/03/14 17:16:28 navaraf Exp $
+ */
+
+#include "videoprt.h"
+
+/* PRIVATE FUNCTIONS **********************************************************/
+
+/*
+ * MapVideoAddressSpace
+ *
+ * This function maps the BIOS memory into our virtual address space and
+ * setups real-mode interrupt table.
+ */
+
+BOOL FASTCALL
+MapVideoAddressSpace(VOID)
+{
+   NTSTATUS Status;
+   PVOID BaseAddress;
+   PVOID NullAddress;
+   ULONG ViewSize;
+   CHAR IVT[1024];
+   CHAR BDA[256];
+   LARGE_INTEGER Offset;
+   OBJECT_ATTRIBUTES ObjectAttributes;
+   UNICODE_STRING PhysMemName;
+   HANDLE PhysMemHandle;
+
+   /*
+    * Open the physical memory section
+    */
+
+   RtlInitUnicodeString(&PhysMemName, L"\\Device\\PhysicalMemory");
+   InitializeObjectAttributes(&ObjectAttributes, &PhysMemName, 0, NULL, NULL);
+   Status = ZwOpenSection(&PhysMemHandle, SECTION_ALL_ACCESS, &ObjectAttributes);
+   if (!NT_SUCCESS(Status))
+   {
+      DPRINT(("VBEMP: Couldn't open \\Device\\PhysicalMemory\n"));
+      return FALSE;
+   }
+
+   /*
+    * Map the BIOS and device registers into the address space
+    */
+
+   Offset.QuadPart = 0xa0000;
+   ViewSize = 0x30000;
+   BaseAddress = (PVOID)0xa0000;
+   Status = ZwMapViewOfSection(PhysMemHandle, NtCurrentProcess(), &BaseAddress,
+      0, 8192, &Offset, &ViewSize, ViewUnmap, 0, PAGE_EXECUTE_READWRITE);
+
+   if (!NT_SUCCESS(Status))
+   {
+      DPRINT("Couldn't map physical memory (%x)\n", Status);
+      NtClose(PhysMemHandle);
+      return FALSE;
+   }
+
+   NtClose(PhysMemHandle);
+
+   if (BaseAddress != (PVOID)0xa0000)
+   {
+      DPRINT("Couldn't map physical memory at the right address "
+              "(was %x)\n", BaseAddress);
+      return FALSE;
+   }
+
+   /*
+    * Map some memory to use for the non-BIOS parts of the v86 mode address
+    * space
+    */
+
+   BaseAddress = (PVOID)0x1;
+   ViewSize = 0x20000;
+   Status = ZwAllocateVirtualMemory(
+      NtCurrentProcess(),
+      &BaseAddress,
+      0,
+      &ViewSize,
+      MEM_COMMIT,
+      PAGE_EXECUTE_READWRITE);
+
+   if (!NT_SUCCESS(Status))
+   {
+      DPRINT("Failed to allocate virtual memory (Status %x)\n", Status);
+      return FALSE;
+   }
+
+   if (BaseAddress != (PVOID)0x0)
+   {
+      DPRINT("Failed to allocate virtual memory at right address "
+             "(was %x)\n", BaseAddress);
+      return FALSE;
+   }
+
+   /*
+    * Get the real mode IVT from the kernel
+    */
+
+   Status = NtVdmControl(0, IVT);
+   if (!NT_SUCCESS(Status))
+   {
+      DPRINT("NtVdmControl failed (status %x)\n", Status);
+      return 0;
+   }
+   
+   /*
+    * Copy the real mode IVT into the right place
+    */
+
+   NullAddress = (PVOID)0x0; /* Workaround for GCC 3.4 */
+   RtlCopyMemory(NullAddress, IVT, 1024);
+   
+   /*
+    * Get the BDA from the kernel
+    */
+
+   Status = NtVdmControl(1, BDA);
+   if (!NT_SUCCESS(Status))
+   {
+      DPRINT("NtVdmControl failed (status %x)\n", Status);
+      return FALSE;
+   }
+   
+   /*
+    * Copy the BDA into the right place
+    */
+
+   RtlCopyMemory((PVOID)0x400, BDA, 256);
+
+   return TRUE;
+}
+
+/*
+ * UnmapVideoAddressSpace
+ *
+ * This function unmaps the BIOS memory from our virtual address space that
+ * was mapped by MapVideoAddressSpace.
+ */
+
+VOID FASTCALL
+UnmapVideoAddressSpace(VOID)
+{
+   /* FIXME */
+   DPRINT1("UnmapVideoAddressSpace: Unimplemented.\n");
+}
+
+PVOID STDCALL
+InternalMapMemory(
+   IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension,
+   IN PHYSICAL_ADDRESS IoAddress,
+   IN ULONG NumberOfUchars,
+   IN UCHAR InIoSpace,
+   OUT VP_STATUS *Status)
+{
+   PHYSICAL_ADDRESS TranslatedAddress;
+   PVIDEO_PORT_ADDRESS_MAPPING AddressMapping;
+   ULONG AddressSpace;
+   PVOID MappedAddress;
+   PLIST_ENTRY Entry;
+
+   DPRINT("- IoAddress: %lx\n", IoAddress.u.LowPart);
+   DPRINT("- NumberOfUchars: %lx\n", NumberOfUchars);
+   DPRINT("- InIoSpace: %x\n", InIoSpace);
+
+   InIoSpace &= ~VIDEO_MEMORY_SPACE_DENSE;
+   if ((InIoSpace & VIDEO_MEMORY_SPACE_P6CACHE) != 0)
+   {
+      DPRINT("VIDEO_MEMORY_SPACE_P6CACHE not supported, turning off\n");
+      InIoSpace &= ~VIDEO_MEMORY_SPACE_P6CACHE;
+   }
+
+   if (!IsListEmpty(&DeviceExtension->AddressMappingListHead))
+   {
+      Entry = DeviceExtension->AddressMappingListHead.Flink;
+      while (Entry != &DeviceExtension->AddressMappingListHead)
+      {
+         AddressMapping = CONTAINING_RECORD(
+            Entry,
+            VIDEO_PORT_ADDRESS_MAPPING,
+            List);
+         if (IoAddress.QuadPart == AddressMapping->IoAddress.QuadPart &&
+             NumberOfUchars <= AddressMapping->NumberOfUchars)
+         {
+            AddressMapping->MappingCount++;
+            if (Status)
+               *Status = NO_ERROR;
+
+            return AddressMapping->MappedAddress;
+         }
+         Entry = Entry->Flink;
+      }
+   }
+
+   AddressSpace = (ULONG)InIoSpace;
+   if (HalTranslateBusAddress(
+          DeviceExtension->AdapterInterfaceType,
+          DeviceExtension->SystemIoBusNumber,
+          IoAddress,
+          &AddressSpace,
+          &TranslatedAddress) == FALSE)
+   {
+      if (Status)
+         *Status = ERROR_NOT_ENOUGH_MEMORY;
+
+      return NULL;
+   }
+
+   /* I/O space */
+   if (AddressSpace != 0)
+   {
+      ASSERT(0 == TranslatedAddress.u.HighPart);
+      if (Status)
+         *Status = NO_ERROR;
+
+      return (PVOID)TranslatedAddress.u.LowPart;
+   }
+
+   MappedAddress = MmMapIoSpace(
+      TranslatedAddress,
+      NumberOfUchars,
+      FALSE);
+
+   if (MappedAddress)
+   {
+      if (Status)
+      {
+         *Status = NO_ERROR;
+      }
+
+      AddressMapping = ExAllocatePoolWithTag(
+         PagedPool,
+         sizeof(VIDEO_PORT_ADDRESS_MAPPING),
+         TAG_VIDEO_PORT);
+
+      if (AddressMapping == NULL)
+         return MappedAddress;
+
+      AddressMapping->MappedAddress = MappedAddress;
+      AddressMapping->NumberOfUchars = NumberOfUchars;
+      AddressMapping->IoAddress = IoAddress;
+      AddressMapping->SystemIoBusNumber = DeviceExtension->SystemIoBusNumber;
+      AddressMapping->MappingCount = 1;
+
+      InsertHeadList(
+         &DeviceExtension->AddressMappingListHead,
+         &AddressMapping->List);
+
+      return MappedAddress;
+   }
+   else
+   {
+      if (Status)
+         *Status = NO_ERROR;
+
+      return NULL;
+   }
+}
+
+VOID STDCALL
+InternalUnmapMemory(
+   IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension,
+   IN PVOID MappedAddress)
+{
+   PVIDEO_PORT_ADDRESS_MAPPING AddressMapping;
+   PLIST_ENTRY Entry;
+
+   Entry = DeviceExtension->AddressMappingListHead.Flink;
+   while (Entry != &DeviceExtension->AddressMappingListHead)
+   {
+      AddressMapping = CONTAINING_RECORD(
+         Entry,
+         VIDEO_PORT_ADDRESS_MAPPING,
+         List);
+      if (AddressMapping->MappedAddress == MappedAddress)
+      {
+         ASSERT(AddressMapping->MappingCount >= 0);
+         AddressMapping->MappingCount--;
+         if (AddressMapping->MappingCount == 0)
+         {
+            MmUnmapIoSpace(
+               AddressMapping->MappedAddress,
+               AddressMapping->NumberOfUchars);
+            RemoveEntryList(Entry);
+            ExFreePool(AddressMapping);
+
+            return;
+         }
+      }
+
+      Entry = Entry->Flink;
+   }
+}
+
+/* PUBLIC FUNCTIONS ***********************************************************/
+
+/*
+ * @implemented
+ */
+
+PVOID STDCALL
+VideoPortGetDeviceBase(
+   IN PVOID HwDeviceExtension,
+   IN PHYSICAL_ADDRESS IoAddress,
+   IN ULONG NumberOfUchars,
+   IN UCHAR InIoSpace)
+{
+   DPRINT("VideoPortGetDeviceBase\n");
+   return InternalMapMemory(
+      VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
+      IoAddress,
+      NumberOfUchars,
+      InIoSpace,
+      NULL);
+}
+
+/*
+ * @implemented
+ */
+
+VOID STDCALL
+VideoPortFreeDeviceBase(
+   IN PVOID HwDeviceExtension, 
+   IN PVOID MappedAddress)
+{
+   DPRINT("VideoPortFreeDeviceBase\n");
+   InternalUnmapMemory(
+      VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
+      MappedAddress);
+}
+
+/*
+ * @unimplemented
+ */
+
+VP_STATUS STDCALL
+VideoPortMapBankedMemory(
+   IN PVOID HwDeviceExtension,
+   IN PHYSICAL_ADDRESS PhysicalAddress,
+   IN PULONG Length,
+   IN PULONG InIoSpace,
+   OUT PVOID *VirtualAddress,
+   IN ULONG BankLength,
+   IN UCHAR ReadWriteBank,
+   IN PBANKED_SECTION_ROUTINE BankRoutine,
+   IN PVOID Context)
+{
+   DPRINT("VideoPortMapBankedMemory\n");
+   UNIMPLEMENTED;
+   return ERROR_CALL_NOT_IMPLEMENTED;
+}
+
+
+/*
+ * @implemented
+ */
+VP_STATUS STDCALL
+VideoPortMapMemory(
+   IN PVOID HwDeviceExtension,
+   IN PHYSICAL_ADDRESS PhysicalAddress,
+   IN PULONG Length,
+   IN PULONG InIoSpace,
+   OUT PVOID *VirtualAddress)
+{
+   PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
+   NTSTATUS Status;
+
+   DPRINT("VideoPortMapMemory\n");
+
+   DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
+   *VirtualAddress = InternalMapMemory(
+      DeviceExtension,
+      PhysicalAddress,
+      *Length,
+      *InIoSpace,
+      &Status);
+
+   return Status;
+}
+
+/*
+ * @implemented
+ */
+
+VP_STATUS STDCALL
+VideoPortUnmapMemory(
+   IN PVOID HwDeviceExtension,
+   IN PVOID VirtualAddress,
+   IN HANDLE ProcessHandle)
+{
+   DPRINT("VideoPortFreeDeviceBase\n");
+
+   InternalUnmapMemory(
+      VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension),
+      VirtualAddress);
+
+   return NO_ERROR;
+}
+
+/*
+ * @implemented
+ */
+
+VP_STATUS STDCALL
+VideoPortGetAccessRanges(
+   IN PVOID HwDeviceExtension,
+   IN ULONG NumRequestedResources,
+   IN PIO_RESOURCE_DESCRIPTOR RequestedResources OPTIONAL,
+   IN ULONG NumAccessRanges,
+   IN PVIDEO_ACCESS_RANGE AccessRanges,
+   IN PVOID VendorId,
+   IN PVOID DeviceId,
+   IN PULONG Slot)
+{
+   PCI_SLOT_NUMBER PciSlotNumber;
+   ULONG FunctionNumber;
+   PCI_COMMON_CONFIG Config;
+   PCM_RESOURCE_LIST AllocatedResources;
+   NTSTATUS Status;
+   UINT AssignedCount;
+   CM_FULL_RESOURCE_DESCRIPTOR *FullList;
+   CM_PARTIAL_RESOURCE_DESCRIPTOR *Descriptor;
+   PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
+   USHORT VendorIdToFind;
+   USHORT DeviceIdToFind;
+   ULONG SlotIdToFind;
+
+   DPRINT("VideoPortGetAccessRanges\n");
+
+   DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
+
+   if (NumRequestedResources == 0 && 
+       DeviceExtension->AdapterInterfaceType == PCIBus)
+   {
+      VendorIdToFind = VendorId != NULL ? *(PUSHORT)VendorId : 0;
+      DeviceIdToFind = DeviceId != NULL ? *(PUSHORT)DeviceId : 0;
+      SlotIdToFind = Slot != NULL ? *Slot : DeviceExtension->SystemIoSlotNumber;
+
+      DPRINT("Looking for VendorId 0x%04x DeviceId 0x%04x SlotId 0x%04x\n", 
+	     VendorIdToFind, DeviceIdToFind, SlotIdToFind);
+
+      PciSlotNumber.u.AsULONG = SlotIdToFind;
+
+      /*
+       * Search for the device id and vendor id on this bus.
+       */
+
+      for (FunctionNumber = 0; FunctionNumber < 8; FunctionNumber++)
+      {
+         ULONG ReturnedLength;
+
+         DPRINT("- Function number: %d\n", FunctionNumber);
+         PciSlotNumber.u.bits.FunctionNumber = FunctionNumber;
+         ReturnedLength = HalGetBusData(
+            PCIConfiguration, 
+            DeviceExtension->SystemIoBusNumber,
+            PciSlotNumber.u.AsULONG,
+            &Config,
+            sizeof(PCI_COMMON_CONFIG));
+         DPRINT("- Length of data: %x\n", ReturnedLength);
+         if (ReturnedLength == sizeof(PCI_COMMON_CONFIG))
+         {
+            DPRINT("- Slot 0x%02x (Device %d Function %d) VendorId 0x%04x "
+                   "DeviceId 0x%04x\n",
+                   PciSlotNumber.u.AsULONG, 
+                   PciSlotNumber.u.bits.DeviceNumber,
+                   PciSlotNumber.u.bits.FunctionNumber,
+                   Config.VendorID,
+                   Config.DeviceID);
+
+            if ((VendorIdToFind == 0 || Config.VendorID == VendorIdToFind) &&
+                (DeviceIdToFind == 0 || Config.DeviceID == DeviceIdToFind))
+            {
+               break;
+            }
+         }
+      }
+
+      if (FunctionNumber == 8)
+      {
+         DPRINT("Didn't find device.\n");
+         return ERROR_NO_SYSTEM_RESOURCES;
+      }
+
+      Status = HalAssignSlotResources(
+         NULL, NULL, NULL, NULL,
+         DeviceExtension->AdapterInterfaceType,
+         DeviceExtension->SystemIoBusNumber,
+         PciSlotNumber.u.AsULONG, 
+         &AllocatedResources);
+
+      if (!NT_SUCCESS(Status))
+      {
+         return Status;
+      }
+
+      AssignedCount = 0;
+      for (FullList = AllocatedResources->List;
+           FullList < AllocatedResources->List + AllocatedResources->Count;
+           FullList++)
+      {
+         ASSERT(FullList->InterfaceType == PCIBus &&
+                FullList->BusNumber == DeviceExtension->SystemIoBusNumber &&
+                1 == FullList->PartialResourceList.Version &&
+                1 == FullList->PartialResourceList.Revision);
+	 for (Descriptor = FullList->PartialResourceList.PartialDescriptors;
+              Descriptor < FullList->PartialResourceList.PartialDescriptors + FullList->PartialResourceList.Count;
+              Descriptor++)
+         {
+            if ((Descriptor->Type == CmResourceTypeMemory ||
+                 Descriptor->Type == CmResourceTypePort) &&
+                AssignedCount >= NumAccessRanges)
+            {
+               DPRINT1("Too many access ranges found\n");
+               ExFreePool(AllocatedResources);
+               return ERROR_NO_SYSTEM_RESOURCES;
+            }
+            if (Descriptor->Type == CmResourceTypeMemory)
+            {
+               if (NumAccessRanges <= AssignedCount)
+               {
+                  DPRINT1("Too many access ranges found\n");
+                  ExFreePool(AllocatedResources);
+                  return ERROR_NO_SYSTEM_RESOURCES;
+               }
+               DPRINT("Memory range starting at 0x%08x length 0x%08x\n",
+                      Descriptor->u.Memory.Start.u.LowPart, Descriptor->u.Memory.Length);
+               AccessRanges[AssignedCount].RangeStart = Descriptor->u.Memory.Start;
+               AccessRanges[AssignedCount].RangeLength = Descriptor->u.Memory.Length;
+               AccessRanges[AssignedCount].RangeInIoSpace = 0;
+               AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
+               AccessRanges[AssignedCount].RangeShareable =
+                  (Descriptor->ShareDisposition == CmResourceShareShared);
+               AssignedCount++;
+            }
+            else if (Descriptor->Type == CmResourceTypePort)
+            {
+               DPRINT("Port range starting at 0x%04x length %d\n",
+                      Descriptor->u.Memory.Start.u.LowPart, Descriptor->u.Memory.Length);
+               AccessRanges[AssignedCount].RangeStart = Descriptor->u.Port.Start;
+               AccessRanges[AssignedCount].RangeLength = Descriptor->u.Port.Length;
+               AccessRanges[AssignedCount].RangeInIoSpace = 1;
+               AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
+               AccessRanges[AssignedCount].RangeShareable = 0;
+               AssignedCount++;
+            }
+            else if (Descriptor->Type == CmResourceTypeInterrupt)
+            {
+               DeviceExtension->InterruptLevel = Descriptor->u.Interrupt.Level;
+               DeviceExtension->InterruptVector = Descriptor->u.Interrupt.Vector;
+            }
+         }
+      }
+      ExFreePool(AllocatedResources);
+   }
+   else
+   {
+      UNIMPLEMENTED
+   }
+
+   return NO_ERROR;
+}
+
+/*
+ * @unimplemented
+ */
+
+VP_STATUS STDCALL
+VideoPortVerifyAccessRanges(
+   IN PVOID HwDeviceExtension,
+   IN ULONG NumAccessRanges,
+   IN PVIDEO_ACCESS_RANGE AccessRanges)
+{
+   DPRINT1("VideoPortVerifyAccessRanges not implemented\n");
+   return NO_ERROR;
+}
+
+/*
+ * @unimplemented
+ */
+
+VP_STATUS STDCALL
+VideoPortGetDeviceData(
+   IN PVOID HwDeviceExtension,
+   IN VIDEO_DEVICE_DATA_TYPE DeviceDataType,
+   IN PMINIPORT_QUERY_DEVICE_ROUTINE CallbackRoutine,
+   IN PVOID Context)
+{
+   DPRINT("VideoPortGetDeviceData\n");
+   UNIMPLEMENTED;
+   return ERROR_CALL_NOT_IMPLEMENTED;
+}
+
+/*
+ * @implemented
+ */
+
+PVOID STDCALL
+VideoPortAllocatePool(
+   IN PVOID HwDeviceExtension,
+   IN VP_POOL_TYPE PoolType,
+   IN SIZE_T NumberOfBytes,
+   IN ULONG Tag)
+{
+   DPRINT("VideoPortAllocatePool\n");
+   return ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag);
+}
+
+/*
+ * @implemented
+ */
+
+VOID STDCALL
+VideoPortFreePool(
+   IN PVOID HwDeviceExtension,
+   IN PVOID Ptr)
+{
+   ExFreePool(Ptr);
+}
+
+/*
+ * @implemented
+ */
+
+VP_STATUS STDCALL
+VideoPortAllocateBuffer(
+   IN PVOID HwDeviceExtension,
+   IN ULONG Size,
+   OUT PVOID *Buffer)
+{
+   DPRINT("VideoPortAllocateBuffer\n");  
+   *Buffer = ExAllocatePool(PagedPool, Size);
+   return *Buffer == NULL ? ERROR_NOT_ENOUGH_MEMORY : NO_ERROR;
+}
+
+/*
+ * @implemented
+ */
+
+VOID STDCALL
+VideoPortReleaseBuffer(
+   IN PVOID HwDeviceExtension,
+   IN PVOID Ptr)
+{
+   DPRINT("VideoPortReleaseBuffer\n");
+   ExFreePool(Ptr);
+}         
+
+/*
+ * @unimplemented
+ */
+
+PVOID STDCALL
+VideoPortLockBuffer(
+   IN PVOID HwDeviceExtension,
+   IN PVOID BaseAddress,
+   IN ULONG Length,
+   IN VP_LOCK_OPERATION Operation)
+{
+   DPRINT1("VideoPortLockBuffer: Unimplemented.\n");
+   return NULL;
+}
+
+/*
+ * @unimplemented
+ */
+
+VOID STDCALL
+VideoPortUnlockBuffer(
+   IN PVOID HwDeviceExtension,
+   IN PVOID Mdl)
+{
+   DPRINT1("VideoPortUnlockBuffer: Unimplemented.\n");
+}
+
+/*
+ * @unimplemented
+ */
+
+VP_STATUS STDCALL
+VideoPortSetTrappedEmulatorPorts(
+   IN PVOID HwDeviceExtension,
+   IN ULONG NumAccessRanges,
+   IN PVIDEO_ACCESS_RANGE AccessRange)
+{
+   DPRINT("VideoPortSetTrappedEmulatorPorts\n");
+   /* Should store the ranges in the device extension for use by ntvdm. */
+   return NO_ERROR;
+}

reactos/drivers/video/videoprt
timer.c added at 1.1.2.1
diff -N timer.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ timer.c	14 Mar 2004 17:16:28 -0000	1.1.2.1
@@ -0,0 +1,69 @@
+/*
+ * VideoPort driver
+ *
+ * Copyright (C) 2002, 2003, 2004 ReactOS Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; see the file COPYING.LIB.
+ * If not, write to the Free Software Foundation,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id: timer.c,v 1.1.2.1 2004/03/14 17:16:28 navaraf Exp $
+ */
+
+#include "videoprt.h"
+
+/* PRIVATE FUNCTIONS **********************************************************/
+
+VOID STDCALL
+VideoPortTimerRoutine(
+   IN PDEVICE_OBJECT DeviceObject,
+   IN PVOID ServiceContext)
+{
+   PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = ServiceContext;
+   PVIDEO_PORT_DRIVER_EXTENSION DriverExtension;
+
+   DriverExtension = IoGetDriverObjectExtension(
+      DeviceExtension->FunctionalDeviceObject->DriverObject,
+      DeviceExtension->FunctionalDeviceObject->DriverObject);
+  
+   ASSERT(DriverExtension->InitializationData.HwTimer != NULL);
+
+   DriverExtension->InitializationData.HwTimer(
+      DeviceExtension->MiniPortDeviceExtension);
+}
+
+/* PUBLIC FUNCTIONS ***********************************************************/
+
+/*
+ * @implemented
+ */
+
+VOID STDCALL
+VideoPortStartTimer(IN PVOID  HwDeviceExtension)
+{
+   DPRINT("VideoPortStartTimer\n");
+   IoStartTimer(VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension)->FunctionalDeviceObject);
+}
+
+
+/*
+ * @implemented
+ */
+
+VOID STDCALL
+VideoPortStopTimer(IN PVOID  HwDeviceExtension)
+{
+   DPRINT("VideoPortStopTimer\n");
+   IoStopTimer(VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension)->FunctionalDeviceObject);
+}

reactos/drivers/video/videoprt
Makefile 1.3 -> 1.3.2.1
diff -u -r1.3 -r1.3.2.1
--- Makefile	9 Mar 2004 17:28:49 -0000	1.3
+++ Makefile	14 Mar 2004 17:16:28 -0000	1.3.2.1
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.3 2004/03/09 17:28:49 navaraf Exp $
+# $Id: Makefile,v 1.3.2.1 2004/03/14 17:16:28 navaraf Exp $
 
 PATH_TO_TOP = ../../..
 
@@ -9,11 +9,17 @@
 TARGET_CFLAGS += -Wall -Werror -D__USE_W32API -I$(PATH_TO_TOP)/ntoskrnl/include
 
 TARGET_OBJECTS = \
+	dispatch.o \
+	dma.o \
+	event.o \
 	int10.o \
 	interrupt.o \
 	videoprt.o \
+	resource.o \
 	services.o \
-	spinlock.o
+	spinlock.o \
+	timer.o
+
 
 include $(PATH_TO_TOP)/rules.mak
 

reactos/drivers/video/videoprt
int10.c 1.4 -> 1.4.2.1
diff -u -r1.4 -r1.4.2.1
--- int10.c	8 Mar 2004 21:45:39 -0000	1.4
+++ int10.c	14 Mar 2004 17:16:28 -0000	1.4.2.1
@@ -18,84 +18,13 @@
  * If not, write to the Free Software Foundation,
  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * $Id: int10.c,v 1.4 2004/03/08 21:45:39 navaraf Exp $
+ * $Id: int10.c,v 1.4.2.1 2004/03/14 17:16:28 navaraf Exp $
  */
 
 #include "videoprt.h"
 #include "internal/v86m.h"
 
-VOID FASTCALL
-IntAttachToCSRSS(PEPROCESS *CallingProcess, PEPROCESS *PrevAttachedProcess)
-{
-   *CallingProcess = PsGetCurrentProcess();
-   if (*CallingProcess != Csrss)
-   {
-      if (NULL != PsGetCurrentThread()->OldProcess)
-      {
-         *PrevAttachedProcess = *CallingProcess;
-         KeDetachProcess();
-      }
-      else
-      {
-         *PrevAttachedProcess = NULL;
-      }
-      KeAttachProcess(Csrss);
-   }
-}
-
-VOID FASTCALL
-IntDetachFromCSRSS(PEPROCESS *CallingProcess, PEPROCESS *PrevAttachedProcess)
-{
-   if (*CallingProcess != Csrss)
-   {
-      KeDetachProcess();
-      if (NULL != *PrevAttachedProcess)
-      {
-         KeAttachProcess(*PrevAttachedProcess);
-      }
-   }
-}
-
-
-/*
- * @implemented
- */
-
-VP_STATUS STDCALL
-VideoPortInt10(
-   IN PVOID HwDeviceExtension,
-   IN PVIDEO_X86_BIOS_ARGUMENTS BiosArguments)
-{
-   KV86M_REGISTERS Regs;
-   NTSTATUS Status;
-   PEPROCESS CallingProcess;
-   PEPROCESS PrevAttachedProcess;
-
-   DPRINT("VideoPortInt10\n");
-
-   IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
-
-   memset(&Regs, 0, sizeof(Regs));
-   DPRINT("- Input register Eax: %x\n", BiosArguments->Eax);
-   Regs.Eax = BiosArguments->Eax;
-   DPRINT("- Input register Ebx: %x\n", BiosArguments->Ebx);
-   Regs.Ebx = BiosArguments->Ebx;
-   DPRINT("- Input register Ecx: %x\n", BiosArguments->Ecx);
-   Regs.Ecx = BiosArguments->Ecx;
-   DPRINT("- Input register Edx: %x\n", BiosArguments->Edx);
-   Regs.Edx = BiosArguments->Edx;
-   DPRINT("- Input register Esi: %x\n", BiosArguments->Esi);
-   Regs.Esi = BiosArguments->Esi;
-   DPRINT("- Input register Edi: %x\n", BiosArguments->Edi);
-   Regs.Edi = BiosArguments->Edi;
-   DPRINT("- Input register Ebp: %x\n", BiosArguments->Ebp);
-   Regs.Ebp = BiosArguments->Ebp;
-   Status = Ke386CallBios(0x10, &Regs);
-
-   IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
-
-   return Status;
-}
+/* PRIVATE FUNCTIONS **********************************************************/
 
 VP_STATUS STDCALL
 IntInt10AllocateBuffer(
@@ -106,27 +35,23 @@
 {
    PVOID MemoryAddress;
    NTSTATUS Status;
-   PEPROCESS CallingProcess;
-   PEPROCESS PrevAttachedProcess;
 
    DPRINT("IntInt10AllocateBuffer\n");
 
-   IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
-
    MemoryAddress = (PVOID)0x20000;
    Status = ZwAllocateVirtualMemory(NtCurrentProcess(), &MemoryAddress, 0,
       Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    if (!NT_SUCCESS(Status))
    {
       DPRINT("- ZwAllocateVirtualMemory failed\n");
-      return STATUS_NO_MEMORY;
+      return ERROR_NOT_ENOUGH_MEMORY;
    }
    if (MemoryAddress > (PVOID)(0x100000 - *Length))
    {
       ZwFreeVirtualMemory(NtCurrentProcess(), &MemoryAddress, Length,
          MEM_RELEASE);
       DPRINT("- Unacceptable memory allocated\n");
-      return STATUS_NO_MEMORY;
+      return ERROR_NOT_ENOUGH_MEMORY;
    }
 
    *Seg = (ULONG)MemoryAddress >> 4;
@@ -136,9 +61,7 @@
    DPRINT("- Offset: %x\n", (ULONG)MemoryAddress & 0xFF);
    DPRINT("- Length: %x\n", *Length);
 
-   IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
-
-   return STATUS_SUCCESS;
+   return NO_ERROR;
 }
 
 VP_STATUS STDCALL
@@ -149,17 +72,13 @@
 {
    PVOID MemoryAddress = (PVOID)((Seg << 4) + Off);
    NTSTATUS Status;
-   PEPROCESS CallingProcess;
-   PEPROCESS PrevAttachedProcess;
 
    DPRINT("IntInt10FreeBuffer\n");
    DPRINT("- Segment: %x\n", Seg);
    DPRINT("- Offset: %x\n", Off);
 
-   IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
    Status = ZwFreeVirtualMemory(NtCurrentProcess(), &MemoryAddress, 0,
       MEM_RELEASE);
-   IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
 
    return Status;
 }
@@ -172,20 +91,15 @@
    OUT PVOID Buffer,
    IN ULONG Length)
 {
-   PEPROCESS CallingProcess;
-   PEPROCESS PrevAttachedProcess;
-
    DPRINT("IntInt10ReadMemory\n");
    DPRINT("- Segment: %x\n", Seg);
    DPRINT("- Offset: %x\n", Off);
    DPRINT("- Buffer: %x\n", Buffer);
    DPRINT("- Length: %x\n", Length);
 
-   IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
    RtlCopyMemory(Buffer, (PVOID)((Seg << 4) + Off), Length);
-   IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
 
-   return STATUS_SUCCESS;
+   return NO_ERROR;
 }
 
 VP_STATUS STDCALL
@@ -196,20 +110,15 @@
    IN PVOID Buffer,
    IN ULONG Length)
 {
-   PEPROCESS CallingProcess;
-   PEPROCESS PrevAttachedProcess;
-
    DPRINT("IntInt10WriteMemory\n");
    DPRINT("- Segment: %x\n", Seg);
    DPRINT("- Offset: %x\n", Off);
    DPRINT("- Buffer: %x\n", Buffer);
    DPRINT("- Length: %x\n", Length);
 
-   IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
    RtlCopyMemory((PVOID)((Seg << 4) + Off), Buffer, Length);
-   IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
 
-   return STATUS_SUCCESS;
+   return NO_ERROR;
 }
 
 VP_STATUS STDCALL
@@ -219,13 +128,9 @@
 {
    KV86M_REGISTERS Regs;
    NTSTATUS Status;
-   PEPROCESS CallingProcess;
-   PEPROCESS PrevAttachedProcess;
 
    DPRINT("IntInt10CallBios\n");
 
-   IntAttachToCSRSS(&CallingProcess, &PrevAttachedProcess);
-
    memset(&Regs, 0, sizeof(Regs));
    DPRINT("- Input register Eax: %x\n", BiosArguments->Eax);
    Regs.Eax = BiosArguments->Eax;
@@ -256,7 +161,41 @@
    BiosArguments->SegDs = Regs.Ds;
    BiosArguments->SegEs = Regs.Es;
 
-   IntDetachFromCSRSS(&CallingProcess, &PrevAttachedProcess);
+   return Status;
+}
+
+/* PUBLIC FUNCTIONS ***********************************************************/
+
+/*
+ * @implemented
+ */
+
+VP_STATUS STDCALL
+VideoPortInt10(
+   IN PVOID HwDeviceExtension,
+   IN PVIDEO_X86_BIOS_ARGUMENTS BiosArguments)
+{
+   KV86M_REGISTERS Regs;
+   NTSTATUS Status;
+
+   DPRINT("VideoPortInt10\n");
+
+   memset(&Regs, 0, sizeof(Regs));
+   DPRINT("- Input register Eax: %x\n", BiosArguments->Eax);
+   Regs.Eax = BiosArguments->Eax;
+   DPRINT("- Input register Ebx: %x\n", BiosArguments->Ebx);
+   Regs.Ebx = BiosArguments->Ebx;
+   DPRINT("- Input register Ecx: %x\n", BiosArguments->Ecx);
+   Regs.Ecx = BiosArguments->Ecx;
+   DPRINT("- Input register Edx: %x\n", BiosArguments->Edx);
+   Regs.Edx = BiosArguments->Edx;
+   DPRINT("- Input register Esi: %x\n", BiosArguments->Esi);
+   Regs.Esi = BiosArguments->Esi;
+   DPRINT("- Input register Edi: %x\n", BiosArguments->Edi);
+   Regs.Edi = BiosArguments->Edi;
+   DPRINT("- Input register Ebp: %x\n", BiosArguments->Ebp);
+   Regs.Ebp = BiosArguments->Ebp;
+   Status = Ke386CallBios(0x10, &Regs);
 
    return Status;
 }

reactos/drivers/video/videoprt
interrupt.c 1.1 -> 1.1.2.1
diff -u -r1.1 -r1.1.2.1
--- interrupt.c	4 Mar 2004 18:51:58 -0000	1.1
+++ interrupt.c	14 Mar 2004 17:16:28 -0000	1.1.2.1
@@ -18,11 +18,33 @@
  * If not, write to the Free Software Foundation,
  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * $Id: interrupt.c,v 1.1 2004/03/04 18:51:58 navaraf Exp $
+ * $Id: interrupt.c,v 1.1.2.1 2004/03/14 17:16:28 navaraf Exp $
  */
 
 #include "videoprt.h"
 
+/* PRIVATE FUNCTIONS **********************************************************/
+
+BOOLEAN STDCALL
+VideoPortInterruptRoutine(
+   IN struct _KINTERRUPT *Interrupt,
+   IN PVOID ServiceContext)
+{
+   PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = ServiceContext;
+   PVIDEO_PORT_DRIVER_EXTENSION DriverExtension;
+
+   DriverExtension = IoGetDriverObjectExtension(
+      DeviceExtension->FunctionalDeviceObject->DriverObject,
+      DeviceExtension->FunctionalDeviceObject->DriverObject);
+  
+   ASSERT(DriverExtension->InitializationData.HwInterrupt != NULL);
+
+   return DriverExtension->InitializationData.HwInterrupt(
+      DeviceExtension->MiniPortDeviceExtension);
+}
+
+/* PUBLIC FUNCTIONS ***********************************************************/
+
 /*
  * @implemented
  */
@@ -45,7 +67,7 @@
       0,
       DeviceExtension->InterruptLevel);
 
-   return Status ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
+   return Status ? NO_ERROR : ERROR_INVALID_ACCESS;
 }
 
 /*
@@ -69,5 +91,5 @@
       DeviceExtension->InterruptVector,
       0);
 
-   return Status ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
+   return Status ? NO_ERROR : ERROR_INVALID_ACCESS;
 }

reactos/drivers/video/videoprt
services.c 1.2 -> 1.2.2.1
diff -u -r1.2 -r1.2.2.1
--- services.c	6 Mar 2004 08:39:06 -0000	1.2
+++ services.c	14 Mar 2004 17:16:28 -0000	1.2.2.1
@@ -18,7 +18,7 @@
  * If not, write to the Free Software Foundation,
  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * $Id: services.c,v 1.2 2004/03/06 08:39:06 jimtabor Exp $
+ * $Id: services.c,v 1.2.2.1 2004/03/14 17:16:28 navaraf Exp $
  */
 
 #include "videoprt.h"
@@ -35,8 +35,7 @@
    /* Do nothing */
 }
 
-VP_STATUS
-STDCALL
+VP_STATUS STDCALL
 VideoPortQueryServices(
   IN PVOID HwDeviceExtension,
   IN VIDEO_PORT_SERVICES ServicesType,
@@ -58,32 +57,30 @@
             Int10Interface->Int10ReadMemory = IntInt10ReadMemory;
             Int10Interface->Int10WriteMemory = IntInt10WriteMemory;
             Int10Interface->Int10CallBios = IntInt10CallBios;
-            return STATUS_SUCCESS;
+            return NO_ERROR;
          }
          break;
 
       case VideoPortServicesAGP:
       case VideoPortServicesI2C:
       case VideoPortServicesHeadless:
-         return STATUS_NOT_IMPLEMENTED;
+         return ERROR_CALL_NOT_IMPLEMENTED;
 
       default:
          break;
    }
 
-   return STATUS_UNSUCCESSFUL;
+   return ERROR_INVALID_FUNCTION;
 }
 
-
-BOOLEAN
-STDCALL
-VideoPortGetAgpServices(IN  PVOID  HwDeviceExtension,
-			IN  PVIDEO_PORT_AGP_SERVICES  AgpServices)
+BOOLEAN STDCALL
+VideoPortGetAgpServices(
+   IN PVOID HwDeviceExtension,
+   IN PVIDEO_PORT_AGP_SERVICES AgpServices)
 {
-
-  DPRINT("VideoPortGetAgpServices\n");
-  UNIMPLEMENTED;
-  return FALSE;
+   DPRINT("VideoPortGetAgpServices\n");
+   UNIMPLEMENTED;
+   return FALSE;
 }
 
 

reactos/drivers/video/videoprt
spinlock.c 1.1 -> 1.1.2.1
diff -u -r1.1 -r1.1.2.1
--- spinlock.c	9 Mar 2004 17:28:49 -0000	1.1
+++ spinlock.c	14 Mar 2004 17:16:28 -0000	1.1.2.1
@@ -18,7 +18,7 @@
  * If not, write to the Free Software Foundation,
  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * $Id: spinlock.c,v 1.1 2004/03/09 17:28:49 navaraf Exp $
+ * $Id: spinlock.c,v 1.1.2.1 2004/03/14 17:16:28 navaraf Exp $
  */
 
 #include "videoprt.h"
@@ -35,9 +35,9 @@
    DPRINT("VideoPortCreateSpinLock\n");   
    *SpinLock = ExAllocatePool(NonPagedPool, sizeof(KSPIN_LOCK));
    if (*SpinLock == NULL)
-      return STATUS_UNSUCCESSFUL;
+      return ERROR_NOT_ENOUGH_MEMORY;
    KeInitializeSpinLock((PKSPIN_LOCK)*SpinLock);
-   return STATUS_SUCCESS;
+   return NO_ERROR;
 }
 
 /*
@@ -51,7 +51,7 @@
 {
    DPRINT("VideoPortDeleteSpinLock\n");
    ExFreePool(SpinLock);
-   return STATUS_SUCCESS;
+   return NO_ERROR;
 }
 
 /*

reactos/drivers/video/videoprt
videoprt.c 1.21 -> 1.21.2.1
diff -u -r1.21 -r1.21.2.1
--- videoprt.c	13 Mar 2004 00:41:40 -0000	1.21
+++ videoprt.c	14 Mar 2004 17:16:28 -0000	1.21.2.1
@@ -18,1372 +18,544 @@
  * If not, write to the Free Software Foundation,
  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * $Id: videoprt.c,v 1.21 2004/03/13 00:41:40 dwelch Exp $
+ * $Id: videoprt.c,v 1.21.2.1 2004/03/14 17:16:28 navaraf Exp $
  */
 
 #include "videoprt.h"
 
-BOOLEAN CsrssInitialized = FALSE;
-PEPROCESS Csrss = NULL;
-PVIDEO_PORT_DEVICE_EXTENSION ResetDisplayParametersDeviceExtension = NULL;
-static PVOID RomImageBuffer = NULL;
-
-VOID STDCALL STATIC
-VideoPortDeferredRoutine(
-   IN PKDPC Dpc,
-   IN PVOID DeferredContext,
-   IN PVOID SystemArgument1,
-   IN PVOID SystemArgument2
-   );
-PVOID STDCALL
-VideoPortGetProcAddress(IN PVOID HwDeviceExtension,
-			IN PUCHAR FunctionName);
-
-//  -------------------------------------------------------  Public Interface
-
-//    DriverEntry
-//
-//  DESCRIPTION:
-//    This function initializes the driver.
-//
-//  RUN LEVEL:
-//    PASSIVE_LEVEL
-//
-//  ARGUMENTS:
-//    IN  PDRIVER_OBJECT   DriverObject  System allocated Driver Object
-//                                       for this driver
-//    IN  PUNICODE_STRING  RegistryPath  Name of registry driver service 
-//                                       key
-//
-//  RETURNS:
-//    NTSTATUS  
+/* PRIVATE FUNCTIONS **********************************************************/
 
 NTSTATUS STDCALL
-DriverEntry(IN PDRIVER_OBJECT DriverObject,
-            IN PUNICODE_STRING RegistryPath)
+DriverEntry(
+   IN PDRIVER_OBJECT DriverObject,
+   IN PUNICODE_STRING RegistryPath)
 {
-  DPRINT("DriverEntry()\n");
-  return(STATUS_SUCCESS);
+   return STATUS_SUCCESS;
 }
 
-/*
- * @implemented
- */
-VOID
-VideoPortDebugPrint(IN VIDEO_DEBUG_LEVEL DebugPrintLevel,
-                    IN PCHAR DebugMessage, ...)
+PVOID STDCALL
+VideoPortImageDirectoryEntryToData(
+   PVOID BaseAddress,
+   ULONG Directory)
 {
-	char Buffer[256];
-	va_list ap;
-
-/*
-	if (DebugPrintLevel > InternalDebugLevel)
-		return;
-*/
-	va_start (ap, DebugMessage);
-	vsprintf (Buffer, DebugMessage, ap);
-	va_end (ap);
-
-	DbgPrint (Buffer);
+   PIMAGE_NT_HEADERS NtHeader;
+   ULONG Va;
+  
+   NtHeader = RtlImageNtHeader(BaseAddress);
+   if (NtHeader == NULL)
+      return NULL;
+  
+   if (Directory >= NtHeader->OptionalHeader.NumberOfRvaAndSizes)
+      return NULL;
+  
+   Va = NtHeader->OptionalHeader.DataDirectory[Directory].VirtualAddress;
+   if (Va == 0)
+      return NULL;
+  
+   return (PVOID)(BaseAddress + Va);
 }
 
-
-/*
- * @implemented
- */
-VOID 
-STDCALL
-VideoPortFreeDeviceBase(IN PVOID  HwDeviceExtension, 
-                        IN PVOID  MappedAddress)
+PVOID STDCALL
+VideoPortGetProcAddress(
+   IN PVOID HwDeviceExtension,
+   IN PUCHAR FunctionName)
 {
-  PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
-
-  DPRINT("VideoPortFreeDeviceBase\n");
+   SYSTEM_LOAD_IMAGE GdiDriverInfo;
+   PVOID BaseAddress;
+   PIMAGE_EXPORT_DIRECTORY ExportDir;
+   PUSHORT OrdinalPtr;
+   PULONG NamePtr;
+   PULONG AddressPtr;
+   ULONG i = 0;
+   NTSTATUS Status;
+
+   DPRINT("VideoPortGetProcAddress(%s)\n", FunctionName);
+
+   RtlInitUnicodeString(&GdiDriverInfo.ModuleName, L"videoprt");
+   Status = ZwSetSystemInformation(
+      SystemLoadImage,
+      &GdiDriverInfo, 
+      sizeof(SYSTEM_LOAD_IMAGE));
+   if (!NT_SUCCESS(Status))
+   {
+      DPRINT("Couldn't get our own module handle?\n");
+      return NULL;
+   }
 
-  DeviceExtension = CONTAINING_RECORD(HwDeviceExtension,
-				      VIDEO_PORT_DEVICE_EXTENSION,
-				      MiniPortDeviceExtension);
+   BaseAddress = GdiDriverInfo.ModuleBase;
 
-  InternalUnmapMemory(DeviceExtension, MappedAddress);
-}
+   /* Get the pointer to the export directory */
+   ExportDir = (PIMAGE_EXPORT_DIRECTORY)VideoPortImageDirectoryEntryToData(
+      BaseAddress,
+      IMAGE_DIRECTORY_ENTRY_EXPORT);
+
+   /* Search by name */
+   AddressPtr = (PULONG)
+      ((ULONG_PTR)BaseAddress + (ULONG_PTR)ExportDir->AddressOfFunctions);
+   OrdinalPtr = (PUSHORT)
+      ((ULONG_PTR)BaseAddress + (ULONG_PTR)ExportDir->AddressOfNameOrdinals);
+   NamePtr = (PULONG)
+      ((ULONG_PTR)BaseAddress + (ULONG_PTR)ExportDir->AddressOfNames);
+   for (i = 0; i < ExportDir->NumberOfNames; i++, NamePtr++, OrdinalPtr++)
+   {
+      if (!_strnicmp(FunctionName, (char*)(BaseAddress + *NamePtr),
+                     strlen(FunctionName)))
+      {
+         return (PVOID)((ULONG_PTR)BaseAddress + 
+                        (ULONG_PTR)AddressPtr[*OrdinalPtr]);	  
+      }
+   }
 
+   DPRINT("VideoPortGetProcAddress: Can't resolve symbol %s\n", FunctionName);
 
-/*
- * @implemented
- */
-ULONG 
-STDCALL
-VideoPortGetBusData(IN PVOID  HwDeviceExtension,
-                    IN BUS_DATA_TYPE  BusDataType,
-                    IN ULONG  SlotNumber,
-                    OUT PVOID  Buffer,
-                    IN ULONG  Offset,
-                    IN ULONG  Length)
-{
-  PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
-
-  DPRINT("VideoPortGetBusData\n");
-
-  DeviceExtension = CONTAINING_RECORD(HwDeviceExtension,
-				      VIDEO_PORT_DEVICE_EXTENSION,
-				      MiniPortDeviceExtension);
-
-  return HalGetBusDataByOffset(BusDataType, 
-                               DeviceExtension->SystemIoBusNumber, 
-                               SlotNumber, 
-                               Buffer, 
-                               Offset, 
-                               Length);
+   return NULL;
 }
 
+/* PUBLIC FUNCTIONS ***********************************************************/
 
 /*
  * @implemented
  */
-UCHAR 
-STDCALL
-VideoPortGetCurrentIrql(VOID)
-{
-  return KeGetCurrentIrql();
-}
-
 
-/*
- * @implemented
- */
-PVOID 
-STDCALL
-VideoPortGetDeviceBase(IN PVOID  HwDeviceExtension,
-                       IN PHYSICAL_ADDRESS  IoAddress,
-                       IN ULONG  NumberOfUchars,
-                       IN UCHAR  InIoSpace)
-{
-  PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
-
-  DPRINT("VideoPortGetDeviceBase\n");
-
-  DeviceExtension = CONTAINING_RECORD(HwDeviceExtension,
-				      VIDEO_PORT_DEVICE_EXTENSION,
-				      MiniPortDeviceExtension);
+ULONG STDCALL
+VideoPortInitialize(
+   IN PVOID Context1,
+   IN PVOID Context2,
+   IN PVIDEO_HW_INITIALIZATION_DATA HwInitializationData,
+   IN PVOID HwContext)
+{
+   PDRIVER_OBJECT DriverObject = Context1;
+   PUNICODE_STRING RegistryPath = Context2;
+   NTSTATUS Status;
+   PVIDEO_PORT_DRIVER_EXTENSION DriverExtension;
 
-  return InternalMapMemory(DeviceExtension, IoAddress, NumberOfUchars, InIoSpace, NULL);
-}
+   DPRINT("VideoPortInitialize\n");
 
+   DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
+   if (DriverExtension != NULL)
+   {
+      DPRINT1(
+         "Oops, we were called twice to initialize the driver. This propably\n"
+         "means that we were loaded by legacy driver, so we have to fallback\n"
+         "to the old driver detection paradigm. Unfortunetly this case isn't\n"
+         "implemented yet.");
 
-/*
- * @unimplemented
- */
-VP_STATUS 
-STDCALL
-VideoPortGetDeviceData(IN PVOID  HwDeviceExtension,
-                       IN VIDEO_DEVICE_DATA_TYPE  DeviceDataType,
-                       IN PMINIPORT_QUERY_DEVICE_ROUTINE  CallbackRoutine,
-                       IN PVOID Context)
-{
-  DPRINT("VideoPortGetDeviceData\n");
-  UNIMPLEMENTED;
-  return STATUS_NOT_IMPLEMENTED;
-}
+      return STATUS_UNSUCCESSFUL;
+   }
 
+   if (!MapVideoAddressSpace())
+   {
+      return STATUS_UNSUCCESSFUL;
+   }
 
-/*
- * @implemented
- */
-VP_STATUS 
-STDCALL
-VideoPortGetAccessRanges(IN PVOID  HwDeviceExtension,
-                         IN ULONG  NumRequestedResources,
-                         IN PIO_RESOURCE_DESCRIPTOR  RequestedResources OPTIONAL,
-                         IN ULONG  NumAccessRanges,
-                         IN PVIDEO_ACCESS_RANGE  AccessRanges,
-                         IN PVOID  VendorId,
-                         IN PVOID  DeviceId,
-                         IN PULONG  Slot)
-{
-  PCI_SLOT_NUMBER PciSlotNumber;
-  ULONG FunctionNumber;
-  PCI_COMMON_CONFIG Config;
-  PCM_RESOURCE_LIST AllocatedResources;
-  NTSTATUS Status;
-  UINT AssignedCount;
-  CM_FULL_RESOURCE_DESCRIPTOR *FullList;
-  CM_PARTIAL_RESOURCE_DESCRIPTOR *Descriptor;
-  PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
-  USHORT VendorIdToFind;
-  USHORT DeviceIdToFind;
-  ULONG SlotIdToFind;
-
-  DPRINT("VideoPortGetAccessRanges\n");
-
-  DeviceExtension = CONTAINING_RECORD(HwDeviceExtension,
-				      VIDEO_PORT_DEVICE_EXTENSION,
-				      MiniPortDeviceExtension);
-
-  if (0 == NumRequestedResources && 
-      PCIBus == DeviceExtension->AdapterInterfaceType)
-    {
-      VendorIdToFind = VendorId != NULL ? *(PUSHORT)VendorId : 0;
-      DeviceIdToFind = DeviceId != NULL ? *(PUSHORT)DeviceId : 0;
-      SlotIdToFind = Slot != NULL ? *Slot : 0;
+   Status = IoAllocateDriverObjectExtension(
+      DriverObject,
+      DriverObject,
+      sizeof(VIDEO_PORT_DRIVER_EXTENSION),
+      (PVOID *)&DriverExtension);
 
-      DPRINT("Looking for VendorId 0x%04x DeviceId 0x%04x SlotId 0x%04x\n", 
-	     VendorIdToFind, DeviceIdToFind, SlotIdToFind);
+   if (!NT_SUCCESS(Status))
+   {
+      return Status;
+   }
 
-      PciSlotNumber.u.AsULONG = SlotIdToFind;
+   RtlCopyMemory(
+      &DriverExtension->InitializationData,
+      HwInitializationData,
+      sizeof(VIDEO_HW_INITIALIZATION_DATA));
+   DriverExtension->HwContext = HwContext;
 
-      /*
-	Search for the device id and vendor id on this bus.
-      */
-      for (FunctionNumber = 0; FunctionNumber < 8; FunctionNumber++)
-	{
-	  ULONG ReturnedLength;
-	  DPRINT("- Function number: %d\n", FunctionNumber);
-	  PciSlotNumber.u.bits.FunctionNumber = FunctionNumber;
-	  ReturnedLength = HalGetBusData(PCIConfiguration, 
-					 DeviceExtension->SystemIoBusNumber,
-					 PciSlotNumber.u.AsULONG,
-					 &Config,
-					 sizeof(PCI_COMMON_CONFIG));
-	  DPRINT("- Length of data: %x\n", ReturnedLength);
-	  if (sizeof(PCI_COMMON_CONFIG) == ReturnedLength)
-	    {
-              DPRINT("- Slot 0x%02x (Device %d Function %d) VendorId 0x%04x "
-                     "DeviceId 0x%04x\n",
-                     PciSlotNumber.u.AsULONG, 
-                     PciSlotNumber.u.bits.DeviceNumber,
-                     PciSlotNumber.u.bits.FunctionNumber,
-                     Config.VendorID,
-                     Config.DeviceID);
-
-	      if ((VendorIdToFind == 0 || Config.VendorID == VendorIdToFind) &&
-		  (DeviceIdToFind == 0 || Config.DeviceID == DeviceIdToFind))
-		{
-		  break;
-		}
-	    }
-	}
-      if (FunctionNumber == 8)
-	{
-	  DPRINT("Didn't find device.\n");
-	  return STATUS_UNSUCCESSFUL;
-	}
-
-      Status = HalAssignSlotResources(NULL, NULL, NULL, NULL,
-                                      DeviceExtension->AdapterInterfaceType,
-                                      DeviceExtension->SystemIoBusNumber,
-                                      PciSlotNumber.u.AsULONG, 
-				      &AllocatedResources);
-      if (! NT_SUCCESS(Status))
-	{
-	  return Status;
-	}
-      AssignedCount = 0;
-      for (FullList = AllocatedResources->List;
-           FullList < AllocatedResources->List + AllocatedResources->Count;
-           FullList++)
-	{
-	  assert(FullList->InterfaceType == PCIBus &&
-	         FullList->BusNumber == DeviceExtension->SystemIoBusNumber &&
-	         1 == FullList->PartialResourceList.Version &&
-	         1 == FullList->PartialResourceList.Revision);
-	  for (Descriptor = FullList->PartialResourceList.PartialDescriptors;
-	       Descriptor < FullList->PartialResourceList.PartialDescriptors + FullList->PartialResourceList.Count;
-	       Descriptor++)
-	    {
-              if ((CmResourceTypeMemory == Descriptor->Type
-                   || CmResourceTypePort == Descriptor->Type)
-                  && NumAccessRanges <= AssignedCount)
-		{
-                  DPRINT1("Too many access ranges found\n");
-                  ExFreePool(AllocatedResources);
-                  return STATUS_UNSUCCESSFUL;
-                }
-	      if (CmResourceTypeMemory == Descriptor->Type)
-		{
-                  if (NumAccessRanges <= AssignedCount)
-                    {
-                      DPRINT1("Too many access ranges found\n");
-                      ExFreePool(AllocatedResources);
-                      return STATUS_UNSUCCESSFUL;
-                    }
-		  DPRINT("Memory range starting at 0x%08x length 0x%08x\n",
-		         Descriptor->u.Memory.Start.u.LowPart, Descriptor->u.Memory.Length);
-		  AccessRanges[AssignedCount].RangeStart = Descriptor->u.Memory.Start;
-		  AccessRanges[AssignedCount].RangeLength = Descriptor->u.Memory.Length;
-		  AccessRanges[AssignedCount].RangeInIoSpace = 0;
-		  AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
-		  AccessRanges[AssignedCount].RangeShareable =
-		    (CmResourceShareShared == Descriptor->ShareDisposition);
-		  AssignedCount++;
-		}
-	      else if (CmResourceTypePort == Descriptor->Type)
-		{
-		  DPRINT("Port range starting at 0x%04x length %d\n",
-		         Descriptor->u.Memory.Start.u.LowPart, Descriptor->u.Memory.Length);
-		  AccessRanges[AssignedCount].RangeStart = Descriptor->u.Port.Start;
-		  AccessRanges[AssignedCount].RangeLength = Descriptor->u.Port.Length;
-		  AccessRanges[AssignedCount].RangeInIoSpace = 1;
-		  AccessRanges[AssignedCount].RangeVisible = 0; /* FIXME: Just guessing */
-		  AccessRanges[AssignedCount].RangeShareable = 0;
-		  AssignedCount++;
-		}
-              else if (CmResourceTypeInterrupt == Descriptor->Type)
-                {
-                  DeviceExtension->InterruptLevel = Descriptor->u.Interrupt.Level;
-                  DeviceExtension->InterruptVector = Descriptor->u.Interrupt.Vector;
-                }
-	    }
-	}
-      ExFreePool(AllocatedResources);
-    }
-  else
-    {
-      UNIMPLEMENTED
-    }
+   RtlCopyMemory(&DriverExtension->RegistryPath, RegistryPath, sizeof(UNICODE_STRING));
 
-  return STATUS_SUCCESS;
-}
+#ifndef NDEBUG
+   switch (HwInitializationData->HwInitDataSize)
+   {
+      case SIZE_OF_NT4_VIDEO_HW_INITIALIZATION_DATA:
+         DPRINT("We were loaded by a Windows NT miniport driver.\n"); break;
+      case SIZE_OF_W2K_VIDEO_HW_INITIALIZATION_DATA:
+         DPRINT("We were loaded by a Windows 2000 miniport driver.\n"); break;
+      case sizeof(VIDEO_HW_INITIALIZATION_DATA):
+         DPRINT("We were loaded by a Windows XP or later miniport driver.\n"); break;
+      default:
+         DPRINT("Invalid HwInitializationData size.\n"); break;
+   }
+#endif
 
-typedef struct QueryRegistryCallbackContext
-{
-  PVOID HwDeviceExtension;
-  PVOID HwContext;
-  PMINIPORT_GET_REGISTRY_ROUTINE HwGetRegistryRoutine;
-} QUERY_REGISTRY_CALLBACK_CONTEXT, *PQUERY_REGISTRY_CALLBACK_CONTEXT;
+   DriverObject->DriverExtension->AddDevice = VideoPortAddDevice;
+   DriverObject->MajorFunction[IRP_MJ_CREATE] = VideoPortDispatchOpen;
+   DriverObject->MajorFunction[IRP_MJ_CLOSE] = VideoPortDispatchClose;
+   DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VideoPortDispatchDeviceControl;
+   DriverObject->MajorFunction[IRP_MJ_PNP] = VideoPortDispatchPnp;
+   DriverObject->MajorFunction[IRP_MJ_POWER] = VideoPortDispatchPower;
+   DriverObject->DriverUnload = VideoPortUnload;
 
-static NTSTATUS STDCALL
-QueryRegistryCallback(IN PWSTR ValueName,
-                      IN ULONG ValueType,
-                      IN PVOID ValueData,
-                      IN ULONG ValueLength,
-                      IN PVOID Context,
-                      IN PVOID EntryContext)
-{
-  PQUERY_REGISTRY_CALLBACK_CONTEXT CallbackContext = (PQUERY_REGISTRY_CALLBACK_CONTEXT) Context;
-
-  DPRINT("Found registry value for name %S: type %d, length %d\n",
-         ValueName, ValueType, ValueLength);
-  return (*(CallbackContext->HwGetRegistryRoutine))(CallbackContext->HwDeviceExtension,
-                                                    CallbackContext->HwContext,
-                                                    ValueName,
-                                                    ValueData,
-                                                    ValueLength);
+   return STATUS_SUCCESS;
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
-VP_STATUS 
-STDCALL
-VideoPortGetRegistryParameters(IN PVOID  HwDeviceExtension,
-                               IN PWSTR  ParameterName,
-                               IN UCHAR  IsParameterFileName,
-                               IN PMINIPORT_GET_REGISTRY_ROUTINE  GetRegistryRoutine,
-                               IN PVOID  HwContext)
-{
-  RTL_QUERY_REGISTRY_TABLE QueryTable[2];
-  QUERY_REGISTRY_CALLBACK_CONTEXT Context;
-  PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
-
-  DPRINT("VideoPortGetRegistryParameters ParameterName %S\n", ParameterName);
-
-  DeviceExtension = CONTAINING_RECORD(HwDeviceExtension,
-				      VIDEO_PORT_DEVICE_EXTENSION,
-				      MiniPortDeviceExtension);
 
-  if (IsParameterFileName)
-    {
-      UNIMPLEMENTED;
-    }
+VOID
+VideoPortDebugPrint(
+   IN VIDEO_DEBUG_LEVEL DebugPrintLevel,
+   IN PCHAR DebugMessage, ...)
+{
+   char Buffer[256];
+   va_list ap;
+
+   va_start(ap, DebugMessage);
+   vsprintf(Buffer, DebugMessage, ap);
+   va_end(ap);
 
-  Context.HwDeviceExtension = HwDeviceExtension;
-  Context.HwContext = HwContext;
-  Context.HwGetRegistryRoutine = GetRegistryRoutine;
-
-  QueryTable[0].QueryRoutine = QueryRegistryCallback;
-  QueryTable[0].Flags = RTL_QUERY_REGISTRY_REQUIRED;
-  QueryTable[0].Name = ParameterName;
-  QueryTable[0].EntryContext = NULL;
-  QueryTable[0].DefaultType = REG_NONE;
-  QueryTable[0].DefaultData = NULL;
-  QueryTable[0].DefaultLength = 0;
-
-  QueryTable[1].QueryRoutine = NULL;
-  QueryTable[1].Name = NULL;
-
-  return NT_SUCCESS(RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
-                                           DeviceExtension->RegistryPath.Buffer,
-                                           QueryTable, &Context, NULL))
-         ? ERROR_SUCCESS : ERROR_INVALID_PARAMETER;
+   DbgPrint(Buffer);
 }
 
-
 /*
- * @implemented
- */ 
-VP_STATUS
-STDCALL
-VideoPortGetVgaStatus(IN PVOID  HwDeviceExtension,
-		      OUT PULONG  VgaStatus)
-{
-  PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
-
-  DPRINT("VideoPortGetVgaStatus = %x \n", VgaStatus);
-
-  DeviceExtension = CONTAINING_RECORD(HwDeviceExtension,
-				      VIDEO_PORT_DEVICE_EXTENSION,
-				      MiniPortDeviceExtension);
-
- if(KeGetCurrentIrql() == PASSIVE_LEVEL)
- {
-  DPRINT("VideoPortGetVgaStatus1 = %x \n", VgaStatus);
-
-  if ( PCIBus == DeviceExtension->AdapterInterfaceType)
-	{
-/*
-  VgaStatus 0 == VGA not enabled, 1 == VGA enabled.
+ * @unimplemented
  */
-  DPRINT("VideoPortGetVgaStatus2 = %x \n", VgaStatus);
-	
-	/* Assumed for now */
-	
-	VgaStatus = (PULONG) 1;
-
- 	return  STATUS_SUCCESS;
- 	}
-  } 	
-  DPRINT("VideoPortGetVgaStatus3 = %x \n", VgaStatus);
-
-  return ERROR_INVALID_FUNCTION;    
-}
-
-static BOOLEAN STDCALL
-VPInterruptRoutine(IN struct _KINTERRUPT *Interrupt,
-                   IN PVOID ServiceContext)
-{
-  PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
-  
-  DeviceExtension = ServiceContext;
-  assert(NULL != DeviceExtension->HwInterrupt);
 
-  return DeviceExtension->HwInterrupt(&DeviceExtension->MiniPortDeviceExtension);
-}
-
-static VOID STDCALL
-VPTimerRoutine(IN PDEVICE_OBJECT DeviceObject,
-               IN PVOID Context)
-{
-  PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension;
-  
-  DeviceExtension = Context;
-  assert(DeviceExtension == DeviceObject->DeviceExtension
-         && NULL != DeviceExtension->HwTimer);
-
-  DeviceExtension->HwTimer(&DeviceExtension->MiniPortDeviceExtension);
+VOID STDCALL
+VideoPortLogError(
+   IN PVOID HwDeviceExtension,
+   IN PVIDEO_REQUEST_PACKET Vrp OPTIONAL,
+   IN VP_STATUS ErrorCode,
+   IN ULONG UniqueId)
+{
+   DPRINT1("VideoPortLogError ErrorCode %d (0x%x) UniqueId %lu (0x%lx)\n",
+           ErrorCode, ErrorCode, UniqueId, UniqueId);
+   if (NULL != Vrp)
+   {
+      DPRINT1("Vrp->IoControlCode %lu (0x%lx)\n", Vrp->IoControlCode, Vrp->IoControlCode);
+   }
 }
 
 /*
  * @implemented
  */
-ULONG STDCALL
-VideoPortInitialize(IN PVOID  Context1,
-                    IN PVOID  Context2,
-                    IN PVIDEO_HW_INITIALIZATION_DATA  HwInitializationData,
-                    IN PVOID  HwContext)
-{
-  PUNICODE_STRING RegistryPath;
-  UCHAR Again = FALSE;
-  WCHAR DeviceBuffer[20];
-  WCHAR SymlinkBuffer[20];
-  WCHAR DeviceVideoBuffer[20];
-  NTSTATUS Status;
-  PDRIVER_OBJECT MPDriverObject = (PDRIVER_OBJECT) Context1;
-  PDEVICE_OBJECT MPDeviceObject;
-  VIDEO_PORT_CONFIG_INFO ConfigInfo;
-  PVIDEO_PORT_DEVICE_EXTENSION  DeviceExtension;
-  ULONG DisplayNumber;
-  UNICODE_STRING DeviceName;
-  UNICODE_STRING SymlinkName;
-  ULONG MaxBus;
-  ULONG MaxLen;
-  KIRQL IRQL;
-  KAFFINITY Affinity;
-  ULONG InterruptVector;
-  OBJECT_ATTRIBUTES Obj;
-  HANDLE ObjHandle;
-
-  DPRINT("VideoPortInitialize\n");
-
-  RegistryPath = (PUNICODE_STRING) Context2;
-
-  /* Build Dispatch table from passed data  */
-  MPDriverObject->DriverStartIo = (PDRIVER_STARTIO) HwInitializationData->HwStartIO;
-
-  /* Find the first free device number */
-  for (DisplayNumber = 0;;)
-    {
-      swprintf(SymlinkBuffer, L"\\??\\DISPLAY%lu", DisplayNumber + 1);
-      RtlInitUnicodeString(&SymlinkName, SymlinkBuffer);
-      InitializeObjectAttributes(&Obj, &SymlinkName, 0, NULL, NULL);
-      Status = ZwOpenSymbolicLinkObject(&ObjHandle, GENERIC_READ, &Obj);
-      if (NT_SUCCESS(Status))
-        {
-          ZwClose(ObjHandle);
-          DisplayNumber++;
-          continue;
-        }
-      else if (Status == STATUS_NOT_FOUND || Status == STATUS_UNSUCCESSFUL)
-        {
-          break;
-        }
-      else
-        {
-          return Status;
-        }
-    }
-
-  DPRINT("- DisplayNumber: %d\n", DisplayNumber);
-
-  Again = FALSE;
-
-  do
-    {
-      /* Create a unicode device name. */
-      swprintf(DeviceBuffer, L"\\Device\\Video%lu", DisplayNumber);
-      RtlInitUnicodeString(&DeviceName, DeviceBuffer);
-
-      /* Create the device. */
-      Status = IoCreateDevice(
-         MPDriverObject,
-         HwInitializationData->HwDeviceExtensionSize +
-         sizeof(VIDEO_PORT_DEVICE_EXTENSION),
-         &DeviceName,
-         FILE_DEVICE_VIDEO,
-         0,
-         TRUE,
-         &MPDeviceObject);
-      if (!NT_SUCCESS(Status))
-        {
-          DPRINT("IoCreateDevice call failed with status 0x%08x\n", Status);
-          return Status;
-        }
-
-      MPDriverObject->DeviceObject = MPDeviceObject;
-
-      /* Initialize the miniport drivers dispatch table */
-      MPDriverObject->MajorFunction[IRP_MJ_CREATE] = VidDispatchOpen;
-      MPDriverObject->MajorFunction[IRP_MJ_CLOSE] = VidDispatchClose;
-      MPDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VidDispatchDeviceControl;
-
-      /* Initialize our device extension */
-      DeviceExtension = 
-        (PVIDEO_PORT_DEVICE_EXTENSION) MPDeviceObject->DeviceExtension;
-      DeviceExtension->DeviceObject = MPDeviceObject;
-      DeviceExtension->HwInitialize = HwInitializationData->HwInitialize;
-      DeviceExtension->HwResetHw = HwInitializationData->HwResetHw;
-      DeviceExtension->AdapterInterfaceType = HwInitializationData->AdapterInterfaceType;
-      DeviceExtension->SystemIoBusNumber = 0;
-      KeInitializeDpc(&DeviceExtension->DpcObject, VideoPortDeferredRoutine,
-		      (PVOID)DeviceExtension);
-      MaxLen = (wcslen(RegistryPath->Buffer) + 10) * sizeof(WCHAR);
-      DeviceExtension->RegistryPath.MaximumLength = MaxLen;
-      DeviceExtension->RegistryPath.Buffer = ExAllocatePoolWithTag(PagedPool,
-                                                                   MaxLen,
-                                                                   TAG_VIDEO_PORT);
-      swprintf(DeviceExtension->RegistryPath.Buffer, L"%s\\Device0",
-               RegistryPath->Buffer);
-      DeviceExtension->RegistryPath.Length = wcslen(DeviceExtension->RegistryPath.Buffer) *
-                                             sizeof(WCHAR);
-
-      MaxBus = (DeviceExtension->AdapterInterfaceType == PCIBus) ? 8 : 1;
-      DPRINT("MaxBus: %lu\n", MaxBus);
-      InitializeListHead(&DeviceExtension->AddressMappingListHead);
-      
-      /*  Set the buffering strategy here...  */
-      /*  If you change this, remember to change VidDispatchDeviceControl too */
-      MPDeviceObject->Flags |= DO_BUFFERED_IO;
-
-      do
-	{
-	  RtlZeroMemory(&DeviceExtension->MiniPortDeviceExtension, 
-	                HwInitializationData->HwDeviceExtensionSize);
-	  DPRINT("Searching on bus %d\n", DeviceExtension->SystemIoBusNumber);
-	  /* Setup configuration info */
-	  RtlZeroMemory(&ConfigInfo, sizeof(VIDEO_PORT_CONFIG_INFO));
-	  ConfigInfo.Length = sizeof(VIDEO_PORT_CONFIG_INFO);
-	  ConfigInfo.AdapterInterfaceType = DeviceExtension->AdapterInterfaceType;
-	  ConfigInfo.SystemIoBusNumber = DeviceExtension->SystemIoBusNumber;
-	  ConfigInfo.InterruptMode = (PCIBus == DeviceExtension->AdapterInterfaceType) ?
-	                              LevelSensitive : Latched;
-	  ConfigInfo.DriverRegistryPath = RegistryPath->Buffer;
-	  ConfigInfo.VideoPortGetProcAddress = VideoPortGetProcAddress;
-
-	  /*  Call HwFindAdapter entry point  */
-	  /* FIXME: Need to figure out what string to pass as param 3  */
-	  DPRINT("FindAdapter %X\n", HwInitializationData->HwFindAdapter);
-	  Status = HwInitializationData->HwFindAdapter(&DeviceExtension->MiniPortDeviceExtension,
-	                                               Context2,
-	                                               NULL,
-	                                               &ConfigInfo,
-	                                               &Again);
-	  if (NO_ERROR != Status)
-	    {
-	      DPRINT("HwFindAdapter call failed with error %X\n", Status);
-	      DeviceExtension->SystemIoBusNumber++;
-	    }
-	}
-      while (NO_ERROR != Status && DeviceExtension->SystemIoBusNumber < MaxBus);
-
-      if (NO_ERROR != Status)
-        {
-	  RtlFreeUnicodeString(&DeviceExtension->RegistryPath);
-          IoDeleteDevice(MPDeviceObject);
-
-          return  Status;
-        }
-      DPRINT("Found adapter\n");
-
-      /* create symbolic link "\??\DISPLAYx" */
-      swprintf(SymlinkBuffer, L"\\??\\DISPLAY%lu", DisplayNumber + 1);
-      RtlInitUnicodeString (&SymlinkName,
-                            SymlinkBuffer);
-      IoCreateSymbolicLink (&SymlinkName,
-                            &DeviceName);
-
-      /* Add entry to DEVICEMAP\VIDEO key in registry */
-      swprintf(DeviceVideoBuffer, L"\\Device\\Video%d", DisplayNumber);
-      RtlWriteRegistryValue(RTL_REGISTRY_DEVICEMAP,
-                            L"VIDEO",
-                            DeviceVideoBuffer,
-                            REG_SZ,
-                            DeviceExtension->RegistryPath.Buffer,
-                            DeviceExtension->RegistryPath.Length + sizeof(WCHAR));
-
-      /* FIXME: Allocate hardware resources for device  */
-
-      /*  Allocate interrupt for device  */
-      DeviceExtension->HwInterrupt = HwInitializationData->HwInterrupt;
-      if (0 == ConfigInfo.BusInterruptVector)
-        {
-          ConfigInfo.BusInterruptVector = DeviceExtension->InterruptVector;
-        }
-      if (0 == ConfigInfo.BusInterruptLevel)
-        {
-          ConfigInfo.BusInterruptLevel = DeviceExtension->InterruptLevel;
-        }
-      if (NULL != HwInitializationData->HwInterrupt)
-        {
-          InterruptVector = 
-            HalGetInterruptVector(ConfigInfo.AdapterInterfaceType,
-                                  ConfigInfo.SystemIoBusNumber,
-                                  ConfigInfo.BusInterruptLevel,
-                                  ConfigInfo.BusInterruptVector,
-                                  &IRQL,
-                                  &Affinity);
-          if (0 == InterruptVector)
-            {
-              DPRINT1("HalGetInterruptVector failed\n");
-              IoDeleteDevice(MPDeviceObject);
-              
-              return STATUS_INSUFFICIENT_RESOURCES;
-            }
-          KeInitializeSpinLock(&DeviceExtension->InterruptSpinLock);
-          Status = IoConnectInterrupt(&DeviceExtension->InterruptObject,
-                                      VPInterruptRoutine,
-                                      DeviceExtension,
-                                      &DeviceExtension->InterruptSpinLock,
-                                      InterruptVector,
-                                      IRQL,
-                                      IRQL,
-                                      ConfigInfo.InterruptMode,
-                                      FALSE,
-                                      Affinity,
-                                      FALSE);
-          if (!NT_SUCCESS(Status))
-            {
-              DPRINT1("IoConnectInterrupt failed with status 0x%08x\n", Status);
-              IoDeleteDevice(MPDeviceObject);
-              
-              return Status;
-            }
-        }
-      DisplayNumber++;
-    }
-  while (Again);
-
-  DeviceExtension->HwTimer = HwInitializationData->HwTimer;
-  if (HwInitializationData->HwTimer != NULL)
-    {
-      DPRINT("Initializing timer\n");
-      Status = IoInitializeTimer(MPDeviceObject,
-                                 VPTimerRoutine,
-                                 DeviceExtension);
-      if (!NT_SUCCESS(Status))
-        {
-          DPRINT("IoInitializeTimer failed with status 0x%08x\n", Status);
-          
-          if (HwInitializationData->HwInterrupt != NULL)
-            {
-              IoDisconnectInterrupt(DeviceExtension->InterruptObject);
-            }
-          IoDeleteDevice(MPDeviceObject);
-          
-          return Status;
-        }
-    }
 
-  return  STATUS_SUCCESS;
+ULONG STDCALL
+VideoPortGetBusData(
+   IN PVOID HwDeviceExtension,
+   IN BUS_DATA_TYPE BusDataType,
+   IN ULONG SlotNumber,
+   OUT PVOID Buffer,
+   IN ULONG Offset,
+   IN ULONG Length)
+{
+   DPRINT("VideoPortGetBusData\n");
+
+   return HalGetBusDataByOffset(
+      BusDataType, 
+      VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension)->SystemIoBusNumber,
+      BusDataType == Cmos ? SlotNumber :
+      VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension)->SystemIoSlotNumber,
+      Buffer, 
+      Offset, 
+      Length);
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
-VOID 
-STDCALL
-VideoPortLogError(IN PVOID  HwDeviceExtension,
-                  IN PVIDEO_REQUEST_PACKET  Vrp OPTIONAL,
-                  IN VP_STATUS  ErrorCode,
-                  IN ULONG  UniqueId)
-{
-  DPRINT1("VideoPortLogError ErrorCode %d (0x%x) UniqueId %lu (0x%lx)\n",
-          ErrorCode, ErrorCode, UniqueId, UniqueId);
-  if (NULL != Vrp)
-    {
-      DPRINT1("Vrp->IoControlCode %lu (0x%lx)\n", Vrp->IoControlCode, Vrp->IoControlCode);
-    }
-}
-
 
-/*
- * @unimplemented
- */
-VP_STATUS 
-STDCALL
-VideoPortMapBankedMemory(IN PVOID  HwDeviceExtension,
-                         IN PHYSICAL_ADDRESS  PhysicalAddress,
-                         IN PULONG  Length,
-                         IN PULONG  InIoSpace,
-                         OUT PVOID  *VirtualAddress,
-                         IN ULONG  BankLength,
-                         IN UCHAR  ReadWriteBank,
-                         IN PBANKED_SECTION_ROUTINE  BankRoutine,
-                         IN PVOID  Context)
-{
-   DPRINT("VideoPortMapBankedMemory\n");
-   UNIMPLEMENTED;
-   return STATUS_NOT_IMPLEMENTED;
+ULONG STDCALL
+VideoPortSetBusData(
+   IN PVOID HwDeviceExtension,
+   IN BUS_DATA_TYPE BusDataType,
+   IN ULONG SlotNumber,
+   IN PVOID Buffer,
+   IN ULONG Offset,
+   IN ULONG Length)
+{
+   DPRINT("VideoPortSetBusData\n");
+   return HalSetBusDataByOffset(
+      BusDataType,
+      VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension)->SystemIoBusNumber,
+      BusDataType == Cmos ? SlotNumber :
+      VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension)->SystemIoSlotNumber,
+      Buffer,
+      Offset,
+      Length);
 }
 
-
 /*
  * @implemented
  */
-VP_STATUS 
-STDCALL
-VideoPortMapMemory(IN PVOID  HwDeviceExtension,
-                   IN PHYSICAL_ADDRESS  PhysicalAddress,
-                   IN PULONG  Length,
-                   IN PULONG  InIoSpace,
-                   OUT PVOID  *VirtualAddress)
-{
-  PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
-  NTSTATUS Status;
-
-  DPRINT("VideoPortMapMemory\n");
-
-  DeviceExtension = CONTAINING_RECORD(HwDeviceExtension,
-				      VIDEO_PORT_DEVICE_EXTENSION,
-				      MiniPortDeviceExtension);
-  *VirtualAddress = InternalMapMemory(DeviceExtension, PhysicalAddress,
-                                      *Length, *InIoSpace, &Status);
 
-  return Status;
+UCHAR STDCALL
+VideoPortGetCurrentIrql(VOID)
+{
+   return KeGetCurrentIrql();
 }
 
+typedef struct QueryRegistryCallbackContext
+{
+  PVOID HwDeviceExtension;
+  PVOID HwContext;
+  PMINIPORT_GET_REGISTRY_ROUTINE HwGetRegistryRoutine;
[truncated at 1000 lines; 1329 more skipped]

reactos/drivers/video/videoprt
videoprt.h 1.6 -> 1.6.2.1
diff -u -r1.6 -r1.6.2.1
--- videoprt.h	9 Mar 2004 18:56:32 -0000	1.6
+++ videoprt.h	14 Mar 2004 17:16:28 -0000	1.6.2.1
@@ -18,7 +18,7 @@
  * If not, write to the Free Software Foundation,
  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * $Id: videoprt.h,v 1.6 2004/03/09 18:56:32 navaraf Exp $
+ * $Id: videoprt.h,v 1.6.2.1 2004/03/14 17:16:28 navaraf Exp $
  */
 
 #ifndef VIDEOPRT_H
@@ -27,25 +27,22 @@
 #include <ddk/miniport.h>
 #include <ddk/video.h>
 #include <ddk/ntddvdeo.h>
-#include "internal/ps.h"
-#define NDEBUG
+#include <ddk/ntapi.h>
+/* #define NDEBUG */
 #include <debug.h>
 
-/*
- * FIXME: Definition missing from w32api!
- */
-#ifndef SYNCH_LEVEL
-#define SYNCH_LEVEL	(IPI_LEVEL - 2)
-#endif
-VOID FASTCALL KfLowerIrql(IN KIRQL NewIrql);
-#define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
-KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql);
-NTKERNELAPI VOID HalAcquireDisplayOwnership(IN PHAL_RESET_DISPLAY_PARAMETERS ResetDisplayParameters);
+typedef PVOID PHAL_RESET_DISPLAY_PARAMETERS;
+int swprintf(wchar_t *buf, const wchar_t *fmt, ...);
+int vsprintf(char *buf, const char *fmt, va_list args);
+VOID STDCALL HalAcquireDisplayOwnership(IN PHAL_RESET_DISPLAY_PARAMETERS ResetDisplayParameters);
+VOID STDCALL HalReleaseDisplayOwnership();
+BOOLEAN STDCALL HalDisableSystemInterrupt(ULONG Vector, ULONG Unknown2);
+BOOLEAN STDCALL HalEnableSystemInterrupt(ULONG Vector, ULONG Unknown2, ULONG Unknown3);
+PIMAGE_NT_HEADERS STDCALL RtlImageNtHeader(IN PVOID BaseAddress);
+#define NtCurrentProcess() ((HANDLE)0xFFFFFFFF)
 
 #define TAG_VIDEO_PORT  TAG('V', 'I', 'D', 'P')
 
-extern PEPROCESS Csrss;
-
 typedef struct _VIDEO_PORT_ADDRESS_MAPPING
 {
    LIST_ENTRY List;
@@ -58,44 +55,99 @@
 
 typedef struct _VIDEO_PORT_DEVICE_EXTENSTION
 {
-   PDEVICE_OBJECT DeviceObject;
+   PDEVICE_OBJECT PhysicalDeviceObject;
+   PDEVICE_OBJECT FunctionalDeviceObject;
+   UNICODE_STRING RegistryPath;
    PKINTERRUPT InterruptObject;
    KSPIN_LOCK InterruptSpinLock;
    ULONG InterruptVector;
    ULONG InterruptLevel;
-   PVIDEO_HW_INITIALIZE HwInitialize;
-   PVIDEO_HW_RESET_HW HwResetHw;
-   PVIDEO_HW_TIMER HwTimer;
-   PVIDEO_HW_INTERRUPT HwInterrupt;
-   LIST_ENTRY AddressMappingListHead;
-   INTERFACE_TYPE AdapterInterfaceType;
+   ULONG AdapterInterfaceType;
    ULONG SystemIoBusNumber;
-   UNICODE_STRING RegistryPath;
+   ULONG SystemIoSlotNumber;
+   LIST_ENTRY AddressMappingListHead;
    KDPC DpcObject;
-   UCHAR MiniPortDeviceExtension[1]; /* must be the last entry */
+   CHAR MiniPortDeviceExtension[1];
 } VIDEO_PORT_DEVICE_EXTENSION, *PVIDEO_PORT_DEVICE_EXTENSION;
 
+typedef struct _VIDEO_PORT_DRIVER_EXTENSION
+{
+   VIDEO_HW_INITIALIZATION_DATA InitializationData;
+   PVOID HwContext;
+   UNICODE_STRING RegistryPath;
+} VIDEO_PORT_DRIVER_EXTENSION, *PVIDEO_PORT_DRIVER_EXTENSION;
+
+#define VIDEO_PORT_GET_DEVICE_EXTENSION(MiniportExtension) \
+   CONTAINING_RECORD( \
+      HwDeviceExtension, \
+      VIDEO_PORT_DEVICE_EXTENSION, \
+      MiniPortDeviceExtension)
+
+/* dispatch.c */
+
 NTSTATUS STDCALL
-VidDispatchOpen(IN PDEVICE_OBJECT pDO, IN PIRP Irp);
+VideoPortAddDevice(
+   IN PDRIVER_OBJECT DriverObject,
+   IN PDEVICE_OBJECT PhysicalDeviceObject);
 
 NTSTATUS STDCALL
-VidDispatchClose(IN PDEVICE_OBJECT pDO, IN PIRP Irp);
+VideoPortDispatchOpen(
+   IN PDEVICE_OBJECT DeviceObject,
+   IN PIRP Irp);
 
 NTSTATUS STDCALL
-VidDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
+VideoPortDispatchClose(
+   IN PDEVICE_OBJECT DeviceObject,
+   IN PIRP Irp);
 
-PVOID STDCALL
-InternalMapMemory(
-   IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension,
-   IN PHYSICAL_ADDRESS IoAddress,
-   IN ULONG NumberOfUchars,
-   IN UCHAR InIoSpace,
-   OUT NTSTATUS *Status);
+NTSTATUS STDCALL
+VideoPortDispatchDeviceControl(
+   IN PDEVICE_OBJECT DeviceObject,
+   IN PIRP Irp);
+
+NTSTATUS STDCALL
+VideoPortDispatchPnp(
+   IN PDEVICE_OBJECT DeviceObject,
+   IN PIRP Irp);
+
+NTSTATUS STDCALL
+VideoPortDispatchPower(
+   IN PDEVICE_OBJECT DeviceObject,
+   IN PIRP Irp);
 
 VOID STDCALL
-InternalUnmapMemory(
-   IN PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension,
-   IN PVOID MappedAddress);
+VideoPortUnload(PDRIVER_OBJECT DriverObject);
+
+/* timer.c */
+
+VOID STDCALL
+VideoPortTimerRoutine(
+   IN PDEVICE_OBJECT DeviceObject,
+   IN PVOID ServiceContext);
+
+/* interrupt.c */
+
+BOOLEAN STDCALL
+VideoPortInterruptRoutine(
+   IN struct _KINTERRUPT *Interrupt,
+   IN PVOID ServiceContext);
+
+/* resource.c */
+
+BOOL FASTCALL
+MapVideoAddressSpace(VOID);
+
+VOID FASTCALL
+UnmapVideoAddressSpace(VOID);
+
+/* videoprt.c */
+
+PVOID STDCALL
+VideoPortGetProcAddress(
+   IN PVOID HwDeviceExtension,
+   IN PUCHAR FunctionName);
+
+/* int10.c */
 
 VP_STATUS STDCALL
 IntInt10AllocateBuffer(

reactos/drivers/video/videoprt
videoprt.rc 1.1 -> 1.1.4.1
diff -u -r1.1 -r1.1.4.1
--- videoprt.rc	19 Jan 2004 15:56:53 -0000	1.1
+++ videoprt.rc	14 Mar 2004 17:16:28 -0000	1.1.4.1
@@ -24,9 +24,9 @@
             VALUE "CompanyName",	RES_STR_COMPANY_NAME
             VALUE "FileDescription",	"Videoport Driver\0"
             VALUE "FileVersion",	"0.0.0\0"
-            VALUE "InternalName",	"vidport\0"
+            VALUE "InternalName",	"videoprt\0"
             VALUE "LegalCopyright",	RES_STR_LEGAL_COPYRIGHT
-            VALUE "OriginalFilename",	"vidport.sys\0"
+            VALUE "OriginalFilename",	"videoprt.sys\0"
             VALUE "ProductName",	RES_STR_PRODUCT_NAME
             VALUE "ProductVersion",	RES_STR_PRODUCT_VERSION
         END
CVSspam 0.2.8