From 4186391b43bf101fda08e92185359c94812e2c3d Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 14 May 2016 11:57:01 +0200 Subject: [PATCH] Domains: Legacy 16-bit domain numbers are maintained in generic code Previously, backward compatibility was kept only with the sysfs back-end. Also, domains which do not fit in 16 bits are replaced by 0xffff. --- lib/access.c | 12 ++++++++++++ lib/pci.h | 5 +++-- lib/sysfs.c | 10 +--------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/access.c b/lib/access.c index 17b8bed..d991129 100644 --- a/lib/access.c +++ b/lib/access.c @@ -40,6 +40,18 @@ pci_link_dev(struct pci_access *a, struct pci_dev *d) d->next = a->devices; a->devices = d; + /* + * Applications compiled with older versions of libpci do not expect + * 32-bit domain numbers. To keep them working, we keep a 16-bit + * version of the domain number at the previous location in struct + * pci_dev. This will keep backward compatibility on systems which + * don't require large domain numbers. + */ + if (d->domain > 0xffff) + d->domain_16 = 0xffff; + else + d->domain_16 = d->domain; + return 1; } diff --git a/lib/pci.h b/lib/pci.h index 47610f3..e3175a3 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -119,7 +119,8 @@ struct pci_param *pci_walk_params(struct pci_access *acc, struct pci_param *prev struct pci_dev { struct pci_dev *next; /* Next device in the chain */ - u16 domain_16; /* 16-bit PCI domain (host bridge) */ + u16 domain_16; /* 16-bit version of the PCI domain for backward compatibility */ + /* 0xffff if the real domain doesn't fit in 16 bits */ u8 bus, dev, func; /* Bus inside domain, device and function */ /* These fields are set by pci_fill_info() */ @@ -138,7 +139,7 @@ struct pci_dev { int numa_node; /* NUMA node */ pciaddr_t flags[6]; /* PCI_IORESOURCE_* flags for regions */ pciaddr_t rom_flags; /* PCI_IORESOURCE_* flags for expansion ROM */ - int domain; /* 32-bit PCI domain (host bridge) */ + int domain; /* PCI domain (host bridge) */ /* Fields used internally: */ struct pci_access *access; diff --git a/lib/sysfs.c b/lib/sysfs.c index 877310c..5779824 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -199,16 +199,8 @@ static void sysfs_scan(struct pci_access *a) /* Ensure kernel provided domain that fits in a signed integer */ if (dom > 0x7fffffff) - a->error("sysfs_scan: invalid domain:%x", dom); + a->error("sysfs_scan: Invalid domain %x", dom); - /* - * The domain value is truncated to 16 bits and stored in the pci_dev - * structure's legacy 16-bit domain offset for compatibility with - * applications compiled with libpci pre-32 bit domains. Such - * applications may not work as expected if they are on a machine - * utilizing PCI domain numbers requiring more than 16 bits. - */ - d->domain_16 = dom; d->domain = dom; d->bus = bus; d->dev = dev; -- 2.39.2