Switch Arm SMCCC firmware services to an SMCCC bus
Subsystems (4)
v6 cover Switch Arm SMCCC firmware services to an SMCCC bus
As discussed here:
https://lore.kernel.org/all/[email protected]
The earlier CCA guest support used an arm-cca-dev platform device as a pure software anchor for the TSM class device. That platform device did not correspond to a DT/ACPI described device, MMIO range, interrupt, or other platform resource; it existed only to make the CCA guest driver bind and to place the resulting TSM device in the driver model. The same pattern also exists for smccc_trng. Creating separate platform devices for such SMCCC-discovered features is misleading, because those features are not independent platform devices.
This series adds an Arm SMCCC bus for services discovered through the SMCCC firmware interface. The bus provides SMCCC device and driver registration helpers, name-based matching, uevent modalias generation, and a sysfs modalias attribute. SMCCC service drivers can use MODULE_DEVICE_TABLE(arm_smccc, ...) to emit arm_smccc:<name> aliases, allowing userspace to autoload service drivers when the SMCCC core registers matching firmware-service devices.
The series then moves SMCCC TRNG and the Arm CCA guest RSI service off the platform bus. When the SMCCC core discovers the corresponding firmware service, it registers an arm-smccc device for that service. The hwrng arm_smccc_trng driver and the Arm CCA guest TSM provider are converted to SMCCC drivers that bind to those discovered devices.
The old arm-cca-dev platform device has also been used by userspace as a Realm guest indicator. Removing it without a replacement would leave userspace depending on an internal driver-binding device. This series therefore adds /sys/firmware/cca/realm_guest as a stable, architecture-provided ABI for detecting whether the kernel is running as an Arm CCA Realm guest, and then removes the dummy arm-cca-dev platform-device registration.
Changes from v5:
https://lore.kernel.org/all/[email protected]
* Replace the arm-smccc platform-device plus auxiliary-child model with a dedicated Arm SMCCC bus.
* Add SMCCC module alias support so SMCCC service drivers can use MODULE_DEVICE_TABLE(arm_smccc, ...) and autoload through arm_smccc:<name> aliases.
* Convert smccc_trng from a platform driver to an SMCCC driver.
* Convert the Arm CCA guest TSM provider from the arm-cca-dev platform device to an SMCCC driver bound to the discovered RSI service.
* Add /sys/firmware/cca/realm_guest before removing the old arm-cca-dev dummy platform device.
Changes from v4:
https://lore.kernel.org/all/[email protected]
* Add /sys/firmware/cca/realm_guest for detecting realm guest
* Convert smccc_trng to auxiliary device from platform device
Changes from v3:
https://lore.kernel.org/all/[email protected]
* Rebased onto the latest kernel
* Drop pr_fmt() from drivers/firmware/smccc/rmm.c
Aneesh Kumar K.V (Arm) (4):
firmware: smccc: Add an Arm SMCCC bus
firmware: hwrng: arm_smccc_trng: Register as an SMCCC device
firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC
device
coco: guest: arm64: Replace dummy CCA device with sysfs ABI
Documentation/ABI/testing/sysfs-firmware-cca | 10 +
arch/arm64/include/asm/rsi.h | 2 +-
arch/arm64/kernel/rsi.c | 39 +++-
drivers/char/hw_random/arm_smccc_trng.c | 26 +--
drivers/firmware/smccc/Makefile | 4 +
drivers/firmware/smccc/rmm.c | 25 +++
drivers/firmware/smccc/rmm.h | 17 ++
drivers/firmware/smccc/smccc.c | 178 +++++++++++++++++-
drivers/virt/coco/arm-cca-guest/Kconfig | 1 +
drivers/virt/coco/arm-cca-guest/Makefile | 2 +
.../{arm-cca-guest.c => arm-cca.c} | 60 +++---
include/linux/arm-smccc-bus.h | 49 +++++
include/linux/mod_devicetable.h | 13 ++
scripts/mod/devicetable-offsets.c | 3 +
scripts/mod/file2alias.c | 8 +
15 files changed, 378 insertions(+), 59 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-firmware-cca
create mode 100644 drivers/firmware/smccc/rmm.c
create mode 100644 drivers/firmware/smccc/rmm.h
rename drivers/virt/coco/arm-cca-guest/{arm-cca-guest.c => arm-cca.c} (85%)
create mode 100644 include/linux/arm-smccc-bus.hbase-commit: 50897c955902c93ae71c38698abb910525ebdc89
Signature · 1 line
2.43.0
PATCH v6 1/4 firmware: smccc: Add an Arm SMCCC bus
SMCCC-discovered firmware services are currently represented by separate platform devices, such as smccc_trng and arm-cca-dev. Those devices do not represent independent DT/ACPI-described platform resources; they are features of the SMCCC firmware interface.
Add an Arm SMCCC bus for services discovered through the SMCCC firmware interface. The bus provides SMCCC device and driver registration helpers, name-based matching, modalias generation, and a sysfs modalias attribute so SMCCC service drivers can bind to discovered firmware services and autoload as modules.
Follow-up changes can then register SMCCC firmware services as arm-smccc devices instead of creating independent per-feature platform devices.
Based on arm_ffa code
--- drivers/firmware/smccc/smccc.c | 158 ++++++++++++++++++++++++++++++ include/linux/arm-smccc-bus.h | 49 +++++++++ include/linux/mod_devicetable.h | 13 +++ scripts/mod/devicetable-offsets.c | 3 + scripts/mod/file2alias.c | 8 ++ 5 files changed, 231 insertions(+) create mode 100644 include/linux/arm-smccc-bus.h
drivers/firmware/smccc/smccc.c +158 -0
@@ -10,10 +10,15 @@#include <linux/arm-smccc.h> #include <linux/kernel.h> #include <linux/platform_device.h> +#include <linux/arm-smccc-bus.h> +#include <linux/idr.h> +#include <linux/slab.h> +#include <asm/archrandom.h> static u32 smccc_version =ARM_SMCCC_VERSION_1_0 ;static enum arm_smccc_conduit smccc_conduit =SMCCC_CONDUIT_NONE ; +static DEFINE_IDA (arm_smccc_bus_id);bool __ro_after_init smccc_trng_available = false;s32 __ro_after_init smccc_soc_id_version =SMCCC_RET_NOT_SUPPORTED ;
@@ -81,6 +86,159 @@ bool arm_smccc_hypervisor_has_uuid(const uuid_t *hyp_uuid) }EXPORT_SYMBOL_GPL (arm_smccc_hypervisor_has_uuid); +static int arm_smccc_bus_match (struct device *dev, +const struct device_driver *drv) +{ +const struct arm_smccc_device_id *id_table; +struct arm_smccc_device *smccc_dev =to_arm_smccc_device (dev); + + id_table =to_arm_smccc_driver (drv)->id_table; +if (!id_table) +return 0 ; + +while (id_table->name[0 ]) { +if (!strcmp (smccc_dev->name, id_table->name)) +return 1 ; + id_table++; + } + +return 0 ; +} + +static int arm_smccc_bus_probe (struct device *dev) +{ +struct arm_smccc_driver *smccc_drv =to_arm_smccc_driver (dev->driver); + +return smccc_drv->probe (to_arm_smccc_device (dev)); +} + +static void arm_smccc_bus_remove (struct device *dev) +{ +struct arm_smccc_driver *smcc_drv =to_arm_smccc_driver (dev->driver); + +if (smcc_drv->remove) + smcc_drv->remove (to_arm_smccc_device (dev)); +} + +static int arm_smccc_bus_uevent (const struct device *dev, +struct kobj_uevent_env *env) +{ +const struct arm_smccc_device *smccc_dev =to_arm_smccc_device (dev); + +return add_uevent_var (env,"MODALIAS=" ARM_SMCCC_MODULE_PREFIX "%s" , + smccc_dev->name); +} + +static ssize_t modalias_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct arm_smccc_device *smccc_dev =to_arm_smccc_device (dev); + +return sysfs_emit (buf,ARM_SMCCC_MODULE_PREFIX "%s\n" , smccc_dev->name); +} +static DEVICE_ATTR_RO (modalias); + +static struct attribute *arm_smccc_device_attrs[] = { + &dev_attr_modalias.attr, +NULL , +}; +ATTRIBUTE_GROUPS (arm_smccc_device); + +const struct bus_type arm_smccc_bus_type = { + .name ="arm_smccc" , + .match = arm_smccc_bus_match, + .probe = arm_smccc_bus_probe, + .remove = arm_smccc_bus_remove, + .uevent = arm_smccc_bus_uevent, + .dev_groups = arm_smccc_device_groups, +}; +EXPORT_SYMBOL_GPL (arm_smccc_bus_type); + +int arm_smccc_driver_register (struct arm_smccc_driver *driver, +struct module *owner,const char *mod_name) +{ +if (!driver->probe) +return -EINVAL ; + + driver->driver.bus = &arm_smccc_bus_type; + driver->driver.name = driver->name; + driver->driver.owner = owner; + driver->driver.mod_name = mod_name; + +return driver_register (&driver->driver); +} +EXPORT_SYMBOL_GPL (arm_smccc_driver_register); + +void arm_smccc_driver_unregister (struct arm_smccc_driver *driver) +{ +driver_unregister (&driver->driver); +} +EXPORT_SYMBOL_GPL (arm_smccc_driver_unregister); + +static void arm_smccc_release_device (struct device *dev) +{ +struct arm_smccc_device *smccc_dev =to_arm_smccc_device (dev); + +ida_free (&arm_smccc_bus_id, smccc_dev->id); +kfree (smccc_dev); +} + +struct arm_smccc_device *arm_smccc_device_register (const char *name) +{ +struct arm_smccc_device *smccc_dev; +int id, ret; + + id =ida_alloc_min (&arm_smccc_bus_id,1 ,GFP_KERNEL ); +if (id <0 ) +return ERR_PTR (id); + + smccc_dev =kzalloc_obj (*smccc_dev); +if (!smccc_dev) { +ida_free (&arm_smccc_bus_id, id); +return ERR_PTR (-ENOMEM ); + } + + smccc_dev->id = id; +if (strscpy (smccc_dev->name, name) <0 ) { +kfree (smccc_dev); +ida_free (&arm_smccc_bus_id, id); +return ERR_PTR (-EINVAL ); + } + smccc_dev->dev.bus = &arm_smccc_bus_type; + smccc_dev->dev.release = arm_smccc_release_device; + + ret =dev_set_name (&smccc_dev->dev,"%s-%d" , smccc_dev->name, id); +if (ret) { +kfree (smccc_dev); +ida_free (&arm_smccc_bus_id, id); +return ERR_PTR (ret); + } + + ret =device_register (&smccc_dev->dev); +if (ret) { +put_device (&smccc_dev->dev); +return ERR_PTR (ret); + } + +return smccc_dev; +} +EXPORT_SYMBOL_GPL (arm_smccc_device_register); + +void arm_smccc_device_unregister (struct arm_smccc_device *smccc_dev) +{ +if (!smccc_dev) +return ; + +device_unregister (&smccc_dev->dev); +} +EXPORT_SYMBOL_GPL (arm_smccc_device_unregister); + +static int __init arm_smccc_bus_init (void ) +{ +return bus_register (&arm_smccc_bus_type); +} +subsys_initcall (arm_smccc_bus_init); +static int __init smccc_devices_init (void ) {struct platform_device *pdev;
include/linux/arm-smccc-bus.h new file +49 -0
49 lines not on this page · raw message
include/linux/mod_devicetable.h +13 -0
@@ -876,6 +876,19 @@ struct auxiliary_device_id {kernel_ulong_t driver_data; }; +#define ARM_SMCCC_NAME_SIZE 40 +#define ARM_SMCCC_MODULE_PREFIX "arm_smccc:" + +/** +* struct arm_smccc_device_id - Arm SMCCC bus device identifier +* @name: SMCCC device name +* @driver_data: driver data +*/ +struct arm_smccc_device_id { +char name[ARM_SMCCC_NAME_SIZE ]; +kernel_ulong_t driver_data; +}; +/* Surface System Aggregator Module */ #define SSAM_MATCH_TARGET 0x1
scripts/mod/devicetable-offsets.c +3 -0
@@ -254,6 +254,9 @@ int main(void)DEVID (auxiliary_device_id);DEVID_FIELD (auxiliary_device_id, name); +DEVID (arm_smccc_device_id); +DEVID_FIELD (arm_smccc_device_id, name); +DEVID (ssam_device_id);DEVID_FIELD (ssam_device_id, match_flags);DEVID_FIELD (ssam_device_id, domain);
scripts/mod/file2alias.c +8 -0
@@ -1296,6 +1296,13 @@ static void do_auxiliary_entry(struct module *mod, void *symval)module_alias_printf (mod, false,AUXILIARY_MODULE_PREFIX "%s" , *name); } +static void do_arm_smccc_entry (struct module *mod,void *symval) +{ +DEF_FIELD_ADDR (symval, arm_smccc_device_id, name); + +module_alias_printf (mod, false,ARM_SMCCC_MODULE_PREFIX "%s" , *name); +} +/* * Looks like: ssam:dNcNtNiNfN *
@@ -1466,6 +1473,7 @@ static const struct devtable devtable[] = { {"mhi", SIZE_mhi_device_id, do_mhi_entry}, {"mhi_ep", SIZE_mhi_device_id, do_mhi_ep_entry}, {"auxiliary", SIZE_auxiliary_device_id, do_auxiliary_entry}, + {"arm_smccc", SIZE_arm_smccc_device_id, do_arm_smccc_entry}, {"ssam", SIZE_ssam_device_id, do_ssam_entry}, {"dfl", SIZE_dfl_device_id, do_dfl_entry}, {"ishtp", SIZE_ishtp_device_id, do_ishtp_entry},
Signature · 1 line
2.43.0
PATCH v6 2/4 firmware: hwrng: arm_smccc_trng: Register as an SMCCC device
In reply to Aneesh Kumar K.V (Arm)The SMCCC TRNG interface is a firmware-provided SMCCC service rather than a standalone platform device. Now that the SMCCC core has an SMCCC bus, create an arm-smccc-trng device for the discovered TRNG service and convert the hwrng driver to an SMCCC driver.
The SMCCC id table preserves module autoloading for systems where the TRNG driver is built as a module.
The sysfs device path changes from the old smccc_trng platform-device path to an arm-smccc device path. No known userspace dependency on the old path was found; a Debian Code Search lookup for the existing platform-device name/path did not find any users.
--- drivers/char/hw_random/arm_smccc_trng.c | 26 ++++++++++++++----------- drivers/firmware/smccc/smccc.c | 14 ++++++------- 2 files changed, 21 insertions(+), 19 deletions(-)
drivers/char/hw_random/arm_smccc_trng.c +15 -11
@@ -16,8 +16,8 @@#include <linux/device.h> #include <linux/hw_random.h> #include <linux/module.h> -#include <linux/platform_device.h> #include <linux/arm-smccc.h> +#include <linux/arm-smccc-bus.h> #ifdef CONFIG_ARM64 #define ARM_SMCCC_TRNG_RND ARM_SMCCC_TRNG_RND64
@@ -94,29 +94,33 @@ static int smccc_trng_read(struct hwrng *rng, void *data, size_t max, bool wait)return copied; } -static int smccc_trng_probe (struct platform_device *pdev) +static int smccc_trng_probe (struct arm_smccc_device *sdev) {struct hwrng *trng; - trng =devm_kzalloc (&pdev->dev,sizeof (*trng),GFP_KERNEL ); + trng =devm_kzalloc (&sdev->dev,sizeof (*trng),GFP_KERNEL );if (!trng)return -ENOMEM ; trng->name ="smccc_trng" ; trng->read = smccc_trng_read; -return devm_hwrng_register (&pdev->dev, trng); +return devm_hwrng_register (&sdev->dev, trng); } -static struct platform_driver smccc_trng_driver = { - .driver = { - .name ="smccc_trng" , - }, - .probe = smccc_trng_probe, +static const struct arm_smccc_device_id smccc_trng_id_table[] = { + { .name ="arm-smccc-trng" }, + {} }; -module_platform_driver (smccc_trng_driver); +MODULE_DEVICE_TABLE (arm_smccc, smccc_trng_id_table); + +static struct arm_smccc_driver smccc_trng_driver = { + .name =KBUILD_MODNAME , + .probe = smccc_trng_probe, + .id_table = smccc_trng_id_table, +}; +module_arm_smccc_driver (smccc_trng_driver); -MODULE_ALIAS ("platform:smccc_trng" );MODULE_AUTHOR ("Andre Przywara" );MODULE_DESCRIPTION ("Arm SMCCC TRNG firmware interface support" );MODULE_LICENSE ("GPL" );
drivers/firmware/smccc/smccc.c +6 -8
@@ -9,7 +9,6 @@#include <linux/init.h> #include <linux/arm-smccc.h> #include <linux/kernel.h> -#include <linux/platform_device.h> #include <linux/arm-smccc-bus.h> #include <linux/idr.h> #include <linux/slab.h>
@@ -241,14 +240,13 @@ subsys_initcall(arm_smccc_bus_init);static int __init smccc_devices_init (void ) { -struct platform_device *pdev; -if (smccc_trng_available) { - pdev =platform_device_register_simple ("smccc_trng" ,-1 , -NULL ,0 ); -if (IS_ERR (pdev)) -pr_err ("smccc_trng: could not register device: %ld\n" , -PTR_ERR (pdev)); +struct arm_smccc_device *sdev; + + sdev =arm_smccc_device_register ("arm-smccc-trng" ); +if (IS_ERR (sdev)) +pr_err ("arm-smccc-trng: could not register device: %ld\n" , +PTR_ERR (sdev)); }return 0 ;
Signature · 1 line
2.43.0
PATCH v6 3/4 firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
In reply to Aneesh Kumar K.V (Arm)The Arm CCA guest TSM provider currently binds through the arm-cca-dev platform device. Like arm-smccc-trng, this device is not an independent platform resource; it is a software representation of the RSI firmware service discovered through SMCCC.
Move RSI discovery into the SMCCC firmware driver. When the SMCCC conduit is SMC and the RSI ABI version check succeeds, create an arm-rsi-dev SMCCC device. Convert the Arm CCA guest TSM provider to an SMCCC driver so it binds to that discovered RSI service and keeps module autoloading through the SMCCC device id table.
Keep the old arm-cca-dev platform-device registration for now. Userspace has used that device as a Realm-guest indicator, so removing it is left to a follow-up patch that adds a replacement sysfs ABI.
---
arch/arm64/include/asm/rsi.h | 2 +-
arch/arm64/kernel/rsi.c | 2 +-
drivers/firmware/smccc/Makefile | 4 ++
drivers/firmware/smccc/rmm.c | 25 ++++++++
drivers/firmware/smccc/rmm.h | 17 ++++++
drivers/firmware/smccc/smccc.c | 8 +++
drivers/virt/coco/arm-cca-guest/Kconfig | 1 +
drivers/virt/coco/arm-cca-guest/Makefile | 2 +
.../{arm-cca-guest.c => arm-cca.c} | 60 +++++++++----------
9 files changed, 89 insertions(+), 32 deletions(-)
create mode 100644 drivers/firmware/smccc/rmm.c
create mode 100644 drivers/firmware/smccc/rmm.h
rename drivers/virt/coco/arm-cca-guest/{arm-cca-guest.c => arm-cca.c} (85%)arch/arm64/include/asm/rsi.h +1 -1
@@ -10,7 +10,7 @@#include <linux/jump_label.h> #include <asm/rsi_cmds.h> -#define RSI_PDEV_NAME "arm-cca-dev" +#define RSI_DEV_NAME "arm-rsi-dev"DECLARE_STATIC_KEY_FALSE (rsi_present);
arch/arm64/kernel/rsi.c +1 -1
@@ -161,7 +161,7 @@ void __init arm64_rsi_init(void) }static struct platform_device rsi_dev = { - .name =RSI_PDEV_NAME , + .name ="arm-cca-dev" , .id =PLATFORM_DEVID_NONE };
drivers/firmware/smccc/Makefile +4 -0
@@ -2,3 +2,7 @@ # obj-$(CONFIG_HAVE_ARM_SMCCC_DISCOVERY) += smccc.o kvm_guest.o obj-$(CONFIG_ARM_SMCCC_SOC_ID) += soc_id.o + +ifeq ($(CONFIG_HAVE_ARM_SMCCC_DISCOVERY),y) +obj-$(CONFIG_ARM64) += rmm.o +endif
drivers/firmware/smccc/rmm.c new file +25 -0
@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2026 Arm Limited +*/ + +#include <linux/arm-smccc-bus.h> +#include <linux/err.h> +#include <linux/printk.h> + +#include "rmm.h" + +void __init register_rsi_device (void ) +{ +unsigned long ret; + +if (arm_smccc_1_1_get_conduit () !=SMCCC_CONDUIT_SMC ) +return ; + + ret =rsi_request_version (RSI_ABI_VERSION ,NULL ,NULL ); +if (ret !=RSI_SUCCESS ) +return ; + +if (IS_ERR (arm_smccc_device_register (RSI_DEV_NAME ))) +pr_err ("%s: could not register device\n" ,RSI_DEV_NAME ); +}
drivers/firmware/smccc/rmm.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SMCCC_RMM_H +#define _SMCCC_RMM_H + +#include <linux/init.h> + +#ifdef CONFIG_ARM64 +#include <linux/arm-smccc-bus.h> +#include <asm/rsi_cmds.h> +void __init register_rsi_device (void ); +#else + +static inline void __init register_rsi_device (void ) +{ +} +#endif +#endif
drivers/firmware/smccc/smccc.c +8 -0
@@ -15,6 +15,8 @@#include <asm/archrandom.h> +#include "rmm.h" +static u32 smccc_version =ARM_SMCCC_VERSION_1_0 ;static enum arm_smccc_conduit smccc_conduit =SMCCC_CONDUIT_NONE ;static DEFINE_IDA (arm_smccc_bus_id);
@@ -240,6 +242,12 @@ subsys_initcall(arm_smccc_bus_init);static int __init smccc_devices_init (void ) { +/* +* Register the RMI and RSI devices only when firmware exposes +* the required SMCCC function IDs at a supported revision. +*/ +register_rsi_device (); +if (smccc_trng_available) {struct arm_smccc_device *sdev;
drivers/virt/coco/arm-cca-guest/Kconfig +1 -0
@@ -1,6 +1,7 @@ config ARM_CCA_GUEST tristate "Arm CCA Guest driver" depends on ARM64 + depends on HAVE_ARM_SMCCC_DISCOVERY select TSM_REPORTS help The driver provides userspace interface to request and
drivers/virt/coco/arm-cca-guest/Makefile +2 -0
@@ -1,2 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_ARM_CCA_GUEST) += arm-cca-guest.o + +arm-cca-guest-y += arm-cca.o
drivers/virt/coco/arm-cca-guest/arm-cca.c renamed from drivers/virt/coco/arm-cca-guest/arm-cca-guest.c +30 -30
88 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v6 4/4 coco: guest: arm64: Replace dummy CCA device with sysfs ABI
In reply to Aneesh Kumar K.V (Arm)The SMCCC firmware driver now creates the arm-smccc platform device and instantiates the CCA RSI auxiliary devices once the RSI ABI is discovered. The arm64-specific arm-cca-dev platform device stub is therefore no longer needed.
However, userspace has used the arm-cca-dev platform device to detect Arm CCA Realm guests [1]. Removing it without a replacement would break that detection and would also leave userspace depending on kernel device-model details.
Add /sys/firmware/cca/realm_guest as a stable, architecture-provided ABI for detecting whether the kernel is running as an Arm CCA Realm guest. The file returns 1 in Realm world and 0 otherwise, similar to the existing s390 /sys/firmware/uv/prot_virt_guest interface for protected virtualization guests.
Remove the dummy arm-cca-dev registration now that userspace has a dedicated CCA Realm guest indicator, and document the new ABI in Documentation/ABI/testing/sysfs-firmware-cca.
[1] https://lore.kernel.org/all/[email protected]
--- Documentation/ABI/testing/sysfs-firmware-cca | 10 +++++ arch/arm64/kernel/rsi.c | 39 +++++++++++++++----- 2 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-firmware-cca
Documentation/ABI/testing/sysfs-firmware-cca new file +10 -0
@@ -0,0 +1,10 @@ +What: /sys/firmware/cca/realm_guest +Date: May 2026 +Contact: Linux ARM Kernel Mailing list <[email protected]> +Description: Read-only. Indicates whether the kernel is running as an + Arm Confidential Compute Architecture (CCA) Realm guest. + + The value is one of: + + 0: the kernel is not running as a Realm guest + 1: the kernel is running as a Realm guest
arch/arm64/kernel/rsi.c +29 -10
@@ -9,6 +9,8 @@#include <linux/swiotlb.h> #include <linux/cc_platform.h> #include <linux/platform_device.h> +#include <linux/kobject.h> +#include <linux/sysfs.h> #include <asm/io.h> #include <asm/mem_encrypt.h>
@@ -16,6 +18,7 @@#include <asm/rsi.h> static struct realm_config config; +static struct kobject *cca_kobj;unsigned long prot_ns_shared;EXPORT_SYMBOL (prot_ns_shared);
@@ -160,17 +163,33 @@ void __init arm64_rsi_init(void)static_branch_enable (&rsi_present); } -static struct platform_device rsi_dev = { - .name ="arm-cca-dev" , - .id =PLATFORM_DEVID_NONE +static ssize_t cca_is_realm_guest (struct kobject *kobj, +struct kobj_attribute *attr,char *buf) +{ +return sysfs_emit (buf,"%d\n" ,is_realm_world ()); +} + +static struct kobj_attribute cca_realm_guest = +__ATTR (realm_guest,0444 , cca_is_realm_guest,NULL ); + +static const struct attribute *cca_realm_attrs[] = { + &cca_realm_guest.attr, +NULL , }; -static int __init arm64_create_dummy_rsi_dev (void ) +static int __init realm_sysfs_init (void ) { -if (is_realm_world () && -platform_device_register (&rsi_dev)) -pr_err ("failed to register rsi platform device\n" ); -return 0 ; -} +int ret; + + cca_kobj =kobject_create_and_add ("cca" , firmware_kobj); +if (!cca_kobj) +return -ENOMEM ; -arch_initcall (arm64_create_dummy_rsi_dev) + ret =sysfs_create_files (cca_kobj, cca_realm_attrs); +if (!ret) +return 0 ; + +kobject_put (cca_kobj); +return ret; +} +device_initcall (realm_sysfs_init);
Signature · 1 line
2.43.0
Sudeep Holla
maintainerRe: [PATCH v6 1/4] firmware: smccc: Add an Arm SMCCC bus
In reply to Aneesh Kumar K.V (Arm)Quoted 5 lines · Aneesh Kumar K.V (Arm)
SMCCC-discovered firmware services are currently represented by separate platform devices, such as
smccc_trngand arm-cca-dev. Those devices do not represent independent DT/ACPI-described platform resources; they are features of the SMCCC firmware interface.
Quoted 9 lines
Add an Arm SMCCC bus for services discovered through the SMCCC firmware interface. The bus provides SMCCC device and driver registration helpers, name-based matching, modalias generation, and a sysfs modalias attribute so SMCCC service drivers can bind to discovered firmware services and autoload as modules.
Follow-up changes can then register SMCCC firmware services as arm-smccc devices instead of creating independent per-feature platform devices.
This looks good to me.
Quoted 5 lines
Based on
arm_ffacodeSigned-off-by Aneesh Kumar K.V (Arm) <[email protected]>--- drivers/firmware/smccc/smccc.c | 158 ++++++++++++++++++++++++++++++
I think it is better to keep it separate say bus.c ?
Signature · 2 lines
Regards, Sudeep
Re: [PATCH v6 3/4] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
In reply to Aneesh Kumar K.V (Arm)Quoted 77 lines · Aneesh Kumar K.V (Arm)
The Arm CCA guest TSM provider currently binds through the arm-cca-dev platform device. Like arm-smccc-trng, this device is not an independent platform resource; it is a software representation of the RSI firmware service discovered through SMCCC.
Move RSI discovery into the SMCCC firmware driver. When the SMCCC conduit is SMC and the RSI ABI version check succeeds, create an arm-rsi-dev SMCCC device. Convert the Arm CCA guest TSM provider to an SMCCC driver so it binds to that discovered RSI service and keeps module autoloading through the SMCCC device id table.
Keep the old arm-cca-dev platform-device registration for now. Userspace has used that device as a Realm-guest indicator, so removing it is left to a follow-up patch that adds a replacement sysfs ABI.
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>--- arch/arm64/include/asm/rsi.h | 2 +- arch/arm64/kernel/rsi.c | 2 +- drivers/firmware/smccc/Makefile | 4 ++ drivers/firmware/smccc/rmm.c | 25 ++++++++ drivers/firmware/smccc/rmm.h | 17 ++++++ drivers/firmware/smccc/smccc.c | 8 +++ drivers/virt/coco/arm-cca-guest/Kconfig | 1 + drivers/virt/coco/arm-cca-guest/Makefile | 2 + .../{arm-cca-guest.c => arm-cca.c} | 60 +++++++++---------- 9 files changed, 89 insertions(+), 32 deletions(-)create mode 100644
drivers/firmware/smccc/rmm.c
create mode 100644drivers/firmware/smccc/rmm.h
renamedrivers/virt/coco/arm-cca-guest/{arm-cca-guest.c=>arm-cca.c} (85%)arch/arm64/include/asm/rsi.h +1
-1@@ -10,7 +10,7 @@#include <linux/jump_label.h> #include <asm/rsi_cmds.h> -#define RSI_PDEV_NAME "arm-cca-dev" +#define RSI_DEV_NAME "arm-rsi-dev"DECLARE_STATIC_KEY_FALSE (rsi_present);arch/arm64/kernel/rsi.c +1
-1@@ -161,7 +161,7 @@ void __init arm64_rsi_init(void) }static struct platform_device rsi_dev = { - .name =RSI_PDEV_NAME , + .name ="arm-cca-dev" , .id =PLATFORM_DEVID_NONE };drivers/firmware/smccc/Makefile +4
-0@@ -2,3 +2,7 @@ # obj-$(CONFIG_HAVE_ARM_SMCCC_DISCOVERY) += smccc.o kvm_guest.o obj-$(CONFIG_ARM_SMCCC_SOC_ID) += soc_id.o + +ifeq ($(CONFIG_HAVE_ARM_SMCCC_DISCOVERY),y) +obj-$(CONFIG_ARM64) += rmm.o +endifdrivers/firmware/smccc/rmm.c new file +2
-0@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0-only +/*
drivers/firmware/smccc/rmm.c line 12
Quoted 10 lines
drivers/firmware/smccc/rmm.c new file +10
-0+* Copyright (C) 2026 Arm Limited +*/ + +#include <linux/arm-smccc-bus.h> +#include <linux/err.h> +#include <linux/printk.h> + +#include "rmm.h" + +void __init register_rsi_device (void )
minor nit: Could we rename this global symbol to scope it under rmm ? perhaps, rmm_register_rsi_device()?
Quoted 19 lines
drivers/firmware/smccc/rmm.c new file +13
-0+{ +unsigned long ret; + +if (arm_smccc_1_1_get_conduit () !=SMCCC_CONDUIT_SMC ) +return ; + + ret =rsi_request_version (RSI_ABI_VERSION ,NULL ,NULL ); +if (ret !=RSI_SUCCESS ) +return ; + +if (IS_ERR (arm_smccc_device_register (RSI_DEV_NAME ))) +pr_err ("%s: could not register device\n" ,RSI_DEV_NAME ); +}drivers/firmware/smccc/rmm.h new file +0
-0
drivers/firmware/smccc/rmm.h line 9
Quoted 9 lines
drivers/firmware/smccc/rmm.h new file +9
-0@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _SMCCC_RMM_H +#define _SMCCC_RMM_H + +#include <linux/init.h> + +#ifdef CONFIG_ARM64 +#include <linux/arm-smccc-bus.h> +#include <asm/rsi_cmds.h>
minor nit: Could the header files be moved to rmm.c ?
Quoted 26 lines
drivers/firmware/smccc/rmm.h new file +8
-0+void __init register_rsi_device (void ); +#else + +static inline void __init register_rsi_device (void ) +{ +} +#endif +#endif drivers/firmware/smccc/smccc.c +2
-0@@ -15,6 +15,8 @@#include <asm/archrandom.h> +#include "rmm.h" +static u32 smccc_version =ARM_SMCCC_VERSION_1_0 ;static enum arm_smccc_conduit smccc_conduit =SMCCC_CONDUIT_NONE ;static DEFINE_IDA (arm_smccc_bus_id);
drivers/firmware/smccc/smccc.c subsys_initcall(arm_smccc_bus_init); · line 249
Quoted 8 lines
drivers/firmware/smccc/smccc.c +5
-0@@ -240,6 +242,12 @@ subsys_initcall(arm_smccc_bus_init);static int __init smccc_devices_init (void ) { +/* +* Register the RMI and RSI devices only when firmware exposes +* the required SMCCC function IDs at a supported revision. +*/ +register_rsi_device ();
nit: We don't have RMI devices yet ? Do we want to make it
rmm_register_devices();
instead ?
Quoted 41 lines
drivers/firmware/smccc/smccc.c +1
-0+if (smccc_trng_available) {struct arm_smccc_device *sdev;drivers/virt/coco/arm-cca-guest/Kconfig +1
-0@@ -1,6 +1,7 @@ config ARM_CCA_GUEST tristate "Arm CCA Guest driver" depends on ARM64 + depends on HAVE_ARM_SMCCC_DISCOVERY select TSM_REPORTS help The driver provides userspace interface to request anddrivers/virt/coco/arm-cca-guest/Makefile +2
-0@@ -1,2 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_ARM_CCA_GUEST) += arm-cca-guest.o + +arm-cca-guest-y += arm-cca.odrivers/virt/coco/arm-cca-guest/arm-cca.c renamed from drivers/virt/coco/arm-cca-guest/arm-cca-guest.c +1
-0@@ -4,6 +4,7 @@*/ #include <linux/arm-smccc.h> +#include <linux/arm-smccc-bus.h> #include <linux/cc_platform.h> #include <linux/kernel.h> #include <linux/mod_devicetable.h>
drivers/virt/coco/arm-cca-guest/arm-cca.c static int arm_cca_report_new(struct tsm_report *report, void *data) · line 190
Quoted 9 lines
drivers/virt/coco/arm-cca-guest/arm-cca.c renamed from drivers/virt/coco/arm-cca-guest/arm-cca-guest.c +1
-1@@ -182,52 +183,51 @@ static int arm_cca_report_new(struct tsm_report *report, void *data)return ret; } -static const struct tsm_report_ops arm_cca_tsm_ops = { +static const struct tsm_report_ops arm_cca_tsm_report_ops = { .name =KBUILD_MODNAME , .report_new = arm_cca_report_new, };
Would you like to either :
1) Call out renaming the existing cca_tsm to reflect cca_tsm_report in the commit description ?
OR
2) Split the renaming of the "report" stuff in a follow up patch ?
Rest looks fine by me.
Suzuki
Quoted 72 lines
drivers/virt/coco/arm-cca-guest/arm-cca.c renamed from drivers/virt/coco/arm-cca-guest/arm-cca-guest.c +28
-29-/** -* arm_cca_guest_init - Register with the Trusted Security Module (TSM) -* interface. -* -* Return: -* * %0 - Registered successfully with the TSM interface. -* * %-ENODEV - The execution context is not an Arm Realm. -* * %-EBUSY - Already registered. -*/ -static int __init arm_cca_guest_init (void ) +static void unregister_cca_tsm_report (void *data) +{ +tsm_report_unregister (&arm_cca_tsm_report_ops); +} + +static int cca_tsm_probe (struct arm_smccc_device *sdev) {int ret;if (!is_realm_world ())return -ENODEV ; - ret =tsm_report_register (&arm_cca_tsm_ops,NULL ); -if (ret <0 ) -pr_err ("Error %d registering with TSM\n" , ret); + ret =tsm_report_register (&arm_cca_tsm_report_ops,NULL ); +if (ret <0 ) { +dev_err_probe (&sdev->dev, ret,"Error registering with TSM\n" ); +return ret; + } -return ret; -} -module_init (arm_cca_guest_init); + ret =devm_add_action_or_reset (&sdev->dev, unregister_cca_tsm_report, +NULL ); +if (ret <0 ) { +dev_err_probe (&sdev->dev, ret,"Error registering devm action\n" ); +return ret; + } -/** -* arm_cca_guest_exit - unregister with the Trusted Security Module (TSM) -* interface. -*/ -static void __exit arm_cca_guest_exit(void) -{ -tsm_report_unregister (&arm_cca_tsm_ops); +return 0 ; } -module_exit (arm_cca_guest_exit); -/* modalias, so userspace can autoload this module when RSI is available */ -static const struct platform_device_id arm_cca_match[]__maybe_unused = { - {RSI_PDEV_NAME ,0 }, - { } +static const struct arm_smccc_device_id cca_tsm_id_table[] = { + { .name =RSI_DEV_NAME }, + {} }; +MODULE_DEVICE_TABLE (arm_smccc, cca_tsm_id_table); -MODULE_DEVICE_TABLE (platform, arm_cca_match); +static struct arm_smccc_driver cca_tsm_driver = { + .name =KBUILD_MODNAME , + .probe = cca_tsm_probe, + .id_table = cca_tsm_id_table, +}; +module_arm_smccc_driver (cca_tsm_driver);MODULE_AUTHOR ("Sami Mujawar <[email protected]>" );MODULE_DESCRIPTION ("Arm CCA Guest TSM Driver" );MODULE_LICENSE ("GPL" );
Sudeep Holla
maintainerRe: [PATCH v6 3/4] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
In reply to Aneesh Kumar K.V (Arm)Quoted 90 lines · Aneesh Kumar K.V (Arm)
The Arm CCA guest TSM provider currently binds through the arm-cca-dev platform device. Like arm-smccc-trng, this device is not an independent platform resource; it is a software representation of the RSI firmware service discovered through SMCCC.
Move RSI discovery into the SMCCC firmware driver. When the SMCCC conduit is SMC and the RSI ABI version check succeeds, create an arm-rsi-dev SMCCC device. Convert the Arm CCA guest TSM provider to an SMCCC driver so it binds to that discovered RSI service and keeps module autoloading through the SMCCC device id table.
Keep the old arm-cca-dev platform-device registration for now. Userspace has used that device as a Realm-guest indicator, so removing it is left to a follow-up patch that adds a replacement sysfs ABI.
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>--- arch/arm64/include/asm/rsi.h | 2 +- arch/arm64/kernel/rsi.c | 2 +- drivers/firmware/smccc/Makefile | 4 ++ drivers/firmware/smccc/rmm.c | 25 ++++++++ drivers/firmware/smccc/rmm.h | 17 ++++++ drivers/firmware/smccc/smccc.c | 8 +++ drivers/virt/coco/arm-cca-guest/Kconfig | 1 + drivers/virt/coco/arm-cca-guest/Makefile | 2 + .../{arm-cca-guest.c => arm-cca.c} | 60 +++++++++---------- 9 files changed, 89 insertions(+), 32 deletions(-) create mode 100644 drivers/firmware/smccc/rmm.c create mode 100644 drivers/firmware/smccc/rmm.h rename drivers/virt/coco/arm-cca-guest/{arm-cca-guest.c => arm-cca.c} (85%)arch/arm64/include/asm/rsi.h +1
-1@@ -10,7 +10,7 @@#include <linux/jump_label.h> #include <asm/rsi_cmds.h> -#define RSI_PDEV_NAME "arm-cca-dev" +#define RSI_DEV_NAME "arm-rsi-dev"DECLARE_STATIC_KEY_FALSE (rsi_present);arch/arm64/kernel/rsi.c +1
-1@@ -161,7 +161,7 @@ void __init arm64_rsi_init(void) }static struct platform_device rsi_dev = { - .name =RSI_PDEV_NAME , + .name ="arm-cca-dev" , .id =PLATFORM_DEVID_NONE };drivers/firmware/smccc/Makefile +4
-0@@ -2,3 +2,7 @@ # obj-$(CONFIG_HAVE_ARM_SMCCC_DISCOVERY) += smccc.o kvm_guest.o obj-$(CONFIG_ARM_SMCCC_SOC_ID) += soc_id.o + +ifeq ($(CONFIG_HAVE_ARM_SMCCC_DISCOVERY),y) +obj-$(CONFIG_ARM64) += rmm.o +endifdrivers/firmware/smccc/rmm.c new file +15
-0@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2026 Arm Limited +*/ + +#include <linux/arm-smccc-bus.h> +#include <linux/err.h> +#include <linux/printk.h> + +#include "rmm.h" + +void __init register_rsi_device (void ) +{ +unsigned long ret; +
drivers/firmware/smccc/rmm.c line 25
Quoted 10 lines
drivers/firmware/smccc/rmm.c new file +10
-0+if (arm_smccc_1_1_get_conduit () !=SMCCC_CONDUIT_SMC ) +return ; + + ret =rsi_request_version (RSI_ABI_VERSION ,NULL ,NULL ); +if (ret !=RSI_SUCCESS ) +return ; + +if (IS_ERR (arm_smccc_device_register (RSI_DEV_NAME ))) +pr_err ("%s: could not register device\n" ,RSI_DEV_NAME ); +}
OK, I had something else in my mind when I started looking at 1/4. I didn't expect each device added on this bus comes up with it's own way to enumerate it. IMO, it defeats the purpose of building the smccc bus. We may find the specs for each feature deviated a bit but we can have a generic probe IMO, let's try that before exploring per feature probe function.
I have a brief sketch of what I think we should aim for(uncompiled/untested) below. Let me know if that makes sense. I just based it on your bus code.
Regards,
Sudeep
-->8
drivers/firmware/smccc/smccc.c +56 -13
@@ -9,21 +9,58 @@#include <linux/init.h> #include <linux/arm-smccc.h> #include <linux/kernel.h> -#include <linux/platform_device.h> #include <linux/arm-smccc-bus.h> #include <linux/idr.h> #include <linux/slab.h> -#include <asm/archrandom.h> -static u32 smccc_version =ARM_SMCCC_VERSION_1_0 ;static enum arm_smccc_conduit smccc_conduit =SMCCC_CONDUIT_NONE ;static DEFINE_IDA (arm_smccc_bus_id); -bool __ro_after_init smccc_trng_available = false; +struct smccc_device_info { +u32 func_id; +bool requires_smc; +unsigned long min_return; +const char *device_name; +}; + +bool __ro_after_init smccc_trng_available;s32 __ro_after_init smccc_soc_id_version =SMCCC_RET_NOT_SUPPORTED ;s32 __ro_after_init smccc_soc_id_revision =SMCCC_RET_NOT_SUPPORTED ; +static const struct smccc_device_info smccc_devices[]__initconst = { + { + .func_id =ARM_SMCCC_TRNG_VERSION , + .requires_smc = false, + .min_return =ARM_SMCCC_TRNG_MIN_VERSION , + .device_name ="arm-smccc-trng" , + }, +}; + +static bool __init +smccc_probe_smccc_device (const struct smccc_device_info *smccc_dev) +{ +struct arm_smccc_res res; +unsigned long ret; + +if (!IS_ENABLED (CONFIG_ARM64 )) +return false; + +if (smccc_conduit ==SMCCC_CONDUIT_NONE ) +return false; + +if (smccc_dev->requires_smc && smccc_conduit !=SMCCC_CONDUIT_SMC ) +return false; + +arm_smccc_1_1_invoke (smccc_dev->func_id, &res); + ret = res.a0; + +if ((s32 )ret <0 ) +return false; + +return ret >= smccc_dev->min_return; +} +void __init arm_smccc_version_init (u32 version,enum arm_smccc_conduit conduit) {struct arm_smccc_res res;
@@ -31,7 +68,7 @@ void __init arm_smccc_version_init(u32 version, enum arm_smccc_conduit conduit) smccc_version = version; smccc_conduit = conduit; - smccc_trng_available =smccc_probe_trng (); + smccc_trng_available =smccc_probe_smccc_device (&smccc_devices[0 ]);if ((smccc_version >=ARM_SMCCC_VERSION_1_2 ) && (smccc_conduit !=SMCCC_CONDUIT_NONE )) {
@@ -241,14 +278,20 @@ subsys_initcall(arm_smccc_bus_init);static int __init smccc_devices_init (void ) { -struct platform_device *pdev; - -if (smccc_trng_available) { - pdev =platform_device_register_simple ("smccc_trng" ,-1 , -NULL ,0 ); -if (IS_ERR (pdev)) -pr_err ("smccc_trng: could not register device: %ld\n" , -PTR_ERR (pdev)); +const struct smccc_device_info *smccc_dev; +struct arm_smccc_device *sdev; +int i; + +for (i =0 ; i <ARRAY_SIZE (smccc_devices); i++) { + smccc_dev = &smccc_devices[i]; + +if (!smccc_probe_smccc_device (smccc_dev)) +continue ; + + sdev =arm_smccc_device_register (smccc_dev->device_name); +if (IS_ERR (sdev)) +pr_err ("%s: could not register device: %ld\n" , + smccc_dev->device_name,PTR_ERR (sdev)); }return 0 ;
Re: [PATCH v6 3/4] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
Quoted 99 lines · Sudeep Holla
Quoted 98 lines · Aneesh Kumar K.V (Arm)
The Arm CCA guest TSM provider currently binds through the arm-cca-dev platform device. Like arm-smccc-trng, this device is not an independent platform resource; it is a software representation of the RSI firmware service discovered through SMCCC.
Move RSI discovery into the SMCCC firmware driver. When the SMCCC conduit is SMC and the RSI ABI version check succeeds, create an arm-rsi-dev SMCCC device. Convert the Arm CCA guest TSM provider to an SMCCC driver so it binds to that discovered RSI service and keeps module autoloading through the SMCCC device id table.
Keep the old arm-cca-dev platform-device registration for now. Userspace has used that device as a Realm-guest indicator, so removing it is left to a follow-up patch that adds a replacement sysfs ABI.
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>--- arch/arm64/include/asm/rsi.h | 2 +- arch/arm64/kernel/rsi.c | 2 +- drivers/firmware/smccc/Makefile | 4 ++ drivers/firmware/smccc/rmm.c | 25 ++++++++ drivers/firmware/smccc/rmm.h | 17 ++++++ drivers/firmware/smccc/smccc.c | 8 +++ drivers/virt/coco/arm-cca-guest/Kconfig | 1 + drivers/virt/coco/arm-cca-guest/Makefile | 2 + .../{arm-cca-guest.c => arm-cca.c} | 60 +++++++++---------- 9 files changed, 89 insertions(+), 32 deletions(-)create mode 100644
drivers/firmware/smccc/rmm.c
create mode 100644drivers/firmware/smccc/rmm.h
renamedrivers/virt/coco/arm-cca-guest/{arm-cca-guest.c=>arm-cca.c} (85%)arch/arm64/include/asm/rsi.h +1
-1@@ -10,7 +10,7 @@#include <linux/jump_label.h> #include <asm/rsi_cmds.h> -#define RSI_PDEV_NAME "arm-cca-dev" +#define RSI_DEV_NAME "arm-rsi-dev"DECLARE_STATIC_KEY_FALSE (rsi_present);arch/arm64/kernel/rsi.c +1
-1@@ -161,7 +161,7 @@ void __init arm64_rsi_init(void) }static struct platform_device rsi_dev = { - .name =RSI_PDEV_NAME , + .name ="arm-cca-dev" , .id =PLATFORM_DEVID_NONE };drivers/firmware/smccc/Makefile +4
-0@@ -2,3 +2,7 @@ # obj-$(CONFIG_HAVE_ARM_SMCCC_DISCOVERY) += smccc.o kvm_guest.o obj-$(CONFIG_ARM_SMCCC_SOC_ID) += soc_id.o + +ifeq ($(CONFIG_HAVE_ARM_SMCCC_DISCOVERY),y) +obj-$(CONFIG_ARM64) += rmm.o +endifdrivers/firmware/smccc/rmm.c new file +23
-0@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2026 Arm Limited +*/ + +#include <linux/arm-smccc-bus.h> +#include <linux/err.h> +#include <linux/printk.h> + +#include "rmm.h" + +void __init register_rsi_device (void ) +{ +unsigned long ret; + +if (arm_smccc_1_1_get_conduit () !=SMCCC_CONDUIT_SMC ) +return ; + + ret =rsi_request_version (RSI_ABI_VERSION ,NULL ,NULL ); +if (ret !=RSI_SUCCESS ) +return ; + +if (IS_ERR (arm_smccc_device_register (RSI_DEV_NAME )))
Quoted 8 lines
drivers/firmware/smccc/rmm.c line 25
Quoted 2 lines
drivers/firmware/smccc/rmm.c new file +2
-0+pr_err ("%s: could not register device\n" ,RSI_DEV_NAME ); +}OK, I had something else in my mind when I started looking at 1/4. I didn't expect each device added on this bus comes up with it's own way to enumerate it. IMO, it defeats the purpose of building the smccc bus. We may find the specs for each feature deviated a bit but we can have a generic probe IMO, let's try that before exploring per feature probe function.
I guess this is ideal, but see below.
Quoted 23 lines
I have a brief sketch of what I think we should aim for(uncompiled/untested) below. Let me know if that makes sense. I just based it on your bus code.
Regards,
Sudeep-->8
drivers/firmware/smccc/smccc.c +0
-2@@ -9,21 +9,58 @@#include <linux/init.h> #include <linux/arm-smccc.h> #include <linux/kernel.h> -#include <linux/platform_device.h> #include <linux/arm-smccc-bus.h> #include <linux/idr.h> #include <linux/slab.h> -#include <asm/archrandom.h>
drivers/firmware/smccc/smccc.c line 23
Quoted 10 lines
drivers/firmware/smccc/smccc.c +4
-2-static u32 smccc_version =ARM_SMCCC_VERSION_1_0 ;static enum arm_smccc_conduit smccc_conduit =SMCCC_CONDUIT_NONE ;static DEFINE_IDA (arm_smccc_bus_id); -bool __ro_after_init smccc_trng_available = false; +struct smccc_device_info { +u32 func_id; +bool requires_smc; +unsigned long min_return;
Is this viable for all ? There may be additional restrictions around the return values and further SMC calls ? Which brings us to call backs and we kind of have a variant of that here.
Suzuki
Quoted 82 lines
drivers/firmware/smccc/smccc.c +52
-9+const char *device_name; +}; + +bool __ro_after_init smccc_trng_available;s32 __ro_after_init smccc_soc_id_version =SMCCC_RET_NOT_SUPPORTED ;s32 __ro_after_init smccc_soc_id_revision =SMCCC_RET_NOT_SUPPORTED ; +static const struct smccc_device_info smccc_devices[]__initconst = { + { + .func_id =ARM_SMCCC_TRNG_VERSION , + .requires_smc = false, + .min_return =ARM_SMCCC_TRNG_MIN_VERSION , + .device_name ="arm-smccc-trng" , + }, +}; + +static bool __init +smccc_probe_smccc_device (const struct smccc_device_info *smccc_dev) +{ +struct arm_smccc_res res; +unsigned long ret; + +if (!IS_ENABLED (CONFIG_ARM64 )) +return false; + +if (smccc_conduit ==SMCCC_CONDUIT_NONE ) +return false; + +if (smccc_dev->requires_smc && smccc_conduit !=SMCCC_CONDUIT_SMC ) +return false; + +arm_smccc_1_1_invoke (smccc_dev->func_id, &res); + ret = res.a0; + +if ((s32 )ret <0 ) +return false; + +return ret >= smccc_dev->min_return; +} +void __init arm_smccc_version_init (u32 version,enum arm_smccc_conduit conduit) {struct arm_smccc_res res;@@ -31,7 +68,7 @@ void __init arm_smccc_version_init(u32 version, enum arm_smccc_conduit conduit) smccc_version = version; smccc_conduit = conduit; - smccc_trng_available =smccc_probe_trng (); + smccc_trng_available =smccc_probe_smccc_device (&smccc_devices[0 ]);if ((smccc_version >=ARM_SMCCC_VERSION_1_2 ) && (smccc_conduit !=SMCCC_CONDUIT_NONE )) {@@ -241,14 +278,20 @@ subsys_initcall(arm_smccc_bus_init);static int __init smccc_devices_init (void ) { -struct platform_device *pdev; - -if (smccc_trng_available) { - pdev =platform_device_register_simple ("smccc_trng" ,-1 , -NULL ,0 ); -if (IS_ERR (pdev)) -pr_err ("smccc_trng: could not register device: %ld\n" , -PTR_ERR (pdev)); +const struct smccc_device_info *smccc_dev; +struct arm_smccc_device *sdev; +int i; + +for (i =0 ; i <ARRAY_SIZE (smccc_devices); i++) { + smccc_dev = &smccc_devices[i]; + +if (!smccc_probe_smccc_device (smccc_dev)) +continue ; + + sdev =arm_smccc_device_register (smccc_dev->device_name); +if (IS_ERR (sdev)) +pr_err ("%s: could not register device: %ld\n" , + smccc_dev->device_name,PTR_ERR (sdev)); }return 0 ;
Sudeep Holla
maintainerRe: [PATCH v6 3/4] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
Quoted 134 lines · Suzuki K Poulose
Quoted 94 lines · Sudeep Holla
Quoted 93 lines · Aneesh Kumar K.V (Arm)
The Arm CCA guest TSM provider currently binds through the arm-cca-dev platform device. Like arm-smccc-trng, this device is not an independent platform resource; it is a software representation of the RSI firmware service discovered through SMCCC.
Move RSI discovery into the SMCCC firmware driver. When the SMCCC conduit is SMC and the RSI ABI version check succeeds, create an arm-rsi-dev SMCCC device. Convert the Arm CCA guest TSM provider to an SMCCC driver so it binds to that discovered RSI service and keeps module autoloading through the SMCCC device id table.
Keep the old arm-cca-dev platform-device registration for now. Userspace has used that device as a Realm-guest indicator, so removing it is left to a follow-up patch that adds a replacement sysfs ABI.
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>--- arch/arm64/include/asm/rsi.h | 2 +- arch/arm64/kernel/rsi.c | 2 +- drivers/firmware/smccc/Makefile | 4 ++ drivers/firmware/smccc/rmm.c | 25 ++++++++ drivers/firmware/smccc/rmm.h | 17 ++++++ drivers/firmware/smccc/smccc.c | 8 +++ drivers/virt/coco/arm-cca-guest/Kconfig | 1 + drivers/virt/coco/arm-cca-guest/Makefile | 2 + .../{arm-cca-guest.c => arm-cca.c} | 60 +++++++++---------- 9 files changed, 89 insertions(+), 32 deletions(-)create mode 100644
drivers/firmware/smccc/rmm.c
create mode 100644drivers/firmware/smccc/rmm.h
renamedrivers/virt/coco/arm-cca-guest/{arm-cca-guest.c=>arm-cca.c} (85%)arch/arm64/include/asm/rsi.h +1
-1@@ -10,7 +10,7 @@#include <linux/jump_label.h> #include <asm/rsi_cmds.h> -#define RSI_PDEV_NAME "arm-cca-dev" +#define RSI_DEV_NAME "arm-rsi-dev"DECLARE_STATIC_KEY_FALSE (rsi_present);arch/arm64/kernel/rsi.c +1
-1@@ -161,7 +161,7 @@ void __init arm64_rsi_init(void) }static struct platform_device rsi_dev = { - .name =RSI_PDEV_NAME , + .name ="arm-cca-dev" , .id =PLATFORM_DEVID_NONE };drivers/firmware/smccc/Makefile +4
-0@@ -2,3 +2,7 @@ # obj-$(CONFIG_HAVE_ARM_SMCCC_DISCOVERY) += smccc.o kvm_guest.o obj-$(CONFIG_ARM_SMCCC_SOC_ID) += soc_id.o + +ifeq ($(CONFIG_HAVE_ARM_SMCCC_DISCOVERY),y) +obj-$(CONFIG_ARM64) += rmm.o +endifdrivers/firmware/smccc/rmm.c new file +23
-0@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2026 Arm Limited +*/ + +#include <linux/arm-smccc-bus.h> +#include <linux/err.h> +#include <linux/printk.h> + +#include "rmm.h" + +void __init register_rsi_device (void ) +{ +unsigned long ret; + +if (arm_smccc_1_1_get_conduit () !=SMCCC_CONDUIT_SMC ) +return ; + + ret =rsi_request_version (RSI_ABI_VERSION ,NULL ,NULL ); +if (ret !=RSI_SUCCESS ) +return ; + +if (IS_ERR (arm_smccc_device_register (RSI_DEV_NAME )))Quoted 8 lines
drivers/firmware/smccc/rmm.c line 25
Quoted 2 lines
drivers/firmware/smccc/rmm.c new file +2
-0+pr_err ("%s: could not register device\n" ,RSI_DEV_NAME ); +}OK, I had something else in my mind when I started looking at 1/4. I didn't expect each device added on this bus comes up with it's own way to enumerate it. IMO, it defeats the purpose of building the smccc bus. We may find the specs for each feature deviated a bit but we can have a generic probe IMO, let's try that before exploring per feature probe function.
I guess this is ideal, but see below.
Quoted 28 lines
I have a brief sketch of what I think we should aim for(uncompiled/untested) below. Let me know if that makes sense. I just based it on your bus code.
Regards,
Sudeep-->8
drivers/firmware/smccc/smccc.c +0
-3@@ -9,21 +9,58 @@#include <linux/init.h> #include <linux/arm-smccc.h> #include <linux/kernel.h> -#include <linux/platform_device.h> #include <linux/arm-smccc-bus.h> #include <linux/idr.h> #include <linux/slab.h> -#include <asm/archrandom.h> -static u32 smccc_version =ARM_SMCCC_VERSION_1_0 ;static enum arm_smccc_conduit smccc_conduit =SMCCC_CONDUIT_NONE ;static DEFINE_IDA (arm_smccc_bus_id);
Quoted 4 lines
drivers/firmware/smccc/smccc.c line 22
Quoted 4 lines
drivers/firmware/smccc/smccc.c +3
-1-bool __ro_after_init smccc_trng_available = false; +struct smccc_device_info { +u32 func_id; +bool requires_smc;
I wanted to ask this but just forgot.
RSI uses SMC because the Realm is calling the RMM, not the host hypervisor. Using HVC would make RSI look like a hypervisor ABI and would blur the trust boundary, is that right assumption ?
I assume the conduit derived from PSCI node for the realms will always be SMC and it shouldn't be a problem. I mean there won't be a case where you would need HVC as conduit within the realm VM kernel ?
Quoted 4 lines
drivers/firmware/smccc/smccc.c line 23
Quoted 1 line
drivers/firmware/smccc/smccc.c +1
-0+unsigned long min_return;Is this viable for all ? There may be additional restrictions around the return values and further SMC calls ?
Fair enough, but do you have examples currently ?
Quoted 2 lines
Which brings us to call backs and we kind of have a variant of that here.
I am fine with callback but need to keep the scope of it as minimum as possible IMO. For me it's simple if that main FID for that feature is implemented we create SMCCC device and probe can deal with all the extra details, why won't that work ? Just trying to understand why the core SMCCC bus need to know more or must provide a callback.
Signature · 2 lines
Regards, Sudeep
Hi Greg,
Quoted 25 lines · Aneesh Kumar K.V (Arm)
As discussed here:
https://lore.kernel.org/all/[email protected]The earlier CCA guest support used an arm-cca-dev platform device as a pure software anchor for the TSM class device. That platform device did not correspond to a DT/ACPI described device, MMIO range, interrupt, or other platform resource; it existed only to make the CCA guest driver bind and to place the resulting TSM device in the driver model. The same pattern also exists for
smccc_trng. Creating separate platform devices for such SMCCC-discovered features is misleading, because those features are not independent platform devices.This series adds an Arm SMCCC bus for services discovered through the SMCCC firmware interface. The bus provides SMCCC device and driver registration helpers, name-based matching, uevent modalias generation, and a sysfs modalias attribute. SMCCC service drivers can use
MODULE_DEVICE_TABLE(arm_smccc, ...)to emit arm_smccc:<name> aliases, allowing userspace to autoload service drivers when the SMCCC core registers matching firmware-service devices.The series then moves SMCCC TRNG and the Arm CCA guest RSI service off the platform bus. When the SMCCC core discovers the corresponding firmware service, it registers an arm-smccc device for that service. The hwrng
arm_smccc_trngdriver and the Arm CCA guest TSM provider are converted to SMCCC drivers that bind to those discovered devices.
Quoted 7 lines
The old arm-cca-dev platform device has also been used by userspace as a Realm guest indicator. Removing it without a replacement would leave userspace depending on an internal driver-binding device. This series therefore adds
/sys/firmware/cca/realm_guestas a stable, architecture-provided ABI for detecting whether the kernel is running as an Arm CCA Realm guest, and then removes the dummy arm-cca-dev platform-device registration.
Gentle ping. Based on your feedback in [1], I reworked the series to use an SMCCC bus, with smccc-trng and arm-cca-dev represented as devices on that bus. Could you let me know whether this approach addresses your concerns?
[1] https://lore.kernel.org/all/2026051451-comfort-museum-4d2a@gregkh/
-aneesh
Re: [PATCH v6 3/4] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
In reply to Sudeep HollaSudeep Holla <[email protected]> writes:
...
Quoted 24 lines
drivers/firmware/smccc/smccc.c +23
-0+static const struct smccc_device_info smccc_devices[]__initconst = { + { + .func_id =ARM_SMCCC_TRNG_VERSION , + .requires_smc = false, + .min_return =ARM_SMCCC_TRNG_MIN_VERSION , + .device_name ="arm-smccc-trng" , + }, +}; + +static bool __init +smccc_probe_smccc_device (const struct smccc_device_info *smccc_dev) +{ +struct arm_smccc_res res; +unsigned long ret; + +if (!IS_ENABLED (CONFIG_ARM64 )) +return false; + +if (smccc_conduit ==SMCCC_CONDUIT_NONE ) +return false; + +if (smccc_dev->requires_smc && smccc_conduit !=SMCCC_CONDUIT_SMC ) +return false;
drivers/firmware/smccc/smccc.c line 63
Quoted 10 lines
drivers/firmware/smccc/smccc.c +10
-0+ +arm_smccc_1_1_invoke (smccc_dev->func_id, &res); + ret = res.a0; + +if ((s32 )ret <0 ) +return false; + +return ret >= smccc_dev->min_return; +} +
I am not sure we want the check to be as simple as ret < 0. Some function IDs may return input errors based on the supplied arguments (for example, RMI_ERROR_INPUT). In those cases, we would likely want this to be handled via a callback.
We also want to use conditional compilation for some function IDs. Given the callback approach and the #ifdefs, I wonder whether what we currently have is actually simpler and more flexible.”
Quoted 32 lines
void
__initarm_smccc_version_init(u32 version, enum arm_smccc_conduit conduit){ struct arm_smccc_res res;drivers/firmware/smccc/smccc.c +8
-9@@ -31,7 +68,7 @@ void __init arm_smccc_version_init(u32 version, enum arm_smccc_conduit conduit) smccc_version = version; smccc_conduit = conduit; - smccc_trng_available =smccc_probe_trng (); + smccc_trng_available =smccc_probe_smccc_device (&smccc_devices[0 ]);if ((smccc_version >=ARM_SMCCC_VERSION_1_2 ) && (smccc_conduit !=SMCCC_CONDUIT_NONE )) {@@ -241,14 +278,20 @@ subsys_initcall(arm_smccc_bus_init);static int __init smccc_devices_init (void ) { -struct platform_device *pdev; - -if (smccc_trng_available) { - pdev =platform_device_register_simple ("smccc_trng" ,-1 , -NULL ,0 ); -if (IS_ERR (pdev)) -pr_err ("smccc_trng: could not register device: %ld\n" , -PTR_ERR (pdev)); +const struct smccc_device_info *smccc_dev; +struct arm_smccc_device *sdev; +int i; + +for (i =0 ; i <ARRAY_SIZE (smccc_devices); i++) { + smccc_dev = &smccc_devices[i]; +
drivers/firmware/smccc/smccc.c subsys_initcall(arm_smccc_bus_init); · line 297
Quoted 10 lines
drivers/firmware/smccc/smccc.c +7
-0+if (!smccc_probe_smccc_device (smccc_dev)) +continue ; + + sdev =arm_smccc_device_register (smccc_dev->device_name); +if (IS_ERR (sdev)) +pr_err ("%s: could not register device: %ld\n" , + smccc_dev->device_name,PTR_ERR (sdev)); }return 0 ;
-aneesh
Sudeep Holla
maintainerRe: [PATCH v6 3/4] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
Quoted 35 lines · Aneesh Kumar K.V
Sudeep Holla <[email protected]> writes:
...
Quoted 31 lines
drivers/firmware/smccc/smccc.c +31
-0+static const struct smccc_device_info smccc_devices[]__initconst = { + { + .func_id =ARM_SMCCC_TRNG_VERSION , + .requires_smc = false, + .min_return =ARM_SMCCC_TRNG_MIN_VERSION , + .device_name ="arm-smccc-trng" , + }, +}; + +static bool __init +smccc_probe_smccc_device (const struct smccc_device_info *smccc_dev) +{ +struct arm_smccc_res res; +unsigned long ret; + +if (!IS_ENABLED (CONFIG_ARM64 )) +return false; + +if (smccc_conduit ==SMCCC_CONDUIT_NONE ) +return false; + +if (smccc_dev->requires_smc && smccc_conduit !=SMCCC_CONDUIT_SMC ) +return false; + +arm_smccc_1_1_invoke (smccc_dev->func_id, &res); + ret = res.a0; + +if ((s32 )ret <0 ) +return false; + +return ret >= smccc_dev->min_return;
Quoted 9 lines
drivers/firmware/smccc/smccc.c line 63
Quoted 3 lines
drivers/firmware/smccc/smccc.c +2
-0+} +I am not sure we want the check to be as simple as ret < 0. Some function IDs may return input errors based on the supplied arguments (for example,
RMI_ERROR_INPUT). In those cases, we would likely want this to be handled via a callback.
As I mentioned in response to Suzuki, we can defer that to probe of that device. If *_VERSION, succeeds SMCCC core can add that device and leave the rest to the core keeping the core and bus layer simple IMO.
Quoted 4 lines
We also want to use conditional compilation for some function IDs. Given the callback approach and the #ifdefs, I wonder whether what we currently have is actually simpler and more flexible.”
I was trying to avoid conditional compilation altogether and hence the reason for keeping it as simple as possible. Also IS_ENABLED(CONFIG_ARM64) in above snippet must come as some condition to this generic probe.
Adding any more logic or callback defeats the bus idea here if we need to rely/depend on multiple conditional compilation or callbacks IMO.
Let's find see if it can work with what we are adding now and may add in near future and then decide.
Signature · 2 lines
Regards, Sudeep
Re: [PATCH v6 3/4] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
Quoted 59 lines · Sudeep Holla
Quoted 35 lines · Aneesh Kumar K.V
Sudeep Holla <[email protected]> writes:
...
Quoted 31 lines
drivers/firmware/smccc/smccc.c +31
-0+static const struct smccc_device_info smccc_devices[]__initconst = { + { + .func_id =ARM_SMCCC_TRNG_VERSION , + .requires_smc = false, + .min_return =ARM_SMCCC_TRNG_MIN_VERSION , + .device_name ="arm-smccc-trng" , + }, +}; + +static bool __init +smccc_probe_smccc_device (const struct smccc_device_info *smccc_dev) +{ +struct arm_smccc_res res; +unsigned long ret; + +if (!IS_ENABLED (CONFIG_ARM64 )) +return false; + +if (smccc_conduit ==SMCCC_CONDUIT_NONE ) +return false; + +if (smccc_dev->requires_smc && smccc_conduit !=SMCCC_CONDUIT_SMC ) +return false; + +arm_smccc_1_1_invoke (smccc_dev->func_id, &res); + ret = res.a0; + +if ((s32 )ret <0 ) +return false; + +return ret >= smccc_dev->min_return;Quoted 9 lines
drivers/firmware/smccc/smccc.c line 63
Quoted 3 lines
drivers/firmware/smccc/smccc.c +2
-0+} +I am not sure we want the check to be as simple as ret < 0. Some function IDs may return input errors based on the supplied arguments (for example,
RMI_ERROR_INPUT). In those cases, we would likely want this to be handled via a callback.As I mentioned in response to Suzuki, we can defer that to probe of that device. If
*_VERSION, succeeds SMCCC core can add that device and leave the rest to the core keeping the core and bus layer simple IMO.Quoted 4 lines
We also want to use conditional compilation for some function IDs. Given the callback approach and the #ifdefs, I wonder whether what we currently have is actually simpler and more flexible.”
I was trying to avoid conditional compilation altogether and hence the reason for keeping it as simple as possible. Also
IS_ENABLED(CONFIG_ARM64)in above snippet must come as some condition to this generic probe.
Quoted 6 lines
Adding any more logic or callback defeats the bus idea here if we need to rely/depend on multiple conditional compilation or callbacks IMO.
Let's find see if it can work with what we are adding now and may add in near future and then decide.
If we move all the conditional checks to the driver probe path, then I think this can work. Something like the below:
struct smccc_device_info {
u32 func_id;
bool requires_smc;
const char *device_name;
};static const struct smccc_device_info smccc_devices[] __initconst = {
{
.func_id = ARM_SMCCC_TRNG_VERSION,
.requires_smc = false,
.device_name = "arm-smccc-trng",
},
{
.func_id = RSI_ABI_VERSION,
.requires_smc = true,
.device_name = RSI_DEV_NAME,
},
};
static bool __init smccc_probe_smccc_device(const struct smccc_device_info *smccc_dev)
{
unsigned long ret;
struct arm_smccc_res res;
if (smccc_conduit == SMCCC_CONDUIT_NONE)
return false;
if (smccc_dev->requires_smc && smccc_conduit != SMCCC_CONDUIT_SMC)
return false;
arm_smccc_1_1_invoke(smccc_dev->func_id, &res);
ret = res.a0;
if ((s32)ret == SMCCC_RET_NOT_SUPPORTED)
return false;
return true;
}static int __init smccc_devices_init(void)
{
struct arm_smccc_device *sdev;
const struct smccc_device_info *smccc_dev;
for (int i = 0; i < ARRAY_SIZE(smccc_devices); i++) {
smccc_dev = &smccc_devices[i];
if (!smccc_probe_smccc_device(smccc_dev))
continue;
sdev = arm_smccc_device_register(smccc_dev->device_name);
if (IS_ERR(sdev))
pr_err("%s: could not register device: %ld\n",
smccc_dev->device_name, PTR_ERR(sdev));
}
return 0;
}device_initcall(smccc_devices_init);
with the diff to hw_random/smccc_trng
modified arch/arm64/include/asm/archrandom.h
@@ -12,7 +12,7 @@
extern bool smccc_trng_available;
-static inline bool __init smccc_probe_trng(void)
+static inline bool smccc_probe_trng(void)
{
struct arm_smccc_res res;
modified drivers/char/hw_random/arm_smccc_trng.c
@@ -19,6 +19,8 @@
#include <linux/arm-smccc.h>
#include <linux/arm-smccc-bus.h>
+#include <asm/archrandom.h>
+
#ifdef CONFIG_ARM64
#define ARM_SMCCC_TRNG_RND ARM_SMCCC_TRNG_RND64
#define MAX_BITS_PER_CALL (3 * 64UL)
@@ -98,6 +100,10 @@ static int smccc_trng_probe(struct arm_smccc_device *sdev)
{
struct hwrng *trng;
+ /* validate the minimum version requirement */
+ if (!smccc_probe_trng())
+ return -ENODEV;
+
trng = devm_kzalloc(&sdev->dev, sizeof(*trng), GFP_KERNEL); if (!trng)
return -ENOMEM;
We can also move arch/arm64/include/asm/rsi_smc.h to include/linux/arm-rsi-smccc.h. There was a suggestion to move these firmware interfaces out of architecture-specific code:
https://lore.kernel.org/all/agsNO9cc7H-b0H8L@willie-the-truck
This will also avoid the #ifdef CONFIG_ARM64
-aneesh
Sudeep Holla
maintainerRe: [PATCH v6 3/4] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
Quoted 64 lines · Aneesh Kumar K.V
Quoted 62 lines · Sudeep Holla
Quoted 35 lines · Aneesh Kumar K.V
Sudeep Holla <[email protected]> writes:
...
Quoted 31 lines
drivers/firmware/smccc/smccc.c +31
-0+static const struct smccc_device_info smccc_devices[]__initconst = { + { + .func_id =ARM_SMCCC_TRNG_VERSION , + .requires_smc = false, + .min_return =ARM_SMCCC_TRNG_MIN_VERSION , + .device_name ="arm-smccc-trng" , + }, +}; + +static bool __init +smccc_probe_smccc_device (const struct smccc_device_info *smccc_dev) +{ +struct arm_smccc_res res; +unsigned long ret; + +if (!IS_ENABLED (CONFIG_ARM64 )) +return false; + +if (smccc_conduit ==SMCCC_CONDUIT_NONE ) +return false; + +if (smccc_dev->requires_smc && smccc_conduit !=SMCCC_CONDUIT_SMC ) +return false; + +arm_smccc_1_1_invoke (smccc_dev->func_id, &res); + ret = res.a0; + +if ((s32 )ret <0 ) +return false; + +return ret >= smccc_dev->min_return;Quoted 9 lines
drivers/firmware/smccc/smccc.c line 63
Quoted 3 lines
drivers/firmware/smccc/smccc.c +2
-0+} +I am not sure we want the check to be as simple as ret < 0. Some function IDs may return input errors based on the supplied arguments (for example,
RMI_ERROR_INPUT). In those cases, we would likely want this to be handled via a callback.As I mentioned in response to Suzuki, we can defer that to probe of that device. If
*_VERSION, succeeds SMCCC core can add that device and leave the rest to the core keeping the core and bus layer simple IMO.Quoted 4 lines
We also want to use conditional compilation for some function IDs. Given the callback approach and the #ifdefs, I wonder whether what we currently have is actually simpler and more flexible.”
I was trying to avoid conditional compilation altogether and hence the reason for keeping it as simple as possible. Also
IS_ENABLED(CONFIG_ARM64)in above snippet must come as some condition to this generic probe.Adding any more logic or callback defeats the bus idea here if we need to rely/depend on multiple conditional compilation or callbacks IMO.
Quoted 7 lines
Quoted 3 lines
Let's find see if it can work with what we are adding now and may add in near future and then decide.
If we move all the conditional checks to the driver probe path, then I think this can work. Something like the below:
Sounds good to me.
[...]
Quoted 6 lines
We can also move
arch/arm64/include/asm/rsi_smc.htoinclude/linux/arm-rsi-smccc.h. There was a suggestion to move these firmware interfaces out of architecture-specific code:https://lore.kernel.org/all/agsNO9cc7H-b0H8L@willie-the-truck
Ah OK, sorry I had missed this.
Signature · 2 lines
Regards, Sudeep
Re: [PATCH v6 3/4] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
In reply to Aneesh Kumar K.VQuoted 84 lines · Aneesh Kumar K.V
Quoted 59 lines · Sudeep Holla
Quoted 35 lines · Aneesh Kumar K.V
Sudeep Holla <[email protected]> writes:
...
Quoted 31 lines
drivers/firmware/smccc/smccc.c +31
-0+static const struct smccc_device_info smccc_devices[]__initconst = { + { + .func_id =ARM_SMCCC_TRNG_VERSION , + .requires_smc = false, + .min_return =ARM_SMCCC_TRNG_MIN_VERSION , + .device_name ="arm-smccc-trng" , + }, +}; + +static bool __init +smccc_probe_smccc_device (const struct smccc_device_info *smccc_dev) +{ +struct arm_smccc_res res; +unsigned long ret; + +if (!IS_ENABLED (CONFIG_ARM64 )) +return false; + +if (smccc_conduit ==SMCCC_CONDUIT_NONE ) +return false; + +if (smccc_dev->requires_smc && smccc_conduit !=SMCCC_CONDUIT_SMC ) +return false; + +arm_smccc_1_1_invoke (smccc_dev->func_id, &res); + ret = res.a0; + +if ((s32 )ret <0 ) +return false; + +return ret >= smccc_dev->min_return;Quoted 9 lines
drivers/firmware/smccc/smccc.c line 63
Quoted 3 lines
drivers/firmware/smccc/smccc.c +2
-0+} +I am not sure we want the check to be as simple as ret < 0. Some function IDs may return input errors based on the supplied arguments (for example,
RMI_ERROR_INPUT). In those cases, we would likely want this to be handled via a callback.As I mentioned in response to Suzuki, we can defer that to probe of that device. If
*_VERSION, succeeds SMCCC core can add that device and leave the rest to the core keeping the core and bus layer simple IMO.Quoted 4 lines
We also want to use conditional compilation for some function IDs. Given the callback approach and the #ifdefs, I wonder whether what we currently have is actually simpler and more flexible.”
I was trying to avoid conditional compilation altogether and hence the reason for keeping it as simple as possible. Also
IS_ENABLED(CONFIG_ARM64)in above snippet must come as some condition to this generic probe.Quoted 6 lines
Adding any more logic or callback defeats the bus idea here if we need to rely/depend on multiple conditional compilation or callbacks IMO.
Let's find see if it can work with what we are adding now and may add in near future and then decide.
If we move all the conditional checks to the driver probe path, then I think this can work. Something like the below:
struct smccc_device_info { u32 func_id; bool requires_smc; const char *device_name; };static const struct
smccc_device_infosmccc_devices[]__initconst= {
{
.func_id =ARM_SMCCC_TRNG_VERSION,
.requires_smc = false,
.device_name = "arm-smccc-trng",
},
Quoted 2 lines
{
.func_id =RSI_ABI_VERSION,
Don't we need parameters passed to this (Requested Interface version for e.g.) ? See more below.
Quoted 6 lines
.requires_smc = true,
.device_name =RSI_DEV_NAME,
},
};static bool
__initsmccc_probe_smccc_device(const struct smccc_device_info *smccc_dev)
Quoted 14 lines
{
unsigned long ret;
struct arm_smccc_res res;
if (smccc_conduit == SMCCC_CONDUIT_NONE)
return false;
if (smccc_dev->requires_smc && smccc_conduit != SMCCC_CONDUIT_SMC)
return false;
arm_smccc_1_1_invoke(smccc_dev->func_id, &res);
ret = res.a0;
if ((s32)ret == SMCCC_RET_NOT_SUPPORTED)Is this a reliable check for all possible SMCCC services ? i.e., Are we expected to get RET_NOT_SUPPORTED for any service for which the backend is not available ?
Also, as pointed out RSI_ABI_VERSION may return other errors based on the input (requested version, e.g., RSI_ERROR_INPUT) and we may still go ahead and register the device ?
Quoted 61 lines
return false; return true; }static int
__initsmccc_devices_init(void){ struct arm_smccc_device *sdev; const struct smccc_device_info *smccc_dev; for (int i = 0; i < ARRAY_SIZE(smccc_devices); i++) { smccc_dev = &smccc_devices[i]; if (!smccc_probe_smccc_device(smccc_dev)) continue; sdev = arm_smccc_device_register(smccc_dev->device_name); if (IS_ERR(sdev)) pr_err("%s: could not register device: %ld\n", smccc_dev->device_name, PTR_ERR(sdev)); } return 0; }
device_initcall(smccc_devices_init);with the diff to hw_random/smccc_trng
modified
arch/arm64/include/asm/archrandom.hdrivers/firmware/smccc/smccc.c +1
-1@@ -12,7 +12,7 @@extern bool smccc_trng_available; -static inline bool __init smccc_probe_trng (void ) +static inline bool smccc_probe_trng (void ) {struct arm_smccc_res res;modified
drivers/char/hw_random/arm_smccc_trng.cdrivers/firmware/smccc/smccc.c +6
-0@@ -19,6 +19,8 @@#include <linux/arm-smccc.h> #include <linux/arm-smccc-bus.h> +#include <asm/archrandom.h> +#ifdef CONFIG_ARM64 #define ARM_SMCCC_TRNG_RND ARM_SMCCC_TRNG_RND64#define MAX_BITS_PER_CALL (3 * 64UL)@@ -98,6 +100,10 @@ static int smccc_trng_probe(struct arm_smccc_device *sdev) {struct hwrng *trng; +/* validate the minimum version requirement */ +if (!smccc_probe_trng ()) +return -ENODEV ; + trng =devm_kzalloc (&sdev->dev,sizeof (*trng),GFP_KERNEL );if (!trng)return -ENOMEM ;
Quoted 2 lines
We can also move
arch/arm64/include/asm/rsi_smc.htoinclude/linux/arm-rsi-smccc.h. There was a suggestion to move these
super minor nit: arm-smccc-rsi.h ?
Cheers
Suzuki
Quoted 7 lines
firmware interfaces out of architecture-specific code:
https://lore.kernel.org/all/agsNO9cc7H-b0H8L@willie-the-truck
This will also avoid the #ifdef
CONFIG_ARM64-aneesh
Re: [PATCH v6 3/4] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
Quoted 7 lines · Suzuki K Poulose
Quoted 6 lines · Aneesh Kumar K.V
Quoted 4 lines · Sudeep Holla
Quoted 3 lines · Aneesh Kumar K.V
Sudeep Holla <[email protected]> writes:
...
...
Quoted 27 lines
Quoted 27 lines
Quoted 10 lines
I was trying to avoid conditional compilation altogether and hence the reason for keeping it as simple as possible. Also
IS_ENABLED(CONFIG_ARM64)in above snippet must come as some condition to this generic probe.Adding any more logic or callback defeats the bus idea here if we need to rely/depend on multiple conditional compilation or callbacks IMO.
Let's find see if it can work with what we are adding now and may add in near future and then decide.
If we move all the conditional checks to the driver probe path, then I think this can work. Something like the below:
struct smccc_device_info { u32 func_id; bool requires_smc; const char *device_name; };static const struct
smccc_device_infosmccc_devices[]__initconst= {
{
.func_id =ARM_SMCCC_TRNG_VERSION,
.requires_smc = false,
.device_name = "arm-smccc-trng",
},
Quoted 6 lines
Quoted 2 lines
{ .func_id = RSI_ABI_VERSION,Don't we need parameters passed to this (Requested Interface version for e.g.) ? See more below.
The idea is that we only check whether the function ID is supported. All other conditional logic should be handled in the driver probe path, as demonstrated by the changes in drivers/char/hw_random/arm_smccc_trng.c.
Quoted 17 lines
Quoted 17 lines
.requires_smc = true,
.device_name =RSI_DEV_NAME,
},
};static bool
__initsmccc_probe_smccc_device(const struct smccc_device_info *smccc_dev){ unsigned long ret; struct arm_smccc_res res; if (smccc_conduit == SMCCC_CONDUIT_NONE) return false; if (smccc_dev->requires_smc && smccc_conduit != SMCCC_CONDUIT_SMC) return false;
Quoted 9 lines
Quoted 4 lines
arm_smccc_1_1_invoke(smccc_dev->func_id, &res); ret = res.a0; if ((s32)ret == SMCCC_RET_NOT_SUPPORTED)Is this a reliable check for all possible SMCCC services ? i.e., Are we expected to get
RET_NOT_SUPPORTEDfor any service for which the backend is not available ?
That is correct. That is what the SMCCC specification says
Quoted 4 lines
Also, as pointed out
RSI_ABI_VERSIONmay return other errors based on the input (requested version, e.g.,RSI_ERROR_INPUT) and we may still go ahead and register the device ?
Correct, and the driver probe will check for the minimum and maximum supported versions.
Quoted 61 lines
Quoted 61 lines
return false; return true; }static int
__initsmccc_devices_init(void){ struct arm_smccc_device *sdev; const struct smccc_device_info *smccc_dev; for (int i = 0; i < ARRAY_SIZE(smccc_devices); i++) { smccc_dev = &smccc_devices[i]; if (!smccc_probe_smccc_device(smccc_dev)) continue; sdev = arm_smccc_device_register(smccc_dev->device_name); if (IS_ERR(sdev)) pr_err("%s: could not register device: %ld\n", smccc_dev->device_name, PTR_ERR(sdev)); } return 0; }
device_initcall(smccc_devices_init);with the diff to hw_random/smccc_trng
modified
arch/arm64/include/asm/archrandom.hdrivers/firmware/smccc/smccc.c +1
-1@@ -12,7 +12,7 @@extern bool smccc_trng_available; -static inline bool __init smccc_probe_trng (void ) +static inline bool smccc_probe_trng (void ) {struct arm_smccc_res res;modified
drivers/char/hw_random/arm_smccc_trng.cdrivers/firmware/smccc/smccc.c +6
-0@@ -19,6 +19,8 @@#include <linux/arm-smccc.h> #include <linux/arm-smccc-bus.h> +#include <asm/archrandom.h> +#ifdef CONFIG_ARM64 #define ARM_SMCCC_TRNG_RND ARM_SMCCC_TRNG_RND64#define MAX_BITS_PER_CALL (3 * 64UL)@@ -98,6 +100,10 @@ static int smccc_trng_probe(struct arm_smccc_device *sdev) {struct hwrng *trng; +/* validate the minimum version requirement */ +if (!smccc_probe_trng ()) +return -ENODEV ; + trng =devm_kzalloc (&sdev->dev,sizeof (*trng),GFP_KERNEL );if (!trng)return -ENOMEM ;
Quoted 5 lines
Quoted 2 lines
We can also move
arch/arm64/include/asm/rsi_smc.htoinclude/linux/arm-rsi-smccc.h. There was a suggestion to move thesesuper minor nit:
arm-smccc-rsi.h?
-aneesh
Sudeep Holla
maintainerRe: [PATCH v6 3/4] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
Quoted 42 lines · Aneesh Kumar K.V
Quoted 7 lines · Suzuki K Poulose
Quoted 6 lines · Aneesh Kumar K.V
Quoted 4 lines · Sudeep Holla
Quoted 3 lines · Aneesh Kumar K.V
Sudeep Holla <[email protected]> writes:
...
...
Quoted 30 lines
Quoted 29 lines
Quoted 10 lines
I was trying to avoid conditional compilation altogether and hence the reason for keeping it as simple as possible. Also
IS_ENABLED(CONFIG_ARM64)in above snippet must come as some condition to this generic probe.Adding any more logic or callback defeats the bus idea here if we need to rely/depend on multiple conditional compilation or callbacks IMO.
Let's find see if it can work with what we are adding now and may add in near future and then decide.
If we move all the conditional checks to the driver probe path, then I think this can work. Something like the below:
struct smccc_device_info { u32 func_id; bool requires_smc; const char *device_name; };static const struct
smccc_device_infosmccc_devices[]__initconst= {
{
.func_id =ARM_SMCCC_TRNG_VERSION,
.requires_smc = false,
.device_name = "arm-smccc-trng",
},{
.func_id =RSI_ABI_VERSION,
Quoted 8 lines
Quoted 3 lines
Don't we need parameters passed to this (Requested Interface version for e.g.) ? See more below.
The idea is that we only check whether the function ID is supported. All other conditional logic should be handled in the driver probe path, as demonstrated by the changes in
drivers/char/hw_random/arm_smccc_trng.c.
+1. Yes, we just want to know whether the firmware is aware of that feature before creating the smccc_device for it. The device probe can then perform a more thorough, feature-specific check to determine whether the device/feature is usable.
That is the main idea behind the approach I suggested. Please let me know if you still see any issues or think this may not work.
Signature · 2 lines
Regards, Sudeep
Re: [PATCH v6 3/4] firmware: smccc: arm-cca-guest: Bind the TSM provider to an SMCCC device
Quoted 52 lines · Sudeep Holla
Quoted 42 lines · Aneesh Kumar K.V
Quoted 7 lines · Suzuki K Poulose
Quoted 6 lines · Aneesh Kumar K.V
Quoted 4 lines · Sudeep Holla
Quoted 3 lines · Aneesh Kumar K.V
Sudeep Holla <[email protected]> writes:
...
...
Quoted 30 lines
Quoted 29 lines
Quoted 10 lines
I was trying to avoid conditional compilation altogether and hence the reason for keeping it as simple as possible. Also
IS_ENABLED(CONFIG_ARM64)in above snippet must come as some condition to this generic probe.Adding any more logic or callback defeats the bus idea here if we need to rely/depend on multiple conditional compilation or callbacks IMO.
Let's find see if it can work with what we are adding now and may add in near future and then decide.
If we move all the conditional checks to the driver probe path, then I think this can work. Something like the below:
struct smccc_device_info { u32 func_id; bool requires_smc; const char *device_name; };static const struct
smccc_device_infosmccc_devices[]__initconst= {
{
.func_id =ARM_SMCCC_TRNG_VERSION,
.requires_smc = false,
.device_name = "arm-smccc-trng",
},{
.func_id =RSI_ABI_VERSION,Quoted 8 lines
Quoted 3 lines
Don't we need parameters passed to this (Requested Interface version for e.g.) ? See more below.
The idea is that we only check whether the function ID is supported. All other conditional logic should be handled in the driver probe path, as demonstrated by the changes in
drivers/char/hw_random/arm_smccc_trng.c.
Quoted 7 lines
+1. Yes, we just want to know whether the firmware is aware of that feature before creating the
smccc_devicefor it. The device probe can then perform a more thorough, feature-specific check to determine whether the device/feature is usable.That is the main idea behind the approach I suggested. Please let me know if you still see any issues or think this may not work.
Ok, yea, I kind of forgot that we are boot strapping a driver based on this "smccc device" and the device is only an indication of the firmware service, the driver would decide if the service matches its expectation.
Thanks for the clarification, apologies for the noise.
Suzuki