diff mbox series

[RFC,v2,4/6] vfio_platform: reset: Introduce new init and release callbacks

Message ID 20240917093851.990344-5-eric.auger@redhat.com (mailing list archive)
State New
Headers show
Series vfio: platform: reset: Introduce tegra234 mgbe reset module | expand

Commit Message

Eric Auger Sept. 17, 2024, 9:38 a.m. UTC
Some devices may require resources such as clocks and resets
which cannot be handled in the vfio_platform agnostic code. Let's
add 2 new callbacks to handle those resources. Those new callbacks
are optional, as opposed to the reset callback. In case they are
implemented, both need to be.

They are not implemented by the existing reset modules.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
 drivers/vfio/platform/vfio_platform_common.c  | 23 ++++++++++++++++++-
 drivers/vfio/platform/vfio_platform_private.h |  6 +++++
 2 files changed, 28 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
index cd0f2ebff586..8d40ca452bbb 100644
--- a/drivers/vfio/platform/vfio_platform_common.c
+++ b/drivers/vfio/platform/vfio_platform_common.c
@@ -228,6 +228,23 @@  static int vfio_platform_call_reset(struct vfio_platform_device *vdev,
 	return -EINVAL;
 }
 
+static void vfio_platform_reset_module_release(struct vfio_platform_device *vpdev)
+{
+	if (VFIO_PLATFORM_IS_ACPI(vpdev))
+		return;
+	if (vpdev->of_reset_ops && vpdev->of_reset_ops->release)
+		vpdev->of_reset_ops->release(vpdev);
+}
+
+static int vfio_platform_reset_module_init(struct vfio_platform_device *vpdev)
+{
+	if (VFIO_PLATFORM_IS_ACPI(vpdev))
+		return 0;
+	if (vpdev->of_reset_ops && vpdev->of_reset_ops->init)
+		return vpdev->of_reset_ops->init(vpdev);
+	return 0;
+}
+
 void vfio_platform_close_device(struct vfio_device *core_vdev)
 {
 	struct vfio_platform_device *vdev =
@@ -665,12 +682,16 @@  int vfio_platform_init_common(struct vfio_platform_device *vdev)
 		return ret;
 	}
 
-	return 0;
+	ret = vfio_platform_reset_module_init(vdev);
+	if (ret)
+		vfio_platform_put_reset(vdev);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(vfio_platform_init_common);
 
 void vfio_platform_release_common(struct vfio_platform_device *vdev)
 {
+	vfio_platform_reset_module_release(vdev);
 	vfio_platform_put_reset(vdev);
 	vfio_platform_regions_cleanup(vdev);
 }
diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h
index 333aefe2a1fc..33183addd235 100644
--- a/drivers/vfio/platform/vfio_platform_private.h
+++ b/drivers/vfio/platform/vfio_platform_private.h
@@ -74,9 +74,13 @@  struct vfio_platform_device {
  * struct vfio_platform_of_reset_ops - reset ops
  *
  * @reset:	reset function (required)
+ * @init:	Called on device attach (optional)
+ * @release:	Called on device detach (optional)
  */
 struct vfio_platform_of_reset_ops {
 	int (*reset)(struct vfio_platform_device *vdev);
+	int (*init)(struct vfio_platform_device *vdev);
+	void (*release)(struct vfio_platform_device *vdev);
 };
 
 
@@ -129,6 +133,8 @@  __vfio_platform_register_reset(&__ops ## _node)
 MODULE_ALIAS("vfio-reset:" compat);				\
 static int __init reset ## _module_init(void)			\
 {								\
+	if (!!ops.init ^ !!ops.release)				\
+		return -EINVAL;					\
 	vfio_platform_register_reset(compat, ops);		\
 	return 0;						\
 };								\