linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Renninger <trenn@suse.de>
To: mj@ucw.cz
Cc: trenn@suse.de, linux-pci@vger.kernel.org
Subject: [PATCH] lspci: Show device name as exported by BIOS (sysfs label attribute) (V2)
Date: Tue, 28 Jan 2014 08:51:02 +0100	[thread overview]
Message-ID: <1390895462-60699-1-git-send-email-trenn@suse.de> (raw)
In-Reply-To: <1390856419-35985-1-git-send-email-trenn@suse.de>

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

Signed-off-by: Thomas Renninger <trenn@suse.de>
CC: linux-pci@vger.kernel.org
---
 lib/access.c |    1 +
 lib/pci.h    |    1 +
 lib/sysfs.c  |    4 ++++
 lspci.c      |    2 ++
 4 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/lib/access.c b/lib/access.c
index 5112504..c23a2fd 100644
--- a/lib/access.c
+++ b/lib/access.c
@@ -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);
 }
diff --git a/lib/pci.h b/lib/pci.h
index 38e2e99..f31419d 100644
--- a/lib/pci.h
+++ b/lib/pci.h
@@ -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;
diff --git a/lib/sysfs.c b/lib/sysfs.c
index 5a48c0d..3a8a34f 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -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);
diff --git a/lspci.c b/lspci.c
index dbba678..eb17af5 100644
--- a/lspci.c
+++ b/lspci.c
@@ -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",
-- 
1.7.6.1


  reply	other threads:[~2014-01-28  7:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-27 21:00 [PATCH] lspci: Show device name as exported by BIOS (sysfs label attribute) Thomas Renninger
2014-01-28  7:51 ` Thomas Renninger [this message]
2014-11-01 15:22   ` [PATCH] lspci: Show device name as exported by BIOS (sysfs label attribute) (V2) Martin Mares
2014-11-01 16:16     ` Martin Mares
2014-11-13 15:23       ` Thomas Renninger
2014-11-14 21:34         ` Martin Mares
2014-11-16 10:05           ` Thomas Renninger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1390895462-60699-1-git-send-email-trenn@suse.de \
    --to=trenn@suse.de \
    --cc=linux-pci@vger.kernel.org \
    --cc=mj@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).