arm-ffa.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
  4. *
  5. * Authors:
  6. * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
  7. */
  8. #include <common.h>
  9. #include <arm_ffa.h>
  10. #include <arm_ffa_priv.h>
  11. #include <dm.h>
  12. #include <log.h>
  13. #include <asm/global_data.h>
  14. #include <dm/device-internal.h>
  15. #include <linux/errno.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. /**
  18. * invoke_ffa_fn() - SMC wrapper
  19. * @args: FF-A ABI arguments to be copied to Xn registers
  20. * @res: FF-A ABI return data to be copied from Xn registers
  21. *
  22. * Calls low level SMC assembly function
  23. */
  24. void invoke_ffa_fn(ffa_value_t args, ffa_value_t *res)
  25. {
  26. arm_smccc_1_2_smc(&args, res);
  27. }
  28. /**
  29. * arm_ffa_discover() - perform FF-A discovery
  30. * @dev: The Arm FF-A bus device (arm_ffa)
  31. * Try to discover the FF-A framework. Discovery is performed by
  32. * querying the FF-A framework version from secure world using the FFA_VERSION ABI.
  33. * Return:
  34. *
  35. * true on success. Otherwise, false.
  36. */
  37. static bool arm_ffa_discover(struct udevice *dev)
  38. {
  39. int ret;
  40. log_debug("Arm FF-A framework discovery\n");
  41. ret = ffa_get_version_hdlr(dev);
  42. if (ret)
  43. return false;
  44. return true;
  45. }
  46. /**
  47. * arm_ffa_is_supported() - FF-A bus discovery callback
  48. * @invoke_fn: legacy SMC invoke function (not used)
  49. *
  50. * Perform FF-A discovery by calling arm_ffa_discover().
  51. * Discovery is performed by querying the FF-A framework version from
  52. * secure world using the FFA_VERSION ABI.
  53. *
  54. * The FF-A driver is registered as an SMCCC feature driver. So, features discovery
  55. * callbacks are called by the PSCI driver (PSCI device is the SMCCC features
  56. * root device).
  57. *
  58. * The FF-A driver supports the SMCCCv1.2 extended input/output registers.
  59. * So, the legacy SMC invocation is not used.
  60. *
  61. * Return:
  62. *
  63. * 0 on success. Otherwise, failure
  64. */
  65. static bool arm_ffa_is_supported(void (*invoke_fn)(ulong a0, ulong a1,
  66. ulong a2, ulong a3,
  67. ulong a4, ulong a5,
  68. ulong a6, ulong a7,
  69. struct arm_smccc_res *res))
  70. {
  71. return arm_ffa_discover(NULL);
  72. }
  73. /* Arm FF-A driver operations */
  74. static const struct ffa_bus_ops ffa_ops = {
  75. .partition_info_get = ffa_get_partitions_info_hdlr,
  76. .sync_send_receive = ffa_msg_send_direct_req_hdlr,
  77. .rxtx_unmap = ffa_unmap_rxtx_buffers_hdlr,
  78. };
  79. /* Registering the FF-A driver as an SMCCC feature driver */
  80. ARM_SMCCC_FEATURE_DRIVER(arm_ffa) = {
  81. .driver_name = FFA_DRV_NAME,
  82. .is_supported = arm_ffa_is_supported,
  83. };
  84. /* Declaring the FF-A driver under UCLASS_FFA */
  85. U_BOOT_DRIVER(arm_ffa) = {
  86. .name = FFA_DRV_NAME,
  87. .id = UCLASS_FFA,
  88. .flags = DM_REMOVE_OS_PREPARE,
  89. .ops = &ffa_ops,
  90. };