mdev_sysfs.c (f2fbc72e6da4f8e01fe5fe3d6871a791e76271c3) mdev_sysfs.c (685a1537f4c603cfcaf4b9be56ff6a571f7ddd08)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * File attributes for Mediated devices
4 *
5 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
6 * Author: Neo Jia <cjia@nvidia.com>
7 * Kirti Wankhede <kwankhede@nvidia.com>
8 */
9
10#include <linux/sysfs.h>
11#include <linux/ctype.h>
12#include <linux/slab.h>
13#include <linux/mdev.h>
14
15#include "mdev_private.h"
16
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * File attributes for Mediated devices
4 *
5 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
6 * Author: Neo Jia <cjia@nvidia.com>
7 * Kirti Wankhede <kwankhede@nvidia.com>
8 */
9
10#include <linux/sysfs.h>
11#include <linux/ctype.h>
12#include <linux/slab.h>
13#include <linux/mdev.h>
14
15#include "mdev_private.h"
16
17/* Static functions */
17struct mdev_type_attribute {
18 struct attribute attr;
19 ssize_t (*show)(struct mdev_type *mtype,
20 struct mdev_type_attribute *attr, char *buf);
21 ssize_t (*store)(struct mdev_type *mtype,
22 struct mdev_type_attribute *attr, const char *buf,
23 size_t count);
24};
18
25
26#define MDEV_TYPE_ATTR_RO(_name) \
27 struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name)
28#define MDEV_TYPE_ATTR_WO(_name) \
29 struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name)
30
19static ssize_t mdev_type_attr_show(struct kobject *kobj,
20 struct attribute *__attr, char *buf)
21{
22 struct mdev_type_attribute *attr = to_mdev_type_attr(__attr);
23 struct mdev_type *type = to_mdev_type(kobj);
24 ssize_t ret = -EIO;
25
26 if (attr->show)

--- 68 unchanged lines hidden (view full) ---

95 char *buf)
96{
97 struct mdev_driver *drv = mtype->parent->mdev_driver;
98
99 return sysfs_emit(buf, "%u\n", drv->get_available(mtype));
100}
101static MDEV_TYPE_ATTR_RO(available_instances);
102
31static ssize_t mdev_type_attr_show(struct kobject *kobj,
32 struct attribute *__attr, char *buf)
33{
34 struct mdev_type_attribute *attr = to_mdev_type_attr(__attr);
35 struct mdev_type *type = to_mdev_type(kobj);
36 ssize_t ret = -EIO;
37
38 if (attr->show)

--- 68 unchanged lines hidden (view full) ---

107 char *buf)
108{
109 struct mdev_driver *drv = mtype->parent->mdev_driver;
110
111 return sysfs_emit(buf, "%u\n", drv->get_available(mtype));
112}
113static MDEV_TYPE_ATTR_RO(available_instances);
114
115static ssize_t description_show(struct mdev_type *mtype,
116 struct mdev_type_attribute *attr,
117 char *buf)
118{
119 return mtype->parent->mdev_driver->show_description(mtype, buf);
120}
121static MDEV_TYPE_ATTR_RO(description);
122
103static struct attribute *mdev_types_core_attrs[] = {
104 &mdev_type_attr_create.attr,
105 &mdev_type_attr_device_api.attr,
106 &mdev_type_attr_name.attr,
107 &mdev_type_attr_available_instances.attr,
123static struct attribute *mdev_types_core_attrs[] = {
124 &mdev_type_attr_create.attr,
125 &mdev_type_attr_device_api.attr,
126 &mdev_type_attr_name.attr,
127 &mdev_type_attr_available_instances.attr,
128 &mdev_type_attr_description.attr,
108 NULL,
109};
110
129 NULL,
130};
131
132static umode_t mdev_types_core_is_visible(struct kobject *kobj,
133 struct attribute *attr, int n)
134{
135 if (attr == &mdev_type_attr_description.attr &&
136 !to_mdev_type(kobj)->parent->mdev_driver->show_description)
137 return 0;
138 return attr->mode;
139}
140
111static struct attribute_group mdev_type_core_group = {
112 .attrs = mdev_types_core_attrs,
141static struct attribute_group mdev_type_core_group = {
142 .attrs = mdev_types_core_attrs,
143 .is_visible = mdev_types_core_is_visible,
113};
114
115static const struct attribute_group *mdev_type_groups[] = {
116 &mdev_type_core_group,
117 NULL,
118};
119
120static void mdev_type_release(struct kobject *kobj)

--- 29 unchanged lines hidden (view full) ---

150 }
151
152 type->devices_kobj = kobject_create_and_add("devices", &type->kobj);
153 if (!type->devices_kobj) {
154 ret = -ENOMEM;
155 goto attr_devices_failed;
156 }
157
144};
145
146static const struct attribute_group *mdev_type_groups[] = {
147 &mdev_type_core_group,
148 NULL,
149};
150
151static void mdev_type_release(struct kobject *kobj)

--- 29 unchanged lines hidden (view full) ---

181 }
182
183 type->devices_kobj = kobject_create_and_add("devices", &type->kobj);
184 if (!type->devices_kobj) {
185 ret = -ENOMEM;
186 goto attr_devices_failed;
187 }
188
158 ret = sysfs_create_files(&type->kobj, parent->mdev_driver->types_attrs);
159 if (ret)
160 goto attrs_failed;
161 return 0;
162
189 return 0;
190
163attrs_failed:
164 kobject_put(type->devices_kobj);
165attr_devices_failed:
166 kobject_del(&type->kobj);
167 kobject_put(&type->kobj);
168 return ret;
169}
170
171static void mdev_type_remove(struct mdev_type *type)
172{
191attr_devices_failed:
192 kobject_del(&type->kobj);
193 kobject_put(&type->kobj);
194 return ret;
195}
196
197static void mdev_type_remove(struct mdev_type *type)
198{
173 sysfs_remove_files(&type->kobj, type->parent->mdev_driver->types_attrs);
174
175 kobject_put(type->devices_kobj);
176 kobject_del(&type->kobj);
177 kobject_put(&type->kobj);
178}
179
180/* mdev sysfs functions */
181void parent_remove_sysfs_files(struct mdev_parent *parent)
182{

--- 92 unchanged lines hidden ---
199 kobject_put(type->devices_kobj);
200 kobject_del(&type->kobj);
201 kobject_put(&type->kobj);
202}
203
204/* mdev sysfs functions */
205void parent_remove_sysfs_files(struct mdev_parent *parent)
206{

--- 92 unchanged lines hidden ---