SAMPLE: DMA in Windows 3.0Last reviewed: February 15, 1996Article ID: Q63937 |
The information in this article applies to:
SUMMARYDMA requires special handling in the different modes of Windows version 3.0. The main concern of this article is the virtualization of the DMA ports that is done by the enhanced-mode Windows. In real mode, DMA can be programmed and performed as usual, as in a normal DOS application. This article addresses the following topics:
MORE INFORMATION
DMA in Enhanced ModeIn enhanced mode, standard (on AT-type machines) DMA channels are virtualized. The Virtual DMA Device (VDMAD) translates (or maps) the linear address to the physical address. As long as an application program can obtain a linear address that is less than 24 bits, it can program the standard DMA channels using the linear address as a physical address. For example, programs (such as MS-DOS-based applications) running in Virtual 86 mode can program the standard DMA channels as they can in real mode. The linear address in the Virtual 86 mode is calculated as (segment<<4)+offset. When this address is used on the standard DMA channels, it is translated (mapped) by the Virtual DMA Device. In other words, the translation is done transparently through I/O virtualization. However, there are two situations when an application cannot rely on VDMAD to do the translation:
To use VDS lock region services, an application needs to know either the virtual address selector(segment):offset or the linear address. The linear address in protected mode can be obtained using GetSelectorBase() (see below for more information). Please be advised that due to a problem in Windows 3.0, it is sometimes necessary to perform GlobalPageLock() on the DMA regions before using the VDS locking services. [See the Windows SDK reference for GlobalPageLock().] Note that a program should disable the DMA translation using the VDS enable/disable translation service before it uses the physical address to program the standard DMA channels. It should enable the translation after the DMA channel is programmed. The following is information about the DMABUFFERSIZE switch in SYSTEM.INI. In enhanced-mode Windows, when an application relies on VDMAD to do the translation, VDMAD may use a buffer it has allocated during initialization time to remap the DMA region. This buffer has a default size of 16K. The size may be changed to a larger one by setting the switch DMABUFFERSIZE in SYSTEM.INI to a value greater than 16. If a DMA region that requires remapping has a size greater than that of the allocated remapping buffer, Windows will crash and ask the user to set the DMABUFFERSIZE switch to a greater value. It is the application's responsibility to inform the user about this and have the user modify the SYSTEM.INI switch beforehand. The Virtual DMA Specification supported by Windows enhanced mode and standard mode can be found in the Microsoft Software Library. Download VDS.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:
Filename Description -------- ----------- DMA_API.DOC Virtual DMA Specification in Microsoft Word format WINDOC.STY Style sheet used by DMA_API.DOC DMA_API.TXT The same specification in text format DMA in Standard ModeVDS services are also provided in Windows standard mode. Windows-based applications can utilize the same services to do DMA in standard mode as in enhanced mode. MS-DOS-based applications running under standard-mode Windows may not have access to VDS services. Because MS-DOS-based applications are running in real mode, they should do the DMA programming as they would in the MS-DOS environment. It is also possible for applications running in standard mode Windows to perform DMA without using VDS. This is because in standard mode, the linear address is the same as the physical address, the memory is contiguous, and memory addressing is limited to 24 bits (the 16 MB address space limit of the 80286 processor). Also, there is no virtualization on the DMA I/O ports, or other I/O ports in standard mode. The Windows-based application should obtain the linear address of the DMA region and program the DMA directly. To obtain the linear address, the application should call GetSelectorBase() to obtain the base address first. GetSelectorBase() is documented in the Windows SDK reference.
DWORD dwBase ; WORD wSelector ; DWORD dwPhyAddr ; wSelector = (WORD)(lpBuffer >> 16) ; // selector of the buffer address. dwBase = GetSelectorBase (wSelector) ; dwPhyAddr = dwBase + (0x0000FFFF & lpBuffer) ; // base + offsetNote that although dwPhyAddr is a 32-bit variable, only the lower 24 bits will be nonzero. The 80286 can only address up to 24 bits of address space. The DMA controller can usually take 24 bits. If it can only take up to 20 bits, GlobalDOSAlloc() should be used to allocate the memory. GlobalDOSAlloc() allocates memory within the first 1 MB range. Please see the SDK reference for information on GlobalDOSAlloc(). Memory allocated in standard mode is physically contiguous. However, it is the application program's responsibility to make sure the memory block does not overlap a segment boundary. Most DMA controllers wrap around when they reach a segment boundary. The application program should break the DMA transfer into two smaller transfers in this case: the first transfer ends at the segment boundary and the second one begins at the segment boundary.
|
Additional reference words: 3.00 softlib VDS.EXE
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |