qtee_shmbridge.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2019, 2021 The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __QTEE_SHMBRIDGE_H__
  7. #define __QTEE_SHMBRIDGE_H__
  8. /* VMID and permission definitions */
  9. #include <soc/qcom/secure_buffer.h>
  10. /**
  11. * struct qtee_shm - info of shared memory allocated from the default bridge
  12. * @ paddr: physical address of the shm allocated from the default bridge
  13. * @ vaddr: virtual address of the shm
  14. * @ size: size of the shm
  15. */
  16. struct qtee_shm {
  17. phys_addr_t paddr;
  18. void *vaddr;
  19. size_t size;
  20. };
  21. /**
  22. * Check whether shmbridge mechanism is enabled in HYP or not
  23. *
  24. * return true when enabled, false when not enabled
  25. */
  26. bool qtee_shmbridge_is_enabled(void);
  27. /**
  28. * Check whether a bridge starting from paddr exists
  29. *
  30. * @ [IN] paddr: physical addr of the buffer
  31. *
  32. * return 0 or -EEXIST
  33. */
  34. int32_t qtee_shmbridge_query(phys_addr_t paddr);
  35. /**
  36. * Register paddr & size as a bridge, get bridge handle
  37. *
  38. * @ [IN] paddr: physical addr of the buffer to be turned into bridge
  39. * @ [IN] size: size of the bridge
  40. * @ [IN] ns_vmid_list: non-secure vmids array
  41. * @ [IN] ns_vm_perm_list: NS VM permission array
  42. * @ [IN] ns_vmid_num: number of NS VMIDs (at most 4)
  43. * @ [IN] tz_perm: TZ permission
  44. * @ [OUT] *handle: output shmbridge handle
  45. *
  46. * return success or error
  47. */
  48. int32_t qtee_shmbridge_register(
  49. phys_addr_t paddr,
  50. size_t size,
  51. uint32_t *ns_vmid_list,
  52. uint32_t *ns_vm_perm_list,
  53. uint32_t ns_vmid_num,
  54. uint32_t tz_perm,
  55. uint64_t *handle);
  56. /**
  57. * Deregister bridge
  58. *
  59. * @ [IN] handle: shmbridge handle
  60. *
  61. * return success or error
  62. */
  63. int32_t qtee_shmbridge_deregister(uint64_t handle);
  64. /**
  65. * Sub-allocate from default kernel bridge created by shmb driver
  66. *
  67. * @ [IN] size: size of the buffer to be sub-allocated from the bridge
  68. * @ [OUT] *shm: output qtee_shm structure with buffer paddr, vaddr and
  69. * size; returns ERR_PTR or NULL otherwise
  70. *
  71. * return success or error
  72. *
  73. * Note: This will allocate a cached buffer, so after a client allocates
  74. * a bridge buffer, it need to first flush cache with
  75. * "qtee_shmbridge_flush_shm_buf" before invoke scm_call to TZ,
  76. * and then invalidate cache with "qtee_shmbridge_inv_shm_buf"
  77. * after scm_call return.
  78. */
  79. int32_t qtee_shmbridge_allocate_shm(size_t size, struct qtee_shm *shm);
  80. /*
  81. * Free buffer that is sub-allocated from default kernel bridge
  82. *
  83. * @ [IN] shm: qtee_shm structure to be freed
  84. *
  85. */
  86. void qtee_shmbridge_free_shm(struct qtee_shm *shm);
  87. /*
  88. * cache clean operation for buffer sub-allocated from default bridge
  89. *
  90. * @ [IN] shm: qtee_shm, its cache to be cleaned
  91. *
  92. */
  93. void qtee_shmbridge_flush_shm_buf(struct qtee_shm *shm);
  94. /*
  95. * cache invalidation operation for buffer sub-allocated from default bridge
  96. *
  97. * @ [IN] shm: qtee_shm, its cache to be invalidated
  98. *
  99. */
  100. void qtee_shmbridge_inv_shm_buf(struct qtee_shm *shm);
  101. #endif /*__QTEE_SHMBRIDGE_H__*/