blob: a796301ea03fbd3709f15be52f78053bb12380f9 [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>
Alex Chiangf46753c2008-06-10 15:28:50 -060017#include <linux/pci.h>
Greg Kroah-Hartman7a54f252006-10-13 20:05:19 -070018#include <linux/pci_hotplug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include "rpadlpar.h"
Alex Chiangf46753c2008-06-10 15:28:50 -060020#include "../pci.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#define DLPAR_KOBJ_NAME "control"
Benjamin Herrenschmidta9b841e2008-05-30 13:39:12 +100023
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#define MAX_DRC_NAME_LEN 64
31
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080032static 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080039 if (nbytes >= MAX_DRC_NAME_LEN)
40 return 0;
41
42 memcpy(drc_name, buf, nbytes);
43
44 end = strchr(drc_name, '\n');
45 if (!end)
46 end = &drc_name[nbytes];
47 *end = '\0';
48
49 rc = dlpar_add_slot(drc_name);
50 if (rc)
51 return rc;
52
53 return nbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080056static ssize_t add_slot_show(struct kobject *kobj,
57 struct kobj_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080059 return sprintf(buf, "0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080062static ssize_t remove_slot_store(struct kobject *kobj,
63 struct kobj_attribute *attr,
64 const char *buf, size_t nbytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
66 char drc_name[MAX_DRC_NAME_LEN];
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080067 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 char *end;
69
Linda Xie02fe75a2005-09-22 00:48:24 -070070 if (nbytes >= MAX_DRC_NAME_LEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 return 0;
72
73 memcpy(drc_name, buf, nbytes);
74
75 end = strchr(drc_name, '\n');
76 if (!end)
77 end = &drc_name[nbytes];
78 *end = '\0';
79
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080080 rc = dlpar_remove_slot(drc_name);
81 if (rc)
82 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 return nbytes;
85}
86
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080087static ssize_t remove_slot_show(struct kobject *kobj,
88 struct kobj_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080090 return sprintf(buf, "0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
92
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080093static struct kobj_attribute add_slot_attr =
94 __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080096static struct kobj_attribute remove_slot_attr =
97 __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99static struct attribute *default_attrs[] = {
100 &add_slot_attr.attr,
101 &remove_slot_attr.attr,
102 NULL,
103};
104
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800105static struct attribute_group dlpar_attr_group = {
106 .attrs = default_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107};
108
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800109static struct kobject *dlpar_kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111int dlpar_sysfs_init(void)
112{
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800113 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800115 dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
Alex Chiangf46753c2008-06-10 15:28:50 -0600116 &pci_slots_kset->kobj);
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800117 if (!dlpar_kobj)
118 return -EINVAL;
119
120 error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
121 if (error)
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -0800122 kobject_put(dlpar_kobj);
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800123 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
126void dlpar_sysfs_exit(void)
127{
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800128 sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -0800129 kobject_put(dlpar_kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}