Author: janderwald
Date: Fri Oct  1 17:43:03 2010
New Revision: 48954

URL: http://svn.reactos.org/svn/reactos?rev=48954&view=rev
Log:
[VIDEOPRT]
- Add sanity checks
- Implement VideoPortGetCommonBuffer, VideoPortLockPages


See issue #5629 for more details.

Modified:
    trunk/reactos/drivers/video/videoprt/dma.c
    trunk/reactos/drivers/video/videoprt/resource.c
    trunk/reactos/drivers/video/videoprt/stubs.c
    trunk/reactos/drivers/video/videoprt/videoprt.c
    trunk/reactos/drivers/video/videoprt/videoprt.h

Modified: trunk/reactos/drivers/video/videoprt/dma.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/video/videoprt/dma.c?rev=48954&r1=48953&r2=48954&view=diff
==============================================================================
--- trunk/reactos/drivers/video/videoprt/dma.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/video/videoprt/dma.c [iso-8859-1] Fri Oct  1 17:43:03 
2010
@@ -14,8 +14,10 @@
 
 typedef struct
 {
+    LIST_ENTRY Entry;
     PDMA_ADAPTER Adapter;
     ULONG MapRegisters;
+    PVOID HwDeviceExtension;
 
 }VIP_DMA_ADAPTER, *PVIP_DMA_ADAPTER;
 
@@ -46,7 +48,14 @@
 {
     PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
 
-
+    /* check for valid arguments */
+    if (!Adapter || !Adapter->Adapter)
+    {
+        /* invalid parameter */
+        return NULL;
+    }
+
+    /* allocate common buffer */
     return 
Adapter->Adapter->DmaOperations->AllocateCommonBuffer(Adapter->Adapter, 
DesiredLength, LogicalAddress, CacheEnabled);
 }
 
@@ -64,6 +73,14 @@
 {
     PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
 
+    /* check for valid arguments */
+    if (!Adapter || !Adapter->Adapter)
+    {
+        /* invalid parameter */
+        return;
+    }
+
+    /* release common buffer */
     Adapter->Adapter->DmaOperations->FreeCommonBuffer(Adapter->Adapter, 
Length, LogicalAddress, VirtualAddress, CacheEnabled);
 }
 
@@ -75,9 +92,22 @@
 VideoPortPutDmaAdapter(IN PVOID HwDeviceExtension,
                        IN PVP_DMA_ADAPTER VpDmaAdapter)
 {
+    PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
     PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
 
+    /* get hw device extension */
+    DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
+
+    /* sanity check */
+    ASSERT(!IsListEmpty(&DeviceExtension->DmaAdapterList));
+
+    /* remove dma adapter from list */
+    RemoveEntryList(&Adapter->Entry);
+
+    /* release dma adapter */
     Adapter->Adapter->DmaOperations->PutDmaAdapter(Adapter->Adapter);
+
+    /* free memory */
     ExFreePool(Adapter);
 }
 
@@ -95,13 +125,21 @@
     PVIP_DMA_ADAPTER Adapter;
     PDMA_ADAPTER DmaAdapter;
 
+    /* allocate private adapter structure */
+    Adapter = ExAllocatePool(NonPagedPool, sizeof(VIP_DMA_ADAPTER));
+    if (!Adapter)
+    {
+        /* failed to allocate adapter structure */
+        return NULL;
+    }
+
     /* Zero the structure */
     RtlZeroMemory(&DeviceDescription,
                   sizeof(DEVICE_DESCRIPTION));
 
     /* Initialize the structure */
     DeviceDescription.Version = DEVICE_DESCRIPTION_VERSION;
-    DeviceDescription.Master = TRUE /* ?? */;
+    DeviceDescription.Master = TRUE;
     DeviceDescription.DmaWidth = Width8Bits;
     DeviceDescription.DmaSpeed = Compatible;
 
@@ -115,21 +153,28 @@
     DeviceDescription.BusNumber = DeviceExtension->SystemIoBusNumber;
     DeviceDescription.InterfaceType = DeviceExtension->AdapterInterfaceType;
 
-    Adapter = ExAllocatePool(NonPagedPool, sizeof(VIP_DMA_ADAPTER));
-    if (!Adapter)
-        return NULL;
-
-
+    /* acquire dma adapter */
     DmaAdapter = IoGetDmaAdapter(DeviceExtension->PhysicalDeviceObject, 
&DeviceDescription, &NumberOfMapRegisters);
     if (!DmaAdapter)
     {
+        /* failed to acquire dma */
         ExFreePool(Adapter);
         return NULL;
     }
 
+    /* store dma adapter */
     Adapter->Adapter = DmaAdapter;
