rpadlpar_sysfs.c 2.8 KB

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