Subject: Re: mmap'ing device driver memory
To: Jason Thorpe <thorpej@nas.nasa.gov>
From: Michael Richardson <mcr@solidum.com>
List: tech-kern
Date: 12/15/1998 17:18:03
>>>>> "Jason" == Jason Thorpe <thorpej@nas.nasa.gov> writes:

    Jason> On Mon, 14 Dec 1998 16:57:05 -0500 Michael Richardson
    Jason> <mcr@solidum.com> wrote:

    >> Am I correct that there is no call like "machine_ptob()" that can be
    >> used by MI device drivers that want to map memory that is on an
    >> expansion card (i.e. PCI) into user space?  I see that, for instance,
    >> the mmap() code for the VGA drivers is all MD.

    Jason> That's correct.  I have not finished my bus_space_mmap() proposal
    Jason> yet.

  AHA! Okay, I knew there was a missing piece.

    >> Second, due to lack of actual hardware, I'm simulating part of my
    >> card's memory with system ram. Is there something I should call other
    >> than than malloc() to get memory that is safe for mmap()'ing?

    Jason> See bus_dma(9).

  Not clear to me how to do this. I have to re-read.

    >> Or should I really switch to using the bus_dma stuff? It isn't clear
    >> to me how to do this although Jason's paper helped a lot...

    Jason> Take a look at e.g. the eap audio driver.

  Thanks for this.

 ...

  Okay, I've gotten things simulated with bus_dma(9) code.
  Is there some MD way to turn a bus_space_handle_t into a bus_dma_segment_t?
Or should I just stick to i386_ptob() for my actual 
  My impression is that I can probably just initialize the ds_addr/ds_len
fields... I guess the real challenge is that the bus_space_handle_t is
already mapped to kernel virtual address space, while I need to have the
physical address for both i386_ptob() and also for the bus_dmamem_map().

  Or, can I just skip mem_map? Hmm.

  ...

  It's a mess, but I finally just did this:
 
  	pmap = pmap_kernel();

	/*
	 * Get the physical address for this segment.
	 */
	curaddr = pmap_extract(pmap, (vaddr_t)sc->sc_pattmem);

	/* need to translate the bus_space_t to physical address */
	sc->sc_dmasegs[0].ds_addr = curaddr;
	sc->sc_dmasegs[0].ds_len  = sc->sc_pattmem_size;
	sc->sc_numsegs = 1;

  and it worked.

   :!mcr!:            |  Solidum Systems Corporation, http://www.solidum.com
   Michael Richardson |For a better connected world,where data flows faster<tm>
 Personal: mcr@sandelman.ottawa.on.ca. PGP key available.
 Corporate: <A HREF="mailto:mcr@solidum.com">mcr@solidum.com</A>.