Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
7b96953b KW |
2 | /* |
3 | * Mediated device definition | |
4 | * | |
5 | * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. | |
6 | * Author: Neo Jia <cjia@nvidia.com> | |
7 | * Kirti Wankhede <kwankhede@nvidia.com> | |
7b96953b KW |
8 | */ |
9 | ||
10 | #ifndef MDEV_H | |
11 | #define MDEV_H | |
12 | ||
bdef2b78 CH |
13 | #include <linux/device.h> |
14 | #include <linux/uuid.h> | |
15 | ||
417fd5bf JG |
16 | struct mdev_type; |
17 | ||
2a3d15f2 JG |
18 | struct mdev_device { |
19 | struct device dev; | |
2a3d15f2 | 20 | guid_t uuid; |
2a3d15f2 | 21 | struct list_head next; |
417fd5bf | 22 | struct mdev_type *type; |
2a3d15f2 JG |
23 | bool active; |
24 | }; | |
25 | ||
89345d51 CH |
26 | /* embedded into the struct device that the mdev devices hang off */ |
27 | struct mdev_parent { | |
28 | struct device *dev; | |
29 | struct mdev_driver *mdev_driver; | |
30 | struct kset *mdev_types_kset; | |
31 | struct list_head type_list; | |
32 | /* Synchronize device creation/removal with parent unregistration */ | |
33 | struct rw_semaphore unreg_sem; | |
34 | }; | |
35 | ||
2a3d15f2 JG |
36 | static inline struct mdev_device *to_mdev_device(struct device *dev) |
37 | { | |
38 | return container_of(dev, struct mdev_device, dev); | |
39 | } | |
7b96953b | 40 | |
15fcc44b | 41 | unsigned int mdev_get_type_group_id(struct mdev_device *mdev); |
9169cff1 JG |
42 | unsigned int mtype_get_type_group_id(struct mdev_type *mtype); |
43 | struct device *mtype_get_parent_dev(struct mdev_type *mtype); | |
15fcc44b | 44 | |
7b96953b KW |
45 | /* interface for exporting mdev supported type attributes */ |
46 | struct mdev_type_attribute { | |
47 | struct attribute attr; | |
9169cff1 JG |
48 | ssize_t (*show)(struct mdev_type *mtype, |
49 | struct mdev_type_attribute *attr, char *buf); | |
50 | ssize_t (*store)(struct mdev_type *mtype, | |
51 | struct mdev_type_attribute *attr, const char *buf, | |
52 | size_t count); | |
7b96953b KW |
53 | }; |
54 | ||
55 | #define MDEV_TYPE_ATTR(_name, _mode, _show, _store) \ | |
56 | struct mdev_type_attribute mdev_type_attr_##_name = \ | |
57 | __ATTR(_name, _mode, _show, _store) | |
58 | #define MDEV_TYPE_ATTR_RW(_name) \ | |
59 | struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name) | |
60 | #define MDEV_TYPE_ATTR_RO(_name) \ | |
61 | struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name) | |
62 | #define MDEV_TYPE_ATTR_WO(_name) \ | |
63 | struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name) | |
64 | ||
65 | /** | |
66 | * struct mdev_driver - Mediated device driver | |
7b96953b KW |
67 | * @probe: called when new device created |
68 | * @remove: called when device removed | |
6b42f491 JG |
69 | * @supported_type_groups: Attributes to define supported types. It is mandatory |
70 | * to provide supported types. | |
7b96953b KW |
71 | * @driver: device driver structure |
72 | * | |
73 | **/ | |
74 | struct mdev_driver { | |
2a3d15f2 JG |
75 | int (*probe)(struct mdev_device *dev); |
76 | void (*remove)(struct mdev_device *dev); | |
6b42f491 | 77 | struct attribute_group **supported_type_groups; |
7b96953b KW |
78 | struct device_driver driver; |
79 | }; | |
80 | ||
7b96953b KW |
81 | extern struct bus_type mdev_bus_type; |
82 | ||
89345d51 CH |
83 | int mdev_register_parent(struct mdev_parent *parent, struct device *dev, |
84 | struct mdev_driver *mdev_driver); | |
85 | void mdev_unregister_parent(struct mdev_parent *parent); | |
7b96953b | 86 | |
91b9969d | 87 | int mdev_register_driver(struct mdev_driver *drv); |
50732af3 | 88 | void mdev_unregister_driver(struct mdev_driver *drv); |
7b96953b | 89 | |
50732af3 | 90 | struct device *mdev_parent_dev(struct mdev_device *mdev); |
2a3d15f2 JG |
91 | static inline struct device *mdev_dev(struct mdev_device *mdev) |
92 | { | |
93 | return &mdev->dev; | |
94 | } | |
95 | static inline struct mdev_device *mdev_from_dev(struct device *dev) | |
96 | { | |
97 | return dev->bus == &mdev_bus_type ? to_mdev_device(dev) : NULL; | |
98 | } | |
9372e6fe | 99 | |
7b96953b | 100 | #endif /* MDEV_H */ |