cam_cpas_hw.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _CAM_CPAS_HW_H_
  7. #define _CAM_CPAS_HW_H_
  8. #include <dt-bindings/msm-camera.h>
  9. #include "cam_cpas_api.h"
  10. #include "cam_cpas_hw_intf.h"
  11. #include "cam_common_util.h"
  12. #include "cam_soc_bus.h"
  13. #define CAM_CPAS_INFLIGHT_WORKS 5
  14. #define CAM_CPAS_MAX_CLIENTS 43
  15. #define CAM_CPAS_MAX_AXI_PORTS 6
  16. #define CAM_CPAS_MAX_DRV_PORTS 4
  17. #define CAM_CPAS_MAX_TREE_LEVELS 4
  18. #define CAM_CPAS_MAX_RT_WR_NIU_NODES 10
  19. #define CAM_CPAS_MAX_GRAN_PATHS_PER_CLIENT 32
  20. #define CAM_CPAS_PATH_DATA_MAX 42
  21. #define CAM_CPAS_TRANSACTION_MAX 2
  22. #define CAM_CAMNOC_FILL_LVL_REG_INFO_MAX 6
  23. #define CAM_CPAS_MAX_SLOPE_FACTOR 100
  24. #define CAM_CPAS_MAX_STRESS_INDICATOR 100
  25. /* Number of camera (CAM_SS) instances */
  26. #define CAM_CPAS_CAMERA_INSTANCES 1
  27. #define CAM_CPAS_AXI_MIN_MNOC_AB_BW (2048 * 1024)
  28. #define CAM_CPAS_AXI_MIN_MNOC_IB_BW (2048 * 1024)
  29. #define CAM_CPAS_AXI_MIN_CAMNOC_AB_BW (2048 * 1024)
  30. #define CAM_CPAS_AXI_MIN_CAMNOC_IB_BW (3000000000UL)
  31. #define CAM_CPAS_GET_CLIENT_IDX(handle) (handle)
  32. #define CAM_CPAS_GET_CLIENT_HANDLE(indx) (indx)
  33. #define CAM_CPAS_WORKQUEUE_NAME "cam-cpas"
  34. #define CAM_CPAS_CLIENT_VALID(indx) \
  35. ((indx >= 0) && (indx < CAM_CPAS_MAX_CLIENTS))
  36. #define CAM_CPAS_CLIENT_REGISTERED(cpas_core, indx) \
  37. ((CAM_CPAS_CLIENT_VALID(indx)) && \
  38. (cpas_core->cpas_client[indx]->registered))
  39. #define CAM_CPAS_CLIENT_STARTED(cpas_core, indx) \
  40. ((CAM_CPAS_CLIENT_REGISTERED(cpas_core, indx)) && \
  41. (cpas_core->cpas_client[indx]->started))
  42. /* Array indices to represent corresponding RPMH BCM info */
  43. #define CAM_RPMH_NUMBER_OF_BCMS 0
  44. #define CAM_RPMH_BCM_FE_OFFSET 1
  45. #define CAM_RPMH_BCM_BE_OFFSET 2
  46. #define CAM_RPMH_BCM_DDR_INDEX 3
  47. #define CAM_RPMH_BCM_MNOC_INDEX 4
  48. #define CAM_RPMH_BCM_INFO_MAX 5
  49. #define CAM_CPAS_MONITOR_MAX_ENTRIES 100
  50. #define CAM_CPAS_INC_MONITOR_HEAD(head, ret) \
  51. div_u64_rem(atomic64_add_return(1, head),\
  52. CAM_CPAS_MONITOR_MAX_ENTRIES, (ret))
  53. #define CAM_CPAS_MAX_CESTA_VCD_NUM 9
  54. #define CAM_CPAS_DUMP_NUM_WORDS_COMM 20
  55. #define CAM_CPAS_DUMP_NUM_WORDS_VOTE_TYEP_DRV 4
  56. #define CAM_CPAS_DUMP_NUM_WORDS_VOTE_TYEP_HLOS 2
  57. #define CAM_CPAS_DUMP_NUM_WORDS_RT_WR_NIUS 2
  58. #define CAM_CPAS_DUMP_NUM_WORDS_VCD_CURR_LVL 2
  59. /**
  60. * enum cam_camnoc_domain_type - Enum for different camnoc domains
  61. * @CAM_CAMNOC_HW_COMBINED: refer to legacy camnoc info that combines RT/NRT HW
  62. * @CAM_CAMNOC_HW_RT: type for camnoc RT info
  63. * @CAM_CAMNOC_HW_NRT: type for camnoc NRT info
  64. * @CAM_CAMNOC_HW_TYPE_MAX: camnoc info maximum type
  65. */
  66. enum cam_camnoc_hw_type {
  67. CAM_CAMNOC_HW_COMBINED,
  68. CAM_CAMNOC_HW_RT,
  69. CAM_CAMNOC_HW_NRT,
  70. CAM_CAMNOC_HW_TYPE_MAX,
  71. };
  72. /**
  73. * enum cam_cpas_access_type - Enum for Register access type
  74. */
  75. enum cam_cpas_access_type {
  76. CAM_REG_TYPE_READ,
  77. CAM_REG_TYPE_WRITE,
  78. CAM_REG_TYPE_READ_WRITE,
  79. };
  80. /**
  81. * struct cam_cpas_vdd_ahb_mapping : Voltage to ahb level mapping
  82. *
  83. * @vdd_corner : Voltage corner value
  84. * @ahb_level : AHB vote level corresponds to this vdd_corner
  85. *
  86. */
  87. struct cam_cpas_vdd_ahb_mapping {
  88. unsigned int vdd_corner;
  89. enum cam_vote_level ahb_level;
  90. };
  91. /**
  92. * struct cam_cpas_bw_vote : AXI bw vote
  93. *
  94. * @ab: AB bw value
  95. * @ib: IB bw value
  96. * @camnoc: CAMNOC bw value
  97. *
  98. */
  99. struct cam_cpas_bw_vote {
  100. uint64_t ab;
  101. uint64_t ib;
  102. uint64_t camnoc;
  103. };
  104. /**
  105. * struct cam_cpas_drv_vote : DRV bw vote
  106. *
  107. * @high: Active bw values
  108. * @low: Sleep bw values
  109. *
  110. */
  111. struct cam_cpas_drv_vote {
  112. struct cam_cpas_bw_vote high;
  113. struct cam_cpas_bw_vote low;
  114. };
  115. /**
  116. * struct cam_cpas_axi_bw_info : AXI bw info
  117. *
  118. * @vote_type: HLOS or DRV vote type
  119. * @hlos_vote: HLOS bw values
  120. * @drv_vote: DRV bw values
  121. *
  122. */
  123. struct cam_cpas_axi_bw_info {
  124. enum cam_cpas_vote_type vote_type;
  125. union {
  126. struct cam_cpas_bw_vote hlos_vote;
  127. struct cam_cpas_drv_vote drv_vote;
  128. };
  129. };
  130. /**
  131. * struct cam_cpas_kobj_map: wrapper structure for base kobject
  132. * and cam cpas private soc info
  133. * @base_kobj: kernel object for camera sysfs
  134. * @cpas_hw: pointer to cam_hw_info structure
  135. */
  136. struct cam_cpas_kobj_map {
  137. struct kobject base_kobj;
  138. struct cam_hw_info *cpas_hw;
  139. };
  140. /**
  141. * struct cam_cpas_internal_ops - CPAS Hardware layer internal ops
  142. *
  143. * @get_hw_info: Function pointer for get hw info
  144. * @init_hw_version: Function pointer for hw init based on version
  145. * @handle_irq: Function poniter for irq handling
  146. * @setup_regbase: Function pointer for setup rebase indices
  147. * @power_on: Function pointer for hw core specific power on settings
  148. * @power_off: Function pointer for hw core specific power off settings
  149. * @setup_qos_settings: Function pointer for hw to select a specific qos header
  150. * @print_poweron_settings: Function pointer for hw to print poweron settings
  151. * @qchannel_handshake: Function pointer for hw core specific qchannel
  152. * handshake settings
  153. * @set_tpg_mux_sel: Set tpg mux select on CPAS TOP register
  154. *
  155. */
  156. struct cam_cpas_internal_ops {
  157. int (*get_hw_info)(struct cam_hw_info *cpas_hw,
  158. struct cam_cpas_hw_caps *hw_caps);
  159. int (*init_hw_version)(struct cam_hw_info *cpas_hw,
  160. struct cam_cpas_hw_caps *hw_caps);
  161. irqreturn_t (*handle_irq)(int irq_num, void *data);
  162. int (*setup_regbase)(struct cam_hw_soc_info *soc_info,
  163. int32_t regbase_index[], int32_t num_reg_map);
  164. int (*power_on)(struct cam_hw_info *cpas_hw);
  165. int (*power_off)(struct cam_hw_info *cpas_hw);
  166. int (*setup_qos_settings)(struct cam_hw_info *cpas_hw,
  167. uint32_t selection_mask);
  168. int (*print_poweron_settings)(struct cam_hw_info *cpas_hw);
  169. int (*qchannel_handshake)(struct cam_hw_info *cpas_hw, bool power_on, bool force_on);
  170. int (*set_tpg_mux_sel)(struct cam_hw_info *cpas_hw, uint32_t tpg_num);
  171. };
  172. /**
  173. * struct cam_cpas_reg : CPAS register info
  174. *
  175. * @enable: Whether this reg info need to be enabled
  176. * @access_type: Register access type
  177. * @masked_value: Whether this register write/read is based on mask, shift
  178. * @mask: Mask for this register value
  179. * @shift: Shift for this register value
  180. * @value: Register value
  181. *
  182. */
  183. struct cam_cpas_reg {
  184. bool enable;
  185. enum cam_cpas_access_type access_type;
  186. bool masked_value;
  187. uint32_t offset;
  188. uint32_t mask;
  189. uint32_t shift;
  190. uint32_t value;
  191. };
  192. /**
  193. * struct cam_cpas_client : CPAS Client structure info
  194. *
  195. * @data: Client register params
  196. * @registered: Whether client has registered with cpas
  197. * @started: Whether client has streamed on
  198. * @tree_node_valid: Indicates whether tree node has at least one valid node
  199. * @is_drv_dyn: Indicates whether this client is DRV dynamic voting client
  200. * @ahb_level: Determined/Applied ahb level for the client
  201. * @axi_vote: Determined/Applied axi vote for the client
  202. * @axi_port: Client's parent axi port
  203. * @tree_node: All granular path voting nodes for the client
  204. *
  205. */
  206. struct cam_cpas_client {
  207. struct cam_cpas_register_params data;
  208. bool registered;
  209. bool started;
  210. bool tree_node_valid;
  211. bool is_drv_dyn;
  212. enum cam_vote_level ahb_level;
  213. struct cam_axi_vote axi_vote;
  214. struct cam_cpas_axi_port *axi_port;
  215. struct cam_cpas_tree_node *tree_node[CAM_CPAS_PATH_DATA_MAX]
  216. [CAM_CPAS_TRANSACTION_MAX];
  217. };
  218. /**
  219. * struct cam_cpas_bus_client : Bus client information
  220. *
  221. * @valid: Whether bus client is valid
  222. * @name: Name of the bus client
  223. * @lock: Mutex lock used while voting on this client
  224. * @curr_vote_level: current voted index
  225. * @common_data: Common data fields for bus client
  226. * @soc_bus_client: Bus client private information
  227. */
  228. struct cam_cpas_bus_client {
  229. bool valid;
  230. struct mutex lock;
  231. unsigned int curr_vote_level;
  232. struct cam_soc_bus_client_common_data common_data;
  233. void *soc_bus_client;
  234. };
  235. /**
  236. * struct cam_cpas_axi_port : AXI port information
  237. *
  238. * @axi_port_name: Name of this AXI port
  239. * @bus_client: bus client info for this port
  240. * @ib_bw_voting_needed: if this port can update ib bw dynamically
  241. * @is_rt: if this port represents a real time axi port
  242. * @axi_port_node: Node representing AXI Port info in device tree
  243. * @drv_idx: DRV index for axi port node
  244. * @cam_rsc_dev: Cam RSC device for DRV
  245. * @is_drv_started: Indicates if DRV started for RSC device corresponding to port
  246. * @curr_bw: Current voted bw after cpas consolidation
  247. * @additional_bw: Additional bandwidth to cover non-hw cpas clients
  248. * @applied_bw: Actual applied bw to port
  249. */
  250. struct cam_cpas_axi_port {
  251. const char *axi_port_name;
  252. struct cam_cpas_bus_client bus_client;
  253. bool ib_bw_voting_needed;
  254. bool is_rt;
  255. struct device_node *axi_port_node;
  256. uint32_t drv_idx;
  257. const struct device *cam_rsc_dev;
  258. bool is_drv_started;
  259. struct cam_cpas_axi_bw_info curr_bw;
  260. uint64_t additional_bw;
  261. struct cam_cpas_axi_bw_info applied_bw;
  262. };
  263. /**
  264. * struct cam_cpas_axi_port_debug_info : AXI port information
  265. *
  266. * @axi_port_name: Name of this AXI port
  267. * @curr_bw: Current voted bw after cpas consolidation
  268. * @camnoc_bw: CAMNOC bw value for this port
  269. * @applied_bw: Actual applied bw to port
  270. * @is_drv_started: Indicates if DRV started for RSC device corresponding to port
  271. */
  272. struct cam_cpas_axi_port_debug_info {
  273. const char *axi_port_name;
  274. struct cam_cpas_axi_bw_info curr_bw;
  275. uint64_t camnoc_bw;
  276. struct cam_cpas_axi_bw_info applied_bw;
  277. bool is_drv_started;
  278. };
  279. struct cam_cpas_cesta_vcd_curr_lvl_debug_info {
  280. uint8_t index;
  281. uint32_t reg_value;
  282. };
  283. /**
  284. * struct cam_cpas_cesta_vcd_reg_debug_info : to hold all cesta register information
  285. *
  286. * @vcd_currol: vcd control reg info
  287. *
  288. */
  289. struct cam_cpas_cesta_vcd_reg_debug_info {
  290. struct cam_cpas_cesta_vcd_curr_lvl_debug_info
  291. vcd_curr_lvl_debug_info[CAM_CPAS_MAX_CESTA_VCD_NUM];
  292. };
  293. /**
  294. * struct cam_cpas_monitor : CPAS monitor array
  295. *
  296. * @timestamp: Timestamp at which this monitor entry is saved
  297. * @identifier_string: String passed by caller
  298. * @identifier_value: Identifier value passed by caller
  299. * @axi_info: AXI port information
  300. * @applied_camnoc_clk: Applied camnoc axi clock rate with sw, hw clients
  301. * @applied_ahb_level: Applied camcc ahb level
  302. * @fe_ddr: RPMH DDR BCM FE (front-end) status register value.
  303. * This indicates requested clock plan
  304. * @be_ddr: RPMH DDR BCM BE (back-end) status register value.
  305. * This indicates actual current clock plan
  306. * @fe_mnoc: RPMH MNOC BCM FE (front-end) status register value.
  307. * This indicates requested clock plan
  308. * @be_mnoc: RPMH MNOC BCM BE (back-end) status register value.
  309. * This indicates actual current clock plan
  310. * @be_shub: RPMH SHUB BCM BE (back-end) status register value.
  311. * This indicates actual current clock plan
  312. * @num_camnoc_lvl_regs: Number of enabled camnoc fill level
  313. * monitoring registers
  314. * @camnoc_port_name: Camnoc port names
  315. * @camnoc_fill_level: Camnoc fill level register info
  316. * @rt_wr_niu_pri_lut_low: priority lut low values of RT Wr NIUs
  317. * @rt_wr_niu_pri_lut_high: priority lut high values of RT Wr NIUs
  318. * @vcd_reg_debug_info: vcd reg debug information
  319. */
  320. struct cam_cpas_monitor {
  321. struct timespec64 timestamp;
  322. char identifier_string[128];
  323. int32_t identifier_value;
  324. struct cam_cpas_axi_port_debug_info axi_info[CAM_CPAS_MAX_AXI_PORTS];
  325. struct cam_soc_util_clk_rates applied_camnoc_clk;
  326. unsigned int applied_ahb_level;
  327. uint32_t fe_ddr;
  328. uint32_t be_ddr;
  329. uint32_t fe_mnoc;
  330. uint32_t be_mnoc;
  331. uint32_t be_shub;
  332. uint32_t num_camnoc_lvl_regs[CAM_CAMNOC_HW_TYPE_MAX];
  333. const char *camnoc_port_name[CAM_CAMNOC_HW_TYPE_MAX]
  334. [CAM_CAMNOC_FILL_LVL_REG_INFO_MAX];
  335. uint32_t camnoc_fill_level[CAM_CAMNOC_HW_TYPE_MAX]
  336. [CAM_CAMNOC_FILL_LVL_REG_INFO_MAX];
  337. uint32_t rt_wr_niu_pri_lut_low[CAM_CPAS_MAX_RT_WR_NIU_NODES];
  338. uint32_t rt_wr_niu_pri_lut_high[CAM_CPAS_MAX_RT_WR_NIU_NODES];
  339. struct cam_cpas_cesta_vcd_reg_debug_info vcd_reg_debug_info;
  340. struct cam_hw_info *cpas_hw;
  341. };
  342. /**
  343. * struct cam_cpas : CPAS core data structure info
  344. *
  345. * @hw_caps: CPAS hw capabilities
  346. * @cpas_client: Array of pointers to CPAS clients info
  347. * @client_mutex: Mutex for accessing client info
  348. * @tree_lock: Mutex lock for accessing CPAS node tree
  349. * @num_clients: Total number of clients that CPAS supports
  350. * @num_axi_ports: Total number of axi ports found in device tree
  351. * @num_camnoc_axi_ports: Total number of camnoc axi ports found in device tree
  352. * @registered_clients: Number of Clients registered currently
  353. * @streamon_clients: Number of Clients that are in start state currently
  354. * @slave_err_irq_idx: Index of slave error in irq error data structure,
  355. * avoids iterating the entire structure to find this
  356. * idx in irq th
  357. * @regbase_index: Register base indices for CPAS register base IDs
  358. * @ahb_bus_client: AHB Bus client info
  359. * @axi_port: AXI port info for a specific axi index
  360. * @camnoc_axi_port: CAMNOC AXI port info for a specific camnoc axi index
  361. * @cam_subpart_info: camera subparts fuse description
  362. * @internal_ops: CPAS HW internal ops
  363. * @work_queue: Work queue handle
  364. * @soc_access_count: atomic soc_access_count count
  365. * @soc_access_count_wq: wait variable to ensure CPAS is not stop,
  366. * while accessing hw through CPAS
  367. * @dentry: debugfs file entry
  368. * @ahb_bus_scaling_disable: ahb scaling based on src clk corner for bus
  369. * @applied_camnoc_axi_rate: applied camnoc axi clock rate through sw, hw clients
  370. * @monitor_head: Monitor array head
  371. * @monitor_entries: cpas monitor array
  372. * @camnoc_info: array of camnoc info pointer
  373. * @cesta_info: Pointer to cesta header info
  374. * @num_valid_camnoc: number of valid camnoc info
  375. * @camnoc_rt_idx: index to real time camnoc info array
  376. * @camnoc_info_idx: map camnoc hw type to index used for camnoc_info array indexing
  377. * @full_state_dump: Whether to enable full cpas state dump or not
  378. * @smart_qos_dump: Whether to dump smart qos information on update
  379. * @slave_err_irq_en: Whether slave error irq is enabled to detect memory
  380. * config issues
  381. * @smmu_fault_handled: Handled address decode error, on fault at SMMU
  382. * @force_hlos_drv: Whether to force disable DRV voting
  383. * @force_cesta_sw_client: Whether to force voting through cesta sw client
  384. */
  385. struct cam_cpas {
  386. struct cam_cpas_hw_caps hw_caps;
  387. struct cam_cpas_client *cpas_client[CAM_CPAS_MAX_CLIENTS];
  388. struct mutex client_mutex[CAM_CPAS_MAX_CLIENTS];
  389. struct mutex tree_lock;
  390. uint32_t num_clients;
  391. uint32_t num_axi_ports;
  392. uint32_t num_camnoc_axi_ports;
  393. uint32_t registered_clients;
  394. uint32_t streamon_clients;
  395. uint32_t slave_err_irq_idx[CAM_CAMNOC_HW_TYPE_MAX];
  396. int32_t regbase_index[CAM_CPAS_REG_MAX];
  397. struct cam_cpas_bus_client ahb_bus_client;
  398. struct cam_cpas_axi_port axi_port[CAM_CPAS_MAX_AXI_PORTS];
  399. struct cam_cpas_axi_port camnoc_axi_port[CAM_CPAS_MAX_AXI_PORTS];
  400. struct cam_cpas_subpart_info *cam_subpart_info;
  401. struct cam_cpas_internal_ops internal_ops;
  402. struct workqueue_struct *work_queue;
  403. atomic_t soc_access_count;
  404. wait_queue_head_t soc_access_count_wq;
  405. struct dentry *dentry;
  406. bool ahb_bus_scaling_disable;
  407. struct cam_soc_util_clk_rates applied_camnoc_axi_rate;
  408. atomic64_t monitor_head;
  409. struct cam_cpas_monitor monitor_entries[CAM_CPAS_MONITOR_MAX_ENTRIES];
  410. void *camnoc_info[CAM_CAMNOC_HW_TYPE_MAX];
  411. void *cesta_info;
  412. uint8_t num_valid_camnoc;
  413. int8_t camnoc_rt_idx;
  414. int8_t camnoc_info_idx[CAM_CAMNOC_HW_TYPE_MAX];
  415. bool full_state_dump;
  416. bool smart_qos_dump;
  417. bool slave_err_irq_en[CAM_CAMNOC_HW_TYPE_MAX];
  418. bool smmu_fault_handled;
  419. bool force_hlos_drv;
  420. bool force_cesta_sw_client;
  421. };
  422. int cam_camsstop_get_internal_ops(struct cam_cpas_internal_ops *internal_ops);
  423. int cam_cpastop_get_internal_ops(struct cam_cpas_internal_ops *internal_ops);
  424. int cam_cpas_util_reg_update(struct cam_hw_info *cpas_hw,
  425. enum cam_cpas_reg_base reg_base, struct cam_cpas_reg *reg_info);
  426. int cam_cpas_util_reg_read(struct cam_hw_info *cpas_hw,
  427. enum cam_cpas_reg_base reg_base, struct cam_cpas_reg *reg_info);
  428. int cam_cpas_util_client_cleanup(struct cam_hw_info *cpas_hw);
  429. int cam_cpas_util_vote_default_ahb_axi(struct cam_hw_info *cpas_hw,
  430. int enable);
  431. #endif /* _CAM_CPAS_HW_H_ */