2 * Mediated device definition
4 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
5 * Author: Neo Jia <cjia@nvidia.com>
6 * Kirti Wankhede <kwankhede@nvidia.com>
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.
19 * struct mdev_parent_ops - Structure to be registered for each parent device to
20 * register the device to mdev module.
22 * @owner: The module owner.
23 * @dev_attr_groups: Attributes of the parent device.
24 * @mdev_attr_groups: Attributes of the mediated device.
25 * @supported_type_groups: Attributes to define supported types. It is mandatory
26 * to provide supported types.
27 * @create: Called to allocate basic resources in parent device's
28 * driver for a particular mediated device. It is
29 * mandatory to provide create ops.
30 * @kobj: kobject of type for which 'create' is called.
31 * @mdev: mdev_device structure on of mediated device
32 * that is being created
33 * Returns integer: success (0) or error (< 0)
34 * @remove: Called to free resources in parent device's driver for a
35 * a mediated device. It is mandatory to provide 'remove'
37 * @mdev: mdev_device device structure which is being
39 * Returns integer: success (0) or error (< 0)
40 * @open: Open mediated device.
41 * @mdev: mediated device.
42 * Returns integer: success (0) or error (< 0)
43 * @release: release mediated device
44 * @mdev: mediated device.
45 * @read: Read emulation callback
46 * @mdev: mediated device structure
48 * @count: number of bytes to read
50 * Retuns number on bytes read on success or error.
51 * @write: Write emulation callback
52 * @mdev: mediated device structure
54 * @count: number of bytes to be written
56 * Retuns number on bytes written on success or error.
57 * @ioctl: IOCTL callback
58 * @mdev: mediated device structure
60 * @arg: arguments to ioctl
61 * @mmap: mmap callback
62 * @mdev: mediated device structure
64 * Parent device that support mediated device should be registered with mdev
65 * module with mdev_parent_ops structure.
67 struct mdev_parent_ops
{
69 const struct attribute_group
**dev_attr_groups
;
70 const struct attribute_group
**mdev_attr_groups
;
71 struct attribute_group
**supported_type_groups
;
73 int (*create
)(struct kobject
*kobj
, struct mdev_device
*mdev
);
74 int (*remove
)(struct mdev_device
*mdev
);
75 int (*open
)(struct mdev_device
*mdev
);
76 void (*release
)(struct mdev_device
*mdev
);
77 ssize_t (*read
)(struct mdev_device
*mdev
, char __user
*buf
,
78 size_t count
, loff_t
*ppos
);
79 ssize_t (*write
)(struct mdev_device
*mdev
, const char __user
*buf
,
80 size_t count
, loff_t
*ppos
);
81 long (*ioctl
)(struct mdev_device
*mdev
, unsigned int cmd
,
83 int (*mmap
)(struct mdev_device
*mdev
, struct vm_area_struct
*vma
);
86 /* interface for exporting mdev supported type attributes */
87 struct mdev_type_attribute
{
88 struct attribute attr
;
89 ssize_t (*show
)(struct kobject
*kobj
, struct device
*dev
, char *buf
);
90 ssize_t (*store
)(struct kobject
*kobj
, struct device
*dev
,
91 const char *buf
, size_t count
);
94 #define MDEV_TYPE_ATTR(_name, _mode, _show, _store) \
95 struct mdev_type_attribute mdev_type_attr_##_name = \
96 __ATTR(_name, _mode, _show, _store)
97 #define MDEV_TYPE_ATTR_RW(_name) \
98 struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name)
99 #define MDEV_TYPE_ATTR_RO(_name) \
100 struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name)
101 #define MDEV_TYPE_ATTR_WO(_name) \
102 struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name)
105 * struct mdev_driver - Mediated device driver
107 * @probe: called when new device created
108 * @remove: called when device removed
109 * @driver: device driver structure
114 int (*probe
)(struct device
*dev
);
115 void (*remove
)(struct device
*dev
);
116 struct device_driver driver
;
119 #define to_mdev_driver(drv) container_of(drv, struct mdev_driver, driver)
121 extern void *mdev_get_drvdata(struct mdev_device
*mdev
);
122 extern void mdev_set_drvdata(struct mdev_device
*mdev
, void *data
);
123 extern uuid_le
mdev_uuid(struct mdev_device
*mdev
);
125 extern struct bus_type mdev_bus_type
;
127 extern int mdev_register_device(struct device
*dev
,
128 const struct mdev_parent_ops
*ops
);
129 extern void mdev_unregister_device(struct device
*dev
);
131 extern int mdev_register_driver(struct mdev_driver
*drv
, struct module
*owner
);
132 extern void mdev_unregister_driver(struct mdev_driver
*drv
);
134 extern struct device
*mdev_parent_dev(struct mdev_device
*mdev
);
135 extern struct device
*mdev_dev(struct mdev_device
*mdev
);
136 extern struct mdev_device
*mdev_from_dev(struct device
*dev
);