cam_cpas_hw.h 11 KB

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