rpadlpar_sysfs.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_hotplug.h>
  18. #include "rpadlpar.h"
  19. #define DLPAR_KOBJ_NAME "control"
  20. #define ADD_SLOT_ATTR_NAME "add_slot"
  21. #define REMOVE_SLOT_ATTR_NAME "remove_slot"
  22. #define MAX_DRC_NAME_LEN 64
  23. static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
  24. const char *buf, size_t nbytes)
  25. {
  26. char drc_name[MAX_DRC_NAME_LEN];
  27. char *end;
  28. int rc;
  29. if (nbytes >= MAX_DRC_NAME_LEN)
  30. return 0;
  31. memcpy(drc_name, buf, nbytes);
  32. end = strchr(drc_name, '\n');
  33. if (!end)
  34. end = &drc_name[nbytes];
  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 sprintf(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. memcpy(drc_name, buf, nbytes);
  56. end = strchr(drc_name, '\n');
  57. if (!end)
  58. end = &drc_name[nbytes];
  59. *end = '\0';
  60. rc = dlpar_remove_slot(drc_name);
  61. if (rc)
  62. return rc;
  63. return nbytes;
  64. }
  65. static ssize_t remove_slot_show(struct kobject *kobj,
  66. struct kobj_attribute *attr, char *buf)
  67. {
  68. return sprintf(buf, "0\n");
  69. }
  70. static struct kobj_attribute add_slot_attr =
  71. __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
  72. static struct kobj_attribute remove_slot_attr =
  73. __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
  74. static struct attribute *default_attrs[] = {
  75. &add_slot_attr.attr,
  76. &remove_slot_attr.attr,
  77. NULL,
  78. };
  79. static struct attribute_group dlpar_attr_group = {
  80. .attrs = default_attrs,
  81. };
  82. static struct kobject *dlpar_kobj;
  83. int dlpar_sysfs_init(void)
  84. {
  85. int error;
  86. dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
  87. &pci_hotplug_slots_kset->kobj);
  88. if (!dlpar_kobj)
  89. return -EINVAL;
  90. error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
  91. if (error)
  92. kobject_put(dlpar_kobj);
  93. return error;
  94. }
  95. void dlpar_sysfs_exit(void)
  96. {
  97. sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
  98. kobject_put(dlpar_kobj);
  99. }