[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

libpciaccess: Changes to 'debian-unstable'



 ChangeLog                |  132 ++++++++++
 configure.ac             |    2 
 debian/changelog         |    6 
 src/Makefile.am          |   10 
 src/common_device_name.c |    7 
 src/common_io.c          |   11 
 src/linux_sysfs.c        |   63 +++--
 src/openbsd_pci.c        |  291 +++++++++++++++++++++++
 src/pciaccess_private.h  |    1 
 src/solx_devfs.c         |  588 +++++++++++++++++++++++++++++------------------
 10 files changed, 861 insertions(+), 250 deletions(-)

New commits:
commit 18b086e71382eab982c5abfa3ca97983ae9bcd4f
Author: Cyril Brulebois <kibi@debian.org>
Date:   Sun Mar 4 09:49:08 2012 +0100

    Bump changelogs.

diff --git a/ChangeLog b/ChangeLog
index 6ce65d0..1a95c90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,135 @@
+commit bf705561d347bc5459bc0af033595c66541cac3e
+Author: Jeremy Huddleston <jeremyhu@apple.com>
+Date:   Sat Mar 3 18:19:11 2012 -0800
+
+    configure.ac: Bump to 0.13
+    
+    Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
+
+commit f550c1347d3518874fe1c1d417a57322ee6b52db
+Author: Adam Jackson <ajax@redhat.com>
+Date:   Mon Feb 27 10:43:20 2012 -0500
+
+    linux: Don't use /dev/port
+    
+    Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
+    Signed-off-by: Adam Jackson <ajax@redhat.com>
+
+commit 2a58cd13c3d14cd2ea57826b56e9906ecfc5648a
+Author: Mathias Krause <mathias.krause@secunet.com>
+Date:   Fri Feb 24 09:39:31 2012 +0100
+
+    Use correct type for pci_id file accessor functions
+    
+    This fixes the compiler warning of using the wrong type for gzgets() and
+    gzclose() as they want a gzFile argument, not a pointer to gzFile. The
+    abstraction layer pci_id_file should just abstract the full type.
+    
+    Signed-off-by: Mathias Krause <mathias.krause@secunet.com>
+    Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
+
+commit 167ffb1c4e431763e30c894131e704bb3599c7c1
+Author: Alan Coopersmith <alan.coopersmith@oracle.com>
+Date:   Wed Feb 8 22:14:08 2012 -0800
+
+    solx_devfs.c: fix gcc warnings about casting away const when reading data
+    
+    solx_devfs.c: In function `pci_device_solx_devfs_write':
+    solx_devfs.c:1085: warning: cast discards qualifiers from pointer target type
+    solx_devfs.c:1089: warning: cast discards qualifiers from pointer target type
+    solx_devfs.c:1093: warning: cast discards qualifiers from pointer target type
+    solx_devfs.c:1097: warning: cast discards qualifiers from pointer target type
+    
+    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
+
+commit 573b25ecd34dd69ee14c58f752bffdb5709654b9
+Author: Alan Coopersmith <alan.coopersmith@oracle.com>
+Date:   Wed Feb 8 22:08:08 2012 -0800
+
+    Close pci.ids file when bailing out because realloc failed
+    
+    Error: File Leak
+       Leaked File f
+          at line 272 of src/common_device_name.c in function 'populate_vendor'.
+            f initialized at line 204 with fopen("/usr/share/hwdata/pci.ids", "r").
+    
+    [ This bug was found by the Parfait 0.5.0 bug checking tool.
+      For more information see http://labs.oracle.com/projects/parfait/ ]
+    
+    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
+
+commit ed6c6157bc94283ce0a8526eeff668094cf3992d
+Author: Alan Coopersmith <alan.coopersmith@oracle.com>
+Date:   Wed Feb 8 21:40:54 2012 -0800
+
+    Solaris: reorder functions to remove need for lots of static prototypes
+    
+    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
+
+commit b56f9a84f3dff995a6901ffec6bcc161ec0245ad
+Author: Mark Kettenis <kettenis@openbsd.org>
+Date:   Thu Dec 29 21:14:44 2011 +0100
+
+    OpenBSD: Implement map_legacy and legacy_io
+    
+    Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
+    Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
+    Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
+    Tested-by: Matthieu Herrb <matthieu.herrb@laas.fr>
+
+commit a798395a1bfd9d06d40e2d8d14377a156c94429a
+Author: Daniel Drake <dsd@laptop.org>
+Date:   Fri Nov 25 12:28:48 2011 -0600
+
+    delete_io_handle: fix deletion of last handle
+    
+    When num_ios goes from 1 to 0, a realloc(ios, 0); call is made.
+    This is equivalent to free(ios) and NULL is returned.
+    
+    However, the previous logic in the code incorrectly discards this NULL
+    return value. When we next call new_io_handle(), realloc(ios, X) is
+    called with "ios" pointing to freed memory. This causes glibc to abort.
+    
+    Correct this logic to detect the 1-to-0 case and handle it correctly.
+    Other cases are unchanged; there is still value in checking the
+    return value from realloc() as it also returns NULL on error.
+    
+    Signed-off-by: Daniel Drake <dsd@laptop.org>
+    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
+
+commit 2601ddd02d608c16b0022fe342e0a3f4bf6cadeb
+Author: Mark Kettenis <mark.kettenis@xs4all.nl>
+Date:   Sun Nov 6 17:34:29 2011 +0000
+
+    Add VGA Arbiter support for OpenBSD.
+    
+    Signed-off-by: Matthieu Herrb <matthieu.herrb@laas.fr>
+
+commit e64ee4ee2b23dba147d144aacead3cb61c744854
+Author: Mark Kettenis <mark.kettenis@xs4all.nl>
+Date:   Sun Nov 6 17:32:51 2011 +0000
+
+    OpenBSD: Indicate that devices need access to legacy VGA resources.
+    
+    Makes sure xserver disables DRI if the VGA arbiter is in use.
+    
+    Signed-off-by: Matthieu Herrb <matthieu.herrb@laas.fr>
+
+commit cfae4096835fe569edb03cd12d4580fc912a0e61
+Author: Henry Zhao <henry.zhao@oracle.com>
+Date:   Mon Nov 14 18:53:21 2011 -0800
+
+    Solaris: improve support for sparc platform
+    
+    (1) added prom property retrieval on sparc
+    (2) added multiple domain support on sparc
+    (3) use kernel device as mapping device
+    (4) performance improvements by removing redundant ioctl
+    
+    Signed-off-by: Henry Zhao <henry.zhao@oracle.com>
+    Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
+    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
+
 commit 78eed07d599ff9e30c075aa7c8d1795e125ffc4b
 Author: Jeremy Huddleston <jeremyhu@apple.com>
 Date:   Wed Nov 9 09:27:49 2011 -0800
diff --git a/debian/changelog b/debian/changelog
index 708590f..13ad61f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+libpciaccess (0.13-1) unstable; urgency=low
+
+  * New upstream release.
+
+ -- Cyril Brulebois <kibi@debian.org>  Sun, 04 Mar 2012 09:48:43 +0100
+
 libpciaccess (0.12.902-1) unstable; urgency=low
 
   * New upstream release candidate.

commit bf705561d347bc5459bc0af033595c66541cac3e
Author: Jeremy Huddleston <jeremyhu@apple.com>
Date:   Sat Mar 3 18:19:11 2012 -0800

    configure.ac: Bump to 0.13
    
    Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>

diff --git a/configure.ac b/configure.ac
index d63ad25..89179ba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,7 +23,7 @@
 
 # Initialize Autoconf
 AC_PREREQ([2.60])
-AC_INIT([libpciaccess],[0.12.902],
+AC_INIT([libpciaccess],[0.13],
         [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg&component=libpciaccess],[libpciaccess])
 AC_CONFIG_SRCDIR([Makefile.am])
 AC_CONFIG_HEADERS([config.h])

commit f550c1347d3518874fe1c1d417a57322ee6b52db
Author: Adam Jackson <ajax@redhat.com>
Date:   Mon Feb 27 10:43:20 2012 -0500

    linux: Don't use /dev/port
    
    Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
    Signed-off-by: Adam Jackson <ajax@redhat.com>

diff --git a/src/linux_sysfs.c b/src/linux_sysfs.c
index 09e7138..9566d40 100644
--- a/src/linux_sysfs.c
+++ b/src/linux_sysfs.c
@@ -1,6 +1,7 @@
 /*
  * (C) Copyright IBM Corporation 2006
  * All Rights Reserved.
+ * Copyright 2012 Red Hat, Inc.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -44,6 +45,18 @@
 #include <dirent.h>
 #include <errno.h>
 
+#if defined(__i386__) || defined(__x86_64__) || defined(__arm__)
+#include <sys/io.h>
+#else
+#define inb(x) -1
+#define inw(x) -1
+#define inl(x) -1
+#define outb(x) do {} while (0)
+#define outw(x) do {} while (0)
+#define outl(x) do {} while (0)
+#define iopl(x) -1
+#endif
+
 #include "config.h"
 
 #ifdef HAVE_MTRR
@@ -769,12 +782,17 @@ pci_device_linux_sysfs_open_legacy_io(struct pci_io_handle *ret,
 	dev = pci_device_get_parent_bridge(dev);
     }
 
-    /* If not, /dev/port is the best we can do */
-    if (!dev)
-	ret->fd = open("/dev/port", O_RDWR);
+    /*
+     * You would think you'd want to use /dev/port here.  Don't make that
+     * mistake, /dev/port only does byte-wide i/o cycles which means it
+     * doesn't work.  If you think this is stupid, well, you're right.
+     */
 
-    if (ret->fd < 0)
-	return NULL;
+    /* If we've no other choice, iopl */
+    if (ret->fd < 0) {
+	if (iopl(3))
+	    return NULL;
+    }
 
     ret->base = base;
     ret->size = size;
@@ -786,7 +804,8 @@ static void
 pci_device_linux_sysfs_close_io(struct pci_device *dev,
 				struct pci_io_handle *handle)
 {
-    close(handle->fd);
+    if (handle->fd > -1)
+	close(handle->fd);
 }
 
 static uint32_t
@@ -794,8 +813,11 @@ pci_device_linux_sysfs_read32(struct pci_io_handle *handle, uint32_t port)
 {
     uint32_t ret;
 
-    pread(handle->fd, &ret, 4, port + handle->base);
-
+    if (handle->fd > -1)
+	pread(handle->fd, &ret, 4, port + handle->base);
+    else
+	ret = inl(port + handle->base);
+	
     return ret;
 }
 
@@ -804,7 +826,10 @@ pci_device_linux_sysfs_read16(struct pci_io_handle *handle, uint32_t port)
 {
     uint16_t ret;
 
-    pread(handle->fd, &ret, 2, port + handle->base);
+    if (handle->fd > -1)
+	pread(handle->fd, &ret, 2, port + handle->base);
+    else
+	ret = inw(port + handle->base);
 
     return ret;
 }
@@ -814,7 +839,10 @@ pci_device_linux_sysfs_read8(struct pci_io_handle *handle, uint32_t port)
 {
     uint8_t ret;
 
-    pread(handle->fd, &ret, 1, port + handle->base);
+    if (handle->fd > -1)
+	pread(handle->fd, &ret, 1, port + handle->base);
+    else
+	ret = inb(port + handle->base);
 
     return ret;
 }
@@ -823,21 +851,30 @@ static void
 pci_device_linux_sysfs_write32(struct pci_io_handle *handle, uint32_t port,
 			       uint32_t data)
 {
-    pwrite(handle->fd, &data, 4, port + handle->base);
+    if (handle->fd > -1)
+	pwrite(handle->fd, &data, 4, port + handle->base);
+    else
+	outl(data, port + handle->base);
 }
 
 static void
 pci_device_linux_sysfs_write16(struct pci_io_handle *handle, uint32_t port,
 			       uint16_t data)
 {
-    pwrite(handle->fd, &data, 2, port + handle->base);
+    if (handle->fd > -1)
+	pwrite(handle->fd, &data, 2, port + handle->base);
+    else
+	outw(data, port + handle->base);
 }
 
 static void
 pci_device_linux_sysfs_write8(struct pci_io_handle *handle, uint32_t port,
 			      uint8_t data)
 {
-    pwrite(handle->fd, &data, 1, port + handle->base);
+    if (handle->fd > -1)
+	pwrite(handle->fd, &data, 1, port + handle->base);
+    else
+	outb(data, port + handle->base);
 }
 
 static int

commit 2a58cd13c3d14cd2ea57826b56e9906ecfc5648a
Author: Mathias Krause <mathias.krause@secunet.com>
Date:   Fri Feb 24 09:39:31 2012 +0100

    Use correct type for pci_id file accessor functions
    
    This fixes the compiler warning of using the wrong type for gzgets() and
    gzclose() as they want a gzFile argument, not a pointer to gzFile. The
    abstraction layer pci_id_file should just abstract the full type.
    
    Signed-off-by: Mathias Krause <mathias.krause@secunet.com>
    Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>

diff --git a/src/common_device_name.c b/src/common_device_name.c
index 8feaf69..b2765dd 100644
--- a/src/common_device_name.c
+++ b/src/common_device_name.c
@@ -69,7 +69,7 @@ pci_id_file_open(void)
 #define pci_id_file_gets(l, s, f)	gzgets(f, l, s)
 #define pci_id_file_close(f)		gzclose(f)
 #else
-typedef FILE pci_id_file;
+typedef FILE * pci_id_file;
 #define pci_id_file_open()		fopen(PCIIDS_PATH "/pci.ids", "r")
 #define pci_id_file_gets(l, s, f)	fgets(l, s, f)
 #define pci_id_file_close(f)		fclose(f)
@@ -189,7 +189,7 @@ insert( uint16_t vendor )
 static void
 populate_vendor( struct pci_id_leaf * vend, int fill_device_data )
 {
-    pci_id_file * f;
+    pci_id_file f;
     char buf[128];
     unsigned vendor = PCI_MATCH_ANY;
 

commit 167ffb1c4e431763e30c894131e704bb3599c7c1
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date:   Wed Feb 8 22:14:08 2012 -0800

    solx_devfs.c: fix gcc warnings about casting away const when reading data
    
    solx_devfs.c: In function `pci_device_solx_devfs_write':
    solx_devfs.c:1085: warning: cast discards qualifiers from pointer target type
    solx_devfs.c:1089: warning: cast discards qualifiers from pointer target type
    solx_devfs.c:1093: warning: cast discards qualifiers from pointer target type
    solx_devfs.c:1097: warning: cast discards qualifiers from pointer target type
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>

diff --git a/src/solx_devfs.c b/src/solx_devfs.c
index 6920e0f..5e91a14 100644
--- a/src/solx_devfs.c
+++ b/src/solx_devfs.c
@@ -1082,19 +1082,19 @@ pci_device_solx_devfs_write( struct pci_device * dev, const void * data,
     switch (size) {
         case 1:
 	    cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_1 + NATIVE_ENDIAN;
-	    cfg_prg.data = *((uint8_t *)data);
+	    cfg_prg.data = *((const uint8_t *)data);
 	    break;
         case 2:
 	    cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_2 + NATIVE_ENDIAN;
-	    cfg_prg.data = *((uint16_t *)data);
+	    cfg_prg.data = *((const uint16_t *)data);
 	    break;
         case 4:
 	    cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_4 + NATIVE_ENDIAN;
-	    cfg_prg.data = *((uint32_t *)data);
+	    cfg_prg.data = *((const uint32_t *)data);
 	    break;
         case 8:
 	    cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_8 + NATIVE_ENDIAN;
-	    cfg_prg.data = *((uint64_t *)data);
+	    cfg_prg.data = *((const uint64_t *)data);
 	    break;
         default:
 	    return EINVAL;

commit 573b25ecd34dd69ee14c58f752bffdb5709654b9
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date:   Wed Feb 8 22:08:08 2012 -0800

    Close pci.ids file when bailing out because realloc failed
    
    Error: File Leak
       Leaked File f
          at line 272 of src/common_device_name.c in function 'populate_vendor'.
            f initialized at line 204 with fopen("/usr/share/hwdata/pci.ids", "r").
    
    [ This bug was found by the Parfait 0.5.0 bug checking tool.
      For more information see http://labs.oracle.com/projects/parfait/ ]
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>

diff --git a/src/common_device_name.c b/src/common_device_name.c
index 8e8a752..8feaf69 100644
--- a/src/common_device_name.c
+++ b/src/common_device_name.c
@@ -269,7 +269,7 @@ populate_vendor( struct pci_id_leaf * vend, int fill_device_data )
 	    d = realloc( vend->devices, (vend->num_devices + 1)
 			 * sizeof( struct pci_device_leaf ) );
 	    if ( d == NULL ) {
-		return;
+		goto cleanup;
 	    }
 
 	    last_dev = & d[ vend->num_devices - 1 ];
@@ -302,6 +302,7 @@ populate_vendor( struct pci_id_leaf * vend, int fill_device_data )
 	}
     }
 
+  cleanup:
     pci_id_file_close( f );
 }
 

commit ed6c6157bc94283ce0a8526eeff668094cf3992d
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date:   Wed Feb 8 21:40:54 2012 -0800

    Solaris: reorder functions to remove need for lots of static prototypes
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>

diff --git a/src/solx_devfs.c b/src/solx_devfs.c
index b668318..6920e0f 100644
--- a/src/solx_devfs.c
+++ b/src/solx_devfs.c
@@ -126,48 +126,6 @@ static di_prom_handle_t di_phdl;
 # define U45_SB_CLASS_RID	0x06040000
 #endif
 
-static int pci_device_solx_devfs_map_range(struct pci_device *dev,
-    struct pci_device_mapping *map);
-
-static int pci_device_solx_devfs_read_rom( struct pci_device * dev,
-    void * buffer );
-
-static int pci_device_solx_devfs_probe( struct pci_device * dev );
-
-static int pci_device_solx_devfs_read( struct pci_device * dev, void * data,
-    pciaddr_t offset, pciaddr_t size, pciaddr_t * bytes_read );
-
-static int pci_device_solx_devfs_write( struct pci_device * dev,
-    const void * data, pciaddr_t offset, pciaddr_t size,
-    pciaddr_t * bytes_written );
-
-static int probe_dev(nexus_t *nexus, pcitool_reg_t *prg_p, probe_info_t *pinfo);
-
-static int do_probe(nexus_t *nexus, probe_info_t *pinfo);
-
-static int probe_nexus_node(di_node_t di_node, di_minor_t minor, void *arg);
-
-static void pci_system_solx_devfs_destroy( void );
-
-static int get_config_header(int fd, uint8_t bus_no, uint8_t dev_no,
-			     uint8_t func_no, pci_conf_hdr_t *config_hdr_p);
-
-int pci_system_solx_devfs_create( void );
-
-static const struct pci_system_methods solx_devfs_methods = {
-    .destroy = pci_system_solx_devfs_destroy,
-    .destroy_device = NULL,
-    .read_rom = pci_device_solx_devfs_read_rom,
-    .probe = pci_device_solx_devfs_probe,
-    .map_range = pci_device_solx_devfs_map_range,
-    .unmap_range = pci_device_generic_unmap_range,
-
-    .read = pci_device_solx_devfs_read,
-    .write = pci_device_solx_devfs_write,
-
-    .fill_capabilities = pci_fill_capabilities_generic
-};
-
 #ifdef __sparc
 static nexus_t *
 find_nexus_for_dev(struct pci_device *dev)
@@ -256,61 +214,6 @@ pci_system_solx_devfs_destroy( void )
 }
 
 /*
- * Attempt to access PCI subsystem using Solaris's devfs interface.
- * Solaris version
- */
-_pci_hidden int
-pci_system_solx_devfs_create( void )
-{
-    int err = 0;
-    di_node_t di_node;
-    probe_info_t pinfo;
-    struct pci_device_private *devices;
-
-    if (nexus_list != NULL) {
-	return 0;
-    }
-
-    if ((di_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
-	err = errno;
-	(void) fprintf(stderr, "di_init() failed: %s\n",
-		       strerror(errno));
-	return (err);
-    }
-
-    if ((devices = calloc(INITIAL_NUM_DEVICES,
-			sizeof (struct pci_device_private))) == NULL) {
-	err = errno;
-	di_fini(di_node);
-	return (err);
-    }
-
-#ifdef __sparc
-    if ((di_phdl = di_prom_init()) == DI_PROM_HANDLE_NIL)
-	(void) fprintf(stderr, "di_prom_init failed: %s\n", strerror(errno));
-#endif
-
-    pinfo.num_allocated_elems = INITIAL_NUM_DEVICES;
-    pinfo.num_devices = 0;
-    pinfo.devices = devices;
-    (void) di_walk_minor(di_node, DDI_NT_REGACC, 0, &pinfo, probe_nexus_node);
-
-    di_fini(di_node);
-
-    if ((pci_sys = calloc(1, sizeof (struct pci_system))) == NULL) {
-	err = errno;
-	free(devices);
-	return (err);
-    }
-
-    pci_sys->methods = &solx_devfs_methods;
-    pci_sys->devices = pinfo.devices;
-    pci_sys->num_devices = pinfo.num_devices;
-
-    return (err);
-}
-
-/*
  * Retrieve first 16 dwords of device's config header, except for the first
  * dword.  First 16 dwords are defined by the PCI specification.
  */
@@ -562,6 +465,64 @@ probe_dev(nexus_t *nexus, pcitool_reg_t *prg_p, probe_info_t *pinfo)
     return (rval);
 }
 
