sandbox_ffa.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 <dm.h>
  11. #include <log.h>
  12. #include <asm/global_data.h>
  13. #include <asm/sandbox_arm_ffa_priv.h>
  14. #include <dm/device-internal.h>
  15. #include <linux/errno.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. /**
  18. * sandbox_ffa_discover() - perform sandbox FF-A discovery
  19. * @dev: The sandbox FF-A bus device
  20. * Try to discover the FF-A framework. Discovery is performed by
  21. * querying the FF-A framework version from secure world using the FFA_VERSION ABI.
  22. * Return:
  23. *
  24. * 0 on success. Otherwise, failure
  25. */
  26. static int sandbox_ffa_discover(struct udevice *dev)
  27. {
  28. int ret;
  29. struct udevice *emul;
  30. log_debug("Emulated FF-A framework discovery\n");
  31. ret = ffa_emul_find(dev, &emul);
  32. if (ret) {
  33. log_err("Cannot find FF-A emulator\n");
  34. return ret;
  35. }
  36. ret = ffa_get_version_hdlr(dev);
  37. if (ret)
  38. return ret;
  39. return 0;
  40. }
  41. /**
  42. * sandbox_ffa_probe() - The sandbox FF-A driver probe function
  43. * @dev: the sandbox-arm-ffa device
  44. * Save the emulator device in uc_priv.
  45. * Return:
  46. *
  47. * 0 on success.
  48. */
  49. static int sandbox_ffa_probe(struct udevice *dev)
  50. {
  51. int ret;
  52. struct ffa_priv *uc_priv = dev_get_uclass_priv(dev);
  53. ret = uclass_first_device_err(UCLASS_FFA_EMUL, &uc_priv->emul);
  54. if (ret) {
  55. log_err("Cannot find FF-A emulator\n");
  56. return ret;
  57. }
  58. return 0;
  59. }
  60. /**
  61. * sandbox_ffa_bind() - The sandbox FF-A driver bind function
  62. * @dev: the sandbox-arm-ffa device
  63. * Try to discover the emulated FF-A bus.
  64. * Return:
  65. *
  66. * 0 on success.
  67. */
  68. static int sandbox_ffa_bind(struct udevice *dev)
  69. {
  70. int ret;
  71. ret = sandbox_ffa_discover(dev);
  72. if (ret)
  73. return ret;
  74. return 0;
  75. }
  76. /* Sandbox Arm FF-A emulator operations */
  77. static const struct ffa_bus_ops sandbox_ffa_ops = {
  78. .partition_info_get = ffa_get_partitions_info_hdlr,
  79. .sync_send_receive = ffa_msg_send_direct_req_hdlr,
  80. .rxtx_unmap = ffa_unmap_rxtx_buffers_hdlr,
  81. };
  82. static const struct udevice_id sandbox_ffa_id[] = {
  83. { "sandbox,arm-ffa", 0 },
  84. { },
  85. };
  86. /* Declaring the sandbox FF-A driver under UCLASS_FFA */
  87. U_BOOT_DRIVER(sandbox_arm_ffa) = {
  88. .name = "sandbox_arm_ffa",
  89. .of_match = sandbox_ffa_id,
  90. .id = UCLASS_FFA,
  91. .bind = sandbox_ffa_bind,
  92. .probe = sandbox_ffa_probe,
  93. .ops = &sandbox_ffa_ops,
  94. };