rpadlpar_sysfs.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 <[email protected]>
  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. strscpy(drc_name, buf, nbytes + 1);
  33. end = strchr(drc_name, '\n');
  34. if (end)
  35. *end = '\0';
  36. rc = dlpar_add_slot(drc_name);
  37. if (rc)
  38. return rc;
  39. return nbytes;
  40. }
  41. static ssize_t add_slot_show(struct kobject *kobj,
  42. struct kobj_attribute *attr, char *buf)
  43. {
  44. return sysfs_emit(buf, "0\n");
  45. }
  46. static ssize_t remove_slot_store(struct kobject *kobj,
  47. struct kobj_attribute *attr,
  48. const char *buf, size_t nbytes)
  49. {
  50. char drc_name[MAX_DRC_NAME_LEN];
  51. int rc;
  52. char *end;
  53. if (nbytes >= MAX_DRC_NAME_LEN)
  54. return 0;
  55. strscpy(drc_name, buf, nbytes + 1);
  56. end = strchr(drc_name, '\n');
  57. if (end)
  58. *end = '\0';
  59. rc = dlpar_remove_slot(drc_name);
  60. if (rc)
  61. return rc;
  62. return nbytes;
  63. }
  64. static ssize_t remove_slot_show(struct kobject *kobj,
  65. struct kobj_attribute *attr, char *buf)
  66. {
  67. return sysfs_emit(buf, "0\n");
  68. }
  69. static struct kobj_attribute add_slot_attr =
  70. __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
  71. static struct kobj_attribute remove_slot_attr =
  72. __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
  73. static struct attribute *default_attrs[] = {
  74. &add_slot_attr.attr,
  75. &remove_slot_attr.attr,
  76. NULL,
  77. };
  78. static const struct attribute_group dlpar_attr_group = {
  79. .attrs = default_attrs,
  80. };
  81. static struct kobject *dlpar_kobj;
  82. int dlpar_sysfs_init(void)
  83. {
  84. int error;
  85. dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
  86. &pci_slots_kset->kobj);
  87. if (!dlpar_kobj)
  88. return -EINVAL;
  89. error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
  90. if (error)
  91. kobject_put(dlpar_kobj);
  92. return error;
  93. }
  94. void dlpar_sysfs_exit(void)
  95. {
  96. sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
  97. kobject_put(dlpar_kobj);
  98. }