]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - include/linux/mdev.h
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.
17 struct parent_device
{
19 const struct parent_ops
*ops
;
24 struct list_head next
;
25 struct kset
*mdev_types_kset
;
26 struct list_head type_list
;
32 struct parent_device
*parent
;
38 struct list_head next
;
39 struct kobject
*type_kobj
;
43 * struct parent_ops - Structure to be registered for each parent device to
44 * register the device to mdev module.
46 * @owner: The module owner.
47 * @dev_attr_groups: Attributes of the parent device.
48 * @mdev_attr_groups: Attributes of the mediated device.
49 * @supported_type_groups: Attributes to define supported types. It is mandatory
50 * to provide supported types.
51 * @create: Called to allocate basic resources in parent device's
52 * driver for a particular mediated device. It is
53 * mandatory to provide create ops.
54 * @kobj: kobject of type for which 'create' is called.
55 * @mdev: mdev_device structure on of mediated device
56 * that is being created
57 * Returns integer: success (0) or error (< 0)
58 * @remove: Called to free resources in parent device's driver for a
59 * a mediated device. It is mandatory to provide 'remove'
61 * @mdev: mdev_device device structure which is being
63 * Returns integer: success (0) or error (< 0)
64 * @open: Open mediated device.
65 * @mdev: mediated device.
66 * Returns integer: success (0) or error (< 0)
67 * @release: release mediated device
68 * @mdev: mediated device.
69 * @read: Read emulation callback
70 * @mdev: mediated device structure
72 * @count: number of bytes to read
74 * Retuns number on bytes read on success or error.
75 * @write: Write emulation callback
76 * @mdev: mediated device structure
78 * @count: number of bytes to be written
80 * Retuns number on bytes written on success or error.
81 * @ioctl: IOCTL callback
82 * @mdev: mediated device structure
84 * @arg: arguments to ioctl
85 * @mmap: mmap callback
86 * @mdev: mediated device structure
88 * Parent device that support mediated device should be registered with mdev
89 * module with parent_ops structure.
94 const struct attribute_group
**dev_attr_groups
;
95 const struct attribute_group
**mdev_attr_groups
;
96 struct attribute_group
**supported_type_groups
;
98 int (*create
)(struct kobject
*kobj
, struct mdev_device
*mdev
);
99 int (*remove
)(struct mdev_device
*mdev
);
100 int (*open
)(struct mdev_device
*mdev
);
101 void (*release
)(struct mdev_device
*mdev
);
102 ssize_t (*read
)(struct mdev_device
*mdev
, char __user
*buf
,
103 size_t count
, loff_t
*ppos
);
104 ssize_t (*write
)(struct mdev_device
*mdev
, const char __user
*buf
,
105 size_t count
, loff_t
*ppos
);
106 ssize_t (*ioctl
)(struct mdev_device
*mdev
, unsigned int cmd
,
108 int (*mmap
)(struct mdev_device
*mdev
, struct vm_area_struct
*vma
);
111 /* interface for exporting mdev supported type attributes */
112 struct mdev_type_attribute
{
113 struct attribute attr
;
114 ssize_t (*show
)(struct kobject
*kobj
, struct device
*dev
, char *buf
);
115 ssize_t (*store
)(struct kobject
*kobj
, struct device
*dev
,
116 const char *buf
, size_t count
);
119 #define MDEV_TYPE_ATTR(_name, _mode, _show, _store) \
120 struct mdev_type_attribute mdev_type_attr_##_name = \
121 __ATTR(_name, _mode, _show, _store)
122 #define MDEV_TYPE_ATTR_RW(_name) \
123 struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name)
124 #define MDEV_TYPE_ATTR_RO(_name) \
125 struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name)
126 #define MDEV_TYPE_ATTR_WO(_name) \
127 struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name)
130 * struct mdev_driver - Mediated device driver
132 * @probe: called when new device created
133 * @remove: called when device removed
134 * @driver: device driver structure
139 int (*probe
)(struct device
*dev
);
140 void (*remove
)(struct device
*dev
);
141 struct device_driver driver
;
144 #define to_mdev_driver(drv) container_of(drv, struct mdev_driver, driver)
145 #define to_mdev_device(dev) container_of(dev, struct mdev_device, dev)
147 static inline void *mdev_get_drvdata(struct mdev_device
*mdev
)
149 return mdev
->driver_data
;
152 static inline void mdev_set_drvdata(struct mdev_device
*mdev
, void *data
)
154 mdev
->driver_data
= data
;
157 extern struct bus_type mdev_bus_type
;
159 #define dev_is_mdev(d) ((d)->bus == &mdev_bus_type)
161 extern int mdev_register_device(struct device
*dev
,
162 const struct parent_ops
*ops
);
163 extern void mdev_unregister_device(struct device
*dev
);
165 extern int mdev_register_driver(struct mdev_driver
*drv
, struct module
*owner
);
166 extern void mdev_unregister_driver(struct mdev_driver
*drv
);