[PATCH 3/3] drivers: firmware: add ARM on s390 accelerator driver

From: Sven Schnelle

Date: Fri Dec 04 2026 - 09:47:37 EST


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@xxxxxxxxxxxxx>
---
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