Commit 9372e6fe authored by Alex Williamson's avatar Alex Williamson

vfio-mdev: Make mdev_parent private

Rather than hoping for good behavior by marking some elements
internal, enforce it by making the entire structure private and
creating an accessor function for the one useful external field.

Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
Cc: Zhi Wang <zhi.a.wang@intel.com>
Cc: Jike Song <jike.song@intel.com>
Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
Reviewed by: Kirti Wankhede <kwankhede@nvidia.com>
parent 42930553
...@@ -223,6 +223,9 @@ Directories and files under the sysfs for Each Physical Device ...@@ -223,6 +223,9 @@ Directories and files under the sysfs for Each Physical Device
sprintf(buf, "%s-%s", dev_driver_string(parent->dev), group->name); sprintf(buf, "%s-%s", dev_driver_string(parent->dev), group->name);
(or using mdev_parent_dev(mdev) to arrive at the parent device outside
of the core mdev code)
* device_api * device_api
This attribute should show which device API is being created, for example, This attribute should show which device API is being created, for example,
......
...@@ -396,7 +396,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) ...@@ -396,7 +396,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
struct device *pdev; struct device *pdev;
void *gvt; void *gvt;
pdev = mdev->parent->dev; pdev = mdev_parent_dev(mdev);
gvt = kdev_to_i915(pdev)->gvt; gvt = kdev_to_i915(pdev)->gvt;
type = intel_gvt_find_vgpu_type(gvt, kobject_name(kobj)); type = intel_gvt_find_vgpu_type(gvt, kobject_name(kobj));
......
...@@ -30,6 +30,12 @@ static struct class_compat *mdev_bus_compat_class; ...@@ -30,6 +30,12 @@ static struct class_compat *mdev_bus_compat_class;
static LIST_HEAD(mdev_list); static LIST_HEAD(mdev_list);
static DEFINE_MUTEX(mdev_list_lock); static DEFINE_MUTEX(mdev_list_lock);
struct device *mdev_parent_dev(struct mdev_device *mdev)
{
return mdev->parent->dev;
}
EXPORT_SYMBOL(mdev_parent_dev);
static int _find_mdev_device(struct device *dev, void *data) static int _find_mdev_device(struct device *dev, void *data)
{ {
struct mdev_device *mdev; struct mdev_device *mdev;
......
...@@ -16,6 +16,16 @@ ...@@ -16,6 +16,16 @@
int mdev_bus_register(void); int mdev_bus_register(void);
void mdev_bus_unregister(void); void mdev_bus_unregister(void);
struct mdev_parent {
struct device *dev;
const struct mdev_parent_ops *ops;
struct kref ref;
struct mutex lock;
struct list_head next;
struct kset *mdev_types_kset;
struct list_head type_list;
};
struct mdev_type { struct mdev_type {
struct kobject kobj; struct kobject kobj;
struct kobject *devices_kobj; struct kobject *devices_kobj;
......
...@@ -13,19 +13,6 @@ ...@@ -13,19 +13,6 @@
#ifndef MDEV_H #ifndef MDEV_H
#define MDEV_H #define MDEV_H
/* Parent device */
struct mdev_parent {
struct device *dev;
const struct mdev_parent_ops *ops;
/* internal */
struct kref ref;
struct mutex lock;
struct list_head next;
struct kset *mdev_types_kset;
struct list_head type_list;
};
/* Mediated device */ /* Mediated device */
struct mdev_device { struct mdev_device {
struct device dev; struct device dev;
...@@ -165,4 +152,6 @@ extern void mdev_unregister_device(struct device *dev); ...@@ -165,4 +152,6 @@ extern void mdev_unregister_device(struct device *dev);
extern int mdev_register_driver(struct mdev_driver *drv, struct module *owner); extern int mdev_register_driver(struct mdev_driver *drv, struct module *owner);
extern void mdev_unregister_driver(struct mdev_driver *drv); extern void mdev_unregister_driver(struct mdev_driver *drv);
extern struct device *mdev_parent_dev(struct mdev_device *mdev);
#endif /* MDEV_H */ #endif /* MDEV_H */
...@@ -734,7 +734,7 @@ int mtty_create(struct kobject *kobj, struct mdev_device *mdev) ...@@ -734,7 +734,7 @@ int mtty_create(struct kobject *kobj, struct mdev_device *mdev)
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
snprintf(name, MTTY_STRING_LEN, "%s-%d", snprintf(name, MTTY_STRING_LEN, "%s-%d",
dev_driver_string(mdev->parent->dev), i + 1); dev_driver_string(mdev_parent_dev(mdev)), i + 1);
if (!strcmp(kobj->name, name)) { if (!strcmp(kobj->name, name)) {
nr_ports = i + 1; nr_ports = i + 1;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment