Thread (30 messages) flat view 30 messages, 3 authors, 4h ago

Re: [PATCH v17 1/7] firmware: arm_rmm: Add SMC definitions for calling the RMM

From: Suzuki K Poulose <suzuki.poulose@arm.com>
Date: 2026-09-09 08:39:50
Also in: kvm, kvmarm, linux-arm-kernel, lkml

On 08/09/2026 23:41, Gavin Shan wrote:
On 9/8/26 8:37 PM, Suzuki K Poulose wrote:
quoted
On 08/09/2026 07:19, Gavin Shan wrote:
quoted
On 9/7/26 7:59 PM, Suzuki K Poulose wrote:
quoted
From: Steven Price <steven.price@arm.com>

The RMM (Realm Management Monitor) provides functionality that can be
accessed by SMC calls from the host.

The SMC definitions are based on DEN0137[1] version 2.0-bet3

[1] https://developer.arm.com/documentation/den0137/2-0bet3/

Signed-off-by: Steven Price <steven.price@arm.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
...
quoted
quoted
---
  include/linux/arm-smccc-rmi.h | 494 ++++++++++++++++++++++++++++++ 
++++
  1 file changed, 494 insertions(+)
  create mode 100644 include/linux/arm-smccc-rmi.h
Some nitpicks below, please pick up the commits that look reasonable :)
quoted
quoted
+
+#define RMI_RETURN_STATUS_MASK        (0xFFUL)
+#define RMI_RETURN_INDEX_MASK        (0xFFUL << 8)
+#define RMI_RETURN_MEMREQ_MASK        (0x3UL << 8)
+#define RMI_RETURN_CAN_CANCEL_MASK    (0x1UL << 10)
+
+#define RMI_RETURN_STATUS(ret) FIELD_GET(RMI_RETURN_STATUS_MASK, ret)
+#define RMI_RETURN_INDEX(ret)        
FIELD_GET(RMI_RETURN_INDEX_MASK, ret)
+#define RMI_RETURN_MEMREQ(ret) FIELD_GET(RMI_RETURN_MEMREQ_MASK, ret)
+#define RMI_RETURN_CAN_CANCEL(ret) 
FIELD_GET(RMI_RETURN_CAN_CANCEL_MASK, ret)
+
If I'm correct enough, RMI_RETURN_{STATUS, INDEX, MEMREQ, CAN_CANEL} 
_MASK are used
for once in this header file. So we needn't explicitly expose them 
and combine their
definitions with users to fetch the corresponding fields, as below.

#define RMI_RETURN_STATUS(ret)        FIELD_GET(GENMASK(7, 0), ret)
#define RMI_RETURN_INDEX(ret)        FIELD_GET(GENMASK(15, 8), ret)
#define RMI_RETURN_MEMREQ(ret)        FIELD_GET(GENMASK(10, 8), ret)
#define RMI_RETURN_CAN_CANCEL(ret)    FIELD_GEt(GENMASK(10, 10), ret)
I belive the header files were generated from a tool (by Steven) and
these would make it easier to compare with the generated header file for
any deviation from the spec. So, I am a bit reluctant make these
changes.

That said, I am happy to convert the mask definitions to GENMASK() for
consistency and readability. i.e., something like:
diff --git a/include/linux/arm-smccc-rmi.h b/include/linux/arm-smccc- 
rmi.h
index 3eb88caf40964..078197284415e 100644
--- a/include/linux/arm-smccc-rmi.h
+++ b/include/linux/arm-smccc-rmi.h
@@ -139,10 +139,10 @@
  #define RMI_ABI_VERSION_GET_MINOR(version) ((version) & 0xFFFF)
  #define RMI_ABI_VERSION(major, minor)      (((major) << 16) | (minor))

