From owner-freebsd-arch@FreeBSD.ORG Tue Jun 18 11:13:53 2013 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id CF977727; Tue, 18 Jun 2013 11:13:53 +0000 (UTC) (envelope-from marius@alchemy.franken.de) Received: from alchemy.franken.de (alchemy.franken.de [194.94.249.214]) by mx1.freebsd.org (Postfix) with ESMTP id 57D4B1FED; Tue, 18 Jun 2013 11:13:53 +0000 (UTC) Received: from alchemy.franken.de (localhost [127.0.0.1]) by alchemy.franken.de (8.14.6/8.14.6/ALCHEMY.FRANKEN.DE) with ESMTP id r5IBDpZU044128; Tue, 18 Jun 2013 13:13:51 +0200 (CEST) (envelope-from marius@alchemy.franken.de) Received: (from marius@localhost) by alchemy.franken.de (8.14.6/8.14.6/Submit) id r5IBDpg5044127; Tue, 18 Jun 2013 13:13:51 +0200 (CEST) (envelope-from marius) Date: Tue, 18 Jun 2013 13:13:51 +0200 From: Marius Strobl To: Niclas Zeising Subject: Re: Bus space routines Message-ID: <20130618111351.GA43938@alchemy.franken.de> References: <51C0345E.4000309@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <51C0345E.4000309@freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: arch@freebsd.org X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jun 2013 11:13:53 -0000 On Tue, Jun 18, 2013 at 12:20:14PM +0200, Niclas Zeising wrote: > This has been discussed before [1], but there seem to still be a lack of > consensus, so I'll ask again. > > Should in*/out* macros or bus_space* functions be used in userland code? > The background is that the port devel/libpciaccess uses these routines > on FreeBSD. 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 > > 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 > > 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. > > My question is simply, which one is correct, or should libpciaccess be > reworked in a completely different way? The latter; in*/out*() are somewhat okay if you want to restrict this to work on x86 without PCI domains only. The above approach to using bus_space(9) is one big hack, though. The right way for employing that API is to allocate the corresponding bus resource of a particular device and then to obtain bus tag and handle via rman_get_bus{tag,handle}(9) - which won't work from userland, however. The shortcut to just stick in {AMD64,I386}_BUS_SPACE_IO instead is totally unportable as generally a bus tag isn't a mere constant and also may depend on which PCI bus and domain a particular device is located on/in. What we really need is a proper interface allowing userland to access PCI I/O and memory registers, f. e. via /dev/pci, and for libpciaccess to build upon that, i. e. essentially the same as things work on/with Linux and /sys/bus/pci/device. As a side-effect this then also permits to properly sanity check PCI accesses from userland within the kernel. Marius