Subject: Re: Appropriate use of bus_space_vaddr()
To: McGranaghan, Sean <SMcGranaghan@vanteon.com>
From: Manuel Bouyer <bouyer@antioche.eu.org>
List: netbsd-help
Date: 02/25/2004 22:26:10
On Wed, Feb 25, 2004 at 11:56:35AM -0500, McGranaghan, Sean wrote:
> 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
The bus_space_barrier() functions should help with this, but I think
currently any bus_space_read*() or bus_space_write*() do an implicit barrier()
> 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);
The problem with the first form is that it won't work on all hardware.
If your driver is going to be MI, you have to use the second form.
--
Manuel Bouyer <bouyer@antioche.eu.org>
NetBSD: 26 ans d'experience feront toujours la difference
--