Date: Fri, 8 Dec 95 13:08:53 GMT From: Neil Jarvis To: djgpp AT sun DOT soe DOT clarkson DOT edu Subject: Getting the physical address of allocated virtual memory Reply-To: Neil DOT Jarvis AT proteon DOT com I am writing an application that interfaces with a number of PC interface cards. These cards use DMA to transfer data to and from the PC's memory, and therefore require to know the physical address of the data. They are programmed via IO, and are not memory-mapped. I am using DJGPP-V2Beta3 and CWSDPMI-Beta8, cross-compiling the application on a Sun using gcc 2.7.1. Works like a treat! Currently the application uses "_go32_dpmi_allocate_dos_memory" to allocate data buffers below 1Mb, because I can derive the physical address from the rm_segment value returned by this function. Data in these buffers is accessed by the application using : _farsetsel(_go32_conventional_mem_selector()) _farnspeekb() and _farnspokeb() Everything works beautifully. In the final configuration however, the PC will be populated with more cards, requiring more data buffers to be allocated. These data buffers are not small. Unfortunately the scheme I described above is limited to allocating buffers from the free memory below 1Mb - currently about 400-500k. The full configuration will require between 1 and 3Mb of data transfer area! My problem is that I do not know exactly how to allocate regions of memory above 1Mb and below 16Mb (the address range the adapter cards can DMA to/from), such that the application can access the data, and calculate the physical address of any of the data to tell the adapter cards how to program their DMA operations. What I require, is the ability to allocate virtual memory in the 1Mb to 16Mb range, lock this area into physical memory, and be able to get hold of the physical memory address of the region allocated. The thoughts I have had so far are : 1) Use __dpmi_allocate_linear_memory() to allocate a block of data. Then use __dpmi_map_device_in_memory_block() to locate this block of data at a well known location between 1Mb and 16Mb. I can then tell the PC adapter cards the physical address of this well known location. I can create the necessary functions to allocate and deallocate these well known locations. Questions: How can I stop these areas of physical memory being used by the PC, DPMI memory allocator etc. ? Do I need to lock the linear memory? How do I lock the areas? Will this approach work? Does DJGPP-V2/CWSDPMI support the approach? 2) Use __dpmi_physical_address_mapping() instead of the linear_memory functions described in 1). Again, the same questions apply. 3) Some other way? I have read the FAQ, and investigated the example programs vbe.zip and sb03_dj2.zip for clues, but I believe the descriptions of how to access memory mapped devices do not solve my problem. Any and all help will be greatly appreciated. -- Neil Jarvis, Proteon International, York R&D (Neil DOT Jarvis AT proteon DOT com) -- -- Avoid tumbling off the cliff of triteness into the black abyss of -- overused metaphors. --