pci_sysfs.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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(container_of(dev, struct pci_dev, dev));
  16. sprintf(buf, "0x%08x\n", zdev->fid);
  17. return strlen(buf);
  18. }
  19. static DEVICE_ATTR(function_id, S_IRUGO, show_fid, NULL);
  20. static ssize_t show_fh(struct device *dev, struct device_attribute *attr,
  21. char *buf)
  22. {
  23. struct zpci_dev *zdev = get_zdev(container_of(dev, struct pci_dev, dev));
  24. sprintf(buf, "0x%08x\n", zdev->fh);
  25. return strlen(buf);
  26. }
  27. static DEVICE_ATTR(function_handle, S_IRUGO, show_fh, NULL);
  28. static ssize_t show_pchid(struct device *dev, struct device_attribute *attr,
  29. char *buf)
  30. {
  31. struct zpci_dev *zdev = get_zdev(container_of(dev, struct pci_dev, dev));
  32. sprintf(buf, "0x%04x\n", zdev->pchid);
  33. return strlen(buf);
  34. }
  35. static DEVICE_ATTR(pchid, S_IRUGO, show_pchid, NULL);
  36. static ssize_t show_pfgid(struct device *dev, struct device_attribute *attr,
  37. char *buf)
  38. {
  39. struct zpci_dev *zdev = get_zdev(container_of(dev, struct pci_dev, dev));
  40. sprintf(buf, "0x%02x\n", zdev->pfgid);
  41. return strlen(buf);
  42. }
  43. static DEVICE_ATTR(pfgid, S_IRUGO, show_pfgid, NULL);
  44. static struct device_attribute *zpci_dev_attrs[] = {
  45. &dev_attr_function_id,
  46. &dev_attr_function_handle,
  47. &dev_attr_pchid,
  48. &dev_attr_pfgid,
  49. NULL,
  50. };
  51. int zpci_sysfs_add_device(struct device *dev)
  52. {
  53. int i, rc = 0;
  54. for (i = 0; zpci_dev_attrs[i]; i++) {
  55. rc = device_create_file(dev, zpci_dev_attrs[i]);
  56. if (rc)
  57. goto error;
  58. }
  59. return 0;
  60. error:
  61. while (--i >= 0)
  62. device_remove_file(dev, zpci_dev_attrs[i]);
  63. return rc;
  64. }
  65. void zpci_sysfs_remove_device(struct device *dev)
  66. {
  67. int i;
  68. for (i = 0; zpci_dev_attrs[i]; i++)
  69. device_remove_file(dev, zpci_dev_attrs[i]);
  70. }