PCI vendor and device strings in sysfs
PATCH 1/1 PCI vendor and device strings in sysfs
Hi,
Here is a patch against 2.6.0-test1 to display PCI vendor and device strings in sysfs.
At present, the PCI "name" attribute has a length restriction (DEVICE_NAME_SIZE) within which it tries to accomodate the vendor and device strings, leading to, in most cases, truncation of one or both strings.
This patch alleviates the issue by creating the vendor_name and device_name attributes for PCI devices.
Here is an example:
ananth@llm06:/sys/devices/pci0000:00/0000:00:01.0> cat name Intel Corp. 82810 DC-100 CGC [Ch ananth@llm06:/sys/devices/pci0000:00/0000:00:01.0> cat vendor_name Intel Corp. ananth@llm06:/sys/devices/pci0000:00/0000:00:01.0> cat device_name 82810 DC-100 CGC [Chipset Graphics Controller]
Thanks,
Signature · 3 lines
Ananth Narayan <[email protected]> Linux Technology Center, IBM Software Lab, INDIA
include/linux/pci.h +4 -0
@@ -416,6 +416,10 @@char * slot_name;/* pointer to dev.bus_id */ +/* pointer to export vendor and device strings to sysfs */ +char * vendor_name; +char * device_name; +/* These fields are used by common fixups */ unsigned int transparent:1; /* Transparent PCI bridge */ unsigned int multifunction:1;/* Part of multi-function device */
drivers/pci/names.c +36 -6
68 lines not on this page · raw message
drivers/pci/pci-sysfs.c +38 -0
@@ -39,6 +39,42 @@pci_config_attr (class,"0x%06x\n" );pci_config_attr (irq,"%u\n" ); +/* show vendor name */ +static ssize_t +pci_show_vendor_name (struct device *dev,char *buf) +{ +struct pci_dev * pci_dev =to_pci_dev (dev); +int len; + +if (!pci_dev->vendor_name) +return 0 ; +strcpy (buf, pci_dev->vendor_name); + len =strlen (pci_dev->vendor_name); + buf[len] ='\n' ; + buf[len+1 ] =0 ; +return len+1 ; +} + +static DEVICE_ATTR(vendor_name,S_IRUGO,pci_show_vendor_name,NULL); + +/* show device name */ +static ssize_t +pci_show_device_name (struct device *dev,char *buf) +{ +struct pci_dev * pci_dev =to_pci_dev (dev); +int len; + +if (!pci_dev->device_name) +return 0 ; +strcpy (buf, pci_dev->device_name); + len =strlen (pci_dev->device_name); + buf[len] ='\n' ; + buf[len+1 ] =0 ; +return len+1 ; +} + +static DEVICE_ATTR(device_name,S_IRUGO,pci_show_device_name,NULL); +/* show resources */ static ssize_t pci_show_resources (struct device * dev,char * buf)
@@ -176,5 +212,7 @@device_create_file (dev, &dev_attr_class);device_create_file (dev, &dev_attr_irq);device_create_file (dev, &dev_attr_resource); +device_create_file (dev, &dev_attr_vendor_name); +device_create_file (dev, &dev_attr_device_name);sysfs_create_bin_file (&dev->kobj, &pci_config_attr); }
drivers/pci/probe.c +2 -0
@@ -478,6 +478,8 @@struct pci_dev *pci_dev; pci_dev =to_pci_dev (dev); +kfree (pci_dev->vendor_name); +kfree (pci_dev->device_name);kfree (pci_dev); }
Quoted 11 lines
Here is a patch against 2.6.0-test1 to display PCI vendor and device strings in sysfs.
At present, the PCI "name" attribute has a length restriction (
DEVICE_NAME_SIZE) within which it tries to accomodate the vendor and device strings, leading to, in most cases, truncation of one or both strings.This patch alleviates the issue by creating the
vendor_nameanddevice_nameattributes for PCI devices.
We don't necessarily need to keep the ASCII strings around at all, and in the case in which CONFIG_PCI_NAMES=n, they are completely irrelevant. They are pretty, but we could just export the vendor/device IDs and have a userspace tool (e.g. sysutils from IBM) look up the name in a userspace database.
-pat
Quoted 5 lines · Ananth N Mavinakayanahalli
Hi,
Here is a patch against 2.6.0-test1 to display PCI vendor and device strings in sysfs.
Quoted 7 lines
At present, the PCI "name" attribute has a length restriction (
DEVICE_NAME_SIZE) within which it tries to accomodate the vendor and device strings, leading to, in most cases, truncation of one or both strings.This patch alleviates the issue by creating the
vendor_nameanddevice_nameattributes for PCI devices.
I agree with Pat, this should be done in userspace.
We should really just get rid of the dev->name file all together to keep people from relying on it :)
thanks,
greg k-h