+
+/*
+ * Solaris version
+ * Probe a given nexus config space for devices.
+ *
+ * fd is the file descriptor of the nexus.
+ * input_args contains commandline options as specified by the user.
+ */
+static int
+do_probe(nexus_t *nexus, probe_info_t *pinfo)
+{
+    pcitool_reg_t prg;
+    uint32_t bus;
+    uint8_t dev;
+    uint32_t last_bus = nexus->last_bus;
+    uint8_t last_dev = PCI_REG_DEV_M >> PCI_REG_DEV_SHIFT;
+    uint8_t first_bus = nexus->first_bus;
+    uint8_t first_dev = 0;
+    int rval = 0;
+
+    prg.barnum = 0;	/* Config space. */
+
+    /* Must read in 4-byte quantities. */
+    prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_4 + NATIVE_ENDIAN;
+
+    prg.data = 0;
+
+    /*
+     * Loop through all valid bus / dev / func combinations to check for
+     * all devices, with the following exceptions:
+     *
+     * When nothing is found at function 0 of a bus / dev combination, skip
+     * the other functions of that bus / dev combination.
+     *
+     * When a found device's function 0 is probed and it is determined that
+     * it is not a multifunction device, skip probing of that device's
+     * other functions.
+     */
+    for (bus = first_bus; ((bus <= last_bus) && (rval == 0)); bus++) {
+	prg.bus_no = (uint8_t)bus;
+
+	for (dev = first_dev; ((dev <= last_dev) && (rval == 0)); dev++) {
+	    prg.dev_no = dev;
+	    rval = probe_dev(nexus, &prg, pinfo);
+	}
+
+	/*
+	 * Ultra-45 southbridge workaround:
+	 * ECANCELED tells to skip to the next bus.
+	 */
+	if (rval == ECANCELED) {
+	    rval = 0;
+	}
+    }
+
+    return (rval);
+}
+
 /*
  * This function is called from di_walk_minor() when any PROBE is processed
  */
