From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,20b5c48bcc4c4594 X-Google-Attributes: gidfee84,public From: Monty Brandenberg Subject: Re: How to pin memory in a limited physical address range in driver? Date: 1998/02/19 Message-ID: <34EBD3AF.E4D3D7F3@ne.mediaone.net>#1/1 X-Deja-AN: 326500228 Content-Transfer-Encoding: 7bit References: <6cdt1t$ndv$1@nnrp1.dejanews.com> Mime-Version: 1.0 Reply-To: mcbinc@ne.mediaone.net.MAPS To: apachexm@usa.net Content-Type: text/plain; charset=us-ascii Organization: MCB, Inc. Newsgroups: comp.unix.osf.osf1 I don't have all the docs at hand but I can answer a few of your questions immediately... apachexm@usa.net wrote: > > Can anyone tell me how to pin memory in a limited physical address range > in device driver in Digital UNIX 4.0? > I am learning to develop device driver in Digital UNIX. > One task of the driver is to pre-allocate and then pin memory for > performing DMA operation on it. Because the bits number of DMA > register is limited. We can only use memory below some physical memory. > > I have only some documents downloaded from Digital's Web site. > I found in the reference of device driver that contig_malloc() and > MALLOC() can be used to allocate memory in device driver. > But who can tell me in detail the difference between them? contig_malloc returns physically and virtually contiguous wired (pinned) kernel-allocated memory. MALLOC returns physically discontiguous, virtually contiguous wired kernel-allocated memory. contig_malloc has additional restrictions and capabilities for which docs are needed. > > contig_malloc() seems can allocate memory in a limited address range, > but is the address it returns the physical or virtual address? My recollection, which needs to be verified, is that it returns a kseg address. Address space lecture: There are several relevant address spaces when writing a device driver. The first is the obvious physical address space of memory on the system. Smallish numbers generally below, oh, 16GB or so. There are several virtual address spaces: process (usual program task addresses), kseg (kernel segment addresses that look like 0xfffffc0x.xxxxxxxx which map directly to physical without requiring a page table entry), and kva (a.k.a. sva: the basic kernel virtual address). Finally, there are the bus address spaces which describe for each bus how addresses map to hardware, other buses, or memory back in the system. There is an assortment of functions to convert among these, some being very static (kseg<>physical) and some very dynamic and transitory (process<>bus). You didn't mention what bus your device uses but, in general, you'll need to use the dma map functions (dma_map_alloc, map_load, map_unload, and map_free) to establish a mapping from the bus address space to a physical or kernel virtual (kseg or kva) address. Additionally, if the dma source/target is a process address, it must first be wired (pinned) using vm_map_pageable. The dma_map functions provide some control over the bus mapping which is critical to you as these are the addresses which your dma engine must generate. Read the docs. > Should we use contig_malloc() or MALLOC() to allocate memory for > DMA operation? Depends on a number of factors. If you want your dma engine to move large amounts of data (multiple pages) in a single request and the engine has no concept of a scatter/gather map, then you need a bus-space contiguous mapping for your buffer. You can get this with contig_malloc and a 'direct' dma_map function or MALLOC() and a scatter/gather dma_map function (using pci capabilities as an example). > Can we use vm_map_pageable() to pin memory for a very > long time? Yes. But you *must* *must* *must* unwire the memory before the process address space is destroyed as the result of exit() or other cleanup. If the vm finds wired addresses in a process map being destroyed, it will panic. There is a process-exit registry function which is very poorly documented but essential for interesting drivers (I think). > Can anyone tell me how to get detail explanation of the > 'type' parameter of contig_malloc() and MALLOC()? I believe it is strictly informative. Used to leave magic dribbles around a system and in a crashdump for postmortem analysis. -- Monty Brandenberg, Software Consultant MCB, Inc. mcbinc@ne.mediaone.net.MAPS P.O. Box 426188 mcbinc@world.std.com.MAPS Cambridge, MA 02142 617.864.6907