smp2p_private.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* drivers/soc/qcom/smp2p_private.h
  2. *
  3. * Copyright (c) 2013-2014,2016 The Linux Foundation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 and
  7. * only version 2 as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef _ARCH_ARM_MACH_MSM_MSM_SMP2P_PRIVATE_H_
  15. #define _ARCH_ARM_MACH_MSM_MSM_SMP2P_PRIVATE_H_
  16. #include <linux/types.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/ipc_logging.h>
  19. #include "smp2p_private_api.h"
  20. #define SMP2P_MAX_ENTRY 16
  21. #define SMP2P_FEATURE_SSR_ACK 0x1
  22. /* SMEM Item Header Macros */
  23. #define SMP2P_MAGIC 0x504D5324
  24. #define SMP2P_LOCAL_PID_MASK 0x0000ffff
  25. #define SMP2P_LOCAL_PID_BIT 0
  26. #define SMP2P_REMOTE_PID_MASK 0xffff0000
  27. #define SMP2P_REMOTE_PID_BIT 16
  28. #define SMP2P_VERSION_MASK 0x000000ff
  29. #define SMP2P_VERSION_BIT 0
  30. #define SMP2P_FEATURE_MASK 0xffffff00
  31. #define SMP2P_FEATURE_BIT 8
  32. #define SMP2P_ENT_TOTAL_MASK 0x0000ffff
  33. #define SMP2P_ENT_TOTAL_BIT 0
  34. #define SMP2P_ENT_VALID_MASK 0xffff0000
  35. #define SMP2P_ENT_VALID_BIT 16
  36. #define SMP2P_FLAGS_RESTART_DONE_BIT 0
  37. #define SMP2P_FLAGS_RESTART_DONE_MASK 0x1
  38. #define SMP2P_FLAGS_RESTART_ACK_BIT 1
  39. #define SMP2P_FLAGS_RESTART_ACK_MASK 0x2
  40. #define SMP2P_GPIO_NO_INT BIT(1)
  41. #define SMP2P_GET_BITS(hdr_val, mask, bit) \
  42. (((hdr_val) & (mask)) >> (bit))
  43. #define SMP2P_SET_BITS(hdr_val, mask, bit, new_value) \
  44. {\
  45. hdr_val = (hdr_val & ~(mask)) \
  46. | (((new_value) << (bit)) & (mask)); \
  47. }
  48. #define SMP2P_IOMEM_GET_BITS(hdr, val, mask, bit) \
  49. ({\
  50. const volatile void __iomem *__p = (hdr); \
  51. __p += offsetof(typeof(*(hdr)), val); \
  52. (readl(__p) & (mask)) >> (bit); \
  53. })
  54. #define SMP2P_IOMEM_SET_BITS(hdr, val, mask, bit, new_value) \
  55. ({\
  56. volatile void __iomem *__p = (hdr); \
  57. __p += offsetof(typeof(*(hdr)), val); \
  58. writel((readl(__p) & ~(mask)) \
  59. | (((new_value) << (bit)) & (mask)), __p); \
  60. })
  61. #define SMP2P_GET_LOCAL_PID(hdr, val) \
  62. SMP2P_IOMEM_GET_BITS(hdr, val, SMP2P_LOCAL_PID_MASK, SMP2P_LOCAL_PID_BIT)
  63. #define SMP2P_SET_LOCAL_PID(hdr, val, pid) \
  64. SMP2P_IOMEM_SET_BITS(hdr, val, SMP2P_LOCAL_PID_MASK, SMP2P_LOCAL_PID_BIT, pid)
  65. #define SMP2P_GET_REMOTE_PID(hdr, val) \
  66. SMP2P_IOMEM_GET_BITS(hdr, val, SMP2P_REMOTE_PID_MASK, SMP2P_REMOTE_PID_BIT)
  67. #define SMP2P_SET_REMOTE_PID(hdr, val, pid) \
  68. SMP2P_IOMEM_SET_BITS(hdr, val, SMP2P_REMOTE_PID_MASK, SMP2P_REMOTE_PID_BIT, pid)
  69. #define SMP2P_GET_VERSION(hdr, val) \
  70. SMP2P_IOMEM_GET_BITS(hdr, val, SMP2P_VERSION_MASK, SMP2P_VERSION_BIT)
  71. #define SMP2P_SET_VERSION(hdr, val, version) \
  72. SMP2P_IOMEM_SET_BITS(hdr, val, SMP2P_VERSION_MASK, SMP2P_VERSION_BIT, version)
  73. #define SMP2P_GET_FEATURES(hdr, val) \
  74. SMP2P_IOMEM_GET_BITS(hdr, val, SMP2P_FEATURE_MASK, SMP2P_FEATURE_BIT)
  75. #define SMP2P_SET_FEATURES(hdr, val, features) \
  76. SMP2P_IOMEM_SET_BITS(hdr, val, SMP2P_FEATURE_MASK, SMP2P_FEATURE_BIT, features)
  77. #define SMP2P_GET_ENT_TOTAL(hdr, val) \
  78. SMP2P_IOMEM_GET_BITS(hdr, val, SMP2P_ENT_TOTAL_MASK, SMP2P_ENT_TOTAL_BIT)
  79. #define SMP2P_SET_ENT_TOTAL(hdr, val, entries) \
  80. SMP2P_IOMEM_SET_BITS(hdr, val, SMP2P_ENT_TOTAL_MASK, SMP2P_ENT_TOTAL_BIT, entries)
  81. #define SMP2P_GET_ENT_VALID(hdr, val) \
  82. SMP2P_IOMEM_GET_BITS(hdr, val, SMP2P_ENT_VALID_MASK, SMP2P_ENT_VALID_BIT)
  83. #define SMP2P_SET_ENT_VALID(hdr, val, entries) \
  84. SMP2P_IOMEM_SET_BITS(hdr, val, SMP2P_ENT_VALID_MASK, SMP2P_ENT_VALID_BIT,\
  85. entries)
  86. #define SMP2P_GET_RESTART_DONE(hdr, val) \
  87. SMP2P_IOMEM_GET_BITS(hdr, val, SMP2P_FLAGS_RESTART_DONE_MASK, \
  88. SMP2P_FLAGS_RESTART_DONE_BIT)
  89. #define SMP2P_SET_RESTART_DONE(hdr, val, value) \
  90. SMP2P_IOMEM_SET_BITS(hdr, val, SMP2P_FLAGS_RESTART_DONE_MASK, \
  91. SMP2P_FLAGS_RESTART_DONE_BIT, value)
  92. #define SMP2P_GET_RESTART_ACK(hdr, val) \
  93. SMP2P_IOMEM_GET_BITS(hdr, val, SMP2P_FLAGS_RESTART_ACK_MASK, \
  94. SMP2P_FLAGS_RESTART_ACK_BIT)
  95. #define SMP2P_SET_RESTART_ACK(hdr, val, value) \
  96. SMP2P_IOMEM_SET_BITS(hdr, val, SMP2P_FLAGS_RESTART_ACK_MASK, \
  97. SMP2P_FLAGS_RESTART_ACK_BIT, value)
  98. /* Loopback Command Macros */
  99. #define SMP2P_RMT_CMD_TYPE_MASK 0x80000000
  100. #define SMP2P_RMT_CMD_TYPE_BIT 31
  101. #define SMP2P_RMT_IGNORE_MASK 0x40000000
  102. #define SMP2P_RMT_IGNORE_BIT 30
  103. #define SMP2P_RMT_CMD_MASK 0x3f000000
  104. #define SMP2P_RMT_CMD_BIT 24
  105. #define SMP2P_RMT_DATA_MASK 0x00ffffff
  106. #define SMP2P_RMT_DATA_BIT 0
  107. #define SMP2P_GET_RMT_CMD_TYPE(val) \
  108. SMP2P_GET_BITS(val, SMP2P_RMT_CMD_TYPE_MASK, SMP2P_RMT_CMD_TYPE_BIT)
  109. #define SMP2P_GET_RMT_CMD(val) \
  110. SMP2P_GET_BITS(val, SMP2P_RMT_CMD_MASK, SMP2P_RMT_CMD_BIT)
  111. #define SMP2P_GET_RMT_DATA(val) \
  112. SMP2P_GET_BITS(val, SMP2P_RMT_DATA_MASK, SMP2P_RMT_DATA_BIT)
  113. #define SMP2P_SET_RMT_CMD_TYPE(val, cmd_type) \
  114. SMP2P_SET_BITS(val, SMP2P_RMT_CMD_TYPE_MASK, SMP2P_RMT_CMD_TYPE_BIT, \
  115. cmd_type)
  116. #define SMP2P_SET_RMT_CMD_TYPE_REQ(val) \
  117. SMP2P_SET_RMT_CMD_TYPE(val, 1)
  118. #define SMP2P_SET_RMT_CMD_TYPE_RESP(val) \
  119. SMP2P_SET_RMT_CMD_TYPE(val, 0)
  120. #define SMP2P_SET_RMT_CMD(val, cmd) \
  121. SMP2P_SET_BITS(val, SMP2P_RMT_CMD_MASK, SMP2P_RMT_CMD_BIT, \
  122. cmd)
  123. #define SMP2P_SET_RMT_DATA(val, data) \
  124. SMP2P_SET_BITS(val, SMP2P_RMT_DATA_MASK, SMP2P_RMT_DATA_BIT, data)
  125. enum {
  126. SMP2P_LB_CMD_NOOP = 0x0,
  127. SMP2P_LB_CMD_ECHO,
  128. SMP2P_LB_CMD_CLEARALL,
  129. SMP2P_LB_CMD_PINGPONG,
  130. SMP2P_LB_CMD_RSPIN_START,
  131. SMP2P_LB_CMD_RSPIN_LOCKED,
  132. SMP2P_LB_CMD_RSPIN_UNLOCKED,
  133. SMP2P_LB_CMD_RSPIN_END,
  134. };
  135. #define SMP2P_RLPB_IGNORE 0x40
  136. #define SMP2P_RLPB_ENTRY_NAME "smp2p"
  137. /* Debug Logging Macros */
  138. enum {
  139. MSM_SMP2P_INFO = 1U << 0,
  140. MSM_SMP2P_DEBUG = 1U << 1,
  141. MSM_SMP2P_GPIO = 1U << 2,
  142. };
  143. #define SMP2P_IPC_LOG_STR(x...) do { \
  144. if (smp2p_get_log_ctx()) \
  145. ipc_log_string(smp2p_get_log_ctx(), x); \
  146. } while (0)
  147. #define SMP2P_DBG(x...) do { \
  148. if (smp2p_get_debug_mask() & MSM_SMP2P_DEBUG) \
  149. SMP2P_IPC_LOG_STR(x); \
  150. } while (0)
  151. #define SMP2P_INFO(x...) do { \
  152. if (smp2p_get_debug_mask() & MSM_SMP2P_INFO) \
  153. SMP2P_IPC_LOG_STR(x); \
  154. } while (0)
  155. #define SMP2P_ERR(x...) do { \
  156. pr_err(x); \
  157. SMP2P_IPC_LOG_STR(x); \
  158. } while (0)
  159. #define SMP2P_GPIO(x...) do { \
  160. if (smp2p_get_debug_mask() & MSM_SMP2P_GPIO) \
  161. SMP2P_IPC_LOG_STR(x); \
  162. } while (0)
  163. enum msm_smp2p_edge_state {
  164. SMP2P_EDGE_STATE_CLOSED,
  165. SMP2P_EDGE_STATE_OPENING,
  166. SMP2P_EDGE_STATE_OPENED,
  167. SMP2P_EDGE_STATE_FAILED = 0xff,
  168. };
  169. /**
  170. * struct smp2p_smem - SMP2P SMEM Item Header
  171. *
  172. * @magic: Set to "$SMP" -- used for identification / debug purposes
  173. * @feature_version: Feature and version fields
  174. * @rem_loc_proc_id: Remote (31:16) and Local (15:0) processor IDs
  175. * @valid_total_ent: Valid (31:16) and total (15:0) entries
  176. * @flags: Flags (bits 31:2 reserved)
  177. */
  178. struct smp2p_smem {
  179. uint32_t magic;
  180. uint32_t feature_version;
  181. uint32_t rem_loc_proc_id;
  182. uint32_t valid_total_ent;
  183. uint32_t flags;
  184. };
  185. struct smp2p_entry_v1 {
  186. char name[SMP2P_MAX_ENTRY_NAME];
  187. uint32_t entry;
  188. };
  189. struct smp2p_smem_item {
  190. struct smp2p_smem header;
  191. struct smp2p_entry_v1 entries[SMP2P_MAX_ENTRY];
  192. };
  193. /* Mock object for internal loopback testing. */
  194. struct msm_smp2p_remote_mock {
  195. struct smp2p_smem_item remote_item;
  196. int rx_interrupt_count;
  197. int (*rx_interrupt)(void);
  198. void (*tx_interrupt)(void);
  199. bool item_exists;
  200. bool initialized;
  201. struct completion cb_completion;
  202. };
  203. void smp2p_init_header(struct smp2p_smem *header_ptr, int local_pid,
  204. int remote_pid, uint32_t features, uint32_t version);
  205. void *msm_smp2p_get_remote_mock(void);
  206. int smp2p_remote_mock_rx_interrupt(void);
  207. int smp2p_reset_mock_edge(void);
  208. void msm_smp2p_interrupt_handler(int remote_pid);
  209. void msm_smp2p_set_remote_mock_exists(bool item_exists);
  210. void *msm_smp2p_get_remote_mock_smem_item(uint32_t *size);
  211. void *msm_smp2p_init_rmt_lpb_proc(int remote_pid);
  212. int msm_smp2p_deinit_rmt_lpb_proc(int remote_pid);
  213. void *smp2p_get_log_ctx(void);
  214. int smp2p_get_debug_mask(void);
  215. /* Inbound / outbound Interrupt configuration. */
  216. struct smp2p_interrupt_config {
  217. bool is_configured;
  218. uint32_t *out_int_ptr;
  219. uint32_t out_int_mask;
  220. int in_int_id;
  221. const char *name;
  222. /* interrupt stats */
  223. unsigned int in_interrupt_count;
  224. unsigned int out_interrupt_count;
  225. };
  226. struct smp2p_interrupt_config *smp2p_get_interrupt_config(void);
  227. const char *smp2p_pid_to_name(int remote_pid);
  228. struct smp2p_smem *smp2p_get_in_item(int remote_pid);
  229. struct smp2p_smem *smp2p_get_out_item(int remote_pid, int *state);
  230. void smp2p_gpio_open_test_entry(const char *name, int remote_pid, bool do_open);
  231. #endif