rpmh-internal.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef __RPM_INTERNAL_H__
  6. #define __RPM_INTERNAL_H__
  7. #include <linux/bitmap.h>
  8. #include <linux/wait.h>
  9. #include <soc/qcom/tcs.h>
  10. #define MAX_NAME_LENGTH 20
  11. #define CH0 0
  12. #define CH1 1
  13. #define MAX_CHANNEL 2
  14. #define TCS_TYPE_NR 5
  15. #define MAX_CMDS_PER_TCS 16
  16. #define MAX_TCS_PER_TYPE 3
  17. #define MAX_TCS_NR (MAX_TCS_PER_TYPE * TCS_TYPE_NR)
  18. #define MAX_TCS_SLOTS (MAX_CMDS_PER_TCS * MAX_TCS_PER_TYPE)
  19. /* CTRLR specific flags */
  20. #define SOLVER_PRESENT 1
  21. #define HW_CHANNEL_PRESENT 2
  22. #define CMD_DB_MAX_RESOURCES 250
  23. struct rsc_drv;
  24. /**
  25. * struct cache_req: the request object for caching
  26. *
  27. * @addr: the address of the resource
  28. * @sleep_val: the sleep vote
  29. * @wake_val: the wake vote
  30. * @list: linked list obj
  31. */
  32. struct cache_req {
  33. u32 addr;
  34. u32 sleep_val;
  35. u32 wake_val;
  36. struct list_head list;
  37. };
  38. /**
  39. * struct tcs_group: group of Trigger Command Sets (TCS) to send state requests
  40. * to the controller
  41. *
  42. * @drv: The controller.
  43. * @type: Type of the TCS in this group - active, sleep, wake.
  44. * @mask: Mask of the TCSes relative to all the TCSes in the RSC.
  45. * @offset: Start of the TCS group relative to the TCSes in the RSC.
  46. * @num_tcs: Number of TCSes in this type.
  47. * @ncpt: Number of commands in each TCS.
  48. * @req: Requests that are sent from the TCS; only used for ACTIVE_ONLY
  49. * transfers (could be on a wake/sleep TCS if we are borrowing for
  50. * an ACTIVE_ONLY transfer).
  51. * Start: grab drv->lock, set req, set tcs_in_use, drop drv->lock,
  52. * trigger
  53. * End: get irq, access req,
  54. * grab drv->lock, clear tcs_in_use, drop drv->lock
  55. * @slots: Indicates which of @cmd_addr are occupied; only used for
  56. * SLEEP / WAKE TCSs. Things are tightly packed in the
  57. * case that (ncpt < MAX_CMDS_PER_TCS). That is if ncpt = 2 and
  58. * MAX_CMDS_PER_TCS = 16 then bit[2] = the first bit in 2nd TCS.
  59. */
  60. struct tcs_group {
  61. struct rsc_drv *drv;
  62. int type;
  63. u32 mask;
  64. u32 offset;
  65. int num_tcs;
  66. int ncpt;
  67. const struct tcs_request *req[MAX_TCS_PER_TYPE];
  68. DECLARE_BITMAP(slots, MAX_TCS_SLOTS);
  69. };
  70. /**
  71. * struct rpmh_request: the message to be sent to rpmh-rsc
  72. *
  73. * @msg: the request
  74. * @cmd: the payload that will be part of the @msg
  75. * @completion: triggered when request is done
  76. * @dev: the device making the request
  77. */
  78. struct rpmh_request {
  79. struct tcs_request msg;
  80. struct tcs_cmd cmd[MAX_RPMH_PAYLOAD];
  81. struct completion *completion;
  82. const struct device *dev;
  83. };
  84. /**
  85. * struct rpmh_ctrlr: our representation of the controller
  86. *
  87. * @cache_lock: synchronize access to the cache data
  88. * @dirty: was the cache updated since flush
  89. * @in_solver_mode: Controller is busy in solver mode
  90. * @flags: Controller specific flags
  91. * @batch_cache: Cache sleep and wake requests sent as batch
  92. */
  93. struct rpmh_ctrlr {
  94. spinlock_t cache_lock;
  95. bool dirty;
  96. bool in_solver_mode;
  97. u32 flags;
  98. struct rpmh_request batch_cache[RPMH_ACTIVE_ONLY_STATE];
  99. u32 non_batch_cache_idx;
  100. struct cache_req *non_batch_cache;
  101. };
  102. /**
  103. * struct drv_channel: our representation of the drv channels
  104. *
  105. * @tcs: TCS groups.
  106. * @drv: DRV containing the channel
  107. * @initialized: Whether channel is initialized
  108. */
  109. struct drv_channel {
  110. struct tcs_group tcs[TCS_TYPE_NR];
  111. struct rsc_drv *drv;
  112. bool initialized;
  113. };
  114. /**
  115. * struct rsc_drv_top: our representation of the top RSC device
  116. *
  117. * @name: Controller RSC device name.
  118. * @drv_count: No. of DRV controllers in the RSC device
  119. * @drv: Controller for each DRV
  120. * @dev: RSC top device
  121. * @list: RSC device added in rpmh_rsc_dev_list.
  122. */
  123. struct rsc_drv_top {
  124. char name[MAX_NAME_LENGTH];
  125. int drv_count;
  126. struct rsc_drv *drv;
  127. struct device *dev;
  128. struct list_head list;
  129. };
  130. /**
  131. * struct rsc_drv: the Direct Resource Voter (DRV) of the
  132. * Resource State Coordinator controller (RSC)
  133. *
  134. * @name: Controller identifier.
  135. * @base: Base address of the RSC controller.
  136. * @tcs_base: Start address of the TCS registers in this controller.
  137. * @reg: Register offsets for RSC controller.
  138. * @id: Instance id in the controller (Direct Resource Voter).
  139. * @num_tcs: Number of TCSes in this DRV.
  140. * @num_channels: Number of channels in this DRV.
  141. * @irq: IRQ at gic.
  142. * @in_solver_mode: Controller is busy in solver mode
  143. * @initialized: Whether DRV is initialized
  144. * @rsc_pm: CPU PM notifier for controller.
  145. * Used when solver mode is not present.
  146. * @cpus_in_pm: Number of CPUs not in idle power collapse.
  147. * Used when solver mode is not present.
  148. * @ch: DRV channels.
  149. * @tcs_in_use: S/W state of the TCS; only set for ACTIVE_ONLY
  150. * transfers, but might show a sleep/wake TCS in use if
  151. * it was borrowed for an active_only transfer. You
  152. * must hold the lock in this struct (AKA drv->lock) in
  153. * order to update this.
  154. * @lock: Synchronize state of the controller. If RPMH's cache
  155. * lock will also be held, the order is: drv->lock then
  156. * cache_lock.
  157. * @tcs_wait: Wait queue used to wait for @tcs_in_use to free up a
  158. * slot
  159. * @client: Handle to the DRV's client.
  160. * @genpd_nb: PM Domain notifier
  161. * @dev: RSC device
  162. * @ipc_log_ctx: IPC logger handle
  163. * @pdev: platform device
  164. */
  165. struct rsc_drv {
  166. char name[MAX_NAME_LENGTH];
  167. void __iomem *base;
  168. void __iomem *tcs_base;
  169. u32 *regs;
  170. int id;
  171. int num_tcs;
  172. int num_channels;
  173. int irq;
  174. bool in_solver_mode;
  175. bool initialized;
  176. struct notifier_block rsc_pm;
  177. atomic_t cpus_in_pm;
  178. struct drv_channel ch[MAX_CHANNEL];
  179. DECLARE_BITMAP(tcs_in_use, MAX_TCS_NR);
  180. spinlock_t lock;
  181. wait_queue_head_t tcs_wait;
  182. struct rpmh_ctrlr client;
  183. struct notifier_block genpd_nb;
  184. struct device *dev;
  185. void *ipc_log_ctx;
  186. struct platform_device *pdev;
  187. };
  188. extern bool rpmh_standalone;
  189. int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg, int ch);
  190. int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv,
  191. const struct tcs_request *msg,
  192. int ch);
  193. void rpmh_rsc_invalidate(struct rsc_drv *drv, int ch);
  194. void rpmh_rsc_debug(struct rsc_drv *drv, struct completion *compl);
  195. void rpmh_rsc_debug_channel_busy(struct rsc_drv *drv);
  196. int rpmh_rsc_mode_solver_set(struct rsc_drv *drv, bool enable);
  197. int rpmh_rsc_get_channel(struct rsc_drv *drv);
  198. int rpmh_rsc_switch_channel(struct rsc_drv *drv, int ch);
  199. int rpmh_rsc_drv_enable(struct rsc_drv *drv, bool enable);
  200. const struct device *rpmh_rsc_get_device(const char *name, u32 drv_id);
  201. void rpmh_tx_done(const struct tcs_request *msg);
  202. int rpmh_flush(struct rpmh_ctrlr *ctrlr, int ch);
  203. int _rpmh_flush(struct rpmh_ctrlr *ctrlr, int ch);
  204. int rpmh_rsc_init_fast_path(struct rsc_drv *drv, const struct tcs_request *msg, int ch);
  205. int rpmh_rsc_update_fast_path(struct rsc_drv *drv,
  206. const struct tcs_request *msg,
  207. u32 update_mask, int ch);
  208. #endif /* __RPM_INTERNAL_H__ */