From: Eric Auger <eric.auger@redhat.com>
To: eric.auger.pro@gmail.com, eric.auger@redhat.com,
treding@nvidia.com, vbhadram@nvidia.com, jonathanh@nvidia.com,
mperttunen@nvidia.com, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, alex.williamson@redhat.com, clg@redhat.com,
alexandre.torgue@foss.st.com, joabreu@synopsys.com
Cc: msalter@redhat.com
Subject: [RFC PATCH 2/5] vfio_platform: reset: Prepare for additional reset ops
Date: Thu, 29 Aug 2024 18:11:06 +0200 [thread overview]
Message-ID: <20240829161302.607928-3-eric.auger@redhat.com> (raw)
In-Reply-To: <20240829161302.607928-1-eric.auger@redhat.com>
Reset modules currently offer a single reset function that gets
called on open, close and VFIO_DEVICE_RESET ioctl.
For more complex devices this infrastructure looks too simplistic.
Indeed some resources may be needed from the open() until the close(),
like clocks, resets. A single function does not allow that setup.
So let's encapsulate the current reset function into an ops struct
that will be soon extended with new open and close callbacks.
Existing reset modules are adapted.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
.../platform/reset/vfio_platform_amdxgbe.c | 7 +++-
.../reset/vfio_platform_calxedaxgmac.c | 7 +++-
drivers/vfio/platform/vfio_platform_common.c | 36 ++++++++++---------
drivers/vfio/platform/vfio_platform_private.h | 30 ++++++++++------
4 files changed, 50 insertions(+), 30 deletions(-)
diff --git a/drivers/vfio/platform/reset/vfio_platform_amdxgbe.c b/drivers/vfio/platform/reset/vfio_platform_amdxgbe.c
index abdca900802d..6d1b641480f4 100644
--- a/drivers/vfio/platform/reset/vfio_platform_amdxgbe.c
+++ b/drivers/vfio/platform/reset/vfio_platform_amdxgbe.c
@@ -109,7 +109,12 @@ static int vfio_platform_amdxgbe_reset(struct vfio_platform_device *vdev)
return 0;
}
-module_vfio_reset_handler("amd,xgbe-seattle-v1a", vfio_platform_amdxgbe_reset);
+static const struct vfio_platform_reset_ops
+vfio_platform_amdxgbe_reset_ops = {
+ .reset = vfio_platform_amdxgbe_reset,
+};
+
+module_vfio_reset_handler("amd,xgbe-seattle-v1a", vfio_platform_amdxgbe_reset_ops);
MODULE_VERSION("0.1");
MODULE_LICENSE("GPL v2");
diff --git a/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c b/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c
index 63cc7f0b2e4a..392a8579f491 100644
--- a/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c
+++ b/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c
@@ -66,7 +66,12 @@ static int vfio_platform_calxedaxgmac_reset(struct vfio_platform_device *vdev)
return 0;
}
-module_vfio_reset_handler("calxeda,hb-xgmac", vfio_platform_calxedaxgmac_reset);
+static const struct vfio_platform_reset_ops
+vfio_platform_calxedaxgmac_reset_ops = {
+ .reset = vfio_platform_calxedaxgmac_reset,
+};
+
+module_vfio_reset_handler("calxeda,hb-xgmac", vfio_platform_calxedaxgmac_reset_ops);
MODULE_VERSION(DRIVER_VERSION);
MODULE_LICENSE("GPL v2");
diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
index 6861f977fd5b..3be08e58365b 100644
--- a/drivers/vfio/platform/vfio_platform_common.c
+++ b/drivers/vfio/platform/vfio_platform_common.c
@@ -28,23 +28,23 @@
static LIST_HEAD(reset_list);
static DEFINE_MUTEX(driver_lock);
-static vfio_platform_reset_fn_t vfio_platform_lookup_reset(const char *compat,
- struct module **module)
+static const struct vfio_platform_reset_ops *
+vfio_platform_lookup_reset(const char *compat, struct module **module)
{
+ const struct vfio_platform_reset_ops *ops = NULL;
struct vfio_platform_reset_node *iter;
- vfio_platform_reset_fn_t reset_fn = NULL;
mutex_lock(&driver_lock);
list_for_each_entry(iter, &reset_list, link) {
if (!strcmp(iter->compat, compat) &&
try_module_get(iter->owner)) {
*module = iter->owner;
- reset_fn = iter->of_reset;
+ ops = &iter->ops;
break;
}
}
mutex_unlock(&driver_lock);
- return reset_fn;
+ return ops;
}
static int vfio_platform_acpi_probe(struct vfio_platform_device *vdev,
@@ -106,7 +106,7 @@ static bool vfio_platform_has_reset(struct vfio_platform_device *vdev)
if (VFIO_PLATFORM_IS_ACPI(vdev))
return vfio_platform_acpi_has_reset(vdev);
- return vdev->of_reset ? true : false;
+ return vdev->reset_ops ? true : false;
}
static int vfio_platform_get_reset(struct vfio_platform_device *vdev)
@@ -114,15 +114,15 @@ static int vfio_platform_get_reset(struct vfio_platform_device *vdev)
if (VFIO_PLATFORM_IS_ACPI(vdev))
return vfio_platform_acpi_has_reset(vdev) ? 0 : -ENOENT;
- vdev->of_reset = vfio_platform_lookup_reset(vdev->compat,
- &vdev->reset_module);
- if (!vdev->of_reset) {
+ vdev->reset_ops = vfio_platform_lookup_reset(vdev->compat,
+ &vdev->reset_module);
+ if (!vdev->reset_ops) {
request_module("vfio-reset:%s", vdev->compat);
- vdev->of_reset = vfio_platform_lookup_reset(vdev->compat,
- &vdev->reset_module);
+ vdev->reset_ops = vfio_platform_lookup_reset(vdev->compat,
+ &vdev->reset_module);
}
- return vdev->of_reset ? 0 : -ENOENT;
+ return vdev->reset_ops ? 0 : -ENOENT;
}
static void vfio_platform_put_reset(struct vfio_platform_device *vdev)
@@ -130,7 +130,7 @@ static void vfio_platform_put_reset(struct vfio_platform_device *vdev)
if (VFIO_PLATFORM_IS_ACPI(vdev))
return;
- if (vdev->of_reset)
+ if (vdev->reset_ops)
module_put(vdev->reset_module);
}
@@ -219,9 +219,9 @@ static int vfio_platform_call_reset(struct vfio_platform_device *vdev,
if (VFIO_PLATFORM_IS_ACPI(vdev)) {
dev_info(vdev->device, "reset\n");
return vfio_platform_acpi_call_reset(vdev, extra_dbg);
- } else if (vdev->of_reset) {
+ } else if (vdev->reset_ops && vdev->reset_ops->reset) {
dev_info(vdev->device, "reset\n");
- return vdev->of_reset(vdev);
+ return vdev->reset_ops->reset(vdev);
}
dev_warn(vdev->device, "no reset function found!\n");
@@ -686,13 +686,15 @@ void __vfio_platform_register_reset(struct vfio_platform_reset_node *node)
EXPORT_SYMBOL_GPL(__vfio_platform_register_reset);
void vfio_platform_unregister_reset(const char *compat,
- vfio_platform_reset_fn_t fn)
+ struct vfio_platform_reset_ops ops)
{
struct vfio_platform_reset_node *iter, *temp;
mutex_lock(&driver_lock);
list_for_each_entry_safe(iter, temp, &reset_list, link) {
- if (!strcmp(iter->compat, compat) && (iter->of_reset == fn)) {
+ if (!strcmp(iter->compat, compat) &&
+ !memcmp(&iter->ops, &ops,
+ sizeof(struct vfio_platform_reset_ops))) {
list_del(&iter->link);
break;
}
diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h
index 20d67634bc41..90c99d2e70f4 100644
--- a/drivers/vfio/platform/vfio_platform_private.h
+++ b/drivers/vfio/platform/vfio_platform_private.h
@@ -65,18 +65,26 @@ struct vfio_platform_device {
struct resource*
(*get_resource)(struct vfio_platform_device *vdev, int i);
int (*get_irq)(struct vfio_platform_device *vdev, int i);
- int (*of_reset)(struct vfio_platform_device *vdev);
+ const struct vfio_platform_reset_ops *reset_ops;
bool reset_required;
};
-typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev);
+/**
+ * struct vfio_platform_reset_ops - reset ops
+ *
+ * @reset: reset function (required)
+ */
+struct vfio_platform_reset_ops {
+ int (*reset)(struct vfio_platform_device *vdev);
+};
+
struct vfio_platform_reset_node {
struct list_head link;
char *compat;
struct module *owner;
- vfio_platform_reset_fn_t of_reset;
+ struct vfio_platform_reset_ops ops;
};
int vfio_platform_init_common(struct vfio_platform_device *vdev);
@@ -104,29 +112,29 @@ int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
void __vfio_platform_register_reset(struct vfio_platform_reset_node *n);
void vfio_platform_unregister_reset(const char *compat,
- vfio_platform_reset_fn_t fn);
+ struct vfio_platform_reset_ops ops);
struct vfio_platform_region *
vfio_platform_get_region(struct vfio_platform_device *vdev, const char *name);
-#define vfio_platform_register_reset(__compat, __reset) \
-static struct vfio_platform_reset_node __reset ## _node = { \
+#define vfio_platform_register_reset(__compat, __ops) \
+static struct vfio_platform_reset_node __ops ## _node = { \
.owner = THIS_MODULE, \
.compat = __compat, \
- .of_reset = __reset, \
+ .ops = __ops, \
}; \
-__vfio_platform_register_reset(&__reset ## _node)
+__vfio_platform_register_reset(&__ops ## _node)
-#define module_vfio_reset_handler(compat, reset) \
+#define module_vfio_reset_handler(compat, ops) \
MODULE_ALIAS("vfio-reset:" compat); \
static int __init reset ## _module_init(void) \
{ \
- vfio_platform_register_reset(compat, reset); \
+ vfio_platform_register_reset(compat, ops); \
return 0; \
}; \
static void __exit reset ## _module_exit(void) \
{ \
- vfio_platform_unregister_reset(compat, reset); \
+ vfio_platform_unregister_reset(compat, ops); \
}; \
module_init(reset ## _module_init); \
module_exit(reset ## _module_exit)
--
2.41.0
next prev parent reply other threads:[~2024-08-29 16:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-29 16:11 [RFC PATCH 0/5] vfio: platform: reset: Introduce tegra234 mgbe reset module Eric Auger
2024-08-29 16:11 ` [RFC PATCH 1/5] vfio_platform: Introduce vfio_platform_get_region helper Eric Auger
2024-08-29 16:11 ` Eric Auger [this message]
2024-08-29 16:11 ` [RFC PATCH 3/5] vfio_platform: reset: Introduce new open and close callbacks Eric Auger
2024-08-29 23:21 ` Alex Williamson
2024-09-02 16:03 ` Eric Auger
2024-09-04 19:40 ` Alex Williamson
2024-09-11 12:18 ` Eric Auger
2024-08-29 16:11 ` [RFC PATCH 4/5] vfio-platform: Add a new handle to store reset data Eric Auger
2024-08-29 16:11 ` [RFC PATCH 5/5] vfio/platform: Add tegra234-mgbe vfio platform reset module Eric Auger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240829161302.607928-3-eric.auger@redhat.com \
--to=eric.auger@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=alexandre.torgue@foss.st.com \
--cc=clg@redhat.com \
--cc=eric.auger.pro@gmail.com \
--cc=joabreu@synopsys.com \
--cc=jonathanh@nvidia.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mperttunen@nvidia.com \
--cc=msalter@redhat.com \
--cc=treding@nvidia.com \
--cc=vbhadram@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox