2 * PROJECT: ReactOS Videoport
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/video/videoprt/dma.c
5 * PURPOSE: Videoport Direct Memory Access Support
9 /* INCLUDES ******************************************************************/
20 }VIP_DMA_ADAPTER
, *PVIP_DMA_ADAPTER
;
24 PVOID HwDeviceExtension
;
25 PSCATTER_GATHER_LIST ScatterGatherList
;
26 PEXECUTE_DMA ExecuteDmaRoutine
;
28 PVP_DMA_ADAPTER VpDmaAdapter
;
30 }DMA_START_CONTEXT
, *PDMA_START_CONTEXT
;
33 /* PUBLIC FUNCTIONS ***********************************************************/
40 VideoPortAllocateCommonBuffer(IN PVOID HwDeviceExtension
,
41 IN PVP_DMA_ADAPTER VpDmaAdapter
,
42 IN ULONG DesiredLength
,
43 OUT PPHYSICAL_ADDRESS LogicalAddress
,
44 IN BOOLEAN CacheEnabled
,
47 PVIP_DMA_ADAPTER Adapter
= (PVIP_DMA_ADAPTER
)VpDmaAdapter
;
50 return Adapter
->Adapter
->DmaOperations
->AllocateCommonBuffer(Adapter
->Adapter
, DesiredLength
, LogicalAddress
, CacheEnabled
);
58 VideoPortReleaseCommonBuffer(IN PVOID HwDeviceExtension
,
59 IN PVP_DMA_ADAPTER VpDmaAdapter
,
61 IN PHYSICAL_ADDRESS LogicalAddress
,
62 IN PVOID VirtualAddress
,
63 IN BOOLEAN CacheEnabled
)
65 PVIP_DMA_ADAPTER Adapter
= (PVIP_DMA_ADAPTER
)VpDmaAdapter
;
67 Adapter
->Adapter
->DmaOperations
->FreeCommonBuffer(Adapter
->Adapter
, Length
, LogicalAddress
, VirtualAddress
, CacheEnabled
);
75 VideoPortPutDmaAdapter(IN PVOID HwDeviceExtension
,
76 IN PVP_DMA_ADAPTER VpDmaAdapter
)
78 PVIP_DMA_ADAPTER Adapter
= (PVIP_DMA_ADAPTER
)VpDmaAdapter
;
80 Adapter
->Adapter
->DmaOperations
->PutDmaAdapter(Adapter
->Adapter
);
89 VideoPortGetDmaAdapter(IN PVOID HwDeviceExtension
,
90 IN PVP_DEVICE_DESCRIPTION VpDeviceExtension
)
92 DEVICE_DESCRIPTION DeviceDescription
;
93 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
94 ULONG NumberOfMapRegisters
;
95 PVIP_DMA_ADAPTER Adapter
;
96 PDMA_ADAPTER DmaAdapter
;
98 /* Zero the structure */
99 RtlZeroMemory(&DeviceDescription
,
100 sizeof(DEVICE_DESCRIPTION
));
102 /* Initialize the structure */
103 DeviceDescription
.Version
= DEVICE_DESCRIPTION_VERSION
;
104 DeviceDescription
.Master
= TRUE
/* ?? */;
105 DeviceDescription
.DmaWidth
= Width8Bits
;
106 DeviceDescription
.DmaSpeed
= Compatible
;
108 /* Copy data from caller's device extension */
109 DeviceDescription
.ScatterGather
= VpDeviceExtension
->ScatterGather
;
110 DeviceDescription
.Dma32BitAddresses
= VpDeviceExtension
->Dma32BitAddresses
;
111 DeviceDescription
.Dma64BitAddresses
= VpDeviceExtension
->Dma64BitAddresses
;
112 DeviceDescription
.MaximumLength
= VpDeviceExtension
->MaximumLength
;
114 /* Copy data from the internal device extension */
115 DeviceDescription
.BusNumber
= DeviceExtension
->SystemIoBusNumber
;
116 DeviceDescription
.InterfaceType
= DeviceExtension
->AdapterInterfaceType
;
118 Adapter
= ExAllocatePool(NonPagedPool
, sizeof(VIP_DMA_ADAPTER
));
123 DmaAdapter
= IoGetDmaAdapter(DeviceExtension
->PhysicalDeviceObject
, &DeviceDescription
, &NumberOfMapRegisters
);
130 Adapter
->Adapter
= DmaAdapter
;
131 Adapter
->MapRegisters
= NumberOfMapRegisters
;
133 return (PVP_DMA_ADAPTER
)Adapter
;
141 VideoPortFreeCommonBuffer(IN PVOID HwDeviceExtension
,
143 IN PVOID VirtualAddress
,
144 IN PHYSICAL_ADDRESS LogicalAddress
,
145 IN BOOLEAN CacheEnabled
)
147 DEVICE_DESCRIPTION DeviceDescription
;
148 PVP_DMA_ADAPTER VpDmaAdapter
;
150 /* FIXME: Broken code*/
151 VpDmaAdapter
= VideoPortGetDmaAdapter(HwDeviceExtension
,
152 (PVP_DEVICE_DESCRIPTION
)&DeviceDescription
);
153 HalFreeCommonBuffer((PADAPTER_OBJECT
)VpDmaAdapter
,
165 VideoPortGetCommonBuffer(IN PVOID HwDeviceExtension
,
166 IN ULONG DesiredLength
,
168 OUT PPHYSICAL_ADDRESS LogicalAddress
,
169 OUT PULONG pActualLength
,
170 IN BOOLEAN CacheEnabled
)
181 VideoPortUnmapDmaMemory(
182 PVOID HwDeviceExtension
,
183 PVOID VirtualAddress
,
184 HANDLE ProcessHandle
,
185 PDMA BoardMemoryHandle
)
196 VideoPortMapDmaMemory(IN PVOID HwDeviceExtension
,
197 IN PVIDEO_REQUEST_PACKET pVrp
,
198 IN PHYSICAL_ADDRESS BoardAddress
,
201 IN PVOID MappedUserEvent
,
202 IN PVOID DisplayDriverEvent
,
203 IN OUT PVOID
*VirtualAddress
)
214 VideoPortSetDmaContext(IN PVOID HwDeviceExtension
,
216 IN PVOID InstanceContext
)
227 VideoPortSignalDmaComplete(IN PVOID HwDeviceExtension
,
240 PDMA_START_CONTEXT StartContext
= (PDMA_START_CONTEXT
)Context
;
242 StartContext
->ExecuteDmaRoutine(StartContext
->HwDeviceExtension
, StartContext
->VpDmaAdapter
, (PVP_SCATTER_GATHER_LIST
)StartContext
->ScatterGatherList
, StartContext
->Context
);
248 ScatterAdapterControl(
249 IN PDEVICE_OBJECT
*DeviceObject
,
251 IN PSCATTER_GATHER_LIST ScatterGather
,
254 PDMA_START_CONTEXT StartContext
= (PDMA_START_CONTEXT
)Context
;
256 StartContext
->ScatterGatherList
= ScatterGather
;
258 VideoPortSynchronizeExecution(StartContext
->HwDeviceExtension
, VpMediumPriority
, SyncScatterRoutine
, StartContext
);
259 ExFreePool(StartContext
);
267 VideoPortStartDma(IN PVOID HwDeviceExtension
,
268 IN PVP_DMA_ADAPTER VpDmaAdapter
,
271 IN OUT PULONG pLength
,
272 IN PEXECUTE_DMA ExecuteDmaRoutine
,
274 IN BOOLEAN WriteToDevice
)
278 PDMA_START_CONTEXT StartContext
;
279 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension
= VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension
);
280 PVIP_DMA_ADAPTER Adapter
= (PVIP_DMA_ADAPTER
)VpDmaAdapter
;
282 StartContext
= ExAllocatePool(NonPagedPool
, sizeof(DMA_START_CONTEXT
));
285 return ERROR_NOT_ENOUGH_MEMORY
;
288 StartContext
->Context
= Context
;
289 StartContext
->ExecuteDmaRoutine
= ExecuteDmaRoutine
;
290 StartContext
->HwDeviceExtension
= HwDeviceExtension
;
291 StartContext
->VpDmaAdapter
= VpDmaAdapter
;
293 KeRaiseIrql(DISPATCH_LEVEL
, &OldIrql
);
295 Status
= Adapter
->Adapter
->DmaOperations
->GetScatterGatherList(Adapter
->Adapter
,
296 DeviceExtension
->PhysicalDeviceObject
,
298 MmGetSystemAddressForMdl((PMDL
)Mdl
),
299 MmGetMdlByteCount((PMDL
)Mdl
),
300 (PDRIVER_LIST_CONTROL
)ScatterAdapterControl
,
304 KeLowerIrql(OldIrql
);
306 if (!NT_SUCCESS(Status
))
309 ExFreePool(StartContext
);
310 Status
= ERROR_NOT_ENOUGH_MEMORY
;
326 VideoPortGetDmaContext(IN PVOID HwDeviceExtension
,
338 VideoPortDoDma(IN PVOID HwDeviceExtension
,
340 IN DMA_FLAGS DmaFlags
)
351 VideoPortAssociateEventsWithDmaHandle(IN PVOID HwDeviceExtension
,
352 IN OUT PVIDEO_REQUEST_PACKET pVrp
,
353 IN PVOID MappedUserEvent
,
354 IN PVOID DisplayDriverEvent
)
365 VideoPortCompleteDma(IN PVOID HwDeviceExtension
,
366 IN PVP_DMA_ADAPTER VpDmaAdapter
,
367 IN PVP_SCATTER_GATHER_LIST VpScatterGather
,
368 IN BOOLEAN WriteToDevice
)
371 PVIP_DMA_ADAPTER Adapter
= (PVIP_DMA_ADAPTER
)VpDmaAdapter
;
373 KeRaiseIrql(DISPATCH_LEVEL
, &OldIrql
);
374 Adapter
->Adapter
->DmaOperations
->PutScatterGatherList(Adapter
->Adapter
, (PSCATTER_GATHER_LIST
)VpScatterGather
, WriteToDevice
);
375 KeLowerIrql(OldIrql
);