1 /* SPDX-License-Identifier: GPL-2.0-only */ << 2 /* 1 /* 3 * Mediated device definition 2 * Mediated device definition 4 * 3 * 5 * Copyright (c) 2016, NVIDIA CORPORATION. All 4 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 6 * Author: Neo Jia <cjia@nvidia.com> 5 * Author: Neo Jia <cjia@nvidia.com> 7 * Kirti Wankhede <kwankhede@nvidi 6 * Kirti Wankhede <kwankhede@nvidia.com> >> 7 * >> 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. 8 */ 11 */ 9 12 10 #ifndef MDEV_H 13 #ifndef MDEV_H 11 #define MDEV_H 14 #define MDEV_H 12 15 13 #include <linux/device.h> !! 16 struct mdev_device; 14 #include <linux/uuid.h> << 15 << 16 struct mdev_type; << 17 << 18 struct mdev_device { << 19 struct device dev; << 20 guid_t uuid; << 21 struct list_head next; << 22 struct mdev_type *type; << 23 bool active; << 24 }; << 25 17 26 struct mdev_type { !! 18 /** 27 /* set by the driver before calling md !! 19 * struct mdev_parent_ops - Structure to be registered for each parent device to 28 const char *sysfs_name; !! 20 * register the device to mdev module. 29 const char *pretty_name; !! 21 * 30 !! 22 * @owner: The module owner. 31 /* set by the core, can be used driver !! 23 * @dev_attr_groups: Attributes of the parent device. 32 struct mdev_parent *parent; !! 24 * @mdev_attr_groups: Attributes of the mediated device. 33 !! 25 * @supported_type_groups: Attributes to define supported types. It is mandatory 34 /* internal only */ !! 26 * to provide supported types. 35 struct kobject kobj; !! 27 * @create: Called to allocate basic resources in parent device's 36 struct kobject *devices_kobj; !! 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' >> 36 * ops. >> 37 * @mdev: mdev_device device structure which is being >> 38 * destroyed >> 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 >> 47 * @buf: read buffer >> 48 * @count: number of bytes to read >> 49 * @ppos: address. >> 50 * Retuns number on bytes read on success or error. >> 51 * @write: Write emulation callback >> 52 * @mdev: mediated device structure >> 53 * @buf: write buffer >> 54 * @count: number of bytes to be written >> 55 * @ppos: address. >> 56 * Retuns number on bytes written on success or error. >> 57 * @ioctl: IOCTL callback >> 58 * @mdev: mediated device structure >> 59 * @cmd: ioctl command >> 60 * @arg: arguments to ioctl >> 61 * @mmap: mmap callback >> 62 * @mdev: mediated device structure >> 63 * @vma: vma structure >> 64 * Parent device that support mediated device should be registered with mdev >> 65 * module with mdev_parent_ops structure. >> 66 **/ >> 67 struct mdev_parent_ops { >> 68 struct module *owner; >> 69 const struct attribute_group **dev_attr_groups; >> 70 const struct attribute_group **mdev_attr_groups; >> 71 struct attribute_group **supported_type_groups; >> 72 >> 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, >> 82 unsigned long arg); >> 83 int (*mmap)(struct mdev_device *mdev, struct vm_area_struct *vma); 37 }; 84 }; 38 85 39 /* embedded into the struct device that the md !! 86 /* interface for exporting mdev supported type attributes */ 40 struct mdev_parent { !! 87 struct mdev_type_attribute { 41 struct device *dev; !! 88 struct attribute attr; 42 struct mdev_driver *mdev_driver; !! 89 ssize_t (*show)(struct kobject *kobj, struct device *dev, char *buf); 43 struct kset *mdev_types_kset; !! 90 ssize_t (*store)(struct kobject *kobj, struct device *dev, 44 /* Synchronize device creation/removal !! 91 const char *buf, size_t count); 45 struct rw_semaphore unreg_sem; << 46 struct mdev_type **types; << 47 unsigned int nr_types; << 48 atomic_t available_instances; << 49 }; 92 }; 50 93 51 static inline struct mdev_device *to_mdev_devi !! 94 #define MDEV_TYPE_ATTR(_name, _mode, _show, _store) \ 52 { !! 95 struct mdev_type_attribute mdev_type_attr_##_name = \ 53 return container_of(dev, struct mdev_d !! 96 __ATTR(_name, _mode, _show, _store) 54 } !! 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) 55 103 56 /** 104 /** 57 * struct mdev_driver - Mediated device driver 105 * struct mdev_driver - Mediated device driver 58 * @device_api: string to return for the devic !! 106 * @name: driver name 59 * @max_instances: maximum number of instances << 60 * @probe: called when new device created 107 * @probe: called when new device created 61 * @remove: called when device removed 108 * @remove: called when device removed 62 * @get_available: Return the max number of in << 63 * @show_description: Print a description of t << 64 * @driver: device driver structure 109 * @driver: device driver structure >> 110 * 65 **/ 111 **/ 66 struct mdev_driver { 112 struct mdev_driver { 67 const char *device_api; !! 113 const char *name; 68 unsigned int max_instances; !! 114 int (*probe)(struct device *dev); 69 int (*probe)(struct mdev_device *dev); !! 115 void (*remove)(struct device *dev); 70 void (*remove)(struct mdev_device *dev << 71 unsigned int (*get_available)(struct m << 72 ssize_t (*show_description)(struct mde << 73 struct device_driver driver; 116 struct device_driver driver; 74 }; 117 }; 75 118 76 int mdev_register_parent(struct mdev_parent *p !! 119 #define to_mdev_driver(drv) container_of(drv, struct mdev_driver, driver) 77 struct mdev_driver *mdev_drive !! 120 78 unsigned int nr_types); !! 121 extern void *mdev_get_drvdata(struct mdev_device *mdev); 79 void mdev_unregister_parent(struct mdev_parent !! 122 extern void mdev_set_drvdata(struct mdev_device *mdev, void *data); 80 !! 123 extern uuid_le mdev_uuid(struct mdev_device *mdev); 81 int mdev_register_driver(struct mdev_driver *d !! 124 82 void mdev_unregister_driver(struct mdev_driver !! 125 extern struct bus_type mdev_bus_type; 83 !! 126 84 static inline struct device *mdev_dev(struct m !! 127 extern int mdev_register_device(struct device *dev, 85 { !! 128 const struct mdev_parent_ops *ops); 86 return &mdev->dev; !! 129 extern void mdev_unregister_device(struct device *dev); 87 } !! 130 >> 131 extern int mdev_register_driver(struct mdev_driver *drv, struct module *owner); >> 132 extern void mdev_unregister_driver(struct mdev_driver *drv); >> 133 >> 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); 88 137 89 #endif /* MDEV_H */ 138 #endif /* MDEV_H */ 90 139
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.