blob: 779c5db71be46150bc5c34896bea57dc23697b9e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Greg Kroah-Hartman7a54f252006-10-13 20:05:19 -070017#include <linux/pci_hotplug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "rpadlpar.h"
19
20#define DLPAR_KOBJ_NAME "control"
Benjamin Herrenschmidta9b841e2008-05-30 13:39:12 +100021
22/* Those two have no quotes because they are passed to __ATTR() which
23 * stringifies the argument (yuck !)
24 */
25#define ADD_SLOT_ATTR_NAME add_slot
26#define REMOVE_SLOT_ATTR_NAME remove_slot
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#define MAX_DRC_NAME_LEN 64
29
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080030
31static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
32 const char *buf, size_t nbytes)
33{
34 char drc_name[MAX_DRC_NAME_LEN];
35 char *end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080038 if (nbytes >= MAX_DRC_NAME_LEN)
39 return 0;
40
41 memcpy(drc_name, buf, nbytes);
42
43 end = strchr(drc_name, '\n');
44 if (!end)
45 end = &drc_name[nbytes];
46 *end = '\0';
47
48 rc = dlpar_add_slot(drc_name);
49 if (rc)
50 return rc;
51
52 return nbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080055static ssize_t add_slot_show(struct kobject *kobj,
56 struct kobj_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080058 return sprintf(buf, "0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080061static ssize_t remove_slot_store(struct kobject *kobj,
62 struct kobj_attribute *attr,
63 const char *buf, size_t nbytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
65 char drc_name[MAX_DRC_NAME_LEN];
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080066 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 char *end;
68
Linda Xie02fe75a2005-09-22 00:48:24 -070069 if (nbytes >= MAX_DRC_NAME_LEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 return 0;
71
72 memcpy(drc_name, buf, nbytes);
73
74 end = strchr(drc_name, '\n');
75 if (!end)
76 end = &drc_name[nbytes];
77 *end = '\0';
78
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080079 rc = dlpar_remove_slot(drc_name);
80 if (rc)
81 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83 return nbytes;
84}
85
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080086static ssize_t remove_slot_show(struct kobject *kobj,
87 struct kobj_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080089 return sprintf(buf, "0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080092static struct kobj_attribute add_slot_attr =
93 __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080095static struct kobj_attribute remove_slot_attr =
96 __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98static struct attribute *default_attrs[] = {
99 &add_slot_attr.attr,
100 &remove_slot_attr.attr,
101 NULL,
102};
103
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800104static struct attribute_group dlpar_attr_group = {
105 .attrs = default_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106};
107
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800108static struct kobject *dlpar_kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110int dlpar_sysfs_init(void)
111{
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800112 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800114 dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
115 &pci_hotplug_slots_kset->kobj);
116 if (!dlpar_kobj)
117 return -EINVAL;
118
119 error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
120 if (error)
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -0800121 kobject_put(dlpar_kobj);
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800122 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
125void dlpar_sysfs_exit(void)
126{
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800127 sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -0800128 kobject_put(dlpar_kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}