rpadlpar_sysfs.c 2.7 KB

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