blob: cdbfa5df3a51f3d629179bf83f830cf7f4f1095b [file] [log] [blame]
Bjorn Helgaas736759e2018-01-26 14:22:04 -06001// SPDX-License-Identifier: GPL-2.0+
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Interface for Dynamic Logical Partitioning of I/O Slots on
4 * RPA-compliant PPC64 platform.
5 *
6 * John Rose <johnrose@austin.ibm.com>
7 * October 2003
8 *
9 * Copyright (C) 2003 IBM.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11#include <linux/kobject.h>
12#include <linux/string.h>
Alex Chiangf46753c2008-06-10 15:28:50 -060013#include <linux/pci.h>
Greg Kroah-Hartman7a54f252006-10-13 20:05:19 -070014#include <linux/pci_hotplug.h>
Michael Bringmann2fcf3ae2017-12-01 17:19:48 -060015#include "rpaphp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include "rpadlpar.h"
Alex Chiangf46753c2008-06-10 15:28:50 -060017#include "../pci.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#define DLPAR_KOBJ_NAME "control"
Benjamin Herrenschmidta9b841e2008-05-30 13:39:12 +100020
21/* Those two have no quotes because they are passed to __ATTR() which
22 * stringifies the argument (yuck !)
23 */
24#define ADD_SLOT_ATTR_NAME add_slot
25#define REMOVE_SLOT_ATTR_NAME remove_slot
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080027static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
28 const char *buf, size_t nbytes)
29{
30 char drc_name[MAX_DRC_NAME_LEN];
31 char *end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080034 if (nbytes >= MAX_DRC_NAME_LEN)
35 return 0;
36
37 memcpy(drc_name, buf, nbytes);
38
39 end = strchr(drc_name, '\n');
40 if (!end)
41 end = &drc_name[nbytes];
42 *end = '\0';
43
44 rc = dlpar_add_slot(drc_name);
45 if (rc)
46 return rc;
47
48 return nbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080051static ssize_t add_slot_show(struct kobject *kobj,
52 struct kobj_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080054 return sprintf(buf, "0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080057static ssize_t remove_slot_store(struct kobject *kobj,
58 struct kobj_attribute *attr,
59 const char *buf, size_t nbytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 char drc_name[MAX_DRC_NAME_LEN];
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080062 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 char *end;
64
Linda Xie02fe75a2005-09-22 00:48:24 -070065 if (nbytes >= MAX_DRC_NAME_LEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 return 0;
67
68 memcpy(drc_name, buf, nbytes);
69
70 end = strchr(drc_name, '\n');
71 if (!end)
72 end = &drc_name[nbytes];
73 *end = '\0';
74
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080075 rc = dlpar_remove_slot(drc_name);
76 if (rc)
77 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79 return nbytes;
80}
81
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080082static ssize_t remove_slot_show(struct kobject *kobj,
83 struct kobj_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080085 return sprintf(buf, "0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080088static struct kobj_attribute add_slot_attr =
89 __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -080091static struct kobj_attribute remove_slot_attr =
92 __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94static struct attribute *default_attrs[] = {
95 &add_slot_attr.attr,
96 &remove_slot_attr.attr,
97 NULL,
98};
99
Arvind Yadav4bd32562017-07-11 14:58:44 +0530100static const struct attribute_group dlpar_attr_group = {
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800101 .attrs = default_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102};
103
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800104static struct kobject *dlpar_kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106int dlpar_sysfs_init(void)
107{
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800108 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800110 dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
Alex Chiangf46753c2008-06-10 15:28:50 -0600111 &pci_slots_kset->kobj);
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800112 if (!dlpar_kobj)
113 return -EINVAL;
114
115 error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
116 if (error)
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -0800117 kobject_put(dlpar_kobj);
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800118 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
120
121void dlpar_sysfs_exit(void)
122{
Greg Kroah-Hartmanf55842f2007-11-06 15:03:30 -0800123 sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -0800124 kobject_put(dlpar_kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125}