-#define RMI_RETURN_STATUS_MASK         (0xFFUL)
-#define RMI_RETURN_INDEX_MASK          (0xFFUL << 8)
-#define RMI_RETURN_MEMREQ_MASK         (0x3UL << 8)
-#define RMI_RETURN_CAN_CANCEL_MASK     (0x1UL << 10)
+#define RMI_RETURN_STATUS_MASK         GENMASK(7, 0)
+#define RMI_RETURN_INDEX_MASK          GENMASK(15, 8)
+#define RMI_RETURN_MEMREQ_MASK         GENMASK(10, 8)
+#define RMI_RETURN_CAN_CANCEL_MASK     BIT(10)
Ok.
quoted
quoted
quoted
+#define RMI_SUCCESS            0
+#define RMI_ERROR_INPUT            1
+#define RMI_ERROR_REALM            2
+#define RMI_ERROR_REC            3
+#define RMI_ERROR_RTT            4
+#define RMI_ERROR_NOT_SUPPORTED        5
+#define RMI_ERROR_DEVICE        6
+#define RMI_ERROR_RTT_AUX        7
+#define RMI_ERROR_PSMMU_ST        8
+#define RMI_ERROR_DPT            9
+#define RMI_BUSY            10
+#define RMI_ERROR_GLOBAL        11
+#define RMI_ERROR_TRACKING        12
+#define RMI_INCOMPLETE            13
+#define RMI_BLOCKED            14
+#define RMI_ERROR_GPT            15
+#define RMI_ERROR_GRANULE        16
+
+#define RMI_CONTINUE_KEEP_GOING        0
+#define RMI_CONTINUE_STOP        1
+
+#define RMI_OP_MEM_REQ_NONE        0
+#define RMI_OP_MEM_REQ_DONATE        1
+#define RMI_OP_MEM_REQ_RECLAIM        2
+
+#define RMI_DONATE_SIZE_MASK        3UL
+#define RMI_DONATE_COUNT_MASK        GENMASK(15, 2)
+#define RMI_DONATE_CONTIG_MASK        BIT(16)
+#define RMI_DONATE_STATE_MASK        GENMASK(18, 17)
+
+#define RMI_DONATE_SIZE(req)        FIELD_GET(RMI_DONATE_SIZE_MASK, 
req)
+#define RMI_DONATE_COUNT(req)        
FIELD_GET(RMI_DONATE_COUNT_MASK, req)
+#define RMI_DONATE_CONTIG(req) FIELD_GET(RMI_DONATE_CONTIG_MASK, req)
+#define RMI_DONATE_STATE(req)        
FIELD_GET(RMI_DONATE_STATE_MASK, req)
+
As above, RMI_DONATE_{SIZE, COUNT, CONTIG, STATE}_MASK are used for 
once in this
header file. So their definitions can be dropped by modifying the 
followup macros,
as below. Some enhancements are also applicable: (a) Use 'BLOCK' to 
indicate the
unit encoded in the request. (b) The macros are put into order from 
MSB to LSB.

#define RMI_DONATE_STATE(req)        FIELD_GET(GENMASK(18, 17), req)
#define RMI_DONATE_CONTIG(req)        FIELD_GET(GENMASK(16, 16), req)
#define RMI_DONATE_BLOCK_COUNT(req)    FIELD_GET(GENMASK(15, 2), req)
#define RMI_DONATE_BLOCK_SIZE(req)    FIELD_GET(GENMASK(1, 0), req)
Same as above.
Please rename RMI_DONATE_{SIZE, COUNT} to RMI_DONATE_BLOCK_{SIZE, COUNT} 
if possible.
Sorry, forgot to add that, I have renamed RMI_{DONATE,ADDR_RANGE}_SIZE
=> RMI_{*}_BLOCK_SIZE, left  the _COUNT as it is.
quoted
quoted
quoted
+#define RMI_OP_MEM_DELEGATED        0
+#define RMI_OP_MEM_UNDELEGATED        1
+#define RMI_OP_MEM_CONDITIONAL        2
+
B4.6.40 RmiOpMemContig type is missed here and they should be used in 
the c code.

#define RMI_OP_MEM_NON_CONTIG    0
#define RMI_OP_MEM_CONTIG    1

In the c code, we shall have:

if (RMI_DONATE_CONTIG(req) == RMI_OP_MEM_CONTIG)) {
    ...
} else {
    ...
}
Does it make much sense though ? I prefer

if (RMI_DONATE_CONTIG(req))

to


if (RMI_DONATE_CONTIG(req) == RMI_OP_MEM_CONTIG)) {


than having a field for a single bit values. I am happy to change
this if there is strong preference to the other.
The point is RMM-v2.0-bet3 expose RMI_OP_{MEM, MEM_NON}_CONTIG instead 
of true/false
to indicate if the requested memory blocks are physically contiguous or 
not. So the
expression 'if (RMI_DONATE_CONTIG(req) == RMI_OP_MEM_CONTIG)' is 
consistent to the
RMM-v2.0-bet3 spec.
Agree, but the values are intuitively assigned to indicate whether it is
1/0. I personally think if (RMI_DONATE_CONTIG(req)) is good enough. But
to be consistent with the spec, I will change them.


Cheers
Suzuki
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help