^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Mediated device interal definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Neo Jia <cjia@nvidia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Kirti Wankhede <kwankhede@nvidia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifndef MDEV_PRIVATE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define MDEV_PRIVATE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) int mdev_bus_register(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) void mdev_bus_unregister(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct mdev_parent {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) const struct mdev_parent_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct kref ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct list_head next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct kset *mdev_types_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct list_head type_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /* Synchronize device creation/removal with parent unregistration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct rw_semaphore unreg_sem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct mdev_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct device dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct mdev_parent *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) guid_t uuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) void *driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct list_head next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct kobject *type_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct device *iommu_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) bool active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define to_mdev_device(dev) container_of(dev, struct mdev_device, dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define dev_is_mdev(d) ((d)->bus == &mdev_bus_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct mdev_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct kobject kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct kobject *devices_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct mdev_parent *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct list_head next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct attribute_group *group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define to_mdev_type_attr(_attr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) container_of(_attr, struct mdev_type_attribute, attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define to_mdev_type(_kobj) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) container_of(_kobj, struct mdev_type, kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int parent_create_sysfs_files(struct mdev_parent *parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) void parent_remove_sysfs_files(struct mdev_parent *parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int mdev_device_create(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct device *dev, const guid_t *uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) int mdev_device_remove(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #endif /* MDEV_PRIVATE_H */