rpmh-internal.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2016-2018, The Linux Foundation. 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 TCS_TYPE_NR 4
  11. #define MAX_CMDS_PER_TCS 16
  12. #define MAX_TCS_PER_TYPE 3
  13. #define MAX_TCS_NR (MAX_TCS_PER_TYPE * TCS_TYPE_NR)
  14. #define MAX_TCS_SLOTS (MAX_CMDS_PER_TCS * MAX_TCS_PER_TYPE)
  15. struct rsc_drv;
  16. /**
  17. * struct tcs_group: group of Trigger Command Sets (TCS) to send state requests
  18. * to the controller
  19. *
  20. * @drv: The controller.
  21. * @type: Type of the TCS in this group - active, sleep, wake.
  22. * @mask: Mask of the TCSes relative to all the TCSes in the RSC.
  23. * @offset: Start of the TCS group relative to the TCSes in the RSC.
  24. * @num_tcs: Number of TCSes in this type.
  25. * @ncpt: Number of commands in each TCS.
  26. * @req: Requests that are sent from the TCS; only used for ACTIVE_ONLY
  27. * transfers (could be on a wake/sleep TCS if we are borrowing for
  28. * an ACTIVE_ONLY transfer).
  29. * Start: grab drv->lock, set req, set tcs_in_use, drop drv->lock,
  30. * trigger
  31. * End: get irq, access req,
  32. * grab drv->lock, clear tcs_in_use, drop drv->lock
  33. * @slots: Indicates which of @cmd_addr are occupied; only used for
  34. * SLEEP / WAKE TCSs. Things are tightly packed in the
  35. * case that (ncpt < MAX_CMDS_PER_TCS). That is if ncpt = 2 and
  36. * MAX_CMDS_PER_TCS = 16 then bit[2] = the first bit in 2nd TCS.
  37. */
  38. struct tcs_group {
  39. struct rsc_drv *drv;
  40. int type;
  41. u32 mask;
  42. u32 offset;
  43. int num_tcs;
  44. int ncpt;
  45. const struct tcs_request *req[MAX_TCS_PER_TYPE];
  46. DECLARE_BITMAP(slots, MAX_TCS_SLOTS);
  47. };
  48. /**
  49. * struct rpmh_request: the message to be sent to rpmh-rsc
  50. *
  51. * @msg: the request
  52. * @cmd: the payload that will be part of the @msg
  53. * @completion: triggered when request is done
  54. * @dev: the device making the request
  55. * @err: err return from the controller
  56. * @needs_free: check to free dynamically allocated request object
  57. */
  58. struct rpmh_request {
  59. struct tcs_request msg;
  60. struct tcs_cmd cmd[MAX_RPMH_PAYLOAD];
  61. struct completion *completion;
  62. const struct device *dev;
  63. int err;
  64. bool needs_free;
  65. };
  66. /**
  67. * struct rpmh_ctrlr: our representation of the controller
  68. *
  69. * @cache: the list of cached requests
  70. * @cache_lock: synchronize access to the cache data
  71. * @dirty: was the cache updated since flush
  72. * @batch_cache: Cache sleep and wake requests sent as batch
  73. */
  74. struct rpmh_ctrlr {
  75. struct list_head cache;
  76. spinlock_t cache_lock;
  77. bool dirty;
  78. struct list_head batch_cache;
  79. };
  80. /**
  81. * struct rsc_drv: the Direct Resource Voter (DRV) of the
  82. * Resource State Coordinator controller (RSC)
  83. *
  84. * @name: Controller identifier.
  85. * @tcs_base: Start address of the TCS registers in this controller.
  86. * @id: Instance id in the controller (Direct Resource Voter).
  87. * @num_tcs: Number of TCSes in this DRV.
  88. * @rsc_pm: CPU PM notifier for controller.
  89. * Used when solver mode is not present.
  90. * @cpus_in_pm: Number of CPUs not in idle power collapse.
  91. * Used when solver mode is not present.
  92. * @tcs: TCS groups.
  93. * @tcs_in_use: S/W state of the TCS; only set for ACTIVE_ONLY
  94. * transfers, but might show a sleep/wake TCS in use if
  95. * it was borrowed for an active_only transfer. You
  96. * must hold the lock in this struct (AKA drv->lock) in
  97. * order to update this.
  98. * @lock: Synchronize state of the controller. If RPMH's cache
  99. * lock will also be held, the order is: drv->lock then
  100. * cache_lock.
  101. * @tcs_wait: Wait queue used to wait for @tcs_in_use to free up a
  102. * slot
  103. * @client: Handle to the DRV's client.
  104. */
  105. struct rsc_drv {
  106. const char *name;
  107. void __iomem *tcs_base;
  108. int id;
  109. int num_tcs;
  110. struct notifier_block rsc_pm;
  111. atomic_t cpus_in_pm;
  112. struct tcs_group tcs[TCS_TYPE_NR];
  113. DECLARE_BITMAP(tcs_in_use, MAX_TCS_NR);
  114. spinlock_t lock;
  115. wait_queue_head_t tcs_wait;
  116. struct rpmh_ctrlr client;
  117. };
  118. int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg);
  119. int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv,
  120. const struct tcs_request *msg);
  121. void rpmh_rsc_invalidate(struct rsc_drv *drv);
  122. void rpmh_tx_done(const struct tcs_request *msg, int r);
  123. int rpmh_flush(struct rpmh_ctrlr *ctrlr);
  124. #endif /* __RPM_INTERNAL_H__ */