[PATCH] W1: w1_netlink: New init/fini netlink callbacks.
[linux-2.6/verdex.git] / drivers / pci / hotplug / rpadlpar_sysfs.c
blob752e6513c447dce6ab3f5882a075e0f66eaf9dca
1 /*
2 * Interface for Dynamic Logical Partitioning of I/O Slots on
3 * RPA-compliant PPC64 platform.
5 * John Rose <johnrose@austin.ibm.com>
6 * October 2003
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 "pci_hotplug.h"
18 #include "rpadlpar.h"
20 #define DLPAR_KOBJ_NAME "control"
21 #define ADD_SLOT_ATTR_NAME "add_slot"
22 #define REMOVE_SLOT_ATTR_NAME "remove_slot"
24 #define MAX_DRC_NAME_LEN 64
26 /* Store return code of dlpar operation in attribute struct */
27 struct dlpar_io_attr {
28 int rc;
29 struct attribute attr;
30 ssize_t (*store)(struct dlpar_io_attr *dlpar_attr, const char *buf,
31 size_t nbytes);
34 /* Common show callback for all attrs, display the return code
35 * of the dlpar op */
36 static ssize_t
37 dlpar_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
39 struct dlpar_io_attr *dlpar_attr = container_of(attr,
40 struct dlpar_io_attr, attr);
41 return sprintf(buf, "%d\n", dlpar_attr->rc);
44 static ssize_t
45 dlpar_attr_store(struct kobject * kobj, struct attribute * attr,
46 const char *buf, size_t nbytes)
48 struct dlpar_io_attr *dlpar_attr = container_of(attr,
49 struct dlpar_io_attr, attr);
50 return dlpar_attr->store ?
51 dlpar_attr->store(dlpar_attr, buf, nbytes) : -EIO;
54 static struct sysfs_ops dlpar_attr_sysfs_ops = {
55 .show = dlpar_attr_show,
56 .store = dlpar_attr_store,
59 static ssize_t add_slot_store(struct dlpar_io_attr *dlpar_attr,
60 const char *buf, size_t nbytes)
62 char drc_name[MAX_DRC_NAME_LEN];
63 char *end;
65 if (nbytes > MAX_DRC_NAME_LEN)
66 return 0;
68 memcpy(drc_name, buf, nbytes);
70 end = strchr(drc_name, '\n');
71 if (!end)
72 end = &drc_name[nbytes];
73 *end = '\0';
75 dlpar_attr->rc = dlpar_add_slot(drc_name);
77 return nbytes;
80 static ssize_t remove_slot_store(struct dlpar_io_attr *dlpar_attr,
81 const char *buf, size_t nbytes)
83 char drc_name[MAX_DRC_NAME_LEN];
84 char *end;
86 if (nbytes > MAX_DRC_NAME_LEN)
87 return 0;
89 memcpy(drc_name, buf, nbytes);
91 end = strchr(drc_name, '\n');
92 if (!end)
93 end = &drc_name[nbytes];
94 *end = '\0';
96 dlpar_attr->rc = dlpar_remove_slot(drc_name);
98 return nbytes;
101 static struct dlpar_io_attr add_slot_attr = {
102 .rc = 0,
103 .attr = { .name = ADD_SLOT_ATTR_NAME, .mode = 0644, },
104 .store = add_slot_store,
107 static struct dlpar_io_attr remove_slot_attr = {
108 .rc = 0,
109 .attr = { .name = REMOVE_SLOT_ATTR_NAME, .mode = 0644},
110 .store = remove_slot_store,
113 static struct attribute *default_attrs[] = {
114 &add_slot_attr.attr,
115 &remove_slot_attr.attr,
116 NULL,
119 static void dlpar_io_release(struct kobject *kobj)
121 /* noop */
122 return;
125 struct kobj_type ktype_dlpar_io = {
126 .release = dlpar_io_release,
127 .sysfs_ops = &dlpar_attr_sysfs_ops,
128 .default_attrs = default_attrs,
131 struct kset dlpar_io_kset = {
132 .subsys = &pci_hotplug_slots_subsys,
133 .kobj = {.name = DLPAR_KOBJ_NAME, .ktype=&ktype_dlpar_io,},
134 .ktype = &ktype_dlpar_io,
137 int dlpar_sysfs_init(void)
139 if (kset_register(&dlpar_io_kset)) {
140 printk(KERN_ERR "rpadlpar_io: cannot register kset for %s\n",
141 dlpar_io_kset.kobj.name);
142 return -EINVAL;
145 return 0;
148 void dlpar_sysfs_exit(void)
150 kset_unregister(&dlpar_io_kset);