ubwcp.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef __UBWCP_H_
  6. #define __UBWCP_H_
  7. #include <linux/types.h>
  8. #include <linux/dma-buf.h>
  9. #include "../uapi/ubwcp_ioctl.h"
  10. typedef int (*configure_mmap)(struct dma_buf *dmabuf, bool linear, phys_addr_t ula_pa_addr,
  11. size_t ula_pa_size);
  12. /**
  13. * Get UBWCP hardware version
  14. *
  15. * @param ver : ptr to ver struct where hw version will be
  16. * copied
  17. *
  18. * @return int : 0 on success, otherwise error code
  19. */
  20. int ubwcp_get_hw_version(struct ubwcp_ioctl_hw_version *ver);
  21. /**
  22. * Configures ubwcp buffer with the provided buffer image
  23. * attributes. This call must be done at least once before
  24. * ubwcp_lock(). Attributes can be configured multiple times,
  25. * but only during unlocked state.
  26. *
  27. * Upon error, buffer will be in undefined state.
  28. * There is no guarantee that previously set attributes will be retained.
  29. * Caller could retry set attributes, but must not reuse buffer
  30. * until a successful set attribute call is done.
  31. *
  32. * @param dmabuf : ptr to the dma buf
  33. * @param attr : buffer attributes to set
  34. *
  35. * @return int : 0 on success, otherwise error code
  36. */
  37. int ubwcp_set_buf_attrs(struct dma_buf *dmabuf, struct ubwcp_buffer_attrs *attr);
  38. /**
  39. * Get the currently configured attributes for the buffer
  40. *
  41. * @param dmabuf : ptr to the dma buf
  42. * @param attr : pointer to location where image attributes
  43. * for this buffer will be copied to.
  44. *
  45. * @return int : 0 on success, otherwise error code
  46. */
  47. int ubwcp_get_buf_attrs(struct dma_buf *dmabuf, struct ubwcp_buffer_attrs *attr);
  48. /**
  49. * Set permanent range translation for the buffer. This reserves
  50. * ubwcp address translation resources for the buffer until free
  51. * is called. This may speed up lock()/unlock() calls as they
  52. * don't need to configure address translations for the buffer.
  53. *
  54. * @param dmabuf : ptr to the dma buf
  55. * @param enable : true == enable, false == disable
  56. *
  57. * @return int : 0 on success, otherwise error code
  58. */
  59. int ubwcp_set_perm_range_translation(struct dma_buf *dmabuf, bool enable);
  60. enum ubwcp_error {
  61. UBWCP_ENCODE_ERROR = 0,
  62. UBWCP_DECODE_ERROR,
  63. UBWCP_RANGE_TRANSLATION_ERROR,
  64. UBWCP_SMMU_FAULT,
  65. UBWCP_UNKNOWN_ERROR,
  66. };
  67. enum iommu_cb_id {
  68. UBWCP_DESC_CB_ID = 0,
  69. UBWCP_BUF_CB_ID,
  70. UBWCP_UNKNOWN_CB_ID,
  71. };
  72. struct ubwcp_enc_err_info {
  73. struct dma_buf *dmabuf;
  74. phys_addr_t ula_pa;
  75. };
  76. struct ubwcp_dec_err_info {
  77. struct dma_buf *dmabuf;
  78. phys_addr_t ula_pa;
  79. };
  80. struct ubwcp_translation_err_info {
  81. struct dma_buf *dmabuf;
  82. phys_addr_t ula_pa;
  83. bool read;
  84. };
  85. struct ubwcp_smmu_fault_err_info {
  86. struct dma_buf *dmabuf;
  87. unsigned long iova;
  88. enum iommu_cb_id iommu_dev_id;
  89. int iommu_fault_flags;
  90. };
  91. struct ubwcp_err_info {
  92. enum ubwcp_error err_code;
  93. union {
  94. struct ubwcp_enc_err_info enc_err;
  95. struct ubwcp_dec_err_info dec_err;
  96. struct ubwcp_translation_err_info translation_err;
  97. struct ubwcp_smmu_fault_err_info smmu_err;
  98. };
  99. };
  100. typedef void (*ubwcp_error_handler_t)(struct ubwcp_err_info *err, void *data);
  101. /*
  102. * Register an error handler
  103. *
  104. * @param client_id : not currently supported (pass in -1)
  105. * @param handler : the error handler function which will be called when an
  106. * error occurs
  107. * @param data : data pointer provided with the error handler function
  108. *
  109. * @return int : 0 on success, otherwise error code
  110. */
  111. int ubwcp_register_error_handler(u32 client_id, ubwcp_error_handler_t handler,
  112. void *data);
  113. /*
  114. * Unregister an error handler
  115. *
  116. * @param client_id : client id of handler to unregister (pass in -1)
  117. *
  118. * @return int : 0 on success, otherwise error code
  119. */
  120. int ubwcp_unregister_error_handler(u32 client_id);
  121. #endif /* __UBWCP_H_ */