Subject: Adding bus_space_{peek,poke}_N() to bus_space(9)
To: None <>
From: Steve Woodford <>
List: tech-kern
Date: 11/22/2000 17:11:40

I'd like to extend the bus_space(9) specification with the addition of MI
functions for cautiously reading/writing bus space, taking care to avoid
causing a kernel panic if there is no hardware backing the target address.
Those of you familiar with Solaris will recognise this as ddi_peekN() and

Right now, some supposedly MI drivers (i.e. in sys/dev/*) assume that a
bus_space_handle_t can be cast to caddr_t and passed to the MD badaddr()
function. This kind of goes against the grain. ;-)

I propose the following new functions, where `N' is 1, 2, 4 and 8:

	int bus_space_peek_N(bus_space_tag_t tag,
		bus_space_handle_t handle,
		bus_size_t offset,
		u_intN_t *valuep);

	int bus_space_poke_N(bus_space_tag_t tag,
		bus_space_handle_t handle,
		bus_size_t offset,
		u_intN_t value);

These will return zero if the read/write succeeded, otherwise non-zero if
the hardware terminated the cycle with an error (eg. a bus error). In the
case of `read', the location pointed to by `valuep' will contain the data
read. In the case of `write', the data written is `value'.

Right now, I'm not sure whether a `handle' is really necessary here since
the functions will mostly be used in a driver's XX_match() routine before
bus_space_map(9) is called. c.f. vme_probe() in the MI VMEbus space code.

Alternatively, the above functions don't change but are supplemented by a
bus_space_probe() function similar to vme_probe():

	int bus_space_probe(bus_space_tag_t tag,
		bus_addr_t offset,
		bus_size_t size,
		int (*callback)(void *, bus_space_tag_t,
		void *arg);

Where `size' is 1, 2, 4 or 8. The caller has the option of specifying a
callback function which performs the access using  bus_space_{read,write}().
bus_space_probe() will map and unmap the specified address space on the
fly and, if necessary, ensure the callback function won't cause a panic.
If no callback is specified, the function will perform a bus_space_read_N()
where `N' is the value passed in `size'.

I'm happy to update the man pages for bus_space(9) with these additions,
but I'll leave the implementation for each affected bus (apart from those
on mvme68k) up to others.


Cheers, Steve