]> mj.ucw.cz Git - pciutils.git/commitdiff
Library: Handle domains in all back-ends
authorMartin Mares <mj@ucw.cz>
Mon, 25 May 2020 13:28:33 +0000 (15:28 +0200)
committerMartin Mares <mj@ucw.cz>
Mon, 25 May 2020 13:28:33 +0000 (15:28 +0200)
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.

TODO
lib/aix-device.c
lib/fbsd-device.c
lib/i386-ports.c
lib/nbsd-libpci.c
lib/obsd-device.c

diff --git a/TODO b/TODO
index 2ff52e24652172d82188c0da90973d4cf470113f..d9efa203982bfb6cb03a7e997e37004127ec6852 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,5 +1,3 @@
-- all back-ends: fail on non-zero domain
-
 - review class names
 
 Setpci:
index a10bea5333220ae5f18d6919f8b86be64b4aaca1..f7d8e782b92dbe53e40d9f2d3213ef9ae6ab4eb1 100644 (file)
@@ -60,9 +60,10 @@ aix_find_bus(struct pci_access *a, int bus_number)
 }
 
 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 @@ aix_bus_open(struct pci_access *a, int bus_number)
       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 @@ aix_read(struct pci_dev *d, int pos, byte *buf, int len)
   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 @@ aix_write(struct pci_dev *d, int pos, byte *buf, int len)
   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;
index 6bb5fddedf2c6f4a9cb7f0b76ec4903668ed5315..cffab69ead982f41343162e3849d9e4d3617acaa 100644 (file)
@@ -266,6 +266,9 @@ fbsd_read(struct pci_dev *d, int pos, byte *buf, int len)
 
 #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 @@ fbsd_write(struct pci_dev *d, int pos, byte *buf, int len)
 
 #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;
index 0b1677a236c7320139f1dafb2f3f2959a0bace47..b3b752cb1f3f7181295100dc64e17bef99344b2b 100644 (file)
@@ -129,7 +129,7 @@ conf1_read(struct pci_dev *d, int pos, byte *buf, int len)
   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 @@ conf1_write(struct pci_dev *d, int pos, byte *buf, int len)
   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 @@ conf2_read(struct pci_dev *d, int pos, byte *buf, int len)
   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 @@ conf2_write(struct pci_dev *d, int pos, byte *buf, int len)
   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);
index f57d133d932b3c360fb3f4684e56e9b3a37ef7b5..2b2ca4166d2a762ef9b5648d1fd112ce34cd1505 100644 (file)
@@ -71,7 +71,7 @@ nbsd_read(struct pci_dev *d, int pos, byte *buf, int len)
   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 @@ nbsd_write(struct pci_dev *d, int pos, byte *buf, int len)
   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;
 
   /*
index dc68422abf1ef02385c0b25145509ee6a1feeed3..71cde5eb32c48bcb2fdec7c439c5409fd36c1b36 100644 (file)
@@ -65,7 +65,7 @@ obsd_read(struct pci_dev *d, int pos, byte *buf, int len)
   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 @@ obsd_write(struct pci_dev *d, int pos, byte *buf, int len)
   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;