Skip to content

Commit a53b896

Browse files
committed
[VIDEOPRT]
- Add sanity checks - Implement VideoPortGetCommonBuffer, VideoPortLockPages See issue reactos#5629 for more details. svn path=/trunk/; revision=48954
1 parent 2374c7c commit a53b896

File tree

5 files changed

+159
-41
lines changed

5 files changed

+159
-41
lines changed

reactos/drivers/video/videoprt/dma.c

Lines changed: 113 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
typedef struct
1616
{
17+
LIST_ENTRY Entry;
1718
PDMA_ADAPTER Adapter;
1819
ULONG MapRegisters;
20+
PVOID HwDeviceExtension;
1921

2022
}VIP_DMA_ADAPTER, *PVIP_DMA_ADAPTER;
2123

@@ -46,7 +48,14 @@ VideoPortAllocateCommonBuffer(IN PVOID HwDeviceExtension,
4648
{
4749
PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
4850

51+
/* check for valid arguments */
52+
if (!Adapter || !Adapter->Adapter)
53+
{
54+
/* invalid parameter */
55+
return NULL;
56+
}
4957

58+
/* allocate common buffer */
5059
return Adapter->Adapter->DmaOperations->AllocateCommonBuffer(Adapter->Adapter, DesiredLength, LogicalAddress, CacheEnabled);
5160
}
5261

@@ -64,6 +73,14 @@ VideoPortReleaseCommonBuffer(IN PVOID HwDeviceExtension,
6473
{
6574
PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
6675

76+
/* check for valid arguments */
77+
if (!Adapter || !Adapter->Adapter)
78+
{
79+
/* invalid parameter */
80+
return;
81+
}
82+
83+
/* release common buffer */
6784
Adapter->Adapter->DmaOperations->FreeCommonBuffer(Adapter->Adapter, Length, LogicalAddress, VirtualAddress, CacheEnabled);
6885
}
6986

@@ -75,9 +92,22 @@ NTAPI
7592
VideoPortPutDmaAdapter(IN PVOID HwDeviceExtension,
7693
IN PVP_DMA_ADAPTER VpDmaAdapter)
7794
{
95+
PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
7896
PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
7997

98+
/* get hw device extension */
99+
DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
100+
101+
/* sanity check */
102+
ASSERT(!IsListEmpty(&DeviceExtension->DmaAdapterList));
103+
104+
/* remove dma adapter from list */
105+
RemoveEntryList(&Adapter->Entry);
106+
107+
/* release dma adapter */
80108
Adapter->Adapter->DmaOperations->PutDmaAdapter(Adapter->Adapter);
109+
110+
/* free memory */
81111
ExFreePool(Adapter);
82112
}
83113

@@ -95,13 +125,21 @@ VideoPortGetDmaAdapter(IN PVOID HwDeviceExtension,
95125
PVIP_DMA_ADAPTER Adapter;
96126
PDMA_ADAPTER DmaAdapter;
97127

128+
/* allocate private adapter structure */
129+
Adapter = ExAllocatePool(NonPagedPool, sizeof(VIP_DMA_ADAPTER));
130+
if (!Adapter)
131+
{
132+
/* failed to allocate adapter structure */
133+
return NULL;
134+
}
135+
98136
/* Zero the structure */
99137
RtlZeroMemory(&DeviceDescription,
100138
sizeof(DEVICE_DESCRIPTION));
101139

102140
/* Initialize the structure */
103141
DeviceDescription.Version = DEVICE_DESCRIPTION_VERSION;
104-
DeviceDescription.Master = TRUE /* ?? */;
142+
DeviceDescription.Master = TRUE;
105143
DeviceDescription.DmaWidth = Width8Bits;
106144
DeviceDescription.DmaSpeed = Compatible;
107145

@@ -115,21 +153,28 @@ VideoPortGetDmaAdapter(IN PVOID HwDeviceExtension,
115153
DeviceDescription.BusNumber = DeviceExtension->SystemIoBusNumber;
116154
DeviceDescription.InterfaceType = DeviceExtension->AdapterInterfaceType;
117155

118-
Adapter = ExAllocatePool(NonPagedPool, sizeof(VIP_DMA_ADAPTER));
119-
if (!Adapter)
120-
return NULL;
121-
122-
156+
/* acquire dma adapter */
123157
DmaAdapter = IoGetDmaAdapter(DeviceExtension->PhysicalDeviceObject, &DeviceDescription, &NumberOfMapRegisters);
124158
if (!DmaAdapter)
125159
{
160+
/* failed to acquire dma */
126161
ExFreePool(Adapter);
127162
return NULL;
128163
}
129164

165+
/* store dma adapter */
130166
Adapter->Adapter = DmaAdapter;
167+
168+
/* store map register count */
131169
Adapter->MapRegisters = NumberOfMapRegisters;
132170

171+
/* store hw device extension */
172+
Adapter->HwDeviceExtension = HwDeviceExtension;
173+
174+
/* store in dma adapter list */
175+
InsertTailList(&DeviceExtension->DmaAdapterList, &Adapter->Entry);
176+
177+
/* return result */
133178
return (PVP_DMA_ADAPTER)Adapter;
134179
}
135180

@@ -144,21 +189,26 @@ VideoPortFreeCommonBuffer(IN PVOID HwDeviceExtension,
144189
IN PHYSICAL_ADDRESS LogicalAddress,
145190
IN BOOLEAN CacheEnabled)
146191
{
147-
DEVICE_DESCRIPTION DeviceDescription;
148-
PVP_DMA_ADAPTER VpDmaAdapter;
192+
PVIP_DMA_ADAPTER VpDmaAdapter;
193+
PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
194+
195+
/* sanity check */
196+
ASSERT(!IsListEmpty(&DeviceExtension->DmaAdapterList));
197+
198+
/* grab first dma adapter */
199+
VpDmaAdapter = (PVIP_DMA_ADAPTER)CONTAINING_RECORD(DeviceExtension->DmaAdapterList.Flink, VIP_DMA_ADAPTER, Entry);
200+
201+
/* sanity checks */
202+
ASSERT(VpDmaAdapter->HwDeviceExtension == HwDeviceExtension);
203+
ASSERT(VpDmaAdapter->Adapter != NULL);
204+
ASSERT(VpDmaAdapter->MapRegisters != 0);
205+
206+
return VideoPortReleaseCommonBuffer(HwDeviceExtension, (PVP_DMA_ADAPTER)VpDmaAdapter, Length, LogicalAddress, VirtualAddress, CacheEnabled);
149207

150-
/* FIXME: Broken code*/
151-
VpDmaAdapter = VideoPortGetDmaAdapter(HwDeviceExtension,
152-
(PVP_DEVICE_DESCRIPTION)&DeviceDescription);
153-
HalFreeCommonBuffer((PADAPTER_OBJECT)VpDmaAdapter,
154-
Length,
155-
LogicalAddress,
156-
VirtualAddress,
157-
CacheEnabled);
158208
}
159209

160210
/*
161-
* @unimplemented
211+
* @implemented
162212
*/
163213
PVOID
164214
NTAPI
@@ -169,8 +219,44 @@ VideoPortGetCommonBuffer(IN PVOID HwDeviceExtension,
169219
OUT PULONG pActualLength,
170220
IN BOOLEAN CacheEnabled)
171221
{
172-
UNIMPLEMENTED;
173-
return NULL;
222+
PVOID Result;
223+
PVIP_DMA_ADAPTER VpDmaAdapter;
224+
PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
225+
226+
/* maximum palette size */
227+
if (DesiredLength > 262144)
228+
{
229+
/* size exceeded */
230+
return NULL;
231+
}
232+
233+
/* sanity check */
234+
ASSERT(!IsListEmpty(&DeviceExtension->DmaAdapterList));
235+
236+
/* grab first dma adapter */
237+
VpDmaAdapter = (PVIP_DMA_ADAPTER)CONTAINING_RECORD(DeviceExtension->DmaAdapterList.Flink, VIP_DMA_ADAPTER, Entry);
238+
239+
/* sanity checks */
240+
ASSERT(VpDmaAdapter->HwDeviceExtension == HwDeviceExtension);
241+
ASSERT(VpDmaAdapter->Adapter != NULL);
242+
ASSERT(VpDmaAdapter->MapRegisters != 0);
243+
244+
245+
/* allocate common buffer */
246+
Result = VideoPortAllocateCommonBuffer(HwDeviceExtension, (PVP_DMA_ADAPTER)VpDmaAdapter, DesiredLength, LogicalAddress, CacheEnabled, NULL);
247+
248+
if (Result)
249+
{
250+
/* store length */
251+
*pActualLength = DesiredLength;
252+
}
253+
else
254+
{
255+
/* failed to allocate common buffer */
256+
*pActualLength = 0;
257+
}
258+
259+
return Result;
174260
}
175261

176262
/*
@@ -185,7 +271,7 @@ VideoPortUnmapDmaMemory(
185271
PDMA BoardMemoryHandle)
186272
{
187273
/* Deprecated */
188-
return FALSE;
274+
return FALSE;
189275
}
190276

191277
/*
@@ -203,7 +289,7 @@ VideoPortMapDmaMemory(IN PVOID HwDeviceExtension,
203289
IN OUT PVOID *VirtualAddress)
204290
{
205291
/* Deprecated */
206-
return NULL;
292+
return NULL;
207293
}
208294

209295
/*
@@ -216,7 +302,7 @@ VideoPortSetDmaContext(IN PVOID HwDeviceExtension,
216302
IN PVOID InstanceContext)
217303
{
218304
/* Deprecated */
219-
return;
305+
return;
220306
}
221307

