ReactOS 0.4.15-dev-7887-g64a59a1
dma.c File Reference
#include <ntddk.h>
#include "sndblst.h"
Include dependency graph for dma.c:

Go to the source code of this file.

Functions

static IO_ALLOCATION_ACTION NTAPI SoundProgramDMA (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context)
 
BOOLEAN CreateDMA (PDEVICE_OBJECT DeviceObject)
 

Function Documentation

◆ CreateDMA()

BOOLEAN CreateDMA ( PDEVICE_OBJECT  DeviceObject)

Definition at line 70 of file dma.c.

71{
73 ULONG MappedRegs = 0;
74 PDEVICE_EXTENSION Device = DeviceObject->DeviceExtension;
75 KEVENT DMAEvent;
77
78 // Buffersize should already be set but it isn't yet !
79 Device->BufferSize = SB_BUFSIZE;
80 DPRINT("Bufsize == %u\n", Device->BufferSize);
81
82 RtlZeroMemory(&Desc, sizeof(DEVICE_DESCRIPTION));
83
84 // Init memory!
86 Desc.Master = FALSE; // Slave
87 Desc.ScatterGather = FALSE; // Don't think so anyway
88 Desc.DemandMode = FALSE; // == !SingleModeDMA
89 Desc.AutoInitialize = TRUE; // ?
90 Desc.Dma32BitAddresses = FALSE; // I don't think we can
91 Desc.IgnoreCount = FALSE; // Should be OK
92 Desc.Reserved1 = 0;
93// Desc.Reserved2 = 0;
94 Desc.BusNumber = 0;
95 Desc.DmaChannel = Device->DMA; // Our channel :)
96 Desc.InterfaceType = Isa; // (BusType == MicroChannel) ? MicroChannel : Isa;
97 Desc.DmaWidth = 0; // hmm... 8 bits?
98 Desc.DmaSpeed = 0; // double hmm (Compatible it should be)
99 Desc.MaximumLength = Device->BufferSize;
100// Desc.MinimumLength = 0;
101 Desc.DmaPort = 0;
102
103 DPRINT("Calling HalGetAdapter(), asking for %d mapped regs\n", MappedRegs);
104
105 Device->Adapter = HalGetAdapter(&Desc, &MappedRegs);
106
107 DPRINT("Called\n");
108
109 if (! Device->Adapter)
110 {
111 DPRINT("HalGetAdapter() FAILED\n");
112 return FALSE;
113 }
114
115 DPRINT("Bufsize == %u\n", Device->BufferSize);
116
117 if (MappedRegs < BYTES_TO_PAGES(Device->BufferSize))
118 {
119 DPRINT("Could only allocate %u mapping registers\n", MappedRegs);
120
121 if (MappedRegs == 0)
122 return FALSE;
123
124 Device->BufferSize = MappedRegs * PAGE_SIZE;
125 DPRINT("Bufsize == %u\n", Device->BufferSize);
126 }
127
128 DPRINT("Allocated %u mapping registers\n", MappedRegs);
129
130 // Check if we already have memory here...
131
132 // Check to make sure we're >= minimum
133
134 DPRINT("Allocating buffer\n");
135
136 DPRINT("Bufsize == %u\n", Device->BufferSize);
137
138 Device->VirtualBuffer = HalAllocateCommonBuffer(Device->Adapter, Device->BufferSize,
139 &Device->Buffer, FALSE);
140
141 // For some reason BufferSize == 0 here?!
142// DPRINT("Buffer == 0x%x Bufsize == %u\n", Device->Buffer, Device->BufferSize);
143 DPRINT("Bufsize == %u,", Device->BufferSize);
144 DPRINT("Buffer == 0x%x\n", Device->Buffer);
145
146 if (! Device->VirtualBuffer)
147 {
148 DPRINT("Could not allocate buffer :(\n");
149 // should try again with smaller buffer...
150 return FALSE;
151 }
152
153// DPRINT("Buffer == 0x%x Bufsize == %u\n", Device->Buffer, Device->BufferSize);
154 DPRINT("Bufsize == %u,", Device->BufferSize);
155 DPRINT("Buffer == 0x%x\n", Device->Buffer);
156
157 DPRINT("Calling IoAllocateMdl()\n");
158 Device->Mdl = IoAllocateMdl(Device->VirtualBuffer, Device->BufferSize, FALSE, FALSE, NULL);
159 DPRINT("Bufsize == %u\n", Device->BufferSize);
160
161 // IS THIS RIGHT:
162 if (! Device->Mdl)
163 {
164 DPRINT("IoAllocateMdl() FAILED\n");
165 // Free the HAL buffer
166 return FALSE;
167 }
168
169 DPRINT("VBuffer == 0x%x Mdl == %u Bufsize == %u\n", Device->VirtualBuffer, Device->Mdl, Device->BufferSize);
170
171 DPRINT("Calling MmBuildMdlForNonPagedPool\n");
173
174 DPRINT("Bufsize == %u\n", Device->BufferSize);
175
176 // part II:
178 // Raise IRQL
181 BYTES_TO_PAGES(Device->BufferSize),
182 SoundProgramDMA, &DMAEvent);
183 // Lower IRQL
185 DPRINT("VBuffer == 0x%x Bufsize == %u\n", Device->VirtualBuffer, Device->BufferSize);
187
188
189// if (MappedRegs == 0)
190// MappedRegs = 2;
191// else
192// MappedRegs ++;
193
194
195// Status = IoAllocateAdapterChannel(
196// Adapter,
197// DeviceObject,
198// MappedRegs,
199// CALLBACK,
200// DeviceObject); // Context
201 return TRUE;
202}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static IO_ALLOCATION_ACTION NTAPI SoundProgramDMA(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context)
Definition: dma.c:37
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define IoAllocateMdl
Definition: fxmdl.h:88
PVOID NTAPI HalAllocateCommonBuffer(IN PADAPTER_OBJECT AdapterObject, IN ULONG Length, IN PPHYSICAL_ADDRESS LogicalAddress, IN BOOLEAN CacheEnabled)
Definition: dma.c:46
PADAPTER_OBJECT NTAPI HalGetAdapter(IN PDEVICE_DESCRIPTION DeviceDescription, OUT PULONG NumberOfMapRegisters)
Definition: dma.c:22
@ Isa
Definition: hwresource.cpp:138
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
Definition: mdlsup.c:424
#define KernelMode
Definition: asm.h:34
@ SynchronizationEvent
NTSTATUS NTAPI IoAllocateAdapterChannel(IN PADAPTER_OBJECT AdapterObject, IN PDEVICE_OBJECT DeviceObject, IN ULONG NumberOfMapRegisters, IN PDRIVER_CONTROL ExecutionRoutine, IN PVOID Context)
Definition: adapter.c:30
#define SB_BUFSIZE
Definition: sndblst.h:41
#define DPRINT
Definition: sndvol32.h:71
DMA_SPEED DmaSpeed
Definition: iotypes.h:2082
BOOLEAN IgnoreCount
Definition: iotypes.h:2075
BOOLEAN ScatterGather
Definition: iotypes.h:2071
BOOLEAN AutoInitialize
Definition: iotypes.h:2073
DMA_WIDTH DmaWidth
Definition: iotypes.h:2081
INTERFACE_TYPE InterfaceType
Definition: iotypes.h:2080
BOOLEAN Dma32BitAddresses
Definition: iotypes.h:2074
BOOLEAN DemandMode
Definition: iotypes.h:2072
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define DEVICE_DESCRIPTION_VERSION
Definition: iotypes.h:2063
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
@ Executive
Definition: ketypes.h:415
#define BYTES_TO_PAGES(Size)

