diff options
| author | Bjorn Helgaas <bhelgaas@google.com> | 2025-10-03 12:13:25 -0500 |
|---|---|---|
| committer | Bjorn Helgaas <bhelgaas@google.com> | 2025-10-03 12:13:25 -0500 |
| commit | 51204faa4273a64b7066b5c1b5383e9b20d58caa (patch) | |
| tree | 4571eaaa725e6442cb3113f414531603d49eadf2 /drivers/pci/pci-sysfs.c | |
| parent | Merge branch 'pci/controller/xilinx-nwl' (diff) | |
| parent | PCI/sysfs: Expose PCI device serial number (diff) | |
| download | linux-51204faa4273a64b7066b5c1b5383e9b20d58caa.tar.gz linux-51204faa4273a64b7066b5c1b5383e9b20d58caa.zip | |
Merge branch 'pci/misc'
- Fix whitespace issues (Li Jun)
- Fix pci_acpi_preserve_config() memory leak (Nirmoy Das)
- Add sysfs 'serial_number' file to expose the Device Serial Number
(Matthew Wood)
* pci/misc:
PCI/sysfs: Expose PCI device serial number
PCI/ACPI: Fix pci_acpi_preserve_config() memory leak
Diffstat (limited to 'drivers/pci/pci-sysfs.c')
| -rw-r--r-- | drivers/pci/pci-sysfs.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 50a2250acc2b..af74cf02bb90 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -30,6 +30,7 @@ #include <linux/msi.h> #include <linux/of.h> #include <linux/aperture.h> +#include <linux/unaligned.h> #include "pci.h" #ifndef ARCH_PCI_DEV_GROUPS @@ -719,6 +720,22 @@ static ssize_t boot_vga_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(boot_vga); +static ssize_t serial_number_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct pci_dev *pci_dev = to_pci_dev(dev); + u64 dsn; + u8 bytes[8]; + + dsn = pci_get_dsn(pci_dev); + if (!dsn) + return -EIO; + + put_unaligned_be64(dsn, bytes); + return sysfs_emit(buf, "%8phD\n", bytes); +} +static DEVICE_ATTR_ADMIN_RO(serial_number); + static ssize_t pci_read_config(struct file *filp, struct kobject *kobj, const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) @@ -1729,6 +1746,7 @@ late_initcall(pci_sysfs_init); static struct attribute *pci_dev_dev_attrs[] = { &dev_attr_boot_vga.attr, + &dev_attr_serial_number.attr, NULL, }; @@ -1741,6 +1759,9 @@ static umode_t pci_dev_attrs_are_visible(struct kobject *kobj, if (a == &dev_attr_boot_vga.attr && pci_is_vga(pdev)) return a->mode; + if (a == &dev_attr_serial_number.attr && pci_get_dsn(pdev)) + return a->mode; + return 0; } |