222308
/*
@@ -228,7 +314,7 @@ VideoPortSignalDmaComplete(IN PVOID HwDeviceExtension,
228314
IN PDMA pDmaHandle)
229315
{
230316
/* Deprecated */
231-
return FALSE;
317+
return FALSE;
232318
}
233319

234320

@@ -327,7 +413,7 @@ VideoPortGetDmaContext(IN PVOID HwDeviceExtension,
327413
IN PDMA pDma)
328414
{
329415
/* Deprecated */
330-
return NULL;
416+
return NULL;
331417
}
332418

333419
/*
@@ -344,7 +430,7 @@ VideoPortDoDma(IN PVOID HwDeviceExtension,
344430
}
345431

346432
/*
347-
* @unimplemented
433+
* @implemented
348434
*/
349435
PDMA
350436
NTAPI
@@ -353,8 +439,8 @@ VideoPortAssociateEventsWithDmaHandle(IN PVOID HwDeviceExtension,
353439
IN PVOID MappedUserEvent,
354440
IN PVOID DisplayDriverEvent)
355441
{
356-
UNIMPLEMENTED;
357-
return NULL;
442+
/* Deprecated */
443+
return NULL;
358444
}
359445

360446
/*

reactos/drivers/video/videoprt/resource.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,49 @@ VideoPortLockBuffer(
760760
}
761761

762762
/*
763-
* @unimplemented
763+
* @implemented
764+
*/
765+
766+
BOOLEAN
767+
NTAPI
768+
VideoPortLockPages(
769+
IN PVOID HwDeviceExtension,
770+
IN OUT PVIDEO_REQUEST_PACKET pVrp,
771+
IN PEVENT pUEvent,
772+
IN PEVENT pDisplayEvent,
773+
IN DMA_FLAGS DmaFlags)
774+
{
775+
PVOID Buffer;
776+
777+
/* clear output buffer */
778+
pVrp->OutputBuffer = NULL;
779+
780+
if (DmaFlags != VideoPortDmaInitOnly)
781+
{
782+
/* VideoPortKeepPagesLocked / VideoPortUnlockAfterDma is no-op */
783+
return FALSE;
784+
}
785+
786+
/* lock the buffer */
787+
Buffer = VideoPortLockBuffer(HwDeviceExtension, pVrp->InputBuffer, pVrp->InputBufferLength, IoModifyAccess);
788+
789+
if (Buffer)
790+
{
791+
/* store result buffer & length */
792+
pVrp->OutputBuffer = Buffer;
793+
pVrp->OutputBufferLength = pVrp->InputBufferLength;
794+
795+
/* operation succeeded */
796+
return TRUE;
797+
}
798+
799+
/* operation failed */
800+
return FALSE;
801+
}
802+
803+
804+
/*
805+
* @implemented
764806
*/
765807

