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 | ||
417fd5bf JG |
13 | struct mdev_type; |
14 | ||
2a3d15f2 JG |
15 | struct mdev_device { |
16 | struct device dev; | |
2a3d15f2 | 17 | guid_t uuid; |
2a3d15f2 | 18 | struct list_head next; |
417fd5bf | 19 | struct mdev_type *type; |
2a3d15f2 JG |
20 | bool active; |
21 | }; | |
22 | ||
23 | static inline struct mdev_device *to_mdev_device(struct device *dev) | |
24 | { | |
25 | return container_of(dev, struct mdev_device, dev); | |
26 | } | |
7b96953b | 27 | |
15fcc44b | 28 | unsigned int mdev_get_type_group_id(struct mdev_device *mdev); |
9169cff1 JG |
29 | unsigned int mtype_get_type_group_id(struct mdev_type *mtype); |
30 | struct device *mtype_get_parent_dev(struct mdev_type *mtype); | |
15fcc44b | 31 | |
7b96953b KW |
32 | /* interface for exporting mdev supported type attributes */ |
33 | struct mdev_type_attribute { | |
34 | struct attribute attr; | |
9169cff1 JG |
35 | ssize_t (*show)(struct mdev_type *mtype, |
36 | struct mdev_type_attribute *attr, char *buf); | |
37 | ssize_t (*store)(struct mdev_type *mtype, | |
38 | struct mdev_type_attribute *attr, const char *buf, | |
39 | size_t count); | |
7b96953b KW |
40 | }; |
41 | ||
42 | #define MDEV_TYPE_ATTR(_name, _mode, _show, _store) \ | |
43 | struct mdev_type_attribute mdev_type_attr_##_name = \ | |
44 | __ATTR(_name, _mode, _show, _store) | |
45 | #define MDEV_TYPE_ATTR_RW(_name) \ | |
46 | struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name) | |
47 | #define MDEV_TYPE_ATTR_RO(_name) \ | |
48 | struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name) | |
49 | #define MDEV_TYPE_ATTR_WO(_name) \ | |
50 | struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name) | |
51 | ||
52 | /** | |
53 | * struct mdev_driver - Mediated device driver | |
7b96953b KW |
54 | * @probe: called when new device created |
55 | * @remove: called when device removed | |
6b42f491 JG |
56 | * @supported_type_groups: Attributes to define supported types. It is mandatory |
57 | * to provide supported types. | |
7b96953b KW |
58 | * @driver: device driver structure |
59 | * | |
60 | **/ | |
61 | struct mdev_driver { | |
2a3d15f2 JG |
62 | int (*probe)(struct mdev_device *dev); |
63 | void (*remove)(struct mdev_device *dev); | |
6b42f491 | 64 | struct attribute_group **supported_type_groups; |
7b96953b KW |
65 | struct device_driver driver; |
66 | }; | |
67 | ||
2a3d15f2 JG |
68 | static inline const guid_t *mdev_uuid(struct mdev_device *mdev) |
69 | { | |
70 | return &mdev->uuid; | |
71 | } | |
7b96953b KW |
72 | |
73 | extern struct bus_type mdev_bus_type; | |
74 | ||
6b42f491 | 75 | int mdev_register_device(struct device *dev, struct mdev_driver *mdev_driver); |
50732af3 | 76 | void mdev_unregister_device(struct device *dev); |
7b96953b | 77 | |
91b9969d | 78 | int mdev_register_driver(struct mdev_driver *drv); |
50732af3 | 79 | void mdev_unregister_driver(struct mdev_driver *drv); |
7b96953b | 80 | |
50732af3 | 81 | struct device *mdev_parent_dev(struct mdev_device *mdev); |
2a3d15f2 JG |
82 | static inline struct device *mdev_dev(struct mdev_device *mdev) |
83 | { | |
84 | return &mdev->dev; | |
85 | } | |
86 | static inline struct mdev_device *mdev_from_dev(struct device *dev) | |
87 | { | |
88 | return dev->bus == &mdev_bus_type ? to_mdev_device(dev) : NULL; | |
89 | } | |
9372e6fe | 90 | |
7b96953b | 91 | #endif /* MDEV_H */ |