Subject: questions about mmap() device memory
To: None <tech-kern@netbsd.org>
From: Michael C. Richardson <mcr@sandelman.ottawa.on.ca>
List: tech-kern
Date: 11/26/1998 17:59:20
  I have a device with several hundred kilobytes of memory on it.

  It lives on a PCI card, and I map it into my driver with pci_mapreg_map().

  I would like, mostly for debugging purposes, to allow a user process
to mmap() it. 
  
  From what I can understand about the *mmap() entry point in the raw 
device table, I am expected to return a physical memory address. (So why
is the return type "int" rather than "caddr_t"?)
 
  Now, how does this interact with bus.h?

  I realize that there may be PCI buses which can *not* map memory into
the addresses of the CPU, and the bus macros deal with this in some way that
I'm not supposed to know about it. I'm happy just to fail on those
architectures (examples?).
  I think I need to use the bus_dma*() stuff, but I'm not quite certain about
this. I don't need to allocate the memory, so I don't want to call
bus_dmamem_alloc() to get memory to pass to bus_dmamem_map().

  Clearly, the pccons.c and pxvt do this. But they don't do it in a 
bus_space way.
  From what I can see, wscons' dev/ic/vga.c currently punts:

static int
vga_mmap(v, offset, prot)
	void *v;
	off_t offset;
	int prot;
{

	/* XXX */
	return -1;
}

  From looking at the alpha cfb driver, it also does it in a MD way.
  ... wait what is this? dev/tc/cfb.c also exists. Aha.

  Is machine_btop() the right formula then?

   :!mcr!:            |  Network and security consulting/contract programming
   Michael Richardson |         Firewalls, TCP/IP and Unix administration
 Personal: http://www.sandelman.ottawa.on.ca/People/Michael_Richardson/Bio.html
 Corporate: http://www.sandelman.ottawa.on.ca/SSW/
	ON HUMILITY: To err is human, to moo bovine.