Subject: Re: Appropriate use of bus_space_vaddr()
To: None <tech-kern@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: tech-kern
Date: 02/25/2004 17:04:48
In article <4926614F7A31D411820F00D0B74FF7E003EAEBE8@RDC03>,
McGranaghan, Sean <SMcGranaghan@vanteon.com> 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
>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?
No they are not equivalent. The former will not work on architectures
that have specific instructions to do I/O (no memory mapped I/O).
christos