* [PATCH RFC v2 0/6] firmware: arm_firme: introduce FIRME support for host attestation
@ 2026-11-27 15:28 Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 1/6] firmware: arm-smccc: introduce match function Yeoreum Yun
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Yeoreum Yun @ 2026-11-27 15:28 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel
Cc: Lorenzo Pieralisi, Catalin Marinas, Suzuki Poulose, Steven Price,
Sami Mujawar, Aneesh Kumar K.V, Jiri Pirko, GONG Ruiqi,
Jason Gunthorpe, Mark Brown, Yeoreum Yun
The Arm Confidential Compute Architecture (CCA) introduces the
Realm Management Extension (FEAT_RME), which enables the creation and
management of dynamically allocated, attestable trusted execution
environments known as Realms.
Realm management relies on EL3 firmware to provide services for Realm
construction, resource allocation and isolation, and attestation of
the initial Realm state.
The Firmware Interface for Realm Management Extensions (FIRME) [0]
specification defines standard interfaces through which EL3 firmware
provides these services. FIRME defines the following service groups:
- Granule Protection Table (GPT) management
- IDE key management for PCIe and CXL Root Ports
- Memory Encryption Context management
- Attestation Token management
- Integrated Device management
FIRME also defines a Base service that provides common functionality,
including service discovery and feature discovery.
Although FIRME primarily supports Arm CCA, its interfaces can also be used
on systems without FEAT_RME to provide firmware-based attestation and
other security services.
This RFC patch series introduces the arm_firme, which provides
the common APIs used to firme service driver implementation.
each firme service driver would be implmented based on the smccc-bus
with common APIs and add firme attestation provider with smccc driver.
This patch based on arm64/for-next/smccc-bus and attestation branch [1-3].
To: linux-kernel@vger.kernel.org
To: linux-arm-kernel@lists.infradead.org
Cc: Lorenzo Pieralisi <lpieralisi@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Suzuki Poulose <suzuki.poulose@arm.com>
Cc: Steven Price <steven.price@arm.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@kernel.org>
Cc: Jiri Pirko <jiri@resnulli.us>
Cc: GONG Ruiqi <gongruiqi1@huawei.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Mark Brown <broonie@kernel.org>
Link: [0] https://support.arm.com/documentation/den0149/latest
Link: [1] https://github.com/jpirko/linux_mlxsw/tree/wip_attestation_all_2
Link: [2] https://lore.kernel.org/all/20261113155515.2510194-1-jiri@resnulli.us/
Link: [3] https://lore.kernel.org/all/20261113160838.2512652-1-jiri@resnulli.us/
---
Changes in RFCv2:
- rebase on the attestation infrastructure.
- librarise arm_firme.c from firme driver.
- add firme attestation provider.
- Link to RFCv1: https://lore.kernel.org/r/20261019-firme_interface-v1-0-27895c9cebaa@arm.com
---
Yeoreum Yun (6):
firmware: arm-smccc: introduce match function
firmware: arm_firme: introduce arm_firme
Documentation/ctlv: introduce ctlv-attestation-firme family
ctlv: add auto-generated files for ctlv-attestation-firme
attestation: providers: introduce FIRME attestation provider
selftest: attestation: add firme_attestation_test selftest
Documentation/ctlv/abi/ctlv-attestation-firme.yaml | 19 +
Documentation/ctlv/abi/families.registry.yaml | 1 +
Documentation/ctlv/families.yaml | 1 +
Documentation/ctlv/generated-files.yaml | 11 +
.../ctlv/specs/ctlv-attestation-firme.yaml | 20 +
drivers/attestation/Kconfig | 9 +
drivers/attestation/Makefile | 5 +
.../generated/ctlv_attestation_firme_gen.c | 64 +
.../generated/ctlv_attestation_firme_gen.h | 40 +
drivers/attestation/providers/firme.c | 292 ++++
drivers/firmware/Kconfig | 36 +
drivers/firmware/Makefile | 1 +
drivers/firmware/arm_firme.c | 275 ++++
drivers/firmware/smccc/bus.c | 24 +-
drivers/firmware/smccc/smccc.c | 3 +-
include/linux/arm-smccc-bus.h | 5 +-
include/linux/arm-smccc.h | 1 +
include/linux/arm_firme.h | 261 ++++
include/uapi/ctlv/ctlv_attestation_firme_gen.h | 34 +
include/uapi/ctlv/ctlv_families_gen.h | 1 +
tools/testing/selftests/attestation/.gitignore | 1 +
tools/testing/selftests/attestation/Makefile | 10 +-
.../attestation/ctlv_attestation_firme_user_gen.c | 1547 ++++++++++++++++++++
.../attestation/ctlv_attestation_firme_user_gen.h | 47 +
.../selftests/attestation/firme_attestation_test.c | 232 +++
25 files changed, 2928 insertions(+), 12 deletions(-)
---
base-commit: 7ff5e548abbc2312431d4eea9ad283347963a6e2
change-id: 20260729-firme_interface-75616c45a203
Best regards,
--
Sincerely,
Yeoreum Yun
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH RFC v2 1/6] firmware: arm-smccc: introduce match function
2026-11-27 15:28 [PATCH RFC v2 0/6] firmware: arm_firme: introduce FIRME support for host attestation Yeoreum Yun
@ 2026-11-27 15:28 ` Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 2/6] firmware: arm_firme: introduce arm_firme Yeoreum Yun
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Yeoreum Yun @ 2026-11-27 15:28 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel
Cc: Lorenzo Pieralisi, Catalin Marinas, Suzuki Poulose, Steven Price,
Sami Mujawar, Aneesh Kumar K.V, Jiri Pirko, GONG Ruiqi,
Jason Gunthorpe, Mark Brown, Yeoreum Yun
Somce of protocol based on the smc is not enough to match smccc-device
and smccc-driver with func_id only.
For example, firme interface will create smccc-device per service
and this requires to chech whether firme smccc-device is for each
service.
To resolve this, add match function and match parameter for device
which is set at the time of smccc-device creation so that smccc-driver
could match proper smccc-device with match parameter and driver specific
match function.
This match parameter is defined under smc func-id. IOW, devices which
share the func-id should have the same type for module parameter so
that each driver under the same func-id can check extra one with
match parameter type.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
drivers/firmware/smccc/bus.c | 24 ++++++++++++++++--------
drivers/firmware/smccc/smccc.c | 3 ++-
include/linux/arm-smccc-bus.h | 5 ++++-
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/drivers/firmware/smccc/bus.c b/drivers/firmware/smccc/bus.c
index 0357a7c48af0b..4a1182153bef8 100644
--- a/drivers/firmware/smccc/bus.c
+++ b/drivers/firmware/smccc/bus.c
@@ -11,15 +11,20 @@ static int arm_smccc_bus_match(struct device *dev,
{
const struct arm_smccc_device_id *id_table;
const struct arm_smccc_device *smccc_dev = to_arm_smccc_device(dev);
+ const struct arm_smccc_driver *smccc_drv = to_arm_smccc_driver(drv);
- id_table = to_arm_smccc_driver(drv)->id_table;
+ id_table = smccc_drv->id_table;
if (!id_table)
return 0;
- while (id_table->func_id) {
- if (smccc_dev->func_id == id_table->func_id)
- return 1;
- id_table++;
+ for (; id_table->func_id; id_table++) {
+ if (smccc_dev->func_id != id_table->func_id)
+ continue;
+ if (!!smccc_dev->match_params != !!smccc_drv->match)
+ continue;
+ if (smccc_drv->match && !smccc_drv->match(smccc_dev))
+ continue;
+ return 1;
}
return 0;
@@ -103,7 +108,7 @@ static void arm_smccc_release_device(struct device *dev)
kfree(smccc_dev);
}
-static struct device *arm_smccc_device_alloc(u32 func_id)
+static struct device *arm_smccc_device_alloc(u32 func_id, void *match_params)
{
struct arm_smccc_device *smccc_dev;
@@ -112,6 +117,7 @@ static struct device *arm_smccc_device_alloc(u32 func_id)
return NULL;
smccc_dev->func_id = func_id;
+ smccc_dev->match_params = match_params;
smccc_dev->dev.bus = &arm_smccc_bus_type;
smccc_dev->dev.release = arm_smccc_release_device;
device_initialize(&smccc_dev->dev);
@@ -119,14 +125,16 @@ static struct device *arm_smccc_device_alloc(u32 func_id)
return &smccc_dev->dev;
}
-struct arm_smccc_device *arm_smccc_device_register(const char *name, u32 func_id)
+struct arm_smccc_device *arm_smccc_device_register(const char *name, u32 func_id,
+ void *match_params)
{
int ret;
if (!name)
return ERR_PTR(-EINVAL);
- struct device *dev __free(put_device) = arm_smccc_device_alloc(func_id);
+ struct device *dev __free(put_device) = arm_smccc_device_alloc(func_id,
+ match_params);
if (!dev)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/firmware/smccc/smccc.c b/drivers/firmware/smccc/smccc.c
index 5dc768ac4143a..93658120114d3 100644
--- a/drivers/firmware/smccc/smccc.c
+++ b/drivers/firmware/smccc/smccc.c
@@ -136,7 +136,8 @@ static int __init smccc_devices_init(void)
if (!smccc_probe_smccc_device(smccc_dev))
continue;
- sdev = arm_smccc_device_register(smccc_dev->device_name, smccc_dev->func_id);
+ sdev = arm_smccc_device_register(smccc_dev->device_name,
+ smccc_dev->func_id, NULL);
if (IS_ERR(sdev))
pr_err("%s: could not register device: %pe\n",
smccc_dev->device_name, sdev);
diff --git a/include/linux/arm-smccc-bus.h b/include/linux/arm-smccc-bus.h
index 05c0c850510e0..b7b44c9b67ec3 100644
--- a/include/linux/arm-smccc-bus.h
+++ b/include/linux/arm-smccc-bus.h
@@ -12,6 +12,7 @@
struct arm_smccc_device {
struct device dev;
u32 func_id;
+ void *match_params;
};
#define to_arm_smccc_device(d) container_of_const(d, struct arm_smccc_device, dev)
@@ -22,6 +23,7 @@ struct arm_smccc_driver {
const char *name;
int (*probe)(struct arm_smccc_device *sdev);
void (*remove)(struct arm_smccc_device *sdev);
+ bool (*match)(const struct arm_smccc_device *sdev);
const struct arm_smccc_device_id *id_table;
};
@@ -31,7 +33,8 @@ struct arm_smccc_driver {
int arm_smccc_driver_register(struct arm_smccc_driver *driver,
struct module *owner, const char *mod_name);
void arm_smccc_driver_unregister(struct arm_smccc_driver *driver);
-struct arm_smccc_device *arm_smccc_device_register(const char *name, u32 func_id);
+struct arm_smccc_device *arm_smccc_device_register(const char *name, u32 func_id,
+ void *match_param);
void arm_smccc_device_unregister(struct arm_smccc_device *smcc_dev);
#define arm_smccc_register(driver) \
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH RFC v2 2/6] firmware: arm_firme: introduce arm_firme
2026-11-27 15:28 [PATCH RFC v2 0/6] firmware: arm_firme: introduce FIRME support for host attestation Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 1/6] firmware: arm-smccc: introduce match function Yeoreum Yun
@ 2026-11-27 15:28 ` Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 3/6] Documentation/ctlv: introduce ctlv-attestation-firme family Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 5/6] attestation: providers: introduce FIRME attestation provider Yeoreum Yun
3 siblings, 0 replies; 5+ messages in thread
From: Yeoreum Yun @ 2026-11-27 15:28 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel
Cc: Lorenzo Pieralisi, Catalin Marinas, Suzuki Poulose, Steven Price,
Sami Mujawar, Aneesh Kumar K.V, Jiri Pirko, GONG Ruiqi,
Jason Gunthorpe, Mark Brown, Yeoreum Yun
The Realm Management Extension (FEAT_RME) is part of Arm Confidential
Compute Architecture (CCA) and enables support for dynamic, attestable
trusted execution environments ("Realms") on Arm systems.
Realm management flows depend on EL3 firmware for operations such as
Realm construction, resource allocation and isolation, and attestation
of initial Realm state.
The FIRME defines standard interfaces provided by EL3 firmware to
satisfy these dependencies. These interfaces include:
- Granule Protection Table management
- IDE key management for PCIe and CXL Root Ports
- Memory Encryption Context management
- Attestation token management
- Integrated device management
Each group of interfaces forms a FIRME service. A base FIRME service
is also defined to provide common concepts, service discovery, and
feature discovery across services.
FIRME interfaces are implemented at the EL3 boundary between the
Non-secure, Realm, and Secure states. They may also be used on systems
without FEAT_RME, for example to provide firmware-based attestation or
security services.
arm_firme.c provides the common APIs to be used for FIRME device/driver
to support for FIRME services
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
drivers/firmware/Kconfig | 36 ++++++
drivers/firmware/Makefile | 1 +
drivers/firmware/arm_firme.c | 275 +++++++++++++++++++++++++++++++++++++++++++
include/linux/arm-smccc.h | 1 +
include/linux/arm_firme.h | 261 ++++++++++++++++++++++++++++++++++++++++
5 files changed, 574 insertions(+)
diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index 43e2e2a645945..d031c36c44dcc 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -60,6 +60,42 @@ config ARM_SDEI_NMI
If unsure, say N.
+config ARM_FIRME
+ bool "Arm Firmware Interfaces for Realm Management Extension (FIRME)"
+ depends on ARM64 && HAVE_ARM_SMCCC_DISCOVERY
+ default n
+ help
+ The Realm Management Extension (FEAT_RME) is part of Arm Confidential
+ Compute Architecture (CCA) and enables support for dynamic, attestable
+ trusted execution environments ("Realms") on Arm systems.
+
+ Realm management flows depend on EL3 firmware for operations such as
+ Realm construction, resource allocation and isolation, and attestation
+ of initial Realm state.
+
+ The FIRME defines standard interfaces provided by EL3 firmware to
+ satisfy these dependencies. These interfaces include:
+
+ - Granule Protection Table management
+ - IDE key management for PCIe and CXL Root Ports
+ - Memory Encryption Context management
+ - Attestation token management
+ - Integrated device management
+
+ Each group of interfaces forms a FIRME service. A base FIRME service
+ is also defined to provide common concepts, service discovery, and
+ feature discovery across services.
+
+ FIRME interfaces are implemented at the EL3 boundary between the
+ Non-secure, Realm, and Secure states. They may also be used on
+ systems without FEAT_RME, for example to provide firmware-based
+ attestation or security services.
+
+ This opions provides the common APIs used for FIRME service
+ implementation driver.
+
+ If unsure, say N.
+
config EDD
tristate "BIOS Enhanced Disk Drive calls determine boot disk"
depends on X86
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
index 50b3383131522..2e217c6b80f26 100644
--- a/drivers/firmware/Makefile
+++ b/drivers/firmware/Makefile
@@ -2,6 +2,7 @@
#
# Makefile for the linux kernel.
#
+obj-$(CONFIG_ARM_FIRME) += arm_firme.o
obj-$(CONFIG_ARM_SCPI_PROTOCOL) += arm_scpi.o
obj-$(CONFIG_ARM_SDE_INTERFACE) += arm_sdei.o
obj-$(CONFIG_ARM_SDEI_NMI) += arm_sdei_nmi.o
diff --git a/drivers/firmware/arm_firme.c b/drivers/firmware/arm_firme.c
new file mode 100644
index 0000000000000..fafed19121141
--- /dev/null
+++ b/drivers/firmware/arm_firme.c
@@ -0,0 +1,275 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Arm Ltd.
+ */
+
+#define DRIVER_NAME "ARM FIRME"
+#define pr_fmt(fmt) DRIVER_NAME ": " fmt
+
+#include <linux/arm_firme.h>
+#include <linux/arm-smccc-bus.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/static_key.h>
+
+struct firme_base_service_info {
+ u32 version;
+ struct firme_shared_buf_info shbuf_info;
+} base_service_info;
+
+static DEFINE_STATIC_KEY_TRUE(firme_disabled);
+
+static __always_inline int __firme_get_version(enum firme_service_id service_id,
+ u32 *version)
+{
+ firme_value_t ret;
+
+ invoke_firme_service((firme_value_t) {
+ .a0 = FIRME_SERVICE_VERSION,
+ .a1 = service_id,
+ }, &ret);
+ if (ret.a0 == FIRME_RET_NOT_SUPPORTED)
+ goto err_out;
+
+ *version = (u32)ret.a0;
+ return 0;
+
+err_out:
+ return firme_status_to_errno(ret.a0);
+}
+
+static __always_inline int __firme_get_feature(enum firme_service_id service_id,
+ uint8_t feat_idx, unsigned long *feature)
+{
+ firme_value_t ret;
+
+ invoke_firme_service((firme_value_t) {
+ .a0 = FIRME_SERVICE_FEATURES,
+ .a1 = service_id,
+ .a2 = feat_idx,
+ }, &ret);
+ if (ret.a0 == FIRME_RET_NOT_SUPPORTED)
+ goto err_out;
+
+ *feature = ret.a1;
+
+err_out:
+ return firme_status_to_errno(ret.a0);
+}
+
+int firme_get_version(enum firme_service_id service_id, u32 *version)
+{
+ if (static_branch_unlikely(&firme_disabled))
+ return -EOPNOTSUPP;
+
+ if (!version || service_id >= FIRME_SERVICE_ID_MAX)
+ return -EINVAL;
+
+ return __firme_get_version(service_id, version);
+}
+EXPORT_SYMBOL_GPL(firme_get_version);
+
+int firme_get_feature(enum firme_service_id service_id,
+ uint8_t feat_idx, unsigned long *feature)
+{
+ if (static_branch_unlikely(&firme_disabled))
+ return -EOPNOTSUPP;
+
+ if (!feature)
+ return -EINVAL;
+
+ return __firme_get_feature(service_id, feat_idx, feature);
+}
+EXPORT_SYMBOL_GPL(firme_get_feature);
+
+int firme_get_shared_buffer_info(struct firme_shared_buf_info *info)
+{
+ if (static_branch_unlikely(&firme_disabled))
+ return -EOPNOTSUPP;
+
+ if (!info)
+ return -EINVAL;
+
+ memcpy(info, &base_service_info.shbuf_info,
+ sizeof(struct firme_shared_buf_info));
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(firme_get_shared_buffer_info);
+
+void *firme_alloc_shared_buffer(size_t *size, gfp_t gfp_flags)
+{
+ struct firme_shared_buf_info *info;
+ int order, min_order, max_order;
+ size_t alloc_size;
+ struct page *page;
+
+ if (static_branch_unlikely(&firme_disabled))
+ return NULL;
+
+ if (!size || (*size == 0))
+ return NULL;
+
+ info = &base_service_info.shbuf_info;
+
+ alloc_size = clamp(*size, info->min_size, info->max_size);
+ min_order = get_order(info->min_size);
+ max_order = min(get_order(alloc_size), MAX_PAGE_ORDER);
+
+ for (order = max_order; order >= min_order; order--) {
+ page = alloc_pages(gfp_flags, order);
+ if (page) {
+ alloc_size = PAGE_SIZE << order;
+ break;
+ }
+ }
+
+ if (!page)
+ return NULL;
+
+ *size = alloc_size;
+
+ return page_address(page);
+}
+EXPORT_SYMBOL_GPL(firme_alloc_shared_buffer);
+
+void firme_free_shared_buffer(void *buf, size_t size)
+{
+ struct firme_shared_buf_info *info;
+ int order, min_order, max_order;
+
+ if (static_branch_unlikely(&firme_disabled))
+ return;
+
+ info = &base_service_info.shbuf_info;
+ min_order = get_order(info->min_size);
+ max_order = min(get_order(info->max_size), MAX_PAGE_ORDER);
+ order = get_order(size);
+
+ WARN_ON_ONCE((order < min_order) || (order > max_order));
+
+ free_pages((unsigned long)buf, order);
+}
+EXPORT_SYMBOL_GPL(firme_free_shared_buffer);
+
+static int firme_base_service_init(void)
+{
+ int ret;
+ u32 version;
+ unsigned long feature;
+ u8 shbuf_min_pgs;
+ u16 max_pgcnt;
+ size_t min_size;
+
+ ret = __firme_get_version(FIRME_BASE_SERVICE_ID, &version);
+ if (ret)
+ return ret;
+
+ ret = __firme_get_feature(FIRME_BASE_SERVICE_ID, 0x01, &feature);
+ if (ret)
+ return ret;
+
+ shbuf_min_pgs = FIELD_GET(FIRME_BASE_FEAT1_SH_BUF_MIN_SZ_MASK, feature);
+ max_pgcnt = FIELD_GET(FIRME_BASE_FEAT1_SH_BUF_MAX_PG_CNT_MASK, feature);
+
+ switch (shbuf_min_pgs) {
+ case FIRME_PGS_4K:
+ min_size = 1UL << 12;
+ break;
+ case FIRME_PGS_16K:
+ min_size = 1UL << 14;
+ break;
+ case FIRME_PGS_64K:
+ min_size = 1UL << 16;
+ break;
+ default:
+ pr_err("Invalid minimum shared buffer size: 0x%x\n", shbuf_min_pgs);
+ return -EINVAL;
+ }
+
+ base_service_info.shbuf_info.min_size = min_size;
+ base_service_info.shbuf_info.max_size = min_size * (max_pgcnt + 1);
+
+ WARN_ON_ONCE(min_size > base_service_info.shbuf_info.max_size);
+
+ pr_info("FIRME version %d.%d\n", FIRME_MAJOR_VERSION(version),
+ FIRME_MINOR_VERSION(version));
+ pr_info("shared buffer size: min: 0x%lx, max: 0x%lx\n",
+ base_service_info.shbuf_info.min_size,
+ base_service_info.shbuf_info.max_size);
+
+ return 0;
+}
+
+static int firme_smccc_dev_create(void)
+{
+ int ret;
+ unsigned long feature, service_list;
+ int i, j;
+
+ struct firme_dev_info {
+ const char *dev_name;
+ struct arm_smccc_device *sdev;
+ } sdev_info[] = {
+ { .dev_name = NULL, },
+ { .dev_name = NULL, },
+ { .dev_name = "arm-firme-ide-keyset", },
+ { .dev_name = NULL, },
+ { .dev_name = "arm-firme-attest", },
+ { .dev_name = NULL, },
+ /* ID_MAX */
+ };
+
+ ret = __firme_get_feature(FIRME_BASE_SERVICE_ID, 0x01, &feature);
+ if (ret)
+ return ret;
+
+ service_list = FIELD_GET(FIRME_BASE_FEAT1_SERVICE_LIST_MASK, feature);
+ service_list = (service_list << 1) | 0x01;
+
+ for (i = FIRME_BASE_SERVICE_ID; i < FIRME_SERVICE_ID_MAX; i++) {
+ if (!sdev_info[i].dev_name || !test_bit(i, &service_list))
+ continue;
+ sdev_info[i].sdev = arm_smccc_device_register(sdev_info[i].dev_name,
+ FIRME_SERVICE_VERSION,
+ (void *)i);
+ if (IS_ERR(sdev_info[i].sdev)) {
+ ret = PTR_ERR(sdev_info[i].sdev);
+ break;
+ }
+ }
+
+ if (!ret)
+ return 0;
+
+ for (j = i - 1; j >= FIRME_BASE_SERVICE_ID; j--) {
+ arm_smccc_device_unregister(sdev_info[j].sdev);
+ }
+
+ return ret;
+}
+
+static int __init firme_init(void)
+{
+ int ret;
+ u32 smccc_version = arm_smccc_get_version();
+
+ if ((smccc_version < ARM_SMCCC_VERSION_1_2) ||
+ (cpus_have_final_cap(ARM64_SVE) && (smccc_version < ARM_SMCCC_VERSION_1_3)) ||
+ (cpus_have_final_cap(ARM64_SME) && (smccc_version < ARM_SMCCC_VERSION_1_4)))
+ return -EOPNOTSUPP;
+
+ ret = firme_base_service_init();
+ if (ret)
+ return ret;
+
+ ret = firme_smccc_dev_create();
+ if (ret)
+ return ret;
+
+ static_branch_disable(&firme_disabled);
+
+ return 0;
+}
+device_initcall(firme_init);
diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h
index 4de81848fe2ee..ad6efb6d223a9 100644
--- a/include/linux/arm-smccc.h
+++ b/include/linux/arm-smccc.h
@@ -70,6 +70,7 @@
#define ARM_SMCCC_VERSION_1_1 0x10001
#define ARM_SMCCC_VERSION_1_2 0x10002
#define ARM_SMCCC_VERSION_1_3 0x10003
+#define ARM_SMCCC_VERSION_1_4 0x10004
#define ARM_SMCCC_1_3_SVE_HINT 0x10000
#define ARM_SMCCC_CALL_HINTS ARM_SMCCC_1_3_SVE_HINT
diff --git a/include/linux/arm_firme.h b/include/linux/arm_firme.h
new file mode 100644
index 0000000000000..c070eb6a4bb08
--- /dev/null
+++ b/include/linux/arm_firme.h
@@ -0,0 +1,261 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2026 Arm Ltd.
+ */
+
+#ifndef _LINUX_ARM_FIRME_H
+#define _LINUX_ARM_FIRME_H
+
+#include <linux/arm-smccc.h>
+#include <linux/bitfield.h>
+#include <linux/cpuhplock.h>
+#include <linux/device.h>
+#include <linux/types.h>
+
+/*
+ * This file provides common defines for Fimware Interface for Realm
+ * Management Extension (FIRME) as specified in
+ * https://developer.arm.com/documentation/den0149/latest
+ */
+
+#define FIRME_SMC(func_num) \
+ ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \
+ ARM_SMCCC_OWNER_STANDARD, (func_num))
+
+/*
+ * FIRME base service function ids.
+ */
+#define FIRME_SERVICE_VERSION FIRME_SMC(0x400)
+#define FIRME_SERVICE_FEATURES FIRME_SMC(0x401)
+
+/*
+ * FIRME granule management service function ids.
+ */
+#define FIRME_GM_GPI_SET FIRME_SMC(0x402)
+#define FIRME_GM_GPI_OP_CONTINUE FIRME_SMC(0x412)
+
+/*
+ * FIRME IDE key mangement service function ids.
+ */
+#define FIRME_IDE_KEYSET_PROG FIRME_SMC(0x403)
+#define FIRME_IDE_KEYSET_GO FIRME_SMC(0x404)
+#define FIRME_IDE_KEYSET_STOP FIRME_SMC(0x405)
+#define FIRME_IDE_KEYSET_POLL FIRME_SMC(0x406)
+
+/*
+ * FIRME IDE key mangement service function ids.
+ *
+ * NOTE:
+ * Other functions except FIRME_ATTEST_PAT_GET are not supported
+ * by normal world instance.
+ */
+#define FIRME_ATTEST_PAT_GET FIRME_SMC(0x408)
+
+/*
+ * FIRME error codes.
+ */
+#define FIRME_RET_SUCCESS (0)
+#define FIRME_RET_NOT_SUPPORTED (-1)
+#define FIRME_RET_INVALID_PARAMETER (-2)
+#define FIRME_RET_ABORTED (-3)
+#define FIRME_RET_INCOMPLETE (-4)
+#define FIRME_RET_DENIED (-5)
+#define FIRME_RET_BUSY (-6)
+#define FIRME_RET_OP_CONFLICT (-7)
+#define FIRME_RET_ALREADY_EXISTS (-8)
+#define FIRME_RET_NOT_FOUND (-9)
+#define FIRME_RET_NO_MEMORY (-10)
+#define FIRME_RET_BAD_DATA (-11)
+
+/*
+ * GPI attributes in GPT for FIRME granule management service.
+ */
+#define GPT_GPI_NO_ACCESS (0x0)
+#define GPT_GPI_SA (0x4)
+#define GPT_GPI_NSP (0x5)
+#define GPT_GPI_SECURE (0x8)
+#define GPT_GPI_NS (0x9)
+#define GPT_GPI_ROOT (0xa)
+#define GPT_GPI_REALM (0xb)
+#define GPT_GPI_NS_BY_NS_OR_ROOT (0xd)
+#define GPT_GPI_ANY (0xf)
+#define GPT_GPI_MASK GENMASK(3, 0)
+
+/*
+ * FIRME version encoding
+ */
+#define FIRME_MAJOR_VERSION_MASK GENMASK(30, 16)
+#define FIRME_MINOR_VERSION_MASK GENMASK(15, 0)
+#define FIRME_MAJOR_VERSION(x) ((u16)(FIELD_GET(FIRME_MAJOR_VERSION_MASK, (x))))
+#define FIRME_MINOR_VERSION(x) ((u16)(FIELD_GET(FIRME_MINOR_VERSION_MASK, (x))))
+#define FIRME_PACK_VERSION_INFO(major, minor) \
+ (FIELD_PREP(FIRME_MAJOR_VERSION_MASK, (major)) | \
+ FIELD_PREP(FIRME_MINOR_VERSION_MASK, (minor)))
+
+#define FIRME_VERSION_1_0 FIRME_PACK_VERSION_INFO(1, 0)
+
+#define FIRME_KEYSET_ID_KEYSET_MASK BIT(0)
+#define FIRME_KEYSET_ID_DIRECTION_MASK BIT(1)
+#define FIRME_KEYSET_ID_SUBSTREAM_MASK GENMASK(5, 2)
+#define FIRME_KEYSET_ID_STREAM_MASK GENMASK(13, 6)
+#define FIRME_KEYSET_ID_ROOT_PORT_MASK GENMASK(29, 14)
+#define FIRME_KEYSET_ID_SEGMENT_MASK GENMASK(37, 30)
+#define FIRME_PACK_KEYSET_ID(ks, d, ss_id, s_id, rp_id, sg_id) \
+ (FIELD_PREP(FIRME_KEYSET_ID_KEYSET_MASK, ks) | \
+ FIELD_PREP(FIRME_KEYSET_ID_DIRECTION_MASK, d) | \
+ FIELD_PREP(FIRME_KEYSET_ID_SUBSTREAM_MASK, ss_id) | \
+ FIELD_PREP(FIRME_KEYSET_ID_STREAM_MASK, s_id) | \
+ FIELD_PREP(FIRME_KEYSET_ID_ROOT_PORT_MASK, rp_id) | \
+ FIELD_PREP(FIRME_KEYSET_ID_SEGMENT_MASK, sg_id))
+
+#define FIRME_PGS_4K (0)
+#define FIRME_PGS_64K (1)
+#define FIRME_PGS_16K (2)
+
+#define FIRME_L0GPTSZ_1GB (0)
+#define FIRME_L0GPTSZ_16GB (4)
+#define FIRME_L0GPTSZ_64GB (6)
+#define FIRME_L0GPTSZ_512GB (9)
+
+#define FIRME_PPS_4GB (0)
+#define FIRME_PPS_64GB (1)
+#define FIRME_PPS_1TB (2)
+#define FIRME_PPS_4TB (3)
+#define FIRME_PPS_16TB (4)
+#define FIRME_PPS_256TB (5)
+#define FIRME_PPS_4PB (6)
+#define FIRME_PPS_64PB (7)
+
+/*
+ * FIRME Base service features.
+ */
+#define FIRME_BASE_FEAT0_FUNC_VERSION BIT(0)
+#define FIRME_BASE_FEAT0_FUNC_FEATURE BIT(1)
+#define FIRME_BASE_FEAT0_FUNC_MASK GENMASK(2, 0)
+
+#define FIRME_BASE_FEAT1_SH_BUF_MIN_SZ_MASK GENMASK(1, 0)
+#define FIRME_BASE_FEAT1_SH_BUF_MAX_PG_CNT_MASK GENMASK(15, 2)
+#define FIRME_BASE_FEAT1_SERVICE_LIST_MASK GENMASK(31, 16)
+
+/*
+ * FIRME Granule management service features.
+ */
+#define FIRME_GM_FEAT0_FUNC_GPI_SET BIT(0)
+#define FIRME_GM_FEAT0_FUNC_GPI_OP_COUTINUME BIT(1)
+#define FIRME_GM_FEAT0_FUNC_MASK GENMASK(3, 0)
+
+#define FIRME_GM_FEAT1_PGS_MASK GENMASK(1, 0)
+#define FIRME_GM_FEAT1_L0GPTSZ_MASK GENMASK(5, 2)
+#define FIRME_GM_FEAT1_PPS_MASK GENMASK(8, 6)
+
+/*
+ * FIRME IDE key management service features.
+ */
+#define FIRME_IDE_KEYSET_FEAT0_FUNC_PROG BIT(0)
+#define FIRME_IDE_KEYSET_FEAT0_FUNC_GO BIT(1)
+#define FIRME_IDE_KEYSET_FEAT0_FUNC_STOP BIT(2)
+#define FIRME_IDE_KEYSET_FEAT0_FUNC_POLL BIT(3)
+#define FIRME_IDE_KEYSET_FEAT0_FUNC_MASK GENMASK(3, 0)
+
+/*
+ * FIRME IDE key management service features.
+ */
+#define FIRME_ATTEST_FEAT0_FUNC_PAT_GET BIT(0)
+#define FIRME_ATTEST_FEAT0_FUNC_MASK GENMASK(5, 0)
+
+#define FIRME_ATTEST_FEAT1_MAX_PAT_PG_CNT_MASK GENMASK(7, 0)
+
+typedef struct arm_smccc_1_2_regs firme_value_t;
+typedef long firme_status_t;
+
+/*
+ * FIRME Service ID
+ */
+enum firme_service_id {
+ FIRME_BASE_SERVICE_ID = 0,
+ FIRME_GM_SERVICE_ID,
+ FIRME_IDE_KEYSET_SERVICE_ID,
+ FIRME_MEC_SERVICE_ID,
+ FIRME_ATTEST_SERVICE_ID,
+ FIRME_IDEV_SERVICE_ID,
+ FIRME_SERVICE_ID_MAX,
+};
+
+enum firme_ide_type {
+ FIRME_IDE_TYPE_SELECTIVE,
+ FIRME_IDE_TYPE_PCIE_LINK,
+ FIRME_IDE_TYPE_CXL_CACHEMEM,
+};
+
+struct firme_shared_buf_info {
+ size_t min_size;
+ size_t max_size;
+};
+
+static __always_inline int firme_status_to_errno(firme_status_t status)
+{
+ static int firme_status_errno_map[] = {
+ 0, /* FIRME_RET_SUCCESS */
+ -EOPNOTSUPP, /* FIRME_RET_NOT_SUPPORTED */
+ -EINVAL, /* FIRME_RET_INVALID_PARAMETER */
+ -ECANCELED, /* FIRME_RET_ABORTED */
+ -EAGAIN, /* FIRME_RET_INCOMPLETE */
+ -EACCES, /* FIRME_RET_DENIED */
+ -EBUSY, /* FIRME_RET_BUSY */
+ -EALREADY, /* FIRME_RET_OP_CONFLICT */
+ -EEXIST, /* FIRME_RET_ALREDAY_EXISTS */
+ -ENOENT, /* FIRME_RET_NOT_FOUND */
+ -ENOMEM, /* FIRME_RET_NO_MEMORY */
+ -EBADMSG, /* FIRME_RET_BAD_DATA */
+ };
+
+ status = -status;
+
+ if (status >= 0 && status < ARRAY_SIZE(firme_status_errno_map))
+ return firme_status_errno_map[status];
+
+ return -EINVAL;
+};
+
+static __always_inline void invoke_firme_service(firme_value_t args,
+ firme_value_t *res)
+{
+ arm_smccc_1_2_smc(&args, res);
+}
+
+#if IS_ENABLED(CONFIG_ARM_FIRME)
+extern int firme_get_version(enum firme_service_id service_id, u32 *version);
+extern int firme_get_feature(enum firme_service_id service_id,
+ uint8_t feat_idx, unsigned long *feature);
+extern int firme_get_shared_buffer_info(struct firme_shared_buf_info *info);
+extern void *firme_alloc_shared_buffer(size_t *size, gfp_t gfp_flags);
+extern void firme_free_shared_buffer(void *buf, size_t size);
+#else
+static __always_inline int firme_get_version(enum firme_service_id service_id,
+ u32 *version)
+{
+ return -EOPNOTSUPP;
+}
+
+static __always_inline int firme_get_feature(enum firme_service_id service_id,
+ uint8_t feat_idx, unsigned long *feature)
+{
+ return -EOPNOTSUPP;
+}
+
+static __always_inline int firme_get_shared_buffer_info(struct firme_shared_buf_info *info)
+{
+ return -EOPNOTSUPP;
+}
+
+static __always_inline void *firme_alloc_shared_buffer(size_t *size, gfp_t gfp_flags)
+{
+ return NULL;
+}
+
+static __always_inline void firme_free_shared_buffer(void *buf, size_t size)
+{
+}
+#endif
+
+#endif /* _LINUX_ARM_FIRME_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH RFC v2 3/6] Documentation/ctlv: introduce ctlv-attestation-firme family
2026-11-27 15:28 [PATCH RFC v2 0/6] firmware: arm_firme: introduce FIRME support for host attestation Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 1/6] firmware: arm-smccc: introduce match function Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 2/6] firmware: arm_firme: introduce arm_firme Yeoreum Yun
@ 2026-11-27 15:28 ` Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 5/6] attestation: providers: introduce FIRME attestation provider Yeoreum Yun
3 siblings, 0 replies; 5+ messages in thread
From: Yeoreum Yun @ 2026-11-27 15:28 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel
Cc: Lorenzo Pieralisi, Catalin Marinas, Suzuki Poulose, Steven Price,
Sami Mujawar, Aneesh Kumar K.V, Jiri Pirko, GONG Ruiqi,
Jason Gunthorpe, Mark Brown, Yeoreum Yun
Introduce ctlv-attestation-firme family and auto-generated abi files
via make -C tools/ctlv regen.
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
Documentation/ctlv/abi/ctlv-attestation-firme.yaml | 19 +++++++++++++++++++
Documentation/ctlv/abi/families.registry.yaml | 1 +
Documentation/ctlv/families.yaml | 1 +
Documentation/ctlv/generated-files.yaml | 11 +++++++++++
Documentation/ctlv/specs/ctlv-attestation-firme.yaml | 20 ++++++++++++++++++++
include/uapi/ctlv/ctlv_families_gen.h | 1 +
6 files changed, 53 insertions(+)
diff --git a/Documentation/ctlv/abi/ctlv-attestation-firme.yaml b/Documentation/ctlv/abi/ctlv-attestation-firme.yaml
new file mode 100644
index 0000000000000..68acbd17b9341
--- /dev/null
+++ b/Documentation/ctlv/abi/ctlv-attestation-firme.yaml
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+%YAML 1.2
+---
+# Checked-in ABI snapshot of the ctlv-attestation-firme family, from
+# Documentation/ctlv/specs/ctlv-attestation-firme.yaml, written by
+# "make -C tools/ctlv regen".
+#
+# Updating the file is how a UAPI change gets reviewed; an update that
+# removes or renumbers anything, narrows a bound, or makes a member required
+# is an ABI break, whatever the file says afterwards.
+family: {name: ctlv-attestation-firme, id: 6, inherits: ctlv-attestation}
+enums:
+ evidence-vendor-format: {platform-attestation-token: 1}
+records:
+ device-info:
+ id: 0x00010000
+ fields:
+ version: {number: 1, type: uint, max: s32-max}
+fills: {device-info: device-info}
diff --git a/Documentation/ctlv/abi/families.registry.yaml b/Documentation/ctlv/abi/families.registry.yaml
index 2146877a4f325..0784747a3ac87 100644
--- a/Documentation/ctlv/abi/families.registry.yaml
+++ b/Documentation/ctlv/abi/families.registry.yaml
@@ -10,3 +10,4 @@ families:
- ctlv-test
- ctlv-test-child
- ctlv-attestation-sim
+ - ctlv-attestation-firme
diff --git a/Documentation/ctlv/families.yaml b/Documentation/ctlv/families.yaml
index 1fd60280cf037..49121305e3282 100644
--- a/Documentation/ctlv/families.yaml
+++ b/Documentation/ctlv/families.yaml
@@ -20,3 +20,4 @@ families:
- ctlv-test
- ctlv-test-child
- ctlv-attestation-sim
+ - ctlv-attestation-firme
diff --git a/Documentation/ctlv/generated-files.yaml b/Documentation/ctlv/generated-files.yaml
index 2621d9fbb8327..b286e28c2b5b7 100644
--- a/Documentation/ctlv/generated-files.yaml
+++ b/Documentation/ctlv/generated-files.yaml
@@ -67,3 +67,14 @@ families:
tools/testing/selftests/attestation/ctlv_attestation_sim_user_gen.h
user-source: >-
tools/testing/selftests/attestation/ctlv_attestation_sim_user_gen.c
+
+ - name: ctlv-attestation-firme
+ source: Documentation/ctlv/specs/ctlv-attestation-firme.yaml
+ outputs:
+ uapi-header: include/uapi/ctlv/ctlv_attestation_firme_gen.h
+ kernel-header: drivers/attestation/generated/ctlv_attestation_firme_gen.h
+ kernel-source: drivers/attestation/generated/ctlv_attestation_firme_gen.c
+ user-header: >-
+ tools/testing/selftests/attestation/ctlv_attestation_firme_user_gen.h
+ user-source: >-
+ tools/testing/selftests/attestation/ctlv_attestation_firme_user_gen.c
diff --git a/Documentation/ctlv/specs/ctlv-attestation-firme.yaml b/Documentation/ctlv/specs/ctlv-attestation-firme.yaml
new file mode 100644
index 0000000000000..fdc8022851a43
--- /dev/null
+++ b/Documentation/ctlv/specs/ctlv-attestation-firme.yaml
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+%YAML 1.2
+---
+#
+# The attestation device of FIRME for host: platform attestation token (PAT)
+#
+family: ctlv-attestation-firme
+inherits: ctlv-attestation
+
+enums:
+ # Fills ctlv-attestation's evidence-vendor-format.
+ evidence-vendor-format:
+ # platform attestation token.
+ - platform-attestation-token
+
+records:
+ # Fills ctlv-attestation's device-info.
+ device-info:
+ # FIRME attestation service version.
+ version: uint(..s32-max)
diff --git a/include/uapi/ctlv/ctlv_families_gen.h b/include/uapi/ctlv/ctlv_families_gen.h
index c90f98173c706..e4c0b06a6d7eb 100644
--- a/include/uapi/ctlv/ctlv_families_gen.h
+++ b/include/uapi/ctlv/ctlv_families_gen.h
@@ -17,6 +17,7 @@ enum _ctlv_family {
CTLV_FAMILY_TEST = 3,
CTLV_FAMILY_TEST_CHILD = 4,
CTLV_FAMILY_ATTESTATION_SIM = 5,
+ CTLV_FAMILY_ATTESTATION_FIRME = 6,
};
#endif /* _UAPI_CTLV_CTLV_FAMILIES_GEN_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH RFC v2 5/6] attestation: providers: introduce FIRME attestation provider
2026-11-27 15:28 [PATCH RFC v2 0/6] firmware: arm_firme: introduce FIRME support for host attestation Yeoreum Yun
` (2 preceding siblings ...)
2026-11-27 15:28 ` [PATCH RFC v2 3/6] Documentation/ctlv: introduce ctlv-attestation-firme family Yeoreum Yun
@ 2026-11-27 15:28 ` Yeoreum Yun
3 siblings, 0 replies; 5+ messages in thread
From: Yeoreum Yun @ 2026-11-27 15:28 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel
Cc: Lorenzo Pieralisi, Catalin Marinas, Suzuki Poulose, Steven Price,
Sami Mujawar, Aneesh Kumar K.V, Jiri Pirko, GONG Ruiqi,
Jason Gunthorpe, Mark Brown, Yeoreum Yun
Introduce FIRME attestation provider for retrieving an attestation
token for host.
When a evidence-get is requested, firme attestation provider invokes
the appropriate FIRME interfaces to query an attestation token.
The steps to retrieve an attestation token are as follows:
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
drivers/attestation/Kconfig | 9 ++
drivers/attestation/Makefile | 5 +
drivers/attestation/providers/firme.c | 292 ++++++++++++++++++++++++++++++++++
3 files changed, 306 insertions(+)
diff --git a/drivers/attestation/Kconfig b/drivers/attestation/Kconfig
index e9c1d7865f2a0..e2391ef4aee2d 100644
--- a/drivers/attestation/Kconfig
+++ b/drivers/attestation/Kconfig
@@ -43,4 +43,13 @@ config ATTESTATION_SIM
If you are unsure, say N.
+config ATTESTATION_FIRME
+ tristate "FIRME attestation provider"
+ depends on ARM_FIRME
+ help
+ Exposes FIRME platform token get (PAT) operations through the common
+ attestation CTLV family.
+
+ If you are unsure, say N.
+
endif # ATTESTATION
diff --git a/drivers/attestation/Makefile b/drivers/attestation/Makefile
index 448fe4a3856d4..2c7a1a09daaed 100644
--- a/drivers/attestation/Makefile
+++ b/drivers/attestation/Makefile
@@ -12,3 +12,8 @@ obj-$(CONFIG_ATTESTATION_SIM) += attestation-sim.o
attestation-sim-y := providers/sim.o \
generated/ctlv_attestation_sim_gen.o
+
+obj-$(CONFIG_ATTESTATION_FIRME) += attestation-firme.o
+
+attestation-firme-y := providers/firme.o \
+ generated/ctlv_attestation_firme_gen.o
diff --git a/drivers/attestation/providers/firme.c b/drivers/attestation/providers/firme.c
new file mode 100644
index 0000000000000..b8de3e14aff5a
--- /dev/null
+++ b/drivers/attestation/providers/firme.c
@@ -0,0 +1,292 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <crypto/sha2.h>
+#include <linux/arm_firme.h>
+#include <linux/arm-smccc-bus.h>
+#include <linux/attestation.h>
+#include <linux/ctlv.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+
+#include "../generated/ctlv_attestation_firme_gen.h"
+
+struct firme_attestation {
+ struct attestation_dev att;
+ u32 version;
+ size_t max_pat_size;
+};
+
+static struct firme_attestation *to_firme_attestation(struct attestation_dev *att)
+{
+ return container_of(att, struct firme_attestation, att);
+}
+
+static const struct attestation_evidence_format firme_attestation_pat_format[] = {
+ { .vendor = true, .value = CTLV_ATTESTATION_FIRME_EVIDENCE_VENDOR_FORMAT_PLATFORM_ATTESTATION_TOKEN },
+};
+
+static const struct attestation_evidence_challenge_length
+firme_attestation_challenge_lengths[] = {
+ { .min = 1, .max = SHA512_DIGEST_SIZE },
+};
+
+static struct attestation_evidence_supported_object
+firme_attestation_evidence_objects[] = {
+ {
+ .evidence_class = ATTESTATION_EVIDENCE_SIGNED,
+ .formats = firme_attestation_pat_format,
+ .formats_count = ARRAY_SIZE(firme_attestation_pat_format),
+ .challenge_lengths = firme_attestation_challenge_lengths,
+ .challenge_lengths_count =
+ ARRAY_SIZE(firme_attestation_challenge_lengths),
+ .max_length = 0,
+ },
+ /*
+ * TODO: add LFA log and need to call
+ * attestation_device_changed_locked() when LFA is done.
+ */
+};
+
+static const struct attestation_evidence_caps firme_attestation_evidence_caps = {
+ .objects = firme_attestation_evidence_objects,
+ .objects_count = ARRAY_SIZE(firme_attestation_evidence_objects),
+};
+
+static int firme_get_platform_attestion_token(struct firme_attestation *firme_att,
+ const void *challenge,
+ size_t challenge_size,
+ void *token, size_t *token_size)
+{
+ firme_status_t status;
+ firme_value_t ret;
+ struct firme_shared_buf_info shbuf_info;
+ void *buffer;
+ size_t alloc_size, buffer_size, buffer_pgcnt;
+ size_t read_size, total_size;
+
+ if (firme_get_shared_buffer_info(&shbuf_info))
+ return -EOPNOTSUPP;
+
+ if ((challenge_size > 0) && !challenge)
+ return -EINVAL;
+
+ buffer_size = min(firme_att->max_pat_size, shbuf_info.max_size);
+ if (WARN_ON_ONCE(buffer_size & (shbuf_info.min_size - 1)))
+ return -ENOBUFS;
+
+ alloc_size = buffer_size;
+
+ buffer = firme_alloc_shared_buffer(&alloc_size, GFP_KERNEL | __GFP_ZERO);
+ if (!buffer)
+ return -ENOMEM;
+
+ if (alloc_size < buffer_size)
+ buffer_size = alloc_size;
+
+ buffer_pgcnt = buffer_size / shbuf_info.min_size;
+
+ if (challenge_size > 0) {
+ memcpy(buffer, challenge, challenge_size);
+ /*
+ * According to Realm Management Monitor specification, S-PNCRK,
+ * maximum chanllege size should be 64 bytes (SHA512_DIGEST_SIZE).
+ * If less than, pad with zero.
+ */
+ challenge_size = SHA512_DIGEST_SIZE;
+ }
+
+ guard(migrate)();
+
+ total_size = 0;
+
+ do {
+ invoke_firme_service((firme_value_t) {
+ .a0 = FIRME_ATTEST_PAT_GET,
+ .a1 = virt_to_phys(buffer),
+ .a2 = 0,
+ .a3 = buffer_pgcnt - 1,
+ .a4 = challenge_size,
+ .a5 = 0, /**< binding size must be 0 for normal world. */
+ }, &ret);
+ status = ret.a0;
+ if ((status != FIRME_RET_SUCCESS) &&
+ (status != FIRME_RET_INCOMPLETE))
+ break;
+
+ challenge_size = 0;
+ read_size = ret.a1;
+ memcpy(token + total_size, buffer, read_size);
+ total_size += read_size;
+ } while (status == FIRME_RET_INCOMPLETE);
+
+ if (status == FIRME_RET_SUCCESS)
+ *token_size = total_size;
+
+ firme_free_shared_buffer(buffer, alloc_size);
+
+ return firme_status_to_errno(status);
+}
+
+static int
+firme_attestation_evidence_get(struct attestation_dev *att,
+ const struct attestation_evidence_request *request,
+ struct attestation_evidence_result *result)
+{
+ const struct attestation_evidence_object_request *object;
+ struct attestation_evidence_object_result *produced;
+ struct firme_attestation *firme_att = to_firme_attestation(att);
+ void *token;
+ size_t token_size;
+ int ret;
+
+ if (request->objects_count != 1)
+ return -EOPNOTSUPP;
+
+ object = &request->objects[0];
+ produced = &result->objects[0];
+
+ token_size = object->supported_object->max_length;
+ token = kvmalloc(token_size, GFP_KERNEL);
+ if (!token)
+ return -ENOMEM;
+ if (object->supported_object == &firme_attestation_evidence_objects[0]) {
+ ret = firme_get_platform_attestion_token(firme_att,
+ request->challenge,
+ request->challenge_length,
+ token, &token_size);
+ if (!ret) {
+ produced->format.vendor = true;
+ produced->format.value = CTLV_ATTESTATION_FIRME_EVIDENCE_VENDOR_FORMAT_PLATFORM_ATTESTATION_TOKEN;
+ }
+ } else {
+ ret = -EOPNOTSUPP;
+ }
+
+ if (!ret)
+ ret = attestation_evidence_write(object, token, token_size);
+ if (!ret)
+ produced->length = token_size;
+ kvfree(token);
+
+ return ret;
+}
+
+static const struct attestation_provider firme_attestation_provider = {
+ .evidence_get = firme_attestation_evidence_get,
+ .evidence_caps = &firme_attestation_evidence_caps,
+};
+
+int ctlv_attestation_firme_device_info_fill(struct ctlv *ctlv,
+ struct ctlv_op_ctx *ctx,
+ const struct ctlv_cursor *request,
+ struct ctlv_cursor *record)
+{
+ const struct firme_attestation *firme_att =
+ to_firme_attestation(attestation_from_ctlv(ctlv));
+ bool ok;
+
+ ok = ctlv_attestation_firme_device_info_version_put(record, firme_att->version);
+ return ok ? 0 : -EMSGSIZE;
+}
+
+void ctlv_attestation_firme_device_info_read(struct ctlv *ctlv,
+ struct ctlv_op_ctx *ctx,
+ const struct ctlv_cursor *record)
+{
+}
+
+static bool firme_attest_drv_match(const struct arm_smccc_device *sdev)
+{
+ const enum firme_service_id id = (const enum firme_service_id)sdev->match_params;
+
+ if (id == FIRME_ATTEST_SERVICE_ID)
+ return true;
+ return false;
+}
+
+static int firme_attest_drv_probe(struct arm_smccc_device *sdev)
+{
+ int ret;
+ u32 version;
+ unsigned long feature;
+ struct firme_shared_buf_info shbuf_info;
+ u8 max_pat_pgcnt;
+ size_t max_pat_size;
+ struct firme_attestation *firme_att;
+
+ ret = firme_get_shared_buffer_info(&shbuf_info);
+ if (ret)
+ return ret;
+
+ ret = firme_get_version(FIRME_ATTEST_SERVICE_ID, &version);
+ if (ret)
+ return ret;
+
+ ret = firme_get_feature(FIRME_ATTEST_SERVICE_ID, 0x01, &feature);
+ if (ret)
+ return ret;
+
+ max_pat_pgcnt = FIELD_GET(FIRME_ATTEST_FEAT1_MAX_PAT_PG_CNT_MASK, feature);
+ max_pat_size = (max_pat_pgcnt + 1) * shbuf_info.min_size;
+ firme_attestation_evidence_objects[0].max_length = max_pat_size;
+
+ pr_info("FIRME attest service version %d.%d\n",
+ FIRME_MAJOR_VERSION(version),
+ FIRME_MINOR_VERSION(version));
+ pr_info("Maximum PAT size: 0x%lx\n", max_pat_size);
+
+ firme_att = attestation_alloc(&sdev->dev,
+ &firme_attestation_provider,
+ &ctlv_attestation_firme_family,
+ struct firme_attestation, att);
+ if (IS_ERR(firme_att))
+ return PTR_ERR(firme_att);
+
+ firme_att->version = version;
+ firme_att->max_pat_size = max_pat_size;
+
+ ret = attestation_register(&firme_att->att);
+ if (ret) {
+ attestation_put(&firme_att->att);
+ return ret;
+ }
+
+ dev_set_drvdata(&sdev->dev, firme_att);
+
+ pr_info("FIRME attestation ctlvdev is registered\n");
+
+ return 0;
+}
+
+static void firme_attest_drv_remove(struct arm_smccc_device *sdev)
+{
+ struct firme_attestation *firme_att = dev_get_drvdata(&sdev->dev);
+
+ if (!firme_att)
+ return;
+
+ attestation_unregister(&firme_att->att);
+ attestation_put(&firme_att->att);
+ dev_set_drvdata(&sdev->dev, NULL);
+}
+
+static const struct arm_smccc_device_id firme_attest_id_table[] = {
+ { .func_id = FIRME_SERVICE_VERSION, },
+ { },
+};
+MODULE_DEVICE_TABLE(arm_smccc, firme_attest_id_table);
+
+static struct arm_smccc_driver firme_attest_drv = {
+ .name = KBUILD_MODNAME,
+ .probe = firme_attest_drv_probe,
+ .remove = firme_attest_drv_remove,
+ .match = firme_attest_drv_match,
+ .id_table = firme_attest_id_table,
+};
+module_arm_smccc_driver(firme_attest_drv);
+
+MODULE_DESCRIPTION("FIRME attestation provider");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS("ATTESTATION");
+MODULE_IMPORT_NS("CTLV");
+MODULE_IMPORT_NS("FIRME");
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-27 15:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 15:28 [PATCH RFC v2 0/6] firmware: arm_firme: introduce FIRME support for host attestation Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 1/6] firmware: arm-smccc: introduce match function Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 2/6] firmware: arm_firme: introduce arm_firme Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 3/6] Documentation/ctlv: introduce ctlv-attestation-firme family Yeoreum Yun
2026-11-27 15:28 ` [PATCH RFC v2 5/6] attestation: providers: introduce FIRME attestation provider Yeoreum Yun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox