qcom_dma_heap.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _QCOM_DMA_HEAP_H
  7. #define _QCOM_DMA_HEAP_H
  8. #include <linux/bits.h>
  9. #include <linux/bitfield.h>
  10. #include <linux/dma-buf.h>
  11. #include <linux/qcom_dma_heap_dt_constants.h>
  12. #include <linux/err.h>
  13. /* Heap flags */
  14. #define QCOM_DMA_HEAP_FLAG_CACHED BIT(1)
  15. #define QCOM_DMA_HEAP_FLAG_CP_TRUSTED_VM BIT(15)
  16. #define QCOM_DMA_HEAP_FLAG_CP_TZ BIT(16)
  17. #define QCOM_DMA_HEAP_FLAG_CP_TOUCH BIT(17)
  18. #define QCOM_DMA_HEAP_FLAG_CP_BITSTREAM BIT(18)
  19. #define QCOM_DMA_HEAP_FLAG_CP_PIXEL BIT(19)
  20. #define QCOM_DMA_HEAP_FLAG_CP_NON_PIXEL BIT(20)
  21. #define QCOM_DMA_HEAP_FLAG_CP_CAMERA BIT(21)
  22. #define QCOM_DMA_HEAP_FLAG_CP_HLOS BIT(22)
  23. #define QCOM_DMA_HEAP_FLAG_CP_SPSS_SP BIT(23)
  24. #define QCOM_DMA_HEAP_FLAG_CP_SPSS_SP_SHARED BIT(24)
  25. #define QCOM_DMA_HEAP_FLAG_CP_SEC_DISPLAY BIT(25)
  26. #define QCOM_DMA_HEAP_FLAG_CP_APP BIT(26)
  27. #define QCOM_DMA_HEAP_FLAG_CP_CAMERA_PREVIEW BIT(27)
  28. #define QCOM_DMA_HEAP_FLAG_CP_MSS_MSA BIT(28)
  29. #define QCOM_DMA_HEAP_FLAG_CP_CDSP BIT(29)
  30. #define QCOM_DMA_HEAP_FLAG_CP_SPSS_HLOS_SHARED BIT(30)
  31. #define QCOM_DMA_HEAP_FLAGS_CP_MASK GENMASK(30, 15)
  32. #define QCOM_DMA_HEAP_FLAG_SECURE BIT(31)
  33. bool qcom_is_dma_buf_file(struct file *file);
  34. struct dma_buf_heap_prefetch_region {
  35. u64 size;
  36. struct dma_heap *heap;
  37. };
  38. int qcom_secure_system_heap_prefetch(struct dma_buf_heap_prefetch_region *regions,
  39. size_t nr_regions);
  40. int qcom_secure_system_heap_drain(struct dma_buf_heap_prefetch_region *regions,
  41. size_t nr_regions);
  42. /**
  43. * dma_buf_heap_hyp_assign - wrapper function for hyp-assigning a dma_buf
  44. * @buf: dma_buf to hyp-assign away from HLOS
  45. * @dest_vmids: array of QCOM_DMA_HEAP_FLAG VMIDs (as defined above)
  46. * @dest_perms: array of PERM_READ/PERM_WRITE/PERM_EXEC permission bits (as
  47. * defined in include/soc/qcom/secure_buffer.h), such that
  48. * dest_perms[i] specifies the permissions for VMID dest_vmids[i]
  49. * @dest_nelems: number of elements in dest_vmids and dest_perms
  50. *
  51. * Return: Temporarily return -EINVAL whilst the functon isn't present. Otherwise, return
  52. * 0 on success, or a negative value returned by hyp_assign_table() on failure.
  53. */
  54. static inline int dma_buf_heap_hyp_assign(struct dma_buf *buf, int *dest_vmids, int *dest_perms,
  55. int dest_nelems)
  56. {
  57. return -EINVAL;
  58. }
  59. /**
  60. * dma_buf_heap_hyp_unassign - wrapper function that hyp-assigns a dma_buf back to HLOS
  61. * @buf: dma_buf to hyp-assign back to HLOS
  62. *
  63. * This function takes a dma_buf, and re-assigns it to HLOS with RWX permissions (at the
  64. * S2 level). The end-points to which the buffer was assigned to are tracked by the flags
  65. * kept in the msm_heap_helper_buffer->flags field (the helper_buffer is accesed through
  66. * dma_buf->priv), so the corresponding VMIDs don't need to be supplied as arguments.
  67. *
  68. * Return: Temporarily return -EINVAL whilst the functon isn't present. Otherwise, return
  69. * 0 on success, or a negative value returned by hyp_assign_table() on failure.
  70. */
  71. static inline int dma_buf_heap_hyp_unassign(struct dma_buf *buf)
  72. {
  73. return -EINVAL;
  74. }
  75. #endif /* _QCOM_DMA_HEAP_H */