]> mj.ucw.cz Git - pciutils.git/commitdiff
Added OpenBSD interface.
authorMartin Mares <mj@ucw.cz>
Fri, 5 May 2006 12:30:35 +0000 (14:30 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 5 May 2006 12:30:35 +0000 (14:30 +0200)
ChangeLog
lib/Makefile
lib/access.c
lib/configure
lib/internal.h
lib/obsd-device.c [new file with mode: 0644]
lib/pci.h

index 75ff0846cfda8c50aa6735a8208eaca6c0b8ef0f..c271f260e0d39cc3c72a8c1d8c3aacdda68dbeba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2006-05-05  Martin Mares  <mj@ucw.cz>
 
+       * lib/obsd-device.c (and other files in lib/*): Added OpenBSD
+       interface by Matthieu Herrb <matthieu.herrb@laas.fr>, based on
+       the existing FreeBSD interface.
+
        * Moved pciutils to a GIT repository, which now contains merged
        history from both CVS and Arch. Good bye, TLA!
 
index 44296ca8595009add49aee6b181f8751d8c644a5..2839db55b277d643452c8de96d210964b1b5a10e 100644 (file)
@@ -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
index 5683eac8dd96a7b3e1b9c493024e155c227af2dc..0ee85c13aa454cd8880b0099c6054dcd1a00165a 100644 (file)
@@ -47,6 +47,11 @@ static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = {
 #else
   NULL,
 #endif
+#ifdef PCI_HAVE_PM_OBSD_DEVICE
+  &pm_obsd_device,
+#else
+  NULL,
+#endif
 #ifdef PCI_HAVE_PM_DUMP
   &pm_dump,
 #else
index ecd350352d444fac3d1ddcc5b67b41c2cc5b8feb..2a91c39732f3d079a9b73209641fcc83c1ec4312 100755 (executable)
@@ -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'
index cae18007578f9362b6a87ab4be6fe4db397b8fb4..117d7b224f0ff0c24c5ae8301e103c7e82eb73cc 100644 (file)
@@ -36,4 +36,5 @@ 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_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;
diff --git a/lib/obsd-device.c b/lib/obsd-device.c
new file mode 100644 (file)
index 0000000..e3e3630
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ *     The PCI Library -- OpenBSD /dev/pci access
+ *
+ *     Adapted from fbsd-device.c by Matthieu Herrb <matthieu.herrb@laas.fr>, 2006
+ *
+ *     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 */
+};
index 5b551ba1f88d603c456f39a113c8fd0d5e6496df..7fa1de656b309361562d058fd6605f60bd398600 100644 (file)
--- a/lib/pci.h
+++ b/lib/pci.h
@@ -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
 };