mem-buf-dev.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef MEM_BUF_PRIVATE_H
  7. #define MEM_BUF_PRIVATE_H
  8. #include <linux/device.h>
  9. #include <linux/dma-buf.h>
  10. #include <linux/mem-buf.h>
  11. #include <linux/slab.h>
  12. #include <linux/mm.h>
  13. #define MEM_BUF_MEMPARCEL_INVALID (U32_MAX)
  14. #define MEM_BUF_CAP_SUPPLIER BIT(0)
  15. #define MEM_BUF_CAP_CONSUMER BIT(1)
  16. #define MEM_BUF_CAP_DUAL (MEM_BUF_CAP_SUPPLIER | MEM_BUF_CAP_CONSUMER)
  17. extern unsigned char mem_buf_capability;
  18. extern struct device *mem_buf_dev;
  19. /* Hypervisor Interface */
  20. int mem_buf_assign_mem(u32 op, struct sg_table *sgt,
  21. struct mem_buf_lend_kernel_arg *arg);
  22. int mem_buf_unassign_mem(struct sg_table *sgt, int *src_vmids,
  23. unsigned int nr_acl_entries,
  24. gh_memparcel_handle_t hdl);
  25. int mem_buf_hyp_assign_table(struct sg_table *sgt, u32 *src_vmid, int source_nelems,
  26. int *dest_vmids, int *dest_perms, int dest_nelems);
  27. #ifdef CONFIG_QCOM_MEM_BUF_DEV_GH
  28. struct gh_acl_desc *mem_buf_vmid_perm_list_to_gh_acl(int *vmids, int *perms,
  29. unsigned int nr_acl_entries);
  30. struct gh_sgl_desc *mem_buf_sgt_to_gh_sgl_desc(struct sg_table *sgt);
  31. int mem_buf_map_mem_s2(u32 op, gh_memparcel_handle_t *__memparcel_hdl,
  32. struct gh_acl_desc *acl_desc, struct gh_sgl_desc **sgl_desc,
  33. int src_vmid);
  34. int mem_buf_unmap_mem_s2(gh_memparcel_handle_t memparcel_hdl);
  35. int mem_buf_gh_acl_desc_to_vmid_perm_list(struct gh_acl_desc *acl_desc,
  36. int **vmids, int **perms);
  37. size_t mem_buf_get_sgl_buf_size(struct gh_sgl_desc *sgl_desc);
  38. struct sg_table *dup_gh_sgl_desc_to_sgt(struct gh_sgl_desc *sgl_desc);
  39. struct gh_sgl_desc *dup_gh_sgl_desc(struct gh_sgl_desc *sgl_desc);
  40. int mem_buf_assign_mem_gunyah(u32 op, struct sg_table *sgt,
  41. struct mem_buf_lend_kernel_arg *arg);
  42. int mem_buf_unassign_mem_gunyah(gh_memparcel_handle_t memparcel_hdl);
  43. #else
  44. static inline struct gh_acl_desc *mem_buf_vmid_perm_list_to_gh_acl(int *vmids, int *perms,
  45. unsigned int nr_acl_entries)
  46. {
  47. return ERR_PTR(-EINVAL);
  48. }
  49. static inline struct gh_sgl_desc *mem_buf_sgt_to_gh_sgl_desc(struct sg_table *sgt)
  50. {
  51. return ERR_PTR(-EINVAL);
  52. }
  53. static inline int mem_buf_map_mem_s2(u32 op, gh_memparcel_handle_t *__memparcel_hdl,
  54. struct gh_acl_desc *acl_desc, struct gh_sgl_desc **__sgl_desc,
  55. int src_vmid)
  56. {
  57. return -EINVAL;
  58. }
  59. static inline int mem_buf_unmap_mem_s2(gh_memparcel_handle_t memparcel_hdl)
  60. {
  61. return -EINVAL;
  62. }
  63. static inline int mem_buf_gh_acl_desc_to_vmid_perm_list(struct gh_acl_desc *acl_desc,
  64. int **vmids, int **perms)
  65. {
  66. return -EINVAL;
  67. }
  68. static inline size_t mem_buf_get_sgl_buf_size(struct gh_sgl_desc *sgl_desc)
  69. {
  70. return 0;
  71. }
  72. static inline struct sg_table *dup_gh_sgl_desc_to_sgt(struct gh_sgl_desc *sgl_desc)
  73. {
  74. return ERR_PTR(-EINVAL);
  75. }
  76. static inline struct gh_sgl_desc *dup_gh_sgl_desc(struct gh_sgl_desc *sgl_desc)
  77. {
  78. return ERR_PTR(-EINVAL);
  79. }
  80. static inline int mem_buf_assign_mem_gunyah(u32 op, struct sg_table *sgt,
  81. struct mem_buf_lend_kernel_arg *arg)
  82. {
  83. return 0;
  84. }
  85. static inline int mem_buf_unassign_mem_gunyah(gh_memparcel_handle_t memparcel_hdl)
  86. {
  87. return 0;
  88. }
  89. #endif
  90. #endif