+
+    /* store map register count */
     Adapter->MapRegisters = NumberOfMapRegisters;
 
+    /* store hw device extension */
+    Adapter->HwDeviceExtension = HwDeviceExtension;
+
+    /* store in dma adapter list */
+    InsertTailList(&DeviceExtension->DmaAdapterList, &Adapter->Entry);
+
+    /* return result */
     return (PVP_DMA_ADAPTER)Adapter;
 }
 
@@ -144,21 +189,26 @@
                           IN PHYSICAL_ADDRESS LogicalAddress,
                           IN BOOLEAN CacheEnabled)
 {
-    DEVICE_DESCRIPTION DeviceDescription;
-    PVP_DMA_ADAPTER VpDmaAdapter;
-
-    /* FIXME: Broken code*/
-    VpDmaAdapter = VideoPortGetDmaAdapter(HwDeviceExtension,
-                                          
(PVP_DEVICE_DESCRIPTION)&DeviceDescription);
-    HalFreeCommonBuffer((PADAPTER_OBJECT)VpDmaAdapter,
-                        Length,
-                        LogicalAddress,
-                        VirtualAddress,
-                        CacheEnabled);
-}
-
-/*
- * @unimplemented
+    PVIP_DMA_ADAPTER VpDmaAdapter;
+    PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = 
VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
+
+    /* sanity check */
+    ASSERT(!IsListEmpty(&DeviceExtension->DmaAdapterList));
+
+    /* grab first dma adapter */
+    VpDmaAdapter = 
(PVIP_DMA_ADAPTER)CONTAINING_RECORD(DeviceExtension->DmaAdapterList.Flink, 
VIP_DMA_ADAPTER, Entry);
+
+    /* sanity checks */
+    ASSERT(VpDmaAdapter->HwDeviceExtension == HwDeviceExtension);
+    ASSERT(VpDmaAdapter->Adapter != NULL);
+    ASSERT(VpDmaAdapter->MapRegisters != 0);
+
+    return VideoPortReleaseCommonBuffer(HwDeviceExtension, 
(PVP_DMA_ADAPTER)VpDmaAdapter, Length, LogicalAddress, VirtualAddress, 
CacheEnabled);
+
+}
+
+/*
+ * @implemented
  */
 PVOID
 NTAPI
@@ -169,8 +219,44 @@
                          OUT PULONG pActualLength,
                          IN BOOLEAN CacheEnabled)
 {
-    UNIMPLEMENTED;
-       return NULL;
+    PVOID Result;
+    PVIP_DMA_ADAPTER VpDmaAdapter;
+    PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = 
VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
+
+    /* maximum palette size */
+    if (DesiredLength > 262144) 
+    {
+        /* size exceeded */
+        return NULL;
+    }
+
+    /* sanity check */
+    ASSERT(!IsListEmpty(&DeviceExtension->DmaAdapterList));
+
+    /* grab first dma adapter */
+    VpDmaAdapter = 
(PVIP_DMA_ADAPTER)CONTAINING_RECORD(DeviceExtension->DmaAdapterList.Flink, 
VIP_DMA_ADAPTER, Entry);
+
+    /* sanity checks */
+    ASSERT(VpDmaAdapter->HwDeviceExtension == HwDeviceExtension);
+    ASSERT(VpDmaAdapter->Adapter != NULL);
+    ASSERT(VpDmaAdapter->MapRegisters != 0);
+
+
+    /* allocate common buffer */
+    Result = VideoPortAllocateCommonBuffer(HwDeviceExtension, 
(PVP_DMA_ADAPTER)VpDmaAdapter, DesiredLength, LogicalAddress, CacheEnabled, 
NULL);
+
+    if (Result)
+    {
+        /* store length */
+        *pActualLength = DesiredLength;
+    }
+    else
+    {
+        /* failed to allocate common buffer */
+        *pActualLength = 0;
+    }
+
+    return Result;
 }
 
 /*
@@ -185,7 +271,7 @@
     PDMA  BoardMemoryHandle)
 {
     /* Deprecated */
-       return FALSE;
+    return FALSE;
 }
 
 /*
@@ -203,7 +289,7 @@
                       IN OUT PVOID *VirtualAddress)
 {
     /* Deprecated */
-       return NULL;
+    return NULL;
 }
 
 /*
@@ -216,7 +302,7 @@
                        IN PVOID InstanceContext)
 {
     /* Deprecated */
-       return;
+    return;
 }
 
 /*
@@ -228,7 +314,7 @@
                            IN PDMA pDmaHandle)
 {
     /* Deprecated */
-       return FALSE;
+    return FALSE;
 }
 
 
