From 848b43472b7013ba8969c4866442471b0b93de0a Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 26 Dec 2002 19:28:33 +0000 Subject: [PATCH] Initial NetBSD support. --- ChangeLog | 6 ++- Makefile | 16 ++++-- lib/Makefile | 14 +++-- lib/access.c | 7 ++- lib/configure | 8 ++- lib/internal.h | 4 +- lib/nbsd-libpci.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++ lib/pci.h | 17 ++++-- 8 files changed, 188 insertions(+), 16 deletions(-) create mode 100644 lib/nbsd-libpci.c diff --git a/ChangeLog b/ChangeLog index 9a91bf1..cd9e37e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-12-26 Martin Mares + + * Added preliminary version of NetBSD support by Quentin Garnier + . + 2002-04-06 Martin Mares * lspci.c: Mention "-xxx" in the help. @@ -729,4 +734,3 @@ Tue Feb 3 20:56:00 1998 Martin Mares (show_htype2): Stub routine. (scan_config): Write sensible error message if the kernel denies reading of upper part of the PCI config space. - diff --git a/Makefile b/Makefile index 73d38dd..041fde6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.42 2002/03/30 15:42:16 mj Exp $ +# $Id: Makefile,v 1.43 2002/12/26 19:28:33 mj Exp $ # Makefile for Linux PCI Utilities # (c) 1998--2002 Martin Mares @@ -6,17 +6,22 @@ OPT=-O2 -fomit-frame-pointer #OPT=-O2 -g CFLAGS=$(OPT) -Wall -W -Wno-parentheses -Wstrict-prototypes -VERSION=2.1.10 -#SUFFIX=-pre2 -#SUFFIX=-alpha -DATE=2002-03-30 +VERSION=2.1.11 +SUFFIX=-pre1 +DATE=2002-12-26 INSTALL=install DIRINSTALL=install -d +PCILIB=libpci.a ifeq ($(shell uname),FreeBSD) ROOT=/usr/local PREFIX=/usr/local else +ifeq ($(shell uname),NetBSD) +ROOT=$(PREFIX) +PCILIB=libpciutils.a +LDFLAGS+=-lpci +else ifeq ($(shell uname),AIX) ROOT=/usr/local PREFIX=/usr/local @@ -28,6 +33,7 @@ ROOT=/ PREFIX=/usr endif endif +endif MANDIR=$(shell if [ -d $(PREFIX)/share/man ] ; then echo $(PREFIX)/share/man ; else echo $(PREFIX)/man ; fi) DISTTMP=/tmp/pciutils-dist diff --git a/lib/Makefile b/lib/Makefile index 9fcbf59..8b43b7e 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.5 2002/03/30 15:39:25 mj Exp $ +# $Id: Makefile,v 1.6 2002/12/26 19:28:33 mj Exp $ # Makefile for The PCI Library # (c) 1999 Martin Mares @@ -7,6 +7,8 @@ include config.mk OBJS=access.o generic.o dump.o names.o filter.o INCL=internal.h pci.h config.h +PCILIB=libpci.a + ifdef HAVE_PM_LINUX_PROC OBJS += proc.o endif @@ -32,13 +34,18 @@ ifdef HAVE_PM_AIX_DEVICE OBJS += aix-device.o endif +ifdef HAVE_PM_NBSD_LIBPCI +OBJS += nbsd-libpci.o +PCILIB=libpciutils.a +endif + ifdef HAVE_OWN_HEADER_H INCL += header.h endif -all: libpci.a +all: $(PCILIB) -libpci.a: $(OBJS) +$(PCILIB): $(OBJS) rm -f $@ ar rcs $@ $^ ranlib $@ @@ -53,3 +60,4 @@ aix-device.o: aix-device.c $(INCL) dump.o: dump.c $(INCL) names.o: names.c $(INCL) filter.o: filter.c $(INCL) +nbsd-libpci.o: nbsd-libpci.c $(INCL) diff --git a/lib/access.c b/lib/access.c index 8fbc224..6d992b6 100644 --- a/lib/access.c +++ b/lib/access.c @@ -1,5 +1,5 @@ /* - * $Id: access.c,v 1.8 2002/03/30 15:39:25 mj Exp $ + * $Id: access.c,v 1.9 2002/12/26 19:28:33 mj Exp $ * * The PCI Library -- User Access * @@ -44,6 +44,11 @@ static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = { #else NULL, #endif +#ifdef HAVE_PM_NBSD_LIBPCI + &pm_nbsd_libpci, +#else + NULL, +#endif #ifdef HAVE_PM_DUMP &pm_dump, #else diff --git a/lib/configure b/lib/configure index 87b111d..b5f9fad 100755 --- a/lib/configure +++ b/lib/configure @@ -69,8 +69,14 @@ case $sys in echo >>$c '#define HAVE_PM_AIX_DEVICE' ok=1 ;; + NetBSD) + echo_n " nbsd-libpci" + echo >>$c '#define HAVE_PM_NBSD_LIBPCI' + echo >>$c '#define PATH_NBSD_DEVICE "/dev/pci0"' + ok=1 + ;; *) - echo " The PCI library currently supports only Linux, AIX and FreeBSD" + echo " The PCI library currently supports only Linux, AIX, FreeBSD and NetBSD" exit 1 ;; esac diff --git a/lib/internal.h b/lib/internal.h index 4f2a113..d3a87b1 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -1,5 +1,5 @@ /* - * $Id: internal.h,v 1.6 2002/03/30 15:39:25 mj Exp $ + * $Id: internal.h,v 1.7 2002/12/26 19:28:33 mj Exp $ * * The PCI Library -- Internal Include File * @@ -91,4 +91,4 @@ 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_fbsd_device, pm_aix_device, pm_dump; + pm_syscalls, pm_fbsd_device, pm_aix_device, pm_nbsd_libpci, pm_dump; diff --git a/lib/nbsd-libpci.c b/lib/nbsd-libpci.c new file mode 100644 index 0000000..60ba575 --- /dev/null +++ b/lib/nbsd-libpci.c @@ -0,0 +1,132 @@ +/* + * The PCI Library -- NetBSD libpci access + * (based on FreeBSD /dev/pci access) + * + * Copyright (c) 1999 Jari Kirma + * Copyright (c) 2002 Quentin Garnier + * + * 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 "internal.h" + +static void +nbsd_config(struct pci_access *a) +{ + a->method_params[PCI_ACCESS_NBSD_LIBPCI] = PATH_NBSD_DEVICE; +} + +static int +nbsd_detect(struct pci_access *a) +{ + char *name = a->method_params[PCI_ACCESS_NBSD_LIBPCI]; + + if (access(name, R_OK)) + { + a->warning("Cannot open %s", name); + return 0; + } + a->debug("...using %s", name); + return 1; +} + +static void +nbsd_init(struct pci_access *a) +{ + char *name = a->method_params[PCI_ACCESS_NBSD_LIBPCI]; + + a->fd = open(name, O_RDWR, 0); + if (a->fd < 0) + { + a->error("nbsd_init: %s open failed", name); + } +} + +static void +nbsd_cleanup(struct pci_access *a) +{ + close(a->fd); +} + +static int +nbsd_read(struct pci_dev *d, int pos, byte *buf, int len) +{ + pcireg_t val; + + if (!(len == 1 || len == 2 || len == 4)) + { + return pci_generic_block_read(d, pos, buf, len); + } + + + if (pcibus_conf_read(d->access->fd, d->bus, d->dev, d->func, pos, &val) < 0) + d->access->error("nbsd_read: pci_bus_conf_read() failed"); + + switch (len) + { + case 1: + buf[0] = (u8) ((val>>16) & 0xff); + break; + case 2: + ((u16 *) buf)[0] = (u16) val; + break; + case 4: + ((u32 *) buf)[0] = (u32) val; + break; + } + return 1; +} + +static int +nbsd_write(struct pci_dev *d, int pos, byte *buf, int len) +{ + pcireg_t val; + + if (!(len == 1 || len == 2 || len == 4)) + { + return pci_generic_block_write(d, pos, buf, len); + } + + switch (len) + { + case 1: + val = buf[0]; + break; + case 2: + val = ((u16 *) buf)[0]; + break; + case 4: + val = ((u32 *) buf)[0]; + break; + } + + if (pcibus_conf_write(d->access->fd, d->bus, d->dev, d->func, pos, val) < 0) + d->access->error("nbsd_write: pci_bus_conf_write() failed"); + + return 1; +} + +struct pci_methods pm_nbsd_libpci = { + "NetBSD-libpci", + nbsd_config, + nbsd_detect, + nbsd_init, + nbsd_cleanup, + pci_generic_scan, + pci_generic_fill_info, + nbsd_read, + nbsd_write, + NULL, /* dev_init */ + NULL /* dev_cleanup */ +}; diff --git a/lib/pci.h b/lib/pci.h index b158c34..bea893c 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -1,5 +1,5 @@ /* - * $Id: pci.h,v 1.9 2002/03/30 15:39:25 mj Exp $ + * $Id: pci.h,v 1.10 2002/12/26 19:28:33 mj Exp $ * * The PCI Library * @@ -43,6 +43,16 @@ typedef u_int16_t u16; typedef u_int32_t u32; #endif +#ifdef OS_NETBSD +#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 OS_AIX #include @@ -73,8 +83,9 @@ struct nl_entry; #define PCI_ACCESS_I386_TYPE2 4 /* i386 ports, type 2 (params: none) */ #define PCI_ACCESS_FBSD_DEVICE 5 /* FreeBSD /dev/pci (params: path) */ #define PCI_ACCESS_AIX_DEVICE 6 /* /dev/pci0, /dev/bus0, etc. */ -#define PCI_ACCESS_DUMP 7 /* Dump file (params: filename) */ -#define PCI_ACCESS_MAX 8 +#define PCI_ACCESS_NBSD_LIBPCI 7 +#define PCI_ACCESS_DUMP 8 /* Dump file (params: filename) */ +#define PCI_ACCESS_MAX 9 struct pci_access { /* Options you can change: */ -- 2.39.2