Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  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.
 
 
 
 
 
 10 */
 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"
 18
 19#define DLPAR_KOBJ_NAME       "control"
 20
 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
 26
 
 
 27static 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;
 32	int rc;
 33
 34	if (nbytes >= MAX_DRC_NAME_LEN)
 35		return 0;
 36
 37	strscpy(drc_name, buf, nbytes + 1);
 38
 39	end = strchr(drc_name, '\n');
 40	if (end)
 41		*end = '\0';
 
 42
 43	rc = dlpar_add_slot(drc_name);
 44	if (rc)
 45		return rc;
 46
 47	return nbytes;
 48}
 49
 50static ssize_t add_slot_show(struct kobject *kobj,
 51			     struct kobj_attribute *attr, char *buf)
 52{
 53	return sysfs_emit(buf, "0\n");
 54}
 55
 56static ssize_t remove_slot_store(struct kobject *kobj,
 57				 struct kobj_attribute *attr,
 58				 const char *buf, size_t nbytes)
 59{
 60	char drc_name[MAX_DRC_NAME_LEN];
 61	int rc;
 62	char *end;
 63
 64	if (nbytes >= MAX_DRC_NAME_LEN)
 65		return 0;
 66
 67	strscpy(drc_name, buf, nbytes + 1);
 68
 69	end = strchr(drc_name, '\n');
 70	if (end)
 71		*end = '\0';
 
 72
 73	rc = dlpar_remove_slot(drc_name);
 74	if (rc)
 75		return rc;
 76
 77	return nbytes;
 78}
 79
 80static ssize_t remove_slot_show(struct kobject *kobj,
 81				struct kobj_attribute *attr, char *buf)
 82{
 83	return sysfs_emit(buf, "0\n");
 84}
 85
 86static struct kobj_attribute add_slot_attr =
 87	__ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
 88
 89static struct kobj_attribute remove_slot_attr =
 90	__ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
 91
 92static struct attribute *default_attrs[] = {
 93	&add_slot_attr.attr,
 94	&remove_slot_attr.attr,
 95	NULL,
 96};
 97
 98static const struct attribute_group dlpar_attr_group = {
 99	.attrs = default_attrs,
100};
101
102static struct kobject *dlpar_kobj;
103
104int dlpar_sysfs_init(void)
105{
106	int error;
107
108	dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
109					    &pci_slots_kset->kobj);
110	if (!dlpar_kobj)
111		return -EINVAL;
112
113	error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
114	if (error)
115		kobject_put(dlpar_kobj);
116	return error;
117}
118
119void dlpar_sysfs_exit(void)
120{
121	sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
122	kobject_put(dlpar_kobj);
123}
v3.15
 
  1/*
  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>
 17#include <linux/pci.h>
 18#include <linux/pci_hotplug.h>
 
 19#include "rpadlpar.h"
 20#include "../pci.h"
 21
 22#define DLPAR_KOBJ_NAME       "control"
 23
 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
 29
 30#define MAX_DRC_NAME_LEN 64
 31
 32static 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;
 37	int rc;
 38
 39	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;
 54}
 55
 56static ssize_t add_slot_show(struct kobject *kobj,
 57			     struct kobj_attribute *attr, char *buf)
 58{
 59	return sprintf(buf, "0\n");
 60}
 61
 62static ssize_t remove_slot_store(struct kobject *kobj,
 63				 struct kobj_attribute *attr,
 64				 const char *buf, size_t nbytes)
 65{
 66	char drc_name[MAX_DRC_NAME_LEN];
 67	int rc;
 68	char *end;
 69
 70	if (nbytes >= MAX_DRC_NAME_LEN)
 71		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
 80	rc = dlpar_remove_slot(drc_name);
 81	if (rc)
 82		return rc;
 83
 84	return nbytes;
 85}
 86
 87static ssize_t remove_slot_show(struct kobject *kobj,
 88				struct kobj_attribute *attr, char *buf)
 89{
 90	return sprintf(buf, "0\n");
 91}
 92
 93static struct kobj_attribute add_slot_attr =
 94	__ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
 95
 96static struct kobj_attribute remove_slot_attr =
 97	__ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);
 98
 99static struct attribute *default_attrs[] = {
100	&add_slot_attr.attr,
101	&remove_slot_attr.attr,
102	NULL,
103};
104
105static struct attribute_group dlpar_attr_group = {
106	.attrs = default_attrs,
107};
108
109static struct kobject *dlpar_kobj;
110
111int dlpar_sysfs_init(void)
112{
113	int error;
114
115	dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
116					    &pci_slots_kset->kobj);
117	if (!dlpar_kobj)
118		return -EINVAL;
119
120	error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
121	if (error)
122		kobject_put(dlpar_kobj);
123	return error;
124}
125
126void dlpar_sysfs_exit(void)
127{
128	sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
129	kobject_put(dlpar_kobj);
130}