ubwcp.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. * @param dmabuf : ptr to the dma buf
  28. * @param attr : buffer attributes to set
  29. *
  30. * @return int : 0 on success, otherwise error code
  31. */
  32. int ubwcp_set_buf_attrs(struct dma_buf *dmabuf, struct ubwcp_buffer_attrs *attr);
  33. /**
  34. * Get the currently configured attributes for the buffer
  35. *
  36. * @param dmabuf : ptr to the dma buf
  37. * @param attr : pointer to location where image attributes
  38. * for this buffer will be copied to.
  39. *
  40. * @return int : 0 on success, otherwise error code
  41. */
  42. int ubwcp_get_buf_attrs(struct dma_buf *dmabuf, struct ubwcp_buffer_attrs *attr);
  43. /**
  44. * Set permanent range translation for the buffer. This reserves
  45. * ubwcp address translation resources for the buffer until free
  46. * is called. This may speed up lock()/unlock() calls as they
  47. * don't need to configure address translations for the buffer.
  48. *
  49. * @param dmabuf : ptr to the dma buf
  50. * @param enable : true == enable, false == disable
  51. *
  52. * @return int : 0 on success, otherwise error code
  53. */
  54. int ubwcp_set_perm_range_translation(struct dma_buf *dmabuf, bool enable);
  55. enum ubwcp_error {
  56. UBWCP_ENCODE_ERROR = 0,
  57. UBWCP_DECODE_ERROR,
  58. UBWCP_RANGE_TRANSLATION_ERROR,
  59. UBWCP_SMMU_FAULT,
  60. UBWCP_UNKNOWN_ERROR,
  61. };
  62. enum iommu_cb_id {
  63. UBWCP_DESC_CB_ID = 0,
  64. UBWCP_BUF_CB_ID,
  65. UBWCP_UNKNOWN_CB_ID,
  66. };
  67. struct ubwcp_enc_err_info {
  68. struct dma_buf *dmabuf;
  69. phys_addr_t ula_pa;
  70. };
  71. struct ubwcp_dec_err_info {
  72. struct dma_buf *dmabuf;
  73. phys_addr_t ula_pa;
  74. };
  75. struct ubwcp_translation_err_info {
  76. struct dma_buf *dmabuf;
  77. phys_addr_t ula_pa;
  78. bool read;
  79. };
  80. struct ubwcp_smmu_fault_err_info {
  81. struct dma_buf *dmabuf;
  82. unsigned long iova;
  83. enum iommu_cb_id iommu_dev_id;
  84. int iommu_fault_flags;
  85. };
  86. struct ubwcp_err_info {
  87. enum ubwcp_error err_code;
  88. union {
  89. struct ubwcp_enc_err_info enc_err;
  90. struct ubwcp_dec_err_info dec_err;
  91. struct ubwcp_translation_err_info translation_err;
  92. struct ubwcp_smmu_fault_err_info smmu_err;
  93. };
  94. };
  95. typedef void (*ubwcp_error_handler_t)(struct ubwcp_err_info *err, void *data);
  96. /*
  97. * Register an error handler
  98. *
  99. * @param client_id : not currently supported (pass in -1)
  100. * @param handler : the error handler function which will be called when an
  101. * error occurs
  102. * @param data : data pointer provided with the error handler function
  103. *
  104. * @return int : 0 on success, otherwise error code
  105. */
  106. int ubwcp_register_error_handler(u32 client_id, ubwcp_error_handler_t handler,
  107. void *data);
  108. /*
  109. * Unregister an error handler
  110. *
  111. * @param client_id : client id of handler to unregister (pass in -1)
  112. *
  113. * @return int : 0 on success, otherwise error code
  114. */
  115. int ubwcp_unregister_error_handler(u32 client_id);
  116. #endif /* __UBWCP_H_ */