rm.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2020 NXP
  4. *
  5. * File containing client-side RPC functions for the RM service. These
  6. * function are ported to clients that communicate to the SC.
  7. */
  8. #include <linux/firmware/imx/svc/rm.h>
  9. struct imx_sc_msg_rm_rsrc_owned {
  10. struct imx_sc_rpc_msg hdr;
  11. u16 resource;
  12. } __packed __aligned(4);
  13. /*
  14. * This function check @resource is owned by current partition or not
  15. *
  16. * @param[in] ipc IPC handle
  17. * @param[in] resource resource the control is associated with
  18. *
  19. * @return Returns 0 for not owned and 1 for owned.
  20. */
  21. bool imx_sc_rm_is_resource_owned(struct imx_sc_ipc *ipc, u16 resource)
  22. {
  23. struct imx_sc_msg_rm_rsrc_owned msg;
  24. struct imx_sc_rpc_msg *hdr = &msg.hdr;
  25. hdr->ver = IMX_SC_RPC_VERSION;
  26. hdr->svc = IMX_SC_RPC_SVC_RM;
  27. hdr->func = IMX_SC_RM_FUNC_IS_RESOURCE_OWNED;
  28. hdr->size = 2;
  29. msg.resource = resource;
  30. /*
  31. * SCU firmware only returns value 0 or 1
  32. * for resource owned check which means not owned or owned.
  33. * So it is always successful.
  34. */
  35. imx_scu_call_rpc(ipc, &msg, true);
  36. return hdr->func;
  37. }
  38. EXPORT_SYMBOL(imx_sc_rm_is_resource_owned);
  39. struct imx_sc_msg_rm_get_resource_owner {
  40. struct imx_sc_rpc_msg hdr;
  41. union {
  42. struct {
  43. u16 resource;
  44. } req;
  45. struct {
  46. u8 val;
  47. } resp;
  48. } data;
  49. } __packed __aligned(4);
  50. /*
  51. * This function get @resource partition number
  52. *
  53. * @param[in] ipc IPC handle
  54. * @param[in] resource resource the control is associated with
  55. * @param[out] pt pointer to return the partition number
  56. *
  57. * @return Returns 0 for success and < 0 for errors.
  58. */
  59. int imx_sc_rm_get_resource_owner(struct imx_sc_ipc *ipc, u16 resource, u8 *pt)
  60. {
  61. struct imx_sc_msg_rm_get_resource_owner msg;
  62. struct imx_sc_rpc_msg *hdr = &msg.hdr;
  63. int ret;
  64. hdr->ver = IMX_SC_RPC_VERSION;
  65. hdr->svc = IMX_SC_RPC_SVC_RM;
  66. hdr->func = IMX_SC_RM_FUNC_GET_RESOURCE_OWNER;
  67. hdr->size = 2;
  68. msg.data.req.resource = resource;
  69. ret = imx_scu_call_rpc(ipc, &msg, true);
  70. if (ret)
  71. return ret;
  72. if (pt)
  73. *pt = msg.data.resp.val;
  74. return 0;
  75. }
  76. EXPORT_SYMBOL(imx_sc_rm_get_resource_owner);