766808
VOID NTAPI

reactos/drivers/video/videoprt/stubs.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,6 @@ VideoPortGetMdl(
6262
return 0;
6363
}
6464

65-
BOOLEAN
66-
NTAPI
67-
VideoPortLockPages(
68-
IN PVOID HwDeviceExtension,
69-
IN OUT PVIDEO_REQUEST_PACKET pVrp,
70-
IN PEVENT pUEvent,
71-
IN PEVENT pDisplayEvent,
72-
IN DMA_FLAGS DmaFlags)
73-
{
74-
UNIMPLEMENTED;
75-
return 0;
76-
}
77-
7865
LONG
7966
NTAPI
8067
VideoPortReadStateEvent(

reactos/drivers/video/videoprt/videoprt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ IntVideoPortCreateAdapterDeviceObject(
304304
}
305305

306306
InitializeListHead(&DeviceExtension->AddressMappingListHead);
307+
InitializeListHead(&DeviceExtension->DmaAdapterList);
308+
307309
KeInitializeDpc(
308310
&DeviceExtension->DpcObject,
309311
IntVideoPortDeferredRoutine,

reactos/drivers/video/videoprt/videoprt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ typedef struct _VIDEO_PORT_DEVICE_EXTENSTION
9595
ULONG DeviceOpened;
9696
AGP_BUS_INTERFACE_STANDARD AgpInterface;
9797
KMUTEX DeviceLock;
98+
LIST_ENTRY DmaAdapterList;
9899
CHAR MiniPortDeviceExtension[1];
99100
} VIDEO_PORT_DEVICE_EXTENSION, *PVIDEO_PORT_DEVICE_EXTENSION;
100101

0 commit comments

Comments
 (0)