Referenced by InitDevice().

◆ SoundProgramDMA()

static IO_ALLOCATION_ACTION NTAPI SoundProgramDMA ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  MapRegisterBase,
IN PVOID  Context 
)
static

Definition at line 37 of file dma.c.

42{
43 PDEVICE_EXTENSION Device = DeviceObject->DeviceExtension;
44 ULONG zzz;
46
47 DPRINT("IoMapTransfer\n");
48 IoMapTransfer(Device->Adapter,
49 Device->Mdl,
52 &Device->BufferSize, // is this right?
53 TRUE);
54
55 DPRINT("VBuffer == 0x%x (really 0x%x?) Bufsize == %u\n", Device->VirtualBuffer, MmGetPhysicalAddress(Device->VirtualBuffer), Device->BufferSize);
56
57 DPRINT("Writing %u bytes of garbage...\n", Device->BufferSize);
58 // Write some garbage:
59 for (zzz = 0; zzz < Device->BufferSize; zzz ++)
60 *(VirtualAddress + zzz) = (UCHAR) zzz % 200;
61
62 DPRINT("done\n");
63
65
66 return KeepObject;
67}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
PHYSICAL_ADDRESS NTAPI IoMapTransfer(IN PADAPTER_OBJECT AdapterObject, IN PMDL Mdl, IN PVOID MapRegisterBase, IN PVOID CurrentVa, IN OUT PULONG Length, IN BOOLEAN WriteToDevice)
Definition: dma.c:144
PHYSICAL_ADDRESS NTAPI MmGetPhysicalAddress(IN PVOID Address)
Definition: stubs.c:685
unsigned char * PUCHAR
Definition: typedefs.h:53
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
_Inout_ struct _IRP _In_ PVOID MapRegisterBase
Definition: iotypes.h:213
@ KeepObject
Definition: iotypes.h:202
#define MmGetMdlVirtualAddress(_Mdl)
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by CreateDMA().