Index: dma.c =================================================================== --- dma.c (revision 48659) +++ dma.c (working copy) @@ -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; + PVIP_DMA_ADAPTER VpDmaAdapter; + PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension); - /* FIXME: Broken code*/ - VpDmaAdapter = VideoPortGetDmaAdapter(HwDeviceExtension, - (PVP_DEVICE_DESCRIPTION)&DeviceDescription); - HalFreeCommonBuffer((PADAPTER_OBJECT)VpDmaAdapter, - Length, - LogicalAddress, - VirtualAddress, - CacheEnabled); + /* 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); + } /* - * @unimplemented + * @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; } /* Index: resource.c =================================================================== --- resource.c (revision 48659) +++ resource.c (working copy) @@ -760,9 +760,51 @@ } /* - * @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 VideoPortUnlockBuffer( IN PVOID HwDeviceExtension, Index: stubs.c =================================================================== --- stubs.c (revision 48659) +++ stubs.c (working copy) @@ -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( Index: videoprt.c =================================================================== --- videoprt.c (revision 48659) +++ videoprt.c (working copy) @@ -304,6 +304,8 @@ } InitializeListHead(&DeviceExtension->AddressMappingListHead); + InitializeListHead(&DeviceExtension->DmaAdapterList); + KeInitializeDpc( &DeviceExtension->DpcObject, IntVideoPortDeferredRoutine, Index: videoprt.h =================================================================== --- videoprt.h (revision 48659) +++ videoprt.h (working copy) @@ -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;