From: Sven Schnelle <svens@linux.ibm.com>
To: Marc Zyngier <maz@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
"Joerg Roedel (AMD)" <joro@8bytes.org>,
Will Deacon <will@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Sudeep Holla <sudeep.holla@kernel.org>,
Ard Biesheuvel <ardb@kernel.org>,
linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Hendrik Brueckner <brueckner@linux.ibm.com>,
Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
Arnd Bergmann <arnd@arndb.de>,
linux-s390@vger.kernel.org
Subject: [PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver
Date: Fri, 4 Dec 2026 15:45:29 +0100 [thread overview]
Message-ID: <20261204144529.960326-4-svens@linux.ibm.com> (raw)
In-Reply-To: <20261204144529.960326-1-svens@linux.ibm.com>
s390 support for ARM guests supports hardware acceleration for
crypto and other functions. This is implemented by providing a special
memory region that can be accessed via st64bv0. To allow userspace to
utilize this functionality, add a driver to map the accelerator memory
region into the userspace process. Note that the misc device files
are created with permission 0666 so all userspace processes can use
the driver without additional configuration.
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
---
drivers/firmware/Kconfig | 10 ++
drivers/firmware/Makefile | 1 +
drivers/firmware/platform-accel.c | 168 ++++++++++++++++++++++++++++++
3 files changed, 179 insertions(+)
create mode 100644 drivers/firmware/platform-accel.c
diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index 43e2e2a64594..bc90aa19b5d3 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -299,6 +299,16 @@ config TURRIS_MOX_RWTM_KEYCTL
endif # TURRIS_MOX_RWTM
+config PLATFORM_ACCEL
+ tristate "Acceleration driver for arm64"
+ depends on ARM64
+ select IOMMU_SVA
+ help
+ Say y here to enable the platform driver for providing a userspace
+ device to utilize acceleration in s390 ARM KVM guests. This works by
+ providing a misc device which can be used to mmap() the required
+ memory region and perform functions with st64bv0 on it.
+
source "drivers/firmware/arm_ffa/Kconfig"
source "drivers/firmware/arm_rmm/Kconfig"
source "drivers/firmware/broadcom/Kconfig"
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
index 50b338313152..c76e84872fc1 100644
--- a/drivers/firmware/Makefile
+++ b/drivers/firmware/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_TH1520_AON_PROTOCOL) += thead,th1520-aon.o
obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o
obj-$(CONFIG_TRUSTED_FOUNDATIONS) += trusted_foundations.o
obj-$(CONFIG_TURRIS_MOX_RWTM) += turris-mox-rwtm.o
+obj-$(CONFIG_PLATFORM_ACCEL) += platform-accel.o
obj-y += arm_ffa/
obj-y += arm_rmm/
diff --git a/drivers/firmware/platform-accel.c b/drivers/firmware/platform-accel.c
new file mode 100644
index 000000000000..0e77a8243d03
--- /dev/null
+++ b/drivers/firmware/platform-accel.c
@@ -0,0 +1,168 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/platform_device.h>
+#include <linux/acpi.h>
+#include <linux/io.h>
+#include <linux/mm.h>
+#include <linux/miscdevice.h>
+#include <linux/iommu.h>
+#include <linux/cpufeature.h>
+#include <linux/pgtable.h>
+
+struct platform_accel {
+ struct platform_device *pdev;
+ resource_size_t phys_size;
+ phys_addr_t phys_base;
+ struct miscdevice misc;
+ struct mutex lock;
+ bool present;
+};
+
+static int platform_accel_mmap(struct file *filep, struct vm_area_struct *vma)
+{
+ struct miscdevice *misc = filep->private_data;
+ struct platform_accel *dev = container_of(misc, struct platform_accel, misc);
+ int ret = -ENODEV;
+
+ mutex_lock(&dev->lock);
+ if (!dev->present)
+ goto out;
+
+ ret = iommu_sva_bind_device_no_iommu(&dev->pdev->dev, current->mm);
+ if (ret)
+ goto out;
+ vma->vm_page_prot = pgprot_device(vma->vm_page_prot);
+ ret = vm_iomap_memory(vma, dev->phys_base, dev->phys_size);
+out:
+ mutex_unlock(&dev->lock);
+ return ret;
+}
+
+static const struct file_operations platform_accel_fops = {
+ .owner = THIS_MODULE,
+ .open = nonseekable_open,
+ .mmap = platform_accel_mmap,
+};
+
+static struct platform_accel platform_accel_dev_cpacf = {
+ .misc = {
+ .name = "platform-accel-cpacf",
+ .minor = MISC_DYNAMIC_MINOR,
+ .fops = &platform_accel_fops,
+ .mode = 0666,
+ },
+ .lock = __MUTEX_INITIALIZER(platform_accel_dev_cpacf.lock),
+};
+
+static struct platform_accel platform_accel_dev_dfltcc = {
+ .misc = {
+ .name = "platform-accel-dfltcc",
+ .minor = MISC_DYNAMIC_MINOR,
+ .fops = &platform_accel_fops,
+ .mode = 0666,
+ },
+ .lock = __MUTEX_INITIALIZER(platform_accel_dev_dfltcc.lock),
+};
+
+static int platform_accel_do_platform_probe(struct platform_device *pdev)
+{
+ struct platform_accel *dev = platform_get_drvdata(pdev);
+ struct resource *r;
+ void __iomem *ret;
+
+ ret = devm_platform_get_and_ioremap_resource(pdev, 0, &r);
+ if (IS_ERR(ret))
+ return PTR_ERR(ret);
+
+ dev_info(&pdev->dev, "mmio at %pR\n", r);
+ dev->phys_base = r->start;
+ dev->phys_size = resource_size(r);
+ dev->pdev = pdev;
+ return 0;
+}
+
+static int platform_accel_probe(struct platform_device *pdev)
+{
+ struct platform_accel *dev;
+ int err;
+
+ if (!system_supports_ls64_accdata())
+ return -ENODEV;
+
+ dev = (struct platform_accel *)device_get_match_data(&pdev->dev);
+ if (!dev)
+ return -EINVAL;
+
+ mutex_lock(&dev->lock);
+ if (dev->present) {
+ err = -EBUSY;
+ goto out;
+ }
+ platform_set_drvdata(pdev, dev);
+
+ err = platform_accel_do_platform_probe(pdev);
+ if (err)
+ goto err_clear;
+
+ dev->present = true;
+ err = misc_register(&dev->misc);
+ if (err)
+ goto err_cleanup;
+ mutex_unlock(&dev->lock);
+ return 0;
+
+err_cleanup:
+ dev->present = false;
+err_clear:
+ platform_set_drvdata(pdev, NULL);
+out:
+ mutex_unlock(&dev->lock);
+ return err;
+}
+
+static void platform_accel_remove(struct platform_device *pdev)
+{
+ struct platform_accel *dev = platform_get_drvdata(pdev);
+
+ mutex_lock(&dev->lock);
+ misc_deregister(&dev->misc);
+ dev->present = false;
+ platform_set_drvdata(pdev, NULL);
+ dev->pdev = NULL;
+ mutex_unlock(&dev->lock);
+}
+
+static const struct of_device_id platform_accel_of_match[] = {
+ { .compatible = "ibm,platform-accel-v1.0-cpacf", .data = &platform_accel_dev_cpacf },
+ { .compatible = "ibm,platform-accel-v1.0-dfltcc", .data = &platform_accel_dev_dfltcc },
+ {},
+};
+MODULE_DEVICE_TABLE(of, platform_accel_of_match);
+
+#if IS_ENABLED(CONFIG_ACPI)
+static const struct acpi_device_id platform_accel_acpi_match[] = {
+ { "IBM077A", (kernel_ulong_t)&platform_accel_dev_cpacf },
+ { "IBM077B", (kernel_ulong_t)&platform_accel_dev_dfltcc },
+ {},
+};
+MODULE_DEVICE_TABLE(acpi, platform_accel_acpi_match);
+#endif
+
+static struct platform_driver platform_accel_driver = {
+ .probe = platform_accel_probe,
+ .remove = platform_accel_remove,
+ .driver = {
+ .name = "platform-accel",
+ .of_match_table = platform_accel_of_match,
+#if IS_ENABLED(CONFIG_ACPI)
+ .acpi_match_table = ACPI_PTR(platform_accel_acpi_match),
+#endif
+ },
+};
+
+module_platform_driver(platform_accel_driver);
+
+MODULE_AUTHOR("IBM Corporation");
+MODULE_DESCRIPTION("IBM s390 ARM acceleration platform driver");
+MODULE_LICENSE("GPL");
--
2.56.1
next prev parent reply other threads:[~2026-12-04 14:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 14:45 [PATCH 0/3] Add arm on s390 accelerator driver Sven Schnelle
2026-12-04 14:45 ` [PATCH 1/3] iommu: sva: allow SVA without PASID Sven Schnelle
2026-12-04 14:45 ` [PATCH 2/3] dt-bindings: firmware: platform-accel: add yaml documentation Sven Schnelle
2026-12-04 14:45 ` Sven Schnelle [this message]
2026-12-04 15:28 ` [PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver Arnd Bergmann
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=20261204144529.960326-4-svens@linux.ibm.com \
--to=svens@linux.ibm.com \
--cc=Ulrich.Weigand@de.ibm.com \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=borntraeger@linux.ibm.com \
--cc=brueckner@linux.ibm.com \
--cc=catalin.marinas@arm.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=robin.murphy@arm.com \
--cc=sudeep.holla@kernel.org \
--cc=will@kernel.org \
/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