1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Mediated device definition
5 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
18 struct list_head next;
19 struct mdev_type *type;
23 static inline struct mdev_device *to_mdev_device(struct device *dev)
25 return container_of(dev, struct mdev_device, dev);
28 unsigned int mdev_get_type_group_id(struct mdev_device *mdev);
29 unsigned int mtype_get_type_group_id(struct mdev_type *mtype);
30 struct device *mtype_get_parent_dev(struct mdev_type *mtype);
32 /* interface for exporting mdev supported type attributes */
33 struct mdev_type_attribute {
34 struct attribute attr;
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,
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)
53 * struct mdev_driver - Mediated device driver
54 * @probe: called when new device created
55 * @remove: called when device removed
56 * @supported_type_groups: Attributes to define supported types. It is mandatory
57 * to provide supported types.
58 * @driver: device driver structure
62 int (*probe)(struct mdev_device *dev);
63 void (*remove)(struct mdev_device *dev);
64 struct attribute_group **supported_type_groups;
65 struct device_driver driver;
68 extern struct bus_type mdev_bus_type;
70 int mdev_register_device(struct device *dev, struct mdev_driver *mdev_driver);
71 void mdev_unregister_device(struct device *dev);
73 int mdev_register_driver(struct mdev_driver *drv);
74 void mdev_unregister_driver(struct mdev_driver *drv);
76 struct device *mdev_parent_dev(struct mdev_device *mdev);
77 static inline struct device *mdev_dev(struct mdev_device *mdev)
81 static inline struct mdev_device *mdev_from_dev(struct device *dev)
83 return dev->bus == &mdev_bus_type ? to_mdev_device(dev) : NULL;