ACPI: arm64: FFH Operation Region support for FF-A (offset 2)
Subsystems (3)
v2 cover ACPI: arm64: FFH Operation Region support for FF-A (offset 2)
Arm DEN0048D (Functional Fixed Hardware Specification v1.3), published in March 2026, adds a third FFH Operation Region flavour:
https://developer.arm.com/documentation/den0048/latest/
An Operation Region declared with an Offset of 0x2 triggers an FFA_MSG_SEND_DIRECT_REQ2 call instead of a bare SMC or HVC:
OperationRegion (AFFH, FFixedHW, 2, 40)
Field (AFFH, BufferAcc, NoLock, Preserve) { FFAD, 320 }
Each 64-bit field is one register, ordered from X0. X0 carries the call status on return, X1[15:0] the receiver endpoint ID (or zero, which asks OSPM to resolve it from the UUID), X2-X3 the service UUID written with ToUUID(), and X4-X17 the payload. The region Length is 32 + 8 * N bytes with 1 <= N <= 14, so X0-X4 at minimum and X0-X17 at most.
The spec recommends offset 0x2 for new platforms on the grounds that not every OSPM implements offsets 0x0 and 0x1. Linux has had both since v6.2 but nothing for 0x2, so AML using the recommended encoding currently gets AE_ERROR back.
These patches implement it. I could not find any prior posting of this on linux-acpi or linux-arm-kernel, so apologies if I have missed one and duplicated someone's work.
All three patches are co-developed with Dat Mach.
Design
------
drivers/acpi/arm64/ffh.c holds the DEN0048D side: region length validation, the X0-X17 layout, the ToUUID() to FF-A UUID byte order conversion, and the table 3 status codes. drivers/firmware/arm_ffa/ holds the FF-A side: resolving a service UUID to an endpoint, and the call itself, including the FFA_YIELD and FFA_INTERRUPT re-invocation DEN0048D asks for.
The two talk through an ops structure the FF-A driver registers rather than a direct call, because ffh.c is built in under a bool Kconfig symbol while CONFIG_ARM_FFA_TRANSPORT is a tristate. Unregistration takes the rwsem for writing, so it cannot race with an access already in flight.
None of what the handler needs was reachable through the existing ffa_device interface. ffa_sync_send_receive2() always addresses dev->vm_id, so a receiver endpoint ID supplied by AML cannot be honoured. UUID to endpoint resolution had no in-kernel user at all. And ffa_msg_send_direct_req2() throws away the response registers DEN0048D wants copied back to AML. Patch 1 splits those out, leaving what existing callers see unchanged.
Testing
-------
Built on arm64 with CONFIG_ACPI_FFH=y and CONFIG_ARM_FFA_TRANSPORT both =y and =m, and with CONFIG_ACPI_FFH=n, W=1 clean. Every patch builds on its own.
Runtime tested on an Arm server whose firmware reports FF-A 1.3 and picks offset 2 in its TPM Physical Presence Interface method. Reading /sys/class/tpm/tpm0/ppi/response drives it; kprobes show the call reaching ffa_acpi_ffh_direct_req2() with the endpoint and the fourteen payload registers the region implies. That method only returns a response when the status field reads back zero, and it does.
That firmware only ever sends well formed requests naming the endpoint, so the rest was driven from test SSDTs loaded through CONFIG_ACPI_CONFIGFS against the same partition, one invocation per table:
X1 zero, UUID set endpoint resolved from the UUID, call succeeds
X1 zero, UUID nil rejected before any FF-A call
X1 an unknown endpoint call attempted rather than refused, and the
callee's FFA_ERROR reported as FFH_FFA_CALL_FAILED with the FF-A error code in X2 per table 3
length 0x28, the min one payload register, call succeeds
length 0x24, invalid rejected before any FF-A call
A second server, whose FF-A 1.1 firmware cannot do FFA_MSG_SEND_DIRECT_REQ2, covers FFH_FFA_NOT_SUPPORTED and regressions: it declares no FFH Operation Regions, and an offset 2 access there returns AE_ERROR without this series. It has one service UUID per endpoint where the first machine has six sharing one, covering both topologies.
With CONFIG_ARM_FFA_TRANSPORT=m, which nothing autoloads, an access before the module is loaded reports FFH_FFA_NOT_SUPPORTED, loading makes it reach the FF-A driver, unloading returns it to NOT_SUPPORTED, and reloading reaches it again.
One path is unexercised: nothing provokes a response that is neither FFA_ERROR nor FFA_MSG_SEND_DIRECT_RESP2, so the -EPROTO mapping is untested. Neither platform has a UUID resolving to more than one endpoint, so the endpoint ID comparison in ffa_acpi_ffh_partition_id() was exercised with a throwaway stub reporting two differing IDs: it returns -ENOTUNIQ, no FF-A call is attempted, and AML reads back FFH_FFA_INVALID_PARAMETERS. ffa_device_match_uuid() already walks the descriptors a UUID query returns, so that case looks reachable rather than theoretical.
Open question
-------------
1. ffa_msg_send_wait_for_completion() loops on FFA_YIELD and FFA_INTERRUPT with no bound, sleeping 1 ms per FFA_YIELD round. The loop predates this series and DEN0048D does require the reinvocation, but until now it was only reachable from in-kernel FF-A drivers. This series opens it up to any control method that writes the Operation Region, including at enumeration time, so a partition that keeps yielding would stall an AML thread indefinitely.
Bounding it would affect the existing FF-A callers too, and table 3 has no status code for a call that was abandoned, so it may be out of scope for this series unless you disagree.
v1: https://lore.kernel.org/all/[email protected]/
Changes since v1:
- Rebased onto v7.3-rc1. The code is byte for byte identical to v1; only the base moved, and it applies to current linux-next as well.
- The testing above was repeated on v7.3-rc1: the build matrix (CONFIG_ACPI_FFH=y and =n, CONFIG_ARM_FFA_TRANSPORT=y and =m, W=1 over both directories, and each patch on its own), and the runtime testing on both machines. On the FF-A 1.1 machine a diff against an unpatched v7.3-rc1 shows FF-A bringup, partitions, driver bindings and the whole dmesg error set unchanged, with the offset 2 access moving from AE_ERROR to FFH_FFA_NOT_SUPPORTED.
- Not repeated on rc1: the throwaway stub for the endpoint ID comparison, and the CONFIG_ARM_FFA_TRANSPORT=m load and unload cycle. Both were run on the v1 base.
- No review comments were received on v1.
Jamie Nguyen (3):
firmware: arm_ffa: Split the response out of
ffa_msg_send_direct_req2()
ACPI: arm64: Add support for the FF-A FFH Operation Region (offset 2)
firmware: arm_ffa: Back the ACPI FF-A FFH Operation Region
drivers/acpi/arm64/ffh.c | 185 ++++++++++++++++++++++++++++++ drivers/firmware/arm_ffa/driver.c | 169 +++++++++++++++++++++++++-- include/linux/acpi.h | 41 +++++++ 3 files changed, 386 insertions(+), 9 deletions(-)
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
Signature · 1 line
2.43.0
PATCH v2 1/3 firmware: arm_ffa: Split the response out of ffa_msg_send_direct_req2()
ffa_msg_send_direct_req2() uses one buffer for both the request and the response, and it only ever reports a callee side FFA_ERROR as a translated errno. The ACPI FFH Operation Region handler added later in this series can work with neither. It has to hand every response register back to AML, including on the paths where the call failed.
Move the body into __ffa_msg_send_direct_req2(). It writes the response to a buffer of its own, returns X1-X3 through @resp_regs, and separates three
outcomes: success, a callee that returned FFA_ERROR (-EIO, with the FF-A error code left in @resp_regs[1]), and anything else (-EPROTO).
ffa_msg_send_direct_req2() sits on top of that as a wrapper. It copies to the caller's buffer only on success and returns the same errnos it did before, so ffa_sync_send_receive2() and its users are untouched.
No functional change.
--- drivers/firmware/arm_ffa/driver.c | 51 ++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 7 deletions(-)
drivers/firmware/arm_ffa/driver.c +44 -7
@@ -560,8 +560,20 @@ static int ffa_msg_send2(struct ffa_device *dev, u16 src_id, void *buf, size_t sreturn retval; } -static int ffa_msg_send_direct_req2 (u16 src_id,u16 dst_id,const uuid_t *uuid, -struct ffa_send_direct_data2 *data) +/* +* Sends @req and reports the callee's X1-X3 through @resp_regs and its +* X4-X17 through @resp, both unconditionally, so that a caller bound by +* DEN0048D section 2.3.1.2 can copy every register back to AML even when the +* callee returned FFA_ERROR. Keeping the response out of @req leaves the +* caller free to decide when, if ever, to overwrite its own buffer. Returns +* -EIO for FFA_ERROR (the FF-A error code is left in @resp_regs[1] as X2) and +* -EPROTO for an unexpected response; both mean the call was made. Callers +* that only need an errno should use ffa_msg_send_direct_req2(). +*/ +static int __ffa_msg_send_direct_req2 (u16 src_id,u16 dst_id,const uuid_t *uuid, +const struct ffa_send_direct_data2 *req, +struct ffa_send_direct_data2 *resp, +u64 resp_regs[3 ]) {u32 src_dst_ids =PACK_TARGET_INFO (src_id, dst_id);union {
@@ -574,21 +586,46 @@ static int ffa_msg_send_direct_req2(u16 src_id, u16 dst_id, const uuid_t *uuid, .a2 = le64_to_cpu(uuid_regs.regs[0]), .a3 = le64_to_cpu(uuid_regs.regs[1]), }; -memcpy ((void *)&args + offsetof(ffa_value_t , a4), data,sizeof (*data)); +memcpy ((void *)&args + offsetof(ffa_value_t , a4), req,sizeof (*req));invoke_ffa_fn (args, &ret);ffa_msg_send_wait_for_completion (&ret); + resp_regs[0 ] = ret.a1; + resp_regs[1 ] = ret.a2; + resp_regs[2 ] = ret.a3; +memcpy (resp, (void *)&ret + offsetof(ffa_value_t , a4),sizeof (*resp)); +if (ret.a0 ==FFA_ERROR ) -return ffa_to_linux_errno ((int )ret.a2); +return -EIO ; + +if (ret.a0 ==FFA_MSG_SEND_DIRECT_RESP2 ) +return 0 ; + +return -EPROTO ; +} -if (ret.a0 ==FFA_MSG_SEND_DIRECT_RESP2 ) { -memcpy (data, (void *)&ret + offsetof(ffa_value_t , a4),sizeof (*data)); +static int ffa_msg_send_direct_req2 (u16 src_id,u16 dst_id,const uuid_t *uuid, +struct ffa_send_direct_data2 *data) +{ +struct ffa_send_direct_data2 resp; +u64 resp_regs[3 ]; +int ret; + + ret =__ffa_msg_send_direct_req2 (src_id, dst_id, uuid, data, &resp, + resp_regs); +if (!ret) { + *data = resp;return 0 ; } -return -EINVAL ; +if (ret == -EIO ) +return ffa_to_linux_errno ((int )resp_regs[1 ]); +if (ret == -EPROTO ) +return -EINVAL ; + +return ret; } static int ffa_mem_first_frag(u32 func_id, phys_addr_t buf, u32 buf_sz,
Signature · 1 line
2.43.0
Hanjun Guo
maintainerRe: [PATCH v2 1/3] firmware: arm_ffa: Split the response out of ffa_msg_send_direct_req2()
Hi Jamie,
Quoted 11 lines · Jamie Nguyen
ffa_msg_send_direct_req2()uses one buffer for both the request and the response, and it only ever reports a callee sideFFA_ERRORas a translated errno. The ACPI FFH Operation Region handler added later in this series can work with neither. It has to hand every response register back to AML, including on the paths where the call failed.Move the body into
__ffa_msg_send_direct_req2(). It writes the response to a buffer of its own, returns X1-X3 through @resp_regs, and separates three
outcomes: success, a callee that returnedFFA_ERROR(-EIO, with the FF-A error code left in @resp_regs[1]), and anything else (-EPROTO).
Quoted 7 lines
ffa_msg_send_direct_req2()sits on top of that as a wrapper. It copies to the caller's buffer only on success and returns the same errnos it did before, soffa_sync_send_receive2()and its users are untouched.No functional change.
Assisted-by Claude:claude-opus-5
Assited-by: LLM
The kernel document was updated for this, please update the rest of two patches as well.
Quoted 35 lines
Co-developed-by Dat Mach <[email protected]>Signed-off-by Dat Mach <[email protected]>Signed-off-by Jamie Nguyen <[email protected]>--- drivers/firmware/arm_ffa/driver.c | 51 ++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 7 deletions(-)drivers/firmware/arm_ffa/driver.c +14
-2@@ -560,8 +560,20 @@ static int ffa_msg_send2(struct ffa_device *dev, u16 src_id, void *buf, size_t sreturn retval; } -static int ffa_msg_send_direct_req2 (u16 src_id,u16 dst_id,const uuid_t *uuid, -struct ffa_send_direct_data2 *data) +/* +* Sends @req and reports the callee's X1-X3 through @resp_regs and its +* X4-X17 through @resp, both unconditionally, so that a caller bound by +* DEN0048D section 2.3.1.2 can copy every register back to AML even when the +* callee returned FFA_ERROR. Keeping the response out of @req leaves the +* caller free to decide when, if ever, to overwrite its own buffer. Returns +* -EIO for FFA_ERROR (the FF-A error code is left in @resp_regs[1] as X2) and +* -EPROTO for an unexpected response; both mean the call was made. Callers +* that only need an errno should use ffa_msg_send_direct_req2(). +*/ +static int __ffa_msg_send_direct_req2 (u16 src_id,u16 dst_id,const uuid_t *uuid, +const struct ffa_send_direct_data2 *req, +struct ffa_send_direct_data2 *resp, +u64 resp_regs[3 ]) {u32 src_dst_ids =PACK_TARGET_INFO (src_id, dst_id);union {
drivers/firmware/arm_ffa/driver.c static int ffa_msg_send_direct_req2(u16 src_id, u16 dst_id, const uuid_t *uuid, · line 593
Quoted 9 lines
drivers/firmware/arm_ffa/driver.c +1
-1@@ -574,21 +586,46 @@ static int ffa_msg_send_direct_req2(u16 src_id, u16 dst_id, const uuid_t *uuid, .a2 = le64_to_cpu(uuid_regs.regs[0]), .a3 = le64_to_cpu(uuid_regs.regs[1]), }; -memcpy ((void *)&args + offsetof(ffa_value_t , a4), data,sizeof (*data)); +memcpy ((void *)&args + offsetof(ffa_value_t , a4), req,sizeof (*req));invoke_ffa_fn (args, &ret);ffa_msg_send_wait_for_completion (&ret);
As you noted in the cover letter, the AML thread will stall here if no response, block the ACPI interpreter and the ACPI global lock when the field is Lock-flagged, so do we have some warnings if that happened?
Quoted 25 lines
drivers/firmware/arm_ffa/driver.c +19
-3+ resp_regs[0 ] = ret.a1; + resp_regs[1 ] = ret.a2; + resp_regs[2 ] = ret.a3; +memcpy (resp, (void *)&ret + offsetof(ffa_value_t , a4),sizeof (*resp)); +if (ret.a0 ==FFA_ERROR ) -return ffa_to_linux_errno ((int )ret.a2); +return -EIO ; + +if (ret.a0 ==FFA_MSG_SEND_DIRECT_RESP2 ) +return 0 ; + +return -EPROTO ; +} -if (ret.a0 ==FFA_MSG_SEND_DIRECT_RESP2 ) { -memcpy (data, (void *)&ret + offsetof(ffa_value_t , a4),sizeof (*data)); +static int ffa_msg_send_direct_req2 (u16 src_id,u16 dst_id,const uuid_t *uuid, +struct ffa_send_direct_data2 *data) +{ +struct ffa_send_direct_data2 resp; +u64 resp_regs[3 ]; +int ret; +
drivers/firmware/arm_ffa/driver.c static int ffa_msg_send_direct_req2(u16 src_id, u16 dst_id, const uuid_t *uuid, · line 624
Quoted 10 lines
drivers/firmware/arm_ffa/driver.c +6
-1+ ret =__ffa_msg_send_direct_req2 (src_id, dst_id, uuid, data, &resp, + resp_regs); +if (!ret) { + *data = resp;return 0 ; } -return -EINVAL ; +if (ret == -EIO ) +return ffa_to_linux_errno ((int )resp_regs[1 ]);
resp_regs[1] is confusing, comment here it links to X1 register is better.
Thanks
Hanjun
Re: [PATCH v2 1/3] firmware: arm_ffa: Split the response out of ffa_msg_send_direct_req2()
Quoted 2 lines
The kernel document was updated for this, please update the rest of two patches as well.
I'll update all three patches to use:
Quoted 3 lines
As you noted in the cover letter, the AML thread will stall here if no response, block the ACPI interpreter and the ACPI global lock when the field is Lock-flagged, so do we have some warnings if that happened?
There's no warning today. Would a rate-limited warning after a prolonged wait be useful here? I'm hesitant because that would also affect non-ACPI callers of this helper, and I don't believe FF-A defines a threshold after which the wait is abnormal.
Quoted 2 lines
resp_regs[1] is confusing, comment here it links to X1 register is better.
I'll clarify that resp_regs[1] is X2; resp_regs[0] is X1.
I'll address these in v3. Thanks!
Hanjun Guo
maintainerRe: [PATCH v2 1/3] firmware: arm_ffa: Split the response out of ffa_msg_send_direct_req2()
Quoted 7 lines · Jamie Nguyen
Quoted 2 lines
The kernel document was updated for this, please update the rest of two patches as well.
I'll update all three patches to use:
Assisted-by LLM
Quoted 8 lines
Quoted 3 lines
As you noted in the cover letter, the AML thread will stall here if no response, block the ACPI interpreter and the ACPI global lock when the field is Lock-flagged, so do we have some warnings if that happened?
There's no warning today. Would a rate-limited warning after a prolonged wait be useful here? I'm hesitant because that would also affect non-ACPI callers of this helper, and I don't believe FF-A defines a threshold after which the wait is abnormal.
Let's keep the code as it is.
Quoted 5 lines
Quoted 3 lines
resp_regs[1] is confusing, comment here it links to X1 register is better.
I'll clarify that resp_regs[1] is X2; resp_regs[0] is X1.
Sorry, but it was confusing me :)
Thanks
Hanjun
PATCH v2 2/3 ACPI: arm64: Add support for the FF-A FFH Operation Region (offset 2)
In reply to Jamie NguyenArm DEN0048D (Functional Fixed Hardware Specification v1.3, March 2026) added a third FFH Operation Region flavour. An Operation Region declared with an Offset of 0x2 triggers an FFA_MSG_SEND_DIRECT_REQ2 call instead of a bare SMC or HVC, and each 64-bit field of the region is one register, starting at X0:
X0 call status, populated by OSPM on return
X1 Bits[15:0] receiver endpoint ID, or zero to have OSPM
resolve it from the service UUID
X2-X3 service UUID of the callee partition, written by ACPI
platform firmware using ToUUID()
X4-X17 message payload, X4 is always present
DEN0048D recommends Offset 0x2 for new platforms, since not every OSPM implements Offsets 0x0 and 0x1. Linux implements both and rejects anything else, so AML using the recommended encoding simply fails today.
Add the Operation Region side of it. Region length validation, the X0-X17 layout, the ToUUID() to FF-A UUID byte order conversion and the DEN0048D table 3 status codes all live here; they are ACPI semantics, not FF-A ones. The call itself goes out through a small set of ops that the FF-A driver registers. That indirection is needed because this file is built in, while CONFIG_ARM_FFA_TRANSPORT is a tristate.
Anything that stops the call being made comes back to AML in the X0 status
field: a malformed region length, or a null service UUID when AML has asked OSPM to find the endpoint itself. Once the call has gone out every register is copied back, whatever the outcome, which is what DEN0048D requires. That also takes care of table 3, because FFA_ERROR reports the FF-A error code in X2 and FFH_FFA_CALL_FAILED wants it in the same place. A response that is neither FFA_ERROR nor FFA_MSG_SEND_DIRECT_RESP2 is handled the same way; the call did complete.
--- drivers/acpi/arm64/ffh.c | 185 +++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 41 +++++++++ 2 files changed, 226 insertions(+)
drivers/acpi/arm64/ffh.c +185 -0
@@ -1,7 +1,9 @@// SPDX-License-Identifier: GPL-2.0-only #include <linux/acpi.h> #include <linux/arm-smccc.h> +#include <linux/rwsem.h> #include <linux/slab.h> +#include <linux/uuid.h> /* * Implements ARM64 specific callbacks to support ACPI FFH Operation Region as
@@ -62,6 +64,183 @@ static bool acpi_ffh_smccc_owner_allowed(u32 fid)return false; } +/* +* FFH Operation Regions declared with an Offset of 0x2 trigger an +* FFA_MSG_SEND_DIRECT_REQ2 call, as described in Arm DEN0048D (Functional +* Fixed Hardware Specification v1.3) section 2.3.1.2. Every 64-bit field of +* the region maps to one register, ordered from X0: +* +* X0 status, one of the ACPI_FFH_FFA_* codes below, populated by +* OSPM on return +* X1 Bits[15:0] hold the receiver endpoint ID, or zero to have OSPM +* resolve it from the service UUID +* X2-X3 service UUID of the callee partition, written by ACPI platform +* firmware with the ToUUID() ASL operator +* X4-X17 message payload, X4 is always present +* +* The region Length is "32 + 8 * N" bytes with 1 <= N <= 14, which is X0-X4 +* at minimum and X0-X17 at most. +*/ +#define ACPI_FFH_FFA_HDR_REGS 4/* X0 - X3 */ +#define ACPI_FFH_FFA_MAX_PAYLOAD_REGS 14/* X4 - X17 */ +#define ACPI_FFH_FFA_UUID_OFFSET (2 * sizeof(u64)) +#define ACPI_FFH_FFA_MIN_LENGTH ((ACPI_FFH_FFA_HDR_REGS + 1) * sizeof(u64)) +#define ACPI_FFH_FFA_MAX_LENGTH \ + ((ACPI_FFH_FFA_HDR_REGS + ACPI_FFH_FFA_MAX_PAYLOAD_REGS) * sizeof(u64)) + +/* DEN0048D table 3, FFH Operation Region status codes for FFA calls */ +#define ACPI_FFH_FFA_CALL_FAILED 1 +#define ACPI_FFH_FFA_SUCCESS 0 +#define ACPI_FFH_FFA_NOT_SUPPORTED (-1) +#define ACPI_FFH_FFA_INVALID_PARAMETERS (-2) +#define ACPI_FFH_FFA_OUT_OF_MEMORY (-3) +#define ACPI_FFH_FFA_UNSPECIFIED_ERROR (-4) + +static const struct acpi_ffh_ffa_ops *ffa_ops; +static DECLARE_RWSEM (ffa_ops_sem); + +int acpi_ffh_ffa_register (const struct acpi_ffh_ffa_ops *ops) +{ +int ret =0 ; + +if (!ops || !ops->partition_id || !ops->direct_req2) +return -EINVAL ; + +down_write (&ffa_ops_sem); +if (ffa_ops) + ret = -EBUSY ; +else + ffa_ops = ops; +up_write (&ffa_ops_sem); + +return ret; +} +EXPORT_SYMBOL_GPL (acpi_ffh_ffa_register); + +void acpi_ffh_ffa_unregister (const struct acpi_ffh_ffa_ops *ops) +{ +down_write (&ffa_ops_sem); +if (ffa_ops == ops) + ffa_ops =NULL ; +up_write (&ffa_ops_sem); +} +EXPORT_SYMBOL_GPL (acpi_ffh_ffa_unregister); + +/* +* ToUUID() emits the UUID in mixed-endian (EFI GUID) byte order whereas FF-A +* expects the RFC4122 layout, which is exactly a guid_t to uuid_t conversion. +*/ +static void acpi_ffh_ffa_uuid (uuid_t *uuid,const u8 *aml_buf) +{ +int i; + +for (i =0 ; i <UUID_SIZE ; i++) + uuid->b[i] = aml_buf[guid_index[i]]; +} + +static int acpi_ffh_ffa_status (int err) +{ +switch (err) { +case 0 : +return ACPI_FFH_FFA_SUCCESS ; +case -EIO : +case -EPROTO : +return ACPI_FFH_FFA_CALL_FAILED ; +case -EOPNOTSUPP : +return ACPI_FFH_FFA_NOT_SUPPORTED ; +case -EINVAL : +case -ENOENT : +case -ENODEV : +case -ENOTUNIQ : +return ACPI_FFH_FFA_INVALID_PARAMETERS ; +case -ENOMEM : +return ACPI_FFH_FFA_OUT_OF_MEMORY ; +default : +return ACPI_FFH_FFA_UNSPECIFIED_ERROR ; + } +} + +static bool acpi_ffh_ffa_length_valid (u64 length) +{ +return length >=ACPI_FFH_FFA_MIN_LENGTH && + length <=ACPI_FFH_FFA_MAX_LENGTH && + !(length %sizeof (u64)); +} + +static void acpi_ffh_ffa_handler (struct acpi_ffh_info *info,void *value) +{ +int status =ACPI_FFH_FFA_INVALID_PARAMETERS ; +u64 resp_regs[3 ] = {}; +unsigned int nr_payload; +u64 *regs = value; +uuid_t uuid; +u16 dst_id; +int ret; + +if (!acpi_ffh_ffa_length_valid (info->length)) + goto out; + + nr_payload = info->length /sizeof (u64) -ACPI_FFH_FFA_HDR_REGS ; + +acpi_ffh_ffa_uuid (&uuid, (u8 *)value +ACPI_FFH_FFA_UUID_OFFSET ); + +down_read (&ffa_ops_sem); +if (!ffa_ops) { + status =ACPI_FFH_FFA_NOT_SUPPORTED ; + goto out_unlock; + } + +/* +* A zero receiver endpoint ID means ACPI platform firmware expects +* OSPM to derive it from the service UUID. +*/ + dst_id = regs[1 ] &GENMASK (15 ,0 ); +if (!dst_id) { +/* +* A null UUID means "every partition" to +* FFA_PARTITION_INFO_GET, so reject it here rather than let a +* bare read of the Operation Region, which arrives as a zeroed +* buffer, resolve to an arbitrary endpoint. +*/ +if (uuid_is_null (&uuid)) + goto out_unlock; + + ret = ffa_ops->partition_id (&uuid, &dst_id); +if (ret) { + status =acpi_ffh_ffa_status (ret); + goto out_unlock; + } + } + + ret = ffa_ops->direct_req2 (dst_id, &uuid, regs +ACPI_FFH_FFA_HDR_REGS , + nr_payload, resp_regs); + status =acpi_ffh_ffa_status (ret); + +/* +* DEN0048D asks for the response registers to be copied back. That also +* takes care of table 3: FFA_ERROR reports the FF-A error code in X2, +* which is exactly where FFH_FFA_CALL_FAILED wants it. -EIO and -EPROTO +* both mean the call completed, so the registers hold the callee's +* response and not AML's own request. +*/ +if (!ret || ret == -EIO || ret == -EPROTO ) { + regs[1 ] = resp_regs[0 ]; + regs[2 ] = resp_regs[1 ]; + regs[3 ] = resp_regs[2 ]; + } + +out_unlock: +up_read (&ffa_ops_sem); +out: +/* +* DEN0048D describes this field as 64 bits wide and gives the table 3 +* codes as signed values, so sign extend rather than write a narrower +* quantity. 0xfffe or 0xfffffffe would read back as a positive number +* in a 64-bit AML comparison. +*/ + regs[0 ] = (u64 )(s64 )status; +} +int acpi_ffh_address_space_arch_handler (acpi_integer *value,void *region_context) {int ret =0 ;
@@ -99,6 +278,12 @@ int acpi_ffh_address_space_arch_handler(acpi_integer *value, void *region_contex ffh_ctxt->invoke_ffh64_fn (r, r);memcpy (value, r, ffh_ctxt->info.length); } + }else if (ffh_ctxt->info.offset ==2 ) { +/* FFA_MSG_SEND_DIRECT_REQ2 call */ +if (ffh_ctxt->info.length <sizeof (u64)) + ret =AE_ERROR ; +else +acpi_ffh_ffa_handler (&ffh_ctxt->info, value); }else { ret =AE_ERROR ; }
include/linux/acpi.h +41 -0
53 lines not on this page · raw message
Signature · 1 line
2.43.0
Hanjun Guo
maintainerRe: [PATCH v2 2/3] ACPI: arm64: Add support for the FF-A FFH Operation Region (offset 2)
Quoted 241 lines · Jamie Nguyen
Arm DEN0048D (Functional Fixed Hardware Specification v1.3, March 2026) added a third FFH Operation Region flavour. An Operation Region declared with an Offset of
0x2triggers anFFA_MSG_SEND_DIRECT_REQ2call instead of a bare SMC or HVC, and each 64-bit field of the region is one register, starting at X0:X0 call status, populated by OSPM on return
X1 Bits[15:0] receiver endpoint ID, or zero to have OSPM
resolve it from the service UUID
X2-X3 service UUID of the callee partition, written by ACPI
platform firmware usingToUUID()
X4-X17 message payload, X4 is always presentDEN0048D recommends Offset
0x2for new platforms, since not every OSPM implements Offsets0x0and0x1. Linux implements both and rejects anything else, so AML using the recommended encoding simply fails today.Add the Operation Region side of it. Region length validation, the X0-X17 layout, the
ToUUID()to FF-A UUID byte order conversion and the DEN0048D table 3 status codes all live here; they are ACPI semantics, not FF-A ones. The call itself goes out through a small set of ops that the FF-A driver registers. That indirection is needed because this file is built in, whileCONFIG_ARM_FFA_TRANSPORTis a tristate.Anything that stops the call being made comes back to AML in the X0 status
field: a malformed region length, or a null service UUID when AML has asked OSPM to find the endpoint itself. Once the call has gone out every register is copied back, whatever the outcome, which is what DEN0048D requires. That also takes care of table 3, becauseFFA_ERRORreports the FF-A error code in X2 andFFH_FFA_CALL_FAILEDwants it in the same place. A response that is neitherFFA_ERRORnorFFA_MSG_SEND_DIRECT_RESP2is handled the same way; the call did complete.Assisted-by Claude:claude-opus-5Co-developed-by Dat Mach <[email protected]>Signed-off-by Dat Mach <[email protected]>Signed-off-by Jamie Nguyen <[email protected]>--- drivers/acpi/arm64/ffh.c | 185 +++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 41 +++++++++ 2 files changed, 226 insertions(+)drivers/acpi/arm64/ffh.c +179
-0@@ -1,7 +1,9 @@// SPDX-License-Identifier: GPL-2.0-only #include <linux/acpi.h> #include <linux/arm-smccc.h> +#include <linux/rwsem.h> #include <linux/slab.h> +#include <linux/uuid.h> /* * Implements ARM64 specific callbacks to support ACPI FFH Operation Region as @@ -62,6 +64,183 @@ static bool acpi_ffh_smccc_owner_allowed(u32 fid)return false; } +/* +* FFH Operation Regions declared with an Offset of 0x2 trigger an +* FFA_MSG_SEND_DIRECT_REQ2 call, as described in Arm DEN0048D (Functional +* Fixed Hardware Specification v1.3) section 2.3.1.2. Every 64-bit field of +* the region maps to one register, ordered from X0: +* +* X0 status, one of the ACPI_FFH_FFA_* codes below, populated by +* OSPM on return +* X1 Bits[15:0] hold the receiver endpoint ID, or zero to have OSPM +* resolve it from the service UUID +* X2-X3 service UUID of the callee partition, written by ACPI platform +* firmware with the ToUUID() ASL operator +* X4-X17 message payload, X4 is always present +* +* The region Length is "32 + 8 * N" bytes with 1 <= N <= 14, which is X0-X4 +* at minimum and X0-X17 at most. +*/ +#define ACPI_FFH_FFA_HDR_REGS 4/* X0 - X3 */ +#define ACPI_FFH_FFA_MAX_PAYLOAD_REGS 14/* X4 - X17 */ +#define ACPI_FFH_FFA_UUID_OFFSET (2 * sizeof(u64)) +#define ACPI_FFH_FFA_MIN_LENGTH ((ACPI_FFH_FFA_HDR_REGS + 1) * sizeof(u64)) +#define ACPI_FFH_FFA_MAX_LENGTH \ + ((ACPI_FFH_FFA_HDR_REGS + ACPI_FFH_FFA_MAX_PAYLOAD_REGS) * sizeof(u64)) + +/* DEN0048D table 3, FFH Operation Region status codes for FFA calls */ +#define ACPI_FFH_FFA_CALL_FAILED 1 +#define ACPI_FFH_FFA_SUCCESS 0 +#define ACPI_FFH_FFA_NOT_SUPPORTED (-1) +#define ACPI_FFH_FFA_INVALID_PARAMETERS (-2) +#define ACPI_FFH_FFA_OUT_OF_MEMORY (-3) +#define ACPI_FFH_FFA_UNSPECIFIED_ERROR (-4) + +static const struct acpi_ffh_ffa_ops *ffa_ops; +static DECLARE_RWSEM (ffa_ops_sem); + +int acpi_ffh_ffa_register (const struct acpi_ffh_ffa_ops *ops) +{ +int ret =0 ; + +if (!ops || !ops->partition_id || !ops->direct_req2) +return -EINVAL ; + +down_write (&ffa_ops_sem); +if (ffa_ops) + ret = -EBUSY ; +else + ffa_ops = ops; +up_write (&ffa_ops_sem); + +return ret; +} +EXPORT_SYMBOL_GPL (acpi_ffh_ffa_register); + +void acpi_ffh_ffa_unregister (const struct acpi_ffh_ffa_ops *ops) +{ +down_write (&ffa_ops_sem); +if (ffa_ops == ops) + ffa_ops =NULL ; +up_write (&ffa_ops_sem); +} +EXPORT_SYMBOL_GPL (acpi_ffh_ffa_unregister); + +/* +* ToUUID() emits the UUID in mixed-endian (EFI GUID) byte order whereas FF-A +* expects the RFC4122 layout, which is exactly a guid_t to uuid_t conversion. +*/ +static void acpi_ffh_ffa_uuid (uuid_t *uuid,const u8 *aml_buf) +{ +int i; + +for (i =0 ; i <UUID_SIZE ; i++) + uuid->b[i] = aml_buf[guid_index[i]]; +} + +static int acpi_ffh_ffa_status (int err) +{ +switch (err) { +case 0 : +return ACPI_FFH_FFA_SUCCESS ; +case -EIO : +case -EPROTO : +return ACPI_FFH_FFA_CALL_FAILED ; +case -EOPNOTSUPP : +return ACPI_FFH_FFA_NOT_SUPPORTED ; +case -EINVAL : +case -ENOENT : +case -ENODEV : +case -ENOTUNIQ : +return ACPI_FFH_FFA_INVALID_PARAMETERS ; +case -ENOMEM : +return ACPI_FFH_FFA_OUT_OF_MEMORY ; +default : +return ACPI_FFH_FFA_UNSPECIFIED_ERROR ; + } +} + +static bool acpi_ffh_ffa_length_valid (u64 length) +{ +return length >=ACPI_FFH_FFA_MIN_LENGTH && + length <=ACPI_FFH_FFA_MAX_LENGTH && + !(length %sizeof (u64)); +} + +static void acpi_ffh_ffa_handler (struct acpi_ffh_info *info,void *value) +{ +int status =ACPI_FFH_FFA_INVALID_PARAMETERS ; +u64 resp_regs[3 ] = {}; +unsigned int nr_payload; +u64 *regs = value; +uuid_t uuid; +u16 dst_id; +int ret; + +if (!acpi_ffh_ffa_length_valid (info->length)) + goto out; + + nr_payload = info->length /sizeof (u64) -ACPI_FFH_FFA_HDR_REGS ; + +acpi_ffh_ffa_uuid (&uuid, (u8 *)value +ACPI_FFH_FFA_UUID_OFFSET ); + +down_read (&ffa_ops_sem); +if (!ffa_ops) { + status =ACPI_FFH_FFA_NOT_SUPPORTED ; + goto out_unlock; + } + +/* +* A zero receiver endpoint ID means ACPI platform firmware expects +* OSPM to derive it from the service UUID. +*/ + dst_id = regs[1 ] &GENMASK (15 ,0 ); +if (!dst_id) { +/* +* A null UUID means "every partition" to +* FFA_PARTITION_INFO_GET, so reject it here rather than let a +* bare read of the Operation Region, which arrives as a zeroed +* buffer, resolve to an arbitrary endpoint. +*/ +if (uuid_is_null (&uuid)) + goto out_unlock; + + ret = ffa_ops->partition_id (&uuid, &dst_id); +if (ret) { + status =acpi_ffh_ffa_status (ret); + goto out_unlock; + } + } + + ret = ffa_ops->direct_req2 (dst_id, &uuid, regs +ACPI_FFH_FFA_HDR_REGS , + nr_payload, resp_regs); + status =acpi_ffh_ffa_status (ret); + +/* +* DEN0048D asks for the response registers to be copied back. That also +* takes care of table 3: FFA_ERROR reports the FF-A error code in X2, +* which is exactly where FFH_FFA_CALL_FAILED wants it. -EIO and -EPROTO +* both mean the call completed, so the registers hold the callee's +* response and not AML's own request. +*/ +if (!ret || ret == -EIO || ret == -EPROTO ) { + regs[1 ] = resp_regs[0 ]; + regs[2 ] = resp_regs[1 ]; + regs[3 ] = resp_regs[2 ]; + } + +out_unlock: +up_read (&ffa_ops_sem); +out: +/* +* DEN0048D describes this field as 64 bits wide and gives the table 3 +* codes as signed values, so sign extend rather than write a narrower +* quantity. 0xfffe or 0xfffffffe would read back as a positive number +* in a 64-bit AML comparison. +*/ + regs[0 ] = (u64 )(s64 )status; +} +int acpi_ffh_address_space_arch_handler (acpi_integer *value,void *region_context) {int ret =0 ;
drivers/acpi/arm64/ffh.c int acpi_ffh_address_space_arch_handler(acpi_integer *value, void *region_contex · line 284
Quoted 7 lines
drivers/acpi/arm64/ffh.c +4
-0@@ -99,6 +278,12 @@ int acpi_ffh_address_space_arch_handler(acpi_integer *value, void *region_contex ffh_ctxt->invoke_ffh64_fn (r, r);memcpy (value, r, ffh_ctxt->info.length); } + }else if (ffh_ctxt->info.offset ==2 ) { +/* FFA_MSG_SEND_DIRECT_REQ2 call */ +if (ffh_ctxt->info.length <sizeof (u64)) + ret =AE_ERROR ;
There is a acpi_ffh_ffa_length_valid() check in acpi_ffh_ffa_handler(), is it a duplicated one here?
drivers/acpi/arm64/ffh.c int acpi_ffh_address_space_arch_handler(acpi_integer *value, void *region_contex · line 286
Quoted 2 lines
drivers/acpi/arm64/ffh.c +2
-0+else +acpi_ffh_ffa_handler (&ffh_ctxt->info, value);
Thanks
Hanjun
Re: [PATCH v2 2/3] ACPI: arm64: Add support for the FF-A FFH Operation Region (offset 2)
Quoted 2 lines
There is a
acpi_ffh_ffa_length_valid()check inacpi_ffh_ffa_handler(), is it a duplicated one here?
A failed acpi_ffh_ffa_length_valid() check is reported through X0. However, a region shorter than 64 bits has no X0 field in which to return that status, so this path returns AE_ERROR instead.
I'll add a comment explaining that distinction in v3.
PATCH v2 3/3 firmware: arm_ffa: Back the ACPI FF-A FFH Operation Region
In reply to Jamie NguyenAdd the FFA_MSG_SEND_DIRECT_REQ2 backend behind FFH Operation Regions declared with an Offset of 0x2, as described in Arm DEN0048D section 2.3.1.2, and register it once partition setup has completed.
None of what the Operation Region handler needs was reachable through the existing ffa_device based interface. Resolving a service UUID to an endpoint ID had no user yet. ffa_sync_send_receive2() always addresses dev->vm_id, so a receiver endpoint ID that AML supplied in X1 cannot be honoured. And the response registers DEN0048D wants copied back to AML are discarded by ffa_msg_send_direct_req2(), which folds the FF-A error code into an errno instead; patch 1 dealt with that one.
DEN0048D only requires the resolved endpoint to be unique, and a single partition may be described by more than one entry, so compare endpoint IDs instead of insisting on exactly one descriptor.
Where the endpoint was enumerated at probe time, check first that it can receive direct request2 messages. AML then gets FFH_FFA_NOT_SUPPORTED instead of a call that was never going to work. An endpoint with no matching device is passed through and left for the callee to reject.
--- drivers/firmware/arm_ffa/driver.c | 118 +++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 2 deletions(-)
drivers/firmware/arm_ffa/driver.c +116 -2
@@ -2146,6 +2146,114 @@ static void ffa_notifications_setup(void)ffa_notifications_cleanup (); } +/* +* Backend for FFH Operation Regions declared with an Offset of 0x2, see Arm +* DEN0048D (Functional Fixed Hardware Specification v1.3) section 2.3.1.2. +* The Operation Region handler itself lives in drivers/acpi/arm64/ffh.c and +* is built in, so it reaches this driver, which may be a module, through the +* ops registered below. +*/ +static int ffa_acpi_ffh_partition_id (const uuid_t *uuid,u16 *dst_id) +{ +struct ffa_partition_info *pbuf; +int count, idx, ret =0 ; +u16 id; + + count =ffa_partition_probe (uuid, &pbuf); +if (count <=0 ) +return count ? : -ENOENT ; + +/* +* DEN0048D only requires the endpoint ID to be unique. A partition may +* be described by more than one entry, so compare IDs rather than +* insisting on a single descriptor. +*/ + id = pbuf[0 ].id; +for (idx =1 ; idx < count; idx++) { +if (pbuf[idx].id != id) { + ret = -ENOTUNIQ ; + goto out; + } + } + + *dst_id = id; +out: +kfree (pbuf); +return ret; +} + +static int ffa_acpi_ffh_match_id (struct device *dev,const void *data) +{ +const u16 *dst_id = data; + +return to_ffa_dev (dev)->vm_id == *dst_id; +} + +static int ffa_acpi_ffh_check_partition (u16 dst_id) +{ +struct device *dev; +bool supported; + + dev =bus_find_device (&ffa_bus_type,NULL , &dst_id, + ffa_acpi_ffh_match_id); +/* +* Only partitions reported by FFA_PARTITION_INFO_GET at probe time have +* a device here. AML may name an endpoint that was never enumerated, so +* an unknown one is left to the callee to reject rather than refused +* outright. +*/ +if (!dev) +return 0 ; + + supported =ffa_partition_supports_direct_req2_recv (to_ffa_dev (dev)); +put_device (dev); + +return supported ?0 : -EOPNOTSUPP ; +} + +static int ffa_acpi_ffh_direct_req2 (u16 dst_id,const uuid_t *uuid, +u64 *payload,unsigned int nr_payload, +u64 resp_regs[3 ]) +{ +struct ffa_send_direct_data2 req = {}, resp; +int ret; + +BUILD_BUG_ON (sizeof (req.data[0 ]) !=sizeof (*payload)); + +if (!drv_info->msg_direct_req2_supp) +return -EOPNOTSUPP ; + +if (!nr_payload || nr_payload >ARRAY_SIZE (req.data)) +return -EINVAL ; + + ret =ffa_acpi_ffh_check_partition (dst_id); +if (ret) +return ret; + +/* +* Registers not represented in the Operation Region stay zero, as +* required by DEN0048D. +*/ +memcpy (req.data, payload, nr_payload *sizeof (*payload)); + + ret =__ffa_msg_send_direct_req2 (drv_info->vm_id, dst_id, uuid, &req, + &resp, resp_regs); + +/* +* DEN0048D asks for the registers to be copied back once the call has +* completed, whatever the outcome, so this runs on the FFA_ERROR path +* too rather than leaving AML looking at its own request. +*/ +memcpy (payload, resp.data, nr_payload *sizeof (*payload)); + +return ret; +} + +static const struct acpi_ffh_ffa_ops ffa_acpi_ffh_ops = { + .partition_id = ffa_acpi_ffh_partition_id, + .direct_req2 = ffa_acpi_ffh_direct_req2, +}; +static int ffa_probe (struct platform_device *pdev) {int ret;
@@ -2228,8 +2336,13 @@ static int ffa_probe(struct platform_device *pdev)ffa_notifications_setup (); ret =ffa_setup_partitions (); -if (!ret) -return ret; +if (!ret) { + ret =acpi_ffh_ffa_register (&ffa_acpi_ffh_ops); +if (ret && ret != -EOPNOTSUPP ) +pr_warn ("failed to register ACPI FFH backend (%d)\n" , + ret); +return 0 ; + }pr_err ("failed to setup partitions\n" );ffa_notifications_cleanup ();
@@ -2249,6 +2362,7 @@ static void ffa_remove(struct platform_device *pdev) {struct ffa_drv_info *info =platform_get_drvdata (pdev); +acpi_ffh_ffa_unregister (&ffa_acpi_ffh_ops);ffa_notifications_cleanup ();ffa_partitions_cleanup ();ffa_rxtx_unmap ();
Signature · 1 line
2.43.0
Gentle ping on this. The series still applies cleanly to v7.3-rc1 and current linux-next, and I'm happy to respin if you'd prefer anything changed.
Thanks,
Jamie
Sudeep Holla
maintainerQuoted 31 lines · Jamie Nguyen
Arm DEN0048D (Functional Fixed Hardware Specification v1.3), published in March 2026, adds a third FFH Operation Region flavour:
https://developer.arm.com/documentation/den0048/latest/
An Operation Region declared with an Offset of
0x2triggers anFFA_MSG_SEND_DIRECT_REQ2call instead of a bare SMC or HVC:OperationRegion (AFFH, FFixedHW, 2, 40)
Field (AFFH, BufferAcc, NoLock, Preserve) { FFAD, 320 }Each 64-bit field is one register, ordered from X0. X0 carries the call status on return, X1[15:0] the receiver endpoint ID (or zero, which asks OSPM to resolve it from the UUID), X2-X3 the service UUID written with
ToUUID(), and X4-X17 the payload. The region Length is 32 + 8 * N bytes with 1 <= N <= 14, so X0-X4 at minimum and X0-X17 at most.The spec recommends offset
0x2for new platforms on the grounds that not every OSPM implements offsets0x0and0x1. Linux has had both since v6.2 but nothing for0x2, so AML using the recommended encoding currently getsAE_ERRORback.These patches implement it. I could not find any prior posting of this on linux-acpi or linux-arm-kernel, so apologies if I have missed one and duplicated someone's work.
All three patches are co-developed with Dat Mach.
Design
------
Quoted 7 lines
drivers/acpi/arm64/ffh.cholds the DEN0048D side: region length validation, the X0-X17 layout, theToUUID()to FF-A UUID byte order conversion, and the table 3 status codes.drivers/firmware/arm_ffa/holds the FF-A side: resolving a service UUID to an endpoint, and the call itself, including theFFA_YIELDandFFA_INTERRUPTre-invocation DEN0048D asks for.
I have concerns regarding the new dependency on the FF-A driver.
Could you clarify how the build and runtime behavior are protected when the FF-A driver is disabled? The current patchset introduces a strict dependency without explicit configuration checks or guards, which will likely cause compilation or execution failures in environments where FF-A is not enabled.
Quoted 5 lines
The two talk through an ops structure the FF-A driver registers rather than a direct call, because
ffh.cis built in under a boolKconfigsymbol whileCONFIG_ARM_FFA_TRANSPORTis a tristate. Unregistration takes the rwsem for writing, so it cannot race with an access already in flight.
We need to explicitly document the reasons for establishing a hard dependency between the ACPI FFH and the FF-A driver. In my view, this FFH mechanism (0x2) simply issues an SMC call with the FFA_MSG_SEND_DIRECT_REQ2 FID. While I understand the specification assigns extra responsibility to the OSPM to populate the partition ID, are there any other technical justifications for this tight coupling?
Quoted 8 lines
None of what the handler needs was reachable through the existing
ffa_deviceinterface.ffa_sync_send_receive2()always addressesdev->vm_id, so a receiver endpoint ID supplied by AML cannot be honoured. UUID to endpoint resolution had no in-kernel user at all. Andffa_msg_send_direct_req2()throws away the response registers DEN0048D wants copied back to AML. Patch 1 splits those out, leaving what existing callers see unchanged.
I see above as one reason why they need to be separate.
Quoted 7 lines
Testing
-------Built on arm64 with
CONFIG_ACPI_FFH=yandCONFIG_ARM_FFA_TRANSPORTboth =y and =m, and withCONFIG_ACPI_FFH=n, W=1 clean. Every patch builds on its own.
How about CONFIG_ARM_FFA_TRANSPORT=n and CONFIG_ACPI_FFH=y ? Is that blocked in someway I am failing to see ?
Signature · 2 lines
Regards, Sudeep
Quoted 2 lines · Sudeep Holla
Could you clarify how the build and runtime behavior are protected when the FF-A driver is disabled?
There is no build-time dependency from ACPI FFH to the FF-A driver. The registration direction is from FF-A into FFH: the FF-A driver registers an optional backend after probe and unregisters it on removal.
With CONFIG_ARM_FFA_TRANSPORT=n, no backend is registered and an offset 2 access returns FFH_FFA_NOT_SUPPORTED. With CONFIG_ACPI_FFH=n, the registration functions are static inline stubs.
I have also built CONFIG_ACPI_FFH=y with CONFIG_ARM_FFA_TRANSPORT=n. The W=1 build and full vmlinux link are clean, with no unresolved references to the FF-A transport driver. I'll mention this case in the v3 cover letter.
Quoted 1 line
Are there any other technical justifications for this tight coupling?
FFA_MSG_SEND_DIRECT_REQ2 requires FF-A state already owned by the driver:
the selected SMC or HVC conduit, the sender endpoint ID from FFA_ID_GET, UUID-to-endpoint resolution through the partition discovery ABIs, REQ2 feature detection, and FFA_RUN handling after FFA_YIELD or FFA_INTERRUPT.
Open-coding those operations in ffh.c would duplicate FF-A initialization and state management. The ops registration lets FFH use that state when the driver is available while degrading cleanly when it is not.
Sudeep Holla
maintainerQuoted 8 lines · Jamie Nguyen
Quoted 2 lines · Sudeep Holla
Could you clarify how the build and runtime behavior are protected when the FF-A driver is disabled?
There is no build-time dependency from ACPI FFH to the FF-A driver. The registration direction is from FF-A into FFH: the FF-A driver registers an optional backend after probe and unregisters it on removal.
Equally ugly. FF-A spec doesn't talk about ACPI FFH, so it doesn't belong in FF-A driver.
Quoted 4 lines
With
CONFIG_ARM_FFA_TRANSPORT=n, no backend is registered and an offset 2 access returnsFFH_FFA_NOT_SUPPORTED. WithCONFIG_ACPI_FFH=n, the registration functions are static inline stubs.
So if on a platform, ASL has FFH with offset 2, we fail if FF-A driver fails to initialise ? What if this FFH offset 2 is used in some other device methods that need to be executed before FF-A module is inserted ? We pull that device down as well ? Is that acceptable ?
Quoted 5 lines
I have also built
CONFIG_ACPI_FFH=ywithCONFIG_ARM_FFA_TRANSPORT=n. The W=1 build and full vmlinux link are clean, with no unresolved references to the FF-A transport driver. I'll mention this case in the v3 cover letter.
Fair enough, build dependency was one of the concern and not the only concern.
Quoted 7 lines
Quoted 1 line
Are there any other technical justifications for this tight coupling?
FFA_MSG_SEND_DIRECT_REQ2requires FF-A state already owned by the driver:
the selected SMC or HVC conduit, the sender endpoint ID fromFFA_ID_GET, UUID-to-endpoint resolution through the partition discovery ABIs, REQ2 feature detection, andFFA_RUNhandling afterFFA_YIELDorFFA_INTERRUPT.
Yes but are they strong reasons to break some use-case like above.
Quoted 3 lines
Open-coding those operations in
ffh.cwould duplicate FF-A initialization and state management. The ops registration lets FFH use that state when the driver is available while degrading cleanly when it is not.
There is no state management with simple FFA_MSG_SEND_DIRECT_REQ2, it is synchronous send request if you look at it along wih offset 0/1 and without FF-A driver knowledge.
I need to think apart from duplication, we shouldn't have much issue.
Signature · 2 lines
Regards, Sudeep
Quoted 2 lines · Sudeep Holla
Equally ugly. FF-A spec doesn't talk about ACPI FFH, so it doesn't belong in FF-A driver.
Okay -- I'll move the ACPI-specific handling into ffh.c.
Quoted 4 lines
So if on a platform, ASL has FFH with offset 2, we fail if FF-A driver fails to initialise ? What if this FFH offset 2 is used in some other device methods that need to be executed before FF-A module is inserted ? We pull that device down as well ? Is that acceptable ?
You're right. With the current registration, offset 2 may be unavailable during initial enumeration or before module load. That's not suitable for AML.
Quoted 3 lines
There is no state management with simple
FFA_MSG_SEND_DIRECT_REQ2, it is synchronous send request if you look at it along wih offset 0/1 and without FF-A driver knowledge.
The request itself is synchronous and register-only. But the whole operation still shares FF-A state: version negotiation must be coordinated with other FF-A use, and X1 == 0 needs UUID lookup. It looks like FFA_PARTITION_INFO_GET_REGS is optional at the Non-secure physical instance according to DEN0077A Table 13.1. As such, I believe a portable implementation would need the shared RX/TX buffers. For example, if X1 is zero and that ABI is unavailable, UUID lookup would need to fall back to FFA_PARTITION_INFO_GET, whose results are returned through the caller's RX buffer.
Sudeep Holla
maintainerQuoted 19 lines · Jamie Nguyen
Quoted 2 lines · Sudeep Holla
Equally ugly. FF-A spec doesn't talk about ACPI FFH, so it doesn't belong in FF-A driver.
Okay -- I'll move the ACPI-specific handling into
ffh.c.Quoted 4 lines
So if on a platform, ASL has FFH with offset 2, we fail if FF-A driver fails to initialise ? What if this FFH offset 2 is used in some other device methods that need to be executed before FF-A module is inserted ? We pull that device down as well ? Is that acceptable ?
You're right. With the current registration, offset 2 may be unavailable during initial enumeration or before module load. That's not suitable for AML.
Quoted 3 lines
There is no state management with simple
FFA_MSG_SEND_DIRECT_REQ2, it is synchronous send request if you look at it along wih offset 0/1 and without FF-A driver knowledge.
Quoted 9 lines
The request itself is synchronous and register-only. But the whole operation still shares FF-A state: version negotiation must be coordinated with other FF-A use, and X1 == 0 needs UUID lookup. It looks like
FFA_PARTITION_INFO_GET_REGSis optional at the Non-secure physical instance according to DEN0077A Table 13.1. As such, I believe a portable implementation would need the shared RX/TX buffers. For example, if X1 is zero and that ABI is unavailable, UUID lookup would need to fall back toFFA_PARTITION_INFO_GET, whose results are returned through the caller's RX buffer.
I did try to come up something simpler and independent last evening and this morning, far from completion and I am also thinking of 2 main changes to it yet:
1. Maintain hash for receiver ID list
2. Drop the whole FFA_VERSION fuss as it must be dealt with in UEFI and that should be sufficient.
Of course not tested yet and even not sure this version is compile tested. Also more checks needs to added like INFO_GET_REGS is used without check.
Regards,
Sudeep
-->8
From a78e71fe5a759687fbc205b817033f1a381b8c5e Mon Sep 17 00:00:00 2001
From: Sudeep Holla <[email protected]>
Date: Wed, 23 Sep 2026 13:18:37 +0100
Subject: [PATCH 1/2] firmware: arm_ffa: Share FF-A register field definitions
ACPI FFH and the FF-A transport driver will be interpreting the same PARTITION_INFO_GET_REGS metadata and pack endpoint IDs using the same bit fields. Define these fields once in arm_ffa.h instead of keeping private copies.
Use the shared masks in the transport driver and check descriptor lengths against the same minimum used by ACPI FFH. This keeps the ABI encoding consistent between the two users.
--- drivers/firmware/arm_ffa/driver.c | 48 +++++++++++-------------------- include/linux/arm_ffa.h | 19 ++++++++++++ 2 files changed, 36 insertions(+), 31 deletions(-)
drivers/firmware/arm_ffa/driver.c +17 -31
@@ -55,13 +55,6 @@#define FFA_MIN_VERSION FFA_VERSION_1_0#define FFA_PLATFORM_NAME "arm-ffa" -#define SENDER_ID_MASK GENMASK(31, 16) -#define RECEIVER_ID_MASK GENMASK(15, 0) -#define SENDER_ID (x) ((u16)(FIELD_GET(SENDER_ID_MASK, (x)))) -#define RECEIVER_ID (x) ((u16)(FIELD_GET(RECEIVER_ID_MASK, (x)))) -#define PACK_TARGET_INFO (s, r) \ - (FIELD_PREP(SENDER_ID_MASK, (s)) | FIELD_PREP(RECEIVER_ID_MASK, (r))) -#define RXTX_MAP_MIN_BUFSZ_MASK GENMASK(1, 0)#define RXTX_MAP_MAX_BUFSZ_MASK GENMASK(31, 16)#define RXTX_MAP_MIN_BUFSZ (x) (FIELD_GET(RXTX_MAP_MIN_BUFSZ_MASK, (x)))
@@ -328,24 +321,16 @@ __ffa_partition_info_get(u32 uuid0, u32 uuid1, u32 uuid2, u32 uuid3,return count; } -#define LAST_INDEX_MASK GENMASK(15, 0) -#define CURRENT_INDEX_MASK GENMASK(31, 16) -#define UUID_INFO_TAG_MASK GENMASK(47, 32) -#define PARTITION_INFO_SZ_MASK GENMASK(63, 48) -#define PARTITION_COUNT (x) ((u16)(FIELD_GET(LAST_INDEX_MASK, (x))) + 1) -#define CURRENT_INDEX (x) ((u16)(FIELD_GET(CURRENT_INDEX_MASK, (x)))) -#define UUID_INFO_TAG (x) ((u16)(FIELD_GET(UUID_INFO_TAG_MASK, (x)))) -#define PARTITION_INFO_SZ (x) ((u16)(FIELD_GET(PARTITION_INFO_SZ_MASK, (x)))) -#define PART_INFO_ID_MASK GENMASK(15, 0) -#define PART_INFO_EXEC_CXT_MASK GENMASK(31, 16) -#define PART_INFO_PROPS_MASK GENMASK(63, 32) +#define PARTITION_COUNT (x) ((u16)(FIELD_GET(FFA_PART_INFO_LAST_IDX_MASK, (x))) + 1) +#define CURRENT_INDEX (x) ((u16)(FIELD_GET(FFA_PART_INFO_CUR_IDX_MASK, (x)))) +#define UUID_INFO_TAG (x) ((u16)(FIELD_GET(FFA_PART_INFO_UUID_TAG_MASK, (x)))) +#define PARTITION_INFO_SZ (x) ((u16)(FIELD_GET(FFA_PART_INFO_DESC_SIZE_MASK, (x))))#define FFA_PART_INFO_GET_REGS_FIRST_REG 3 -#define FFA_PART_INFO_GET_REGS_MIN_REGS_PER_DESC 3#define FFA_PART_INFO_GET_REGS_NUM_REGS \ (sizeof(ffa_value_t) / sizeof_field(ffa_value_t, a0)) -#define PART_INFO_ID (x) ((u16)(FIELD_GET(PART_INFO_ID_MASK, (x)))) -#define PART_INFO_EXEC_CXT (x) ((u16)(FIELD_GET(PART_INFO_EXEC_CXT_MASK, (x)))) -#define PART_INFO_PROPERTIES (x) ((u32)(FIELD_GET(PART_INFO_PROPS_MASK, (x)))) +#define PART_INFO_ID (x) ((u16)(FIELD_GET(FFA_PART_INFO_ID_MASK, (x)))) +#define PART_INFO_EXEC_CXT (x) ((u16)(FIELD_GET(FFA_PART_INFO_EXEC_CXT_MASK, (x)))) +#define PART_INFO_PROPERTIES (x) ((u32)(FIELD_GET(FFA_PART_INFO_PROPS_MASK, (x))))static int __ffa_partition_info_get_regs (u32 uuid0,u32 uuid1,u32 uuid2,u32 uuid3,struct ffa_partition_info *buffer,int num_parts)
@@ -383,9 +368,9 @@ __ffa_partition_info_get_regs(u32 uuid0, u32 uuid1, u32 uuid2, u32 uuid3,if (buf_sz %sizeof (*regs))return -EINVAL ; - regs_per_desc = buf_sz /sizeof (*regs); -if (regs_per_desc <FFA_PART_INFO_GET_REGS_MIN_REGS_PER_DESC ) +if (buf_sz <FFA_PART_INFO_MIN_DESC_SIZE )return -EINVAL ; + regs_per_desc = buf_sz /sizeof (*regs); nr_desc = cur_idx - start_idx +1 ; max_desc = (FFA_PART_INFO_GET_REGS_NUM_REGS -
@@ -501,7 +486,7 @@ static inline void ffa_msg_send_wait_for_completion(ffa_value_t *ret)static int ffa_msg_send_direct_req (u16 src_id,u16 dst_id,bool mode_32bit,struct ffa_send_direct_data *data) { -u32 req_id, resp_id, src_dst_ids =PACK_TARGET_INFO (src_id, dst_id); +u32 req_id, resp_id, src_dst_ids =ffa_pack_target_info (src_id, dst_id);ffa_value_t ret;if (mode_32bit) {
@@ -537,7 +522,7 @@ static int ffa_msg_send_direct_req(u16 src_id, u16 dst_id, bool mode_32bit,static int ffa_msg_send2 (struct ffa_device *dev,u16 src_id,void *buf,size_t sz) { -u32 src_dst_ids =PACK_TARGET_INFO (src_id, dev->vm_id); +u32 src_dst_ids =ffa_pack_target_info (src_id, dev->vm_id);struct ffa_indirect_msg_hdr *msg;ffa_value_t ret;int retval =0 ;
@@ -571,7 +556,7 @@ static int ffa_msg_send2(struct ffa_device *dev, u16 src_id, void *buf, size_t sstatic int ffa_msg_send_direct_req2 (u16 src_id,u16 dst_id,const uuid_t *uuid,struct ffa_send_direct_data2 *data) { -u32 src_dst_ids =PACK_TARGET_INFO (src_id, dst_id); +u32 src_dst_ids =ffa_pack_target_info (src_id, dst_id);union {uuid_t uuid;__le64 regs[2 ];
@@ -897,7 +882,7 @@ enum notify_type {#define RECEIVER_VCPU_MASK GENMASK(31, 16)#define PACK_NOTIFICATION_GET_RECEIVER_INFO (vcpu_r, r) \ (FIELD_PREP(RECEIVER_VCPU_MASK, (vcpu_r)) | \ - FIELD_PREP(RECEIVER_ID_MASK, (r))) + FIELD_PREP(FFA_TARGET_INFO_RECEIVER_MASK, (r)))#define NOTIFICATION_INFO_GET_MORE_PEND_MASK BIT(0)#define NOTIFICATION_INFO_GET_ID_COUNT GENMASK(11, 7)
@@ -928,7 +913,7 @@ static int ffa_notification_bind_common(u16 dst_id, u64 bitmap, u32 flags, bool is_bind) {ffa_value_t ret; -u32 func, src_dst_ids =PACK_TARGET_INFO (dst_id, drv_info->vm_id); +u32 func, src_dst_ids =ffa_pack_target_info (dst_id, drv_info->vm_id); func = is_bind ?FFA_NOTIFICATION_BIND :FFA_NOTIFICATION_UNBIND ;
@@ -950,7 +935,7 @@ staticint ffa_notification_set (u16 src_id,u16 dst_id,u32 flags,u64 bitmap) {ffa_value_t ret; -u32 src_dst_ids =PACK_TARGET_INFO (dst_id, src_id); +u32 src_dst_ids =ffa_pack_target_info (dst_id, src_id); invoke_ffa_fn((ffa_value_t) { .a0 = FFA_NOTIFICATION_SET, .a1 = src_dst_ids, .a2 = flags,
@@ -1567,7 +1552,8 @@ static void handle_fwk_notif_callbacks(u32 bitmap)return ; } - target =SENDER_ID (msg->send_recv_id); + target =FIELD_GET (FFA_TARGET_INFO_SENDER_MASK , + msg->send_recv_id);if (offset >=sizeof (*msg))uuid_copy (&uuid, &msg->uuid);else
include/linux/arm_ffa.h +19 -0
@@ -130,6 +130,15 @@#define FFA_FEAT_RXTX_MIN_SZ_16K 2#define FFA_FEAT_RXTX_MIN_SZ_MASK GENMASK(1, 0) +#define FFA_TARGET_INFO_SENDER_MASK GENMASK(31, 16) +#define FFA_TARGET_INFO_RECEIVER_MASK GENMASK(15, 0) + +static inline u32 ffa_pack_target_info (u16 sender,u16 receiver) +{ +return FIELD_PREP (FFA_TARGET_INFO_SENDER_MASK , sender) | +FIELD_PREP (FFA_TARGET_INFO_RECEIVER_MASK , receiver); +} +/* FFA Bus/Device/Driver related */ struct ffa_device {u32 id;
@@ -228,6 +237,16 @@ extern const struct bus_type ffa_bus_type;/* The FF-A 1.0 partition structure lacks the uuid[4] */ #define FFA_1_0_PARTITON_INFO_SZ (8) +/* FFA_PARTITION_INFO_GET_REGS response fields */ +#define FFA_PART_INFO_LAST_IDX_MASK GENMASK_ULL(15, 0) +#define FFA_PART_INFO_CUR_IDX_MASK GENMASK_ULL(31, 16) +#define FFA_PART_INFO_UUID_TAG_MASK GENMASK_ULL(47, 32) +#define FFA_PART_INFO_DESC_SIZE_MASK GENMASK_ULL(63, 48) +#define FFA_PART_INFO_MIN_DESC_SIZE 24 +#define FFA_PART_INFO_ID_MASK GENMASK_ULL(15, 0) +#define FFA_PART_INFO_EXEC_CXT_MASK GENMASK_ULL(31, 16) +#define FFA_PART_INFO_PROPS_MASK GENMASK_ULL(63, 32) +/* FFA transport related */ struct ffa_partition_info {u16 id;
Signature · 30 lines
2.43.0 From 47807754d0d21003a37a6d30022317d8696e0daa Mon Sep 17 00:00:00 2001 From: Sudeep Holla <[email protected]> Date: Tue, 22 Sep 2026 14:36:24 +0100 Subject: [PATCH 2/2][WIP] ACPI: FFH: Support FF-A direct request 2 calls Arm Functional Fixed Hardware specification v1.3 defines FFH OperationRegion offset 2 for issuing FFA_MSG_SEND_DIRECT_REQ2 calls. The arm64 FFH handler currently supports only generic 32-bit and 64-bit SMCCC calls, so it cannot implement this standardized interface. Add a standalone FF-A path using the existing SMCCC conduit. Negotiate FF-A v1.2, discover the sender endpoint with FFA_ID_GET, and use either the receiver supplied by firmware or resolve a unique receiver from the service UUID with FFA_PARTITION_INFO_GET_REGS. Convert the ACPI ToUUID representation to the FF-A register encoding, construct the direct request, resume interrupted or yielded calls with FFA_RUN, and return the defined FFH status codes to AML. Register-based partition discovery avoids RX/TX buffer ownership and keeps the FFH implementation independent of the Arm FF-A transport driver. Signed-off-by: Sudeep Holla <[email protected]> --- drivers/acpi/arm64/ffh.c | 223 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+)
drivers/acpi/arm64/ffh.c +223 -0
242 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 8 lines · Sudeep Holla
I did try to come up something simpler and independent last evening and this morning, far from completion and I am also thinking of 2 main changes to it yet:
1. Maintain hash for receiver ID list
2. Drop the wholeFFA_VERSIONfuss as it must be dealt with in UEFI and that should be sufficient.Of course not tested yet and even not sure this version is compile tested.
Thanks, this looks much simpler. I can confirm that both patches apply to v7.3-rc4 and build W=1 clean with ARM_FFA_TRANSPORT=y, =m and =n. The =n vmlinux also links with no transport-driver symbols pulled in.
On FFA_VERSION: as written, if the transport driver has already mapped its RX/TX buffers, I think DEN0077A R0216 has this negotiation return the Null version, so offset 2 would report NOT_SUPPORTED for any AML run after the driver probes. But if it's dropped, I don't think it's guaranteed that a compatible version will have been negotiated by then, right?
[...]
drivers/acpi/arm64/ffh.c struct acpi_ffh_data { · line 219
Quoted 1 line
drivers/acpi/arm64/ffh.c +1
-0+memcpy (&args.a4, &buf[4 ], len -4 *sizeof (u64));
This would trip CONFIG_FORTIFY_SOURCE's field-spanning write check whenever the region has more than one payload register. I think this would cover that case:
memcpy((void *)&args + offsetof(struct arm_smccc_1_2_regs, a4), &buf[4], len - 4 * sizeof(u64));
Sudeep Holla
maintainerQuoted 8 lines · Jamie Nguyen
Quoted 7 lines · Sudeep Holla
I did try to come up something simpler and independent last evening and this morning, far from completion and I am also thinking of 2 main changes to it yet:
1. Maintain hash for receiver ID list
2. Drop the wholeFFA_VERSIONfuss as it must be dealt with in UEFI and that should be sufficient.
Quoted 6 lines
Quoted 1 line
Of course not tested yet and even not sure this version is compile tested.
Thanks, this looks much simpler. I can confirm that both patches apply to v7.3-rc4 and build W=1 clean with ARM_FFA_TRANSPORT=y, =m and =n. The =n vmlinux also links with no transport-driver symbols pulled in.
Thanks for giving it a spin.
Quoted 6 lines
On
FFA_VERSION: as written, if the transport driver has already mapped its RX/TX buffers, I think DEN0077A R0216 has this negotiation return the Null version, so offset 2 would reportNOT_SUPPORTEDfor any AML run after the driver probes. But if it's dropped, I don't think it's guaranteed that a compatible version will have been negotiated by then, right?
Agreed, I need to think it through. I definitely want to avoid any usage of Rx/Tx buffers here.
Quoted 10 lines
[...]
drivers/acpi/arm64/ffh.c struct acpi_ffh_data { · line 219
Quoted 1 line
drivers/acpi/arm64/ffh.c +1
-0+memcpy (&args.a4, &buf[4 ], len -4 *sizeof (u64));This would trip CONFIG_FORTIFY_SOURCE's field-spanning write check whenever the region has more than one payload register. I think this would cover that case:
memcpy((void *)&args + offsetof(struct arm_smccc_1_2_regs, a4), &buf[4], len - 4 * sizeof(u64));
Thanks, will update.
Which version of FF-A is being deployed on your platforms ? Just wondering if we can set v1.3 as minimum required here and use query negotiated version feature of FFA_VERSION. It is not a must, just checking if that might simplify things.
Signature · 2 lines
Regards, Sudeep
Quoted 1 line · Sudeep Holla
Which version of FF-A is being deployed on your platforms?
We have platforms with FF-A firmware versions 1.1, 1.2 and 1.3. The platform I have been using to test offset 2 reports FF-A 1.3.
Sudeep Holla
maintainerQuoted 6 lines · Jamie Nguyen
Quoted 1 line · Sudeep Holla
Which version of FF-A is being deployed on your platforms?
We have platforms with FF-A firmware versions 1.1, 1.2 and 1.3. The platform I have been using to test offset 2 reports FF-A 1.3.
Thanks, will think a bit on this and see what is the best way to progress.
Signature · 2 lines
Regards, Sudeep
Quoted 1 line · Sudeep Holla
Thanks, will think a bit on this and see what is the best way to progress.
One further data point: our platforms using offset 2 for a TPM DSM have an FF-A 1.2 SPMC. I'd like to keep 1.2 support if possible, since FFA_MSG_SEND_DIRECT_REQ2 was added in 1.2. How would you handle version negotiation in ffh.c when the transport may already have negotiated a version?