ReactOS 0.4.16-dev-91-g764881a
dma.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Videoport
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/drivers/videoprt/dma.c
5 * PURPOSE: Videoport Direct Memory Access Support
6 * PROGRAMMERS: ...
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <videoprt.h>
12
13#define NDEBUG
14#include <debug.h>
15
16typedef struct
17{
22
24
25typedef struct
26{
32
34
35
36/* PUBLIC FUNCTIONS ***********************************************************/
37
38/*
39 * @implemented
40 */
44 IN PVP_DMA_ADAPTER VpDmaAdapter,
45 IN ULONG DesiredLength,
46 OUT PPHYSICAL_ADDRESS LogicalAddress,
47 IN BOOLEAN CacheEnabled,
49{
50 PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
51
52 /* check for valid arguments */
53 if (!Adapter || !Adapter->Adapter)
54 {
55 /* invalid parameter */
56 return NULL;
57 }
58
59 /* allocate common buffer */
60 return Adapter->Adapter->DmaOperations->AllocateCommonBuffer(Adapter->Adapter, DesiredLength, LogicalAddress, CacheEnabled);
61}
62
63/*
64 * @implemented
65 */
66VOID
69 IN PVP_DMA_ADAPTER VpDmaAdapter,
71 IN PHYSICAL_ADDRESS LogicalAddress,
73 IN BOOLEAN CacheEnabled)
74{
75 PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
76
77 /* check for valid arguments */
78 if (!Adapter || !Adapter->Adapter)
79 {
80 /* invalid parameter */
81 return;
82 }
83
84 /* release common buffer */
85 Adapter->Adapter->DmaOperations->FreeCommonBuffer(Adapter->Adapter, Length, LogicalAddress, VirtualAddress, CacheEnabled);
86}
87
88/*
89 * @implemented
90 */
91VOID
94 IN PVP_DMA_ADAPTER VpDmaAdapter)
95{
96 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
97 PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
98
99 /* get hw device extension */
100 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
101
102 /* sanity check */
103 ASSERT(!IsListEmpty(&DeviceExtension->DmaAdapterList));
104
105 /* remove dma adapter from list */
106 RemoveEntryList(&Adapter->Entry);
107
108 /* release dma adapter */
109 Adapter->Adapter->DmaOperations->PutDmaAdapter(Adapter->Adapter);
110
111 /* free memory */
112 ExFreePool(Adapter);
113}
114
115/*
116 * @implemented
117 */
119NTAPI
121 IN PVP_DEVICE_DESCRIPTION VpDeviceExtension)
122{
124 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
126 PVIP_DMA_ADAPTER Adapter;
127 PDMA_ADAPTER DmaAdapter;
128
129 /* allocate private adapter structure */
130 Adapter = ExAllocatePool(NonPagedPool, sizeof(VIP_DMA_ADAPTER));
131 if (!Adapter)
132 {
133 /* failed to allocate adapter structure */
134 return NULL;
135 }
136
137 /* Zero the structure */
139 sizeof(DEVICE_DESCRIPTION));
140
141 /* Initialize the structure */
143 DeviceDescription.Master = TRUE;
144 DeviceDescription.DmaWidth = Width8Bits;
145 DeviceDescription.DmaSpeed = Compatible;
146
147 /* Copy data from caller's device extension */
148 DeviceDescription.ScatterGather = VpDeviceExtension->ScatterGather;
149 DeviceDescription.Dma32BitAddresses = VpDeviceExtension->Dma32BitAddresses;
150 DeviceDescription.Dma64BitAddresses = VpDeviceExtension->Dma64BitAddresses;
151 DeviceDescription.MaximumLength = VpDeviceExtension->MaximumLength;
152
153 /* Copy data from the internal device extension */
154 DeviceDescription.BusNumber = DeviceExtension->SystemIoBusNumber;
155 DeviceDescription.InterfaceType = DeviceExtension->AdapterInterfaceType;
156
157 /* acquire dma adapter */
159 if (!DmaAdapter)
160 {
161 /* failed to acquire dma */
162 ExFreePool(Adapter);
163 return NULL;
164 }
165
166 /* store dma adapter */
167 Adapter->Adapter = DmaAdapter;
168
169 /* store map register count */
171
172 /* store hw device extension */
173 Adapter->HwDeviceExtension = HwDeviceExtension;
174
175 /* store in dma adapter list */
176 InsertTailList(&DeviceExtension->DmaAdapterList, &Adapter->Entry);
177
178 /* return result */
179 return (PVP_DMA_ADAPTER)Adapter;
180}
181
182/*
183 * @implemented
184 */
185VOID
186NTAPI
190 IN PHYSICAL_ADDRESS LogicalAddress,
191 IN BOOLEAN CacheEnabled)
192{
193 PVIP_DMA_ADAPTER VpDmaAdapter;
194 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
195
196 /* sanity check */
197 ASSERT(!IsListEmpty(&DeviceExtension->DmaAdapterList));
198
199 /* grab first dma adapter */
201
202 /* sanity checks */
203 ASSERT(VpDmaAdapter->HwDeviceExtension == HwDeviceExtension);
204 ASSERT(VpDmaAdapter->Adapter != NULL);
205 ASSERT(VpDmaAdapter->MapRegisters != 0);
206
207 VideoPortReleaseCommonBuffer(HwDeviceExtension, (PVP_DMA_ADAPTER)VpDmaAdapter, Length, LogicalAddress, VirtualAddress, CacheEnabled);
208}
209
210/*
211 * @implemented
212 */
213PVOID
214NTAPI
216 IN ULONG DesiredLength,
218 OUT PPHYSICAL_ADDRESS LogicalAddress,
219 OUT PULONG pActualLength,
220 IN BOOLEAN CacheEnabled)
221{
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 if (IsListEmpty(&DeviceExtension->DmaAdapterList))
234 {
235 /* no adapter available */
236 return NULL;
237 }
238
239 /* grab first dma adapter */
241
242 /* sanity checks */
243 ASSERT(VpDmaAdapter->HwDeviceExtension == HwDeviceExtension);
244 ASSERT(VpDmaAdapter->Adapter != NULL);
245 ASSERT(VpDmaAdapter->MapRegisters != 0);
246
247 /* allocate common buffer */
248 Result = VideoPortAllocateCommonBuffer(HwDeviceExtension, (PVP_DMA_ADAPTER)VpDmaAdapter, DesiredLength, LogicalAddress, CacheEnabled, NULL);
249
250 if (Result)
251 {
252 /* store length */
253 *pActualLength = DesiredLength;
254 }
255 else
256 {
257 /* failed to allocate common buffer */
258 *pActualLength = 0;
259 }
260
261 return Result;
262}
263
264/*
265 * @implemented
266 */
268NTAPI
270 PVOID HwDeviceExtension,
273 PDMA BoardMemoryHandle)
274{
275 /* Deprecated */
276 return FALSE;
277}
278
279/*
280 * @implemented
281 */
282PDMA
283NTAPI
286 IN PHYSICAL_ADDRESS BoardAddress,
288 IN PULONG InIoSpace,
289 IN PVOID MappedUserEvent,
290 IN PVOID DisplayDriverEvent,
292{
293 /* Deprecated */
294 return NULL;
295}
296
297/*
298 * @implemented
299 */
300VOID
301NTAPI
303 OUT PDMA pDma,
304 IN PVOID InstanceContext)
305{
306 /* Deprecated */
307 return;
308}
309
310/*
311 * @implemented
312 */
314NTAPI
316 IN PDMA pDmaHandle)
317{
318 /* Deprecated */
319 return FALSE;
320}
321
322
324NTAPI
327{
329
330 StartContext->ExecuteDmaRoutine(StartContext->HwDeviceExtension, StartContext->VpDmaAdapter, (PVP_SCATTER_GATHER_LIST)StartContext->ScatterGatherList, StartContext->Context);
331 return TRUE;
332}
333
334VOID
335NTAPI
338 IN PIRP *Irp,
341{
343
344 StartContext->ScatterGatherList = ScatterGather;
345
347 ExFreePool(StartContext);
348}
349
350/*
351 * @implemented
352 */
354NTAPI
355VideoPortStartDma(IN PVOID HwDeviceExtension,
356 IN PVP_DMA_ADAPTER VpDmaAdapter,
357 IN PVOID Mdl,
359 IN OUT PULONG pLength,
360 IN PEXECUTE_DMA ExecuteDmaRoutine,
363{
366 PDMA_START_CONTEXT StartContext;
367 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
368 PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
369
370 StartContext = ExAllocatePool(NonPagedPool, sizeof(DMA_START_CONTEXT));
371 if (!StartContext)
372 {
374 }
375
376 StartContext->Context = Context;
377 StartContext->ExecuteDmaRoutine = ExecuteDmaRoutine;
378 StartContext->HwDeviceExtension = HwDeviceExtension;
379 StartContext->VpDmaAdapter = VpDmaAdapter;
380
382
383 Status = Adapter->Adapter->DmaOperations->GetScatterGatherList(Adapter->Adapter,
384 DeviceExtension->PhysicalDeviceObject,
385 Mdl,
389 StartContext,
391
393
394 if (!NT_SUCCESS(Status))
395 {
396 *pLength = 0;
397 ExFreePool(StartContext);
399 }
400 else
401 {
403 }
404
405 /* Return status */
406 return Status;
407}
408
409/*
410 * @implemented
411 */
412PVOID
413NTAPI
415 IN PDMA pDma)
416{
417 /* Deprecated */
418 return NULL;
419}
420
421/*
422 * @implemented
423 */
424PDMA
425NTAPI
426VideoPortDoDma(IN PVOID HwDeviceExtension,
427 IN PDMA pDma,
428 IN DMA_FLAGS DmaFlags)
429{
430 /* Deprecated */
431 return NULL;
432}
433
434/*
435 * @implemented
436 */
437PDMA
438NTAPI
441 IN PVOID MappedUserEvent,
442 IN PVOID DisplayDriverEvent)
443{
444 /* Deprecated */
445 return NULL;
446}
447
448/*
449 * @implemented
450 */
452NTAPI
453VideoPortCompleteDma(IN PVOID HwDeviceExtension,
454 IN PVP_DMA_ADAPTER VpDmaAdapter,
455 IN PVP_SCATTER_GATHER_LIST VpScatterGather,
457{
459 PVIP_DMA_ADAPTER Adapter = (PVIP_DMA_ADAPTER)VpDmaAdapter;
460
462 Adapter->Adapter->DmaOperations->PutScatterGatherList(Adapter->Adapter, (PSCATTER_GATHER_LIST)VpScatterGather, WriteToDevice);
464
465 return NO_ERROR;
466}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_In_ PSCSI_REQUEST_BLOCK _In_opt_ PVOID _In_ ULONG _In_ BOOLEAN WriteToDevice
Definition: cdrom.h:992
_In_ PIRP Irp
Definition: csq.h:116
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NO_ERROR
Definition: dderror.h:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
PDMA_ADAPTER NTAPI IoGetDmaAdapter(IN PDEVICE_OBJECT PhysicalDeviceObject, IN PDEVICE_DESCRIPTION DeviceDescription, IN OUT PULONG NumberOfMapRegisters)
Definition: pnpdma.c:23
@ Width8Bits
Definition: miniport.h:105
@ Compatible
Definition: miniport.h:112
VPAPI BOOLEAN NTAPI VideoPortSynchronizeExecution(IN PVOID HwDeviceExtension, IN VIDEO_SYNCHRONIZE_PRIORITY Priority, IN PMINIPORT_SYNCHRONIZE_ROUTINE SynchronizeRoutine, IN PVOID Context)
LONG VP_STATUS
Definition: video.h:153
@ VpMediumPriority
Definition: video.h:536
struct __DMA_PARAMETERS * PDMA
Definition: video.h:158
enum _DMA_FLAGS DMA_FLAGS
VOID(NTAPI * PEXECUTE_DMA)(IN PVOID HwDeviceExtension, IN PVP_DMA_ADAPTER VpDmaAdapter, IN PVP_SCATTER_GATHER_LIST SGList, IN PVOID Context)
Definition: video.h:253
struct __VP_DMA_ADAPTER * PVP_DMA_ADAPTER
Definition: video.h:159
PVOID HwDeviceExtension
Definition: dma.c:27
PVP_DMA_ADAPTER VpDmaAdapter
Definition: dma.c:31
PEXECUTE_DMA ExecuteDmaRoutine
Definition: dma.c:29
PSCATTER_GATHER_LIST ScatterGatherList
Definition: dma.c:28
PVOID Context
Definition: dma.c:30
base of all file and directory entries
Definition: entries.h:83
LIST_ENTRY Entry
Definition: dma.c:18
PDMA_ADAPTER Adapter
Definition: dma.c:19
PVOID HwDeviceExtension
Definition: dma.c:21
ULONG MapRegisters
Definition: dma.c:20
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2295
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
PDEVICE_OBJECT PhysicalDeviceObject
Definition: videoprt.h:87
INTERFACE_TYPE AdapterInterfaceType
Definition: videoprt.h:98
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define VIDEO_PORT_GET_DEVICE_EXTENSION(MiniportExtension)
Definition: videoprt.h:140
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING DeviceDescription
Definition: wdfpdo.h:432
VOID NTAPI VideoPortPutDmaAdapter(IN PVOID HwDeviceExtension, IN PVP_DMA_ADAPTER VpDmaAdapter)
Definition: dma.c:93
PVP_DMA_ADAPTER NTAPI VideoPortGetDmaAdapter(IN PVOID HwDeviceExtension, IN PVP_DEVICE_DESCRIPTION VpDeviceExtension)
Definition: dma.c:120
VOID NTAPI ScatterAdapterControl(IN PDEVICE_OBJECT *DeviceObject, IN PIRP *Irp, IN PSCATTER_GATHER_LIST ScatterGather, IN PVOID Context)
Definition: dma.c:336
PVOID NTAPI VideoPortAllocateCommonBuffer(IN PVOID HwDeviceExtension, IN PVP_DMA_ADAPTER VpDmaAdapter, IN ULONG DesiredLength, OUT PPHYSICAL_ADDRESS LogicalAddress, IN BOOLEAN CacheEnabled, PVOID Reserved)
Definition: dma.c:43
BOOLEAN NTAPI VideoPortUnmapDmaMemory(PVOID HwDeviceExtension, PVOID VirtualAddress, HANDLE ProcessHandle, PDMA BoardMemoryHandle)
Definition: dma.c:269
VOID NTAPI VideoPortSetDmaContext(IN PVOID HwDeviceExtension, OUT PDMA pDma, IN PVOID InstanceContext)
Definition: dma.c:302
VP_STATUS 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)
Definition: dma.c:355
VP_STATUS NTAPI VideoPortCompleteDma(IN PVOID HwDeviceExtension, IN PVP_DMA_ADAPTER VpDmaAdapter, IN PVP_SCATTER_GATHER_LIST VpScatterGather, IN BOOLEAN WriteToDevice)
Definition: dma.c:453
PVOID NTAPI VideoPortGetCommonBuffer(IN PVOID HwDeviceExtension, IN ULONG DesiredLength, IN ULONG Alignment, OUT PPHYSICAL_ADDRESS LogicalAddress, OUT PULONG pActualLength, IN BOOLEAN CacheEnabled)
Definition: dma.c:215
PDMA NTAPI VideoPortDoDma(IN PVOID HwDeviceExtension, IN PDMA pDma, IN DMA_FLAGS DmaFlags)
Definition: dma.c:426
PDMA 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)
Definition: dma.c:284
PDMA NTAPI VideoPortAssociateEventsWithDmaHandle(IN PVOID HwDeviceExtension, IN OUT PVIDEO_REQUEST_PACKET pVrp, IN PVOID MappedUserEvent, IN PVOID DisplayDriverEvent)
Definition: dma.c:439
PVOID NTAPI VideoPortGetDmaContext(IN PVOID HwDeviceExtension, IN PDMA pDma)
Definition: dma.c:414
VOID NTAPI VideoPortFreeCommonBuffer(IN PVOID HwDeviceExtension, IN ULONG Length, IN PVOID VirtualAddress, IN PHYSICAL_ADDRESS LogicalAddress, IN BOOLEAN CacheEnabled)
Definition: dma.c:187
struct DMA_START_CONTEXT * PDMA_START_CONTEXT
struct VIP_DMA_ADAPTER * PVIP_DMA_ADAPTER
VOID NTAPI VideoPortReleaseCommonBuffer(IN PVOID HwDeviceExtension, IN PVP_DMA_ADAPTER VpDmaAdapter, IN ULONG Length, IN PHYSICAL_ADDRESS LogicalAddress, IN PVOID VirtualAddress, IN BOOLEAN CacheEnabled)
Definition: dma.c:68
BOOLEAN NTAPI VideoPortSignalDmaComplete(IN PVOID HwDeviceExtension, IN PDMA pDmaHandle)
Definition: dma.c:315
BOOLEAN NTAPI SyncScatterRoutine(IN PVOID Context)
Definition: dma.c:325
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
_Out_ PULONG NumberOfMapRegisters
Definition: halfuncs.h:209
struct _SCATTER_GATHER_LIST * PSCATTER_GATHER_LIST
Definition: iotypes.h:2204
#define DEVICE_DESCRIPTION_VERSION
Definition: iotypes.h:2063
DRIVER_LIST_CONTROL * PDRIVER_LIST_CONTROL
Definition: iotypes.h:2377
_In_ struct _IRP _In_ struct _SCATTER_GATHER_LIST * ScatterGather
Definition: iotypes.h:2375
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
#define MmGetMdlByteCount(_Mdl)
#define MmGetSystemAddressForMdl(Mdl)