2 * Interface for Dynamic Logical Partitioning of I/O Slots on
3 * RPA-compliant PPC64 platform.
5 * John Rose <johnrose@austin.ibm.com>
8 * Copyright (C) 2003 IBM.
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.
15 #include <linux/kobject.h>
16 #include <linux/string.h>
17 #include <linux/pci_hotplug.h>
20 #define DLPAR_KOBJ_NAME "control"
22 /* Those two have no quotes because they are passed to __ATTR() which
23 * stringifies the argument (yuck !)
25 #define ADD_SLOT_ATTR_NAME add_slot
26 #define REMOVE_SLOT_ATTR_NAME remove_slot
28 #define MAX_DRC_NAME_LEN 64
31 static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
32 const char *buf, size_t nbytes)
34 char drc_name[MAX_DRC_NAME_LEN];
38 if (nbytes >= MAX_DRC_NAME_LEN)
41 memcpy(drc_name, buf, nbytes);
43 end = strchr(drc_name, '\n');
45 end = &drc_name[nbytes];
48 rc = dlpar_add_slot(drc_name);
55 static ssize_t add_slot_show(struct kobject *kobj,
56 struct kobj_attribute *attr, char *buf)
58 return sprintf(buf, "0\n");
61 static ssize_t remove_slot_store(struct kobject *kobj,
62 struct kobj_attribute *attr,
63 const char *buf, size_t nbytes)
65 char drc_name[MAX_DRC_NAME_LEN];
69 if (nbytes >= MAX_DRC_NAME_LEN)
72 memcpy(drc_name, buf, nbytes);
74 end = strchr(drc_name, '\n');
76 end = &drc_name[nbytes];
79 rc = dlpar_remove_slot(drc_name);
86 static ssize_t remove_slot_show(struct kobject *kobj,
87 struct kobj_attribute *attr, char *buf)
89 return sprintf(buf, "0\n");
92 static struct kobj_attribute add_slot_attr =
93 __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
95 static struct kobj_attribute remove_slot_attr =
96 __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
98 static struct attribute *default_attrs[] = {
100 &remove_slot_attr.attr,
104 static struct attribute_group dlpar_attr_group = {
105 .attrs = default_attrs,
108 static struct kobject *dlpar_kobj;
110 int dlpar_sysfs_init(void)
114 dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
115 &pci_hotplug_slots_kset->kobj);
119 error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
121 kobject_put(dlpar_kobj);
125 void dlpar_sysfs_exit(void)
127 sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
128 kobject_put(dlpar_kobj);