rpmh-internal.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 <soc/qcom/tcs.h>
  9. #define TCS_TYPE_NR 4
  10. #define MAX_CMDS_PER_TCS 16
  11. #define MAX_TCS_PER_TYPE 3
  12. #define MAX_TCS_NR (MAX_TCS_PER_TYPE * TCS_TYPE_NR)
  13. #define MAX_TCS_SLOTS (MAX_CMDS_PER_TCS * MAX_TCS_PER_TYPE)
  14. struct rsc_drv;
  15. /**
  16. * struct tcs_group: group of Trigger Command Sets (TCS) to send state requests
  17. * to the controller
  18. *
  19. * @drv: the controller
  20. * @type: type of the TCS in this group - active, sleep, wake
  21. * @mask: mask of the TCSes relative to all the TCSes in the RSC
  22. * @offset: start of the TCS group relative to the TCSes in the RSC
  23. * @num_tcs: number of TCSes in this type
  24. * @ncpt: number of commands in each TCS
  25. * @lock: lock for synchronizing this TCS writes
  26. * @req: requests that are sent from the TCS
  27. * @cmd_cache: flattened cache of cmds in sleep/wake TCS
  28. * @slots: indicates which of @cmd_addr are occupied
  29. */
  30. struct tcs_group {
  31. struct rsc_drv *drv;
  32. int type;
  33. u32 mask;
  34. u32 offset;
  35. int num_tcs;
  36. int ncpt;
  37. spinlock_t lock;
  38. const struct tcs_request *req[MAX_TCS_PER_TYPE];
  39. u32 *cmd_cache;
  40. DECLARE_BITMAP(slots, MAX_TCS_SLOTS);
  41. };
  42. /**
  43. * struct rpmh_request: the message to be sent to rpmh-rsc
  44. *
  45. * @msg: the request
  46. * @cmd: the payload that will be part of the @msg
  47. * @completion: triggered when request is done
  48. * @dev: the device making the request
  49. * @err: err return from the controller
  50. * @needs_free: check to free dynamically allocated request object
  51. */
  52. struct rpmh_request {
  53. struct tcs_request msg;
  54. struct tcs_cmd cmd[MAX_RPMH_PAYLOAD];
  55. struct completion *completion;
  56. const struct device *dev;
  57. int err;
  58. bool needs_free;
  59. };
  60. /**
  61. * struct rpmh_ctrlr: our representation of the controller
  62. *
  63. * @cache: the list of cached requests
  64. * @cache_lock: synchronize access to the cache data
  65. * @dirty: was the cache updated since flush
  66. * @batch_cache: Cache sleep and wake requests sent as batch
  67. */
  68. struct rpmh_ctrlr {
  69. struct list_head cache;
  70. spinlock_t cache_lock;
  71. bool dirty;
  72. struct list_head batch_cache;
  73. };
  74. /**
  75. * struct rsc_drv: the Direct Resource Voter (DRV) of the
  76. * Resource State Coordinator controller (RSC)
  77. *
  78. * @name: controller identifier
  79. * @tcs_base: start address of the TCS registers in this controller
  80. * @id: instance id in the controller (Direct Resource Voter)
  81. * @num_tcs: number of TCSes in this DRV
  82. * @tcs: TCS groups
  83. * @tcs_in_use: s/w state of the TCS
  84. * @lock: synchronize state of the controller
  85. * @client: handle to the DRV's client.
  86. */
  87. struct rsc_drv {
  88. const char *name;
  89. void __iomem *tcs_base;
  90. int id;
  91. int num_tcs;
  92. struct tcs_group tcs[TCS_TYPE_NR];
  93. DECLARE_BITMAP(tcs_in_use, MAX_TCS_NR);
  94. spinlock_t lock;
  95. struct rpmh_ctrlr client;
  96. };
  97. int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg);
  98. int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv,
  99. const struct tcs_request *msg);
  100. int rpmh_rsc_invalidate(struct rsc_drv *drv);
  101. void rpmh_tx_done(const struct tcs_request *msg, int r);
  102. #endif /* __RPM_INTERNAL_H__ */