Add pciutils, a library for portable access to PCI bus configuration

registers and utilities based on this library (lspci & co).
with help from and ok sturm@.
This commit is contained in:
matthieu 2006-03-25 21:53:35 +00:00
parent b68509bff8
commit ee0bc96ecd
11 changed files with 311 additions and 0 deletions

View File

@ -0,0 +1,30 @@
# $OpenBSD: Makefile,v 1.1.1.1 2006/03/25 21:53:35 matthieu Exp $
NOT_FOR_ARCHS= sparc m68k m88k vax
COMMENT= "PCI bus configuration register access tools"
DISTNAME= pciutils-2.2.1
CATEGORIES= sysutils
HOMEPAGE= http://atrey.karlin.mff.cuni.cz/~mj/pciutils.shtml
MAINTAINER= Matthieu Herrb <matthieu@openbsd.org>
# GPL
PERMIT_PACKAGE_CDROM= Yes
PERMIT_PACKAGE_FTP= Yes
PERMIT_DISTFILES_CDROM= Yes
PERMIT_DISTFILES_FTP= Yes
WANTLIB= c
MASTER_SITES= ftp://atrey.karlin.mff.cuni.cz/pub/linux/pci/
USE_GMAKE= Yes
MAKE_ENV= CC="${CC}"
FAKE_FLAGS= PREFIX=${WRKINST}${PREFIX}
NO_REGRESS= Yes
.include <bsd.port.mk>

View File

@ -0,0 +1,4 @@
MD5 (pciutils-2.2.1.tar.gz) = c18e2a5f04e9abae5a42439de294f086
RMD160 (pciutils-2.2.1.tar.gz) = fc12da1261a33f03fc54e4bcc48cd0b8277990a6
SHA1 (pciutils-2.2.1.tar.gz) = 01ae9a2c826e06d48d2b0d8f78cfddf7e1cadb4c
SIZE (pciutils-2.2.1.tar.gz) = 194389

View File

@ -0,0 +1,13 @@
$OpenBSD: patch-Makefile,v 1.1.1.1 2006/03/25 21:53:35 matthieu Exp $
--- Makefile.orig Sat Nov 26 14:00:57 2005
+++ Makefile Fri Mar 24 22:57:18 2006
@@ -1,8 +1,7 @@
# Makefile for The PCI Utilities
# (c) 1998--2005 Martin Mares <mj@ucw.cz>
-OPT=-O2
-CFLAGS=$(OPT) -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline
+CFLAGS+= -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Winline
VERSION=2.2.1
DATE=2005-11-26

View File

@ -0,0 +1,14 @@
$OpenBSD: patch-lib_Makefile,v 1.1.1.1 2006/03/25 21:53:35 matthieu Exp $
--- lib/Makefile.orig Fri Aug 13 22:29:06 2004
+++ lib/Makefile Wed Mar 22 23:20:03 2006
@@ -36,6 +36,10 @@ CFLAGS += -I${FREEBSD_SYS}
endif
endif
+ifdef PCI_HAVE_PM_OBSD_DEVICE
+OBJS += obsd-device.o
+endif
+
ifdef PCI_HAVE_PM_AIX_DEVICE
OBJS += aix-device.o
endif

View File

@ -0,0 +1,15 @@
$OpenBSD: patch-lib_access_c,v 1.1.1.1 2006/03/25 21:53:35 matthieu Exp $
--- lib/access.c.orig Fri Aug 13 22:15:11 2004
+++ lib/access.c Tue Mar 21 22:56:47 2006
@@ -47,6 +47,11 @@ static struct pci_methods *pci_methods[P
#else
NULL,
#endif
+#ifdef PCI_HAVE_PM_OBSD_DEVICE
+ &pm_obsd_device,
+#else
+ NULL,
+#endif
#ifdef PCI_HAVE_PM_DUMP
&pm_dump,
#else

View File

@ -0,0 +1,16 @@
$OpenBSD: patch-lib_configure,v 1.1.1.1 2006/03/25 21:53:35 matthieu Exp $
--- lib/configure.orig Wed Sep 21 13:42:03 2005
+++ lib/configure Tue Mar 21 22:56:47 2006
@@ -74,6 +74,12 @@ case $sys in
echo >>$c '#define PCI_PATH_FBSD_DEVICE "/dev/pci"'
ok=1
;;
+ openbsd)
+ echo_n " obsd-device"
+ echo >>$c '#define PCI_HAVE_PM_OBSD_DEVICE'
+ echo >>$c '#define PCI_PATH_OBSD_DEVICE "/dev/pci"'
+ ok=1
+ ;;
aix)
echo_n " aix-device"
echo >>$c '#define PCI_HAVE_PM_AIX_DEVICE'

