hw_fence_drv_utils.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. */
  29. enum hw_fence_mem_reserve {
  30. HW_FENCE_MEM_RESERVE_CTRL_QUEUE,
  31. HW_FENCE_MEM_RESERVE_LOCKS_REGION,
  32. HW_FENCE_MEM_RESERVE_TABLE,
  33. HW_FENCE_MEM_RESERVE_CLIENT_QUEUE
  34. };
  35. /**
  36. * struct hw_fence_client_type_desc - Structure holding client type properties, including static
  37. * properties and client queue properties read from device-tree.
  38. *
  39. * @name: name of client type, used to parse properties from device-tree
  40. * @init_id: initial client_id for given client type within the 'hw_fence_client_id' enum, e.g.
  41. * HW_FENCE_CLIENT_ID_CTL0 for DPU clients
  42. * @max_clients_num: maximum number of clients of given client type
  43. * @clients_num: number of clients of given client type
  44. * @queues_num: number of queues per client of given client type; either one (for only Tx Queue) or
  45. * two (for both Tx and Rx Queues)
  46. * @queue_entries: number of entries per client queue of given client type
  47. * @mem_size: size of memory allocated for client queue(s) per client
  48. * @skip_txq_wr_idx: bool to indicate if update to tx queue write_index is skipped within hw fence
  49. * driver and hfi_header->tx_wm is updated instead
  50. */
  51. struct hw_fence_client_type_desc {
  52. char *name;
  53. enum hw_fence_client_id init_id;
  54. u32 max_clients_num;
  55. u32 clients_num;
  56. u32 queues_num;
  57. u32 queue_entries;
  58. u32 mem_size;
  59. bool skip_txq_wr_idx;
  60. };
  61. /**
  62. * global_atomic_store() - Inter-processor lock
  63. * @drv_data: hw fence driver data
  64. * @lock: memory to lock
  65. * @val: if true, api locks the memory, if false it unlocks the memory
  66. */
  67. void global_atomic_store(struct hw_fence_driver_data *drv_data, uint64_t *lock, bool val);
  68. /**
  69. * hw_fence_utils_init_virq() - Initialilze doorbell (i.e. vIRQ) for SVM to HLOS signaling
  70. * @drv_data: hw fence driver data
  71. *
  72. * Returns zero if success, otherwise returns negative error code.
  73. */
  74. int hw_fence_utils_init_virq(struct hw_fence_driver_data *drv_data);
  75. /**
  76. * hw_fence_utils_process_doorbell_mask() - Sends doorbell mask to process the signaled clients
  77. * this API is only exported for simulation purposes.
  78. * @drv_data: hw fence driver data.
  79. * @db_flags: doorbell flag
  80. */
  81. void hw_fence_utils_process_doorbell_mask(struct hw_fence_driver_data *drv_data, u64 db_flags);
  82. /**
  83. * hw_fence_utils_alloc_mem() - Allocates the carved-out memory pool that will be used for the HW
  84. * Fence global table, locks and queues.
  85. * @hw_fence_drv_data: hw fence driver data
  86. *
  87. * Returns zero if success, otherwise returns negative error code.
  88. */
  89. int hw_fence_utils_alloc_mem(struct hw_fence_driver_data *hw_fence_drv_data);
  90. /**
  91. * hw_fence_utils_reserve_mem() - Reserves memory from the carved-out memory pool.
  92. * @drv_data: hw fence driver data.
  93. * @type: memory reservation type.
  94. * @phys: physical address of the carved-out memory pool
  95. *
  96. * Returns zero if success, otherwise returns negative error code.
  97. */
  98. int hw_fence_utils_reserve_mem(struct hw_fence_driver_data *drv_data,
  99. enum hw_fence_mem_reserve type, phys_addr_t *phys, void **pa, u32 *size, int client_id);
  100. /**
  101. * hw_fence_utils_parse_dt_props() - Init dt properties
  102. * @drv_data: hw fence driver data
  103. *
  104. * Returns zero if success, otherwise returns negative error code.
  105. */
  106. int hw_fence_utils_parse_dt_props(struct hw_fence_driver_data *drv_data);
  107. /**
  108. * hw_fence_utils_map_ipcc() - Maps IPCC registers and enable signaling
  109. * @drv_data: hw fence driver data
  110. *
  111. * Returns zero if success, otherwise returns negative error code.
  112. */
  113. int hw_fence_utils_map_ipcc(struct hw_fence_driver_data *drv_data);
  114. /**
  115. * hw_fence_utils_map_qtime() - Maps qtime register
  116. * @drv_data: hw fence driver data
  117. *
  118. * Returns zero if success, otherwise returns negative error code.
  119. */
  120. int hw_fence_utils_map_qtime(struct hw_fence_driver_data *drv_data);
  121. /**
  122. * hw_fence_utils_map_ctl_start() - Maps ctl_start registers from dpu hw
  123. * @drv_data: hw fence driver data
  124. *
  125. * Returns zero if success, otherwise returns negative error code. This API is only used
  126. * for simulation purposes in platforms where dpu does not support ipc signal.
  127. */
  128. int hw_fence_utils_map_ctl_start(struct hw_fence_driver_data *drv_data);
  129. /**
  130. * hw_fence_utils_cleanup_fence() - Cleanup the hw-fence from a specified client
  131. * @drv_data: hw fence driver data
  132. * @hw_fence_client: client, for which the fence must be cleared
  133. * @hw_fence: hw-fence to cleanup
  134. * @hash: hash of the hw-fence to cleanup
  135. * @reset_flags: flags to determine how to handle the reset
  136. *
  137. * Returns zero if success, otherwise returns negative error code.
  138. */
  139. int hw_fence_utils_cleanup_fence(struct hw_fence_driver_data *drv_data,
  140. struct msm_hw_fence_client *hw_fence_client, struct msm_hw_fence *hw_fence, u64 hash,
  141. u32 reset_flags);
  142. /**
  143. * hw_fence_utils_get_client_id_priv() - Gets the index into clients struct within hw fence driver
  144. * from the client_id used externally
  145. *
  146. * Performs a 1-to-1 mapping for all client IDs less than HW_FENCE_MAX_STATIC_CLIENTS_INDEX,
  147. * otherwise consolidates client IDs of clients with configurable number of sub-clients. Fails if
  148. * provided with client IDs for such clients when support for those clients is not configured in
  149. * device-tree.
  150. *
  151. * @drv_data: hw fence driver data
  152. * @client_id: external client_id to get internal client_id for
  153. *
  154. * Returns client_id < drv_data->clients_num if success, otherwise returns HW_FENCE_CLIENT_MAX
  155. */
  156. enum hw_fence_client_id hw_fence_utils_get_client_id_priv(struct hw_fence_driver_data *drv_data,
  157. enum hw_fence_client_id client_id);
  158. /**
  159. * hw_fence_utils_skips_txq_wr_index() - Returns bool to indicate if client Tx Queue write_index
  160. * is not updated in hw fence driver. Instead,
  161. * hfi_header->tx_wm tracks where payload is written within
  162. * the queue.
  163. *
  164. * @drv_data: driver data
  165. * @client_id: hw fence driver client id
  166. *
  167. * Returns: true if hw fence driver skips update to client tx queue write_index, false otherwise
  168. */
  169. bool hw_fence_utils_skips_txq_wr_idx(struct hw_fence_driver_data *drv_data, int client_id);
  170. #endif /* __HW_FENCE_DRV_UTILS_H */