1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * PROJECT: ReactOS Videoport
3*c2c66affSColin Finck * LICENSE: GPL - See COPYING in the top level directory
4*c2c66affSColin Finck * FILE: win32ss/drivers/videoprt/dma.c
5*c2c66affSColin Finck * PURPOSE: Videoport Direct Memory Access Support
6*c2c66affSColin Finck * PROGRAMMERS: ...
7*c2c66affSColin Finck */
8*c2c66affSColin Finck
9*c2c66affSColin Finck /* INCLUDES ******************************************************************/
10*c2c66affSColin Finck
11*c2c66affSColin Finck #include <videoprt.h>
12*c2c66affSColin Finck
13*c2c66affSColin Finck #define NDEBUG
14*c2c66affSColin Finck #include <debug.h>
15*c2c66affSColin Finck
16*c2c66affSColin Finck typedef struct
17*c2c66affSColin Finck {
18*c2c66affSColin Finck LIST_ENTRY Entry;
19*c2c66affSColin Finck PDMA_ADAPTER Adapter;
20*c2c66affSColin Finck ULONG MapRegisters;
21*c2c66affSColin Finck PVOID HwDeviceExtension;
22*c2c66affSColin Finck
23*c2c66affSColin Finck }VIP_DMA_ADAPTER, *PVIP_DMA_ADAPTER;
24*c2c66affSColin Finck
25*c2c66affSColin Finck typedef struct
26*c2c66affSColin Finck {
27*c2c66affSColin Finck PVOID HwDeviceExtension;
28*c2c66affSColin Finck PSCATTER_GATHER_LIST ScatterGatherList;
29*c2c66affSColin Finck PEXECUTE_DMA ExecuteDmaRoutine;
30*c2c66affSColin Finck PVOID Context;
31*c2c66affSColin Finck PVP_DMA_ADAPTER VpDmaAdapter;
32*c2c66affSColin Finck
33*c2c66affSColin Finck }DMA_START_CONTEXT, *PDMA_START_CONTEXT;
34*c2c66affSColin Finck
35*c2c66affSColin Finck
36*c2c66affSColin Finck /* PUBLIC FUNCTIONS ***********************************************************/
37*c2c66affSColin Finck
38*c2c66affSColin Finck /*
39*c2c66affSColin Finck * @implemented
40*c2c66affSColin Finck */
41*c2c66affSColin Finck PVOID
42*c2c66affSColin Finck NTAPI
VideoPortAllocateCommonBuffer(IN PVOID HwDeviceExtension,IN PVP_DMA_ADAPTER VpDmaAdapter,IN ULONG DesiredLength,OUT PPHYSICAL_ADDRESS LogicalAddress,IN BOOLEAN CacheEnabled,PVOID Reserved)43*c2c66affSColin Finck VideoPortAllocateCommonBuffer(IN PVOID HwDeviceExtension,
44*c2c66affSColin Finck IN PVP_DMA_ADAPTER VpDmaAdapter,
45*c2c66affSColin Finck IN ULONG DesiredLength,
46*c2c66affSColin Finck OUT PPHYSICAL_ADDRESS LogicalAddress,
47*c2c66affSColin Finck IN BOOLEAN CacheEnabled,
48*c2c66affSColin Finck PVOID Reserved)
49*c2c66affSColin Finck {
50*c2c66affSColin Finck PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
51*c2c66affSColin Finck
52*c2c66affSColin Finck /* check for valid arguments */
53*c2c66affSColin Finck if (!Adapter || !Adapter->Adapter)
54*c2c66affSColin Finck {
55*c2c66affSColin Finck /* invalid parameter */
56*c2c66affSColin Finck return NULL;
57*c2c66affSColin Finck }
58*c2c66affSColin Finck
59*c2c66affSColin Finck /* allocate common buffer */
60*c2c66affSColin Finck return Adapter->Adapter->DmaOperations->AllocateCommonBuffer(Adapter->Adapter, DesiredLength, LogicalAddress, CacheEnabled);
61*c2c66affSColin Finck }
62*c2c66affSColin Finck
63*c2c66affSColin Finck /*
64*c2c66affSColin Finck * @implemented
65*c2c66affSColin Finck */
66*c2c66affSColin Finck VOID
67*c2c66affSColin Finck NTAPI
VideoPortReleaseCommonBuffer(IN PVOID HwDeviceExtension,IN PVP_DMA_ADAPTER VpDmaAdapter,IN ULONG Length,IN PHYSICAL_ADDRESS LogicalAddress,IN PVOID VirtualAddress,IN BOOLEAN CacheEnabled)68*c2c66affSColin Finck VideoPortReleaseCommonBuffer(IN PVOID HwDeviceExtension,
69*c2c66affSColin Finck IN PVP_DMA_ADAPTER VpDmaAdapter,
70*c2c66affSColin Finck IN ULONG Length,
71*c2c66affSColin Finck IN PHYSICAL_ADDRESS LogicalAddress,
72*c2c66affSColin Finck IN PVOID VirtualAddress,
73*c2c66affSColin Finck IN BOOLEAN CacheEnabled)
74*c2c66affSColin Finck {
75*c2c66affSColin Finck PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
76*c2c66affSColin Finck
77*c2c66affSColin Finck /* check for valid arguments */
78*c2c66affSColin Finck if (!Adapter || !Adapter->Adapter)
79*c2c66affSColin Finck {
80*c2c66affSColin Finck /* invalid parameter */
81*c2c66affSColin Finck return;
82*c2c66affSColin Finck }
83*c2c66affSColin Finck
84*c2c66affSColin Finck /* release common buffer */
85*c2c66affSColin Finck Adapter->Adapter->DmaOperations->FreeCommonBuffer(Adapter->Adapter, Length, LogicalAddress, VirtualAddress, CacheEnabled);
86*c2c66affSColin Finck }
87*c2c66affSColin Finck
88*c2c66affSColin Finck /*
89*c2c66affSColin Finck * @implemented
90*c2c66affSColin Finck */
91*c2c66affSColin Finck VOID
92*c2c66affSColin Finck NTAPI
VideoPortPutDmaAdapter(IN PVOID HwDeviceExtension,IN PVP_DMA_ADAPTER VpDmaAdapter)93*c2c66affSColin Finck VideoPortPutDmaAdapter(IN PVOID HwDeviceExtension,
94*c2c66affSColin Finck IN PVP_DMA_ADAPTER VpDmaAdapter)
95*c2c66affSColin Finck {
96*c2c66affSColin Finck PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
97*c2c66affSColin Finck PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
98*c2c66affSColin Finck
99*c2c66affSColin Finck /* get hw device extension */
100*c2c66affSColin Finck DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
101*c2c66affSColin Finck
102*c2c66affSColin Finck /* sanity check */
103*c2c66affSColin Finck ASSERT(!IsListEmpty(&DeviceExtension->DmaAdapterList));
104*c2c66affSColin Finck
105*c2c66affSColin Finck /* remove dma adapter from list */
106*c2c66affSColin Finck RemoveEntryList(&Adapter->Entry);
107*c2c66affSColin Finck
108*c2c66affSColin Finck /* release dma adapter */
109*c2c66affSColin Finck Adapter->Adapter->DmaOperations->PutDmaAdapter(Adapter->Adapter);
110*c2c66affSColin Finck
111*c2c66affSColin Finck /* free memory */
112*c2c66affSColin Finck ExFreePool(Adapter);
113*c2c66affSColin Finck }
114*c2c66affSColin Finck
115*c2c66affSColin Finck /*
116*c2c66affSColin Finck * @implemented
117*c2c66affSColin Finck */
118*c2c66affSColin Finck PVP_DMA_ADAPTER
119*c2c66affSColin Finck NTAPI
VideoPortGetDmaAdapter(IN PVOID HwDeviceExtension,IN PVP_DEVICE_DESCRIPTION VpDeviceExtension)120*c2c66affSColin Finck VideoPortGetDmaAdapter(IN PVOID HwDeviceExtension,
121*c2c66affSColin Finck IN PVP_DEVICE_DESCRIPTION VpDeviceExtension)
122*c2c66affSColin Finck {
123*c2c66affSColin Finck DEVICE_DESCRIPTION DeviceDescription;
124*c2c66affSColin Finck PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
125*c2c66affSColin Finck ULONG NumberOfMapRegisters;
126*c2c66affSColin Finck PVIP_DMA_ADAPTER Adapter;
127*c2c66affSColin Finck PDMA_ADAPTER DmaAdapter;
128*c2c66affSColin Finck
129*c2c66affSColin Finck /* allocate private adapter structure */
130*c2c66affSColin Finck Adapter = ExAllocatePool(NonPagedPool, sizeof(VIP_DMA_ADAPTER));
131*c2c66affSColin Finck if (!Adapter)
132*c2c66affSColin Finck {
133*c2c66affSColin Finck /* failed to allocate adapter structure */
134*c2c66affSColin Finck return NULL;
135*c2c66affSColin Finck }
136*c2c66affSColin Finck
137*c2c66affSColin Finck /* Zero the structure */
138*c2c66affSColin Finck RtlZeroMemory(&DeviceDescription,
139*c2c66affSColin Finck sizeof(DEVICE_DESCRIPTION));
140*c2c66affSColin Finck
141*c2c66affSColin Finck /* Initialize the structure */
142*c2c66affSColin Finck DeviceDescription.Version = DEVICE_DESCRIPTION_VERSION;
143*c2c66affSColin Finck DeviceDescription.Master = TRUE;
144*c2c66affSColin Finck DeviceDescription.DmaWidth = Width8Bits;
145*c2c66affSColin Finck DeviceDescription.DmaSpeed = Compatible;
146*c2c66affSColin Finck
147*c2c66affSColin Finck /* Copy data from caller's device extension */
148*c2c66affSColin Finck DeviceDescription.ScatterGather = VpDeviceExtension->ScatterGather;
149*c2c66affSColin Finck DeviceDescription.Dma32BitAddresses = VpDeviceExtension->Dma32BitAddresses;
150*c2c66affSColin Finck DeviceDescription.Dma64BitAddresses = VpDeviceExtension->Dma64BitAddresses;
151*c2c66affSColin Finck DeviceDescription.MaximumLength = VpDeviceExtension->MaximumLength;
152*c2c66affSColin Finck
153*c2c66affSColin Finck /* Copy data from the internal device extension */
154*c2c66affSColin Finck DeviceDescription.BusNumber = DeviceExtension->SystemIoBusNumber;
155*c2c66affSColin Finck DeviceDescription.InterfaceType = DeviceExtension->AdapterInterfaceType;
156*c2c66affSColin Finck
157*c2c66affSColin Finck /* acquire dma adapter */
158*c2c66affSColin Finck DmaAdapter = IoGetDmaAdapter(DeviceExtension->PhysicalDeviceObject, &DeviceDescription, &NumberOfMapRegisters);
159*c2c66affSColin Finck if (!DmaAdapter)
160*c2c66affSColin Finck {
161*c2c66affSColin Finck /* failed to acquire dma */
162*c2c66affSColin Finck ExFreePool(Adapter);
163*c2c66affSColin Finck return NULL;
164*c2c66affSColin Finck }
165*c2c66affSColin Finck
166*c2c66affSColin Finck /* store dma adapter */
167*c2c66affSColin Finck Adapter->Adapter = DmaAdapter;
168*c2c66affSColin Finck
169*c2c66affSColin Finck /* store map register count */
170*c2c66affSColin Finck Adapter->MapRegisters = NumberOfMapRegisters;
171*c2c66affSColin Finck
172*c2c66affSColin Finck /* store hw device extension */
173*c2c66affSColin Finck Adapter->HwDeviceExtension = HwDeviceExtension;
174*c2c66affSColin Finck
175*c2c66affSColin Finck /* store in dma adapter list */
176*c2c66affSColin Finck InsertTailList(&DeviceExtension->DmaAdapterList, &Adapter->Entry);
177*c2c66affSColin Finck
178*c2c66affSColin Finck /* return result */
179*c2c66affSColin Finck return (PVP_DMA_ADAPTER)Adapter;
180*c2c66affSColin Finck }
181*c2c66affSColin Finck
182*c2c66affSColin Finck /*
183*c2c66affSColin Finck * @implemented
184*c2c66affSColin Finck */
185*c2c66affSColin Finck VOID
186*c2c66affSColin Finck NTAPI
VideoPortFreeCommonBuffer(IN PVOID HwDeviceExtension,IN ULONG Length,IN PVOID VirtualAddress,IN PHYSICAL_ADDRESS LogicalAddress,IN BOOLEAN CacheEnabled)187*c2c66affSColin Finck VideoPortFreeCommonBuffer(IN PVOID HwDeviceExtension,
188*c2c66affSColin Finck IN ULONG Length,
189*c2c66affSColin Finck IN PVOID VirtualAddress,
190*c2c66affSColin Finck IN PHYSICAL_ADDRESS LogicalAddress,
191*c2c66affSColin Finck IN BOOLEAN CacheEnabled)
192*c2c66affSColin Finck {
193*c2c66affSColin Finck PVIP_DMA_ADAPTER VpDmaAdapter;
194*c2c66affSColin Finck PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
195*c2c66affSColin Finck
196*c2c66affSColin Finck /* sanity check */
197*c2c66affSColin Finck ASSERT(!IsListEmpty(&DeviceExtension->DmaAdapterList));
198*c2c66affSColin Finck
199*c2c66affSColin Finck /* grab first dma adapter */
200*c2c66affSColin Finck VpDmaAdapter = (PVIP_DMA_ADAPTER)CONTAINING_RECORD(DeviceExtension->DmaAdapterList.Flink, VIP_DMA_ADAPTER, Entry);
201*c2c66affSColin Finck
202*c2c66affSColin Finck /* sanity checks */
203*c2c66affSColin Finck ASSERT(VpDmaAdapter->HwDeviceExtension == HwDeviceExtension);
204*c2c66affSColin Finck ASSERT(VpDmaAdapter->Adapter != NULL);
205*c2c66affSColin Finck ASSERT(VpDmaAdapter->MapRegisters != 0);
206*c2c66affSColin Finck
207*c2c66affSColin Finck VideoPortReleaseCommonBuffer(HwDeviceExtension, (PVP_DMA_ADAPTER)VpDmaAdapter, Length, LogicalAddress, VirtualAddress, CacheEnabled);
208*c2c66affSColin Finck }
209*c2c66affSColin Finck
210*c2c66affSColin Finck /*
211*c2c66affSColin Finck * @implemented
212*c2c66affSColin Finck */
213*c2c66affSColin Finck PVOID
214*c2c66affSColin Finck NTAPI
VideoPortGetCommonBuffer(IN PVOID HwDeviceExtension,IN ULONG DesiredLength,IN ULONG Alignment,OUT PPHYSICAL_ADDRESS LogicalAddress,OUT PULONG pActualLength,IN BOOLEAN CacheEnabled)215*c2c66affSColin Finck VideoPortGetCommonBuffer(IN PVOID HwDeviceExtension,
216*c2c66affSColin Finck IN ULONG DesiredLength,
217*c2c66affSColin Finck IN ULONG Alignment,
218*c2c66affSColin Finck OUT PPHYSICAL_ADDRESS LogicalAddress,
219*c2c66affSColin Finck OUT PULONG pActualLength,
220*c2c66affSColin Finck IN BOOLEAN CacheEnabled)
221*c2c66affSColin Finck {
222*c2c66affSColin Finck PVOID Result;
223*c2c66affSColin Finck PVIP_DMA_ADAPTER VpDmaAdapter;
224*c2c66affSColin Finck PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
225*c2c66affSColin Finck
226*c2c66affSColin Finck /* maximum palette size */
227*c2c66affSColin Finck if (DesiredLength > 262144)
228*c2c66affSColin Finck {
229*c2c66affSColin Finck /* size exceeded */
230*c2c66affSColin Finck return NULL;
231*c2c66affSColin Finck }
232*c2c66affSColin Finck
233*c2c66affSColin Finck if (IsListEmpty(&DeviceExtension->DmaAdapterList))
234*c2c66affSColin Finck {
235*c2c66affSColin Finck /* no adapter available */
236*c2c66affSColin Finck return NULL;
237*c2c66affSColin Finck }
238*c2c66affSColin Finck
239*c2c66affSColin Finck /* grab first dma adapter */
240*c2c66affSColin Finck VpDmaAdapter = (PVIP_DMA_ADAPTER)CONTAINING_RECORD(DeviceExtension->DmaAdapterList.Flink, VIP_DMA_ADAPTER, Entry);
241*c2c66affSColin Finck
242*c2c66affSColin Finck /* sanity checks */
243*c2c66affSColin Finck ASSERT(VpDmaAdapter->HwDeviceExtension == HwDeviceExtension);
244*c2c66affSColin Finck ASSERT(VpDmaAdapter->Adapter != NULL);
245*c2c66affSColin Finck ASSERT(VpDmaAdapter->MapRegisters != 0);
246*c2c66affSColin Finck
247*c2c66affSColin Finck /* allocate common buffer */
248*c2c66affSColin Finck Result = VideoPortAllocateCommonBuffer(HwDeviceExtension, (PVP_DMA_ADAPTER)VpDmaAdapter, DesiredLength, LogicalAddress, CacheEnabled, NULL);
249*c2c66affSColin Finck
250*c2c66affSColin Finck if (Result)
251*c2c66affSColin Finck {
252*c2c66affSColin Finck /* store length */
253*c2c66affSColin Finck *pActualLength = DesiredLength;
254*c2c66affSColin Finck }
255*c2c66affSColin Finck else
256*c2c66affSColin Finck {
257*c2c66affSColin Finck /* failed to allocate common buffer */
258*c2c66affSColin Finck *pActualLength = 0;
259*c2c66affSColin Finck }
260*c2c66affSColin Finck
261*c2c66affSColin Finck return Result;
262*c2c66affSColin Finck }
263*c2c66affSColin Finck
264*c2c66affSColin Finck /*
265*c2c66affSColin Finck * @implemented
266*c2c66affSColin Finck */
267*c2c66affSColin Finck BOOLEAN
268*c2c66affSColin Finck NTAPI
VideoPortUnmapDmaMemory(PVOID HwDeviceExtension,PVOID VirtualAddress,HANDLE ProcessHandle,PDMA BoardMemoryHandle)269*c2c66affSColin Finck VideoPortUnmapDmaMemory(
270*c2c66affSColin Finck PVOID HwDeviceExtension,
271*c2c66affSColin Finck PVOID VirtualAddress,
272*c2c66affSColin Finck HANDLE ProcessHandle,
273*c2c66affSColin Finck PDMA BoardMemoryHandle)
274*c2c66affSColin Finck {
275*c2c66affSColin Finck /* Deprecated */
276*c2c66affSColin Finck return FALSE;
277*c2c66affSColin Finck }
278*c2c66affSColin Finck
279*c2c66affSColin Finck /*
280*c2c66affSColin Finck * @implemented
281*c2c66affSColin Finck */
282*c2c66affSColin Finck PDMA
283*c2c66affSColin Finck NTAPI
VideoPortMapDmaMemory(IN PVOID HwDeviceExtension,IN PVIDEO_REQUEST_PACKET pVrp,IN PHYSICAL_ADDRESS BoardAddress,IN PULONG Length,IN PULONG InIoSpace,IN PVOID MappedUserEvent,IN PVOID DisplayDriverEvent,IN OUT PVOID * VirtualAddress)284*c2c66affSColin Finck VideoPortMapDmaMemory(IN PVOID HwDeviceExtension,
285*c2c66affSColin Finck IN PVIDEO_REQUEST_PACKET pVrp,
286*c2c66affSColin Finck IN PHYSICAL_ADDRESS BoardAddress,
287*c2c66affSColin Finck IN PULONG Length,
288*c2c66affSColin Finck IN PULONG InIoSpace,
289*c2c66affSColin Finck IN PVOID MappedUserEvent,
290*c2c66affSColin Finck IN PVOID DisplayDriverEvent,
291*c2c66affSColin Finck IN OUT PVOID *VirtualAddress)
292*c2c66affSColin Finck {
293*c2c66affSColin Finck /* Deprecated */
294*c2c66affSColin Finck return NULL;
295*c2c66affSColin Finck }
296*c2c66affSColin Finck
297*c2c66affSColin Finck /*
298*c2c66affSColin Finck * @implemented
299*c2c66affSColin Finck */
300*c2c66affSColin Finck VOID
301*c2c66affSColin Finck NTAPI
VideoPortSetDmaContext(IN PVOID HwDeviceExtension,OUT PDMA pDma,IN PVOID InstanceContext)302*c2c66affSColin Finck VideoPortSetDmaContext(IN PVOID HwDeviceExtension,
303*c2c66affSColin Finck OUT PDMA pDma,
304*c2c66affSColin Finck IN PVOID InstanceContext)
305*c2c66affSColin Finck {
306*c2c66affSColin Finck /* Deprecated */
307*c2c66affSColin Finck return;
308*c2c66affSColin Finck }
309*c2c66affSColin Finck
310*c2c66affSColin Finck /*
311*c2c66affSColin Finck * @implemented
312*c2c66affSColin Finck */
313*c2c66affSColin Finck BOOLEAN
314*c2c66affSColin Finck NTAPI
VideoPortSignalDmaComplete(IN PVOID HwDeviceExtension,IN PDMA pDmaHandle)315*c2c66affSColin Finck VideoPortSignalDmaComplete(IN PVOID HwDeviceExtension,
316*c2c66affSColin Finck IN PDMA pDmaHandle)
317*c2c66affSColin Finck {
318*c2c66affSColin Finck /* Deprecated */
319*c2c66affSColin Finck return FALSE;
320*c2c66affSColin Finck }
321*c2c66affSColin Finck
322*c2c66affSColin Finck
323*c2c66affSColin Finck BOOLEAN
324*c2c66affSColin Finck NTAPI
SyncScatterRoutine(IN PVOID Context)325*c2c66affSColin Finck SyncScatterRoutine(
326*c2c66affSColin Finck IN PVOID Context)
327*c2c66affSColin Finck {
328*c2c66affSColin Finck PDMA_START_CONTEXT StartContext = (PDMA_START_CONTEXT)Context;
329*c2c66affSColin Finck
330*c2c66affSColin Finck StartContext->ExecuteDmaRoutine(StartContext->HwDeviceExtension, StartContext->VpDmaAdapter, (PVP_SCATTER_GATHER_LIST)StartContext->ScatterGatherList, StartContext->Context);
331*c2c66affSColin Finck return TRUE;
332*c2c66affSColin Finck }
333*c2c66affSColin Finck
334*c2c66affSColin Finck VOID
335*c2c66affSColin Finck NTAPI
ScatterAdapterControl(IN PDEVICE_OBJECT * DeviceObject,IN PIRP * Irp,IN PSCATTER_GATHER_LIST ScatterGather,IN PVOID Context)336*c2c66affSColin Finck ScatterAdapterControl(
337*c2c66affSColin Finck IN PDEVICE_OBJECT *DeviceObject,
338*c2c66affSColin Finck IN PIRP *Irp,
339*c2c66affSColin Finck IN PSCATTER_GATHER_LIST ScatterGather,
340*c2c66affSColin Finck IN PVOID Context)
341*c2c66affSColin Finck {
342*c2c66affSColin Finck PDMA_START_CONTEXT StartContext = (PDMA_START_CONTEXT)Context;
343*c2c66affSColin Finck
344*c2c66affSColin Finck StartContext->ScatterGatherList = ScatterGather;
345*c2c66affSColin Finck
346*c2c66affSColin Finck VideoPortSynchronizeExecution(StartContext->HwDeviceExtension, VpMediumPriority, SyncScatterRoutine, StartContext);
347*c2c66affSColin Finck ExFreePool(StartContext);
348*c2c66affSColin Finck }
349*c2c66affSColin Finck
350*c2c66affSColin Finck /*
351*c2c66affSColin Finck * @implemented
352*c2c66affSColin Finck */
353*c2c66affSColin Finck VP_STATUS
354*c2c66affSColin Finck NTAPI
VideoPortStartDma(IN PVOID HwDeviceExtension,IN PVP_DMA_ADAPTER VpDmaAdapter,IN PVOID Mdl,IN ULONG Offset,IN OUT PULONG pLength,IN PEXECUTE_DMA ExecuteDmaRoutine,IN PVOID Context,IN BOOLEAN WriteToDevice)355*c2c66affSColin Finck VideoPortStartDma(IN PVOID HwDeviceExtension,
356*c2c66affSColin Finck IN PVP_DMA_ADAPTER VpDmaAdapter,
357*c2c66affSColin Finck IN PVOID Mdl,
358*c2c66affSColin Finck IN ULONG Offset,
359*c2c66affSColin Finck IN OUT PULONG pLength,
360*c2c66affSColin Finck IN PEXECUTE_DMA ExecuteDmaRoutine,
361*c2c66affSColin Finck IN PVOID Context,
362*c2c66affSColin Finck IN BOOLEAN WriteToDevice)
363*c2c66affSColin Finck {
364*c2c66affSColin Finck NTSTATUS Status;
365*c2c66affSColin Finck KIRQL OldIrql;
366*c2c66affSColin Finck PDMA_START_CONTEXT StartContext;
367*c2c66affSColin Finck PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
368*c2c66affSColin Finck PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
369*c2c66affSColin Finck
370*c2c66affSColin Finck StartContext = ExAllocatePool(NonPagedPool, sizeof(DMA_START_CONTEXT));
371*c2c66affSColin Finck if (!StartContext)
372*c2c66affSColin Finck {
373*c2c66affSColin Finck return ERROR_NOT_ENOUGH_MEMORY;
374*c2c66affSColin Finck }
375*c2c66affSColin Finck
376*c2c66affSColin Finck StartContext->Context = Context;
377*c2c66affSColin Finck StartContext->ExecuteDmaRoutine = ExecuteDmaRoutine;
378*c2c66affSColin Finck StartContext->HwDeviceExtension = HwDeviceExtension;
379*c2c66affSColin Finck StartContext->VpDmaAdapter = VpDmaAdapter;
380*c2c66affSColin Finck
381*c2c66affSColin Finck KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
382*c2c66affSColin Finck
383*c2c66affSColin Finck Status = Adapter->Adapter->DmaOperations->GetScatterGatherList(Adapter->Adapter,
384*c2c66affSColin Finck DeviceExtension->PhysicalDeviceObject,
385*c2c66affSColin Finck Mdl,
386*c2c66affSColin Finck MmGetSystemAddressForMdl((PMDL)Mdl),
387*c2c66affSColin Finck MmGetMdlByteCount((PMDL)Mdl),
388*c2c66affSColin Finck (PDRIVER_LIST_CONTROL)ScatterAdapterControl,
389*c2c66affSColin Finck StartContext,
390*c2c66affSColin Finck WriteToDevice);
391*c2c66affSColin Finck
392*c2c66affSColin Finck KeLowerIrql(OldIrql);
393*c2c66affSColin Finck
394*c2c66affSColin Finck if (!NT_SUCCESS(Status))
395*c2c66affSColin Finck {
396*c2c66affSColin Finck *pLength = 0;
397*c2c66affSColin Finck ExFreePool(StartContext);
398*c2c66affSColin Finck Status = ERROR_NOT_ENOUGH_MEMORY;
399*c2c66affSColin Finck }
400*c2c66affSColin Finck else
401*c2c66affSColin Finck {
402*c2c66affSColin Finck Status = NO_ERROR;
403*c2c66affSColin Finck }
404*c2c66affSColin Finck
405*c2c66affSColin Finck /* Return status */
406*c2c66affSColin Finck return Status;
407*c2c66affSColin Finck }
408*c2c66affSColin Finck
409*c2c66affSColin Finck /*
410*c2c66affSColin Finck * @implemented
411*c2c66affSColin Finck */
412*c2c66affSColin Finck PVOID
413*c2c66affSColin Finck NTAPI
VideoPortGetDmaContext(IN PVOID HwDeviceExtension,IN PDMA pDma)414*c2c66affSColin Finck VideoPortGetDmaContext(IN PVOID HwDeviceExtension,
415*c2c66affSColin Finck IN PDMA pDma)
416*c2c66affSColin Finck {
417*c2c66affSColin Finck /* Deprecated */
418*c2c66affSColin Finck return NULL;
419*c2c66affSColin Finck }
420*c2c66affSColin Finck
421*c2c66affSColin Finck /*
422*c2c66affSColin Finck * @implemented
423*c2c66affSColin Finck */
424*c2c66affSColin Finck PDMA
425*c2c66affSColin Finck NTAPI
VideoPortDoDma(IN PVOID HwDeviceExtension,IN PDMA pDma,IN DMA_FLAGS DmaFlags)426*c2c66affSColin Finck VideoPortDoDma(IN PVOID HwDeviceExtension,
427*c2c66affSColin Finck IN PDMA pDma,
428*c2c66affSColin Finck IN DMA_FLAGS DmaFlags)
429*c2c66affSColin Finck {
430*c2c66affSColin Finck /* Deprecated */
431*c2c66affSColin Finck return NULL;
432*c2c66affSColin Finck }
433*c2c66affSColin Finck
434*c2c66affSColin Finck /*
435*c2c66affSColin Finck * @implemented
436*c2c66affSColin Finck */
437*c2c66affSColin Finck PDMA
438*c2c66affSColin Finck NTAPI
VideoPortAssociateEventsWithDmaHandle(IN PVOID HwDeviceExtension,IN OUT PVIDEO_REQUEST_PACKET pVrp,IN PVOID MappedUserEvent,IN PVOID DisplayDriverEvent)439*c2c66affSColin Finck VideoPortAssociateEventsWithDmaHandle(IN PVOID HwDeviceExtension,
440*c2c66affSColin Finck IN OUT PVIDEO_REQUEST_PACKET pVrp,
441*c2c66affSColin Finck IN PVOID MappedUserEvent,
442*c2c66affSColin Finck IN PVOID DisplayDriverEvent)
443*c2c66affSColin Finck {
444*c2c66affSColin Finck /* Deprecated */
445*c2c66affSColin Finck return NULL;
446*c2c66affSColin Finck }
447*c2c66affSColin Finck
448*c2c66affSColin Finck /*
449*c2c66affSColin Finck * @implemented
450*c2c66affSColin Finck */
451*c2c66affSColin Finck VP_STATUS
452*c2c66affSColin Finck NTAPI
VideoPortCompleteDma(IN PVOID HwDeviceExtension,IN PVP_DMA_ADAPTER VpDmaAdapter,IN PVP_SCATTER_GATHER_LIST VpScatterGather,IN BOOLEAN WriteToDevice)453*c2c66affSColin Finck VideoPortCompleteDma(IN PVOID HwDeviceExtension,
454*c2c66affSColin Finck IN PVP_DMA_ADAPTER VpDmaAdapter,
455*c2c66affSColin Finck IN PVP_SCATTER_GATHER_LIST VpScatterGather,
456*c2c66affSColin Finck IN BOOLEAN WriteToDevice)
457*c2c66affSColin Finck {
458*c2c66affSColin Finck KIRQL OldIrql;
459*c2c66affSColin Finck PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
460*c2c66affSColin Finck
461*c2c66affSColin Finck KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
462*c2c66affSColin Finck Adapter->Adapter->DmaOperations->PutScatterGatherList(Adapter->Adapter, (PSCATTER_GATHER_LIST)VpScatterGather, WriteToDevice);
463*c2c66affSColin Finck KeLowerIrql(OldIrql);
464*c2c66affSColin Finck
465*c2c66affSColin Finck return NO_ERROR;
466*c2c66affSColin Finck }
467