On 29/10/18 21:19, Damien Zammit wrote:
> Please see below and attached tarball with all rebased patches:

I have another patch for each of libpciaccess and pciutils that go on
top of my previous ones.

This provides fallback mechanism for when servers/bus/pci is unavailable
it will fall back to regular x86 access methods for both libraries.

See attached.

Thanks,
Damien
>From cc42ae54e07dd0ea0bb8b448253730e88e737a23 Mon Sep 17 00:00:00 2001
From: Damien Zammit <dam...@zamaudio.com>
Date: Fri, 2 Nov 2018 06:33:57 -0400
Subject: [PATCH] Autodetect hurd access method && re-add i386 method for hurd
 as fallback

---
 lib/configure      |  2 ++
 lib/hurd.c         |  3 ++-
 lib/i386-io-hurd.h | 35 +++++++++++++++++++++++++++++++++++
 lib/i386-ports.c   |  2 ++
 lib/init.c         |  1 +
 5 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 lib/i386-io-hurd.h

diff --git a/lib/configure b/lib/configure
index a1541ac..7e12e6f 100755
--- a/lib/configure
+++ b/lib/configure
@@ -127,6 +127,8 @@ case $sys in
 	gnu)
 		echo_n " hurd"
 		echo >>$c '#define PCI_HAVE_PM_HURD_CONF'
+		echo_n " i386-ports"
+		echo >>$c '#define PCI_HAVE_PM_INTEL_CONF'
 		;;
 	djgpp)
 		echo_n " i386-ports"
diff --git a/lib/hurd.c b/lib/hurd.c
index c9581df..6f46902 100644
--- a/lib/hurd.c
+++ b/lib/hurd.c
@@ -50,7 +50,7 @@ hurd_detect (struct pci_access *a)
   err = lstat (_SERVERS_BUS_PCI, &st);
   if (err)
     {
-      a->error ("Could not open file `%s'", _SERVERS_BUS_PCI);
+      a->warning ("Could not open file `%s'", _SERVERS_BUS_PCI);
       return 0;
     }
 
@@ -187,6 +187,7 @@ hurd_scan (struct pci_access *a)
 {
   int err;
 
+  assert (hurd_detect(a) != 0);
   err = enum_devices (_SERVERS_BUS_PCI, a, -1, -1, -1, -1, LEVEL_DOMAIN);
   assert (err == 0);
 }
diff --git a/lib/i386-io-hurd.h b/lib/i386-io-hurd.h
new file mode 100644
index 0000000..261f681
--- /dev/null
+++ b/lib/i386-io-hurd.h
@@ -0,0 +1,35 @@
+/*
+ *     The PCI Library -- Access to i386 I/O ports on GNU Hurd
+ *
+ *     Copyright (c) 2003 Marco Gerards <metgera...@student.han.nl>
+ *     Copyright (c) 2003 Martin Mares <m...@ucw.cz>
+ *     Copyright (c) 2006 Samuel Thibault <samuel.thiba...@ens-lyon.org> and
+ *                        Thomas Schwinge <tschwi...@gnu.org>
+ *     Copyright (c) 2007 Thomas Schwinge <tschwi...@gnu.org>
+ *
+ *     Can be freely distributed and used under the terms of the GNU GPL.
+ */
+
+#include <sys/io.h>
+
+static inline int
+intel_setup_io(struct pci_access *a UNUSED)
+{
+  return (ioperm (0, 65535, 1) == -1) ? 0 : 1;
+}
+
+static inline int
+intel_cleanup_io(struct pci_access *a UNUSED)
+{
+  ioperm (0, 65535, 0);
+
+  return -1;
+}
+
+static inline void intel_io_lock(void)
+{
+}
+
+static inline void intel_io_unlock(void)
+{
+}
diff --git a/lib/i386-ports.c b/lib/i386-ports.c
index 85515ca..c3502d9 100644
--- a/lib/i386-ports.c
+++ b/lib/i386-ports.c
@@ -24,6 +24,8 @@
 #include "i386-io-beos.h"
 #elif defined(PCI_OS_DJGPP)
 #include "i386-io-djgpp.h"
+#elif defined(PCI_OS_GNU)
+#include "i386-io-hurd.h"
 #else
 #error Do not know how to access I/O ports on this OS.
 #endif
diff --git a/lib/init.c b/lib/init.c
index e067f0a..d543301 100644
--- a/lib/init.c
+++ b/lib/init.c
@@ -85,6 +85,7 @@ static int probe_sequence[] = {
   PCI_ACCESS_OBSD_DEVICE,
   PCI_ACCESS_DARWIN,
   PCI_ACCESS_SYLIXOS_DEVICE,
+  PCI_ACCESS_GNU,
   // Low-level methods poking the hardware directly
   PCI_ACCESS_I386_TYPE1,
   PCI_ACCESS_I386_TYPE2,
-- 
2.17.1

>From dd87b5d7e022c82efb068c8f2af84919111e2947 Mon Sep 17 00:00:00 2001
From: Damien Zammit <dam...@zamaudio.com>
Date: Fri, 2 Nov 2018 06:42:28 -0400
Subject: [PATCH libpciaccess] Add fallback mechanism from hurd to x86 access
 method when unavailable

---
 src/hurd_pci.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/hurd_pci.c b/src/hurd_pci.c
index abdcb0e..eefb618 100644
--- a/src/hurd_pci.c
+++ b/src/hurd_pci.c
@@ -460,14 +460,17 @@ pci_system_hurd_create(void)
     pci_sys->methods = &hurd_pci_methods;
 
     pci_server_port = file_name_lookup(_SERVERS_BUS_PCI, 0, 0);
-    if (pci_server_port == MACH_PORT_NULL)
-        return errno;
+    if (!pci_server_port) {
+        /* Fall back to x86 access method */
+        return pci_system_x86_create();
+    }
 
     /* The server gives us the number of available devices for us */
     err = pci_get_ndevs (pci_server_port, &ndevs);
     if (err) {
         mach_port_deallocate (mach_task_self (), pci_server_port);
-        return err;
+        /* Fall back to x86 access method */
+        return pci_system_x86_create();
     }
     mach_port_deallocate (mach_task_self (), pci_server_port);
 
@@ -484,7 +487,7 @@ pci_system_hurd_create(void)
     err = enum_devices(_SERVERS_BUS_PCI, &device, -1, -1, -1, -1,
                        LEVEL_DOMAIN);
     if (err)
-        return err;
+        return pci_system_x86_create();
 
     return 0;
 }
-- 
2.17.1

Reply via email to