aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>2020-05-25 15:28:33 +0200
committerMartin Mares <mj@ucw.cz>2020-05-25 15:28:33 +0200
commit1ae94881c9f30d274fe55f4c3677510da5d789fd (patch)
tree252b1ef3a46ed36822f4411a1a3157b1716a9906
parent82c06b47dea5a38075ce9d56f743360bc47b4c78 (diff)
downloadpciutils-1ae94881c9f30d274fe55f4c3677510da5d789fd.tar.gz
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.
-rw-r--r--TODO2
-rw-r--r--lib/aix-device.c17
-rw-r--r--lib/fbsd-device.c6
-rw-r--r--lib/i386-ports.c11
-rw-r--r--lib/nbsd-libpci.c4
-rw-r--r--lib/obsd-device.c4
6 files changed, 24 insertions, 20 deletions
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 @@ 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;
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 @@ 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;
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 @@ 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);
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 @@ 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;
/*
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 @@ 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;