hw_fence_drv_utils.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. * global_atomic_store() - Inter-processor lock
  37. * @drv_data: hw fence driver data
  38. * @lock: memory to lock
  39. * @val: if true, api locks the memory, if false it unlocks the memory
  40. */
  41. void global_atomic_store(struct hw_fence_driver_data *drv_data, uint64_t *lock, bool val);
  42. /**
  43. * hw_fence_utils_init_virq() - Initialilze doorbell (i.e. vIRQ) for SVM to HLOS signaling
  44. * @drv_data: hw fence driver data
  45. *
  46. * Returns zero if success, otherwise returns negative error code.
  47. */
  48. int hw_fence_utils_init_virq(struct hw_fence_driver_data *drv_data);
  49. /**
  50. * hw_fence_utils_process_doorbell_mask() - Sends doorbell mask to process the signaled clients
  51. * this API is only exported for simulation purposes.
  52. * @drv_data: hw fence driver data.
  53. * @db_flags: doorbell flag
  54. */
  55. void hw_fence_utils_process_doorbell_mask(struct hw_fence_driver_data *drv_data, u64 db_flags);
  56. /**
  57. * hw_fence_utils_alloc_mem() - Allocates the carved-out memory pool that will be used for the HW
  58. * Fence global table, locks and queues.
  59. * @hw_fence_drv_data: hw fence driver data
  60. *
  61. * Returns zero if success, otherwise returns negative error code.
  62. */
  63. int hw_fence_utils_alloc_mem(struct hw_fence_driver_data *hw_fence_drv_data);
  64. /**
  65. * hw_fence_utils_reserve_mem() - Reserves memory from the carved-out memory pool.
  66. * @drv_data: hw fence driver data.
  67. * @type: memory reservation type.
  68. * @phys: physical address of the carved-out memory pool
  69. *
  70. * Returns zero if success, otherwise returns negative error code.
  71. */
  72. int hw_fence_utils_reserve_mem(struct hw_fence_driver_data *drv_data,
  73. enum hw_fence_mem_reserve type, phys_addr_t *phys, void **pa, u32 *size, int client_id);
  74. /**
  75. * hw_fence_utils_parse_dt_props() - Init dt properties
  76. * @drv_data: hw fence driver data
  77. *
  78. * Returns zero if success, otherwise returns negative error code.
  79. */
  80. int hw_fence_utils_parse_dt_props(struct hw_fence_driver_data *drv_data);
  81. /**
  82. * hw_fence_utils_map_ipcc() - Maps IPCC registers and enable signaling
  83. * @drv_data: hw fence driver data
  84. *
  85. * Returns zero if success, otherwise returns negative error code.
  86. */
  87. int hw_fence_utils_map_ipcc(struct hw_fence_driver_data *drv_data);
  88. /**
  89. * hw_fence_utils_map_qtime() - Maps qtime register
  90. * @drv_data: hw fence driver data
  91. *
  92. * Returns zero if success, otherwise returns negative error code.
  93. */
  94. int hw_fence_utils_map_qtime(struct hw_fence_driver_data *drv_data);
  95. /**
  96. * hw_fence_utils_cleanup_fence() - Cleanup the hw-fence from a specified client
  97. * @drv_data: hw fence driver data
  98. * @hw_fence_client: client, for which the fence must be cleared
  99. * @hw_fence: hw-fence to cleanup
  100. * @hash: hash of the hw-fence to cleanup
  101. * @reset_flags: flags to determine how to handle the reset
  102. *
  103. * Returns zero if success, otherwise returns negative error code.
  104. */
  105. int hw_fence_utils_cleanup_fence(struct hw_fence_driver_data *drv_data,
  106. struct msm_hw_fence_client *hw_fence_client, struct msm_hw_fence *hw_fence, u64 hash,
  107. u32 reset_flags);
  108. /**
  109. * hw_fence_utils_get_client_id_priv() - Gets the index into clients struct within hw fence driver
  110. * from the client_id used externally
  111. *
  112. * Performs a 1-to-1 mapping for all client IDs less than HW_FENCE_MAX_STATIC_CLIENTS_INDEX,
  113. * otherwise consolidates client IDs of clients with configurable number of sub-clients. Fails if
  114. * provided with client IDs for such clients when support for those clients is not configured in
  115. * device-tree.
  116. *
  117. * @drv_data: hw fence driver data
  118. * @client_id: external client_id to get internal client_id for
  119. *
  120. * Returns client_id < drv_data->clients_num if success, otherwise returns HW_FENCE_CLIENT_MAX
  121. */
  122. enum hw_fence_client_id hw_fence_utils_get_client_id_priv(struct hw_fence_driver_data *drv_data,
  123. enum hw_fence_client_id client_id);
  124. /**
  125. * hw_fence_utils_get_queues_num() - Returns number of client queues for the client_id.
  126. *
  127. * @drv_data: driver data
  128. * @client_id: hw fence driver client id
  129. *
  130. * Returns: number of client queues
  131. */
  132. int hw_fence_utils_get_queues_num(struct hw_fence_driver_data *drv_data, int client_id);
  133. #endif /* __HW_FENCE_DRV_UTILS_H */