cam_cpas_hw.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_CPAS_HW_H_
  6. #define _CAM_CPAS_HW_H_
  7. #include <dt-bindings/msm-camera.h>
  8. #include "cam_cpas_api.h"
  9. #include "cam_cpas_hw_intf.h"
  10. #include "cam_common_util.h"
  11. #include "cam_soc_bus.h"
  12. #define CAM_CPAS_INFLIGHT_WORKS 5
  13. #define CAM_CPAS_MAX_CLIENTS 41
  14. #define CAM_CPAS_MAX_AXI_PORTS 6
  15. #define CAM_CPAS_MAX_TREE_LEVELS 4
  16. #define CAM_CPAS_MAX_GRAN_PATHS_PER_CLIENT 32
  17. #define CAM_CPAS_PATH_DATA_MAX 40
  18. #define CAM_CPAS_TRANSACTION_MAX 2
  19. #define CAM_CPAS_AXI_MIN_MNOC_AB_BW (2048 * 1024)
  20. #define CAM_CPAS_AXI_MIN_MNOC_IB_BW (2048 * 1024)
  21. #define CAM_CPAS_AXI_MIN_CAMNOC_AB_BW (2048 * 1024)
  22. #define CAM_CPAS_AXI_MIN_CAMNOC_IB_BW (3000000000UL)
  23. #define CAM_CPAS_GET_CLIENT_IDX(handle) (handle)
  24. #define CAM_CPAS_GET_CLIENT_HANDLE(indx) (indx)
  25. #define CAM_CPAS_CLIENT_VALID(indx) \
  26. ((indx >= 0) && (indx < CAM_CPAS_MAX_CLIENTS))
  27. #define CAM_CPAS_CLIENT_REGISTERED(cpas_core, indx) \
  28. ((CAM_CPAS_CLIENT_VALID(indx)) && \
  29. (cpas_core->cpas_client[indx]->registered))
  30. #define CAM_CPAS_CLIENT_STARTED(cpas_core, indx) \
  31. ((CAM_CPAS_CLIENT_REGISTERED(cpas_core, indx)) && \
  32. (cpas_core->cpas_client[indx]->started))
  33. /* Array indices to represent corresponding RPMH BCM info */
  34. #define CAM_RPMH_NUMBER_OF_BCMS 0
  35. #define CAM_RPMH_BCM_FE_OFFSET 1
  36. #define CAM_RPMH_BCM_BE_OFFSET 2
  37. #define CAM_RPMH_BCM_DDR_INDEX 3
  38. #define CAM_RPMH_BCM_MNOC_INDEX 4
  39. #define CAM_RPMH_BCM_INFO_MAX 5
  40. #define CAM_CPAS_MONITOR_MAX_ENTRIES 100
  41. #define CAM_CPAS_INC_MONITOR_HEAD(head, ret) \
  42. div_u64_rem(atomic64_add_return(1, head),\
  43. CAM_CPAS_MONITOR_MAX_ENTRIES, (ret))
  44. /**
  45. * enum cam_cpas_access_type - Enum for Register access type
  46. */
  47. enum cam_cpas_access_type {
  48. CAM_REG_TYPE_READ,
  49. CAM_REG_TYPE_WRITE,
  50. CAM_REG_TYPE_READ_WRITE,
  51. };
  52. /**
  53. * struct cam_cpas_internal_ops - CPAS Hardware layer internal ops
  54. *
  55. * @get_hw_info: Function pointer for get hw info
  56. * @init_hw_version: Function pointer for hw init based on version
  57. * @handle_irq: Function poniter for irq handling
  58. * @setup_regbase: Function pointer for setup rebase indices
  59. * @power_on: Function pointer for hw core specific power on settings
  60. * @power_off: Function pointer for hw core specific power off settings
  61. * @setup_qos_settings: Function pointer for hw to select a specific qos header
  62. * @print_poweron_settings: Function pointer for hw to print poweron settings
  63. * @qchannel_handshake: Function pointer for hw core specific qchannel
  64. * handshake settings
  65. *
  66. */
  67. struct cam_cpas_internal_ops {
  68. int (*get_hw_info)(struct cam_hw_info *cpas_hw,
  69. struct cam_cpas_hw_caps *hw_caps);
  70. int (*init_hw_version)(struct cam_hw_info *cpas_hw,
  71. struct cam_cpas_hw_caps *hw_caps);
  72. irqreturn_t (*handle_irq)(int irq_num, void *data);
  73. int (*setup_regbase)(struct cam_hw_soc_info *soc_info,
  74. int32_t regbase_index[], int32_t num_reg_map);
  75. int (*power_on)(struct cam_hw_info *cpas_hw);
  76. int (*power_off)(struct cam_hw_info *cpas_hw);
  77. int (*setup_qos_settings)(struct cam_hw_info *cpas_hw,
  78. uint32_t selection_mask);
  79. int (*print_poweron_settings)(struct cam_hw_info *cpas_hw);
  80. int (*qchannel_handshake)(struct cam_hw_info *cpas_hw, bool power_on);
  81. };
  82. /**
  83. * struct cam_cpas_reg : CPAS register info
  84. *
  85. * @enable: Whether this reg info need to be enabled
  86. * @access_type: Register access type
  87. * @masked_value: Whether this register write/read is based on mask, shift
  88. * @mask: Mask for this register value
  89. * @shift: Shift for this register value
  90. * @value: Register value
  91. *
  92. */
  93. struct cam_cpas_reg {
  94. bool enable;
  95. enum cam_cpas_access_type access_type;
  96. bool masked_value;
  97. uint32_t offset;
  98. uint32_t mask;
  99. uint32_t shift;
  100. uint32_t value;
  101. };
  102. /**
  103. * struct cam_cpas_client : CPAS Client structure info
  104. *
  105. * @data: Client register params
  106. * @registered: Whether client has registered with cpas
  107. * @started: Whether client has streamed on
  108. * @tree_node_valid: Indicates whether tree node has at least one valid node
  109. * @ahb_level: Determined/Applied ahb level for the client
  110. * @axi_vote: Determined/Applied axi vote for the client
  111. * @axi_port: Client's parent axi port
  112. * @tree_node: All granular path voting nodes for the client
  113. *
  114. */
  115. struct cam_cpas_client {
  116. struct cam_cpas_register_params data;
  117. bool registered;
  118. bool started;
  119. bool tree_node_valid;
  120. enum cam_vote_level ahb_level;
  121. struct cam_axi_vote axi_vote;
  122. struct cam_cpas_axi_port *axi_port;
  123. struct cam_cpas_tree_node *tree_node[CAM_CPAS_PATH_DATA_MAX]
  124. [CAM_CPAS_TRANSACTION_MAX];
  125. };
  126. /**
  127. * struct cam_cpas_bus_client : Bus client information
  128. *
  129. * @valid: Whether bus client is valid
  130. * @name: Name of the bus client
  131. * @lock: Mutex lock used while voting on this client
  132. * @curr_vote_level: current voted index
  133. * @common_data: Common data fields for bus client
  134. * @soc_bus_client: Bus client private information
  135. */
  136. struct cam_cpas_bus_client {
  137. bool valid;
  138. struct mutex lock;
  139. unsigned int curr_vote_level;
  140. struct cam_soc_bus_client_common_data common_data;
  141. void *soc_bus_client;
  142. };
  143. /**
  144. * struct cam_cpas_axi_port : AXI port information
  145. *
  146. * @axi_port_name: Name of this AXI port
  147. * @bus_client: bus client info for this port
  148. * @ib_bw_voting_needed: if this port can update ib bw dynamically
  149. * @axi_port_node: Node representing AXI Port info in device tree
  150. * @ab_bw: AB bw value for this port
  151. * @ib_bw: IB bw value for this port
  152. * @camnoc_bw: CAMNOC bw value for this port
  153. * @additional_bw: Additional bandwidth to cover non-hw cpas clients
  154. * @applied_ab_bw: applied ab bw for this port
  155. * @applied_ib_bw: applied ib bw for this port
  156. */
  157. struct cam_cpas_axi_port {
  158. const char *axi_port_name;
  159. struct cam_cpas_bus_client bus_client;
  160. bool ib_bw_voting_needed;
  161. struct device_node *axi_port_node;
  162. uint64_t ab_bw;
  163. uint64_t ib_bw;
  164. uint64_t camnoc_bw;
  165. uint64_t additional_bw;
  166. uint64_t applied_ab_bw;
  167. uint64_t applied_ib_bw;
  168. };
  169. /**
  170. * struct cam_cpas_axi_port_debug_info : AXI port information
  171. *
  172. * @axi_port_name: Name of this AXI port
  173. * @ab_bw: AB bw value for this port
  174. * @ib_bw: IB bw value for this port
  175. * @camnoc_bw: CAMNOC bw value for this port
  176. * @applied_ab_bw: applied ab bw for this port
  177. * @applied_ib_bw: applied ib bw for this port
  178. */
  179. struct cam_cpas_axi_port_debug_info {
  180. const char *axi_port_name;
  181. uint64_t ab_bw;
  182. uint64_t ib_bw;
  183. uint64_t camnoc_bw;
  184. uint64_t applied_ab_bw;
  185. uint64_t applied_ib_bw;
  186. };
  187. /**
  188. * struct cam_cpas_monitor : CPAS monitor array
  189. *
  190. * @timestamp: Timestamp at which this monitor entry is saved
  191. * @axi_info: AXI port information
  192. * @identifier_string: String passed by caller
  193. * @identifier_value: Identifier value passed by caller
  194. * @applied_camnoc_clk: Applied camnoc axi clock rate
  195. * @applied_ahb_level: Applied camcc ahb level
  196. * @fe_ddr: RPMH DDR BCM FE (front-end) status register value.
  197. * This indicates requested clock plan
  198. * @be_ddr: RPMH DDR BCM BE (back-end) status register value.
  199. * This indicates actual current clock plan
  200. * @fe_mnoc: RPMH MNOC BCM FE (front-end) status register value.
  201. * This indicates requested clock plan
  202. * @be_mnoc: RPMH MNOC BCM BE (back-end) status register value.
  203. * This indicates actual current clock plan
  204. * @be_shub: RPMH SHUB BCM BE (back-end) status register value.
  205. * This indicates actual current clock plan
  206. * @camnoc_fill_level: Camnoc fill level register info
  207. */
  208. struct cam_cpas_monitor {
  209. struct timespec64 timestamp;
  210. char identifier_string[128];
  211. int32_t identifier_value;
  212. struct cam_cpas_axi_port_debug_info axi_info[CAM_CPAS_MAX_AXI_PORTS];
  213. uint64_t applied_camnoc_clk;
  214. unsigned int applied_ahb_level;
  215. uint32_t fe_ddr;
  216. uint32_t be_ddr;
  217. uint32_t fe_mnoc;
  218. uint32_t be_mnoc;
  219. uint32_t be_shub;
  220. uint32_t camnoc_fill_level[5];
  221. };
  222. /**
  223. * struct cam_cpas : CPAS core data structure info
  224. *
  225. * @hw_caps: CPAS hw capabilities
  226. * @cpas_client: Array of pointers to CPAS clients info
  227. * @client_mutex: Mutex for accessing client info
  228. * @tree_lock: Mutex lock for accessing CPAS node tree
  229. * @num_clients: Total number of clients that CPAS supports
  230. * @num_axi_ports: Total number of axi ports found in device tree
  231. * @num_camnoc_axi_ports: Total number of camnoc axi ports found in device tree
  232. * @registered_clients: Number of Clients registered currently
  233. * @streamon_clients: Number of Clients that are in start state currently
  234. * @regbase_index: Register base indices for CPAS register base IDs
  235. * @ahb_bus_client: AHB Bus client info
  236. * @axi_port: AXI port info for a specific axi index
  237. * @camnoc_axi_port: CAMNOC AXI port info for a specific camnoc axi index
  238. * @internal_ops: CPAS HW internal ops
  239. * @work_queue: Work queue handle
  240. * @irq_count: atomic irq count
  241. * @irq_count_wq: wait variable to ensure all irq's are handled
  242. * @dentry: debugfs file entry
  243. * @ahb_bus_scaling_disable: ahb scaling based on src clk corner for bus
  244. * @applied_camnoc_axi_rate: applied camnoc axi clock rate
  245. * @monitor_head: Monitor array head
  246. * @monitor_entries: cpas monitor array
  247. * @full_state_dump: Whether to enable full cpas state dump or not
  248. */
  249. struct cam_cpas {
  250. struct cam_cpas_hw_caps hw_caps;
  251. struct cam_cpas_client *cpas_client[CAM_CPAS_MAX_CLIENTS];
  252. struct mutex client_mutex[CAM_CPAS_MAX_CLIENTS];
  253. struct mutex tree_lock;
  254. uint32_t num_clients;
  255. uint32_t num_axi_ports;
  256. uint32_t num_camnoc_axi_ports;
  257. uint32_t registered_clients;
  258. uint32_t streamon_clients;
  259. int32_t regbase_index[CAM_CPAS_REG_MAX];
  260. struct cam_cpas_bus_client ahb_bus_client;
  261. struct cam_cpas_axi_port axi_port[CAM_CPAS_MAX_AXI_PORTS];
  262. struct cam_cpas_axi_port camnoc_axi_port[CAM_CPAS_MAX_AXI_PORTS];
  263. struct cam_cpas_internal_ops internal_ops;
  264. struct workqueue_struct *work_queue;
  265. atomic_t irq_count;
  266. wait_queue_head_t irq_count_wq;
  267. struct dentry *dentry;
  268. bool ahb_bus_scaling_disable;
  269. uint64_t applied_camnoc_axi_rate;
  270. atomic64_t monitor_head;
  271. struct cam_cpas_monitor monitor_entries[CAM_CPAS_MONITOR_MAX_ENTRIES];
  272. bool full_state_dump;
  273. };
  274. int cam_camsstop_get_internal_ops(struct cam_cpas_internal_ops *internal_ops);
  275. int cam_cpastop_get_internal_ops(struct cam_cpas_internal_ops *internal_ops);
  276. int cam_cpas_util_reg_update(struct cam_hw_info *cpas_hw,
  277. enum cam_cpas_reg_base reg_base, struct cam_cpas_reg *reg_info);
  278. int cam_cpas_util_reg_read(struct cam_hw_info *cpas_hw,
  279. enum cam_cpas_reg_base reg_base, struct cam_cpas_reg *reg_info);
  280. int cam_cpas_util_client_cleanup(struct cam_hw_info *cpas_hw);
  281. #endif /* _CAM_CPAS_HW_H_ */