1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 2 /* 3 * Mediated device definition 3 * Mediated device definition 4 * 4 * 5 * Copyright (c) 2016, NVIDIA CORPORATION. All 5 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 6 * Author: Neo Jia <cjia@nvidia.com> 6 * Author: Neo Jia <cjia@nvidia.com> 7 * Kirti Wankhede <kwankhede@nvidi 7 * Kirti Wankhede <kwankhede@nvidia.com> 8 */ 8 */ 9 9 10 #ifndef MDEV_H 10 #ifndef MDEV_H 11 #define MDEV_H 11 #define MDEV_H 12 12 13 #include <linux/device.h> 13 #include <linux/device.h> 14 #include <linux/uuid.h> 14 #include <linux/uuid.h> 15 15 16 struct mdev_type; 16 struct mdev_type; 17 17 18 struct mdev_device { 18 struct mdev_device { 19 struct device dev; 19 struct device dev; 20 guid_t uuid; 20 guid_t uuid; 21 struct list_head next; 21 struct list_head next; 22 struct mdev_type *type; 22 struct mdev_type *type; 23 bool active; 23 bool active; 24 }; 24 }; 25 25 26 struct mdev_type { 26 struct mdev_type { 27 /* set by the driver before calling md 27 /* set by the driver before calling mdev_register parent: */ 28 const char *sysfs_name; 28 const char *sysfs_name; 29 const char *pretty_name; 29 const char *pretty_name; 30 30 31 /* set by the core, can be used driver 31 /* set by the core, can be used drivers */ 32 struct mdev_parent *parent; 32 struct mdev_parent *parent; 33 33 34 /* internal only */ 34 /* internal only */ 35 struct kobject kobj; 35 struct kobject kobj; 36 struct kobject *devices_kobj; 36 struct kobject *devices_kobj; 37 }; 37 }; 38 38 39 /* embedded into the struct device that the md 39 /* embedded into the struct device that the mdev devices hang off */ 40 struct mdev_parent { 40 struct mdev_parent { 41 struct device *dev; 41 struct device *dev; 42 struct mdev_driver *mdev_driver; 42 struct mdev_driver *mdev_driver; 43 struct kset *mdev_types_kset; 43 struct kset *mdev_types_kset; 44 /* Synchronize device creation/removal 44 /* Synchronize device creation/removal with parent unregistration */ 45 struct rw_semaphore unreg_sem; 45 struct rw_semaphore unreg_sem; 46 struct mdev_type **types; 46 struct mdev_type **types; 47 unsigned int nr_types; 47 unsigned int nr_types; 48 atomic_t available_instances; 48 atomic_t available_instances; 49 }; 49 }; 50 50 51 static inline struct mdev_device *to_mdev_devi 51 static inline struct mdev_device *to_mdev_device(struct device *dev) 52 { 52 { 53 return container_of(dev, struct mdev_d 53 return container_of(dev, struct mdev_device, dev); 54 } 54 } 55 55 56 /** 56 /** 57 * struct mdev_driver - Mediated device driver 57 * struct mdev_driver - Mediated device driver 58 * @device_api: string to return for the devic 58 * @device_api: string to return for the device_api sysfs 59 * @max_instances: maximum number of instances 59 * @max_instances: maximum number of instances supported (optional) 60 * @probe: called when new device created 60 * @probe: called when new device created 61 * @remove: called when device removed 61 * @remove: called when device removed 62 * @get_available: Return the max number of in 62 * @get_available: Return the max number of instances that can be created 63 * @show_description: Print a description of t 63 * @show_description: Print a description of the mtype 64 * @driver: device driver structure 64 * @driver: device driver structure 65 **/ 65 **/ 66 struct mdev_driver { 66 struct mdev_driver { 67 const char *device_api; 67 const char *device_api; 68 unsigned int max_instances; 68 unsigned int max_instances; 69 int (*probe)(struct mdev_device *dev); 69 int (*probe)(struct mdev_device *dev); 70 void (*remove)(struct mdev_device *dev 70 void (*remove)(struct mdev_device *dev); 71 unsigned int (*get_available)(struct m 71 unsigned int (*get_available)(struct mdev_type *mtype); 72 ssize_t (*show_description)(struct mde 72 ssize_t (*show_description)(struct mdev_type *mtype, char *buf); 73 struct device_driver driver; 73 struct device_driver driver; 74 }; 74 }; 75 75 76 int mdev_register_parent(struct mdev_parent *p 76 int mdev_register_parent(struct mdev_parent *parent, struct device *dev, 77 struct mdev_driver *mdev_drive 77 struct mdev_driver *mdev_driver, struct mdev_type **types, 78 unsigned int nr_types); 78 unsigned int nr_types); 79 void mdev_unregister_parent(struct mdev_parent 79 void mdev_unregister_parent(struct mdev_parent *parent); 80 80 81 int mdev_register_driver(struct mdev_driver *d 81 int mdev_register_driver(struct mdev_driver *drv); 82 void mdev_unregister_driver(struct mdev_driver 82 void mdev_unregister_driver(struct mdev_driver *drv); 83 83 84 static inline struct device *mdev_dev(struct m 84 static inline struct device *mdev_dev(struct mdev_device *mdev) 85 { 85 { 86 return &mdev->dev; 86 return &mdev->dev; 87 } 87 } 88 88 89 #endif /* MDEV_H */ 89 #endif /* MDEV_H */ 90 90
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.