1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 27b96953bSKirti Wankhede /* 37b96953bSKirti Wankhede * Mediated device definition 47b96953bSKirti Wankhede * 57b96953bSKirti Wankhede * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 67b96953bSKirti Wankhede * Author: Neo Jia <cjia@nvidia.com> 77b96953bSKirti Wankhede * Kirti Wankhede <kwankhede@nvidia.com> 87b96953bSKirti Wankhede */ 97b96953bSKirti Wankhede 107b96953bSKirti Wankhede #ifndef MDEV_H 117b96953bSKirti Wankhede #define MDEV_H 127b96953bSKirti Wankhede 13*bdef2b78SChristoph Hellwig #include <linux/device.h> 14*bdef2b78SChristoph Hellwig #include <linux/uuid.h> 15*bdef2b78SChristoph Hellwig 16417fd5bfSJason Gunthorpe struct mdev_type; 17417fd5bfSJason Gunthorpe 182a3d15f2SJason Gunthorpe struct mdev_device { 192a3d15f2SJason Gunthorpe struct device dev; 202a3d15f2SJason Gunthorpe guid_t uuid; 212a3d15f2SJason Gunthorpe struct list_head next; 22417fd5bfSJason Gunthorpe struct mdev_type *type; 232a3d15f2SJason Gunthorpe bool active; 242a3d15f2SJason Gunthorpe }; 252a3d15f2SJason Gunthorpe 262a3d15f2SJason Gunthorpe static inline struct mdev_device *to_mdev_device(struct device *dev) 272a3d15f2SJason Gunthorpe { 282a3d15f2SJason Gunthorpe return container_of(dev, struct mdev_device, dev); 292a3d15f2SJason Gunthorpe } 307b96953bSKirti Wankhede 3115fcc44bSJason Gunthorpe unsigned int mdev_get_type_group_id(struct mdev_device *mdev); 329169cff1SJason Gunthorpe unsigned int mtype_get_type_group_id(struct mdev_type *mtype); 339169cff1SJason Gunthorpe struct device *mtype_get_parent_dev(struct mdev_type *mtype); 3415fcc44bSJason Gunthorpe 357b96953bSKirti Wankhede /* interface for exporting mdev supported type attributes */ 367b96953bSKirti Wankhede struct mdev_type_attribute { 377b96953bSKirti Wankhede struct attribute attr; 389169cff1SJason Gunthorpe ssize_t (*show)(struct mdev_type *mtype, 399169cff1SJason Gunthorpe struct mdev_type_attribute *attr, char *buf); 409169cff1SJason Gunthorpe ssize_t (*store)(struct mdev_type *mtype, 419169cff1SJason Gunthorpe struct mdev_type_attribute *attr, const char *buf, 429169cff1SJason Gunthorpe size_t count); 437b96953bSKirti Wankhede }; 447b96953bSKirti Wankhede 457b96953bSKirti Wankhede #define MDEV_TYPE_ATTR(_name, _mode, _show, _store) \ 467b96953bSKirti Wankhede struct mdev_type_attribute mdev_type_attr_##_name = \ 477b96953bSKirti Wankhede __ATTR(_name, _mode, _show, _store) 487b96953bSKirti Wankhede #define MDEV_TYPE_ATTR_RW(_name) \ 497b96953bSKirti Wankhede struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RW(_name) 507b96953bSKirti Wankhede #define MDEV_TYPE_ATTR_RO(_name) \ 517b96953bSKirti Wankhede struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_RO(_name) 527b96953bSKirti Wankhede #define MDEV_TYPE_ATTR_WO(_name) \ 537b96953bSKirti Wankhede struct mdev_type_attribute mdev_type_attr_##_name = __ATTR_WO(_name) 547b96953bSKirti Wankhede 557b96953bSKirti Wankhede /** 567b96953bSKirti Wankhede * struct mdev_driver - Mediated device driver 577b96953bSKirti Wankhede * @probe: called when new device created 587b96953bSKirti Wankhede * @remove: called when device removed 596b42f491SJason Gunthorpe * @supported_type_groups: Attributes to define supported types. It is mandatory 606b42f491SJason Gunthorpe * to provide supported types. 617b96953bSKirti Wankhede * @driver: device driver structure 627b96953bSKirti Wankhede * 637b96953bSKirti Wankhede **/ 647b96953bSKirti Wankhede struct mdev_driver { 652a3d15f2SJason Gunthorpe int (*probe)(struct mdev_device *dev); 662a3d15f2SJason Gunthorpe void (*remove)(struct mdev_device *dev); 676b42f491SJason Gunthorpe struct attribute_group **supported_type_groups; 687b96953bSKirti Wankhede struct device_driver driver; 697b96953bSKirti Wankhede }; 707b96953bSKirti Wankhede 717b96953bSKirti Wankhede extern struct bus_type mdev_bus_type; 727b96953bSKirti Wankhede 736b42f491SJason Gunthorpe int mdev_register_device(struct device *dev, struct mdev_driver *mdev_driver); 7450732af3SParav Pandit void mdev_unregister_device(struct device *dev); 757b96953bSKirti Wankhede 7691b9969dSJason Gunthorpe int mdev_register_driver(struct mdev_driver *drv); 7750732af3SParav Pandit void mdev_unregister_driver(struct mdev_driver *drv); 787b96953bSKirti Wankhede 7950732af3SParav Pandit struct device *mdev_parent_dev(struct mdev_device *mdev); 802a3d15f2SJason Gunthorpe static inline struct device *mdev_dev(struct mdev_device *mdev) 812a3d15f2SJason Gunthorpe { 822a3d15f2SJason Gunthorpe return &mdev->dev; 832a3d15f2SJason Gunthorpe } 842a3d15f2SJason Gunthorpe static inline struct mdev_device *mdev_from_dev(struct device *dev) 852a3d15f2SJason Gunthorpe { 862a3d15f2SJason Gunthorpe return dev->bus == &mdev_bus_type ? to_mdev_device(dev) : NULL; 872a3d15f2SJason Gunthorpe } 889372e6feSAlex Williamson 897b96953bSKirti Wankhede #endif /* MDEV_H */ 90