Library: Handle domains in all back-ends

Even if the back-end does not implement multiple domains, it can
be called on a device in a non-zero domain if the use obtained the
device by calling pci_get_dev() instead of scanning the bus.

In all such cases, report that 0 bytes were read/written.
diff --git a/TODO b/TODO
index 2ff52e2..d9efa20 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,3 @@
-- all back-ends: fail on non-zero domain
-
 - review class names
 
 Setpci:
diff --git a/lib/aix-device.c b/lib/aix-device.c
index a10bea5..f7d8e78 100644
--- a/lib/aix-device.c
+++ b/lib/aix-device.c
@@ -60,9 +60,10 @@
 }
 
 static int
-aix_bus_open(struct pci_access *a, int bus_number)
+aix_bus_open(struct pci_dev *d)
 {
-  aix_pci_bus *bp = aix_find_bus(a, bus_number);
+  struct pci_access *a = d->access;
+  aix_pci_bus *bp = aix_find_bus(a, d->bus);
 
   if (bp->bus_fd < 0)
     {
@@ -72,9 +73,7 @@
       snprintf(devbuf, sizeof (devbuf), "/dev/%s", bp->bus_name);
       bp->bus_fd = open(devbuf, mode, 0);
       if (bp->bus_fd < 0)
-        {
-          a->error("aix_open_bus: %s open failed", devbuf);
-        }
+	a->error("aix_open_bus: %s open failed", devbuf);
     }
 
   return bp->bus_fd;
@@ -218,10 +217,10 @@
   struct mdio mdio;
   int fd;
 
-  if (pos + len > 256)
+  if (d->domain || pos + len > 256)
     return 0;
 
-  fd = aix_bus_open(d->access, d->bus);
+  fd = aix_bus_open(d);
   mdio.md_addr = (ulong) pos;
   mdio.md_size = len;
   mdio.md_incr = MV_BYTE;
@@ -240,10 +239,10 @@
   struct mdio mdio;
   int fd;
 
-  if (pos + len > 256)
+  if (d->domain || pos + len > 256)
     return 0;
 
-  fd = aix_bus_open(d->access, d->bus);
+  fd = aix_bus_open(d);
   mdio.md_addr = (ulong) pos;
   mdio.md_size = len;
   mdio.md_incr = MV_BYTE;
diff --git a/lib/fbsd-device.c b/lib/fbsd-device.c
index 6bb5fdd..cffab69 100644
--- a/lib/fbsd-device.c
+++ b/lib/fbsd-device.c
@@ -266,6 +266,9 @@
 
 #if __FreeBSD_version >= 700053 || defined(__DragonFly__)
   pi.pi_sel.pc_domain = d->domain;
+#else
+  if (d->domain)
+    return 0;
 #endif
   pi.pi_sel.pc_bus = d->bus;
   pi.pi_sel.pc_dev = d->dev;
@@ -315,6 +318,9 @@
 
 #if __FreeBSD_version >= 700053 || defined(__DragonFly__)
   pi.pi_sel.pc_domain = d->domain;
+#else
+  if (d->domain)
+    return 0;
 #endif
   pi.pi_sel.pc_bus = d->bus;
   pi.pi_sel.pc_dev = d->dev;
diff --git a/lib/i386-ports.c b/lib/i386-ports.c
index 0b1677a..b3b752c 100644
--- a/lib/i386-ports.c
+++ b/lib/i386-ports.c
@@ -129,7 +129,7 @@
   int addr = 0xcfc + (pos&3);
   int res = 1;
 
-  if (pos >= 256)
+  if (d->domain || pos >= 256)
     return 0;
 
   intel_io_lock();
@@ -160,7 +160,7 @@
   int addr = 0xcfc + (pos&3);
   int res = 1;
 
-  if (pos >= 256)
+  if (d->domain || pos >= 256)
     return 0;
 
   intel_io_lock();
@@ -217,7 +217,7 @@
   int res = 1;
   int addr = 0xc000 | (d->dev << 8) | pos;
 
-  if (pos >= 256)
+  if (d->domain || pos >= 256)
     return 0;
 
   if (d->dev >= 16)
@@ -252,11 +252,12 @@
   int res = 1;
   int addr = 0xc000 | (d->dev << 8) | pos;
 
-  if (pos >= 256)
+  if (d->domain || pos >= 256)
     return 0;
 
   if (d->dev >= 16)
-    d->access->error("conf2_write: only first 16 devices exist.");
+    /* conf2 supports only 16 devices per bus */
+    return 0;
 
   intel_io_lock();
   outb((d->func << 1) | 0xf0, 0xcf8);
diff --git a/lib/nbsd-libpci.c b/lib/nbsd-libpci.c
index f57d133..2b2ca41 100644
--- a/lib/nbsd-libpci.c
+++ b/lib/nbsd-libpci.c
@@ -71,7 +71,7 @@
   if (!(len == 1 || len == 2 || len == 4))
     return pci_generic_block_read(d, pos, buf, len);
 
-  if (pos >= 4096)
+  if (d->domain || pos >= 4096)
     return 0;
 
   shift = 8*(pos % 4);
@@ -104,7 +104,7 @@
   if (!(len == 1 || len == 2 || len == 4))
     return pci_generic_block_write(d, pos, buf, len);
 
-  if (pos >= 256)
+  if (d->domain || pos >= 256)
     return 0;
 
   /*
diff --git a/lib/obsd-device.c b/lib/obsd-device.c
index dc68422..71cde5e 100644
--- a/lib/obsd-device.c
+++ b/lib/obsd-device.c
@@ -65,7 +65,7 @@
   if (!(len == 1 || len == 2 || len == 4))
     return pci_generic_block_read(d, pos, buf, len);
 
-  if (pos >= 256)
+  if (d->domain || pos >= 256)
     return 0;
 
   pi.pi_sel.pc_bus = d->bus;
@@ -106,7 +106,7 @@
   if (!(len == 1 || len == 2 || len == 4))
     return pci_generic_block_write(d, pos, buf, len);
 
-  if (pos >= 256)
+  if (d->domain || pos >= 256)
     return 0;
 
   pi.pi_sel.pc_bus = d->bus;