aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/vfio/mdev/mdev_driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/vfio/mdev/mdev_driver.c')
-rw-r--r--drivers/vfio/mdev/mdev_driver.c83
1 files changed, 21 insertions, 62 deletions
diff --git a/drivers/vfio/mdev/mdev_driver.c b/drivers/vfio/mdev/mdev_driver.c
index 0d3223aee20b..7825d83a55f8 100644
--- a/drivers/vfio/mdev/mdev_driver.c
+++ b/drivers/vfio/mdev/mdev_driver.c
@@ -7,65 +7,36 @@
* Kirti Wankhede <kwankhede@nvidia.com>
*/
-#include <linux/device.h>
#include <linux/iommu.h>
#include <linux/mdev.h>
#include "mdev_private.h"
-static int mdev_attach_iommu(struct mdev_device *mdev)
+static int mdev_probe(struct device *dev)
{
- int ret;
- struct iommu_group *group;
-
- group = iommu_group_alloc();
- if (IS_ERR(group))
- return PTR_ERR(group);
-
- ret = iommu_group_add_device(group, &mdev->dev);
- if (!ret)
- dev_info(&mdev->dev, "MDEV: group_id = %d\n",
- iommu_group_id(group));
-
- iommu_group_put(group);
- return ret;
-}
+ struct mdev_driver *drv =
+ container_of(dev->driver, struct mdev_driver, driver);
-static void mdev_detach_iommu(struct mdev_device *mdev)
-{
- iommu_group_remove_device(&mdev->dev);
- dev_info(&mdev->dev, "MDEV: detaching iommu\n");
+ if (!drv->probe)
+ return 0;
+ return drv->probe(to_mdev_device(dev));
}
-static int mdev_probe(struct device *dev)
+static void mdev_remove(struct device *dev)
{
- struct mdev_driver *drv = to_mdev_driver(dev->driver);
- struct mdev_device *mdev = to_mdev_device(dev);
- int ret;
-
- ret = mdev_attach_iommu(mdev);
- if (ret)
- return ret;
+ struct mdev_driver *drv =
+ container_of(dev->driver, struct mdev_driver, driver);
- if (drv && drv->probe) {
- ret = drv->probe(dev);
- if (ret)
- mdev_detach_iommu(mdev);
- }
-
- return ret;
+ if (drv->remove)
+ drv->remove(to_mdev_device(dev));
}
-static int mdev_remove(struct device *dev)
+static int mdev_match(struct device *dev, struct device_driver *drv)
{
- struct mdev_driver *drv = to_mdev_driver(dev->driver);
- struct mdev_device *mdev = to_mdev_device(dev);
-
- if (drv && drv->remove)
- drv->remove(dev);
-
- mdev_detach_iommu(mdev);
-
+ /*
+ * No drivers automatically match. Drivers are only bound by explicit
+ * device_driver_attach()
+ */
return 0;
}
@@ -73,24 +44,22 @@ struct bus_type mdev_bus_type = {
.name = "mdev",
.probe = mdev_probe,
.remove = mdev_remove,
+ .match = mdev_match,
};
-EXPORT_SYMBOL_GPL(mdev_bus_type);
/**
* mdev_register_driver - register a new MDEV driver
* @drv: the driver to register
- * @owner: module owner of driver to be registered
*
* Returns a negative value on error, otherwise 0.
**/
-int mdev_register_driver(struct mdev_driver *drv, struct module *owner)
+int mdev_register_driver(struct mdev_driver *drv)
{
+ if (!drv->device_api)
+ return -EINVAL;
+
/* initialize common driver fields */
- drv->driver.name = drv->name;
drv->driver.bus = &mdev_bus_type;
- drv->driver.owner = owner;
-
- /* register with core */
return driver_register(&drv->driver);
}
EXPORT_SYMBOL(mdev_register_driver);
@@ -104,13 +73,3 @@ void mdev_unregister_driver(struct mdev_driver *drv)
driver_unregister(&drv->driver);
}
EXPORT_SYMBOL(mdev_unregister_driver);
-
-int mdev_bus_register(void)
-{
- return bus_register(&mdev_bus_type);
-}
-
-void mdev_bus_unregister(void)
-{
- bus_unregister(&mdev_bus_type);
-}