blob: 7d922950caaf3c1f5269556a8a913d42d6144710 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-only */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Mediated device interal definitions
4 *
5 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
6 * Author: Neo Jia <cjia@nvidia.com>
7 * Kirti Wankhede <kwankhede@nvidia.com>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00008 */
9
10#ifndef MDEV_PRIVATE_H
11#define MDEV_PRIVATE_H
12
13int mdev_bus_register(void);
14void mdev_bus_unregister(void);
15
16struct mdev_parent {
17 struct device *dev;
18 const struct mdev_parent_ops *ops;
19 struct kref ref;
20 struct list_head next;
21 struct kset *mdev_types_kset;
22 struct list_head type_list;
David Brazdil0f672f62019-12-10 10:32:29 +000023 /* Synchronize device creation/removal with parent unregistration */
24 struct rw_semaphore unreg_sem;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000025};
26
27struct mdev_device {
28 struct device dev;
29 struct mdev_parent *parent;
David Brazdil0f672f62019-12-10 10:32:29 +000030 guid_t uuid;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000031 void *driver_data;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000032 struct list_head next;
33 struct kobject *type_kobj;
David Brazdil0f672f62019-12-10 10:32:29 +000034 struct device *iommu_device;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000035 bool active;
36};
37
38#define to_mdev_device(dev) container_of(dev, struct mdev_device, dev)
39#define dev_is_mdev(d) ((d)->bus == &mdev_bus_type)
40
41struct mdev_type {
42 struct kobject kobj;
43 struct kobject *devices_kobj;
44 struct mdev_parent *parent;
45 struct list_head next;
46 struct attribute_group *group;
47};
48
49#define to_mdev_type_attr(_attr) \
50 container_of(_attr, struct mdev_type_attribute, attr)
51#define to_mdev_type(_kobj) \
52 container_of(_kobj, struct mdev_type, kobj)
53
54int parent_create_sysfs_files(struct mdev_parent *parent);
55void parent_remove_sysfs_files(struct mdev_parent *parent);
56
57int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type);
58void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type);
59
David Brazdil0f672f62019-12-10 10:32:29 +000060int mdev_device_create(struct kobject *kobj,
61 struct device *dev, const guid_t *uuid);
62int mdev_device_remove(struct device *dev);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000063
64#endif /* MDEV_PRIVATE_H */