pci_sysfs.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright IBM Corp. 2012
  3. *
  4. * Author(s):
  5. * Jan Glauber <jang@linux.vnet.ibm.com>
  6. */
  7. #define COMPONENT "zPCI"
  8. #define pr_fmt(fmt) COMPONENT ": " fmt
  9. #include <linux/kernel.h>
  10. #include <linux/stat.h>
  11. #include <linux/pci.h>
  12. static ssize_t show_fid(struct device *dev, struct device_attribute *attr,
  13. char *buf)
  14. {
  15. struct zpci_dev *zdev = get_zdev(to_pci_dev(dev));
  16. return sprintf(buf, "0x%08x\n", zdev->fid);
  17. }
  18. static DEVICE_ATTR(function_id, S_IRUGO, show_fid, NULL);
  19. static ssize_t show_fh(struct device *dev, struct device_attribute *attr,
  20. char *buf)
  21. {
  22. struct zpci_dev *zdev = get_zdev(to_pci_dev(dev));
  23. return sprintf(buf, "0x%08x\n", zdev->fh);
  24. }
  25. static DEVICE_ATTR(function_handle, S_IRUGO, show_fh, NULL);
  26. static ssize_t show_pchid(struct device *dev, struct device_attribute *attr,
  27. char *buf)
  28. {
  29. struct zpci_dev *zdev = get_zdev(to_pci_dev(dev));
  30. return sprintf(buf, "0x%04x\n", zdev->pchid);
  31. }
  32. static DEVICE_ATTR(pchid, S_IRUGO, show_pchid, NULL);
  33. static ssize_t show_pfgid(struct device *dev, struct device_attribute *attr,
  34. char *buf)
  35. {
  36. struct zpci_dev *zdev = get_zdev(to_pci_dev(dev));
  37. return sprintf(buf, "0x%02x\n", zdev->pfgid);
  38. }
  39. static DEVICE_ATTR(pfgid, S_IRUGO, show_pfgid, NULL);
  40. static struct device_attribute *zpci_dev_attrs[] = {
  41. &dev_attr_function_id,
  42. &dev_attr_function_handle,
  43. &dev_attr_pchid,
  44. &dev_attr_pfgid,
  45. NULL,
  46. };
  47. int zpci_sysfs_add_device(struct device *dev)
  48. {
  49. int i, rc = 0;
  50. for (i = 0; zpci_dev_attrs[i]; i++) {
  51. rc = device_create_file(dev, zpci_dev_attrs[i]);
  52. if (rc)
  53. goto error;
  54. }
  55. return 0;
  56. error:
  57. while (--i >= 0)
  58. device_remove_file(dev, zpci_dev_attrs[i]);
  59. return rc;
  60. }
  61. void zpci_sysfs_remove_device(struct device *dev)
  62. {
  63. int i;
  64. for (i = 0; zpci_dev_attrs[i]; i++)
  65. device_remove_file(dev, zpci_dev_attrs[i]);
  66. }