@@ -728,64 +689,6 @@ probe_nexus_node(di_node_t di_node, di_minor_t minor, void *arg)
     return DI_WALK_CONTINUE;
 }
 
-
-/*
- * Solaris version
- * Probe a given nexus config space for devices.
- *
- * fd is the file descriptor of the nexus.
- * input_args contains commandline options as specified by the user.
- */
-static int
-do_probe(nexus_t *nexus, probe_info_t *pinfo)
-{
-    pcitool_reg_t prg;
-    uint32_t bus;
-    uint8_t dev;
-    uint32_t last_bus = nexus->last_bus;
-    uint8_t last_dev = PCI_REG_DEV_M >> PCI_REG_DEV_SHIFT;
-    uint8_t first_bus = nexus->first_bus;
-    uint8_t first_dev = 0;
-    int rval = 0;
-
-    prg.barnum = 0;	/* Config space. */
-
-    /* Must read in 4-byte quantities. */
-    prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_4 + NATIVE_ENDIAN;
-
-    prg.data = 0;
-
-    /*
-     * Loop through all valid bus / dev / func combinations to check for
-     * all devices, with the following exceptions:
-     *
-     * When nothing is found at function 0 of a bus / dev combination, skip
-     * the other functions of that bus / dev combination.
-     *
-     * When a found device's function 0 is probed and it is determined that
-     * it is not a multifunction device, skip probing of that device's
-     * other functions.
-     */
-    for (bus = first_bus; ((bus <= last_bus) && (rval == 0)); bus++) {
-	prg.bus_no = (uint8_t)bus;
-
-	for (dev = first_dev; ((dev <= last_dev) && (rval == 0)); dev++) {
-	    prg.dev_no = dev;
-	    rval = probe_dev(nexus, &prg, pinfo);
-	}
-
-	/*
-	 * Ultra-45 southbridge workaround:
-	 * ECANCELED tells to skip to the next bus.
-	 */
-	if (rval == ECANCELED) {
-	    rval = 0;
-	}
-    }
-
-    return (rval);
-}
-
 static int
 find_target_node(di_node_t node, void *arg)
 {
@@ -1002,6 +905,70 @@ pci_device_solx_devfs_probe( struct pci_device * dev )
     return (err);
 }
 
