mirror of
https://github.com/torvalds/linux.git
synced 2024-09-21 15:33:19 +00:00
vfio-mdev: de-polute the namespace, rename parent_device & parent_ops
Add an mdev_ prefix so we're not poluting the namespace so much. 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: Alex Williamson <alex.williamson@redhat.com> Reviewed by: Kirti Wankhede <kwankhede@nvidia.com>
This commit is contained in:
parent
49550787a9
commit
42930553a7
|
@ -127,22 +127,22 @@ the VFIO when devices are unbound from the driver.
|
||||||
Physical Device Driver Interface
|
Physical Device Driver Interface
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
|
||||||
The physical device driver interface provides the parent_ops[3] structure to
|
The physical device driver interface provides the mdev_parent_ops[3] structure
|
||||||
define the APIs to manage work in the mediated core driver that is related to
|
to define the APIs to manage work in the mediated core driver that is related
|
||||||
the physical device.
|
to the physical device.
|
||||||
|
|
||||||
The structures in the parent_ops structure are as follows:
|
The structures in the mdev_parent_ops structure are as follows:
|
||||||
|
|
||||||
* dev_attr_groups: attributes of the parent device
|
* dev_attr_groups: attributes of the parent device
|
||||||
* mdev_attr_groups: attributes of the mediated device
|
* mdev_attr_groups: attributes of the mediated device
|
||||||
* supported_config: attributes to define supported configurations
|
* supported_config: attributes to define supported configurations
|
||||||
|
|
||||||
The functions in the parent_ops structure are as follows:
|
The functions in the mdev_parent_ops structure are as follows:
|
||||||
|
|
||||||
* create: allocate basic resources in a driver for a mediated device
|
* create: allocate basic resources in a driver for a mediated device
|
||||||
* remove: free resources in a driver when a mediated device is destroyed
|
* remove: free resources in a driver when a mediated device is destroyed
|
||||||
|
|
||||||
The callbacks in the parent_ops structure are as follows:
|
The callbacks in the mdev_parent_ops structure are as follows:
|
||||||
|
|
||||||
* open: open callback of mediated device
|
* open: open callback of mediated device
|
||||||
* close: close callback of mediated device
|
* close: close callback of mediated device
|
||||||
|
@ -151,14 +151,14 @@ The callbacks in the parent_ops structure are as follows:
|
||||||
* write: write emulation callback
|
* write: write emulation callback
|
||||||
* mmap: mmap emulation callback
|
* mmap: mmap emulation callback
|
||||||
|
|
||||||
A driver should use the parent_ops structure in the function call to register
|
A driver should use the mdev_parent_ops structure in the function call to
|
||||||
itself with the mdev core driver:
|
register itself with the mdev core driver:
|
||||||
|
|
||||||
extern int mdev_register_device(struct device *dev,
|
extern int mdev_register_device(struct device *dev,
|
||||||
const struct parent_ops *ops);
|
const struct mdev_parent_ops *ops);
|
||||||
|
|
||||||
However, the parent_ops structure is not required in the function call that a
|
However, the mdev_parent_ops structure is not required in the function call
|
||||||
driver should use to unregister itself with the mdev core driver:
|
that a driver should use to unregister itself with the mdev core driver:
|
||||||
|
|
||||||
extern void mdev_unregister_device(struct device *dev);
|
extern void mdev_unregister_device(struct device *dev);
|
||||||
|
|
||||||
|
@ -394,5 +394,5 @@ References
|
||||||
|
|
||||||
[1] See Documentation/vfio.txt for more information on VFIO.
|
[1] See Documentation/vfio.txt for more information on VFIO.
|
||||||
[2] struct mdev_driver in include/linux/mdev.h
|
[2] struct mdev_driver in include/linux/mdev.h
|
||||||
[3] struct parent_ops in include/linux/mdev.h
|
[3] struct mdev_parent_ops in include/linux/mdev.h
|
||||||
[4] struct vfio_iommu_driver_ops in include/linux/vfio.h
|
[4] struct vfio_iommu_driver_ops in include/linux/vfio.h
|
||||||
|
|
|
@ -1089,7 +1089,7 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct parent_ops intel_vgpu_ops = {
|
static const struct mdev_parent_ops intel_vgpu_ops = {
|
||||||
.supported_type_groups = intel_vgpu_type_groups,
|
.supported_type_groups = intel_vgpu_type_groups,
|
||||||
.create = intel_vgpu_create,
|
.create = intel_vgpu_create,
|
||||||
.remove = intel_vgpu_remove,
|
.remove = intel_vgpu_remove,
|
||||||
|
|
|
@ -45,7 +45,7 @@ static int _find_mdev_device(struct device *dev, void *data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool mdev_device_exist(struct parent_device *parent, uuid_le uuid)
|
static bool mdev_device_exist(struct mdev_parent *parent, uuid_le uuid)
|
||||||
{
|
{
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
|
|
||||||
|
@ -59,9 +59,9 @@ static bool mdev_device_exist(struct parent_device *parent, uuid_le uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Should be called holding parent_list_lock */
|
/* Should be called holding parent_list_lock */
|
||||||
static struct parent_device *__find_parent_device(struct device *dev)
|
static struct mdev_parent *__find_parent_device(struct device *dev)
|
||||||
{
|
{
|
||||||
struct parent_device *parent;
|
struct mdev_parent *parent;
|
||||||
|
|
||||||
list_for_each_entry(parent, &parent_list, next) {
|
list_for_each_entry(parent, &parent_list, next) {
|
||||||
if (parent->dev == dev)
|
if (parent->dev == dev)
|
||||||
|
@ -72,8 +72,8 @@ static struct parent_device *__find_parent_device(struct device *dev)
|
||||||
|
|
||||||
static void mdev_release_parent(struct kref *kref)
|
static void mdev_release_parent(struct kref *kref)
|
||||||
{
|
{
|
||||||
struct parent_device *parent = container_of(kref, struct parent_device,
|
struct mdev_parent *parent = container_of(kref, struct mdev_parent,
|
||||||
ref);
|
ref);
|
||||||
struct device *dev = parent->dev;
|
struct device *dev = parent->dev;
|
||||||
|
|
||||||
kfree(parent);
|
kfree(parent);
|
||||||
|
@ -81,7 +81,7 @@ static void mdev_release_parent(struct kref *kref)
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
inline struct parent_device *mdev_get_parent(struct parent_device *parent)
|
inline struct mdev_parent *mdev_get_parent(struct mdev_parent *parent)
|
||||||
{
|
{
|
||||||
if (parent)
|
if (parent)
|
||||||
kref_get(&parent->ref);
|
kref_get(&parent->ref);
|
||||||
|
@ -89,7 +89,7 @@ inline struct parent_device *mdev_get_parent(struct parent_device *parent)
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void mdev_put_parent(struct parent_device *parent)
|
static inline void mdev_put_parent(struct mdev_parent *parent)
|
||||||
{
|
{
|
||||||
if (parent)
|
if (parent)
|
||||||
kref_put(&parent->ref, mdev_release_parent);
|
kref_put(&parent->ref, mdev_release_parent);
|
||||||
|
@ -98,7 +98,7 @@ static inline void mdev_put_parent(struct parent_device *parent)
|
||||||
static int mdev_device_create_ops(struct kobject *kobj,
|
static int mdev_device_create_ops(struct kobject *kobj,
|
||||||
struct mdev_device *mdev)
|
struct mdev_device *mdev)
|
||||||
{
|
{
|
||||||
struct parent_device *parent = mdev->parent;
|
struct mdev_parent *parent = mdev->parent;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = parent->ops->create(kobj, mdev);
|
ret = parent->ops->create(kobj, mdev);
|
||||||
|
@ -125,7 +125,7 @@ static int mdev_device_create_ops(struct kobject *kobj,
|
||||||
*/
|
*/
|
||||||
static int mdev_device_remove_ops(struct mdev_device *mdev, bool force_remove)
|
static int mdev_device_remove_ops(struct mdev_device *mdev, bool force_remove)
|
||||||
{
|
{
|
||||||
struct parent_device *parent = mdev->parent;
|
struct mdev_parent *parent = mdev->parent;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -156,10 +156,10 @@ static int mdev_device_remove_cb(struct device *dev, void *data)
|
||||||
* Add device to list of registered parent devices.
|
* Add device to list of registered parent devices.
|
||||||
* Returns a negative value on error, otherwise 0.
|
* Returns a negative value on error, otherwise 0.
|
||||||
*/
|
*/
|
||||||
int mdev_register_device(struct device *dev, const struct parent_ops *ops)
|
int mdev_register_device(struct device *dev, const struct mdev_parent_ops *ops)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct parent_device *parent;
|
struct mdev_parent *parent;
|
||||||
|
|
||||||
/* check for mandatory ops */
|
/* check for mandatory ops */
|
||||||
if (!ops || !ops->create || !ops->remove || !ops->supported_type_groups)
|
if (!ops || !ops->create || !ops->remove || !ops->supported_type_groups)
|
||||||
|
@ -232,7 +232,7 @@ EXPORT_SYMBOL(mdev_register_device);
|
||||||
|
|
||||||
void mdev_unregister_device(struct device *dev)
|
void mdev_unregister_device(struct device *dev)
|
||||||
{
|
{
|
||||||
struct parent_device *parent;
|
struct mdev_parent *parent;
|
||||||
bool force_remove = true;
|
bool force_remove = true;
|
||||||
|
|
||||||
mutex_lock(&parent_list_lock);
|
mutex_lock(&parent_list_lock);
|
||||||
|
@ -269,7 +269,7 @@ int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct mdev_device *mdev;
|
struct mdev_device *mdev;
|
||||||
struct parent_device *parent;
|
struct mdev_parent *parent;
|
||||||
struct mdev_type *type = to_mdev_type(kobj);
|
struct mdev_type *type = to_mdev_type(kobj);
|
||||||
|
|
||||||
parent = mdev_get_parent(type->parent);
|
parent = mdev_get_parent(type->parent);
|
||||||
|
@ -338,7 +338,7 @@ create_err:
|
||||||
int mdev_device_remove(struct device *dev, bool force_remove)
|
int mdev_device_remove(struct device *dev, bool force_remove)
|
||||||
{
|
{
|
||||||
struct mdev_device *mdev, *tmp;
|
struct mdev_device *mdev, *tmp;
|
||||||
struct parent_device *parent;
|
struct mdev_parent *parent;
|
||||||
struct mdev_type *type;
|
struct mdev_type *type;
|
||||||
int ret;
|
int ret;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
|
@ -19,7 +19,7 @@ void mdev_bus_unregister(void);
|
||||||
struct mdev_type {
|
struct mdev_type {
|
||||||
struct kobject kobj;
|
struct kobject kobj;
|
||||||
struct kobject *devices_kobj;
|
struct kobject *devices_kobj;
|
||||||
struct parent_device *parent;
|
struct mdev_parent *parent;
|
||||||
struct list_head next;
|
struct list_head next;
|
||||||
struct attribute_group *group;
|
struct attribute_group *group;
|
||||||
};
|
};
|
||||||
|
@ -29,8 +29,8 @@ struct mdev_type {
|
||||||
#define to_mdev_type(_kobj) \
|
#define to_mdev_type(_kobj) \
|
||||||
container_of(_kobj, struct mdev_type, kobj)
|
container_of(_kobj, struct mdev_type, kobj)
|
||||||
|
|
||||||
int parent_create_sysfs_files(struct parent_device *parent);
|
int parent_create_sysfs_files(struct mdev_parent *parent);
|
||||||
void parent_remove_sysfs_files(struct parent_device *parent);
|
void parent_remove_sysfs_files(struct mdev_parent *parent);
|
||||||
|
|
||||||
int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type);
|
int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type);
|
||||||
void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type);
|
void mdev_remove_sysfs_files(struct device *dev, struct mdev_type *type);
|
||||||
|
|
|
@ -92,7 +92,7 @@ static struct kobj_type mdev_type_ktype = {
|
||||||
.release = mdev_type_release,
|
.release = mdev_type_release,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mdev_type *add_mdev_supported_type(struct parent_device *parent,
|
struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent,
|
||||||
struct attribute_group *group)
|
struct attribute_group *group)
|
||||||
{
|
{
|
||||||
struct mdev_type *type;
|
struct mdev_type *type;
|
||||||
|
@ -158,7 +158,7 @@ static void remove_mdev_supported_type(struct mdev_type *type)
|
||||||
kobject_put(&type->kobj);
|
kobject_put(&type->kobj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_mdev_supported_type_groups(struct parent_device *parent)
|
static int add_mdev_supported_type_groups(struct mdev_parent *parent)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ static int add_mdev_supported_type_groups(struct parent_device *parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mdev sysfs functions */
|
/* mdev sysfs functions */
|
||||||
void parent_remove_sysfs_files(struct parent_device *parent)
|
void parent_remove_sysfs_files(struct mdev_parent *parent)
|
||||||
{
|
{
|
||||||
struct mdev_type *type, *tmp;
|
struct mdev_type *type, *tmp;
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ void parent_remove_sysfs_files(struct parent_device *parent)
|
||||||
kset_unregister(parent->mdev_types_kset);
|
kset_unregister(parent->mdev_types_kset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int parent_create_sysfs_files(struct parent_device *parent)
|
int parent_create_sysfs_files(struct mdev_parent *parent)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
static int vfio_mdev_open(void *device_data)
|
static int vfio_mdev_open(void *device_data)
|
||||||
{
|
{
|
||||||
struct mdev_device *mdev = device_data;
|
struct mdev_device *mdev = device_data;
|
||||||
struct parent_device *parent = mdev->parent;
|
struct mdev_parent *parent = mdev->parent;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (unlikely(!parent->ops->open))
|
if (unlikely(!parent->ops->open))
|
||||||
|
@ -46,7 +46,7 @@ static int vfio_mdev_open(void *device_data)
|
||||||
static void vfio_mdev_release(void *device_data)
|
static void vfio_mdev_release(void *device_data)
|
||||||
{
|
{
|
||||||
struct mdev_device *mdev = device_data;
|
struct mdev_device *mdev = device_data;
|
||||||
struct parent_device *parent = mdev->parent;
|
struct mdev_parent *parent = mdev->parent;
|
||||||
|
|
||||||
if (likely(parent->ops->release))
|
if (likely(parent->ops->release))
|
||||||
parent->ops->release(mdev);
|
parent->ops->release(mdev);
|
||||||
|
@ -58,7 +58,7 @@ static long vfio_mdev_unlocked_ioctl(void *device_data,
|
||||||
unsigned int cmd, unsigned long arg)
|
unsigned int cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
struct mdev_device *mdev = device_data;
|
struct mdev_device *mdev = device_data;
|
||||||
struct parent_device *parent = mdev->parent;
|
struct mdev_parent *parent = mdev->parent;
|
||||||
|
|
||||||
if (unlikely(!parent->ops->ioctl))
|
if (unlikely(!parent->ops->ioctl))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -70,7 +70,7 @@ static ssize_t vfio_mdev_read(void *device_data, char __user *buf,
|
||||||
size_t count, loff_t *ppos)
|
size_t count, loff_t *ppos)
|
||||||
{
|
{
|
||||||
struct mdev_device *mdev = device_data;
|
struct mdev_device *mdev = device_data;
|
||||||
struct parent_device *parent = mdev->parent;
|
struct mdev_parent *parent = mdev->parent;
|
||||||
|
|
||||||
if (unlikely(!parent->ops->read))
|
if (unlikely(!parent->ops->read))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -82,7 +82,7 @@ static ssize_t vfio_mdev_write(void *device_data, const char __user *buf,
|
||||||
size_t count, loff_t *ppos)
|
size_t count, loff_t *ppos)
|
||||||
{
|
{
|
||||||
struct mdev_device *mdev = device_data;
|
struct mdev_device *mdev = device_data;
|
||||||
struct parent_device *parent = mdev->parent;
|
struct mdev_parent *parent = mdev->parent;
|
||||||
|
|
||||||
if (unlikely(!parent->ops->write))
|
if (unlikely(!parent->ops->write))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -93,7 +93,7 @@ static ssize_t vfio_mdev_write(void *device_data, const char __user *buf,
|
||||||
static int vfio_mdev_mmap(void *device_data, struct vm_area_struct *vma)
|
static int vfio_mdev_mmap(void *device_data, struct vm_area_struct *vma)
|
||||||
{
|
{
|
||||||
struct mdev_device *mdev = device_data;
|
struct mdev_device *mdev = device_data;
|
||||||
struct parent_device *parent = mdev->parent;
|
struct mdev_parent *parent = mdev->parent;
|
||||||
|
|
||||||
if (unlikely(!parent->ops->mmap))
|
if (unlikely(!parent->ops->mmap))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
@ -14,9 +14,9 @@
|
||||||
#define MDEV_H
|
#define MDEV_H
|
||||||
|
|
||||||
/* Parent device */
|
/* Parent device */
|
||||||
struct parent_device {
|
struct mdev_parent {
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
const struct parent_ops *ops;
|
const struct mdev_parent_ops *ops;
|
||||||
|
|
||||||
/* internal */
|
/* internal */
|
||||||
struct kref ref;
|
struct kref ref;
|
||||||
|
@ -29,7 +29,7 @@ struct parent_device {
|
||||||
/* Mediated device */
|
/* Mediated device */
|
||||||
struct mdev_device {
|
struct mdev_device {
|
||||||
struct device dev;
|
struct device dev;
|
||||||
struct parent_device *parent;
|
struct mdev_parent *parent;
|
||||||
uuid_le uuid;
|
uuid_le uuid;
|
||||||
void *driver_data;
|
void *driver_data;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ struct mdev_device {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct parent_ops - Structure to be registered for each parent device to
|
* struct mdev_parent_ops - Structure to be registered for each parent device to
|
||||||
* register the device to mdev module.
|
* register the device to mdev module.
|
||||||
*
|
*
|
||||||
* @owner: The module owner.
|
* @owner: The module owner.
|
||||||
|
@ -86,10 +86,10 @@ struct mdev_device {
|
||||||
* @mdev: mediated device structure
|
* @mdev: mediated device structure
|
||||||
* @vma: vma structure
|
* @vma: vma structure
|
||||||
* Parent device that support mediated device should be registered with mdev
|
* Parent device that support mediated device should be registered with mdev
|
||||||
* module with parent_ops structure.
|
* module with mdev_parent_ops structure.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
struct parent_ops {
|
struct mdev_parent_ops {
|
||||||
struct module *owner;
|
struct module *owner;
|
||||||
const struct attribute_group **dev_attr_groups;
|
const struct attribute_group **dev_attr_groups;
|
||||||
const struct attribute_group **mdev_attr_groups;
|
const struct attribute_group **mdev_attr_groups;
|
||||||
|
@ -159,7 +159,7 @@ extern struct bus_type mdev_bus_type;
|
||||||
#define dev_is_mdev(d) ((d)->bus == &mdev_bus_type)
|
#define dev_is_mdev(d) ((d)->bus == &mdev_bus_type)
|
||||||
|
|
||||||
extern int mdev_register_device(struct device *dev,
|
extern int mdev_register_device(struct device *dev,
|
||||||
const struct parent_ops *ops);
|
const struct mdev_parent_ops *ops);
|
||||||
extern void mdev_unregister_device(struct device *dev);
|
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);
|
||||||
|
|
|
@ -1402,7 +1402,7 @@ struct attribute_group *mdev_type_groups[] = {
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct parent_ops mdev_fops = {
|
struct mdev_parent_ops mdev_fops = {
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.dev_attr_groups = mtty_dev_groups,
|
.dev_attr_groups = mtty_dev_groups,
|
||||||
.mdev_attr_groups = mdev_dev_groups,
|
.mdev_attr_groups = mdev_dev_groups,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user