Subject: Re: Proposal to alter VM interfaces for bus.h mmap support
To: None <tech-kern@NetBSD.ORG, thorpej@nas.nasa.gov>
From: Chris Torek <torek@BSDI.COM>
List: tech-kern
Date: 09/03/1997 17:46:13
I am pushing for a similar (but slightly different flavor) change
to the VM and pmap code for BSD/OS.

There are several things wrong here, and they mostly descend from
a small but fundamental error in the VM code.  In particular, the
type "vm_offset_t" should not exist at all.  (My standard question:
what is this an offset *from*?  The very name is a lie; it is an
absolute address.)

There need to be at least two, and maybe three, separate types:

	- A "physical address" type (physadr_t).  This could be
	  (and should be on the sun3, sun4, sun4c, sun4m, etc) a
	  structured type; e.g., the sun4m has a 36-bit physical
	  address that can be viewed as a four-bit "space" and a
	  32-bit "address".  This might also carry around special
	  bits like "I am a device and need to be non-cached and
	  I cause side effects" (this is overloading the notion
	  of an address a bit, but by the time you are talking
	  about a *particular* physadr, as opposed to physadrs
	  in general, they do acquire these sorts of semantics).

	- A "virtual address" type.  This may need to be split into:
		- kernel virtual address (kva_t?)
		- user virtual address (uva_t?)
	  It helps keep code size and interface proliferation down
	  if these two are a single type, but for some 64-bit
	  machines, it might be better to split them, with the
	  kernel using only 32 bits of addressing.

The virtual address type is really just "char *", "caddr_t", or
"void *", except that a lot of code needs to manipulate it as an
integer (e.g., to find page offsets).

Device mmap functions should also be able to make use of "big page"
TLB entries.  I am not sure how this "ought" to be done, but at
the least, the device mmap entry point must be able to view the
overall mmap() call, rather than just receiving information one
(small) page at a time.

The physadr_t (possibly structured) type is probably best passed
around via pointers, and (e.g.) the bw2 or cg3 device should have
a "physadr_t sc_phys" field that it gets MD code to fill in at
attach time.  When mapping that device, its mmap routine ought
to be able to fill in a new physadr_t by calling an MD function,
passing the original physadr_t and the offset; the code for most
machines is:

	void frob_pa(physadr_t *out_pa, physadr_t *in_pa, some_type offset)
	{

	#ifdef CONTROL_BITS
		/* space and control bits are unchanged */
		out_pa->space_and_ctl = in_pa->space_and_ctl;
	#endif

		/* address part just gets an offset added */
		out_pa->addr_part = in_pa->addr_part + offset;
	}

Chris