Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Jun 2013 12:56:15 +0200
From:      Robert Millan <rmh@freebsd.org>
To:        Niclas Zeising <zeising@freebsd.org>, Bruce Evans <brde@optusnet.com.au>
Cc:        arch@freebsd.org
Subject:   Re: Bus space routines
Message-ID:  <CAOfDtXNWMO-D1D9UAcvG_nhv4uqMQmrpEvsPd-PAEB1-FdoXtA@mail.gmail.com>
In-Reply-To: <51C0345E.4000309@freebsd.org>
References:  <51C0345E.4000309@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi Niclas,

Thank you for bringing this up.

2013/6/18 Niclas Zeising <zeising@freebsd.org>
> In a first incarnation it used the bus_space* routines, see
> this patch:
>
> http://trillian.chruetertee.ch/ports/browser/trunk/devel/libpciaccess/files/patch-src-freebsd_pci.c?rev=591

Yes, this was my original patch. I wrote it to fix a problem on
GNU/kFreeBSD. As always, I took care to do things in a way that would
be likely to work on FreeBSD as well (rather than, e.g. using
<sys/io.h>).

> This was later changed to use the in*/out* macros directly, with the
> motivation that the bus_space* functions is a KPI that shouldn't be used
> in userland.  See following for an updated patch:
>
> http://trillian.chruetertee.ch/ports/browser/trunk/devel/libpciaccess/files/patch-src-freebsd_pci.c?rev=815

Actually, based on previous discussion my understanding was that it's
in*/out* which wasn't ment to be used in userland:

http://lists.freebsd.org/pipermail/freebsd-arch/2012-March/012470.html

I'm adding Bruce Evans to CC, as he participated in that thread. I
expect he can provide some insight.

> The problem is that the in*/out* macros differ between FreeBSD and
> Debian/kFreeBSD, and Debian/kFreeBSD want to switch back to use
> bus_space* again.

Well, there's part of truth in this, but it's not quite the point I
was trying to make.

Yes, GNU/kFreeBSD is an hybrid system, and as such in some cases it is
forced to support two namespaces, because sometimes the semantics from
each system just don't get along:

>>>>  FreeBSD code: outw(port, data);
>>>>  Glibc code: outw(data, port);

We can cope with this problem (mostly) by forcing programs into the
namespace they were expecting.

But this is IMHO a more general issue, and is not just relevant to
GNU/kFreeBSD. The problem is: what happens when someone reuses this
code somewhere else?

Then we're in for some very ugly trouble. Undefined I/O behaviour is
not something I'd like to happen without notice simply because I
ported some code from one system to another.

I think the BSD world did the right thing by introducing new
semantics. Plus they're also more portable (on the hardware sense),
have a look, e.g.:

static __inline void
bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsh,
                       bus_size_t offset, u_int8_t value)
{

        if (tag == X86_BUS_SPACE_IO)
                outb(bsh + offset, value);
        else
                *(volatile u_int8_t *)(bsh + offset) = value;
}

So why not just use those? It seems very natural to me that if you
have something which is unambigous and reliable, you use this instead
of something else which is prone to nasty errors.

--
Robert Millan



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOfDtXNWMO-D1D9UAcvG_nhv4uqMQmrpEvsPd-PAEB1-FdoXtA>