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
22 #define DLPAR_KOBJ_NAME "control"
23
24 /* Those two have no quotes because they are passed to __ATTR() which
25 * stringifies the argument (yuck !)
26 */
27 #define ADD_SLOT_ATTR_NAME add_slot
28 #define REMOVE_SLOT_ATTR_NAME remove_slot
29
30 #define MAX_DRC_NAME_LEN 64
31
add_slot_store(struct kobject * kobj,struct kobj_attribute * attr,const char * buf,size_t nbytes)32 static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
33 const char *buf, size_t nbytes)
34 {
35 char drc_name[MAX_DRC_NAME_LEN];
36 char *end;
37 int rc;
38
39 if (nbytes >= MAX_DRC_NAME_LEN)
40 return 0;
41
42 strscpy(drc_name, buf, nbytes + 1);
43
44 end = strchr(drc_name, '\n');
45 if (end)
46 *end = '\0';
47
48 rc = dlpar_add_slot(drc_name);
49 if (rc)
50 return rc;
51
52 return nbytes;
53 }
54
add_slot_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)55 static ssize_t add_slot_show(struct kobject *kobj,
56 struct kobj_attribute *attr, char *buf)
57 {
58 return sprintf(buf, "0\n");
59 }
60
remove_slot_store(struct kobject * kobj,struct kobj_attribute * attr,const char * buf,size_t nbytes)61 static ssize_t remove_slot_store(struct kobject *kobj,
62 struct kobj_attribute *attr,
63 const char *buf, size_t nbytes)
64 {
65 char drc_name[MAX_DRC_NAME_LEN];
66 int rc;
67 char *end;
68
69 if (nbytes >= MAX_DRC_NAME_LEN)
70 return 0;
71
72 strscpy(drc_name, buf, nbytes + 1);
73
74 end = strchr(drc_name, '\n');
75 if (end)
76 *end = '\0';
77
78 rc = dlpar_remove_slot(drc_name);
79 if (rc)
80 return rc;
81
82 return nbytes;
83 }
84
remove_slot_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)85 static ssize_t remove_slot_show(struct kobject *kobj,
86 struct kobj_attribute *attr, char *buf)
87 {
88 return sprintf(buf, "0\n");
89 }
90
91 static struct kobj_attribute add_slot_attr =
92 __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
93
94 static struct kobj_attribute remove_slot_attr =
95 __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
96
97 static struct attribute *default_attrs[] = {
98 &add_slot_attr.attr,
99 &remove_slot_attr.attr,
100 NULL,
101 };
102
103 static struct attribute_group dlpar_attr_group = {
104 .attrs = default_attrs,
105 };
106
107 static struct kobject *dlpar_kobj;
108
dlpar_sysfs_init(void)109 int dlpar_sysfs_init(void)
110 {
111 int error;
112
113 dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
114 &pci_slots_kset->kobj);
115 if (!dlpar_kobj)
116 return -EINVAL;
117
118 error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
119 if (error)
120 kobject_put(dlpar_kobj);
121 return error;
122 }
123
dlpar_sysfs_exit(void)124 void dlpar_sysfs_exit(void)
125 {
126 sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
127 kobject_put(dlpar_kobj);
128 }
129