@@ -327,7 +413,7 @@
                        IN PDMA pDma)
 {
     /* Deprecated */
-       return NULL;
+    return NULL;
 }
 
 /*
@@ -344,7 +430,7 @@
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
 PDMA
 NTAPI
@@ -353,8 +439,8 @@
                                       IN PVOID MappedUserEvent,
                                       IN PVOID DisplayDriverEvent)
 {
-    UNIMPLEMENTED;
-       return NULL;
+    /* Deprecated */
+    return NULL;
 }
 
 /*

Modified: trunk/reactos/drivers/video/videoprt/resource.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/video/videoprt/resource.c?rev=48954&r1=48953&r2=48954&view=diff
==============================================================================
--- trunk/reactos/drivers/video/videoprt/resource.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/video/videoprt/resource.c [iso-8859-1] Fri Oct  1 
17:43:03 2010
@@ -760,7 +760,49 @@
 }
 
 /*
- * @unimplemented
+ * @implemented
+ */
+
+BOOLEAN
+NTAPI
+VideoPortLockPages(
+    IN PVOID HwDeviceExtension,
+    IN OUT PVIDEO_REQUEST_PACKET pVrp,
+    IN PEVENT pUEvent,
+    IN PEVENT pDisplayEvent,
+    IN DMA_FLAGS DmaFlags)
+{
+    PVOID Buffer;
+
+    /* clear output buffer */
+    pVrp->OutputBuffer = NULL;
+
+    if (DmaFlags != VideoPortDmaInitOnly)
+    {
+        /* VideoPortKeepPagesLocked / VideoPortUnlockAfterDma is no-op */
+        return FALSE;
+    }
+
+    /* lock the buffer */
+    Buffer = VideoPortLockBuffer(HwDeviceExtension, pVrp->InputBuffer, 
pVrp->InputBufferLength, IoModifyAccess);
+
+    if (Buffer)
+    {
+        /* store result buffer & length */
+        pVrp->OutputBuffer = Buffer;
+        pVrp->OutputBufferLength = pVrp->InputBufferLength;
+
+        /* operation succeeded */
+        return TRUE;
+    }
+
+    /* operation failed */
+    return FALSE;
+}
+
+
+/*
+ * @implemented
  */
 
 VOID NTAPI

Modified: trunk/reactos/drivers/video/videoprt/stubs.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/video/videoprt/stubs.c?rev=48954&r1=48953&r2=48954&view=diff
==============================================================================
--- trunk/reactos/drivers/video/videoprt/stubs.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/video/videoprt/stubs.c [iso-8859-1] Fri Oct  1 
17:43:03 2010
@@ -62,19 +62,6 @@
     return 0;
 }
 
-BOOLEAN
-NTAPI
-VideoPortLockPages(
-    IN PVOID HwDeviceExtension,
-    IN OUT PVIDEO_REQUEST_PACKET pVrp,
-    IN PEVENT pUEvent,
-    IN PEVENT pDisplayEvent,
-    IN DMA_FLAGS DmaFlags)
-{
-    UNIMPLEMENTED;
-    return 0;
-}
-
 LONG
 NTAPI
 VideoPortReadStateEvent(

Modified: trunk/reactos/drivers/video/videoprt/videoprt.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/video/videoprt/videoprt.c?rev=48954&r1=48953&r2=48954&view=diff
==============================================================================
--- trunk/reactos/drivers/video/videoprt/videoprt.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/video/videoprt/videoprt.c [iso-8859-1] Fri Oct  1 
17:43:03 2010
@@ -304,6 +304,8 @@
    }
 
    InitializeListHead(&DeviceExtension->AddressMappingListHead);
+   InitializeListHead(&DeviceExtension->DmaAdapterList);
+
    KeInitializeDpc(
       &DeviceExtension->DpcObject,
       IntVideoPortDeferredRoutine,

Modified: trunk/reactos/drivers/video/videoprt/videoprt.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/video/videoprt/videoprt.h?rev=48954&r1=48953&r2=48954&view=diff
==============================================================================
--- trunk/reactos/drivers/video/videoprt/videoprt.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/video/videoprt/videoprt.h [iso-8859-1] Fri Oct  1 
17:43:03 2010
@@ -95,6 +95,7 @@
    ULONG DeviceOpened;
    AGP_BUS_INTERFACE_STANDARD AgpInterface;
    KMUTEX DeviceLock;
+   LIST_ENTRY DmaAdapterList;
    CHAR MiniPortDeviceExtension[1];
 } VIDEO_PORT_DEVICE_EXTENSION, *PVIDEO_PORT_DEVICE_EXTENSION;
 


Reply via email to