]> mj.ucw.cz Git - pciutils.git/commitdiff
Cleaned up NetBSD access functions.
authorMartin Mares <mj@ucw.cz>
Fri, 27 Dec 2002 19:59:26 +0000 (19:59 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 5 May 2006 12:10:53 +0000 (14:10 +0200)
ChangeLog
Makefile
lib/nbsd-libpci.c

index 6052a2fa87c80a7c6e5a7558395bdab02068a84e..d7a2e4dfb65bc5bc1512a5e4a4c48b0b57136c77 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2002-12-27  Martin Mares  <mj@ucw.cz>
 
+       * lib/nbsd-libpci.c: Cleaned up and hopefully made it endian safe.
+
        * lib/generic.c (pci_generic_scan_bus): Added work-around for devices with
        discontiguous numbering of functions. This is already present in the Linux
        kernel for several years, but I forgot to update pciutils as well.
index fb324308f6b522c1631d9796d5ecf1ef90c27c2f..6246266fb6cb2dca90e17604ebfd0e3e944160a2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.44 2002/12/27 19:02:20 mj Exp $
+# $Id: Makefile,v 1.45 2002/12/27 19:59:26 mj Exp $
 # Makefile for Linux PCI Utilities
 # (c) 1998--2002 Martin Mares <mj@ucw.cz>
 
@@ -7,8 +7,8 @@ OPT=-O2 -fomit-frame-pointer
 CFLAGS=$(OPT) -Wall -W -Wno-parentheses -Wstrict-prototypes
 
 VERSION=2.1.11
-SUFFIX=-pre1
-DATE=2002-12-26
+SUFFIX=-pre2
+DATE=2002-12-27
 
 INSTALL=install
 DIRINSTALL=install -d
index 60ba57530ba7cc9e86c63851430b9a2bf37f3053..e1bebd7d60a056485b4d99e2ec20d19c33ff315d 100644 (file)
@@ -4,6 +4,7 @@
  *
  *     Copyright (c) 1999 Jari Kirma <kirma@cs.hut.fi>
  *      Copyright (c) 2002 Quentin Garnier <cube@cubidou.net>
+ *     Copyright (c) 2002 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
@@ -48,9 +49,7 @@ nbsd_init(struct pci_access *a)
 
   a->fd = open(name, O_RDWR, 0);
   if (a->fd < 0)
-    {
-      a->error("nbsd_init: %s open failed", name);
-    }
+    a->error("nbsd_init: %s open failed", name);
 }
 
 static void
@@ -63,26 +62,27 @@ static int
 nbsd_read(struct pci_dev *d, int pos, byte *buf, int len)
 {
   pcireg_t val;
+  int shift;
 
   if (!(len == 1 || len == 2 || len == 4))
-    {
-      return pci_generic_block_read(d, pos, buf, len);
-    }
+    return pci_generic_block_read(d, pos, buf, len);
 
+  shift = 8*(pos % 4);
+  pos &= ~3;
        
   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);
+      *buf = val >> shift;
       break;
     case 2:
-      ((u16 *) buf)[0] = (u16) val;
+      *(u16*)buf = cpu_to_le16(val >> shift);
       break;
     case 4:
-      ((u32 *) buf)[0] = (u32) val;
+      *(u32*)buf = cpu_to_le32(val);
       break;
     }
   return 1;
@@ -91,23 +91,36 @@ nbsd_read(struct pci_dev *d, int pos, byte *buf, int len)
 static int
 nbsd_write(struct pci_dev *d, int pos, byte *buf, int len)
 {
-  pcireg_t val;
+  pcireg_t val = 0;
+  int shift;
 
   if (!(len == 1 || len == 2 || len == 4))
+    return pci_generic_block_write(d, pos, buf, len);
+
+  /*
+   *  BEWARE: NetBSD seems to support only 32-bit access, so we have
+   *  to emulate byte and word writes by read-modify-write, possibly
+   *  causing troubles.
+   */
+
+  shift = 8*(pos % 4);
+  pos &= 3;
+  if (len != 4)
     {
-      return pci_generic_block_write(d, pos, buf, len);
+      if (pcibus_conf_read(d->access->fd, d->bus, d->dev, d->func, pos, &val) < 0)
+       d->access->error("nbsd_write: pci_bus_conf_read() failed");
     }
 
   switch (len)
     {
     case 1:
-      val = buf[0];
+      val = (val & ~(0xff << shift)) | buf[0];
       break;
     case 2:
-      val = ((u16 *) buf)[0];
+      val = (val & ~(0xffff << shift)) | le16_to_cpu(*(u16*)buf);
       break;
     case 4:
-      val = ((u32 *) buf)[0];
+      val = le32_to_cpu(*(u32*)buf);
       break;
     }