Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / pci / hotplug / rpadlpar_sysfs.c
blob068b7810a5746ba06d00d7e2c532dc590ac24c72
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Interface for Dynamic Logical Partitioning of I/O Slots on
4 * RPA-compliant PPC64 platform.
6 * John Rose <johnrose@austin.ibm.com>
7 * October 2003
9 * Copyright (C) 2003 IBM.
11 #include <linux/kobject.h>
12 #include <linux/string.h>
13 #include <linux/pci.h>
14 #include <linux/pci_hotplug.h>
15 #include "rpaphp.h"
16 #include "rpadlpar.h"
17 #include "../pci.h"
19 #define DLPAR_KOBJ_NAME "control"
21 /* Those two have no quotes because they are passed to __ATTR() which
22 * stringifies the argument (yuck !)
24 #define ADD_SLOT_ATTR_NAME add_slot
25 #define REMOVE_SLOT_ATTR_NAME remove_slot
27 static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
28 const char *buf, size_t nbytes)
30 char drc_name[MAX_DRC_NAME_LEN];
31 char *end;
32 int rc;
34 if (nbytes >= MAX_DRC_NAME_LEN)
35 return 0;
37 strscpy(drc_name, buf, nbytes + 1);
39 end = strchr(drc_name, '\n');
40 if (end)
41 *end = '\0';
43 rc = dlpar_add_slot(drc_name);
44 if (rc)
45 return rc;
47 return nbytes;
50 static ssize_t add_slot_show(struct kobject *kobj,
51 struct kobj_attribute *attr, char *buf)
53 return sysfs_emit(buf, "0\n");
56 static ssize_t remove_slot_store(struct kobject *kobj,
57 struct kobj_attribute *attr,
58 const char *buf, size_t nbytes)
60 char drc_name[MAX_DRC_NAME_LEN];
61 int rc;
62 char *end;
64 if (nbytes >= MAX_DRC_NAME_LEN)
65 return 0;
67 strscpy(drc_name, buf, nbytes + 1);
69 end = strchr(drc_name, '\n');
70 if (end)
71 *end = '\0';
73 rc = dlpar_remove_slot(drc_name);
74 if (rc)
75 return rc;
77 return nbytes;
80 static ssize_t remove_slot_show(struct kobject *kobj,
81 struct kobj_attribute *attr, char *buf)
83 return sysfs_emit(buf, "0\n");
86 static struct kobj_attribute add_slot_attr =
87 __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
89 static struct kobj_attribute remove_slot_attr =
90 __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
92 static struct attribute *default_attrs[] = {
93 &add_slot_attr.attr,
94 &remove_slot_attr.attr,
95 NULL,
98 static const struct attribute_group dlpar_attr_group = {
99 .attrs = default_attrs,
102 static struct kobject *dlpar_kobj;
104 int dlpar_sysfs_init(void)
106 int error;
108 dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
109 &pci_slots_kset->kobj);
110 if (!dlpar_kobj)
111 return -EINVAL;
113 error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
114 if (error)
115 kobject_put(dlpar_kobj);
116 return error;
119 void dlpar_sysfs_exit(void)
121 sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
122 kobject_put(dlpar_kobj);