0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/kobject.h>
0012 #include <linux/string.h>
0013 #include <linux/pci.h>
0014 #include <linux/pci_hotplug.h>
0015 #include "rpaphp.h"
0016 #include "rpadlpar.h"
0017 #include "../pci.h"
0018
0019 #define DLPAR_KOBJ_NAME "control"
0020
0021
0022
0023
0024 #define ADD_SLOT_ATTR_NAME add_slot
0025 #define REMOVE_SLOT_ATTR_NAME remove_slot
0026
0027 static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
0028 const char *buf, size_t nbytes)
0029 {
0030 char drc_name[MAX_DRC_NAME_LEN];
0031 char *end;
0032 int rc;
0033
0034 if (nbytes >= MAX_DRC_NAME_LEN)
0035 return 0;
0036
0037 strscpy(drc_name, buf, nbytes + 1);
0038
0039 end = strchr(drc_name, '\n');
0040 if (end)
0041 *end = '\0';
0042
0043 rc = dlpar_add_slot(drc_name);
0044 if (rc)
0045 return rc;
0046
0047 return nbytes;
0048 }
0049
0050 static ssize_t add_slot_show(struct kobject *kobj,
0051 struct kobj_attribute *attr, char *buf)
0052 {
0053 return sysfs_emit(buf, "0\n");
0054 }
0055
0056 static ssize_t remove_slot_store(struct kobject *kobj,
0057 struct kobj_attribute *attr,
0058 const char *buf, size_t nbytes)
0059 {
0060 char drc_name[MAX_DRC_NAME_LEN];
0061 int rc;
0062 char *end;
0063
0064 if (nbytes >= MAX_DRC_NAME_LEN)
0065 return 0;
0066
0067 strscpy(drc_name, buf, nbytes + 1);
0068
0069 end = strchr(drc_name, '\n');
0070 if (end)
0071 *end = '\0';
0072
0073 rc = dlpar_remove_slot(drc_name);
0074 if (rc)
0075 return rc;
0076
0077 return nbytes;
0078 }
0079
0080 static ssize_t remove_slot_show(struct kobject *kobj,
0081 struct kobj_attribute *attr, char *buf)
0082 {
0083 return sysfs_emit(buf, "0\n");
0084 }
0085
0086 static struct kobj_attribute add_slot_attr =
0087 __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
0088
0089 static struct kobj_attribute remove_slot_attr =
0090 __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
0091
0092 static struct attribute *default_attrs[] = {
0093 &add_slot_attr.attr,
0094 &remove_slot_attr.attr,
0095 NULL,
0096 };
0097
0098 static const struct attribute_group dlpar_attr_group = {
0099 .attrs = default_attrs,
0100 };
0101
0102 static struct kobject *dlpar_kobj;
0103
0104 int dlpar_sysfs_init(void)
0105 {
0106 int error;
0107
0108 dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
0109 &pci_slots_kset->kobj);
0110 if (!dlpar_kobj)
0111 return -EINVAL;
0112
0113 error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
0114 if (error)
0115 kobject_put(dlpar_kobj);
0116 return error;
0117 }
0118
0119 void dlpar_sysfs_exit(void)
0120 {
0121 sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
0122 kobject_put(dlpar_kobj);
0123 }