Skip to contentSkip to conversation

pci/lspci: Identify Enhanced Allocation (EA) Resources

PATCH Applied Sean O. Stalley 3 participants 7 messages Feb 12, 2016 – May 16, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover pci/lspci: Identify Enhanced Allocation (EA) Resources

Identify BAR-equivalent resources that are described by EA entries with the IORESOURCE_PCI_EA_BEI flag.

lspci cannot distinguish between resources from VF BARs and resources from EA. This results in EA Resources being incorrectly identified as [virtual]. Adding this flag allows EA resources to be marked more accurately as [enhanced].

Although this patchset only add support for this flag to lspci, there are other use cases (such as vfio) where knowing a resource comes from EA would be useful.

[PATCH 1/2] is for the kernel, [PATCH 2/2] is for lspci.

Changes from V1:
-Rewrote commit message for linux changes

Changes from V2:
- Rewrote commit message for linux, fixing spelling :)
- Added warning about resource flags being exposed in sysfs

Changes from V3 (only lspci changes):
- Incremented libpci API version number
- append new flag variables to the end of struct pci_dev (so we don't break binary compatiblity)
- expanded comment for the resource flags
- removed brackets around 1 line conditionals

Alex Williamson (1):
pci: Identify Enhanced Allocation (EA) BAR Equivalent resources

Sean O. Stalley (1):
Add support for enhanced allocation regions

linux changes:

 drivers/pci/pci.c      | 2 +-
 include/linux/ioport.h | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

lspci changes:

 lib/access.c   | 18 ++++++++++--------
 lib/caps.c     |  2 +-
 lib/filter.c   |  2 +-
 lib/header.h   |  4 ++++
 lib/libpci.ver |  5 +++++
 lib/pci.h      |  3 +++
 lib/sysfs.c    |  7 +++++--
 lspci.c        | 12 +++++++++---
 8 files changed, 38 insertions(+), 15 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v4 1/2 pci: Identify Enhanced Allocation (EA) BAR Equivalent resources

From: Alex Williamson <[email protected]>

Resource flags are exposed to userspace via the sysfs "resource" file. lspci reads the sysfs file to determine resource properties. Adding this flag allows lspci to distinguish between [virtual] and [enhanced] resources.

If the resource is not aligned, userspace could deduce where the resource is EA based on the size & address fields. However, a flag indicating whether a PCI resource is a traditional BAR or BAR equivalent seems like a much simpler solution and works if the EA resource is aligned.

Although this patchset only improves lspci, other uses for this flag have been identified. For example, vfio makes assumptions about alignment and sizing, and runs into problems when attempting to emulate a BAR Equivalent EA resource.

---
 drivers/pci/pci.c      | 2 +-
 include/linux/ioport.h | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/pci/pci.c +1 -1
index d1a7105..8ff678c 100644
@@ -2229,7 +2229,7 @@ void pci_pm_init(struct pci_dev *dev)
 
 static unsigned long pci_ea_flags(struct pci_dev *dev, u8 prop)
 {
-	unsigned long flags = IORESOURCE_PCI_FIXED;
+	unsigned long flags = IORESOURCE_PCI_FIXED | IORESOURCE_PCI_EA_BEI;
 
 	switch (prop) {
 	case PCI_EA_P_MEM:
include/linux/ioport.h +7 -0
index 24bea08..88816f9 100644
@@ -25,7 +25,11 @@ struct resource {
 
 /*
  * IO resources have these defined flags.
+ *
+ * PCI devices expose these flags to userspace in the "resource" sysfs file,
+ * Moving them around could break stuff, so don't do it.
  */
+
 #define IORESOURCE_BITS		0x000000ff	/* Bus-specific bits */
 
 #define IORESOURCE_TYPE_BITS	0x00001f00	/* Resource type */
@@ -97,6 +101,7 @@ struct resource {
 #define IORESOURCE_IO_SPARSE		(1<<2)
 
 /* PCI ROM control bits (IORESOURCE_BITS) */
+
 #define IORESOURCE_ROM_ENABLE		(1<<0)	/* ROM is enabled, same as PCI_ROM_ADDRESS_ENABLE */
 #define IORESOURCE_ROM_SHADOW		(1<<1)	/* ROM is copy at C000:0 */
 #define IORESOURCE_ROM_COPY		(1<<2)	/* ROM is alloc'd copy, resource field overlaid */
@@ -105,6 +110,8 @@ struct resource {
 /* PCI control bits.  Shares IORESOURCE_BITS with above PCI ROM.  */
 #define IORESOURCE_PCI_FIXED		(1<<4)	/* Do not move resource */
 
+/* PCI Enhanced Allocation defined BAR equivalent resource */
+#define IORESOURCE_PCI_EA_BEI		(1<<5)
 
 /* helpers to define resources */
 #define DEFINE_RES_NAMED(_start, _size, _name, _flags)			\
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v4 1/2] pci: Identify Enhanced Allocation (EA) BAR Equivalent resources

Quoted 13 lines · Sean O. Stalley

From: Alex Williamson <[email protected]>

Resource flags are exposed to userspace via the sysfs "resource" file. lspci reads the sysfs file to determine resource properties. Adding this flag allows lspci to distinguish between [virtual] and [enhanced] resources.

If the resource is not aligned, userspace could deduce where the resource is EA based on the size & address fields. However, a flag indicating whether a PCI resource is a traditional BAR or BAR equivalent seems like a much simpler solution and works if the EA resource is aligned.

Quoted 7 lines

Although this patchset only improves lspci, other uses for this flag have been identified. For example, vfio makes assumptions about alignment and sizing, and runs into problems when attempting to emulate a BAR Equivalent EA resource.

I applied this to pci/resource and intend to merge it for v4.7.

Quoted 58 lines
---
 drivers/pci/pci.c      | 2 +-
 include/linux/ioport.h | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/pci/pci.c +1 -1
index d1a7105..8ff678c 100644
@@ -2229,7 +2229,7 @@ void pci_pm_init(struct pci_dev *dev)
 
 static unsigned long pci_ea_flags(struct pci_dev *dev, u8 prop)
 {
-	unsigned long flags = IORESOURCE_PCI_FIXED;
+	unsigned long flags = IORESOURCE_PCI_FIXED | IORESOURCE_PCI_EA_BEI;
 
 	switch (prop) {
 	case PCI_EA_P_MEM:
include/linux/ioport.h +7 -0
index 24bea08..88816f9 100644
@@ -25,7 +25,11 @@ struct resource {
 
 /*
  * IO resources have these defined flags.
+ *
+ * PCI devices expose these flags to userspace in the "resource" sysfs file,
+ * Moving them around could break stuff, so don't do it.
  */
+
 #define IORESOURCE_BITS		0x000000ff	/* Bus-specific bits */
 
 #define IORESOURCE_TYPE_BITS	0x00001f00	/* Resource type */
@@ -97,6 +101,7 @@ struct resource {
 #define IORESOURCE_IO_SPARSE		(1<<2)
 
 /* PCI ROM control bits (IORESOURCE_BITS) */
+
 #define IORESOURCE_ROM_ENABLE		(1<<0)	/* ROM is enabled, same as PCI_ROM_ADDRESS_ENABLE */
 #define IORESOURCE_ROM_SHADOW		(1<<1)	/* ROM is copy at C000:0 */
 #define IORESOURCE_ROM_COPY		(1<<2)	/* ROM is alloc'd copy, resource field overlaid */
@@ -105,6 +110,8 @@ struct resource {
 /* PCI control bits.  Shares IORESOURCE_BITS with above PCI ROM.  */
 #define IORESOURCE_PCI_FIXED		(1<<4)	/* Do not move resource */
 
+/* PCI Enhanced Allocation defined BAR equivalent resource */
+#define IORESOURCE_PCI_EA_BEI		(1<<5)
 
 /* helpers to define resources */
 #define DEFINE_RES_NAMED(_start, _size, _name, _flags)			\
Signature · 6 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

RE: [PATCH v4 1/2] pci: Identify Enhanced Allocation (EA) BAR Equivalent resources

Thanks Bjorn & Martin!

-Sean

Quoted 97 lines

-----Original Message-----
From: Bjorn Helgaas [mailto:[email protected]]
Sent: Monday, May 16, 2016 1:32 PM
To: Stalley, Sean <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 1/2] pci: Identify Enhanced Allocation (EA) BAR Equivalent resources
=20

Quoted 13 lines · Sean O. Stalley

From: Alex Williamson <[email protected]>

Resource flags are exposed to userspace via the sysfs "resource" file. lspci reads the sysfs file to determine resource properties. Adding this flag allows lspci to distinguish between [virtual] and [enhanced] resources.

If the resource is not aligned, userspace could deduce where the resource is EA based on the size & address fields.
However, a flag indicating whether a PCI resource is a traditional BAR or BAR equivalent seems like a much simpler solution and works if the EA resource is aligned.

Quoted 7 lines

Although this patchset only improves lspci, other uses for this flag have been identified. For example, vfio makes assumptions about alignment and sizing, and runs into problems when attempting to emulate a BAR Equivalent EA resource.

=20
I applied this to pci/resource and intend to merge it for v4.7. =20

Quoted 10 lines
---
 drivers/pci/pci.c      | 2 +-
 include/linux/ioport.h | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/pci/pci.c index renamed from drivers/pci/pci.c +0 -0

d1a7105..8ff678c 100644

drivers/pci/pci.c void pci_pm_init(struct pci_dev *dev) · line 2231

Quoted 4 lines
drivers/pci/pci.c +1 -1
@@ -2229,7 +2229,7 @@ void pci_pm_init(struct pci_dev *dev)
 
 static unsigned long pci_ea_flags(struct pci_dev *dev, u8 prop)  {
-	unsigned long flags =3D IORESOURCE_PCI_FIXED;
+	unsigned long flags =3D IORESOURCE_PCI_FIXED |

IORESOURCE_PCI_EA_BEI;

Quoted 21 lines
drivers/pci/pci.c +0 -0
 	switch (prop) {
 	case PCI_EA_P_MEM:
include/linux/ioport.h index renamed from include/linux/ioport.h +0 -0

24bea08..88816f9 100644

include/linux/ioport.h +5 -0
@@ -25,7 +25,11 @@ struct resource {
 
 /*
  * IO resources have these defined flags.
+ *
+ * PCI devices expose these flags to userspace in the "resource"
+ sysfs file,
+ * Moving them around could break stuff, so don't do it.
  */
+
 #define IORESOURCE_BITS		0x000000ff	/* Bus-specific bits */
 
 #define IORESOURCE_TYPE_BITS	0x00001f00	/* Resource type */

include/linux/ioport.h struct resource { · line 105

Quoted 5 lines
include/linux/ioport.h +1 -0
@@ -97,6 +101,7 @@ struct resource {
 #define IORESOURCE_IO_SPARSE		(1<<2)
 
 /* PCI ROM control bits (IORESOURCE_BITS) */
+
 #define IORESOURCE_ROM_ENABLE		(1<<0)	/* ROM is enabled,

same as PCI_ROM_ADDRESS_ENABLE */

include/linux/ioport.h struct resource { · line 106

Quoted 1 line
include/linux/ioport.h +0 -0
 #define IORESOURCE_ROM_SHADOW		(1<<1)	/* ROM is copy at

C000:0 */

include/linux/ioport.h struct resource { · line 107

Quoted 1 line
include/linux/ioport.h +0 -0
 #define IORESOURCE_ROM_COPY		(1<<2)	/* ROM is alloc'd copy,

resource field overlaid */

include/linux/ioport.h struct resource { · line 111

Quoted 3 lines
include/linux/ioport.h +0 -0
@@ -105,6 +110,8 @@ struct resource {
 /* PCI control bits.  Shares IORESOURCE_BITS with above PCI ROM.  */
 #define IORESOURCE_PCI_FIXED		(1<<4)	/* Do not move

resource */

include/linux/ioport.h struct resource {

Quoted 6 lines
include/linux/ioport.h +2 -0
+/* PCI Enhanced Allocation defined BAR equivalent resource */
+#define IORESOURCE_PCI_EA_BEI		(1<<5)
 
 /* helpers to define resources */
 #define DEFINE_RES_NAMED(_start, _size, _name, _flags)
	\
Quoted 7 lines
include/linux/ioport.h +0 -1
--

1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

PATCH v4 2/2 Add support for enhanced allocation regions

In reply to Sean O. Stalley

Append [enhanced] to Regions that contain the BEI flag in sysfs.
To do this, we need to add the resource flags to the pci_dev struct. This struct is passed through the libpci API, so we increment the API version number.

Don't tuncate least significant bits of the region size.
ex: a 2000 byte region should display [size=2000] instead of [size=1K]

---
 lib/access.c   | 18 ++++++++++--------
 lib/caps.c     |  2 +-
 lib/filter.c   |  2 +-
 lib/header.h   |  4 ++++
 lib/libpci.ver |  5 +++++
 lib/pci.h      |  3 +++
 lib/sysfs.c    |  7 +++++--
 lspci.c        | 12 +++++++++---
 8 files changed, 38 insertions(+), 15 deletions(-)
lib/access.c +10 -8
index 5994008..17b8bed 100644
@@ -155,7 +155,7 @@ pci_write_block(struct pci_dev *d, int pos, byte *buf, int len)
 }
 
 int
-pci_fill_info_v34(struct pci_dev *d, int flags)
+pci_fill_info_v35(struct pci_dev *d, int flags)
 {
   if (flags & PCI_FILL_RESCAN)
     {
@@ -169,17 +169,19 @@ pci_fill_info_v34(struct pci_dev *d, int flags)
 }
 
 /* In version 3.1, pci_fill_info got new flags => versioned alias */
-/* In versions 3.2, 3.3 and 3.4, the same has happened */
-STATIC_ALIAS(int pci_fill_info(struct pci_dev *d, int flags), pci_fill_info_v34(d, flags));
-DEFINE_ALIAS(int pci_fill_info_v30(struct pci_dev *d, int flags), pci_fill_info_v34);
-DEFINE_ALIAS(int pci_fill_info_v31(struct pci_dev *d, int flags), pci_fill_info_v34);
-DEFINE_ALIAS(int pci_fill_info_v32(struct pci_dev *d, int flags), pci_fill_info_v34);
-DEFINE_ALIAS(int pci_fill_info_v33(struct pci_dev *d, int flags), pci_fill_info_v34);
+/* In versions 3.2, 3.3, 3.4 and 3.5, the same has happened */
+STATIC_ALIAS(int pci_fill_info(struct pci_dev *d, int flags), pci_fill_info_v35(d, flags));
+DEFINE_ALIAS(int pci_fill_info_v30(struct pci_dev *d, int flags), pci_fill_info_v35);
+DEFINE_ALIAS(int pci_fill_info_v31(struct pci_dev *d, int flags), pci_fill_info_v35);
+DEFINE_ALIAS(int pci_fill_info_v32(struct pci_dev *d, int flags), pci_fill_info_v35);
+DEFINE_ALIAS(int pci_fill_info_v33(struct pci_dev *d, int flags), pci_fill_info_v35);
+DEFINE_ALIAS(int pci_fill_info_v34(struct pci_dev *d, int flags), pci_fill_info_v35);
 SYMBOL_VERSION(pci_fill_info_v30, pci_fill_info@LIBPCI_3.0);
 SYMBOL_VERSION(pci_fill_info_v31, pci_fill_info@LIBPCI_3.1);
 SYMBOL_VERSION(pci_fill_info_v32, pci_fill_info@LIBPCI_3.2);
 SYMBOL_VERSION(pci_fill_info_v33, pci_fill_info@LIBPCI_3.3);
-SYMBOL_VERSION(pci_fill_info_v34, pci_fill_info@@LIBPCI_3.4);
+SYMBOL_VERSION(pci_fill_info_v34, pci_fill_info@LIBPCI_3.4);
+SYMBOL_VERSION(pci_fill_info_v35, pci_fill_info@@LIBPCI_3.5);
 
 void
 pci_setup_cache(struct pci_dev *d, byte *cache, int len)
lib/caps.c +1 -1
index a812fb9..9a2e0a5 100644
@@ -106,7 +106,7 @@ pci_find_cap(struct pci_dev *d, unsigned int id, unsigned int type)
 {
   struct pci_cap *c;
 
-  pci_fill_info_v34(d, ((type == PCI_CAP_NORMAL) ? PCI_FILL_CAPS : PCI_FILL_EXT_CAPS));
+  pci_fill_info_v35(d, ((type == PCI_CAP_NORMAL) ? PCI_FILL_CAPS : PCI_FILL_EXT_CAPS));
   for (c=d->first_cap; c; c=c->next)
     if (c->type == type && c->id == id)
       return c;
lib/filter.c +1 -1
index d4254a0..ab1476f 100644
@@ -129,7 +129,7 @@ pci_filter_match_v33(struct pci_filter *f, struct pci_dev *d)
     return 0;
   if (f->device >= 0 || f->vendor >= 0)
     {
-      pci_fill_info_v34(d, PCI_FILL_IDENT);
+      pci_fill_info_v35(d, PCI_FILL_IDENT);
       if ((f->device >= 0 && f->device != d->device_id) ||
 	  (f->vendor >= 0 && f->vendor != d->vendor_id))
 	return 0;
lib/header.h +4 -0
index b8f7dc1..7b9a803 100644
@@ -1235,3 +1235,7 @@
 
 #define PCI_VENDOR_ID_INTEL		0x8086
 #define PCI_VENDOR_ID_COMPAQ		0x0e11
+
+/* taken from <include/linux/ioport.h> */
+
+#define IORESOURCE_PCI_EA_BEI          (1<<5)
lib/libpci.ver +5 -0
index 7ac8d34..83f3c50 100644
@@ -66,3 +66,8 @@ LIBPCI_3.4 {
 	global:
 		pci_fill_info;
 };
+
+LIBPCI_3.5 {
+	global:
+		pci_fill_info;
+};
lib/pci.h +3 -0
index 9c1e281..a86bfd7 100644
@@ -136,6 +136,8 @@ struct pci_dev {
   char *module_alias;			/* Linux kernel module alias */
   char *label;				/* Device name as exported by BIOS */
   int numa_node;			/* NUMA node */
+  pciaddr_t flags[6];			/* Region IORESOURCE flags */
+  pciaddr_t rom_flags;			/* Expansion ROM IORESOURCE flags */
 
   /* Fields used internally: */
   struct pci_access *access;
@@ -174,6 +176,7 @@ int pci_fill_info(struct pci_dev *, int flags) PCI_ABI; /* Fill in device inform
 #define PCI_FILL_MODULE_ALIAS	0x0200
 #define PCI_FILL_LABEL		0x0400
 #define PCI_FILL_NUMA_NODE	0x0800
+#define PCI_FILL_IO_FLAGS	0x1000
 #define PCI_FILL_RESCAN		0x00010000
 
 void pci_setup_cache(struct pci_dev *, u8 *cache, int len) PCI_ABI;
lib/sysfs.c +5 -2
index 986ecc9..65f58bf 100644
@@ -153,14 +153,17 @@ sysfs_get_resources(struct pci_dev *d)
 	size = end - start + 1;
       else
 	size = 0;
-      flags &= PCI_ADDR_FLAG_MASK;
       if (i < 6)
 	{
+	  d->flags[i] = flags;
+	  flags &= PCI_ADDR_FLAG_MASK;
 	  d->base_addr[i] = start | flags;
 	  d->size[i] = size;
 	}
       else
 	{
+	  d->rom_flags = flags;
+	  flags &= PCI_ADDR_FLAG_MASK;
 	  d->rom_base_addr = start | flags;
 	  d->rom_size = size;
 	}
@@ -208,7 +211,7 @@ static void sysfs_scan(struct pci_access *a)
 	  d->vendor_id = sysfs_get_value(d, "vendor", 1);
 	  d->device_id = sysfs_get_value(d, "device", 1);
 	  d->device_class = sysfs_get_value(d, "class", 1) >> 8;
-	  d->known_fields = PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES;
+	  d->known_fields = PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES | PCI_FILL_IO_FLAGS;
 	}
       pci_link_dev(a, d);
     }
lspci.c +9 -3
index fe7b7fe..52d14f3 100644
@@ -336,7 +336,7 @@ show_size(pciaddr_t x)
   if (!x)
     return;
   for (i = 0; i < (sizeof(suffix) / sizeof(*suffix) - 1); i++) {
-    if (x < 1024)
+    if (x % 1024)
       break;
     x /= 1024;
   }
@@ -355,6 +355,7 @@ show_bases(struct device *d, int cnt)
     {
       pciaddr_t pos = p->base_addr[i];
       pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0;
+      pciaddr_t ioflg = (p->known_fields & PCI_FILL_IO_FLAGS) ? p->flags[i] : 0;
       u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
       if (flg == 0xffffffff)
 	flg = 0;
@@ -364,7 +365,9 @@ show_bases(struct device *d, int cnt)
 	printf("\tRegion %d: ", i);
       else
 	putchar('\t');
-      if (pos && !flg)			/* Reported by the OS, but not by the device */
+      if (ioflg & IORESOURCE_PCI_EA_BEI)
+	  printf("[enhanced] ");
+      else if (pos && !flg)	/* Reported by the OS, but not by the device */
 	{
 	  printf("[virtual] ");
 	  flg = pos;
@@ -430,6 +433,7 @@ show_rom(struct device *d, int reg)
   struct pci_dev *p = d->dev;
   pciaddr_t rom = p->rom_base_addr;
   pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
+  pciaddr_t ioflg = (p->known_fields & PCI_FILL_IO_FLAGS) ? p->rom_flags : 0;
   u32 flg = get_conf_long(d, reg);
   word cmd = get_conf_word(d, PCI_COMMAND);
   int virtual = 0;
@@ -437,7 +441,9 @@ show_rom(struct device *d, int reg)
   if (!rom && !flg && !len)
     return;
   putchar('\t');
-  if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
+  if (ioflg & IORESOURCE_PCI_EA_BEI)
+      printf("[enhanced] ");
+  else if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
     {
       printf("[virtual] ");
       flg = rom;
Signature · 1 line
1.9.1
#5 lore raw

Re: [PATCH v4 2/2] Add support for enhanced allocation regions

Hi Martin,

Quoted 5 lines · Sean O. Stalley

Append [enhanced] to Regions that contain the BEI flag in sysfs.
To do this, we need to add the resource flags to the pci_dev struct. This struct is passed through the libpci API, so we increment the API version number.

Don't tuncate least significant bits of the region size.

s/tuncate/truncate/

Quoted 1 line

ex: a 2000 byte region should display [size=2000] instead of [size=1K]

What do you think of this? I don't object to the kernel PCI part of it, but I don't want to apply it unless you plan to make lspci make use of it.

Bjorn

Quoted 214 lines
---
 lib/access.c   | 18 ++++++++++--------
 lib/caps.c     |  2 +-
 lib/filter.c   |  2 +-
 lib/header.h   |  4 ++++
 lib/libpci.ver |  5 +++++
 lib/pci.h      |  3 +++
 lib/sysfs.c    |  7 +++++--
 lspci.c        | 12 +++++++++---
 8 files changed, 38 insertions(+), 15 deletions(-)
lib/access.c +10 -8
index 5994008..17b8bed 100644
@@ -155,7 +155,7 @@ pci_write_block(struct pci_dev *d, int pos, byte *buf, int len)
 }
 
 int
-pci_fill_info_v34(struct pci_dev *d, int flags)
+pci_fill_info_v35(struct pci_dev *d, int flags)
 {
   if (flags & PCI_FILL_RESCAN)
     {
@@ -169,17 +169,19 @@ pci_fill_info_v34(struct pci_dev *d, int flags)
 }
 
 /* In version 3.1, pci_fill_info got new flags => versioned alias */
-/* In versions 3.2, 3.3 and 3.4, the same has happened */
-STATIC_ALIAS(int pci_fill_info(struct pci_dev *d, int flags), pci_fill_info_v34(d, flags));
-DEFINE_ALIAS(int pci_fill_info_v30(struct pci_dev *d, int flags), pci_fill_info_v34);
-DEFINE_ALIAS(int pci_fill_info_v31(struct pci_dev *d, int flags), pci_fill_info_v34);
-DEFINE_ALIAS(int pci_fill_info_v32(struct pci_dev *d, int flags), pci_fill_info_v34);
-DEFINE_ALIAS(int pci_fill_info_v33(struct pci_dev *d, int flags), pci_fill_info_v34);
+/* In versions 3.2, 3.3, 3.4 and 3.5, the same has happened */
+STATIC_ALIAS(int pci_fill_info(struct pci_dev *d, int flags), pci_fill_info_v35(d, flags));
+DEFINE_ALIAS(int pci_fill_info_v30(struct pci_dev *d, int flags), pci_fill_info_v35);
+DEFINE_ALIAS(int pci_fill_info_v31(struct pci_dev *d, int flags), pci_fill_info_v35);
+DEFINE_ALIAS(int pci_fill_info_v32(struct pci_dev *d, int flags), pci_fill_info_v35);
+DEFINE_ALIAS(int pci_fill_info_v33(struct pci_dev *d, int flags), pci_fill_info_v35);
+DEFINE_ALIAS(int pci_fill_info_v34(struct pci_dev *d, int flags), pci_fill_info_v35);
 SYMBOL_VERSION(pci_fill_info_v30, pci_fill_info@LIBPCI_3.0);
 SYMBOL_VERSION(pci_fill_info_v31, pci_fill_info@LIBPCI_3.1);
 SYMBOL_VERSION(pci_fill_info_v32, pci_fill_info@LIBPCI_3.2);
 SYMBOL_VERSION(pci_fill_info_v33, pci_fill_info@LIBPCI_3.3);
-SYMBOL_VERSION(pci_fill_info_v34, pci_fill_info@@LIBPCI_3.4);
+SYMBOL_VERSION(pci_fill_info_v34, pci_fill_info@LIBPCI_3.4);
+SYMBOL_VERSION(pci_fill_info_v35, pci_fill_info@@LIBPCI_3.5);
 
 void
 pci_setup_cache(struct pci_dev *d, byte *cache, int len)
lib/caps.c +1 -1
index a812fb9..9a2e0a5 100644
@@ -106,7 +106,7 @@ pci_find_cap(struct pci_dev *d, unsigned int id, unsigned int type)
 {
   struct pci_cap *c;
 
-  pci_fill_info_v34(d, ((type == PCI_CAP_NORMAL) ? PCI_FILL_CAPS : PCI_FILL_EXT_CAPS));
+  pci_fill_info_v35(d, ((type == PCI_CAP_NORMAL) ? PCI_FILL_CAPS : PCI_FILL_EXT_CAPS));
   for (c=d->first_cap; c; c=c->next)
     if (c->type == type && c->id == id)
       return c;
lib/filter.c +1 -1
index d4254a0..ab1476f 100644
@@ -129,7 +129,7 @@ pci_filter_match_v33(struct pci_filter *f, struct pci_dev *d)
     return 0;
   if (f->device >= 0 || f->vendor >= 0)
     {
-      pci_fill_info_v34(d, PCI_FILL_IDENT);
+      pci_fill_info_v35(d, PCI_FILL_IDENT);
       if ((f->device >= 0 && f->device != d->device_id) ||
 	  (f->vendor >= 0 && f->vendor != d->vendor_id))
 	return 0;
lib/header.h +4 -0
index b8f7dc1..7b9a803 100644
@@ -1235,3 +1235,7 @@
 
 #define PCI_VENDOR_ID_INTEL		0x8086
 #define PCI_VENDOR_ID_COMPAQ		0x0e11
+
+/* taken from <include/linux/ioport.h> */
+
+#define IORESOURCE_PCI_EA_BEI          (1<<5)
lib/libpci.ver +5 -0
index 7ac8d34..83f3c50 100644
@@ -66,3 +66,8 @@ LIBPCI_3.4 {
 	global:
 		pci_fill_info;
 };
+
+LIBPCI_3.5 {
+	global:
+		pci_fill_info;
+};
lib/pci.h +3 -0
index 9c1e281..a86bfd7 100644
@@ -136,6 +136,8 @@ struct pci_dev {
   char *module_alias;			/* Linux kernel module alias */
   char *label;				/* Device name as exported by BIOS */
   int numa_node;			/* NUMA node */
+  pciaddr_t flags[6];			/* Region IORESOURCE flags */
+  pciaddr_t rom_flags;			/* Expansion ROM IORESOURCE flags */
 
   /* Fields used internally: */
   struct pci_access *access;
@@ -174,6 +176,7 @@ int pci_fill_info(struct pci_dev *, int flags) PCI_ABI; /* Fill in device inform
 #define PCI_FILL_MODULE_ALIAS	0x0200
 #define PCI_FILL_LABEL		0x0400
 #define PCI_FILL_NUMA_NODE	0x0800
+#define PCI_FILL_IO_FLAGS	0x1000
 #define PCI_FILL_RESCAN		0x00010000
 
 void pci_setup_cache(struct pci_dev *, u8 *cache, int len) PCI_ABI;
lib/sysfs.c +5 -2
index 986ecc9..65f58bf 100644
@@ -153,14 +153,17 @@ sysfs_get_resources(struct pci_dev *d)
 	size = end - start + 1;
       else
 	size = 0;
-      flags &= PCI_ADDR_FLAG_MASK;
       if (i < 6)
 	{
+	  d->flags[i] = flags;
+	  flags &= PCI_ADDR_FLAG_MASK;
 	  d->base_addr[i] = start | flags;
 	  d->size[i] = size;
 	}
       else
 	{
+	  d->rom_flags = flags;
+	  flags &= PCI_ADDR_FLAG_MASK;
 	  d->rom_base_addr = start | flags;
 	  d->rom_size = size;
 	}
@@ -208,7 +211,7 @@ static void sysfs_scan(struct pci_access *a)
 	  d->vendor_id = sysfs_get_value(d, "vendor", 1);
 	  d->device_id = sysfs_get_value(d, "device", 1);
 	  d->device_class = sysfs_get_value(d, "class", 1) >> 8;
-	  d->known_fields = PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES;
+	  d->known_fields = PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES | PCI_FILL_IO_FLAGS;
 	}
       pci_link_dev(a, d);
     }
lspci.c +9 -3
index fe7b7fe..52d14f3 100644
@@ -336,7 +336,7 @@ show_size(pciaddr_t x)
   if (!x)
     return;
   for (i = 0; i < (sizeof(suffix) / sizeof(*suffix) - 1); i++) {
-    if (x < 1024)
+    if (x % 1024)
       break;
     x /= 1024;
   }
@@ -355,6 +355,7 @@ show_bases(struct device *d, int cnt)
     {
       pciaddr_t pos = p->base_addr[i];
       pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0;
+      pciaddr_t ioflg = (p->known_fields & PCI_FILL_IO_FLAGS) ? p->flags[i] : 0;
       u32 flg = get_conf_long(d, PCI_BASE_ADDRESS_0 + 4*i);
       if (flg == 0xffffffff)
 	flg = 0;
@@ -364,7 +365,9 @@ show_bases(struct device *d, int cnt)
 	printf("\tRegion %d: ", i);
       else
 	putchar('\t');
-      if (pos && !flg)			/* Reported by the OS, but not by the device */
+      if (ioflg & IORESOURCE_PCI_EA_BEI)
+	  printf("[enhanced] ");
+      else if (pos && !flg)	/* Reported by the OS, but not by the device */
 	{
 	  printf("[virtual] ");
 	  flg = pos;
@@ -430,6 +433,7 @@ show_rom(struct device *d, int reg)
   struct pci_dev *p = d->dev;
   pciaddr_t rom = p->rom_base_addr;
   pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->rom_size : 0;
+  pciaddr_t ioflg = (p->known_fields & PCI_FILL_IO_FLAGS) ? p->rom_flags : 0;
   u32 flg = get_conf_long(d, reg);
   word cmd = get_conf_word(d, PCI_COMMAND);
   int virtual = 0;
@@ -437,7 +441,9 @@ show_rom(struct device *d, int reg)
   if (!rom && !flg && !len)
     return;
   putchar('\t');
-  if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
+  if (ioflg & IORESOURCE_PCI_EA_BEI)
+      printf("[enhanced] ");
+  else if ((rom & PCI_ROM_ADDRESS_MASK) && !(flg & PCI_ROM_ADDRESS_MASK))
     {
       printf("[virtual] ");
       flg = rom;
Signature · 6 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw

Re: [PATCH v4 2/2] Add support for enhanced allocation regions

Hi Bjorn,

sorry for the delay, I was too busy with rebuilding my house :)

Quoted 5 lines
Quoted 1 line

ex: a 2000 byte region should display [size=2000] instead of [size=1K]

What do you think of this? I don't object to the kernel PCI part of it, but I don't want to apply it unless you plan to make lspci make use of it.

I like it. Applied to pciutils.git.

Have a nice fortnight

Signature · 3 lines
Martin `MJ' Mares                          <[email protected]>   http://mj.ucw.cz/
Faculty of Math and Physics, Charles University, Prague, Czech Rep., Earth
Nothing is smiple enough to be not screwed up.