+/**
+ * Map a memory region for a device using /dev/xsvc.
+ *
+ * \param dev   Device whose memory region is to be mapped.
+ * \param map   Parameters of the mapping that is to be created.
+ *
+ * \return
+ * Zero on success or an \c errno value on failure.
+ */
+static int
+pci_device_solx_devfs_map_range(struct pci_device *dev,
+				struct pci_device_mapping *map)
+{
+    const int prot = ((map->flags & PCI_DEV_MAP_FLAG_WRITABLE) != 0)
+			? (PROT_READ | PROT_WRITE) : PROT_READ;
+    int err = 0;
+
+#ifdef __sparc
+    char	map_dev[128];
+    int		map_fd;
+
+    if (MAPPING_DEV_PATH(dev))
+	snprintf(map_dev, sizeof (map_dev), "%s%s", "/devices", MAPPING_DEV_PATH(dev));
+    else
+	strcpy (map_dev, "/dev/fb0");
+
+    if ((map_fd = open(map_dev, O_RDWR)) < 0) {
+	err = errno;
+	(void) fprintf(stderr, "can not open %s: %s\n", map_dev,
+			   strerror(errno));
+	return err;
+    }
+
+    map->memory = mmap(NULL, map->size, prot, MAP_SHARED, map_fd, map->base);
+#else
+    /*
+     * Still used xsvc to do the user space mapping
+     */
+    if (xsvc_fd < 0) {
+	if ((xsvc_fd = open("/dev/xsvc", O_RDWR)) < 0) {
+	    err = errno;
+	    (void) fprintf(stderr, "can not open /dev/xsvc: %s\n",
+			   strerror(errno));
+	    return err;
+	}
+    }
+
+    map->memory = mmap(NULL, map->size, prot, MAP_SHARED, xsvc_fd, map->base);
+#endif
+
+    if (map->memory == MAP_FAILED) {
+	err = errno;
+
+	(void) fprintf(stderr, "map rom region =%llx failed: %s\n",
+		       map->base, strerror(errno));
+    }
+
+#ifdef __sparc
+    close (map_fd);
+#endif
+
+    return err;
+}
+
 /*
  * Solaris version: read the VGA ROM data
  */