View File

@ -0,0 +1,10 @@
$OpenBSD: patch-lib_internal_h,v 1.1.1.1 2006/03/25 21:53:35 matthieu Exp $
--- lib/internal.h.orig Fri Aug 13 22:21:22 2004
+++ lib/internal.h Tue Mar 21 22:56:47 2006
@@ -36,4 +36,5 @@ struct pci_dev *pci_alloc_dev(struct pci
int pci_link_dev(struct pci_access *, struct pci_dev *);
extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_linux_proc,
- pm_fbsd_device, pm_aix_device, pm_nbsd_libpci, pm_dump, pm_linux_sysfs;
+ pm_fbsd_device, pm_aix_device, pm_nbsd_libpci, pm_obsd_device,
+ pm_dump, pm_linux_sysfs;

View File

@ -0,0 +1,164 @@
$OpenBSD: patch-lib_obsd-device_c,v 1.1.1.1 2006/03/25 21:53:35 matthieu Exp $
--- lib/obsd-device.c.orig Wed Mar 22 22:59:36 2006
+++ lib/obsd-device.c Wed Mar 22 22:59:36 2006
@@ -0,0 +1,160 @@
+/*
+ * The PCI Library -- FreeBSD /dev/pci access
+ *
+ * Copyright (c) 1999 Jari Kirma <kirma@cs.hut.fi>
+ * Updated in 2003 by Samy Al Bahra <samy@kerneled.com>
+ *
+ * Can be freely distributed and used under the terms of the GNU GPL.
+ */
+
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/endian.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/pciio.h>
+#include "internal.h"
+
+static void
+obsd_config(struct pci_access *a)
+{
+ a->method_params[PCI_ACCESS_OBSD_DEVICE] = PCI_PATH_OBSD_DEVICE;
+}
+
+static int
+obsd_detect(struct pci_access *a)
+{
+ char *name = a->method_params[PCI_ACCESS_OBSD_DEVICE];
+
+ if (access(name, R_OK))
+ {
+ a->warning("Cannot open %s", name);
+ return 0;
+ }
+ a->debug("...using %s", name);
+ return 1;
+}
+
+static void
+obsd_init(struct pci_access *a)
+{
+ char *name = a->method_params[PCI_ACCESS_OBSD_DEVICE];
+
+ a->fd = open(name, O_RDWR, 0);
+ if (a->fd < 0)
+ {
+ a->error("obsd_init: %s open failed", name);
+ }
+}
+
+static void
+obsd_cleanup(struct pci_access *a)
+{
+ close(a->fd);
+}
+
+static int
+obsd_read(struct pci_dev *d, int pos, byte *buf, int len)
+{
+ struct pci_io pi;
+ union {
+ u_int32_t u32;
+ u_int16_t u16[2];
+ u_int8_t u8[4];
+ } u;
+
+ if (!(len == 1 || len == 2 || len == 4))
+ {
+ return pci_generic_block_read(d, pos, buf, len);
+ }
+
+ if (pos >= 256)
+ return 0;
+
+ pi.pi_sel.pc_bus = d->bus;
+ pi.pi_sel.pc_dev = d->dev;
+ pi.pi_sel.pc_func = d->func;
+
+ pi.pi_reg = pos - (pos % 4);
+ pi.pi_width = 4;
+
+ if (ioctl(d->access->fd, PCIOCREAD, &pi) < 0) {
+ if (errno == ENXIO) {
+ pi.pi_data = 0xffffffff;
+ } else {
+ d->access->error("obsd_read: ioctl(PCIOCREAD) failed");
+ }
+ }
+ u.u32 = pi.pi_data;
+
+ switch (len)
+ {
+ case 1:
+ buf[0] = (u8) u.u8[pos % 4];
+ break;
+ case 2:
+ ((u16 *) buf)[0] = letoh16(u.u16[(pos % 4) / 2]);
+ break;
+ case 4:
+ ((u32 *) buf)[0] = (u32) letoh32(pi.pi_data);
+ break;
+ }
+ return 1;
+}
+
+static int
+obsd_write(struct pci_dev *d, int pos, byte *buf, int len)
+{
+ struct pci_io pi;
+
+ if (!(len == 1 || len == 2 || len == 4))
+ {
+ return pci_generic_block_write(d, pos, buf, len);
+ }
+
+ if (pos >= 256)
+ return 0;
+
+ pi.pi_sel.pc_bus = d->bus;
+ pi.pi_sel.pc_dev = d->dev;
+ pi.pi_sel.pc_func = d->func;
+
+ pi.pi_reg = pos;
+ pi.pi_width = len;
+
+ switch (len)
+ {
+ case 1:
+ pi.pi_data = buf[0];
+ break;
+ case 2:
+ pi.pi_data = ((u16 *) buf)[0];
+ break;
+ case 4:
+ pi.pi_data = ((u32 *) buf)[0];
+ break;
+ }
+
+ if (ioctl(d->access->fd, PCIOCWRITE, &pi) < 0)
+ {
+ d->access->error("obsd_write: ioctl(PCIOCWRITE) failed");
+ }
+
+ return 1;
+}
+
+struct pci_methods pm_obsd_device = {
+ "OpenBSD-device",
+ obsd_config,
+ obsd_detect,
+ obsd_init,
+ obsd_cleanup,
+ pci_generic_scan,
+ pci_generic_fill_info,
+ obsd_read,
+ obsd_write,
+ NULL, /* dev_init */
+ NULL /* dev_cleanup */
+};

View File

@ -0,0 +1,11 @@
$OpenBSD: patch-lib_pci_h,v 1.1.1.1 2006/03/25 21:53:35 matthieu Exp $
--- lib/pci.h.orig Sat Sep 10 14:10:54 2005
+++ lib/pci.h Tue Mar 21 22:56:47 2006
@@ -31,6 +31,7 @@ enum pci_access_type {
PCI_ACCESS_FBSD_DEVICE, /* FreeBSD /dev/pci (params: path) */
PCI_ACCESS_AIX_DEVICE, /* /dev/pci0, /dev/bus0, etc. */
PCI_ACCESS_NBSD_LIBPCI, /* NetBSD libpci */
+ PCI_ACCESS_OBSD_DEVICE, /* OpenBSD /dev/pci */
PCI_ACCESS_DUMP, /* Dump file (params: filename) */
PCI_ACCESS_MAX
};

View File

@ -0,0 +1,25 @@
The PCI Utilities package contains a library for portable access to
PCI bus configuration registers and several utilities based on this
library.
Currently, pciutils work on all versions of Linux and they also have
somewhat experimental support for OpenBSD, FreeBSD, NetBSD, AIX, GNU
Hurd and Solaris/x86. It should be very easy to add support for other
systems as well (volunteers wanted; if you want to try that, I'll be
very glad to see the patches and include them in the next version).
The utilities include: (See manual pages for more details)
- lspci: displays detailed information about all PCI buses and
devices.
- setpci: allows to read from and write to PCI device configuration
registers. For example, you can adjust the latency timers with it.
CAUTION: There is a couple of dangerous points and caveats, please
read the manual page first!
- update-pciids: download the current version of the pci.ids file.
On OpenBSD you need to set sysctl machdep.allowaperture=2 in
/etc/sysctl.conf, and run lspci and setpci as root.

View File

@ -0,0 +1,9 @@
@comment $OpenBSD: PLIST,v 1.1.1.1 2006/03/25 21:53:35 matthieu Exp $
@man man/man8/lspci.8
@man man/man8/setpci.8
@man man/man8/update-pciids.8
sbin/lspci
sbin/setpci
sbin/update-pciids
@comment no checksum
share/pci.ids