Subject: Appropriate use of bus_space_vaddr()
To: 'netbsd-help@netbsd.org' <netbsd-help@netbsd.org>
From: McGranaghan, Sean <SMcGranaghan@vanteon.com>
List: tech-kern
Date: 02/25/2004 11:56:35
Hello,
I am writing a device driver and would like to know when it is appropriate
to use the bus_space_vaddr() function. I need to guarentee the ordering of
my read-modify-writes for the control registers I am manipulating. It would
be nice to setup a few register pointers via bus_space_vaddr() and use
regular C operators. For example, given that sc->iot and sc->ioh are mapped
to the base address of a set of control registers:
#define rCTRLREG(b) (*(b + REG_OFFSET))
vaddr_t b;
b = (vaddr_t) bus_space_vaddr(sc->sc_iot, sc->ioh);
rCTRLREG(b) |= BITMSK;
Seems preferable to:
u_int32_t value;
value = bus_space_read_4(sc->sc_iot, sc->ioh, REG_OFFSET);
value |= BITMSK;
bus_space_write_4(sc->sc_iot, sc->ioh, offset, REG_OFFSET);
Are these equivalent? Do I need to specify a barrier after my
read-modify-write? I have searched through several existing drivers and
bus_space_vaddr() seems used rarely. There is a warning about its use in the
bus_space(9) man page so I am cautious. Is there any convention for how
bus_space_vaddr() is used?
Any help is appcreciated,
Sean