@@ -1156,66 +1123,72 @@ pci_device_solx_devfs_write( struct pci_device * dev, const void * data,
 }
 
 
-/**
- * Map a memory region for a device using /dev/xsvc.
- *
- * \param dev   Device whose memory region is to be mapped.
- * \param map   Parameters of the mapping that is to be created.
- *
- * \return
- * Zero on success or an \c errno value on failure.
+
+static const struct pci_system_methods solx_devfs_methods = {
+    .destroy = pci_system_solx_devfs_destroy,
+    .destroy_device = NULL,
+    .read_rom = pci_device_solx_devfs_read_rom,
+    .probe = pci_device_solx_devfs_probe,
+    .map_range = pci_device_solx_devfs_map_range,
+    .unmap_range = pci_device_generic_unmap_range,
+
+    .read = pci_device_solx_devfs_read,
+    .write = pci_device_solx_devfs_write,
+
+    .fill_capabilities = pci_fill_capabilities_generic
+};
+
+/*
+ * Attempt to access PCI subsystem using Solaris's devfs interface.
+ * Solaris version
  */
-static int
-pci_device_solx_devfs_map_range(struct pci_device *dev,
-				struct pci_device_mapping *map)
+_pci_hidden int
+pci_system_solx_devfs_create( void )
 {
-    const int prot = ((map->flags & PCI_DEV_MAP_FLAG_WRITABLE) != 0)
-			? (PROT_READ | PROT_WRITE) : PROT_READ;
     int err = 0;
+    di_node_t di_node;
+    probe_info_t pinfo;
+    struct pci_device_private *devices;
 
-#ifdef __sparc
-    char	map_dev[128];
-    int		map_fd;
-
-    if (MAPPING_DEV_PATH(dev))
-	snprintf(map_dev, sizeof (map_dev), "%s%s", "/devices", MAPPING_DEV_PATH(dev));
-    else
-	strcpy (map_dev, "/dev/fb0");
+    if (nexus_list != NULL) {
+	return 0;
+    }
 
-    if ((map_fd = open(map_dev, O_RDWR)) < 0) {
+    if ((di_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
 	err = errno;
-	(void) fprintf(stderr, "can not open %s: %s\n", map_dev,
-			   strerror(errno));
-	return err;
+	(void) fprintf(stderr, "di_init() failed: %s\n",
+		       strerror(errno));
+	return (err);
     }
 
-    map->memory = mmap(NULL, map->size, prot, MAP_SHARED, map_fd, map->base);
-#else
-    /*
-     * Still used xsvc to do the user space mapping
-     */
-    if (xsvc_fd < 0) {
-	if ((xsvc_fd = open("/dev/xsvc", O_RDWR)) < 0) {
-	    err = errno;
-	    (void) fprintf(stderr, "can not open /dev/xsvc: %s\n",
-			   strerror(errno));
-	    return err;
-	}
+    if ((devices = calloc(INITIAL_NUM_DEVICES,
+			sizeof (struct pci_device_private))) == NULL) {
+	err = errno;
+	di_fini(di_node);
+	return (err);
     }
 
-    map->memory = mmap(NULL, map->size, prot, MAP_SHARED, xsvc_fd, map->base);
+#ifdef __sparc
+    if ((di_phdl = di_prom_init()) == DI_PROM_HANDLE_NIL)
+	(void) fprintf(stderr, "di_prom_init failed: %s\n", strerror(errno));
 #endif
 
-    if (map->memory == MAP_FAILED) {
-	err = errno;
+    pinfo.num_allocated_elems = INITIAL_NUM_DEVICES;
+    pinfo.num_devices = 0;
+    pinfo.devices = devices;
+    (void) di_walk_minor(di_node, DDI_NT_REGACC, 0, &pinfo, probe_nexus_node);
 
-	(void) fprintf(stderr, "map rom region =%llx failed: %s\n",
-		       map->base, strerror(errno));
+    di_fini(di_node);
+
+    if ((pci_sys = calloc(1, sizeof (struct pci_system))) == NULL) {
+	err = errno;
+	free(devices);
+	return (err);
     }
 
-#ifdef __sparc
-    close (map_fd);
-#endif
+    pci_sys->methods = &solx_devfs_methods;
+    pci_sys->devices = pinfo.devices;
+    pci_sys->num_devices = pinfo.num_devices;
 
-    return err;
+    return (err);
 }

commit b56f9a84f3dff995a6901ffec6bcc161ec0245ad
Author: Mark Kettenis <kettenis@openbsd.org>
Date:   Thu Dec 29 21:14:44 2011 +0100

    OpenBSD: Implement map_legacy and legacy_io
    
    Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
    Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
    Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
    Tested-by: Matthieu Herrb <matthieu.herrb@laas.fr>

diff --git a/src/openbsd_pci.c b/src/openbsd_pci.c
index 219aba7..14e976d 100644
--- a/src/openbsd_pci.c
+++ b/src/openbsd_pci.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008 Mark Kettenis
+ * Copyright (c) 2008, 2011 Mark Kettenis
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -394,6 +394,141 @@ pci_device_openbsd_probe(struct pci_device *device)
 	return 0;
 }
 
+#if defined(__i386__) || defined(__amd64__)
+#include <machine/sysarch.h>
+#include <machine/pio.h>
+#endif
+
+static struct pci_io_handle *
+pci_device_openbsd_open_legacy_io(struct pci_io_handle *ret,
+    struct pci_device *dev, pciaddr_t base, pciaddr_t size)
+{
+#if defined(__i386__)
+	struct i386_iopl_args ia;
+
+	ia.iopl = 1;
+	if (sysarch(I386_IOPL, &ia))
+		return NULL;
+
+	ret->base = base;
+	ret->size = size;
+	return ret;
+#elif defined(__amd64__)
+	struct amd64_iopl_args ia;
+
+	ia.iopl = 1;
+	if (sysarch(AMD64_IOPL, &ia))
+		return NULL;
+
+	ret->base = base;
+	ret->size = size;
+	return ret;
+#elif defined(PCI_MAGIC_IO_RANGE)
+	ret->memory = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
+	    aperturefd, PCI_MAGIC_IO_RANGE + base);
+	if (ret->memory == MAP_FAILED)
+		return NULL;
+
+	ret->base = base;
+	ret->size = size;
+	return ret;
+#else
+	return NULL;
+#endif
+}
+
+static uint32_t
+pci_device_openbsd_read32(struct pci_io_handle *handle, uint32_t reg)
+{
+#if defined(__i386__) || defined(__amd64__)
+	return inl(handle->base + reg);
+#else
+	return *(uint32_t *)((uintptr_t)handle->memory + reg);
+#endif
+}
+
+static uint16_t
+pci_device_openbsd_read16(struct pci_io_handle *handle, uint32_t reg)
+{
+#if defined(__i386__) || defined(__amd64__)
+	return inw(handle->base + reg);
+#else
+	return *(uint16_t *)((uintptr_t)handle->memory + reg);
+#endif
+}
+
+static uint8_t
+pci_device_openbsd_read8(struct pci_io_handle *handle, uint32_t reg)
+{
+#if defined(__i386__) || defined(__amd64__)
+	return inb(handle->base + reg);
+#else
+	return *(uint8_t *)((uintptr_t)handle->memory + reg);
+#endif


Reply to: