arm64.ffa.rst 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. .. SPDX-License-Identifier: GPL-2.0+
  2. Arm FF-A Support
  3. ================
  4. Summary
  5. -------
  6. FF-A stands for Firmware Framework for Arm A-profile processors.
  7. FF-A specifies interfaces that enable a pair of software execution environments aka partitions to
  8. communicate with each other. A partition could be a VM in the Normal or Secure world, an
  9. application in S-EL0, or a Trusted OS in S-EL1.
  10. The U-Boot FF-A support (the bus) implements the interfaces to communicate
  11. with partitions in the Secure world aka Secure partitions (SPs).
  12. The FF-A support specifically focuses on communicating with SPs that
  13. isolate portions of EFI runtime services that must run in a protected
  14. environment which is inaccessible by the Host OS or Hypervisor.
  15. Examples of such services are set/get variables.
  16. The FF-A support uses the SMC ABIs defined by the FF-A specification to:
  17. - Discover the presence of SPs of interest
  18. - Access an SP's service through communication protocols
  19. e.g. EFI MM communication protocol
  20. At this stage of development only EFI boot-time services are supported.
  21. Runtime support will be added in future developments.
  22. The U-Boot FF-A support provides the following parts:
  23. - A Uclass driver providing generic FF-A methods.
  24. - An Arm FF-A device driver providing Arm-specific methods and reusing the Uclass methods.
  25. - A sandbox emulator for Arm FF-A, emulates the FF-A side of the Secure World and provides
  26. FF-A ABIs inspection methods.
  27. - An FF-A sandbox device driver for FF-A communication with the emulated Secure World.
  28. The driver leverages the FF-A Uclass to establish FF-A communication.
  29. - Sandbox FF-A test cases.
  30. FF-A and SMC specifications
  31. -------------------------------------------
  32. The current implementation of the U-Boot FF-A support relies on
  33. `FF-A v1.0 specification`_ and uses SMC32 calling convention which
  34. means using the first 32-bit data of the Xn registers.
  35. At this stage we only need the FF-A v1.0 features.
  36. The FF-A support has been tested with OP-TEE which supports SMC32 calling
  37. convention.
  38. Hypervisors are supported if they are configured to trap SMC calls.
  39. The FF-A support uses 64-bit registers as per `SMC Calling Convention v1.2 specification`_.
  40. Supported hardware
  41. --------------------------------
  42. Aarch64 plaforms
  43. Configuration
  44. ----------------------
  45. CONFIG_ARM_FFA_TRANSPORT
  46. Enables the FF-A support. Turn this on if you want to use FF-A
  47. communication.
  48. When using an Arm 64-bit platform, the Arm FF-A driver will be used.
  49. When using sandbox, the sandbox FF-A emulator and FF-A sandbox driver will be used.
  50. FF-A ABIs under the hood
  51. ---------------------------------------
  52. Invoking an FF-A ABI involves providing to the secure world/hypervisor the
  53. expected arguments from the ABI.
  54. On an Arm 64-bit platform, the ABI arguments are stored in x0 to x7 registers.
  55. Then, an SMC instruction is executed.
  56. At the secure side level or hypervisor the ABI is handled at a higher exception
  57. level and the arguments are read and processed.
  58. The response is put back through x0 to x7 registers and control is given back
  59. to the U-Boot Arm FF-A driver (non-secure world).
  60. The driver reads the response and processes it accordingly.
  61. This methodology applies to all the FF-A ABIs.
  62. FF-A bus discovery on Arm 64-bit platforms
  63. ---------------------------------------------
  64. When CONFIG_ARM_FFA_TRANSPORT is enabled, the FF-A bus is considered as
  65. an architecture feature and discovered using ARM_SMCCC_FEATURES mechanism.
  66. This discovery mechanism is performed by the PSCI driver.
  67. The PSCI driver comes with a PSCI device tree node which is the root node for all
  68. architecture features including FF-A bus.
  69. ::
  70. => dm tree
  71. Class Index Probed Driver Name
  72. -----------------------------------------------------------
  73. firmware 0 [ + ] psci |-- psci
  74. ffa 0 [ ] arm_ffa | `-- arm_ffa
  75. The PSCI driver is bound to the PSCI device and when probed it tries to discover
  76. the architecture features by calling a callback the features drivers provide.
  77. In case of FF-A, the callback is arm_ffa_is_supported() which tries to discover the
  78. FF-A framework by querying the FF-A framework version from secure world using
  79. FFA_VERSION ABI. When discovery is successful, the ARM_SMCCC_FEATURES
  80. mechanism creates a U-Boot device for the FF-A bus and binds the Arm FF-A driver
  81. with the device using device_bind_driver().
  82. At this stage the FF-A bus is registered with the DM and can be interacted with using
  83. the DM APIs.
  84. Clients are able to probe then use the FF-A bus by calling uclass_first_device().
  85. Please refer to the armffa command implementation as an example of how to probe
  86. and interact with the FF-A bus.
  87. When calling uclass_first_device(), the FF-A driver is probed and ends up calling
  88. ffa_do_probe() provided by the Uclass which does the following:
  89. - saving the FF-A framework version in uc_priv
  90. - querying from secure world the u-boot endpoint ID
  91. - querying from secure world the supported features of FFA_RXTX_MAP
  92. - mapping the RX/TX buffers
  93. - querying from secure world all the partitions information
  94. When one of the above actions fails, probing fails and the driver stays not active
  95. and can be probed again if needed.
  96. Requirements for clients
  97. -------------------------------------
  98. When using the FF-A bus with EFI, clients must query the SPs they are looking for
  99. during EFI boot-time mode using the service UUID.
  100. The RX/TX buffers are only available at EFI boot-time. Querying partitions is
  101. done at boot time and data is cached for future use.
  102. RX/TX buffers should be unmapped before EFI runtime mode starts.
  103. The driver provides a bus operation for that called ffa_rxtx_unmap().
  104. The user should call ffa_rxtx_unmap() to unmap the RX/TX buffers when required
  105. (e.g: at efi_exit_boot_services()).
  106. The Linux kernel allocates its own RX/TX buffers. To be able to register these kernel buffers
  107. with secure world, the U-Boot's RX/TX buffers should be unmapped before EFI runtime starts.
  108. When invoking FF-A direct messaging, clients should specify which ABI protocol
  109. they want to use (32-bit vs 64-bit). Selecting the protocol means using
  110. the 32-bit or 64-bit version of FFA_MSG_SEND_DIRECT_{REQ, RESP}.
  111. The calling convention between U-Boot and the secure world stays the same: SMC32.
  112. Requirements for user drivers
  113. -------------------------------------
  114. Users who want to implement their custom FF-A device driver while reusing the FF-A Uclass can do so
  115. by implementing their own invoke_ffa_fn() in the user driver.
  116. The bus driver layer
  117. ------------------------------
  118. FF-A support comes on top of the SMCCC layer and is implemented by the FF-A Uclass drivers/firmware/arm-ffa/arm-ffa-uclass.c
  119. The following features are provided:
  120. - Support for the 32-bit version of the following ABIs:
  121. - FFA_VERSION
  122. - FFA_ID_GET
  123. - FFA_FEATURES
  124. - FFA_PARTITION_INFO_GET
  125. - FFA_RXTX_UNMAP
  126. - FFA_RX_RELEASE
  127. - FFA_RUN
  128. - FFA_ERROR
  129. - FFA_SUCCESS
  130. - FFA_INTERRUPT
  131. - FFA_MSG_SEND_DIRECT_REQ
  132. - FFA_MSG_SEND_DIRECT_RESP
  133. - Support for the 64-bit version of the following ABIs:
  134. - FFA_RXTX_MAP
  135. - FFA_MSG_SEND_DIRECT_REQ
  136. - FFA_MSG_SEND_DIRECT_RESP
  137. - Processing the received data from the secure world/hypervisor and caching it
  138. - Hiding from upper layers the FF-A protocol and registers details. Upper
  139. layers focus on exchanged data, FF-A support takes care of how to transport
  140. that to the secure world/hypervisor using FF-A
  141. - FF-A support provides driver operations to be used by upper layers:
  142. - ffa_partition_info_get
  143. - ffa_sync_send_receive
  144. - ffa_rxtx_unmap
  145. - FF-A bus discovery makes sure FF-A framework is responsive and compatible
  146. with the driver
  147. - FF-A bus can be compiled and used without EFI
  148. Relationship between the sandbox emulator and the FF-A device
  149. ---------------------------------------------------------------
  150. ::
  151. => dm tree
  152. Class Index Probed Driver Name
  153. -----------------------------------------------------------
  154. ffa_emul 0 [ + ] sandbox_ffa_emul `-- arm-ffa-emul
  155. ffa 0 [ ] sandbox_arm_ffa `-- sandbox-arm-ffa
  156. The armffa command
  157. -----------------------------------
  158. armffa is a command showcasing how to use the FF-A bus and how to invoke the driver operations.
  159. Please refer the command documentation at :doc:`../usage/cmd/armffa`
  160. Example of boot logs with FF-A enabled
  161. --------------------------------------
  162. For example, when using FF-A with Corstone-1000, debug logs enabled, the output is as follows:
  163. ::
  164. U-Boot 2023.01 (May 10 2023 - 11:08:07 +0000) corstone1000 aarch64
  165. DRAM: 2 GiB
  166. Arm FF-A framework discovery
  167. FF-A driver 1.0
  168. FF-A framework 1.0
  169. FF-A versions are compatible
  170. ...
  171. FF-A driver 1.0
  172. FF-A framework 1.0
  173. FF-A versions are compatible
  174. EFI: MM partition ID 0x8003
  175. ...
  176. EFI stub: Booting Linux Kernel...
  177. ...
  178. Linux version 6.1.9-yocto-standard (oe-user@oe-host) (aarch64-poky-linux-musl-gcc (GCC) 12.2.0, GNU ld (GNU Binutils) 2.40.202301193
  179. Machine model: ARM Corstone1000 FPGA MPS3 board
  180. Contributors
  181. ------------
  182. * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
  183. .. _`FF-A v1.0 specification`: https://documentation-service.arm.com/static/5fb7e8a6ca04df4095c1d65e
  184. .. _`SMC Calling Convention v1.2 specification`: https://documentation-service.arm.com/static/5f8edaeff86e16515cdbe4c6