18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Mediated device interal definitions 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 68c2ecf20Sopenharmony_ci * Author: Neo Jia <cjia@nvidia.com> 78c2ecf20Sopenharmony_ci * Kirti Wankhede <kwankhede@nvidia.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef MDEV_PRIVATE_H 118c2ecf20Sopenharmony_ci#define MDEV_PRIVATE_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciint mdev_bus_register(void); 148c2ecf20Sopenharmony_civoid mdev_bus_unregister(void); 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cistruct mdev_parent { 178c2ecf20Sopenharmony_ci struct device *dev; 188c2ecf20Sopenharmony_ci const struct mdev_parent_ops *ops; 198c2ecf20Sopenharmony_ci struct kref ref; 208c2ecf20Sopenharmony_ci struct list_head next; 218c2ecf20Sopenharmony_ci struct kset *mdev_types_kset; 228c2ecf20Sopenharmony_ci struct list_head type_list; 238c2ecf20Sopenharmony_ci /* Synchronize device creation/removal with parent unregistration */ 248c2ecf20Sopenharmony_ci struct rw_semaphore unreg_sem; 258c2ecf20Sopenharmony_ci}; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistruct mdev_device { 288c2ecf20Sopenharmony_ci struct device dev; 298c2ecf20Sopenharmony_ci struct mdev_parent *parent; 308c2ecf20Sopenharmony_ci guid_t uuid; 318c2ecf20Sopenharmony_ci void *driver_data; 328c2ecf20Sopenharmony_ci struct list_head next; 338c2ecf20Sopenharmony_ci struct kobject *type_kobj; 348c2ecf20Sopenharmony_ci struct device *iommu_device; 358c2ecf20Sopenharmony_ci bool active; 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistatic inline struct mdev_device *to_mdev_device(struct device *dev) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci return container_of(dev, struct mdev_device, dev); 418c2ecf20Sopenharmony_ci} 428c2ecf20Sopenharmony_ci#define dev_is_mdev(d) ((d)->bus == &mdev_bus_type) 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistruct mdev_type { 458c2ecf20Sopenharmony_ci struct kobject kobj; 468c2ecf20Sopenharmony_ci struct kobject *devices_kobj; 478c2ecf20Sopenharmony_ci struct mdev_parent *parent; 488c2ecf20Sopenharmony_ci struct list_head next; 498c2ecf20Sopenharmony_ci struct attribute_group *group; 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define to_mdev_type_attr(_attr) \ 538c2ecf20Sopenharmony_ci container_of(_attr, struct mdev_type_attribute, attr) 548c2ecf20Sopenharmony_ci#define to_mdev_type(_kobj) \ 558c2ecf20Sopenharmony_ci container_of(_kobj, struct mdev_type, kobj) 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ciint parent_create_sysfs_files(struct mdev_parent *parent); 588c2ecf20Sopenharmony_civoid parent_remove_sysfs_files(struct mdev_parent *parent); 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ciint mdev_create_sysfs_files(struct device *dev, struct mdev_type *type); 618c2ecf20Sopenharmony_civoid mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ciint mdev_device_create(struct kobject *kobj, 648c2ecf20Sopenharmony_ci struct device *dev, const guid_t *uuid); 658c2ecf20Sopenharmony_ciint mdev_device_remove(struct device *dev); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#endif /* MDEV_PRIVATE_H */ 68