cam_cdm.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_CDM_H_
  6. #define _CAM_CDM_H_
  7. #include <linux/module.h>
  8. #include <linux/of_platform.h>
  9. #include <linux/random.h>
  10. #include <linux/spinlock_types.h>
  11. #include <linux/mutex.h>
  12. #include <linux/workqueue.h>
  13. #include <linux/bug.h>
  14. #include "cam_cdm_intf_api.h"
  15. #include "cam_soc_util.h"
  16. #include "cam_cpas_api.h"
  17. #include "cam_hw_intf.h"
  18. #include "cam_hw.h"
  19. #include "cam_debug_util.h"
  20. #define CAM_MAX_SW_CDM_VERSION_SUPPORTED 1
  21. #define CAM_SW_CDM_INDEX 0
  22. #define CAM_CDM_INFLIGHT_WORKS 5
  23. #define CAM_CDM_HW_RESET_TIMEOUT 300
  24. /*
  25. * Macros to get prepare and get information
  26. * from client CDM handles.
  27. */
  28. #define CAM_CDM_HW_ID_MASK 0xF
  29. #define CAM_CDM_HW_ID_SHIFT 0x10
  30. #define CAM_CDM_CLIENTS_ID_MASK 0xFF
  31. #define CAM_CDM_BL_FIFO_ID_MASK 0xF
  32. #define CAM_CDM_BL_FIFO_ID_SHIFT 0x8
  33. #define CAM_CDM_GET_HW_IDX(x) (((x) >> CAM_CDM_HW_ID_SHIFT) & \
  34. CAM_CDM_HW_ID_MASK)
  35. #define CAM_CDM_GET_BLFIFO_IDX(x) (((x) >> CAM_CDM_BL_FIFO_ID_SHIFT) & \
  36. CAM_CDM_BL_FIFO_ID_MASK)
  37. #define CAM_CDM_CREATE_CLIENT_HANDLE(hw_idx, priority, client_idx) \
  38. ((((hw_idx) & CAM_CDM_HW_ID_MASK) << CAM_CDM_HW_ID_SHIFT) | \
  39. (((priority) & CAM_CDM_BL_FIFO_ID_MASK) << CAM_CDM_BL_FIFO_ID_SHIFT)| \
  40. ((client_idx) & CAM_CDM_CLIENTS_ID_MASK))
  41. #define CAM_CDM_GET_CLIENT_IDX(x) ((x) & CAM_CDM_CLIENTS_ID_MASK)
  42. #define CAM_PER_CDM_MAX_REGISTERED_CLIENTS (CAM_CDM_CLIENTS_ID_MASK + 1)
  43. #define CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM (CAM_CDM_HW_ID_MASK + 1)
  44. /* Number of FIFO supported on CDM */
  45. #define CAM_CDM_NUM_BL_FIFO 0x4
  46. /* Max number of register set for different CDM */
  47. #define CAM_CDM_BL_FIFO_REG_NUM 0x4
  48. #define CAM_CDM_BL_FIFO_IRQ_REG_NUM 0x4
  49. #define CAM_CDM_BL_FIFO_PENDING_REQ_REG_NUM 0x2
  50. #define CAM_CDM_SCRATCH_REG_NUM 0xc
  51. #define CAM_CDM_COMP_WAIT_STATUS_REG_NUM 0x2
  52. #define CAM_CDM_PERF_MON_REG_NUM 0x2
  53. /* BL_FIFO configurations*/
  54. #define CAM_CDM_BL_FIFO_LENGTH_MAX_DEFAULT 0x40
  55. #define CAM_CDM_BL_FIFO_LENGTH_CFG_SHIFT 0x10
  56. #define CAM_CDM_BL_FIFO_FLUSH_SHIFT 0x3
  57. #define CAM_CDM_BL_FIFO_REQ_SIZE_MAX 0x00
  58. #define CAM_CDM_BL_FIFO_REQ_SIZE_MAX_DIV2 0x01
  59. #define CAM_CDM_BL_FIFO_REQ_SIZE_MAX_DIV4 0x10
  60. #define CAM_CDM_BL_FIFO_REQ_SIZE_MAX_DIV8 0x11
  61. /* CDM core status bitmap */
  62. #define CAM_CDM_HW_INIT_STATUS 0x0
  63. #define CAM_CDM_FIFO_0_BLDONE_STATUS 0x0
  64. #define CAM_CDM_FIFO_1_BLDONE_STATUS 0x1
  65. #define CAM_CDM_FIFO_2_BLDONE_STATUS 0x2
  66. #define CAM_CDM_FIFO_3_BLDONE_STATUS 0x3
  67. #define CAM_CDM_RESET_HW_STATUS 0x4
  68. #define CAM_CDM_ERROR_HW_STATUS 0x5
  69. #define CAM_CDM_FLUSH_HW_STATUS 0x6
  70. #define CAM_CDM_RESET_ERR_STATUS 0x7
  71. /* Curent used AHB masks and shifts */
  72. #define CAM_CDM_AHB_LOG_CID_SHIFT 28
  73. #define CAM_CDM_AHB_LOG_CID_MASK 0X30000000
  74. #define CAM_CDM_AHB_ADDR_MASK 0x00FFFFFF
  75. /* Invalid command status register's masks and shifts */
  76. #define CAM_CDM_ICL_STATUS_LAST_CID_SHIFT 4
  77. #define CAM_CDM_ICL_STATUS_LAST_CID_MASK 0X30
  78. #define CAM_CDM_ICL_STATUS_INV_CID_MASK 0x03
  79. /* Core_cfg register's masks and shifts */
  80. #define CAM_CDM_CORE_CFG_PRIORITY_MASK 0XF00000
  81. #define CAM_CDM_CORE_CFG_PRIORITY_SHIFT 20
  82. #define CAM_CDM_CORE_CFG_IMPLICIT_WAIT_EN_MASK 0x20000
  83. #define CAM_CDM_CORE_CFG_ARB_SEL_RR_MASK 0x10000
  84. #define CAM_CDM_CORE_CFG_AHB_STOP_ON_ERR_MASK 0x100
  85. #define CAM_CDM_CORE_CFG_AHB_BURST_EN_MASK 0x10
  86. #define CAM_CDM_CORE_CFG_AHB_BURST_LEN_MASK 0x0F
  87. /* Core enable register masks and shifts */
  88. #define CAM_CDM_CORE_EN_MASK 0x1
  89. #define CAM_CDM_CORE_PAUSE_MASK 0X2
  90. /* Curent BL command masks and shifts */
  91. #define CAM_CDM_CURRENT_BL_LEN 0xFFFFF
  92. #define CAM_CDM_CURRENT_BL_ARB 0x100000
  93. #define CAM_CDM_CURRENT_BL_FIFO 0xC00000
  94. #define CAM_CDM_CURRENT_BL_TAG 0xFF000000
  95. #define CAM_CDM_CURRENT_BL_ARB_SHIFT 0x14
  96. #define CAM_CDM_CURRENT_BL_FIFO_SHIFT 0x16
  97. #define CAM_CDM_CURRENT_BL_TAG_SHIFT 0x18
  98. /* IRQ bit-masks */
  99. #define CAM_CDM_IRQ_STATUS_RST_DONE_MASK 0x1
  100. #define CAM_CDM_IRQ_STATUS_INLINE_IRQ_MASK 0x2
  101. #define CAM_CDM_IRQ_STATUS_BL_DONE_MASK 0x4
  102. #define CAM_CDM_IRQ_STATUS_ERROR_INV_CMD_MASK 0x10000
  103. #define CAM_CDM_IRQ_STATUS_ERROR_OVER_FLOW_MASK 0x20000
  104. #define CAM_CDM_IRQ_STATUS_ERROR_AHB_BUS_MASK 0x40000
  105. #define CAM_CDM_IRQ_STATUS_USR_DATA_MASK 0xFF
  106. #define CAM_CDM_IRQ_STATUS_ERRORS \
  107. (CAM_CDM_IRQ_STATUS_ERROR_INV_CMD_MASK | \
  108. CAM_CDM_IRQ_STATUS_ERROR_OVER_FLOW_MASK | \
  109. CAM_CDM_IRQ_STATUS_ERROR_AHB_BUS_MASK)
  110. struct cam_cdm_pid_mid_data {
  111. int cdm_pid;
  112. int cdm_mid;
  113. int ope_cdm_pid;
  114. int ope_cdm_mid;
  115. };
  116. /* Structure to store hw version info */
  117. struct cam_version_reg {
  118. uint32_t hw_version;
  119. };
  120. /**
  121. * struct cam_cdm_irq_regs - CDM IRQ registers
  122. *
  123. * @irq_mask: register offset for irq_mask
  124. * @irq_clear: register offset for irq_clear
  125. * @irq_clear_cmd: register offset to initiate irq clear
  126. * @irq_set: register offset to set irq
  127. * @irq_set_cmd: register offset to issue set_irq from irq_set
  128. * @irq_status: register offset to look which irq is received
  129. */
  130. struct cam_cdm_irq_regs {
  131. uint32_t irq_mask;
  132. uint32_t irq_clear;
  133. uint32_t irq_clear_cmd;
  134. uint32_t irq_set;
  135. uint32_t irq_set_cmd;
  136. uint32_t irq_status;
  137. };
  138. /**
  139. * struct cam_cdm_bl_fifo_regs - BL_FIFO registers
  140. *
  141. * @bl_fifo_base: register offset to write bl_cmd base address
  142. * @bl_fifo_len: register offset to write bl_cmd length
  143. * @bl_fifo_store: register offset to commit the BL cmd
  144. * @bl_fifo_cfg: register offset to config BL_FIFO depth, etc.
  145. */
  146. struct cam_cdm_bl_fifo_regs {
  147. uint32_t bl_fifo_base;
  148. uint32_t bl_fifo_len;
  149. uint32_t bl_fifo_store;
  150. uint32_t bl_fifo_cfg;
  151. };
  152. /**
  153. * struct cam_cdm_bl_pending_req_reg_params - BL_FIFO pending registers
  154. *
  155. * @rb_offset: register offset pending bl request in BL_FIFO
  156. * @rb_mask: mask to get number of pending BLs in BL_FIFO
  157. * @rb_num_fifo: number of BL_FIFO's information in the register
  158. * @rb_next_fifo_shift: shift to get next fifo's pending BLs.
  159. */
  160. struct cam_cdm_bl_pending_req_reg_params {
  161. uint32_t rb_offset;
  162. uint32_t rb_mask;
  163. uint32_t rb_num_fifo;
  164. uint32_t rb_next_fifo_shift;
  165. };
  166. /**
  167. * struct cam_cdm_scratch_reg - scratch register
  168. *
  169. * @scratch_reg: offset of scratch register
  170. */
  171. struct cam_cdm_scratch_reg {
  172. uint32_t scratch_reg;
  173. };
  174. /* struct cam_cdm_perf_mon_regs - perf_mon registers */
  175. struct cam_cdm_perf_mon_regs {
  176. uint32_t perf_mon_ctrl;
  177. uint32_t perf_mon_0;
  178. uint32_t perf_mon_1;
  179. uint32_t perf_mon_2;
  180. };
  181. /**
  182. * struct cam_cdm_perf_mon_regs - perf mon counter's registers
  183. *
  184. * @count_cfg_0: register offset to configure perf measures
  185. * @always_count_val: register offset for always count value
  186. * @busy_count_val: register offset to get busy count
  187. * @stall_axi_count_val: register offset to get axi stall counts
  188. * @count_status: register offset to know if count status finished
  189. * for stall, busy and always.
  190. */
  191. struct cam_cdm_perf_regs {
  192. uint32_t count_cfg_0;
  193. uint32_t always_count_val;
  194. uint32_t busy_count_val;
  195. uint32_t stall_axi_count_val;
  196. uint32_t count_status;
  197. };
  198. /**
  199. * struct cam_cdm_icl_data_regs - CDM icl data registers
  200. *
  201. * @icl_last_data_0: register offset to log last known good command
  202. * @icl_last_data_1: register offset to log last known good command 1
  203. * @icl_last_data_2: register offset to log last known good command 2
  204. * @icl_inv_data: register offset to log CDM cmd that triggered
  205. * invalid command.
  206. */
  207. struct cam_cdm_icl_data_regs {
  208. uint32_t icl_last_data_0;
  209. uint32_t icl_last_data_1;
  210. uint32_t icl_last_data_2;
  211. uint32_t icl_inv_data;
  212. };
  213. /**
  214. * struct cam_cdm_icl_misc_regs - CDM icl misc registers
  215. *
  216. * @icl_inv_bl_addr: register offset to give address of bl_cmd that
  217. * gave invalid command
  218. * @icl_status: register offset for context that gave good BL
  219. * command and invalid command.
  220. */
  221. struct cam_cdm_icl_misc_regs {
  222. uint32_t icl_inv_bl_addr;
  223. uint32_t icl_status;
  224. };
  225. /**
  226. * struct cam_cdm_icl_regs - CDM icl registers
  227. *
  228. * @data_regs: structure with registers of all cdm good and invalid
  229. * BL command information.
  230. * @misc_regs: structure with registers for invalid command address
  231. * and context
  232. */
  233. struct cam_cdm_icl_regs {
  234. struct cam_cdm_icl_data_regs *data_regs;
  235. struct cam_cdm_icl_misc_regs *misc_regs;
  236. };
  237. /**
  238. * struct cam_cdm_comp_wait_status - BL_FIFO comp_event status register
  239. *
  240. * @comp_wait_status: register offset to give information on whether the
  241. * CDM is waiting for an event from another module
  242. */
  243. struct cam_cdm_comp_wait_status {
  244. uint32_t comp_wait_status;
  245. };
  246. /**
  247. * struct cam_cdm_common_reg_data - structure for register data
  248. *
  249. * @num_bl_fifo: number of FIFO are there in CDM
  250. * @num_bl_fifo_irq: number of FIFO irqs in CDM
  251. * @num_bl_pending_req_reg: number of pending_requests register in CDM
  252. * @num_scratch_reg: number of scratch registers in CDM
  253. */
  254. struct cam_cdm_common_reg_data {
  255. uint32_t num_bl_fifo;
  256. uint32_t num_bl_fifo_irq;
  257. uint32_t num_bl_pending_req_reg;
  258. uint32_t num_scratch_reg;
  259. };
  260. /**
  261. * struct cam_cdm_common_regs - common structure to get common registers
  262. * of CDM
  263. *
  264. * @cdm_hw_version: offset to read cdm_hw_version
  265. * @cam_version: offset to read the camera Titan architecture version
  266. * @rst_cmd: offset to reset the CDM
  267. * @cgc_cfg: offset to configure CDM CGC logic
  268. * @core_cfg: offset to configure CDM core with ARB_SEL, implicit
  269. * wait, etc.
  270. * @core_en: offset to pause/enable CDM
  271. * @fe_cfg: offset to configure CDM fetch engine
  272. * @irq_context_status offset to read back irq context status
  273. * @bl_fifo_rb: offset to set BL_FIFO read back
  274. * @bl_fifo_base_rb: offset to read back base address on offset set by
  275. * bl_fifo_rb
  276. * @bl_fifo_len_rb: offset to read back base len and tag on offset set by
  277. * bl_fifo_rb
  278. * @usr_data: offset to read user data from GEN_IRQ commands
  279. * @wait_status: offset to read status for last WAIT command
  280. * @last_ahb_addr: offset to read back last AHB address generated by CDM
  281. * @last_ahb_data: offset to read back last AHB data generated by CDM
  282. * @core_debug: offset to configure CDM debug bus and debug features
  283. * @last_ahb_err_addr: offset to read back last AHB Error address generated
  284. * by CDM
  285. * @last_ahb_err_data: offset to read back last AHB Error data generated
  286. * by CDM
  287. * @current_bl_base: offset to read back current command buffer BASE address
  288. * value out of BL_FIFO
  289. * @current_bl_len: offset to read back current command buffer len, TAG,
  290. * context ID ARB value out of BL_FIFO
  291. * @current_used_ahb_base: offset to read back current base address used by
  292. * CDM to access camera register
  293. * @debug_status: offset to read back current CDM status
  294. * @bus_misr_cfg0: offset to enable bus MISR and configure sampling mode
  295. * @bus_misr_cfg1: offset to select from one of the six MISR's for reading
  296. * signature value
  297. * @bus_misr_rd_val: offset to read MISR signature
  298. * @pending_req: registers to read pending request in FIFO
  299. * @comp_wait: registers to read comp_event CDM is waiting for
  300. * @perf_mon: registers to read perf_mon information
  301. * @scratch: registers to read scratch register value
  302. * @perf_reg: registers to read performance counters value
  303. * @icl_reg: registers to read information related to good
  304. * and invalid commands in FIFO
  305. * @spare: spare register
  306. * @priority_group_bit_offset offset of priority group bits
  307. *
  308. */
  309. struct cam_cdm_common_regs {
  310. uint32_t cdm_hw_version;
  311. const struct cam_version_reg *cam_version;
  312. uint32_t rst_cmd;
  313. uint32_t cgc_cfg;
  314. uint32_t core_cfg;
  315. uint32_t core_en;
  316. uint32_t fe_cfg;
  317. uint32_t irq_context_status;
  318. uint32_t bl_fifo_rb;
  319. uint32_t bl_fifo_base_rb;
  320. uint32_t bl_fifo_len_rb;
  321. uint32_t usr_data;
  322. uint32_t wait_status;
  323. uint32_t last_ahb_addr;
  324. uint32_t last_ahb_data;
  325. uint32_t core_debug;
  326. uint32_t last_ahb_err_addr;
  327. uint32_t last_ahb_err_data;
  328. uint32_t current_bl_base;
  329. uint32_t current_bl_len;
  330. uint32_t current_used_ahb_base;
  331. uint32_t debug_status;
  332. uint32_t bus_misr_cfg0;
  333. uint32_t bus_misr_cfg1;
  334. uint32_t bus_misr_rd_val;
  335. const struct cam_cdm_bl_pending_req_reg_params
  336. *pending_req[CAM_CDM_BL_FIFO_PENDING_REQ_REG_NUM];
  337. const struct cam_cdm_comp_wait_status
  338. *comp_wait[CAM_CDM_COMP_WAIT_STATUS_REG_NUM];
  339. const struct cam_cdm_perf_mon_regs
  340. *perf_mon[CAM_CDM_PERF_MON_REG_NUM];
  341. const struct cam_cdm_scratch_reg
  342. *scratch[CAM_CDM_SCRATCH_REG_NUM];
  343. const struct cam_cdm_perf_regs *perf_reg;
  344. const struct cam_cdm_icl_regs *icl_reg;
  345. uint32_t spare;
  346. uint32_t priority_group_bit_offset;
  347. struct cam_cdm_pid_mid_data *cdm_pid_mid_info;
  348. };
  349. /**
  350. * struct cam_cdm_hw_reg_offset - BL_FIFO comp_event status register
  351. *
  352. * @cmn_reg: pointer to structure to get common registers of a CDM
  353. * @bl_fifo_reg: pointer to structure to get BL_FIFO registers of a CDM
  354. * @irq_reg: pointer to structure to get IRQ registers of a CDM
  355. * @reg_data: pointer to structure to reg_data related to CDM
  356. * registers
  357. */
  358. struct cam_cdm_hw_reg_offset {
  359. const struct cam_cdm_common_regs *cmn_reg;
  360. const struct cam_cdm_bl_fifo_regs *bl_fifo_reg[CAM_CDM_BL_FIFO_REG_NUM];
  361. const struct cam_cdm_irq_regs *irq_reg[CAM_CDM_BL_FIFO_IRQ_REG_NUM];
  362. const struct cam_cdm_common_reg_data *reg_data;
  363. };
  364. /* enum cam_cdm_hw_process_intf_cmd - interface commands.*/
  365. enum cam_cdm_hw_process_intf_cmd {
  366. CAM_CDM_HW_INTF_CMD_ACQUIRE,
  367. CAM_CDM_HW_INTF_CMD_RELEASE,
  368. CAM_CDM_HW_INTF_CMD_SUBMIT_BL,
  369. CAM_CDM_HW_INTF_CMD_RESET_HW,
  370. CAM_CDM_HW_INTF_CMD_FLUSH_HW,
  371. CAM_CDM_HW_INTF_CMD_HANDLE_ERROR,
  372. CAM_CDM_HW_INTF_CMD_HANG_DETECT,
  373. CAM_CDM_HW_INTF_DUMP_DBG_REGS,
  374. CAM_CDM_HW_INTF_CMD_INVALID,
  375. };
  376. /* enum cam_cdm_flags - Bit fields for CDM flags used */
  377. enum cam_cdm_flags {
  378. CAM_CDM_FLAG_SHARED_CDM,
  379. CAM_CDM_FLAG_PRIVATE_CDM,
  380. };
  381. /* enum cam_cdm_type - Enum for possible CAM CDM types */
  382. enum cam_cdm_type {
  383. CAM_VIRTUAL_CDM,
  384. CAM_HW_CDM,
  385. };
  386. /* enum cam_cdm_mem_base_index - Enum for possible CAM CDM types */
  387. enum cam_cdm_mem_base_index {
  388. CAM_HW_CDM_BASE_INDEX,
  389. CAM_HW_CDM_MAX_INDEX = CAM_SOC_MAX_BLOCK,
  390. };
  391. /* enum cam_cdm_bl_cb_type - Enum for possible CAM CDM cb request types */
  392. enum cam_cdm_bl_cb_type {
  393. CAM_HW_CDM_BL_CB_CLIENT = 1,
  394. CAM_HW_CDM_BL_CB_INTERNAL,
  395. };
  396. /* enum cam_cdm_arbitration - Enum type of arbitration */
  397. enum cam_cdm_arbitration {
  398. CAM_CDM_ARBITRATION_NONE,
  399. CAM_CDM_ARBITRATION_ROUND_ROBIN,
  400. CAM_CDM_ARBITRATION_PRIORITY_BASED,
  401. CAM_CDM_ARBITRATION_MAX,
  402. };
  403. enum cam_cdm_hw_version {
  404. CAM_CDM_VERSION = 0,
  405. CAM_CDM_VERSION_1_0 = 0x10000000,
  406. CAM_CDM_VERSION_1_1 = 0x10010000,
  407. CAM_CDM_VERSION_1_2 = 0x10020000,
  408. CAM_CDM_VERSION_2_0 = 0x20000000,
  409. CAM_CDM_VERSION_2_1 = 0x20010000,
  410. CAM_CDM_VERSION_MAX,
  411. };
  412. /* struct cam_cdm_client - struct for cdm clients data.*/
  413. struct cam_cdm_client {
  414. struct cam_cdm_acquire_data data;
  415. void __iomem *changebase_addr;
  416. uint32_t stream_on;
  417. uint32_t refcount;
  418. struct mutex lock;
  419. uint32_t handle;
  420. };
  421. /* struct cam_cdm_work_payload - struct for cdm work payload data.*/
  422. struct cam_cdm_work_payload {
  423. struct cam_hw_info *hw;
  424. uint32_t irq_status;
  425. uint32_t irq_data;
  426. int fifo_idx;
  427. ktime_t workq_scheduled_ts;
  428. struct work_struct work;
  429. };
  430. /* struct cam_cdm_bl_cb_request_entry - callback entry for work to process.*/
  431. struct cam_cdm_bl_cb_request_entry {
  432. uint8_t bl_tag;
  433. enum cam_cdm_bl_cb_type request_type;
  434. uint32_t client_hdl;
  435. void *userdata;
  436. uint32_t cookie;
  437. struct list_head entry;
  438. };
  439. /* struct cam_cdm_hw_intf_cmd_submit_bl - cdm interface submit command.*/
  440. struct cam_cdm_hw_intf_cmd_submit_bl {
  441. uint32_t handle;
  442. struct cam_cdm_bl_request *data;
  443. };
  444. /* struct cam_cdm_hw_mem - CDM hw memory struct */
  445. struct cam_cdm_hw_mem {
  446. int32_t handle;
  447. uint32_t vaddr;
  448. uintptr_t kmdvaddr;
  449. size_t size;
  450. };
  451. /* struct cam_cdm_bl_fifo - CDM hw memory struct */
  452. struct cam_cdm_bl_fifo {
  453. struct completion bl_complete;
  454. struct workqueue_struct *work_queue;
  455. struct list_head bl_request_list;
  456. struct mutex fifo_lock;
  457. uint8_t bl_tag;
  458. uint32_t bl_depth;
  459. uint8_t last_bl_tag_done;
  460. atomic_t work_record;
  461. };
  462. /**
  463. * struct cam_cdm - CDM hw device struct
  464. *
  465. * @index: index of CDM hardware
  466. * @name: cdm_name
  467. * @id: enum for possible CDM hardwares
  468. * @flags: enum to tell if CDM is private of shared
  469. * @reset_complete: completion event to make CDM wait for reset
  470. * @work_queue: workqueue to schedule work for virtual CDM
  471. * @bl_request_list: bl_request list for submitted commands in
  472. * virtual CDM
  473. * @version: CDM version with major, minor, incr and reserved
  474. * @hw_version: CDM version as read from the cdm_version register
  475. * @hw_family_version: version of hw family the CDM belongs to
  476. * @iommu_hdl: CDM iommu handle
  477. * @offsets: pointer to structure of CDM registers
  478. * @ops: CDM ops for generating cdm commands
  479. * @clients: CDM clients array currently active on CDM
  480. * @bl_fifo: structure with per fifo related attributes
  481. * @cdm_status: bitfield with bits assigned for different cdm status
  482. * @bl_tag: slot value at which the next bl cmd will be written
  483. * in case of virtual CDM
  484. * @gen_irq: memory region in which gen_irq command will be written
  485. * @cpas_handle: handle for cpas driver
  486. * @arbitration: type of arbitration to be used for the CDM
  487. */
  488. struct cam_cdm {
  489. uint32_t index;
  490. char name[128];
  491. enum cam_cdm_id id;
  492. enum cam_cdm_flags flags;
  493. struct completion reset_complete;
  494. struct workqueue_struct *work_queue;
  495. struct list_head bl_request_list;
  496. struct cam_hw_version version;
  497. uint32_t hw_version;
  498. uint32_t hw_family_version;
  499. struct cam_iommu_handle iommu_hdl;
  500. struct cam_cdm_hw_reg_offset *offsets;
  501. struct cam_cdm_utils_ops *ops;
  502. struct cam_cdm_client *clients[CAM_PER_CDM_MAX_REGISTERED_CLIENTS];
  503. struct cam_cdm_bl_fifo bl_fifo[CAM_CDM_BL_FIFO_MAX];
  504. unsigned long cdm_status;
  505. uint8_t bl_tag;
  506. struct cam_cdm_hw_mem gen_irq[CAM_CDM_BL_FIFO_MAX];
  507. uint32_t cpas_handle;
  508. enum cam_cdm_arbitration arbitration;
  509. };
  510. /* struct cam_cdm_private_dt_data - CDM hw custom dt data */
  511. struct cam_cdm_private_dt_data {
  512. bool dt_cdm_shared;
  513. bool config_fifo;
  514. bool is_single_ctx_cdm;
  515. uint8_t priority_group;
  516. uint32_t fifo_depth[CAM_CDM_BL_FIFO_MAX];
  517. uint32_t dt_num_supported_clients;
  518. const char *dt_cdm_client_name[CAM_PER_CDM_MAX_REGISTERED_CLIENTS];
  519. };
  520. /* struct cam_cdm_intf_devices - CDM mgr interface devices */
  521. struct cam_cdm_intf_devices {
  522. struct mutex lock;
  523. uint32_t refcount;
  524. struct cam_hw_intf *device;
  525. struct cam_cdm_private_dt_data *data;
  526. };
  527. /* struct cam_cdm_intf_mgr - CDM mgr interface device struct */
  528. struct cam_cdm_intf_mgr {
  529. bool probe_done;
  530. uint32_t cdm_count;
  531. uint32_t dt_supported_hw_cdm;
  532. int32_t refcount;
  533. struct cam_cdm_intf_devices nodes[CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM];
  534. };
  535. int cam_cdm_intf_register_hw_cdm(struct cam_hw_intf *hw,
  536. struct cam_cdm_private_dt_data *data, enum cam_cdm_type type,
  537. uint32_t *index);
  538. int cam_cdm_intf_deregister_hw_cdm(struct cam_hw_intf *hw,
  539. struct cam_cdm_private_dt_data *data, enum cam_cdm_type type,
  540. uint32_t index);
  541. #endif /* _CAM_CDM_H_ */