ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dma.c
Go to the documentation of this file.
00001 /*
00002     Routines to simplify the use of DMA for Sound Blaster driver
00003 */
00004 
00005 #include <ntddk.h>
00006 #include "sndblst.h"
00007 
00008 #if 0
00009 BOOLEAN CheckDMA(PDEVICE_EXTENSION Device)
00010 {
00011     // Don't forget to check for Compaq machines (they can't be configured
00012     // manually...)
00013 
00014     return TRUE;    // for now...
00015 
00016 // if (! CompaqBA)
00017 // return (BOOLEAN) !((INPORT(pHw, BOARD_ID) & 0x80) && Device->DMA == 0);
00018 // else
00019 // {
00020 //    UCHAR CompaqPIDR;
00021 //    UCHAR Expected = (UCHAR)(Device->DMA == 0 ? 0x40 :
00022 //                             Device->DMA == 1 ? 0x80 :
00023 //                             0xc0);
00024 // CompaqPIDR = READ_PORT_UCHAR(pHw->CompaqBA + BOARD_ID);
00025 // if (CompaqPIDR != 0xff)
00026 // {
00027 //    if ((UCHAR)(CompaqPIDR & 0xc0) == Expected)
00028 //        return true;
00029 // }
00030 // }
00031 
00032     return FALSE;
00033 }
00034 #endif
00035 
00036 
00037 static IO_ALLOCATION_ACTION NTAPI SoundProgramDMA(
00038     IN PDEVICE_OBJECT DeviceObject,
00039     IN PIRP Irp,
00040     IN PVOID MapRegisterBase,
00041     IN PVOID Context)
00042 {
00043     PDEVICE_EXTENSION Device = DeviceObject->DeviceExtension;
00044     ULONG zzz;
00045     PUCHAR VirtualAddress = (PUCHAR) MmGetMdlVirtualAddress(Device->Mdl);
00046 
00047     DPRINT("IoMapTransfer\n");
00048     IoMapTransfer(Device->Adapter,
00049                     Device->Mdl,
00050                     MapRegisterBase,
00051                     (PUCHAR) MmGetMdlVirtualAddress(Device->Mdl),
00052                     &Device->BufferSize,    // is this right?
00053                     TRUE);
00054 
00055     DPRINT("VBuffer == 0x%x (really 0x%x?) Bufsize == %u\n", Device->VirtualBuffer, MmGetPhysicalAddress(Device->VirtualBuffer), Device->BufferSize);
00056 
00057     DPRINT("Writing %u bytes of garbage...\n", Device->BufferSize);
00058     // Write some garbage:
00059     for (zzz = 0; zzz < Device->BufferSize; zzz ++)
00060         *(VirtualAddress + zzz) = (UCHAR) zzz % 200;
00061 
00062     DPRINT("done\n");
00063 
00064     KeSetEvent(Context, 0, FALSE);
00065 
00066     return KeepObject;
00067 }
00068 
00069 
00070 BOOLEAN CreateDMA(PDEVICE_OBJECT DeviceObject)
00071 {
00072     DEVICE_DESCRIPTION Desc;
00073     ULONG MappedRegs = 0;
00074     PDEVICE_EXTENSION Device = DeviceObject->DeviceExtension;
00075     KEVENT DMAEvent;
00076     KIRQL OldIrql;
00077 
00078     // Buffersize should already be set but it isn't yet !
00079     Device->BufferSize = SB_BUFSIZE;
00080     DPRINT("Bufsize == %u\n", Device->BufferSize);
00081 
00082     RtlZeroMemory(&Desc, sizeof(DEVICE_DESCRIPTION));
00083 
00084     // Init memory!
00085     Desc.Version = DEVICE_DESCRIPTION_VERSION;
00086     Desc.Master = FALSE;    // Slave
00087     Desc.ScatterGather = FALSE; // Don't think so anyway
00088     Desc.DemandMode = FALSE;    // == !SingleModeDMA
00089     Desc.AutoInitialize = TRUE; // ?
00090     Desc.Dma32BitAddresses = FALSE; // I don't think we can
00091     Desc.IgnoreCount = FALSE; // Should be OK
00092     Desc.Reserved1 = 0;
00093 //    Desc.Reserved2 = 0;
00094     Desc.BusNumber = 0;
00095     Desc.DmaChannel = Device->DMA;    // Our channel :)
00096     Desc.InterfaceType = Isa;   // (BusType == MicroChannel) ? MicroChannel : Isa;
00097     Desc.DmaWidth = 0;    // hmm... 8 bits?
00098     Desc.DmaSpeed = 0;     // double hmm (Compatible it should be)
00099     Desc.MaximumLength = Device->BufferSize;
00100 //    Desc.MinimumLength = 0;
00101     Desc.DmaPort = 0;
00102 
00103     DPRINT("Calling HalGetAdapter(), asking for %d mapped regs\n", MappedRegs);
00104 
00105     Device->Adapter = HalGetAdapter(&Desc, &MappedRegs);
00106 
00107     DPRINT("Called\n");
00108 
00109     if (! Device->Adapter)
00110     {
00111         DPRINT("HalGetAdapter() FAILED\n");
00112         return FALSE;
00113     }
00114 
00115     DPRINT("Bufsize == %u\n", Device->BufferSize);
00116 
00117     if (MappedRegs < BYTES_TO_PAGES(Device->BufferSize))
00118     {
00119         DPRINT("Could only allocate %u mapping registers\n", MappedRegs);
00120 
00121         if (MappedRegs == 0)
00122             return FALSE;
00123 
00124         Device->BufferSize = MappedRegs * PAGE_SIZE;
00125         DPRINT("Bufsize == %u\n", Device->BufferSize);
00126     }
00127 
00128     DPRINT("Allocated %u mapping registers\n", MappedRegs);
00129 
00130     // Check if we already have memory here...
00131 
00132     // Check to make sure we're >= minimum
00133 
00134     DPRINT("Allocating buffer\n");
00135 
00136     DPRINT("Bufsize == %u\n", Device->BufferSize);
00137 
00138     Device->VirtualBuffer = HalAllocateCommonBuffer(Device->Adapter, Device->BufferSize,
00139                                                 &Device->Buffer, FALSE);
00140 
00141     // For some reason BufferSize == 0 here?!
00142 //    DPRINT("Buffer == 0x%x Bufsize == %u\n", Device->Buffer, Device->BufferSize);
00143     DPRINT("Bufsize == %u,", Device->BufferSize);
00144     DPRINT("Buffer == 0x%x\n", Device->Buffer);
00145 
00146     if (! Device->VirtualBuffer)
00147     {
00148         DPRINT("Could not allocate buffer :(\n");
00149         // should try again with smaller buffer...
00150         return FALSE;
00151     }
00152 
00153 //    DPRINT("Buffer == 0x%x Bufsize == %u\n", Device->Buffer, Device->BufferSize);
00154     DPRINT("Bufsize == %u,", Device->BufferSize);
00155     DPRINT("Buffer == 0x%x\n", Device->Buffer);
00156 
00157     DPRINT("Calling IoAllocateMdl()\n");
00158     Device->Mdl = IoAllocateMdl(Device->VirtualBuffer, Device->BufferSize, FALSE, FALSE, NULL);
00159     DPRINT("Bufsize == %u\n", Device->BufferSize);
00160 
00161     // IS THIS RIGHT:
00162     if (! Device->Mdl)
00163     {
00164         DPRINT("IoAllocateMdl() FAILED\n");
00165         // Free the HAL buffer
00166         return FALSE;
00167     }
00168 
00169     DPRINT("VBuffer == 0x%x Mdl == %u Bufsize == %u\n", Device->VirtualBuffer, Device->Mdl, Device->BufferSize);
00170 
00171     DPRINT("Calling MmBuildMdlForNonPagedPool\n");
00172     MmBuildMdlForNonPagedPool(Device->Mdl);
00173 
00174     DPRINT("Bufsize == %u\n", Device->BufferSize);
00175 
00176     // part II:
00177     KeInitializeEvent(&DMAEvent, SynchronizationEvent, FALSE);
00178     // Raise IRQL
00179     KeRaiseIrql(DISPATCH_LEVEL,&OldIrql);
00180     IoAllocateAdapterChannel(Device->Adapter, DeviceObject,
00181                             BYTES_TO_PAGES(Device->BufferSize),
00182                             SoundProgramDMA, &DMAEvent);
00183     // Lower IRQL
00184     KeLowerIrql(OldIrql);
00185     DPRINT("VBuffer == 0x%x Bufsize == %u\n", Device->VirtualBuffer, Device->BufferSize);
00186     KeWaitForSingleObject(&DMAEvent, Executive, KernelMode, FALSE, NULL);
00187 
00188 
00189 //    if (MappedRegs == 0)
00190 //        MappedRegs = 2;
00191 //    else
00192 //        MappedRegs ++;
00193 
00194 
00195 //    Status = IoAllocateAdapterChannel(
00196 //                    Adapter,
00197 //                    DeviceObject,
00198 //                    MappedRegs,
00199 //                    CALLBACK,
00200 //                    DeviceObject); // Context
00201     return TRUE;
00202 }
00203 

Generated on Sun May 27 2012 04:27:59 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.