aee_platform_debug.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2016. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. #include <malloc.h>
  32. #include <dev/aee_platform_debug.h>
  33. #include <platform/mt_reg_base.h>
  34. #include <platform/mt_typedefs.h>
  35. #include <platform/mtk_wdt.h>
  36. #include <platform/platform_debug.h>
  37. #include "log_store_lk.h"
  38. #include <plat_debug_interface.h>
  39. #include <spm_common.h>
  40. #include <reg.h>
  41. #include <fdt.h>
  42. #include <libfdt.h>
  43. #include <debug.h>
  44. #ifdef MTK_TINYSYS_SSPM_SUPPORT
  45. #include <platform/mt_sspm.h>
  46. #include <arch/arm/mmu.h>
  47. #include <platform/timer.h>
  48. #endif
  49. #ifdef MTK_TINYSYS_SCP_SUPPORT
  50. #include <lib/zlib.h>
  51. #include <mt_scp.h>
  52. #include <mt_scp_excep.h>
  53. #endif
  54. #ifdef MTK_AUDIODSP_SUPPORT
  55. #include <mt_adsp.h>
  56. #endif
  57. #include <mtk_mcdi.h>
  58. #include "mtk_secure_api.h"
  59. #ifdef MTK_AB_OTA_UPDATER
  60. #include <mt_boot.h>
  61. #endif
  62. #include <plat_sram_flag.h>
  63. int plt_get_cluster_id(unsigned int cpu_id, unsigned int *core_id_in_cluster)
  64. {
  65. return 0;
  66. }
  67. unsigned long plt_get_cpu_power_status_at_wdt(void)
  68. {
  69. unsigned long bitmask = 0xff, ret;
  70. ret = readl(MCUCFG_BASE + cfg_pc_latch.spm_pwr_sts);
  71. bitmask = ret & 0xff;
  72. return bitmask;
  73. }
  74. static bool dfd_valid = false;
  75. static bool check_dfd_valid(u32* data)
  76. {
  77. if (data != NULL) {
  78. /*
  79. * 0x0 = 16'hAA55
  80. * 0x4 = 16'h0F0F
  81. * 0x8 = 32’h1683-0000
  82. */
  83. if ((((data[0] & 0xffff0000) >> 16) == 0xAA55)
  84. && (((data[1] & 0xffff0000) >> 16) == 0x0F0F)
  85. && data[2] == 0x16830000)
  86. dfd_valid = true;
  87. }
  88. return dfd_valid;
  89. }
  90. void reset_snoop_filter_ctrl(void)
  91. {
  92. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_RESET_SNOOP_FILTER_MAGIC, 0, 0, 0);
  93. }
  94. static void setup_snoop_filter_ram_ctrl(void)
  95. {
  96. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_SETUP_SNOOP_FILTER_MAGIC, 0, 0, 0);
  97. }
  98. static void return_snoop_filter_ram_ctrl(void)
  99. {
  100. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_RETURN_SNOOP_FILTER_MAGIC, 0, 0, 0);
  101. }
  102. static void circular_buffer_lock(void)
  103. {
  104. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_CIRCULAR_BUFFER_LOCK, 0, 0, 0);
  105. }
  106. static void circular_buffer_unlock(void)
  107. {
  108. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_CIRCULAR_BUFFER_UNLOCK, 0, 0, 0);
  109. }
  110. unsigned int plt_get_dfd_dump_type(void)
  111. {
  112. return DFD_DUMP_TO_DRAM;
  113. }
  114. static unsigned int save_cpu_bus_data(u64 offset, int *len, CALLBACK dev_write)
  115. {
  116. char *buf = NULL;
  117. int ret;
  118. unsigned int datasize = 0;
  119. /* Save latch buffer */
  120. ret = latch_get((void **)&buf, len);
  121. if (ret && (buf != NULL)) {
  122. if (*len > 0)
  123. datasize = dev_write(buf, *len);
  124. latch_put((void **)&buf);
  125. }
  126. /* Save systracker buffer */
  127. ret = systracker_get((void **)&buf, len, 32);
  128. if (buf != NULL) {
  129. if (*len > 0)
  130. datasize += dev_write(buf, *len);
  131. systracker_put((void **)&buf);
  132. }
  133. return datasize;
  134. }
  135. static unsigned int save_dfd_data(u64 offset, int *len, CALLBACK dev_write)
  136. {
  137. char *buf = NULL;
  138. int ret;
  139. unsigned int datasize = 0;
  140. /* Save dfd buffer */
  141. ret = dfd_get((void **)&buf, len);
  142. if (buf != NULL) {
  143. if (*len > 0)
  144. datasize = dev_write(buf, *len);
  145. dfd_put((void **)&buf);
  146. }
  147. return datasize;
  148. }
  149. void platform_clear_all_on_mux(void)
  150. {
  151. /* clear rg_mcu_pwr_iso_dis */
  152. writel(readl(MCU_ALL_PWR_ON_CTRL) & ~(1 << 2), MCU_ALL_PWR_ON_CTRL);
  153. dsb();
  154. /* clear rg_mcu_pwr_on */
  155. writel(readl(MCU_ALL_PWR_ON_CTRL) & ~(1 << 1), MCU_ALL_PWR_ON_CTRL);
  156. dsb();
  157. }
  158. /* SPM Debug Features */
  159. static unsigned int spm_wdt_latch_regs[] = {
  160. SLEEP_BASE + 0x800, /* PCM_WDT_LATCH_0 */
  161. SLEEP_BASE + 0x804, /* PCM_WDT_LATCH_1 */
  162. SLEEP_BASE + 0x808, /* PCM_WDT_LATCH_2 */
  163. SLEEP_BASE + 0x80C, /* PCM_WDT_LATCH_3 */
  164. SLEEP_BASE + 0x810, /* PCM_WDT_LATCH_4 */
  165. SLEEP_BASE + 0x814, /* PCM_WDT_LATCH_5 */
  166. SLEEP_BASE + 0x818, /* PCM_WDT_LATCH_6 */
  167. SLEEP_BASE + 0x81C, /* PCM_WDT_LATCH_7 */
  168. SLEEP_BASE + 0x820, /* PCM_WDT_LATCH_8 */
  169. SLEEP_BASE + 0x824, /* PCM_WDT_LATCH_9 */
  170. SLEEP_BASE + 0x828, /* PCM_WDT_LATCH_10 */
  171. SLEEP_BASE + 0x82C, /* PCM_WDT_LATCH_11 */
  172. SLEEP_BASE + 0x830, /* PCM_WDT_LATCH_12 */
  173. SLEEP_BASE + 0x834, /* PCM_WDT_LATCH_13 */
  174. SLEEP_BASE + 0x838, /* PCM_WDT_LATCH_14 */
  175. SLEEP_BASE + 0x83C, /* PCM_WDT_LATCH_15 */
  176. SLEEP_BASE + 0x840, /* DVFSRC_IRQ_LATCH_0 */
  177. SLEEP_BASE + 0x848, /* DVFSRC_IRQ_LATCH_1 */
  178. SLEEP_BASE + 0x850, /* DRAMC_GATING_ERR_LATCH_CH0_0 */
  179. SLEEP_BASE + 0x854, /* DRAMC_GATING_ERR_LATCH_CH0_1 */
  180. SLEEP_BASE + 0x858, /* DRAMC_GATING_ERR_LATCH_CH0_2 */
  181. SLEEP_BASE + 0x85C, /* DRAMC_GATING_ERR_LATCH_CH0_3 */
  182. SLEEP_BASE + 0x860, /* DRAMC_GATING_ERR_LATCH_CH0_4 */
  183. SLEEP_BASE + 0x864, /* DRAMC_GATING_ERR_LATCH_CH0_5 */
  184. SLEEP_BASE + 0x868, /* DRAMC_GATING_ERR_LATCH_CH0_6 */
  185. SLEEP_BASE + 0x86C, /* DRAMC_GATING_ERR_LATCH_CH0_7 */
  186. SLEEP_BASE + 0x870, /* DRAMC_GATING_ERR_LATCH_CH0_8 */
  187. SLEEP_BASE + 0x880, /* DRAMC_GATING_ERR_LATCH_CH1_0 */
  188. SLEEP_BASE + 0x884, /* DRAMC_GATING_ERR_LATCH_CH1_1 */
  189. SLEEP_BASE + 0x888, /* DRAMC_GATING_ERR_LATCH_CH1_2 */
  190. SLEEP_BASE + 0x88C, /* DRAMC_GATING_ERR_LATCH_CH1_3 */
  191. SLEEP_BASE + 0x890, /* DRAMC_GATING_ERR_LATCH_CH1_4 */
  192. SLEEP_BASE + 0x894, /* DRAMC_GATING_ERR_LATCH_CH1_5 */
  193. SLEEP_BASE + 0x898, /* DRAMC_GATING_ERR_LATCH_CH1_6 */
  194. SLEEP_BASE + 0x89C, /* DRAMC_GATING_ERR_LATCH_CH1_7 */
  195. SLEEP_BASE + 0x8A0, /* DRAMC_GATING_ERR_LATCH_CH1_8 */
  196. SLEEP_BASE + 0x8B0, /* PCM_WDT_LATCH_SPARE_0 */
  197. SLEEP_BASE + 0x8B4, /* PCM_WDT_LATCH_SPARE_1 */
  198. SLEEP_BASE + 0x8B8, /* DRAMC_GATING_ERR_LATCH_SPARE_0 */
  199. SLEEP_BASE + 0x8BC, /* PCM_WDT_LATCH_16 */
  200. SLEEP_BASE + 0x8D0, /* PCM_WDT_LATCH_17 */
  201. SLEEP_BASE + 0x8D4, /* PCM_WDT_LATCH_18 */
  202. SLEEP_BASE + 0x8D8, /* PCM_WDT_LATCH_CONN_0 */
  203. SLEEP_BASE + 0x8DC, /* PCM_WDT_LATCH_CONN_1 */
  204. SLEEP_BASE + 0x8E0, /* PCM_WDT_LATCH_CONN_2 */
  205. };
  206. #define DVFSRC_DUMP (DVFSRC_BASE + 0xBF4)
  207. #define DVFSRC_SIZE 0xE0
  208. #define DVFSRC_LAST_L (DVFSRC_BASE + 0xB0C)
  209. #define DVFSRC_SRAM_DUMP (0x0011BBD0)
  210. #define DVFSRC_SRAM_SIZE 0x10
  211. /* need to check aee_db_file_info[] @ app/mt_boot/aee/KEDump.c */
  212. #define SPM_DATA_BUF_LENGTH (4096)
  213. static int spm_dump_data(char *buf, int *wp)
  214. {
  215. unsigned int i;
  216. unsigned val;
  217. #ifdef SPM_FW_USE_PARTITION
  218. char part_name[16] = "spmfw";
  219. #ifdef MTK_AB_OTA_UPDATER
  220. get_AB_OTA_name((void *)&part_name, sizeof(part_name));
  221. #endif /* MTK_AB_OTA_UPDATER */
  222. #endif /* SPM_FW_USE_PARTITION */
  223. if (buf == NULL || wp == NULL)
  224. return -1;
  225. for (i = 0; i < (sizeof(spm_wdt_latch_regs)/sizeof(unsigned int)); i++) {
  226. val = readl(spm_wdt_latch_regs[i]);
  227. *wp += sprintf(buf + *wp,
  228. "SPM regs(0x%x) = 0x%x\n",
  229. spm_wdt_latch_regs[i], val);
  230. }
  231. #ifdef SPM_FW_USE_PARTITION
  232. get_spmfw_version(part_name, "spmfw", buf, wp);
  233. #endif /* SPM_FW_USE_PARTITION */
  234. val = readl(DVFSRC_LAST_L);
  235. *wp += sprintf(buf + *wp,
  236. "DVFSRC regs(0x%x) = 0x%08x\n", DVFSRC_LAST_L, val);
  237. for (i = 0; i < DVFSRC_SIZE; i += 4) {
  238. val = readl(DVFSRC_DUMP + i);
  239. *wp += sprintf(buf + *wp,
  240. "DVFSRC regs(0x%x) = 0x%08x\n", DVFSRC_DUMP + i, val);
  241. }
  242. for (i = 0; i < DVFSRC_SRAM_SIZE; i += 4) {
  243. val = readl(DVFSRC_SRAM_DUMP + i);
  244. *wp += sprintf(buf + *wp,
  245. "DVFSRC regs(0x%x) = 0x%08x\n", DVFSRC_SRAM_DUMP + i, val);
  246. }
  247. if (*wp > SPM_DATA_BUF_LENGTH) {
  248. dprintf(CRITICAL, "[spm] out of range: 0x%x > SPM_DATA_BUF_LENGTH(0x%x)\n", *wp, SPM_DATA_BUF_LENGTH);
  249. assert(0);
  250. }
  251. return 1;
  252. }
  253. int spm_data_get(void **data, int *len)
  254. {
  255. int ret;
  256. *len = 0;
  257. *data = malloc(SPM_DATA_BUF_LENGTH);
  258. if (*data == NULL)
  259. return 0;
  260. ret = spm_dump_data(*data, len);
  261. if (ret < 0 || *len > SPM_DATA_BUF_LENGTH) {
  262. *len = (*len > SPM_DATA_BUF_LENGTH) ? SPM_DATA_BUF_LENGTH : *len;
  263. return ret;
  264. }
  265. return 1;
  266. }
  267. void spm_data_put(void **data)
  268. {
  269. free(*data);
  270. }
  271. static unsigned int save_spm_data(u64 offset, int *len, CALLBACK dev_write)
  272. {
  273. char *buf = NULL;
  274. unsigned int datasize = 0;
  275. /* Save SPM buffer */
  276. spm_data_get((void **)&buf, len);
  277. if (buf != NULL) {
  278. if (*len > 0)
  279. datasize = dev_write(buf, *len);
  280. spm_data_put((void **)&buf);
  281. }
  282. return datasize;
  283. }
  284. /* SRAM for SPM */
  285. #define SPM_SRAM_ADDRESS 0x10021000
  286. #define SPM_SRAM_LENGTH 0x1000 /* 4K bytes */
  287. static int plat_spm_sram_get(void **data, int *len)
  288. {
  289. *data = (void *)SPM_SRAM_ADDRESS;
  290. *len = SPM_SRAM_LENGTH;
  291. return 1;
  292. }
  293. static unsigned int save_spm_sram_data(u64 offset, int *len, CALLBACK dev_write)
  294. {
  295. char *buf = NULL;
  296. unsigned int datasize = 0;
  297. if (plat_spm_sram_get((void **)&buf, len)) {
  298. datasize = dev_write(buf, *len);
  299. }
  300. return datasize;
  301. }
  302. /* FOR DRAMC data and DRAM Calibration Log
  303. *
  304. * This area is applied for DRAM related debug.
  305. */
  306. /* DRAMC data */
  307. #define DRAM_DEBUG_SRAM_ADDRESS 0x11D800
  308. #define DRAM_DEBUG_SRAM_LENGTH 1024
  309. static int plat_dram_debug_get(void **data, int *len)
  310. {
  311. *data = (void *)DRAM_DEBUG_SRAM_ADDRESS;
  312. *len = DRAM_DEBUG_SRAM_LENGTH;
  313. return 1;
  314. }
  315. /* shared SRAM for DRAMLOG calibration log */
  316. #define DRAM_KLOG_SRAM_ADDRESS 0x0011E000
  317. #define DRAM_KLOG_SRAM_LENGTH 8192
  318. #define DRAM_KLOG_VALID_ADDRESS 0x0011E00C
  319. static int plat_dram_klog_get(void **data, int *len)
  320. {
  321. *data = (void *)DRAM_KLOG_SRAM_ADDRESS;
  322. *len = DRAM_KLOG_SRAM_LENGTH;
  323. return 1;
  324. }
  325. static bool plat_dram_has_klog(void)
  326. {
  327. if (*(volatile unsigned int*)DRAM_KLOG_VALID_ADDRESS)
  328. return true;
  329. return false;
  330. }
  331. static unsigned int save_dram_data(u64 offset, int *len, CALLBACK dev_write)
  332. {
  333. char *buf = NULL;
  334. unsigned int datasize = 0, allsize = 0;
  335. if (plat_dram_debug_get((void **)&buf, len)) {
  336. datasize = dev_write(buf, *len);
  337. allsize = datasize;
  338. }
  339. if (plat_dram_klog_get((void **)&buf, len)) {
  340. buf = malloc(*len);
  341. if (buf) {
  342. mrdump_read_log(buf, *len, MRDUMP_EXPDB_DRAM_KLOG_OFFSET);
  343. datasize = dev_write(buf, *len);
  344. allsize += datasize;
  345. free(buf);
  346. }
  347. }
  348. return allsize;
  349. }
  350. #ifdef MTK_TINYSYS_SSPM_SUPPORT
  351. static unsigned int save_sspm_coredump(u64 offset, int *len, CALLBACK dev_write)
  352. {
  353. unsigned int *buf = NULL;
  354. unsigned int datasize = 0;
  355. int retry = SSPM_COREDUP_RETRY;
  356. if (!(*(unsigned int *)SSPM_BACKUP)) {
  357. return 0;
  358. }
  359. do {
  360. buf = *(unsigned int **)(SSPM_DM_ADDR);
  361. *len = *(int *)SSPM_DM_SZ;
  362. if (*len > 0) {
  363. datasize = dev_write( buf, *len);
  364. break;
  365. } else {
  366. udelay(100);
  367. }
  368. } while ( --retry);
  369. buf = *(unsigned int **)(SSPM_RM_ADDR);
  370. *len = *(int *)SSPM_RM_SZ;
  371. if (*len > 0) {
  372. datasize += dev_write( buf, *len);
  373. }
  374. return datasize;
  375. }
  376. static unsigned int save_sspm_data(u64 offset, int *len, CALLBACK dev_write)
  377. {
  378. char *buf = NULL;
  379. unsigned int datasize = 0, tbufl, tbufh, r, i, j;
  380. int length = 0;
  381. char dispatch;
  382. unsigned int ahb_status, ahb_addr_m0, ahb_addr_m1, ahb_addr_m2;
  383. buf = malloc(SSPM_DATA_BUF_SZ);
  384. if (!buf) {
  385. return 0;
  386. }
  387. ahb_status = DRV_Reg32(SSPM_AHB_STATUS);
  388. ahb_addr_m0 = DRV_Reg32(SSPM_AHB_M0_ADDR);
  389. ahb_addr_m1 = DRV_Reg32(SSPM_AHB_M1_ADDR);
  390. ahb_addr_m2 = DRV_Reg32(SSPM_AHB_M2_ADDR);
  391. #define CHK_PENDING(n) ((ahb_status & (1 << (n))) == 0 )
  392. #define CHK_MASTER(n) ((ahb_status & (1 << (n))) != 0 )
  393. if (CHK_PENDING(17)) {
  394. /* M0 trans is pending*/
  395. if (((ahb_addr_m0 >= SYSRAM_START) && (ahb_addr_m0 < SYSRAM_END)) || (ahb_addr_m0 >= DRAM_START))
  396. dispatch = 'P'; /* Platform owner */
  397. else
  398. dispatch = 'S'; /* SSPM owner */
  399. } else if ((CHK_PENDING(18) && CHK_MASTER(3)) || CHK_PENDING(19)) {
  400. /* M1 or M2 trans is pending*/
  401. dispatch = 'P'; /* Platform owner */
  402. } else {
  403. dispatch = 'L'; /* To see SSPM_LAST_LOG */
  404. }
  405. memset(buf, 0, SSPM_DATA_BUF_SZ);
  406. length += snprintf(buf + length, (SSPM_DATA_BUF_SZ-1) - length,
  407. "AHB_STATUS: 0x%08x\n"
  408. "AHB_M0_ADDR: 0x%x\n"
  409. "AHB_M1_ADDR: 0x%x\n"
  410. "AHB_M2_ADDR: 0x%x\n"
  411. "LastSP: 0x%x\n"
  412. "LastLR: 0x%x\n"
  413. "LastPC: 0x%x\n"
  414. "Dispatch: %c\n",
  415. ahb_status, ahb_addr_m0, ahb_addr_m1, ahb_addr_m2,
  416. DRV_Reg32(SSPM_SP), DRV_Reg32(SSPM_LR), DRV_Reg32(SSPM_PC), dispatch);
  417. r = DRV_Reg32(SSPM_TBUF_WPTR);
  418. length += snprintf(buf + length, (SSPM_DATA_BUF_SZ-1) - length, "\nTBUF_WPTR=%u\n", r);
  419. for (i = 0, j = r; i < 16; ++i, j = (j-1) & 0xF) {
  420. DRV_WriteReg32(SSPM_DBG_SEL, j);
  421. tbufl = DRV_Reg32(SSPM_TBUFL);
  422. tbufh = DRV_Reg32(SSPM_TBUFH);
  423. length += snprintf(buf + length, (SSPM_DATA_BUF_SZ-1) - length, "%u: TBUF[%u] H=0x%x L=0x%x\n", i, j, tbufh, tbufl);
  424. }
  425. *len = length;
  426. if (*len > 0) {
  427. datasize = dev_write((unsigned int*)buf, *len);
  428. }
  429. free(buf);
  430. return datasize;
  431. }
  432. static unsigned int save_sspm_xfile(u64 offset, int *len, CALLBACK dev_write)
  433. {
  434. unsigned int *buf = NULL;
  435. unsigned int *sspm_info = NULL;
  436. unsigned int datasize = 0;
  437. int ret;
  438. /* Get the information stored in *SSPM_INFO by preloader
  439. struct sspm_info_t {
  440. unsigned int sspm_dm_ofs;
  441. unsigned int sspm_dm_sz;
  442. unsigned int rd_ofs;
  443. unsigned int rd_sz;
  444. unsigned int xfile_addr;
  445. unsigned int xfile_sz;
  446. };
  447. */
  448. #ifdef MTK_3LEVEL_PAGETABLE
  449. ret = arch_mmu_map(ROUNDDOWN(*(uint64_t *)(SSPM_INFO), SECTION_SIZE),
  450. ROUNDDOWN(*(uint32_t *)(SSPM_INFO), SECTION_SIZE),
  451. MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA,
  452. SECTION_SIZE);
  453. if (ret) {
  454. dprintf(CRITICAL, "kedump: mmu map to 0x%llx fail(%d), SSPM dump might fail.\n",
  455. (unsigned long long)ROUNDDOWN(*(uint64_t *)(SSPM_INFO), SECTION_SIZE), ret);
  456. return 0;
  457. }
  458. #endif
  459. sspm_info = *(unsigned int **)(SSPM_INFO);
  460. buf = *(unsigned int **)(sspm_info + 4);
  461. *len = *(int *)(sspm_info + 5);
  462. dprintf(CRITICAL, "sspm buf 0x%x, len:0x%x\n", *buf, *len);
  463. if (*len > 0) {
  464. datasize = dev_write( buf, *len);
  465. }
  466. return datasize;
  467. }
  468. static unsigned int save_sspm_last_log(u64 offset, int *len, CALLBACK dev_write)
  469. {
  470. unsigned int *buf = NULL;
  471. unsigned int datasize = 0;
  472. buf = *(unsigned int **)(SSPM_LASTK_ADDR);
  473. *len = *(int *)SSPM_LASTK_SZ;
  474. if (*len > 0) {
  475. datasize = dev_write( buf, *len);
  476. }
  477. return datasize;
  478. }
  479. #endif
  480. #ifdef MTK_TINYSYS_SCP_SUPPORT
  481. #define SCP_EE_SIZE 0xA0000 //640 KB
  482. static unsigned int save_scp_coredump(u64 offset, int *len, CALLBACK dev_write)
  483. {
  484. int memory_dump_size;
  485. unsigned char *output = malloc(SCP_EE_SIZE);
  486. if (!output) {
  487. return 0;
  488. }
  489. memory_dump_size = scp_crash_dump(output);
  490. if ((memory_dump_size > SCP_EE_SIZE) || (memory_dump_size <= Z_NEED_DICT)) {
  491. dprintf(CRITICAL, "SCP memory_dump_size ERR %d\n", memory_dump_size);
  492. memory_dump_size = 0;
  493. } else
  494. memory_dump_size = dev_write(output, memory_dump_size);
  495. free(output);
  496. return memory_dump_size;
  497. }
  498. #endif
  499. #ifdef MTK_AUDIODSP_SUPPORT
  500. #define ADSP_EE_SIZE 0x11000 //68KB
  501. static int adsp_crash_dump(void *crash_buffer)
  502. {
  503. unsigned int offset = 0;
  504. if (ADSP_EE_SIZE < (ADSP_ITCM_SIZE + ADSP_DTCM_SIZE)) {
  505. dprintf(CRITICAL, "adsp TCM size > alloc size\n");
  506. return 0;
  507. }
  508. /* all TCM enable clock and release cpu reset */
  509. DRV_SetReg32(MODULE_SW_CG_3_CLR, 0x1<<27);
  510. DRV_ClrReg8(ADSP_A_REBOOT, 0x11);
  511. memcpy((void *)crash_buffer,
  512. (void *)(ADSP_ITCM_BASE), (ADSP_ITCM_SIZE));
  513. offset += ADSP_ITCM_SIZE;
  514. memcpy((void *)(crash_buffer + offset),
  515. (void *)(ADSP_DTCM_BASE), (ADSP_DTCM_SIZE));
  516. offset += ADSP_DTCM_SIZE;
  517. return offset;
  518. }
  519. static unsigned int save_adsp_coredump(u64 offset, int *len, CALLBACK dev_write)
  520. {
  521. int memory_dump_size;
  522. unsigned char *output = malloc(ADSP_EE_SIZE);
  523. if (!output) {
  524. return 0;
  525. }
  526. memory_dump_size = adsp_crash_dump(output);
  527. if (memory_dump_size > ADSP_EE_SIZE) {
  528. dprintf(CRITICAL, "adsp memory_dump_size ERR %d\n", memory_dump_size);
  529. memory_dump_size = 0;
  530. } else
  531. memory_dump_size = dev_write(output, memory_dump_size);
  532. free(output);
  533. return memory_dump_size;
  534. }
  535. #endif
  536. static int plat_write_dram_klog(void)
  537. {
  538. char *sram_base = NULL;
  539. int len = 0;
  540. if (plat_dram_klog_get((void **)&sram_base, (int *)&len)) {
  541. if (plat_dram_has_klog()) {
  542. mrdump_write_log(MRDUMP_EXPDB_DRAM_KLOG_OFFSET, sram_base, len);
  543. }
  544. }
  545. return 0;
  546. }
  547. /* SRAM for Hybrid CPU DVFS */
  548. #define HVFS_SRAM_ADDRESS 0x0011bc00
  549. #define HVFS_SRAM_LENGTH 0x1400 /* 5K bytes */
  550. static int plat_hvfs_data_get(void **data, int *len)
  551. {
  552. *data = (void *)HVFS_SRAM_ADDRESS;
  553. *len = HVFS_SRAM_LENGTH;
  554. return 1;
  555. }
  556. static unsigned int save_hvfs_data(u64 offset, int *len, CALLBACK dev_write)
  557. {
  558. char *buf = NULL;
  559. unsigned int datasize = 0;
  560. if (plat_hvfs_data_get((void **)&buf, len)) {
  561. datasize = dev_write(buf, *len);
  562. }
  563. return datasize;
  564. }
  565. static int plat_log_dur_lkdump_get(void **data, int *len)
  566. {
  567. *data = (void *)current_buf_addr_get();
  568. *len = current_buf_pl_lk_log_size_get();
  569. if((*data == 0) || (*len == 0)) {
  570. dprintf(CRITICAL, "[LK_LOG_STORE] invalid current address or log length(addr 0x%x, len 0x%x)\n", (unsigned int)*data, (unsigned int)*len);
  571. return 0;
  572. }
  573. dprintf(CRITICAL, "[LK_LOG_STORE] the current buf addr is 0x%x, log len is 0x%x\n", (unsigned int)*data, (unsigned int)*len);
  574. return 1;
  575. }
  576. static unsigned int save_log_dur_lkdump(u64 offset, int *len, CALLBACK dev_write)
  577. {
  578. char *buf = NULL;
  579. unsigned int datasize = 0;
  580. if (plat_log_dur_lkdump_get((void **)&buf, len)) {
  581. datasize = dev_write(buf, *len);
  582. }
  583. return datasize;
  584. }
  585. static int plat_mcdi_data_get(void **data, int *len)
  586. {
  587. mcdi_setup_file_info_for_kedump();
  588. *data = (void *)MCDI_SRAM_ADDRESS;
  589. *len = MCDI_SRAM_LENGTH;
  590. return 1;
  591. }
  592. static unsigned int save_mcdi_data(u64 offset, int *len, CALLBACK dev_write)
  593. {
  594. char *buf = NULL;
  595. unsigned int datasize = 0;
  596. if (plat_mcdi_data_get((void **)&buf, len)) {
  597. datasize = dev_write(buf, *len);
  598. }
  599. return datasize;
  600. }
  601. /* INFRA Debug Features */
  602. static unsigned int infra_wdt_latch_regs[] = {
  603. INFRA_AO_MON_0,
  604. INFRA_AO_MON_1,
  605. INFRA_AO_MON_2,
  606. INFRA_AO_MON_3,
  607. };
  608. /* need to check aee_db_file_info[] @ app/mt_boot/aee/KEDump.c */
  609. #define INFRA_DATA_BUF_LENGTH (4096)
  610. static int infra_dump_data(char *buf, int *wp)
  611. {
  612. unsigned int i;
  613. unsigned val;
  614. if (buf == NULL || wp == NULL)
  615. return -1;
  616. for (i = 0; i < (sizeof(infra_wdt_latch_regs)/sizeof(unsigned int)); i++) {
  617. val = readl(infra_wdt_latch_regs[i]);
  618. *wp += sprintf(buf + *wp,
  619. "INFRA CG regs(0x%x) = 0x%x\n",
  620. infra_wdt_latch_regs[i], val);
  621. }
  622. return 1;
  623. }
  624. int infra_data_get(void **data, int *len)
  625. {
  626. int ret;
  627. *len = 0;
  628. *data = malloc(INFRA_DATA_BUF_LENGTH);
  629. if (*data == NULL)
  630. return 0;
  631. ret = infra_dump_data(*data, len);
  632. if (ret < 0 || *len > INFRA_DATA_BUF_LENGTH) {
  633. *len = (*len > INFRA_DATA_BUF_LENGTH) ? INFRA_DATA_BUF_LENGTH : *len;
  634. return ret;
  635. }
  636. return 1;
  637. }
  638. void infra_data_put(void **data)
  639. {
  640. free(*data);
  641. }
  642. static unsigned int save_infra_data(u64 offset, int *len, CALLBACK dev_write)
  643. {
  644. char *buf = NULL;
  645. unsigned int datasize = 0;
  646. /* Save SPM buffer */
  647. infra_data_get((void **)&buf, len);
  648. if (buf != NULL) {
  649. if (*len > 0)
  650. datasize = dev_write(buf, *len);
  651. infra_data_put((void **)&buf);
  652. }
  653. return datasize;
  654. }
  655. unsigned int plat_is_perisys_timeout(const struct plt_cfg_bus_latch *self)
  656. {
  657. return (readl(PERICFG_BASE + self->perisys_offsets.bus_peri_r1) & 1);
  658. }
  659. unsigned int plt_infrasys_is_timeout(const struct plt_cfg_bus_latch *self)
  660. {
  661. return (readl(INFRACFG_AO_BASE + self->infrasys_offsets.bus_infra_ctrl) & 1);
  662. }
  663. void plat_perisys_monitor_init(const struct plt_cfg_bus_latch *self)
  664. {
  665. /* set PERIBUS_TIMEOUT_THRE and PERIBUS_TIMEOUT_THRE_TYPE */
  666. writel(self->perisys_timeout, PERICFG_BASE + self->perisys_offsets.bus_peri_r0);
  667. /* set PERIBUS_DBG_EN and PERIBUS_DBG_CKEN*/
  668. writel(0xc, PERICFG_BASE + self->perisys_offsets.bus_peri_r1);
  669. }
  670. int dfd_set_base_addr(void *fdt)
  671. {
  672. int ret = 0;
  673. int offset;
  674. int cache_dump;
  675. u64 addr;
  676. unsigned int dfd_size;
  677. u32 addr_msb;
  678. unsigned int md_addr;
  679. unsigned long long ap_addr;
  680. DEF_PLAT_SRAM_FLAG *plat = NULL;
  681. if (!fdt)
  682. return -1;
  683. ret = get_ccci_md_view_smem_addr_size(0, &ap_addr, &md_addr, &dfd_size);
  684. if (ret < 0)
  685. return ret;
  686. offset = fdt_path_offset(fdt, "/chosen");
  687. if (offset < 0)
  688. return offset;
  689. /* pass base address to kernel */
  690. addr = cpu_to_fdt64(md_addr);
  691. ret = fdt_setprop(fdt, offset, "dfd,base_addr", &addr, sizeof(addr));
  692. if (ret < 0)
  693. return ret;
  694. addr_msb = cpu_to_fdt32(ap_addr);
  695. ret = fdt_setprop(fdt, offset, "dfd,base_addr_msb", &addr_msb, sizeof(addr_msb));
  696. if (ret < 0)
  697. return ret;
  698. #ifdef MTK_DFD_ENABLE_CACHE_DUMP
  699. cache_dump = 1;
  700. #else
  701. cache_dump = 0;
  702. #endif
  703. cache_dump = cpu_to_fdt32(cache_dump);
  704. ret = fdt_setprop(fdt, offset, "dfd,cache_dump_support", &cache_dump, sizeof(cache_dump));
  705. if (ret < 0)
  706. return ret;
  707. /*
  708. * write base address[31:1] from AP view to plat_sram_flag2[31:1]
  709. * write base address[32:32] from AP view to plat_sram_flag2[0:0]
  710. */
  711. plat = (DEF_PLAT_SRAM_FLAG *)get_dbg_info_base(PLAT_SRAM_FLAG_KEY);
  712. if (!plat) {
  713. dprintf(CRITICAL, "[dfd] error: plat == NULL\n");
  714. return -1;
  715. }
  716. plat->plat_sram_flag2 = (ap_addr & ~(0x1)) | ((ap_addr >> 32) & 0x1);
  717. dprintf(CRITICAL, "[dfd] plat->plat_sram_flag2 = 0x%lx, addr = 0x%llx, addr_msb = 0x%lx\n", plat->plat_sram_flag2,
  718. addr, addr_msb);
  719. return ret;
  720. }
  721. /* platform initial function */
  722. int platform_debug_init(void)
  723. {
  724. /* function pointer assignment */
  725. plat_spm_data_get = save_spm_data;
  726. plat_spm_sram_data_get = save_spm_sram_data;
  727. plat_dram_get = save_dram_data;
  728. plat_cpu_bus_get = save_cpu_bus_data;
  729. #ifdef MTK_TINYSYS_SSPM_SUPPORT
  730. plat_sspm_coredump_get = save_sspm_coredump;
  731. plat_sspm_data_get = save_sspm_data;
  732. plat_sspm_xfile_get = save_sspm_xfile;
  733. plat_sspm_log_get = save_sspm_last_log;
  734. #endif
  735. #ifdef MTK_TINYSYS_SCP_SUPPORT
  736. plat_scp_coredump_get = save_scp_coredump;
  737. #endif
  738. plat_hvfs_get = save_hvfs_data;
  739. plat_dur_lkdump_get = save_log_dur_lkdump;
  740. plat_mcdi_get = save_mcdi_data;
  741. plat_dfd20_get = save_dfd_data;
  742. dfd_op.acquire_ram_control = setup_snoop_filter_ram_ctrl;
  743. dfd_op.release_ram_control = return_snoop_filter_ram_ctrl;
  744. circular_buffer_op.lock = circular_buffer_lock;
  745. circular_buffer_op.unlock = circular_buffer_unlock;
  746. dfd_op.check_dfd_valid = check_dfd_valid;
  747. plat_infra_cg_get = save_infra_data;
  748. #ifdef MTK_AUDIODSP_SUPPORT
  749. plat_adsp_coredump_get = save_adsp_coredump;
  750. #endif
  751. /* routine tasks */
  752. plat_write_dram_klog();
  753. return 1;
  754. }