public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] ArmCallSmc() and SMCCC specification
@ 2024-05-31  7:14 Marcin Juszkiewicz
  2024-06-03 16:47 ` Leif Lindholm
  0 siblings, 1 reply; 4+ messages in thread
From: Marcin Juszkiewicz @ 2024-05-31  7:14 UTC (permalink / raw)
  To: devel; +Cc: Leif Lindholm, Ard Biesheuvel, Sami Mujawar

EDK2/ArmPkg/Library/ArmSmcLib has code to do SMC calls.

There are ArmCallSmc[0-3]() functions for up to 3 arguments/results and 
ArmCallSmc() function which can use 7 arguments and get 4 results back.

This implementation looks like version B (Nov 2016) of SMCCC 
specification [1] with one more register used.

1. https://developer.arm.com/documentation/den0028/b/


In 2020 we got version C of spec (and then D, E, F) which allows to use 
more registers:

 > Allow R4—R7 (SMC32/HVC32) to be used as result registers.
 > Allow X8—X17 to be used as parameter registers in SMC64/HVC64.
 > Allow X4—X17 to be used as result registers in SMC64/HVC64.

And I started to wonder how to update EDK2 to newer version of SMCCC 
spec as one of in-progress QemuSbsa SMC calls may return more than 4 values.


ARM_SMC_ARGS in ArmSmcLib.h can be expanded to handle up to Arg17 in an 
easy way and guarded by "#if defined(__aarch64__)" to not change it on 
Arm32.


Then ArmCallSmc() in {AArch64,Arm}/ArmSmc.S needs changes. But here it 
gets tricky.

On Arm we preserve r4-r8 and restore them after call like spec says. 
Which we do not do on AArch64 as version B of spec did not required that 
(and this changed in version C).

If we start handling more than 4 results then we need to know how many 
results are expected and restore rest of r4-r7/x4-x17 registers:

 > When an SMC32/HVC32 call is made from AArch32:
 > • A Function Identifier is passed in register R0.
 > • Arguments are passed in registers R1-R7.
 > • Results are returned in R0-R7.
 > • The registers R4-R7 must be preserved unless they contain results,
 >   as specified in the function definition.
 > • Registers R8-R14 are saved by the function that is called, and must
 >   be preserved over the SMC or HVC call.
 >
 > When an SMC64/HVC64 call is made from AArch64:
 > • A Function Identifier is passed in register W0.
 > • Arguments are passed in registers X1-X17.
 > • Results are returned in X0-X17.
 > • Registers X4-X17 must be preserved unless they contain results, as
 >   specified in the function definition.
 > • Registers X18-X30 and stack pointers SP_EL0 and SP_ELx are saved by 
 >   the function that is called, and must be preserved over the SMC or
 >   HVC call.


 From what I saw in both edk2/ and edk2-platforms/ most of code uses 
ArmCallSmc() function with ARM_SMC_ARGS structure populared with 
arguments. ArmCallSmc[0-3]() are used by Smbios, Psci and QemuSbsa code 
only.


Now the question is: how to handle change?

We could add ArmCallSmc[4-17] but that name only tells how many 
arguments we pass to SMC call, not how many results we expect. Or should 
we add NumberOfResults argument to ArmCallSmc() to know which registers 
we should preserve and which are results? And how complicated this 
assembly function will become?


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119408): https://edk2.groups.io/g/devel/message/119408
Mute This Topic: https://groups.io/mt/106403741/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-04 13:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-31  7:14 [edk2-devel] ArmCallSmc() and SMCCC specification Marcin Juszkiewicz
2024-06-03 16:47 ` Leif Lindholm
2024-06-04 12:37   ` Marcin Juszkiewicz
2024-06-04 13:33     ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox