blob: 39876752627679149180e19492893a24109f5597 [file] [log] [blame]
Kirti Wankhede7b969532016-11-17 02:16:13 +05301/*
2 * Mediated device interal definitions
3 *
4 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
5 * Author: Neo Jia <cjia@nvidia.com>
6 * Kirti Wankhede <kwankhede@nvidia.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#ifndef MDEV_PRIVATE_H
14#define MDEV_PRIVATE_H
15
16int mdev_bus_register(void);
17void mdev_bus_unregister(void);
18
Alex Williamson9372e6fe2016-12-30 08:13:41 -070019struct mdev_parent {
20 struct device *dev;
21 const struct mdev_parent_ops *ops;
22 struct kref ref;
Alex Williamson9372e6fe2016-12-30 08:13:41 -070023 struct list_head next;
24 struct kset *mdev_types_kset;
25 struct list_head type_list;
Parav Pandit5715c4dd2019-06-06 10:52:33 -060026 /* Synchronize device creation/removal with parent unregistration */
27 struct rw_semaphore unreg_sem;
Alex Williamson9372e6fe2016-12-30 08:13:41 -070028};
29
Alex Williamson99e31232016-12-30 08:13:44 -070030struct mdev_device {
31 struct device dev;
32 struct mdev_parent *parent;
Andy Shevchenko278bca72019-01-10 21:00:27 +020033 guid_t uuid;
Alex Williamson99e31232016-12-30 08:13:44 -070034 void *driver_data;
Alex Williamson99e31232016-12-30 08:13:44 -070035 struct list_head next;
36 struct kobject *type_kobj;
Lu Baolu8ac13172019-04-12 12:13:24 +080037 struct device *iommu_device;
Alex Williamson002fe992018-05-15 13:53:55 -060038 bool active;
Alex Williamson99e31232016-12-30 08:13:44 -070039};
40
41#define to_mdev_device(dev) container_of(dev, struct mdev_device, dev)
42#define dev_is_mdev(d) ((d)->bus == &mdev_bus_type)
43
Kirti Wankhede7b969532016-11-17 02:16:13 +053044struct mdev_type {
45 struct kobject kobj;
46 struct kobject *devices_kobj;
Alex Williamson42930552016-12-30 08:13:38 -070047 struct mdev_parent *parent;
Kirti Wankhede7b969532016-11-17 02:16:13 +053048 struct list_head next;
49 struct attribute_group *group;
50};
51
52#define to_mdev_type_attr(_attr) \
53 container_of(_attr, struct mdev_type_attribute, attr)
54#define to_mdev_type(_kobj) \
55 container_of(_kobj, struct mdev_type, kobj)
56
Alex Williamson42930552016-12-30 08:13:38 -070057int parent_create_sysfs_files(struct mdev_parent *parent);
58void parent_remove_sysfs_files(struct mdev_parent *parent);
Kirti Wankhede7b969532016-11-17 02:16:13 +053059
60int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type);
61void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type);
62
Andy Shevchenko278bca72019-01-10 21:00:27 +020063int mdev_device_create(struct kobject *kobj,
64 struct device *dev, const guid_t *uuid);
Parav Pandit522ecce2019-06-06 10:52:32 -060065int mdev_device_remove(struct device *dev);
Kirti Wankhede7b969532016-11-17 02:16:13 +053066
67#endif /* MDEV_PRIVATE_H */