gsi_reg.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2018-2023 Linaro Ltd.
  4. */
  5. #ifndef _GSI_REG_H_
  6. #define _GSI_REG_H_
  7. /* === Only "gsi.c" and "gsi_reg.c" should include this file === */
  8. #include <linux/bits.h>
  9. struct platform_device;
  10. struct gsi;
  11. /**
  12. * DOC: GSI Registers
  13. *
  14. * GSI registers are located within the "gsi" address space defined by Device
  15. * Tree. The offset of each register within that space is specified by
  16. * symbols defined below. The GSI address space is mapped to virtual memory
  17. * space in gsi_init(). All GSI registers are 32 bits wide.
  18. *
  19. * Each register type is duplicated for a number of instances of something.
  20. * For example, each GSI channel has its own set of registers defining its
  21. * configuration. The offset to a channel's set of registers is computed
  22. * based on a "base" offset plus an additional "stride" amount computed
  23. * from the channel's ID. For such registers, the offset is computed by a
  24. * function-like macro that takes a parameter used in the computation.
  25. *
  26. * The offset of a register dependent on execution environment is computed
  27. * by a macro that is supplied a parameter "ee". The "ee" value is a member
  28. * of the gsi_ee_id enumerated type.
  29. *
  30. * The offset of a channel register is computed by a macro that is supplied a
  31. * parameter "ch". The "ch" value is a channel id whose maximum value is 30
  32. * (though the actual limit is hardware-dependent).
  33. *
  34. * The offset of an event register is computed by a macro that is supplied a
  35. * parameter "ev". The "ev" value is an event id whose maximum value is 15
  36. * (though the actual limit is hardware-dependent).
  37. */
  38. /* enum gsi_reg_id - GSI register IDs */
  39. enum gsi_reg_id {
  40. INTER_EE_SRC_CH_IRQ_MSK, /* IPA v3.5+ */
  41. INTER_EE_SRC_EV_CH_IRQ_MSK, /* IPA v3.5+ */
  42. CH_C_CNTXT_0,
  43. CH_C_CNTXT_1,
  44. CH_C_CNTXT_2,
  45. CH_C_CNTXT_3,
  46. CH_C_QOS,
  47. CH_C_SCRATCH_0,
  48. CH_C_SCRATCH_1,
  49. CH_C_SCRATCH_2,
  50. CH_C_SCRATCH_3,
  51. EV_CH_E_CNTXT_0,
  52. EV_CH_E_CNTXT_1,
  53. EV_CH_E_CNTXT_2,
  54. EV_CH_E_CNTXT_3,
  55. EV_CH_E_CNTXT_4,
  56. EV_CH_E_CNTXT_8,
  57. EV_CH_E_CNTXT_9,
  58. EV_CH_E_CNTXT_10,
  59. EV_CH_E_CNTXT_11,
  60. EV_CH_E_CNTXT_12,
  61. EV_CH_E_CNTXT_13,
  62. EV_CH_E_SCRATCH_0,
  63. EV_CH_E_SCRATCH_1,
  64. CH_C_DOORBELL_0,
  65. EV_CH_E_DOORBELL_0,
  66. GSI_STATUS,
  67. CH_CMD,
  68. EV_CH_CMD,
  69. GENERIC_CMD,
  70. HW_PARAM_2, /* IPA v3.5.1+ */
  71. HW_PARAM_4, /* IPA v5.0+ */
  72. CNTXT_TYPE_IRQ,
  73. CNTXT_TYPE_IRQ_MSK,
  74. CNTXT_SRC_CH_IRQ,
  75. CNTXT_SRC_CH_IRQ_MSK,
  76. CNTXT_SRC_CH_IRQ_CLR,
  77. CNTXT_SRC_EV_CH_IRQ,
  78. CNTXT_SRC_EV_CH_IRQ_MSK,
  79. CNTXT_SRC_EV_CH_IRQ_CLR,
  80. CNTXT_SRC_IEOB_IRQ,
  81. CNTXT_SRC_IEOB_IRQ_MSK,
  82. CNTXT_SRC_IEOB_IRQ_CLR,
  83. CNTXT_GLOB_IRQ_STTS,
  84. CNTXT_GLOB_IRQ_EN,
  85. CNTXT_GLOB_IRQ_CLR,
  86. CNTXT_GSI_IRQ_STTS,
  87. CNTXT_GSI_IRQ_EN,
  88. CNTXT_GSI_IRQ_CLR,
  89. CNTXT_INTSET,
  90. ERROR_LOG,
  91. ERROR_LOG_CLR,
  92. CNTXT_SCRATCH_0,
  93. GSI_REG_ID_COUNT, /* Last; not an ID */
  94. };
  95. /* CH_C_CNTXT_0 register */
  96. enum gsi_reg_ch_c_cntxt_0_field_id {
  97. CHTYPE_PROTOCOL,
  98. CHTYPE_DIR,
  99. CH_EE,
  100. CHID,
  101. CHTYPE_PROTOCOL_MSB, /* IPA v4.5-4.11 */
  102. ERINDEX, /* Not IPA v5.0+ */
  103. CHSTATE,
  104. ELEMENT_SIZE,
  105. };
  106. /** enum gsi_channel_type - CHTYPE_PROTOCOL field values in CH_C_CNTXT_0 */
  107. enum gsi_channel_type {
  108. GSI_CHANNEL_TYPE_MHI = 0x0,
  109. GSI_CHANNEL_TYPE_XHCI = 0x1,
  110. GSI_CHANNEL_TYPE_GPI = 0x2,
  111. GSI_CHANNEL_TYPE_XDCI = 0x3,
  112. GSI_CHANNEL_TYPE_WDI2 = 0x4,
  113. GSI_CHANNEL_TYPE_GCI = 0x5,
  114. GSI_CHANNEL_TYPE_WDI3 = 0x6,
  115. GSI_CHANNEL_TYPE_MHIP = 0x7,
  116. GSI_CHANNEL_TYPE_AQC = 0x8,
  117. GSI_CHANNEL_TYPE_11AD = 0x9,
  118. };
  119. /* CH_C_CNTXT_1 register */
  120. enum gsi_reg_ch_c_cntxt_1_field_id {
  121. CH_R_LENGTH,
  122. CH_ERINDEX, /* IPA v5.0+ */
  123. };
  124. /* CH_C_QOS register */
  125. enum gsi_reg_ch_c_qos_field_id {
  126. WRR_WEIGHT,
  127. MAX_PREFETCH,
  128. USE_DB_ENG,
  129. USE_ESCAPE_BUF_ONLY, /* IPA v4.0-4.2 */
  130. PREFETCH_MODE, /* IPA v4.5+ */
  131. EMPTY_LVL_THRSHOLD, /* IPA v4.5+ */
  132. DB_IN_BYTES, /* IPA v4.9+ */
  133. LOW_LATENCY_EN, /* IPA v5.0+ */
  134. };
  135. /** enum gsi_prefetch_mode - PREFETCH_MODE field in CH_C_QOS */
  136. enum gsi_prefetch_mode {
  137. USE_PREFETCH_BUFS = 0,
  138. ESCAPE_BUF_ONLY = 1,
  139. SMART_PREFETCH = 2,
  140. FREE_PREFETCH = 3,
  141. };
  142. /* EV_CH_E_CNTXT_0 register */
  143. enum gsi_reg_ch_c_ev_ch_e_cntxt_0_field_id {
  144. EV_CHTYPE, /* enum gsi_channel_type */
  145. EV_EE, /* enum gsi_ee_id; always GSI_EE_AP for us */
  146. EV_EVCHID,
  147. EV_INTYPE,
  148. EV_CHSTATE,
  149. EV_ELEMENT_SIZE,
  150. };
  151. /* EV_CH_E_CNTXT_1 register */
  152. enum gsi_reg_ev_ch_c_cntxt_1_field_id {
  153. R_LENGTH,
  154. };
  155. /* EV_CH_E_CNTXT_8 register */
  156. enum gsi_reg_ch_c_ev_ch_e_cntxt_8_field_id {
  157. EV_MODT,
  158. EV_MODC,
  159. EV_MOD_CNT,
  160. };
  161. /* GSI_STATUS register */
  162. enum gsi_reg_gsi_status_field_id {
  163. ENABLED,
  164. };
  165. /* CH_CMD register */
  166. enum gsi_reg_gsi_ch_cmd_field_id {
  167. CH_CHID,
  168. CH_OPCODE,
  169. };
  170. /** enum gsi_ch_cmd_opcode - CH_OPCODE field values in CH_CMD */
  171. enum gsi_ch_cmd_opcode {
  172. GSI_CH_ALLOCATE = 0x0,
  173. GSI_CH_START = 0x1,
  174. GSI_CH_STOP = 0x2,
  175. GSI_CH_RESET = 0x9,
  176. GSI_CH_DE_ALLOC = 0xa,
  177. GSI_CH_DB_STOP = 0xb,
  178. };
  179. /* EV_CH_CMD register */
  180. enum gsi_ev_ch_cmd_field_id {
  181. EV_CHID,
  182. EV_OPCODE,
  183. };
  184. /** enum gsi_evt_cmd_opcode - EV_OPCODE field values in EV_CH_CMD */
  185. enum gsi_evt_cmd_opcode {
  186. GSI_EVT_ALLOCATE = 0x0,
  187. GSI_EVT_RESET = 0x9,
  188. GSI_EVT_DE_ALLOC = 0xa,
  189. };
  190. /* GENERIC_CMD register */
  191. enum gsi_generic_cmd_field_id {
  192. GENERIC_OPCODE,
  193. GENERIC_CHID,
  194. GENERIC_EE,
  195. GENERIC_PARAMS, /* IPA v4.11+ */
  196. };
  197. /** enum gsi_generic_cmd_opcode - GENERIC_OPCODE field values in GENERIC_CMD */
  198. enum gsi_generic_cmd_opcode {
  199. GSI_GENERIC_HALT_CHANNEL = 0x1,
  200. GSI_GENERIC_ALLOCATE_CHANNEL = 0x2,
  201. GSI_GENERIC_ENABLE_FLOW_CONTROL = 0x3, /* IPA v4.2+ */
  202. GSI_GENERIC_DISABLE_FLOW_CONTROL = 0x4, /* IPA v4.2+ */
  203. GSI_GENERIC_QUERY_FLOW_CONTROL = 0x5, /* IPA v4.11+ */
  204. };
  205. /* HW_PARAM_2 register */ /* IPA v3.5.1+ */
  206. enum gsi_hw_param_2_field_id {
  207. IRAM_SIZE,
  208. NUM_CH_PER_EE,
  209. NUM_EV_PER_EE, /* Not IPA v5.0+ */
  210. GSI_CH_PEND_TRANSLATE,
  211. GSI_CH_FULL_LOGIC,
  212. GSI_USE_SDMA, /* IPA v4.0+ */
  213. GSI_SDMA_N_INT, /* IPA v4.0+ */
  214. GSI_SDMA_MAX_BURST, /* IPA v4.0+ */
  215. GSI_SDMA_N_IOVEC, /* IPA v4.0+ */
  216. GSI_USE_RD_WR_ENG, /* IPA v4.2+ */
  217. GSI_USE_INTER_EE, /* IPA v4.2+ */
  218. };
  219. /** enum gsi_iram_size - IRAM_SIZE field values in HW_PARAM_2 */
  220. enum gsi_iram_size {
  221. IRAM_SIZE_ONE_KB = 0x0,
  222. IRAM_SIZE_TWO_KB = 0x1,
  223. /* The next two values are available for IPA v4.0 and above */
  224. IRAM_SIZE_TWO_N_HALF_KB = 0x2,
  225. IRAM_SIZE_THREE_KB = 0x3,
  226. /* The next two values are available for IPA v4.5 and above */
  227. IRAM_SIZE_THREE_N_HALF_KB = 0x4,
  228. IRAM_SIZE_FOUR_KB = 0x5,
  229. };
  230. /* HW_PARAM_4 register */ /* IPA v5.0+ */
  231. enum gsi_hw_param_4_field_id {
  232. EV_PER_EE,
  233. IRAM_PROTOCOL_COUNT,
  234. };
  235. /**
  236. * enum gsi_irq_type_id: GSI IRQ types
  237. * @GSI_CH_CTRL: Channel allocation, deallocation, etc.
  238. * @GSI_EV_CTRL: Event ring allocation, deallocation, etc.
  239. * @GSI_GLOB_EE: Global/general event
  240. * @GSI_IEOB: Transfer (TRE) completion
  241. * @GSI_INTER_EE_CH_CTRL: Remote-issued stop/reset (unused)
  242. * @GSI_INTER_EE_EV_CTRL: Remote-issued event reset (unused)
  243. * @GSI_GENERAL: General hardware event (bus error, etc.)
  244. */
  245. enum gsi_irq_type_id {
  246. GSI_CH_CTRL = BIT(0),
  247. GSI_EV_CTRL = BIT(1),
  248. GSI_GLOB_EE = BIT(2),
  249. GSI_IEOB = BIT(3),
  250. GSI_INTER_EE_CH_CTRL = BIT(4),
  251. GSI_INTER_EE_EV_CTRL = BIT(5),
  252. GSI_GENERAL = BIT(6),
  253. /* IRQ types 7-31 (and their bit values) are reserved */
  254. };
  255. /** enum gsi_global_irq_id: Global GSI interrupt events */
  256. enum gsi_global_irq_id {
  257. ERROR_INT = BIT(0),
  258. GP_INT1 = BIT(1),
  259. GP_INT2 = BIT(2),
  260. GP_INT3 = BIT(3),
  261. /* Global IRQ types 4-31 (and their bit values) are reserved */
  262. };
  263. /** enum gsi_general_irq_id: GSI general IRQ conditions */
  264. enum gsi_general_irq_id {
  265. BREAK_POINT = BIT(0),
  266. BUS_ERROR = BIT(1),
  267. CMD_FIFO_OVRFLOW = BIT(2),
  268. MCS_STACK_OVRFLOW = BIT(3),
  269. /* General IRQ types 4-31 (and their bit values) are reserved */
  270. };
  271. /* CNTXT_INTSET register */
  272. enum gsi_cntxt_intset_field_id {
  273. INTYPE,
  274. };
  275. /* ERROR_LOG register */
  276. enum gsi_error_log_field_id {
  277. ERR_ARG3,
  278. ERR_ARG2,
  279. ERR_ARG1,
  280. ERR_CODE,
  281. ERR_VIRT_IDX,
  282. ERR_TYPE,
  283. ERR_EE,
  284. };
  285. /** enum gsi_err_code - ERR_CODE field values in EE_ERR_LOG */
  286. enum gsi_err_code {
  287. GSI_INVALID_TRE = 0x1,
  288. GSI_OUT_OF_BUFFERS = 0x2,
  289. GSI_OUT_OF_RESOURCES = 0x3,
  290. GSI_UNSUPPORTED_INTER_EE_OP = 0x4,
  291. GSI_EVT_RING_EMPTY = 0x5,
  292. GSI_NON_ALLOCATED_EVT_ACCESS = 0x6,
  293. /* 7 is not assigned */
  294. GSI_HWO_1 = 0x8,
  295. };
  296. /** enum gsi_err_type - ERR_TYPE field values in EE_ERR_LOG */
  297. enum gsi_err_type {
  298. GSI_ERR_TYPE_GLOB = 0x1,
  299. GSI_ERR_TYPE_CHAN = 0x2,
  300. GSI_ERR_TYPE_EVT = 0x3,
  301. };
  302. /* CNTXT_SCRATCH_0 register */
  303. enum gsi_cntxt_scratch_0_field_id {
  304. INTER_EE_RESULT,
  305. GENERIC_EE_RESULT,
  306. };
  307. /** enum gsi_generic_ee_result - GENERIC_EE_RESULT field values in SCRATCH_0 */
  308. enum gsi_generic_ee_result {
  309. GENERIC_EE_SUCCESS = 0x1,
  310. GENERIC_EE_INCORRECT_CHANNEL_STATE = 0x2,
  311. GENERIC_EE_INCORRECT_DIRECTION = 0x3,
  312. GENERIC_EE_INCORRECT_CHANNEL_TYPE = 0x4,
  313. GENERIC_EE_INCORRECT_CHANNEL = 0x5,
  314. GENERIC_EE_RETRY = 0x6,
  315. GENERIC_EE_NO_RESOURCES = 0x7,
  316. };
  317. extern const struct regs gsi_regs_v3_1;
  318. extern const struct regs gsi_regs_v3_5_1;
  319. extern const struct regs gsi_regs_v4_0;
  320. extern const struct regs gsi_regs_v4_5;
  321. extern const struct regs gsi_regs_v4_9;
  322. extern const struct regs gsi_regs_v4_11;
  323. extern const struct regs gsi_regs_v5_0;
  324. /**
  325. * gsi_reg() - Return the structure describing a GSI register
  326. * @gsi: GSI pointer
  327. * @reg_id: GSI register ID
  328. */
  329. const struct reg *gsi_reg(struct gsi *gsi, enum gsi_reg_id reg_id);
  330. /**
  331. * gsi_reg_init() - Perform GSI register initialization
  332. * @gsi: GSI pointer
  333. * @pdev: GSI (IPA) platform device
  334. *
  335. * Initialize GSI registers, including looking up and I/O mapping
  336. * the "gsi" memory space.
  337. */
  338. int gsi_reg_init(struct gsi *gsi, struct platform_device *pdev);
  339. /**
  340. * gsi_reg_exit() - Inverse of gsi_reg_init()
  341. * @gsi: GSI pointer
  342. */
  343. void gsi_reg_exit(struct gsi *gsi);
  344. #endif /* _GSI_REG_H_ */