cvp_dump.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <asm/memory.h>
  6. #include <linux/coresight-stm.h>
  7. #include <linux/delay.h>
  8. #include <linux/devfreq.h>
  9. #include <linux/hash.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/io.h>
  12. #include <linux/iommu.h>
  13. #include <linux/iopoll.h>
  14. #include <linux/of.h>
  15. #include <linux/pm_qos.h>
  16. #include <linux/regulator/consumer.h>
  17. #include <linux/slab.h>
  18. #include <linux/workqueue.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/soc/qcom/llcc-qcom.h>
  21. #include <linux/qcom_scm.h>
  22. #include <linux/soc/qcom/smem.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/reset.h>
  25. #include "hfi_packetization.h"
  26. #include "msm_cvp_debug.h"
  27. #include "cvp_core_hfi.h"
  28. #include "cvp_hfi_helper.h"
  29. #include "cvp_hfi_io.h"
  30. #include "msm_cvp_dsp.h"
  31. #include "msm_cvp_clocks.h"
  32. #include "cvp_dump.h"
  33. #ifdef CVP_MINIDUMP_ENABLED
  34. /*Declare and init the head node of the linked list
  35. for queue va_md dump*/
  36. static LIST_HEAD(head_node_hfi_queue);
  37. /*Declare and init the head node of the linked list
  38. for debug struct va_md dump*/
  39. static LIST_HEAD(head_node_dbg_struct);
  40. static int eva_struct_list_notif_handler(struct notifier_block *this,
  41. unsigned long event, void *ptr);
  42. static int eva_hfiq_list_notif_handler(struct notifier_block *this,
  43. unsigned long event, void *ptr);
  44. static struct notifier_block eva_struct_list_notif_blk = {
  45. .notifier_call = eva_struct_list_notif_handler,
  46. .priority = INT_MAX-1,
  47. };
  48. static struct notifier_block eva_hfiq_list_notif_blk = {
  49. .notifier_call = eva_hfiq_list_notif_handler,
  50. .priority = INT_MAX,
  51. };
  52. struct list_head *dump_array[CVP_MAX_DUMP] = {
  53. [CVP_QUEUE_DUMP] = &head_node_hfi_queue,
  54. [CVP_DBG_DUMP] = &head_node_dbg_struct,
  55. };
  56. int md_eva_dump(const char* name, u64 virt, u64 phys, u64 size)
  57. {
  58. struct md_region md_entry;
  59. if (msm_minidump_enabled()) {
  60. dprintk(CVP_INFO, "Minidump is enabled!\n");
  61. strlcpy(md_entry.name, name, sizeof(md_entry.name));
  62. md_entry.virt_addr = (uintptr_t)virt;
  63. md_entry.phys_addr = phys;
  64. md_entry.size = size;
  65. if (msm_minidump_add_region(&md_entry) < 0) {
  66. dprintk(CVP_ERR, "Failed to add \"%s\" data in \
  67. Minidump\n", name);
  68. return 1;
  69. } else {
  70. dprintk(CVP_INFO,
  71. "add region success for \"%s\" with virt addr:\
  72. 0x%x, phy addr: 0x%x, size: %d",
  73. md_entry.name, md_entry.virt_addr,
  74. md_entry.phys_addr, md_entry.size);
  75. return 0;
  76. }
  77. } else {
  78. dprintk(CVP_ERR, "Minidump is NOT enabled!\n");
  79. return 1;
  80. }
  81. }
  82. void cvp_va_md_register(char* name, void* notf_blk_ptr)
  83. {
  84. int rc = 0;
  85. struct notifier_block* notf_blk = (struct notifier_block*)notf_blk_ptr;
  86. rc = qcom_va_md_register(name, notf_blk);
  87. if (rc) {
  88. dprintk(CVP_ERR,
  89. "\"%s\" : qcom_va_md_register failed rc = %d\n",
  90. name, rc);
  91. } else {
  92. dprintk(CVP_INFO, "\"%s\" : eva_queue qcom_va_md_register \
  93. success rc = %d\n", name, rc);
  94. }
  95. }
  96. void cvp_register_va_md_region()
  97. {
  98. if (qcom_va_md_enabled()) {
  99. cvp_va_md_register("eva_queues", &eva_hfiq_list_notif_blk);
  100. cvp_va_md_register("dbg_struct", &eva_struct_list_notif_blk);
  101. } else {
  102. dprintk(CVP_ERR, "VA_Minidump is NOT enabled!\n");
  103. }
  104. }
  105. void cvp_free_va_md_list(void)
  106. {
  107. struct eva_va_md_queue *cursor, *temp;
  108. list_for_each_entry_safe(cursor, temp, &head_node_hfi_queue, list) {
  109. list_del(&cursor->list);
  110. kfree(cursor);
  111. }
  112. list_for_each_entry_safe(cursor, temp, &head_node_dbg_struct, list) {
  113. list_del(&cursor->list);
  114. kfree(cursor);
  115. }
  116. }
  117. void add_va_node_to_list(enum cvp_dump_type type, void *buff_va, u32 buff_size,
  118. const char *region_name, bool copy)
  119. {
  120. struct list_head *head_node;
  121. struct eva_va_md_queue *temp_node = NULL;
  122. if (type >= CVP_MAX_DUMP)
  123. return;
  124. head_node = dump_array[type];
  125. /*Creating Node*/
  126. temp_node = kzalloc(sizeof(struct eva_va_md_queue), GFP_KERNEL);
  127. if (!temp_node) {
  128. dprintk(CVP_ERR, "Memory allocation failed for list node\n");
  129. return;
  130. }
  131. INIT_LIST_HEAD(&temp_node->list);
  132. temp_node->va_md_buff = buff_va;
  133. temp_node->va_md_buff_size = buff_size;
  134. strlcpy(temp_node->region_name, region_name,
  135. sizeof(temp_node->region_name));
  136. temp_node->copy = copy;
  137. list_add_tail(&temp_node->list, head_node);
  138. dprintk(CVP_INFO,
  139. "\"%s\" added to buffer list, vaddr: %px size: 0x%x\n",
  140. temp_node->region_name, temp_node->va_md_buff,
  141. temp_node->va_md_buff_size);
  142. }
  143. void add_hfi_queue_to_va_md_list(void *device)
  144. {
  145. struct cvp_iface_q_info *iface_q;
  146. struct iris_hfi_device *dev;
  147. dev = (struct iris_hfi_device*)device;
  148. iface_q = &dev->iface_queues[CVP_IFACEQ_CMDQ_IDX];
  149. add_va_node_to_list(CVP_QUEUE_DUMP,
  150. iface_q->q_array.align_virtual_addr,
  151. iface_q->q_array.mem_size,
  152. "eva_cmdq_cpu", false);
  153. iface_q = &dev->iface_queues[CVP_IFACEQ_MSGQ_IDX];
  154. add_va_node_to_list(CVP_QUEUE_DUMP,
  155. iface_q->q_array.align_virtual_addr,
  156. iface_q->q_array.mem_size,
  157. "eva_msgq_cpu", false);
  158. iface_q = &dev->dsp_iface_queues[CVP_IFACEQ_CMDQ_IDX];
  159. add_va_node_to_list(CVP_QUEUE_DUMP,
  160. iface_q->q_array.align_virtual_addr,
  161. iface_q->q_array.mem_size,
  162. "eva_cmdq_dsp", false);
  163. iface_q = &dev->dsp_iface_queues[CVP_IFACEQ_MSGQ_IDX];
  164. add_va_node_to_list(CVP_QUEUE_DUMP,
  165. iface_q->q_array.align_virtual_addr,
  166. iface_q->q_array.mem_size,
  167. "eva_msgq_dsp", false);
  168. }
  169. void add_queue_header_to_va_md_list(void *device)
  170. {
  171. struct cvp_iface_q_info *iface_q;
  172. struct iris_hfi_device *dev;
  173. struct cvp_hfi_queue_header *queue;
  174. dev = (struct iris_hfi_device*)device;
  175. iface_q = &dev->iface_queues[CVP_IFACEQ_CMDQ_IDX];
  176. queue = (struct cvp_hfi_queue_header *)iface_q->q_hdr;
  177. add_va_node_to_list(CVP_DBG_DUMP,
  178. queue, sizeof(struct cvp_hfi_queue_header),
  179. "cvp_hfi_queue_header-cpucmdQ", false);
  180. iface_q = &dev->iface_queues[CVP_IFACEQ_MSGQ_IDX];
  181. queue = (struct cvp_hfi_queue_header *)iface_q->q_hdr;
  182. add_va_node_to_list(CVP_DBG_DUMP,
  183. queue, sizeof(struct cvp_hfi_queue_header),
  184. "cvp_hfi_queue_header-cpumsgQ", false);
  185. iface_q = &dev->dsp_iface_queues[CVP_IFACEQ_CMDQ_IDX];
  186. queue = (struct cvp_hfi_queue_header *)iface_q->q_hdr;
  187. add_va_node_to_list(CVP_DBG_DUMP,
  188. queue, sizeof(struct cvp_hfi_queue_header),
  189. "cvp_hfi_queue_header-dspcmdQ", false);
  190. iface_q = &dev->dsp_iface_queues[CVP_IFACEQ_MSGQ_IDX];
  191. queue = (struct cvp_hfi_queue_header *)iface_q->q_hdr;
  192. add_va_node_to_list(CVP_DBG_DUMP,
  193. queue, sizeof(struct cvp_hfi_queue_header),
  194. "cvp_hfi_queue_header-dspmsgQ", false);
  195. }
  196. static int eva_hfiq_list_notif_handler(struct notifier_block *this,
  197. unsigned long event, void *ptr)
  198. {
  199. struct va_md_entry entry;
  200. struct eva_va_md_queue *cursor, *temp;
  201. int rc = 0;
  202. void *temp_data;
  203. list_for_each_entry_safe(cursor, temp, &head_node_hfi_queue, list) {
  204. entry.vaddr = (unsigned long)cursor->va_md_buff;
  205. if (cursor->copy) {
  206. dprintk(CVP_INFO, "Copying \"%s\"(%d Bytes)\
  207. to intermediate buffer\n",
  208. cursor->region_name, cursor->va_md_buff_size);
  209. temp_data = kzalloc(cursor->va_md_buff_size,
  210. GFP_KERNEL);
  211. if (temp_data) {
  212. memcpy(temp_data, cursor->va_md_buff,
  213. cursor->va_md_buff_size);
  214. entry.vaddr = (unsigned long)temp_data;
  215. }
  216. }
  217. entry.size = cursor->va_md_buff_size;
  218. strlcpy(entry.owner, cursor->region_name, sizeof(entry.owner));
  219. entry.cb = NULL;
  220. if (msm_cvp_minidump_enable) {
  221. rc = qcom_va_md_add_region(&entry);
  222. if (rc)
  223. dprintk(CVP_ERR, "Add region \"failed\" for \
  224. \"%s\", vaddr: %px size: 0x%x\n", entry.owner,
  225. cursor->va_md_buff, entry.size);
  226. else
  227. dprintk(CVP_INFO, "Add region \"success\" for \
  228. \"%s\", vaddr: %px size: 0x%x\n", entry.owner,
  229. cursor->va_md_buff, entry.size);
  230. }
  231. }
  232. return NOTIFY_OK;
  233. }
  234. static int eva_struct_list_notif_handler(struct notifier_block *this,
  235. unsigned long event, void *ptr)
  236. {
  237. struct va_md_entry entry;
  238. struct eva_va_md_queue *cursor, *temp;
  239. int rc = 0;
  240. void *temp_data;
  241. list_for_each_entry_safe(cursor, temp, &head_node_dbg_struct, list) {
  242. entry.vaddr = (unsigned long)cursor->va_md_buff;
  243. if (cursor->copy) {
  244. dprintk(CVP_INFO, "Copying \"%s\"(%d Bytes) to \
  245. intermediate buffer\n", cursor->region_name,
  246. cursor->va_md_buff_size);
  247. temp_data = kzalloc(cursor->va_md_buff_size,
  248. GFP_KERNEL);
  249. if (temp_data) {
  250. memcpy(temp_data, cursor->va_md_buff,
  251. cursor->va_md_buff_size);
  252. entry.vaddr = (unsigned long)temp_data;
  253. }
  254. }
  255. entry.size = cursor->va_md_buff_size;
  256. strlcpy(entry.owner, cursor->region_name, sizeof(entry.owner));
  257. entry.cb = NULL;
  258. if (msm_cvp_minidump_enable) {
  259. rc = qcom_va_md_add_region(&entry);
  260. if (rc)
  261. dprintk(CVP_ERR, "Add region \"failed\" for \
  262. \"%s\", vaddr: %px size: 0x%x\n",
  263. entry.owner, cursor->va_md_buff,
  264. entry.size);
  265. else
  266. dprintk(CVP_INFO, "Add region \"success\" for \
  267. \"%s\", vaddr: %px size: 0x%x\n", entry.owner,
  268. cursor->va_md_buff, entry.size);
  269. }
  270. }
  271. return NOTIFY_OK;
  272. }
  273. #endif