diff options
author | Bjorn Helgaas <bhelgaas@google.com> | 2018-03-19 14:06:17 -0400 |
---|---|---|
committer | Bjorn Helgaas <helgaas@kernel.org> | 2018-03-19 14:06:17 -0400 |
commit | b1c615c48fa93db64310e8d1a457b364a486fde8 (patch) | |
tree | 067317ad7af8950ae39030d2727091857b6fd000 | |
parent | f0eb77ae6b857bf8118f7a8ee0a8ba076feed70d (diff) |
PCI/VPD: Move VPD sysfs code to vpd.c
Move the VPD-related sysfs code from pci-sysfs.c to vpd.c. This follows
the pattern of pcie_aspm_create_sysfs_dev_files(). The goal is to
encapsulate all the VPD code and structures in vpd.c.
No functional change intended.
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
-rw-r--r-- | drivers/pci/pci-sysfs.c | 67 | ||||
-rw-r--r-- | drivers/pci/pci.h | 2 | ||||
-rw-r--r-- | drivers/pci/vpd.c | 67 |
3 files changed, 72 insertions, 64 deletions
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index eb6bee8724cc..4415e624cf7e 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c | |||
@@ -982,38 +982,6 @@ static ssize_t pci_write_config(struct file *filp, struct kobject *kobj, | |||
982 | return count; | 982 | return count; |
983 | } | 983 | } |
984 | 984 | ||
985 | static ssize_t read_vpd_attr(struct file *filp, struct kobject *kobj, | ||
986 | struct bin_attribute *bin_attr, char *buf, | ||
987 | loff_t off, size_t count) | ||
988 | { | ||
989 | struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj)); | ||
990 | |||
991 | if (bin_attr->size > 0) { | ||
992 | if (off > bin_attr->size) | ||
993 | count = 0; | ||
994 | else if (count > bin_attr->size - off) | ||
995 | count = bin_attr->size - off; | ||
996 | } | ||
997 | |||
998 | return pci_read_vpd(dev, off, count, buf); | ||
999 | } | ||
1000 | |||
1001 | static ssize_t write_vpd_attr(struct file *filp, struct kobject *kobj, | ||
1002 | struct bin_attribute *bin_attr, char *buf, | ||
1003 | loff_t off, size_t count) | ||
1004 | { | ||
1005 | struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj)); | ||
1006 | |||
1007 | if (bin_attr->size > 0) { | ||
1008 | if (off > bin_attr->size) | ||
1009 | count = 0; | ||
1010 | else if (count > bin_attr->size - off) | ||
1011 | count = bin_attr->size - off; | ||
1012 | } | ||
1013 | |||
1014 | return pci_write_vpd(dev, off, count, buf); | ||
1015 | } | ||
1016 | |||
1017 | #ifdef HAVE_PCI_LEGACY | 985 | #ifdef HAVE_PCI_LEGACY |
1018 | /** | 986 | /** |
1019 | * pci_read_legacy_io - read byte(s) from legacy I/O port space | 987 | * pci_read_legacy_io - read byte(s) from legacy I/O port space |
@@ -1517,29 +1485,8 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor | |||
1517 | static int pci_create_capabilities_sysfs(struct pci_dev *dev) | 1485 | static int pci_create_capabilities_sysfs(struct pci_dev *dev) |
1518 | { | 1486 | { |
1519 | int retval; | 1487 | int retval; |
1520 | struct bin_attribute *attr; | ||
1521 | |||
1522 | /* If the device has VPD, try to expose it in sysfs. */ | ||
1523 | if (dev->vpd) { | ||
1524 | attr = kzalloc(sizeof(*attr), GFP_ATOMIC); | ||
1525 | if (!attr) | ||
1526 | return -ENOMEM; | ||
1527 | 1488 | ||
1528 | sysfs_bin_attr_init(attr); | 1489 | pcie_vpd_create_sysfs_dev_files(dev); |
1529 | attr->size = 0; | ||
1530 | attr->attr.name = "vpd"; | ||
1531 | attr->attr.mode = S_IRUSR | S_IWUSR; | ||
1532 | attr->read = read_vpd_attr; | ||
1533 | attr->write = write_vpd_attr; | ||
1534 | retval = sysfs_create_bin_file(&dev->dev.kobj, attr); | ||
1535 | if (retval) { | ||
1536 | kfree(attr); | ||
1537 | return retval; | ||
1538 | } | ||
1539 | dev->vpd->attr = attr; | ||
1540 | } | ||
1541 | |||
1542 | /* Active State Power Management */ | ||
1543 | pcie_aspm_create_sysfs_dev_files(dev); | 1490 | pcie_aspm_create_sysfs_dev_files(dev); |
1544 | 1491 | ||
1545 | if (!pci_probe_reset_function(dev)) { | 1492 | if (!pci_probe_reset_function(dev)) { |
@@ -1552,11 +1499,7 @@ static int pci_create_capabilities_sysfs(struct pci_dev *dev) | |||
1552 | 1499 | ||
1553 | error: | 1500 | error: |
1554 | pcie_aspm_remove_sysfs_dev_files(dev); | 1501 | pcie_aspm_remove_sysfs_dev_files(dev); |
1555 | if (dev->vpd && dev->vpd->attr) { | 1502 | pcie_vpd_remove_sysfs_dev_files(dev); |
1556 | sysfs_remove_bin_file(&dev->dev.kobj, dev->vpd->attr); | ||
1557 | kfree(dev->vpd->attr); | ||
1558 | } | ||
1559 | |||
1560 | return retval; | 1503 | return retval; |
1561 | } | 1504 | } |
1562 | 1505 | ||
@@ -1630,11 +1573,7 @@ err: | |||
1630 | 1573 | ||
1631 | static void pci_remove_capabilities_sysfs(struct pci_dev *dev) | 1574 | static void pci_remove_capabilities_sysfs(struct pci_dev *dev) |
1632 | { | 1575 | { |
1633 | if (dev->vpd && dev->vpd->attr) { | 1576 | pcie_vpd_remove_sysfs_dev_files(dev); |
1634 | sysfs_remove_bin_file(&dev->dev.kobj, dev->vpd->attr); | ||
1635 | kfree(dev->vpd->attr); | ||
1636 | } | ||
1637 | |||
1638 | pcie_aspm_remove_sysfs_dev_files(dev); | 1577 | pcie_aspm_remove_sysfs_dev_files(dev); |
1639 | if (dev->reset_fn) { | 1578 | if (dev->reset_fn) { |
1640 | device_remove_file(&dev->dev, &reset_attr); | 1579 | device_remove_file(&dev->dev, &reset_attr); |
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index fcd81911b127..1191320a44d5 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h | |||
@@ -123,6 +123,8 @@ struct pci_vpd { | |||
123 | 123 | ||
124 | int pci_vpd_init(struct pci_dev *dev); | 124 | int pci_vpd_init(struct pci_dev *dev); |
125 | void pci_vpd_release(struct pci_dev *dev); | 125 | void pci_vpd_release(struct pci_dev *dev); |
126 | void pcie_vpd_create_sysfs_dev_files(struct pci_dev *dev); | ||
127 | void pcie_vpd_remove_sysfs_dev_files(struct pci_dev *dev); | ||
126 | 128 | ||
127 | /* PCI /proc functions */ | 129 | /* PCI /proc functions */ |
128 | #ifdef CONFIG_PROC_FS | 130 | #ifdef CONFIG_PROC_FS |
diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 4596452d58bf..55477f24d8b9 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c | |||
@@ -378,6 +378,73 @@ void pci_vpd_release(struct pci_dev *dev) | |||
378 | kfree(dev->vpd); | 378 | kfree(dev->vpd); |
379 | } | 379 | } |
380 | 380 | ||
381 | static ssize_t read_vpd_attr(struct file *filp, struct kobject *kobj, | ||
382 | struct bin_attribute *bin_attr, char *buf, | ||
383 | loff_t off, size_t count) | ||
384 | { | ||
385 | struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj)); | ||
386 | |||
387 | if (bin_attr->size > 0) { | ||
388 | if (off > bin_attr->size) | ||
389 | count = 0; | ||
390 | else if (count > bin_attr->size - off) | ||
391 | count = bin_attr->size - off; | ||
392 | } | ||
393 | |||
394 | return pci_read_vpd(dev, off, count, buf); | ||
395 | } | ||
396 | |||
397 | static ssize_t write_vpd_attr(struct file *filp, struct kobject *kobj, | ||
398 | struct bin_attribute *bin_attr, char *buf, | ||
399 | loff_t off, size_t count) | ||
400 | { | ||
401 | struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj)); | ||
402 | |||
403 | if (bin_attr->size > 0) { | ||
404 | if (off > bin_attr->size) | ||
405 | count = 0; | ||
406 | else if (count > bin_attr->size - off) | ||
407 | count = bin_attr->size - off; | ||
408 | } | ||
409 | |||
410 | return pci_write_vpd(dev, off, count, buf); | ||
411 | } | ||
412 | |||
413 | void pcie_vpd_create_sysfs_dev_files(struct pci_dev *dev) | ||
414 | { | ||
415 | int retval; | ||
416 | struct bin_attribute *attr; | ||
417 | |||
418 | if (!dev->vpd) | ||
419 | return; | ||
420 | |||
421 | attr = kzalloc(sizeof(*attr), GFP_ATOMIC); | ||
422 | if (!attr) | ||
423 | return; | ||
424 | |||
425 | sysfs_bin_attr_init(attr); | ||
426 | attr->size = 0; | ||
427 | attr->attr.name = "vpd"; | ||
428 | attr->attr.mode = S_IRUSR | S_IWUSR; | ||
429 | attr->read = read_vpd_attr; | ||
430 | attr->write = write_vpd_attr; | ||
431 | retval = sysfs_create_bin_file(&dev->dev.kobj, attr); | ||
432 | if (retval) { | ||
433 | kfree(attr); | ||
434 | return; | ||
435 | } | ||
436 | |||
437 | dev->vpd->attr = attr; | ||
438 | } | ||
439 | |||
440 | void pcie_vpd_remove_sysfs_dev_files(struct pci_dev *dev) | ||
441 | { | ||
442 | if (dev->vpd && dev->vpd->attr) { | ||
443 | sysfs_remove_bin_file(&dev->dev.kobj, dev->vpd->attr); | ||
444 | kfree(dev->vpd->attr); | ||
445 | } | ||
446 | } | ||
447 | |||
381 | int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt) | 448 | int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt) |
382 | { | 449 | { |
383 | int i; | 450 | int i; |