[VIDEOPRT]

- Add sanity checks
- Implement VideoPortGetCommonBuffer, VideoPortLockPages


See issue #5629 for more details.

svn path=/trunk/; revision=48954
This commit is contained in:
Johannes Anderwald 2010-10-01 17:43:03 +00:00
parent 2374c7cb8d
commit a53b8966ba
5 changed files with 159 additions and 41 deletions

View file

@ -14,8 +14,10 @@
typedef struct typedef struct
{ {
LIST_ENTRY Entry;
PDMA_ADAPTER Adapter; PDMA_ADAPTER Adapter;
ULONG MapRegisters; ULONG MapRegisters;
PVOID HwDeviceExtension;
}VIP_DMA_ADAPTER, *PVIP_DMA_ADAPTER; }VIP_DMA_ADAPTER, *PVIP_DMA_ADAPTER;
@ -46,7 +48,14 @@ VideoPortAllocateCommonBuffer(IN PVOID HwDeviceExtension,
{ {
PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter; 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); return Adapter->Adapter->DmaOperations->AllocateCommonBuffer(Adapter->Adapter, DesiredLength, LogicalAddress, CacheEnabled);
} }
@ -64,6 +73,14 @@ VideoPortReleaseCommonBuffer(IN PVOID HwDeviceExtension,
{ {
PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter; 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); Adapter->Adapter->DmaOperations->FreeCommonBuffer(Adapter->Adapter, Length, LogicalAddress, VirtualAddress, CacheEnabled);
} }
@ -75,9 +92,22 @@ NTAPI
VideoPortPutDmaAdapter(IN PVOID HwDeviceExtension, VideoPortPutDmaAdapter(IN PVOID HwDeviceExtension,
IN PVP_DMA_ADAPTER VpDmaAdapter) IN PVP_DMA_ADAPTER VpDmaAdapter)
{ {
PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter; 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); Adapter->Adapter->DmaOperations->PutDmaAdapter(Adapter->Adapter);
/* free memory */
ExFreePool(Adapter); ExFreePool(Adapter);
} }
@ -95,13 +125,21 @@ VideoPortGetDmaAdapter(IN PVOID HwDeviceExtension,
PVIP_DMA_ADAPTER Adapter; PVIP_DMA_ADAPTER Adapter;
PDMA_ADAPTER DmaAdapter; 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 */ /* Zero the structure */
RtlZeroMemory(&DeviceDescription, RtlZeroMemory(&DeviceDescription,
sizeof(DEVICE_DESCRIPTION)); sizeof(DEVICE_DESCRIPTION));
/* Initialize the structure */ /* Initialize the structure */
DeviceDescription.Version = DEVICE_DESCRIPTION_VERSION; DeviceDescription.Version = DEVICE_DESCRIPTION_VERSION;
DeviceDescription.Master = TRUE /* ?? */; DeviceDescription.Master = TRUE;
DeviceDescription.DmaWidth = Width8Bits; DeviceDescription.DmaWidth = Width8Bits;
DeviceDescription.DmaSpeed = Compatible; DeviceDescription.DmaSpeed = Compatible;
@ -115,21 +153,28 @@ VideoPortGetDmaAdapter(IN PVOID HwDeviceExtension,
DeviceDescription.BusNumber = DeviceExtension->SystemIoBusNumber; DeviceDescription.BusNumber = DeviceExtension->SystemIoBusNumber;
DeviceDescription.InterfaceType = DeviceExtension->AdapterInterfaceType; DeviceDescription.InterfaceType = DeviceExtension->AdapterInterfaceType;
Adapter = ExAllocatePool(NonPagedPool, sizeof(VIP_DMA_ADAPTER)); /* acquire dma adapter */
if (!Adapter)
return NULL;
DmaAdapter = IoGetDmaAdapter(DeviceExtension->PhysicalDeviceObject, &DeviceDescription, &NumberOfMapRegisters); DmaAdapter = IoGetDmaAdapter(DeviceExtension->PhysicalDeviceObject, &DeviceDescription, &NumberOfMapRegisters);
if (!DmaAdapter) if (!DmaAdapter)
{ {
/* failed to acquire dma */
ExFreePool(Adapter); ExFreePool(Adapter);
return NULL; return NULL;
} }
/* store dma adapter */
Adapter->Adapter = DmaAdapter; Adapter->Adapter = DmaAdapter;
/* store map register count */
Adapter->MapRegisters = NumberOfMapRegisters; 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; return (PVP_DMA_ADAPTER)Adapter;
} }
@ -144,21 +189,26 @@ VideoPortFreeCommonBuffer(IN PVOID HwDeviceExtension,
IN PHYSICAL_ADDRESS LogicalAddress, IN PHYSICAL_ADDRESS LogicalAddress,
IN BOOLEAN CacheEnabled) IN BOOLEAN CacheEnabled)
{ {
DEVICE_DESCRIPTION DeviceDescription; PVIP_DMA_ADAPTER VpDmaAdapter;
PVP_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);
/* FIXME: Broken code*/
VpDmaAdapter = VideoPortGetDmaAdapter(HwDeviceExtension,
(PVP_DEVICE_DESCRIPTION)&DeviceDescription);
HalFreeCommonBuffer((PADAPTER_OBJECT)VpDmaAdapter,
Length,
LogicalAddress,
VirtualAddress,
CacheEnabled);
} }
/* /*
* @unimplemented * @implemented
*/ */
PVOID PVOID
NTAPI NTAPI
@ -169,8 +219,44 @@ VideoPortGetCommonBuffer(IN PVOID HwDeviceExtension,
OUT PULONG pActualLength, OUT PULONG pActualLength,
IN BOOLEAN CacheEnabled) IN BOOLEAN CacheEnabled)
{ {
UNIMPLEMENTED; PVOID Result;
return NULL; 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 @@ VideoPortUnmapDmaMemory(
PDMA BoardMemoryHandle) PDMA BoardMemoryHandle)
{ {
/* Deprecated */ /* Deprecated */
return FALSE; return FALSE;
} }
/* /*
@ -203,7 +289,7 @@ VideoPortMapDmaMemory(IN PVOID HwDeviceExtension,
IN OUT PVOID *VirtualAddress) IN OUT PVOID *VirtualAddress)
{ {
/* Deprecated */ /* Deprecated */
return NULL; return NULL;
} }
/* /*
@ -216,7 +302,7 @@ VideoPortSetDmaContext(IN PVOID HwDeviceExtension,
IN PVOID InstanceContext) IN PVOID InstanceContext)
{ {
/* Deprecated */ /* Deprecated */
return; return;
} }
/* /*
@ -228,7 +314,7 @@ VideoPortSignalDmaComplete(IN PVOID HwDeviceExtension,
IN PDMA pDmaHandle) IN PDMA pDmaHandle)
{ {
/* Deprecated */ /* Deprecated */
return FALSE; return FALSE;
} }
@ -327,7 +413,7 @@ VideoPortGetDmaContext(IN PVOID HwDeviceExtension,
IN PDMA pDma) IN PDMA pDma)
{ {
/* Deprecated */ /* Deprecated */
return NULL; return NULL;
} }
/* /*
@ -344,7 +430,7 @@ VideoPortDoDma(IN PVOID HwDeviceExtension,
} }
/* /*
* @unimplemented * @implemented
*/ */
PDMA PDMA
NTAPI NTAPI
@ -353,8 +439,8 @@ VideoPortAssociateEventsWithDmaHandle(IN PVOID HwDeviceExtension,
IN PVOID MappedUserEvent, IN PVOID MappedUserEvent,
IN PVOID DisplayDriverEvent) IN PVOID DisplayDriverEvent)
{ {
UNIMPLEMENTED; /* Deprecated */
return NULL; return NULL;
} }
/* /*

View file

@ -760,7 +760,49 @@ VideoPortLockBuffer(
} }
/* /*
* @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 VOID NTAPI

View file

@ -62,19 +62,6 @@ VideoPortGetMdl(
return 0; 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 LONG
NTAPI NTAPI
VideoPortReadStateEvent( VideoPortReadStateEvent(

View file

@ -304,6 +304,8 @@ IntVideoPortCreateAdapterDeviceObject(
} }
InitializeListHead(&DeviceExtension->AddressMappingListHead); InitializeListHead(&DeviceExtension->AddressMappingListHead);
InitializeListHead(&DeviceExtension->DmaAdapterList);
KeInitializeDpc( KeInitializeDpc(
&DeviceExtension->DpcObject, &DeviceExtension->DpcObject,
IntVideoPortDeferredRoutine, IntVideoPortDeferredRoutine,

View file

@ -95,6 +95,7 @@ typedef struct _VIDEO_PORT_DEVICE_EXTENSTION
ULONG DeviceOpened; ULONG DeviceOpened;
AGP_BUS_INTERFACE_STANDARD AgpInterface; AGP_BUS_INTERFACE_STANDARD AgpInterface;
KMUTEX DeviceLock; KMUTEX DeviceLock;
LIST_ENTRY DmaAdapterList;
CHAR MiniPortDeviceExtension[1]; CHAR MiniPortDeviceExtension[1];
} VIDEO_PORT_DEVICE_EXTENSION, *PVIDEO_PORT_DEVICE_EXTENSION; } VIDEO_PORT_DEVICE_EXTENSION, *PVIDEO_PORT_DEVICE_EXTENSION;