Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* How to pin memory in a limited physical address range in driver?
@ 1998-02-17  5:00 apachexm
  1998-02-19  5:00 ` Monty Brandenberg
  0 siblings, 1 reply; 2+ messages in thread
From: apachexm @ 1998-02-17  5:00 UTC (permalink / raw)



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() seems can allocate memory in a limited address range,
but is the address it returns the physical or virtual address?
Should we use contig_malloc() or MALLOC() to allocate memory for
DMA operation?
Can we use vm_map_pageable() to pin memory for a very
long time?
Can anyone tell me how to get detail explanation of the
'type' parameter of contig_malloc() and MALLOC()?

I am new to Digital UNIX. And it is some different than the traditional
SYSV. Sorry for my asking so many questions.

Any help are welcomed! Thanks!

apachexm@usa.net

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to pin memory in a limited physical address range in driver?
  1998-02-17  5:00 How to pin memory in a limited physical address range in driver? apachexm
@ 1998-02-19  5:00 ` Monty Brandenberg
  0 siblings, 0 replies; 2+ messages in thread
From: Monty Brandenberg @ 1998-02-19  5:00 UTC (permalink / raw)
  To: apachexm


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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1998-02-19  5:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-02-17  5:00 How to pin memory in a limited physical address range in driver? apachexm
1998-02-19  5:00 ` Monty Brandenberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox