vfio-mdev: Make mdev_device private and abstract interfaces
Abstract access to mdev_device so that we can define which interfaces are public rather than relying on comments in the structure. Cc: Zhenyu Wang <zhenyuw@linux.intel.com> Cc: Zhi Wang <zhi.a.wang@intel.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Reviewed-by: Jike Song <jike.song@intel.com> Reviewed by: Kirti Wankhede <kwankhede@nvidia.com>
This commit is contained in:
parent
9372e6feaa
commit
99e3123e3d
5 changed files with 71 additions and 45 deletions
|
@ -166,7 +166,7 @@ static void __gvt_cache_remove_entry(struct intel_vgpu *vgpu,
|
||||||
|
|
||||||
static void gvt_cache_remove(struct intel_vgpu *vgpu, gfn_t gfn)
|
static void gvt_cache_remove(struct intel_vgpu *vgpu, gfn_t gfn)
|
||||||
{
|
{
|
||||||
struct device *dev = &vgpu->vdev.mdev->dev;
|
struct device *dev = mdev_dev(vgpu->vdev.mdev);
|
||||||
struct gvt_dma *this;
|
struct gvt_dma *this;
|
||||||
unsigned long g1;
|
unsigned long g1;
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -195,7 +195,7 @@ static void gvt_cache_destroy(struct intel_vgpu *vgpu)
|
||||||
{
|
{
|
||||||
struct gvt_dma *dma;
|
struct gvt_dma *dma;
|
||||||
struct rb_node *node = NULL;
|
struct rb_node *node = NULL;
|
||||||
struct device *dev = &vgpu->vdev.mdev->dev;
|
struct device *dev = mdev_dev(vgpu->vdev.mdev);
|
||||||
unsigned long gfn;
|
unsigned long gfn;
|
||||||
|
|
||||||
mutex_lock(&vgpu->vdev.cache_lock);
|
mutex_lock(&vgpu->vdev.cache_lock);
|
||||||
|
@ -418,7 +418,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
|
||||||
mdev_set_drvdata(mdev, vgpu);
|
mdev_set_drvdata(mdev, vgpu);
|
||||||
|
|
||||||
gvt_dbg_core("intel_vgpu_create succeeded for mdev: %s\n",
|
gvt_dbg_core("intel_vgpu_create succeeded for mdev: %s\n",
|
||||||
dev_name(&mdev->dev));
|
dev_name(mdev_dev(mdev)));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,7 +482,7 @@ static int intel_vgpu_open(struct mdev_device *mdev)
|
||||||
vgpu->vdev.group_notifier.notifier_call = intel_vgpu_group_notifier;
|
vgpu->vdev.group_notifier.notifier_call = intel_vgpu_group_notifier;
|
||||||
|
|
||||||
events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;
|
events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;
|
||||||
ret = vfio_register_notifier(&mdev->dev, VFIO_IOMMU_NOTIFY, &events,
|
ret = vfio_register_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, &events,
|
||||||
&vgpu->vdev.iommu_notifier);
|
&vgpu->vdev.iommu_notifier);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
gvt_err("vfio_register_notifier for iommu failed: %d\n", ret);
|
gvt_err("vfio_register_notifier for iommu failed: %d\n", ret);
|
||||||
|
@ -490,7 +490,7 @@ static int intel_vgpu_open(struct mdev_device *mdev)
|
||||||
}
|
}
|
||||||
|
|
||||||
events = VFIO_GROUP_NOTIFY_SET_KVM;
|
events = VFIO_GROUP_NOTIFY_SET_KVM;
|
||||||
ret = vfio_register_notifier(&mdev->dev, VFIO_GROUP_NOTIFY, &events,
|
ret = vfio_register_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY, &events,
|
||||||
&vgpu->vdev.group_notifier);
|
&vgpu->vdev.group_notifier);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
gvt_err("vfio_register_notifier for group failed: %d\n", ret);
|
gvt_err("vfio_register_notifier for group failed: %d\n", ret);
|
||||||
|
@ -500,7 +500,7 @@ static int intel_vgpu_open(struct mdev_device *mdev)
|
||||||
return kvmgt_guest_init(mdev);
|
return kvmgt_guest_init(mdev);
|
||||||
|
|
||||||
undo_iommu:
|
undo_iommu:
|
||||||
vfio_unregister_notifier(&mdev->dev, VFIO_IOMMU_NOTIFY,
|
vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
|
||||||
&vgpu->vdev.iommu_notifier);
|
&vgpu->vdev.iommu_notifier);
|
||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -513,9 +513,9 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu)
|
||||||
if (!handle_valid(vgpu->handle))
|
if (!handle_valid(vgpu->handle))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
vfio_unregister_notifier(&vgpu->vdev.mdev->dev, VFIO_IOMMU_NOTIFY,
|
vfio_unregister_notifier(mdev_dev(vgpu->vdev.mdev), VFIO_IOMMU_NOTIFY,
|
||||||
&vgpu->vdev.iommu_notifier);
|
&vgpu->vdev.iommu_notifier);
|
||||||
vfio_unregister_notifier(&vgpu->vdev.mdev->dev, VFIO_GROUP_NOTIFY,
|
vfio_unregister_notifier(mdev_dev(vgpu->vdev.mdev), VFIO_GROUP_NOTIFY,
|
||||||
&vgpu->vdev.group_notifier);
|
&vgpu->vdev.group_notifier);
|
||||||
|
|
||||||
info = (struct kvmgt_guest_info *)vgpu->handle;
|
info = (struct kvmgt_guest_info *)vgpu->handle;
|
||||||
|
@ -1372,7 +1372,7 @@ static unsigned long kvmgt_gfn_to_pfn(unsigned long handle, unsigned long gfn)
|
||||||
return pfn;
|
return pfn;
|
||||||
|
|
||||||
pfn = INTEL_GVT_INVALID_ADDR;
|
pfn = INTEL_GVT_INVALID_ADDR;
|
||||||
dev = &info->vgpu->vdev.mdev->dev;
|
dev = mdev_dev(info->vgpu->vdev.mdev);
|
||||||
rc = vfio_pin_pages(dev, &gfn, 1, IOMMU_READ | IOMMU_WRITE, &pfn);
|
rc = vfio_pin_pages(dev, &gfn, 1, IOMMU_READ | IOMMU_WRITE, &pfn);
|
||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
gvt_err("vfio_pin_pages failed for gfn 0x%lx: %d\n", gfn, rc);
|
gvt_err("vfio_pin_pages failed for gfn 0x%lx: %d\n", gfn, rc);
|
||||||
|
|
|
@ -36,6 +36,36 @@ struct device *mdev_parent_dev(struct mdev_device *mdev)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(mdev_parent_dev);
|
EXPORT_SYMBOL(mdev_parent_dev);
|
||||||
|
|
||||||
|
void *mdev_get_drvdata(struct mdev_device *mdev)
|
||||||
|
{
|
||||||
|
return mdev->driver_data;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(mdev_get_drvdata);
|
||||||
|
|
||||||
|
void mdev_set_drvdata(struct mdev_device *mdev, void *data)
|
||||||
|
{
|
||||||
|
mdev->driver_data = data;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(mdev_set_drvdata);
|
||||||
|
|
||||||
|
struct device *mdev_dev(struct mdev_device *mdev)
|
||||||
|
{
|
||||||
|
return &mdev->dev;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(mdev_dev);
|
||||||
|
|
||||||
|
struct mdev_device *mdev_from_dev(struct device *dev)
|
||||||
|
{
|
||||||
|
return dev_is_mdev(dev) ? to_mdev_device(dev) : NULL;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(mdev_from_dev);
|
||||||
|
|
||||||
|
uuid_le mdev_uuid(struct mdev_device *mdev)
|
||||||
|
{
|
||||||
|
return mdev->uuid;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(mdev_uuid);
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
@ -26,6 +26,19 @@ struct mdev_parent {
|
||||||
struct list_head type_list;
|
struct list_head type_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct mdev_device {
|
||||||
|
struct device dev;
|
||||||
|
struct mdev_parent *parent;
|
||||||
|
uuid_le uuid;
|
||||||
|
void *driver_data;
|
||||||
|
struct kref ref;
|
||||||
|
struct list_head next;
|
||||||
|
struct kobject *type_kobj;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define to_mdev_device(dev) container_of(dev, struct mdev_device, dev)
|
||||||
|
#define dev_is_mdev(d) ((d)->bus == &mdev_bus_type)
|
||||||
|
|
||||||
struct mdev_type {
|
struct mdev_type {
|
||||||
struct kobject kobj;
|
struct kobject kobj;
|
||||||
struct kobject *devices_kobj;
|
struct kobject *devices_kobj;
|
||||||
|
|
|
@ -13,18 +13,7 @@
|
||||||
#ifndef MDEV_H
|
#ifndef MDEV_H
|
||||||
#define MDEV_H
|
#define MDEV_H
|
||||||
|
|
||||||
/* Mediated device */
|
struct mdev_device;
|
||||||
struct mdev_device {
|
|
||||||
struct device dev;
|
|
||||||
struct mdev_parent *parent;
|
|
||||||
uuid_le uuid;
|
|
||||||
void *driver_data;
|
|
||||||
|
|
||||||
/* internal */
|
|
||||||
struct kref ref;
|
|
||||||
struct list_head next;
|
|
||||||
struct kobject *type_kobj;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct mdev_parent_ops - Structure to be registered for each parent device to
|
* struct mdev_parent_ops - Structure to be registered for each parent device to
|
||||||
|
@ -75,7 +64,6 @@ struct mdev_device {
|
||||||
* Parent device that support mediated device should be registered with mdev
|
* Parent device that support mediated device should be registered with mdev
|
||||||
* module with mdev_parent_ops structure.
|
* module with mdev_parent_ops structure.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
struct mdev_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;
|
||||||
|
@ -129,22 +117,13 @@ struct mdev_driver {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define to_mdev_driver(drv) container_of(drv, struct mdev_driver, driver)
|
#define to_mdev_driver(drv) container_of(drv, struct mdev_driver, driver)
|
||||||
#define to_mdev_device(dev) container_of(dev, struct mdev_device, dev)
|
|
||||||
|
|
||||||
static inline void *mdev_get_drvdata(struct mdev_device *mdev)
|
extern void *mdev_get_drvdata(struct mdev_device *mdev);
|
||||||
{
|
extern void mdev_set_drvdata(struct mdev_device *mdev, void *data);
|
||||||
return mdev->driver_data;
|
extern uuid_le mdev_uuid(struct mdev_device *mdev);
|
||||||
}
|
|
||||||
|
|
||||||
static inline void mdev_set_drvdata(struct mdev_device *mdev, void *data)
|
|
||||||
{
|
|
||||||
mdev->driver_data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern struct bus_type mdev_bus_type;
|
extern struct bus_type 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 mdev_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);
|
||||||
|
@ -153,5 +132,7 @@ 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);
|
extern struct device *mdev_parent_dev(struct mdev_device *mdev);
|
||||||
|
extern struct device *mdev_dev(struct mdev_device *mdev);
|
||||||
|
extern struct mdev_device *mdev_from_dev(struct device *dev);
|
||||||
|
|
||||||
#endif /* MDEV_H */
|
#endif /* MDEV_H */
|
||||||
|
|
|
@ -164,7 +164,7 @@ static struct mdev_state *find_mdev_state_by_uuid(uuid_le uuid)
|
||||||
struct mdev_state *mds;
|
struct mdev_state *mds;
|
||||||
|
|
||||||
list_for_each_entry(mds, &mdev_devices_list, next) {
|
list_for_each_entry(mds, &mdev_devices_list, next) {
|
||||||
if (uuid_le_cmp(mds->mdev->uuid, uuid) == 0)
|
if (uuid_le_cmp(mdev_uuid(mds->mdev), uuid) == 0)
|
||||||
return mds;
|
return mds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +341,8 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
|
||||||
pr_err("Serial port %d: Fifo level trigger\n",
|
pr_err("Serial port %d: Fifo level trigger\n",
|
||||||
index);
|
index);
|
||||||
#endif
|
#endif
|
||||||
mtty_trigger_interrupt(mdev_state->mdev->uuid);
|
mtty_trigger_interrupt(
|
||||||
|
mdev_uuid(mdev_state->mdev));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#if defined(DEBUG_INTR)
|
#if defined(DEBUG_INTR)
|
||||||
|
@ -355,7 +356,8 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
|
||||||
*/
|
*/
|
||||||
if (mdev_state->s[index].uart_reg[UART_IER] &
|
if (mdev_state->s[index].uart_reg[UART_IER] &
|
||||||
UART_IER_RLSI)
|
UART_IER_RLSI)
|
||||||
mtty_trigger_interrupt(mdev_state->mdev->uuid);
|
mtty_trigger_interrupt(
|
||||||
|
mdev_uuid(mdev_state->mdev));
|
||||||
}
|
}
|
||||||
mutex_unlock(&mdev_state->rxtx_lock);
|
mutex_unlock(&mdev_state->rxtx_lock);
|
||||||
break;
|
break;
|
||||||
|
@ -374,7 +376,8 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
|
||||||
pr_err("Serial port %d: IER_THRI write\n",
|
pr_err("Serial port %d: IER_THRI write\n",
|
||||||
index);
|
index);
|
||||||
#endif
|
#endif
|
||||||
mtty_trigger_interrupt(mdev_state->mdev->uuid);
|
mtty_trigger_interrupt(
|
||||||
|
mdev_uuid(mdev_state->mdev));
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_unlock(&mdev_state->rxtx_lock);
|
mutex_unlock(&mdev_state->rxtx_lock);
|
||||||
|
@ -445,7 +448,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
|
||||||
#if defined(DEBUG_INTR)
|
#if defined(DEBUG_INTR)
|
||||||
pr_err("Serial port %d: MCR_OUT2 write\n", index);
|
pr_err("Serial port %d: MCR_OUT2 write\n", index);
|
||||||
#endif
|
#endif
|
||||||
mtty_trigger_interrupt(mdev_state->mdev->uuid);
|
mtty_trigger_interrupt(mdev_uuid(mdev_state->mdev));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mdev_state->s[index].uart_reg[UART_IER] & UART_IER_MSI) &&
|
if ((mdev_state->s[index].uart_reg[UART_IER] & UART_IER_MSI) &&
|
||||||
|
@ -453,7 +456,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state,
|
||||||
#if defined(DEBUG_INTR)
|
#if defined(DEBUG_INTR)
|
||||||
pr_err("Serial port %d: MCR RTS/DTR write\n", index);
|
pr_err("Serial port %d: MCR RTS/DTR write\n", index);
|
||||||
#endif
|
#endif
|
||||||
mtty_trigger_interrupt(mdev_state->mdev->uuid);
|
mtty_trigger_interrupt(mdev_uuid(mdev_state->mdev));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -504,7 +507,8 @@ static void handle_bar_read(unsigned int index, struct mdev_state *mdev_state,
|
||||||
#endif
|
#endif
|
||||||
if (mdev_state->s[index].uart_reg[UART_IER] &
|
if (mdev_state->s[index].uart_reg[UART_IER] &
|
||||||
UART_IER_THRI)
|
UART_IER_THRI)
|
||||||
mtty_trigger_interrupt(mdev_state->mdev->uuid);
|
mtty_trigger_interrupt(
|
||||||
|
mdev_uuid(mdev_state->mdev));
|
||||||
}
|
}
|
||||||
mutex_unlock(&mdev_state->rxtx_lock);
|
mutex_unlock(&mdev_state->rxtx_lock);
|
||||||
|
|
||||||
|
@ -1298,10 +1302,8 @@ static ssize_t
|
||||||
sample_mdev_dev_show(struct device *dev, struct device_attribute *attr,
|
sample_mdev_dev_show(struct device *dev, struct device_attribute *attr,
|
||||||
char *buf)
|
char *buf)
|
||||||
{
|
{
|
||||||
struct mdev_device *mdev = to_mdev_device(dev);
|
if (mdev_from_dev(dev))
|
||||||
|
return sprintf(buf, "This is MDEV %s\n", dev_name(dev));
|
||||||
if (mdev)
|
|
||||||
return sprintf(buf, "This is MDEV %s\n", dev_name(&mdev->dev));
|
|
||||||
|
|
||||||
return sprintf(buf, "\n");
|
return sprintf(buf, "\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue