hw_fence_drv_utils.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef __HW_FENCE_DRV_UTILS_H
  6. #define __HW_FENCE_DRV_UTILS_H
  7. /**
  8. * HW_FENCE_MAX_CLIENT_TYPE_STATIC:
  9. * Total number of client types without configurable number of sub-clients (GFX, DPU, VAL)
  10. */
  11. #define HW_FENCE_MAX_CLIENT_TYPE_STATIC 3
  12. /**
  13. * HW_FENCE_MAX_CLIENT_TYPE_CONFIGURABLE:
  14. * Maximum number of client types with configurable number of sub-clients (e.g. IPE, VPU, IFE)
  15. */
  16. #define HW_FENCE_MAX_CLIENT_TYPE_CONFIGURABLE 10
  17. /**
  18. * HW_FENCE_MAX_STATIC_CLIENTS_INDEX:
  19. * Maximum number of static clients, i.e. clients without configurable numbers of sub-clients
  20. */
  21. #define HW_FENCE_MAX_STATIC_CLIENTS_INDEX HW_FENCE_CLIENT_ID_IPE
  22. /**
  23. * enum hw_fence_mem_reserve - Types of reservations for the carved-out memory.
  24. * HW_FENCE_MEM_RESERVE_CTRL_QUEUE: Reserve memory for the ctrl rx/tx queues.
  25. * HW_FENCE_MEM_RESERVE_LOCKS_REGION: Reserve memory for the per-client locks memory region.
  26. * HW_FENCE_MEM_RESERVE_TABLE: Reserve memory for the hw-fences global table.
  27. * HW_FENCE_MEM_RESERVE_CLIENT_QUEUE: Reserve memory per-client for the rx/tx queues.
  28. * HW_FENCE_MEM_RESERVE_EVENTS_BUFF: Reserve memory for the debug events
  29. */
  30. enum hw_fence_mem_reserve {
  31. HW_FENCE_MEM_RESERVE_CTRL_QUEUE,
  32. HW_FENCE_MEM_RESERVE_LOCKS_REGION,
  33. HW_FENCE_MEM_RESERVE_TABLE,
  34. HW_FENCE_MEM_RESERVE_CLIENT_QUEUE,
  35. HW_FENCE_MEM_RESERVE_EVENTS_BUFF
  36. };
  37. /**
  38. * global_atomic_store() - Inter-processor lock
  39. * @drv_data: hw fence driver data
  40. * @lock: memory to lock
  41. * @val: if true, api locks the memory, if false it unlocks the memory
  42. */
  43. void global_atomic_store(struct hw_fence_driver_data *drv_data, uint64_t *lock, bool val);
  44. /**
  45. * hw_fence_utils_init_virq() - Initialilze doorbell (i.e. vIRQ) for SVM to HLOS signaling
  46. * @drv_data: hw fence driver data
  47. *
  48. * Returns zero if success, otherwise returns negative error code.
  49. */
  50. int hw_fence_utils_init_virq(struct hw_fence_driver_data *drv_data);
  51. /**
  52. * hw_fence_utils_process_doorbell_mask() - Sends doorbell mask to process the signaled clients
  53. * this API is only exported for simulation purposes.
  54. * @drv_data: hw fence driver data.
  55. * @db_flags: doorbell flag
  56. */
  57. void hw_fence_utils_process_doorbell_mask(struct hw_fence_driver_data *drv_data, u64 db_flags);
  58. /**
  59. * hw_fence_utils_alloc_mem() - Allocates the carved-out memory pool that will be used for the HW
  60. * Fence global table, locks and queues.
  61. * @hw_fence_drv_data: hw fence driver data
  62. *
  63. * Returns zero if success, otherwise returns negative error code.
  64. */
  65. int hw_fence_utils_alloc_mem(struct hw_fence_driver_data *hw_fence_drv_data);
  66. /**
  67. * hw_fence_utils_reserve_mem() - Reserves memory from the carved-out memory pool.
  68. * @drv_data: hw fence driver data.
  69. * @type: memory reservation type.
  70. * @phys: physical address of the carved-out memory pool
  71. *
  72. * Returns zero if success, otherwise returns negative error code.
  73. */
  74. int hw_fence_utils_reserve_mem(struct hw_fence_driver_data *drv_data,
  75. enum hw_fence_mem_reserve type, phys_addr_t *phys, void **pa, u32 *size, int client_id);
  76. /**
  77. * hw_fence_utils_parse_dt_props() - Init dt properties
  78. * @drv_data: hw fence driver data
  79. *
  80. * Returns zero if success, otherwise returns negative error code.
  81. */
  82. int hw_fence_utils_parse_dt_props(struct hw_fence_driver_data *drv_data);
  83. /**
  84. * hw_fence_utils_map_ipcc() - Maps IPCC registers and enable signaling
  85. * @drv_data: hw fence driver data
  86. *
  87. * Returns zero if success, otherwise returns negative error code.
  88. */
  89. int hw_fence_utils_map_ipcc(struct hw_fence_driver_data *drv_data);
  90. /**
  91. * hw_fence_utils_map_qtime() - Maps qtime register
  92. * @drv_data: hw fence driver data
  93. *
  94. * Returns zero if success, otherwise returns negative error code.
  95. */
  96. int hw_fence_utils_map_qtime(struct hw_fence_driver_data *drv_data);
  97. /**
  98. * hw_fence_utils_cleanup_fence() - Cleanup the hw-fence from a specified client
  99. * @drv_data: hw fence driver data
  100. * @hw_fence_client: client, for which the fence must be cleared
  101. * @hw_fence: hw-fence to cleanup
  102. * @hash: hash of the hw-fence to cleanup
  103. * @reset_flags: flags to determine how to handle the reset
  104. *
  105. * Returns zero if success, otherwise returns negative error code.
  106. */
  107. int hw_fence_utils_cleanup_fence(struct hw_fence_driver_data *drv_data,
  108. struct msm_hw_fence_client *hw_fence_client, struct msm_hw_fence *hw_fence, u64 hash,
  109. u32 reset_flags);
  110. /**
  111. * hw_fence_utils_fence_error_cb() - Invokes fence error callback registered by specified client
  112. *
  113. * @hw_fence_client: client, for which fence error callback must be invoked
  114. * @ctxt_id: context id of the hw-fence
  115. * @seqno: sequence number of the hw-fence
  116. * @hash: hash of the hw-fence
  117. * @flags: flags of the hw-fence
  118. * @error: error of the hw-fence
  119. *
  120. * Returns zero if success, otherwise returns negative error code
  121. */
  122. int hw_fence_utils_fence_error_cb(struct msm_hw_fence_client *hw_fence_client, u64 ctxt_id,
  123. u64 seqno, u64 hash, u64 flags, u32 error);
  124. /**
  125. * hw_fence_utils_get_client_id_priv() - Gets the index into clients struct within hw fence driver
  126. * from the client_id used externally
  127. *
  128. * Performs a 1-to-1 mapping for all client IDs less than HW_FENCE_MAX_STATIC_CLIENTS_INDEX,
  129. * otherwise consolidates client IDs of clients with configurable number of sub-clients. Fails if
  130. * provided with client IDs for such clients when support for those clients is not configured in
  131. * device-tree.
  132. *
  133. * @drv_data: hw fence driver data
  134. * @client_id: external client_id to get internal client_id for
  135. *
  136. * Returns client_id < drv_data->clients_num if success, otherwise returns HW_FENCE_CLIENT_MAX
  137. */
  138. enum hw_fence_client_id hw_fence_utils_get_client_id_priv(struct hw_fence_driver_data *drv_data,
  139. enum hw_fence_client_id client_id);
  140. /**
  141. * hw_fence_utils_get_queues_num() - Returns number of client queues for the client_id.
  142. *
  143. * @drv_data: driver data
  144. * @client_id: hw fence driver client id
  145. *
  146. * Returns: number of client queues
  147. */
  148. int hw_fence_utils_get_queues_num(struct hw_fence_driver_data *drv_data, int client_id);
  149. #endif /* __HW_FENCE_DRV_UTILS_H */