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 "pci_hotplug.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
{
29 struct attribute attr
;
30 ssize_t (*store
)(struct dlpar_io_attr
*dlpar_attr
, const char *buf
,
34 /* Common show callback for all attrs, display the return code
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
);
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
];
65 if (nbytes
> MAX_DRC_NAME_LEN
)
68 memcpy(drc_name
, buf
, nbytes
);
70 end
= strchr(drc_name
, '\n');
72 end
= &drc_name
[nbytes
];
75 dlpar_attr
->rc
= dlpar_add_slot(drc_name
);
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
];
86 if (nbytes
> MAX_DRC_NAME_LEN
)
89 memcpy(drc_name
, buf
, nbytes
);
91 end
= strchr(drc_name
, '\n');
93 end
= &drc_name
[nbytes
];
96 dlpar_attr
->rc
= dlpar_remove_slot(drc_name
);
101 static struct dlpar_io_attr add_slot_attr
= {
103 .attr
= { .name
= ADD_SLOT_ATTR_NAME
, .mode
= 0644, },
104 .store
= add_slot_store
,
107 static struct dlpar_io_attr remove_slot_attr
= {
109 .attr
= { .name
= REMOVE_SLOT_ATTR_NAME
, .mode
= 0644},
110 .store
= remove_slot_store
,
113 static struct attribute
*default_attrs
[] = {
115 &remove_slot_attr
.attr
,
119 static void dlpar_io_release(struct kobject
*kobj
)
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
);
148 void dlpar_sysfs_exit(void)
150 kset_unregister(&dlpar_io_kset
);