lspci: Show device name as exported by BIOS (sysfs label attribute)
Subsystems (2)
PATCH 1/1 lspci: Show device name as exported by BIOS (sysfs label attribute)
The Device name of a PCI or PCI Express device under OS may be exported via ACPI _DSM function with function index 7.
The kernel already exports this string through sysfs under a PCI device through the "label" sysfs attribute.
This patch reads the device name if available and shows it to the user. Real world examples:
Device Name: "USB HS EHCI Controller #2 #3"
Device Name: "USB HS EHCI Controller #1"
Device Name: "SATA Controller #1"
Device Name: "Onboard LAN #1"
Device Name: "Onboard LAN #2"
Device Name: "Onboard Video (PILOT-3)"
Compare with PCI Firmware Spec v3.1 chapter 4.6.7 and ACPI spec v5.0 chapter 9.14.1
The DeviceName is not shown by default, but starting from first verbose parameter (-v).
--- lib/pci.h | 1 + lib/sysfs.c | 4 ++++ lspci.c | 2 ++ 3 files changed, 7 insertions(+), 0 deletions(-)
lib/pci.h +1 -0
@@ -131,6 +131,7 @@ struct pci_dev {struct pci_cap *first_cap;/* List of capabilities */ char *phy_slot;/* Physical slot */ char *module_alias;/* Linux kernel module alias */ +char *label;/* Device name as exported by BIOS */ /* Fields used internally: */ struct pci_access *access;
lib/sysfs.c +4 -0
@@ -199,6 +199,10 @@ static void sysfs_scan(struct pci_access *a) d->vendor_id =sysfs_get_value (d,"vendor" ); d->device_id =sysfs_get_value (d,"device" ); d->device_class =sysfs_get_value (d,"class" ) >>8 ; +char buf[1024 ]; +if (sysfs_get_string (d,"label" , buf,0 )) + d->label =pci_strdup (d->access, buf); + d->known_fields =PCI_FILL_IDENT |PCI_FILL_CLASS |PCI_FILL_IRQ |PCI_FILL_BASES |PCI_FILL_ROM_BASE |PCI_FILL_SIZES ; }pci_link_dev (a, d);
lspci.c +2 -0
@@ -315,6 +315,8 @@ show_terse(struct device *d)word subsys_v, subsys_d;char ssnamebuf[256 ]; +if (p->label) +printf ("\tDeviceName: %s" , p->label);get_subid (d, &subsys_v, &subsys_d);if (subsys_v && subsys_v !=0xffff ) printf("\tSubsystem: %s\n",
Signature · 1 line
1.7.6.1
PATCH 1/1 lspci: Show device name as exported by BIOS (sysfs label attribute) (V2)
The Device name of a PCI or PCI Express device under OS may be exported via ACPI _DSM function with function index 7.
This allows to connect a described PCI device in the platform documentation or as labeled on the chassis with PCI devices shown via lspci.
The kernel already exports this string through sysfs under a PCI device through the "label" sysfs attribute.
This patch reads the device name if available and shows it to the user. Real world examples:
Device Name: "USB HS EHCI Controller #2 #3"
Device Name: "USB HS EHCI Controller #1"
Device Name: "SATA Controller #1"
Device Name: "Onboard LAN #1"
Device Name: "Onboard LAN #2"
Device Name: "Onboard Video (PILOT-3)"
Compare with PCI Firmware Spec v3.1 chapter 4.6.7 and ACPI spec v5.0 chapter 9.14.1
The DeviceName is not shown by default, but starting from first verbose parameter (-v).
V2: - Free label string if allocated
- Enhance changelog
--- lib/access.c | 1 + lib/pci.h | 1 + lib/sysfs.c | 4 ++++ lspci.c | 2 ++ 4 files changed, 8 insertions(+), 0 deletions(-)
lib/access.c +1 -0
@@ -60,6 +60,7 @@ void pci_free_dev(struct pci_dev *d) d->methods->cleanup_dev (d);pci_free_caps (d);pci_mfree (d->module_alias); +pci_mfree (d->label);pci_mfree (d->phy_slot);pci_mfree (d); }
lib/pci.h +1 -0
@@ -131,6 +131,7 @@ struct pci_dev {struct pci_cap *first_cap;/* List of capabilities */ char *phy_slot;/* Physical slot */ char *module_alias;/* Linux kernel module alias */ +char *label;/* Device name as exported by BIOS */ /* Fields used internally: */ struct pci_access *access;
lib/sysfs.c +4 -0
@@ -199,6 +199,10 @@ static void sysfs_scan(struct pci_access *a) d->vendor_id =sysfs_get_value (d,"vendor" ); d->device_id =sysfs_get_value (d,"device" ); d->device_class =sysfs_get_value (d,"class" ) >>8 ; +char buf[1024 ]; +if (sysfs_get_string (d,"label" , buf,0 )) + d->label =pci_strdup (d->access, buf); + d->known_fields =PCI_FILL_IDENT |PCI_FILL_CLASS |PCI_FILL_IRQ |PCI_FILL_BASES |PCI_FILL_ROM_BASE |PCI_FILL_SIZES ; }pci_link_dev (a, d);
lspci.c +2 -0
@@ -315,6 +315,8 @@ show_terse(struct device *d)word subsys_v, subsys_d;char ssnamebuf[256 ]; +if (p->label) +printf ("\tDeviceName: %s" , p->label);get_subid (d, &subsys_v, &subsys_d);if (subsys_v && subsys_v !=0xffff ) printf("\tSubsystem: %s\n",
Signature · 1 line
1.7.6.1
Martin Mares
AppliedRe: [PATCH] lspci: Show device name as exported by BIOS (sysfs label attribute) (V2)
Hi!
Quoted 6 lines
The Device name of a PCI or PCI Express device under OS may be exported via ACPI
_DSMfunction with function index 7.
This allows to connect a described PCI device in the platform documentation or as labeled on the chassis with PCI devices shown via lspci.
The kernel already exports this string through sysfs under a PCI device through the "label" sysfs attribute.
Thanks, applied. (With minor changes, like using OBJBUFSIZE instead of a hard-coded constant 1024.)
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 Got mole problems? Call Avogadro, 602-1023!
Re: [PATCH] lspci: Show device name as exported by BIOS (sysfs label attribute) (V2)
Quoted 2 lines
Thanks, applied. (With minor changes, like using OBJBUFSIZE instead of a hard-coded constant 1024.)
... I realized that your way of reading the label attribute was completely different from reading of most other device attributes.
I changed it, now it read only on request by pci_fill_info() with the PCI_FILL_LABEL flag.
Could you please check that the version in pciutils.git still works for you?
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 A jury consists of 12 persons chosen to decide who has the better lawyer.
Re: [PATCH] lspci: Show device name as exported by BIOS (sysfs label attribute) (V2)
Hi,
and sorry for the late reply.
Quoted 11 lines · Martin Mares
Quoted 2 lines
Thanks, applied. (With minor changes, like using OBJBUFSIZE instead of a hard-coded constant 1024.)
... I realized that your way of reading the label attribute was completely different from reading of most other device attributes.
I changed it, now it read only on request by
pci_fill_info()with thePCI_FILL_LABELflag.Could you please check that the version in pciutils.git still works for you?
I tried with latest 3.3.0 version and things work as expected:
lspci -v |grep DeviceName:
DeviceName: USB HS EHCI Controller #2 #3
DeviceName: USB HS EHCI Controller #1
DeviceName: SATA Controller #1
DeviceName: Onboard LAN #1
DeviceName: Onboard LAN #2
DeviceName: Onboard Video (PILOT-3)Thanks a lot!
Hm, while using the latest 3.3.0 tarball with our pciutils dist package I realized that this diff does not perfectly patch anymore.
Unfortunately without author, looks like a gcc guy added it. I paste it in the end
You may want to incorporate (a shortened version?) it if appropriate. Be careful, needs patch -p0
Thomas
Dear kernel developers. we plead to you, please use documented,optimized userspace interfaces, thanks !
sysdep.h renamed from sysdep.h.orig +4 -65
@@ -18,71 +18,10 @@typedef u8 byte ;typedef u16 word ; -#ifdef PCI_OS_WINDOWS -#define strcasecmp strcmpi -#endif - -#ifdef PCI_HAVE_LINUX_BYTEORDER_H - -#include <asm/byteorder.h> -#define cpu_to_le16 __cpu_to_le16 -#define cpu_to_le32 __cpu_to_le32 -#define le16_to_cpu __le16_to_cpu -#define le32_to_cpu __le32_to_cpu - -#else - -#ifdef PCI_OS_LINUX #include <endian.h> -#define BYTE_ORDER __BYTE_ORDER -#define BIG_ENDIAN __BIG_ENDIAN -#endif - -#ifdef PCI_OS_SUNOS -#include <sys/byteorder.h> -#define BIG_ENDIAN 4321 -#ifdef _LITTLE_ENDIAN -#define BYTE_ORDER 1234 -#else -#define BYTE_ORDER 4321 -#endif -#endif - -#ifdef PCI_OS_WINDOWS -#ifdef __MINGW32__ -#include <sys/param.h> -#else -#include <io.h> -#define BIG_ENDIAN 4321 -#define LITTLE_ENDIAN 1234 -#define BYTE_ORDER LITTLE_ENDIAN -#define snprintf _snprintf -#endif -#endif - -#if BYTE_ORDER ==BIG_ENDIAN -#define cpu_to_le16 swab16 -#define cpu_to_le32 swab32 -#define le16_to_cpu swab16 -#define le32_to_cpu swab32 - -static inline word swab16 (word w) -{ -return (w <<8 ) | ((w >>8 ) &0xff ); -} -static inline u32 swab32 (u32 w) -{ -return ((w &0xff000000 ) >>24 ) | - ((w &0x00ff0000 ) >>8 ) | - ((w &0x0000ff00 ) <<8 ) | - ((w &0x000000ff ) <<24 ); -} -#else -#define cpu_to_le16 (x) (x) -#define cpu_to_le32 (x) (x) -#define le16_to_cpu (x) (x) -#define le32_to_cpu (x) (x) -#endif +#define cpu_to_le16 htole16 +#define cpu_to_le32 htole32 +#define le16_to_cpu le16toh +#define le32_to_cpu le32toh -#endif
Re: [PATCH] lspci: Show device name as exported by BIOS (sysfs label attribute) (V2)
Hi!
Quoted 7 lines
Hm, while using the latest 3.3.0 tarball with our pciutils dist package I realized that this diff does not perfectly patch anymore.
Unfortunately without author, looks like a gcc guy added it. I paste it in the end
You may want to incorporate (a shortened version?) it if appropriate.
No, I don't want :-) While it simplifies the code on Linux, it breaks many other platforms.
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 Why is it called "common sense" when nobody seems to have any?
Re: [PATCH] lspci: Show device name as exported by BIOS (sysfs label attribute) (V2)
Quoted 6 lines · Martin Mares
Hi!
Quoted 4 lines
Hm, while using the latest 3.3.0 tarball with our pciutils dist package I realized that this diff does not perfectly patch anymore.
Quoted 6 lines
Quoted 3 lines
Unfortunately without author, looks like a gcc guy added it. I paste it in the end
You may want to incorporate (a shortened version?) it if appropriate.No, I don't want :-) While it simplifies the code on Linux, it breaks many other platforms.
Of course not the whole patch.
The OS specific stuff must stay.
It is about (be careful, copy and pasted) these
which seem to be a nice code reduction:
-#if BYTE_ORDER == BIG_ENDIAN
-#define cpu_to_le16 swab16
-#define cpu_to_le32 swab32
-#define le16_to_cpu swab16
-#define le32_to_cpu swab32
-
-static inline word swab16(word w)
-{
- return (w << 8) | ((w >> 8) & 0xff);
-}
-static inline u32 swab32(u32 w)
-{
- return ((w & 0xff000000) >> 24) |
- ((w & 0x00ff0000) >> 8) | - ((w & 0x0000ff00) << 8) | - ((w & 0x000000ff) << 24);
-}
-#else
-#define cpu_to_le16(x) (x)
-#define cpu_to_le32(x) (x)
-#define le16_to_cpu(x) (x)
-#define le32_to_cpu(x) (x)
-#endif
+#define cpu_to_le16 htole16
+#define cpu_to_le32 htole32
+#define le16_to_cpu le16toh
+#define le32_to_cpu le32toh
Thomas