Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Mediated device definition
0004  *
0005  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
0006  *     Author: Neo Jia <cjia@nvidia.com>
0007  *             Kirti Wankhede <kwankhede@nvidia.com>
0008  */
0009 
0010 #ifndef MDEV_H
0011 #define MDEV_H
0012 
0013 struct mdev_type;
0014 
0015 struct mdev_device {
0016     struct device dev;
0017     guid_t uuid;
0018     struct list_head next;
0019     struct mdev_type *type;
0020     bool active;
0021 };
0022 
0023 static inline struct mdev_device *to_mdev_device(struct device *dev)
0024 {
0025     return container_of(dev, struct mdev_device, dev);
0026 }
0027 
0028 unsigned int mdev_get_type_group_id(struct mdev_device *mdev);
0029 unsigned int mtype_get_type_group_id(struct mdev_type *mtype);
0030 struct device *mtype_get_parent_dev(struct mdev_type *mtype);
0031 
0032 /* interface for exporting mdev supported type attributes */
0033 struct mdev_type_attribute {
0034     struct attribute attr;
0035     ssize_t (*show)(struct mdev_type *mtype,
0036             struct mdev_type_attribute *attr, char *buf);
0037     ssize_t (*store)(struct mdev_type *mtype,
0038              struct mdev_type_attribute *attr, const char *buf,
0039              size_t count);
0040 };
0041 
0042 #define MDEV_TYPE_ATTR(_name, _mode, _show, _store)     \
0043 struct mdev_type_attribute mdev_type_attr_##_name =     \
0044     __ATTR(_name, _mode, _show, _store)
0045 #define MDEV_TYPE_ATTR_RW(_name) \
0046     struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name)
0047 #define MDEV_TYPE_ATTR_RO(_name) \
0048     struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name)
0049 #define MDEV_TYPE_ATTR_WO(_name) \
0050     struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name)
0051 
0052 /**
0053  * struct mdev_driver - Mediated device driver
0054  * @probe: called when new device created
0055  * @remove: called when device removed
0056  * @supported_type_groups: Attributes to define supported types. It is mandatory
0057  *          to provide supported types.
0058  * @driver: device driver structure
0059  *
0060  **/
0061 struct mdev_driver {
0062     int (*probe)(struct mdev_device *dev);
0063     void (*remove)(struct mdev_device *dev);
0064     struct attribute_group **supported_type_groups;
0065     struct device_driver driver;
0066 };
0067 
0068 extern struct bus_type mdev_bus_type;
0069 
0070 int mdev_register_device(struct device *dev, struct mdev_driver *mdev_driver);
0071 void mdev_unregister_device(struct device *dev);
0072 
0073 int mdev_register_driver(struct mdev_driver *drv);
0074 void mdev_unregister_driver(struct mdev_driver *drv);
0075 
0076 struct device *mdev_parent_dev(struct mdev_device *mdev);
0077 static inline struct device *mdev_dev(struct mdev_device *mdev)
0078 {
0079     return &mdev->dev;
0080 }
0081 static inline struct mdev_device *mdev_from_dev(struct device *dev)
0082 {
0083     return dev->bus == &mdev_bus_type ? to_mdev_device(dev) : NULL;
0084 }
0085 
0086 #endif /* MDEV_H */