rpadlpar_sysfs.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Interface for Dynamic Logical Partitioning of I/O Slots on
  4. * RPA-compliant PPC64 platform.
  5. *
  6. * John Rose <johnrose@austin.ibm.com>
  7. * October 2003
  8. *
  9. * Copyright (C) 2003 IBM.
  10. */
  11. #include <linux/kobject.h>
  12. #include <linux/string.h>
  13. #include <linux/pci.h>
  14. #include <linux/pci_hotplug.h>
  15. #include "rpaphp.h"
  16. #include "rpadlpar.h"
  17. #include "../pci.h"
  18. #define DLPAR_KOBJ_NAME "control"
  19. /* Those two have no quotes because they are passed to __ATTR() which
  20. * stringifies the argument (yuck !)
  21. */
  22. #define ADD_SLOT_ATTR_NAME add_slot
  23. #define REMOVE_SLOT_ATTR_NAME remove_slot
  24. static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
  25. const char *buf, size_t nbytes)
  26. {
  27. char drc_name[MAX_DRC_NAME_LEN];
  28. char *end;
  29. int rc;
  30. if (nbytes >= MAX_DRC_NAME_LEN)
  31. return 0;
  32. memcpy(drc_name, buf, nbytes);
  33. end = strchr(drc_name, '\n');
  34. if (!end)
  35. end = &drc_name[nbytes];
  36. *end = '\0';
  37. rc = dlpar_add_slot(drc_name);
  38. if (rc)
  39. return rc;
  40. return nbytes;
  41. }
  42. static ssize_t add_slot_show(struct kobject *kobj,
  43. struct kobj_attribute *attr, char *buf)
  44. {
  45. return sprintf(buf, "0\n");
  46. }
  47. static ssize_t remove_slot_store(struct kobject *kobj,
  48. struct kobj_attribute *attr,
  49. const char *buf, size_t nbytes)
  50. {
  51. char drc_name[MAX_DRC_NAME_LEN];
  52. int rc;
  53. char *end;
  54. if (nbytes >= MAX_DRC_NAME_LEN)
  55. return 0;
  56. memcpy(drc_name, buf, nbytes);
  57. end = strchr(drc_name, '\n');
  58. if (!end)
  59. end = &drc_name[nbytes];
  60. *end = '\0';
  61. rc = dlpar_remove_slot(drc_name);
  62. if (rc)
  63. return rc;
  64. return nbytes;
  65. }
  66. static ssize_t remove_slot_show(struct kobject *kobj,
  67. struct kobj_attribute *attr, char *buf)
  68. {
  69. return sprintf(buf, "0\n");
  70. }
  71. static struct kobj_attribute add_slot_attr =
  72. __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
  73. static struct kobj_attribute remove_slot_attr =
  74. __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
  75. static struct attribute *default_attrs[] = {
  76. &add_slot_attr.attr,
  77. &remove_slot_attr.attr,
  78. NULL,
  79. };
  80. static const struct attribute_group dlpar_attr_group = {
  81. .attrs = default_attrs,
  82. };
  83. static struct kobject *dlpar_kobj;
  84. int dlpar_sysfs_init(void)
  85. {
  86. int error;
  87. dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
  88. &pci_slots_kset->kobj);
  89. if (!dlpar_kobj)
  90. return -EINVAL;
  91. error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
  92. if (error)
  93. kobject_put(dlpar_kobj);
  94. return error;
  95. }
  96. void dlpar_sysfs_exit(void)
  97. {
  98. sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
  99. kobject_put(dlpar_kobj);
  100. }