]> mj.ucw.cz Git - pciutils.git/commitdiff
Initial NetBSD support.
authorMartin Mares <mj@ucw.cz>
Thu, 26 Dec 2002 19:28:33 +0000 (19:28 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 5 May 2006 12:10:52 +0000 (14:10 +0200)
ChangeLog
Makefile
lib/Makefile
lib/access.c
lib/configure
lib/internal.h
lib/nbsd-libpci.c [new file with mode: 0644]
lib/pci.h

index 9a91bf17306a570269d1858e59f440f29f8e9c11..cd9e37e64ad15a0ea694dd7f0b35b8ffbfef7307 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2002-12-26  Martin Mares  <mj@ucw.cz>
+
+       * Added preliminary version of NetBSD support by Quentin Garnier
+       <netbsd@quatriemek.com>.
+
 2002-04-06  Martin Mares  <mj@ucw.cz>
 
        * lspci.c: Mention "-xxx" in the help.
@@ -729,4 +734,3 @@ Tue Feb  3 20:56:00 1998  Martin Mares  <mj@albireo.ucw.cz>
        (show_htype2): Stub routine.
        (scan_config): Write sensible error message if the kernel denies reading of
        upper part of the PCI config space.
-
index 73d38dd57fcfb134fd84e8b551404bb2772f47c1..041fde68aec9cfe910638b840116f720acb24af3 100644 (file)
--- 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 <mj@ucw.cz>
 
@@ -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
 
index 9fcbf59895f0efc7a6ea4e24e9f1b439453fd520..8b43b7ef3096fd685c0d57b633db4632e96dfd27 100644 (file)
@@ -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 <mj@ucw.cz>
 
@@ -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)
index 8fbc224d9e14e0e7af0cba26a7bce0c2a863e47a..6d992b68575e2cf2362d3a3a8bcc1bd7da5eed4f 100644 (file)
@@ -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
index 87b111d0d10718ebcd33fec6610c0eafd27f79ad..b5f9fadbe285116fcdf5342fc354c24418203506 100755 (executable)
@@ -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
index 4f2a113cc4bb7db1bea8a31b23cc7f5652ba1755..d3a87b18c5e0b7c3dbf34e47acef40381e2f982b 100644 (file)
@@ -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 (file)
index 0000000..60ba575
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ *     The PCI Library -- NetBSD libpci access
+ *         (based on FreeBSD /dev/pci access)
+ *
+ *     Copyright (c) 1999 Jari Kirma <kirma@cs.hut.fi>
+ *      Copyright (c) 2002 Quentin Garnier <cube@cubidou.net>
+ *
+ *     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 <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <pci.h>
+
+#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 */
+};
index b158c34c9cbbfd6a01507e227d6b2323c19b634b..bea893cf3bdcc8fa62378b325ee746b2297e8c69 100644 (file)
--- 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 <sys/types.h>
+
+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 <sys/param.h>
 
@@ -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: */