From: Martin Mares Date: Tue, 20 Jul 1999 14:01:15 +0000 (+0000) Subject: Added support for FreeBSD and its /dev/pci access method. X-Git-Tag: v3.0.0~269 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=168b4f4612e4524fe68cacbd036df01cdbdbd007;p=pciutils.git Added support for FreeBSD and its /dev/pci access method. Contributed by Jari Kirma and tweaked by me. --- diff --git a/ChangeLog b/ChangeLog index 0bd4151..cbcfdfb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,26 @@ Tue Jul 20 13:25:09 1999 Martin Mares + * lib/pci.h: Types are OS dependent. + + * lib/internal.h: Byte order hacks are OS dependent. + + * lib/configure: Recognize FreeBSD. Also set OS_XXX according to the OS. + + * lib/Makefile, lib/access.c: Added fbsd-device target. + + * pci.ids: Added an entry for PLX 9080 bridges with subsystem ID + incorrectly set to device ID. + + * README: Added a note that we support FreeBSD. + + * Makefile (PREFIX, ROOT): Set it depending on the OS. + (%.8): Grrr, BSD date is not able to convert date formats the same way + as GNU date does. Use sed instead. + (install): Use `-c' when calling install. + + * lib/fbsd-device.c: Added FreeBSD /dev/pci access module contributed + by Jari Kirma . + * lib/proc.c: Rewrote the pread/pwrite things once again. Use pread and pwrite only when we are certain it's safe (i.e., glibc 2.1 on all architectures or any libc on a i386 where we really know diff --git a/Makefile b/Makefile index f8ad9f1..7db5ae7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.19 1999/07/20 12:13:39 mj Exp $ +# $Id: Makefile,v 1.20 1999/07/20 14:01:17 mj Exp $ # Makefile for Linux PCI Utilities # (c) 1998--1999 Martin Mares @@ -6,13 +6,18 @@ OPT=-O2 -fomit-frame-pointer #OPT=-O2 -g CFLAGS=$(OPT) -Wall -W -Wno-parentheses -Wstrict-prototypes -Werror -ROOT=/ -PREFIX=/usr - VERSION=2.1-pre5 SUFFIX= #SUFFIX=-alpha -DATE=99-07-20 +DATE=1999-07-20 + +ifeq ($(shell uname),FreeBSD) +ROOT=/usr/local +PREFIX=/usr/local +else +ROOT=/ +PREFIX=/usr +endif export @@ -32,7 +37,7 @@ setpci.o: setpci.c pciutils.h lib/libpci.a common.o: common.c pciutils.h lib/libpci.a %.8: %.man - sed <$< >$@ "s/@TODAY@/`date -d $(DATE) '+%d %B %Y'`/;s/@VERSION@/pciutils-$(VERSION)$(SUFFIX)/" + M=`echo $(DATE) | sed 's/-01-/-January-/;s/-02-/-February-/;s/-03-/-March-/;s/-04-/-April-/;s/-05-/-May-/;s/-06-/-June-/;s/-07-/-July-/;s/-08-/-August-/;s/-09-/-September-/;s/-10-/-October-/;s/-11-/-November-/;s/-12-/-December-/;s/\(.*\)-\(.*\)-\(.*\)/\3 \2 \1/'` ; sed <$< >$@ "s/@TODAY@/$$M/;s/@VERSION@/pciutils-$(VERSION)$(SUFFIX)/" clean: rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core` @@ -40,9 +45,10 @@ clean: rm -rf dist install: all - install -m 755 -s lspci setpci $(ROOT)/sbin - install -m 644 pci.ids $(PREFIX)/share - install -m 644 lspci.8 setpci.8 $(PREFIX)/man/man8 + # -c is ignored on Linux, but required on FreeBSD + install -c -m 755 -s lspci setpci $(ROOT)/sbin + install -c 644 pci.ids $(PREFIX)/share + install -c 644 lspci.8 setpci.8 $(PREFIX)/man/man8 # Remove relics from old versions rm -f $(ROOT)/etc/pci.ids diff --git a/README b/README index d6ad0fa..04f1aed 100644 --- a/README +++ b/README @@ -11,8 +11,8 @@ for details. The PCI Utilities package contains a library for portable access to PCI bus configuration space and several utilities based on this library. Current -version works only on Linux, but it can be easily extended to work on other -systems as well. +version works only on Linux and also has an experimental support for FreeBSD, +but it can be easily extended to work on other systems as well. The utilities include: (See manual pages for more details) diff --git a/lib/Makefile b/lib/Makefile index 0752908..5c6c586 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.2 1999/01/24 21:35:35 mj Exp $ +# $Id: Makefile,v 1.3 1999/07/20 14:01:27 mj Exp $ # Makefile for The PCI Library # (c) 1999 Martin Mares @@ -23,6 +23,11 @@ ifdef HAVE_PM_SYSCALLS OBJS += syscalls.o endif +ifdef HAVE_PM_FBSD_DEVICE +OBJS += fbsd-device.o +CFLAGS += -I/usr/src/sys +endif + ifdef HAVE_OWN_HEADER_H INCL += header.h endif @@ -39,6 +44,7 @@ i386-ports.o: i386-ports.c $(INCL) proc.o: proc.c $(INCL) generic.o: generic.c $(INCL) syscalls.o: syscalls.c $(INCL) +fbsd-device.o: fbsd-device.c $(INCL) dump.o: dump.c $(INCL) names.o: names.c $(INCL) filter.o: filter.c $(INCL) diff --git a/lib/access.c b/lib/access.c index a5e2616..4c47a0e 100644 --- a/lib/access.c +++ b/lib/access.c @@ -1,5 +1,5 @@ /* - * $Id: access.c,v 1.4 1999/07/07 11:23:08 mj Exp $ + * $Id: access.c,v 1.5 1999/07/20 14:01:28 mj Exp $ * * The PCI Library -- User Access * @@ -27,6 +27,11 @@ static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = { #else NULL, #endif +#ifdef HAVE_PM_FBSD_DEVICE + &pm_fbsd_device, +#else + NULL, +#endif #ifdef HAVE_PM_INTEL_CONF &pm_intel_conf1, &pm_intel_conf2, diff --git a/lib/configure b/lib/configure index dae9b13..84afe12 100755 --- a/lib/configure +++ b/lib/configure @@ -7,38 +7,53 @@ sys=`uname -s` rel=`uname -r` cpu=`uname -m | sed 's/^i.86$/i386/;s/^sun4u$/sparc64/'` echo "$sys/$cpu $rel" -if [ "$sys" != Linux ] ; then - echo "libpci currently supports only Linux" - exit 1 -fi -echo -n "Looking for access methods..." + c=config.h echo >$c "#define ARCH_`echo $cpu | tr 'a-z' 'A-Z'`" -case $rel in - 2.[1-9]*|[3-9]*) echo -n " proc" - echo >>$c '#define HAVE_PM_LINUX_PROC' - echo >>$c '#define HAVE_LINUX_BYTEORDER_H' - echo >>$c '#define PATH_PROC_BUS_PCI "/proc/bus/pci"' - ok=1 - ;; -esac -case $cpu in - i386) echo -n " i386-ports" - echo >>$c '#define HAVE_PM_INTEL_CONF' - ok=1 - ;; - alpha) echo >>$c '#define HAVE_64BIT_ADDRESS' -# echo -n " syscalls" -# echo >>$c '#define HAVE_PM_SYSCALLS' -# ok=1 - ;; - sparc|sparc64) echo >>$c '#define HAVE_64BIT_ADDRESS' - echo >>$c '#define HAVE_LONG_ADDRESS' -# echo -n " syscalls" -# echo >>$c '#define HAVE_PM_SYSCALLS' -# ok=1 - ;; +echo >$c "#define OS_`echo $sys | tr 'a-z' 'A-Z'`" + +echo -n "Looking for access methods..." + +case $sys in + Linux) + case $rel in + 2.[1-9]*|[3-9]*) echo -n " proc" + echo >>$c '#define HAVE_PM_LINUX_PROC' + echo >>$c '#define HAVE_LINUX_BYTEORDER_H' + echo >>$c '#define PATH_PROC_BUS_PCI "/proc/bus/pci"' + ok=1 + ;; + esac + case $cpu in + i386) echo -n " i386-ports" + echo >>$c '#define HAVE_PM_INTEL_CONF' + ok=1 + ;; + alpha) echo >>$c '#define HAVE_64BIT_ADDRESS' +# echo -n " syscalls" +# echo >>$c '#define HAVE_PM_SYSCALLS' +# ok=1 + ;; + sparc|sparc64) echo >>$c '#define HAVE_64BIT_ADDRESS' + echo >>$c '#define HAVE_LONG_ADDRESS' +# echo -n " syscalls" +# echo >>$c '#define HAVE_PM_SYSCALLS' +# ok=1 + ;; + esac + ;; + FreeBSD) + echo -n " fbsd-device" + echo >>$c '#define HAVE_PM_FBSD_DEVICE' + echo >>$c '#define PATH_FBSD_DEVICE "/dev/pci"' + ok=1 + ;; + *) + echo " The PCI library currently supports only Linux and FreeBSD" + exit 1 + ;; esac + echo >>$c '#define HAVE_PM_DUMP' echo " dump" if [ -z "$ok" ] ; then diff --git a/lib/fbsd-device.c b/lib/fbsd-device.c new file mode 100644 index 0000000..13dc91a --- /dev/null +++ b/lib/fbsd-device.c @@ -0,0 +1,146 @@ +/* + * The PCI Library -- FreeBSD /dev/pci access + * + * Copyright (c) 1999 Jari Kirma + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +/* + * Read functionality of this driver is briefly tested, and seems + * to supply basic information correctly, but I promise no more. + */ + +#include +#include +#include + +#include +#include + +#include "internal.h" + +static void +fbsd_config(struct pci_access *a) +{ + a->method_params[PCI_ACCESS_FBSD_DEVICE] = PATH_FBSD_DEVICE; +} + +static int +fbsd_detect(struct pci_access *a) +{ + char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE]; + + if (access(name, R_OK)) + { + a->warning("Cannot open %s", name); + return 0; + } + a->debug("...using %s", name); + return 1; +} + +static void +fbsd_init(struct pci_access *a) +{ + char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE]; + + a->fd = open(name, O_RDWR, 0); + if (a->fd < 0) + { + a->error("fbsd_init: %s open failed", name); + } +} + +static void +fbsd_cleanup(struct pci_access *a) +{ + close(a->fd); +} + +static int +fbsd_read(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_read(d, pos, buf, len); + } + + 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; + + if (ioctl(d->access->fd, PCIOCREAD, &pi) < 0) + d->access->error("fbsd_read: ioctl(PCIOCREAD) failed"); + + switch (len) + { + case 1: + buf[0] = (u8) pi.pi_data; + break; + case 2: + ((u16 *) buf)[0] = (u16) pi.pi_data; + break; + case 4: + ((u32 *) buf)[0] = (u32) pi.pi_data; + break; + } + return 1; +} + +static int +fbsd_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); + } + + 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("fbsd_write: ioctl(PCIOCWRITE) failed"); + } + + return 1; +} + +struct pci_methods pm_fbsd_device = { + "FreeBSD-device", + fbsd_config, + fbsd_detect, + fbsd_init, + fbsd_cleanup, + pci_generic_scan, + pci_generic_fill_info, + fbsd_read, + fbsd_write, + NULL, /* dev_init */ + NULL /* dev_cleanup */ +}; diff --git a/lib/internal.h b/lib/internal.h index 6805afc..b049f3d 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -1,5 +1,5 @@ /* - * $Id: internal.h,v 1.2 1999/07/07 11:23:10 mj Exp $ + * $Id: internal.h,v 1.3 1999/07/20 14:01:32 mj Exp $ * * The PCI Library -- Internal Include File * @@ -20,8 +20,17 @@ #else +#ifdef OS_LINUX #include -#if __BYTE_ORDER == __BIG_ENDIAN +#define BYTE_ORDER __BYTE_ORDER +#define BIG_ENDIAN __BIG_ENDIAN +#endif + +#ifdef OS_FREEBSD +#include +#endif + +#if BYTE_ORDER == BIG_ENDIAN #define cpu_to_le16 swab16 #define cpu_to_le32 swab32 #define le16_to_cpu swab16 @@ -74,6 +83,6 @@ struct pci_dev *pci_alloc_dev(struct pci_access *); int pci_link_dev(struct pci_access *, struct pci_dev *); extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_linux_proc, - pm_syscalls, pm_dump; + pm_syscalls, pm_fbsd_device, pm_dump; #define UNUSED __attribute__((unused)) diff --git a/lib/pci.h b/lib/pci.h index 4fca73e..fbf41d4 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -1,5 +1,5 @@ /* - * $Id: pci.h,v 1.5 1999/07/20 12:13:40 mj Exp $ + * $Id: pci.h,v 1.6 1999/07/20 14:01:35 mj Exp $ * * The PCI Library * @@ -23,6 +23,7 @@ * Types */ +#ifdef OS_LINUX #include typedef __u8 byte; @@ -30,6 +31,17 @@ typedef __u8 u8; typedef __u16 word; typedef __u16 u16; typedef __u32 u32; +#endif + +#ifdef OS_FREEBSD +#include + +typedef u_int8_t byte; +typedef u_int8_t u8; +typedef u_int16_t word; +typedef u_int16_t u16; +typedef u_int32_t u32; +#endif #ifdef HAVE_LONG_ADDRESS typedef unsigned long long pciaddr_t; @@ -49,8 +61,9 @@ struct nl_entry; #define PCI_ACCESS_SYSCALLS 2 /* pciconfig_read() syscalls (params: none) */ #define PCI_ACCESS_I386_TYPE1 3 /* i386 ports, type 1 (params: none) */ #define PCI_ACCESS_I386_TYPE2 4 /* i386 ports, type 2 (params: none) */ -#define PCI_ACCESS_DUMP 5 /* Dump file (params: filename) */ -#define PCI_ACCESS_MAX 6 +#define PCI_ACCESS_FBSD_DEVICE 5 /* FreeBSD /dev/pci (params: path) */ +#define PCI_ACCESS_DUMP 6 /* Dump file (params: filename) */ +#define PCI_ACCESS_MAX 7 struct pci_access { /* Options you can change: */ diff --git a/pci.ids b/pci.ids index b5b8760..2a5858a 100644 --- a/pci.ids +++ b/pci.ids @@ -4,7 +4,7 @@ # Maintained by Martin Mares # If you have any new entries, send them to the maintainer. # -# $Id: pci.ids,v 1.32 1999/07/20 11:29:41 mj Exp $ +# $Id: pci.ids,v 1.33 1999/07/20 14:01:21 mj Exp $ # # Vendors and devices. Please keep sorted. @@ -2999,6 +2999,8 @@ S 1092 Diamond Multimedia 4820 Viper V550 Graphics Accelerator S 10b4 STB Systems Inc 273e Velocity 4400 +S 10b5 PLX Technology, Inc. + 9080 9080 [real subsystem ID not set] S 1102 Creative Labs 1015 Graphics Blaster CT6710 S 125c Aurora Technologies, Inc.