aee_platform_debug.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  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 <arch/arm/mmu.h>
  34. #include <platform/mt_reg_base.h>
  35. #include <platform/mt_typedefs.h>
  36. #include <platform/mtk_wdt.h>
  37. #include <platform/platform_debug.h>
  38. #include "log_store_lk.h"
  39. #include <plat_debug_interface.h>
  40. #include <spm_common.h>
  41. #include <reg.h>
  42. #include <libfdt.h>
  43. #include <debug.h>
  44. #include <err.h>
  45. #ifdef MTK_TINYSYS_SSPM_SUPPORT
  46. #include <platform/mt_sspm.h>
  47. #include <arch/arm/mmu.h>
  48. #include <platform/timer.h>
  49. #endif
  50. #ifdef MTK_TINYSYS_SCP_SUPPORT
  51. #include <lib/zlib.h>
  52. #include <mt_scp.h>
  53. #include <mt_scp_excep.h>
  54. #endif
  55. #ifdef MTK_AUDIODSP_SUPPORT
  56. #include <mt_adsp.h>
  57. #endif
  58. #include <mtk_mcdi.h>
  59. #ifdef MTK_SMC_ID_MGMT
  60. #include "mtk_secure_api.h"
  61. #endif
  62. #ifdef MTK_TINYSYS_MCUPM_SUPPORT
  63. #include <platform/mt_mcupm.h>
  64. #include <platform/mt_mcupm_excep.h>
  65. #endif
  66. #ifdef MTK_AB_OTA_UPDATER
  67. #include <mt_boot.h>
  68. #endif
  69. #include <plat_sram_flag.h>
  70. #include <ram_console.h>
  71. #ifdef MTK_DPM_SUPPORT
  72. #include <platform/mt_dpm.h>
  73. #endif
  74. int plt_get_cluster_id(unsigned int cpu_id, unsigned int *core_id_in_cluster)
  75. {
  76. if (core_id_in_cluster == NULL)
  77. return -1;
  78. *core_id_in_cluster = (cpu_id % 4);
  79. return (cpu_id / 4);
  80. }
  81. unsigned long plt_get_cpu_power_status_at_wdt(void)
  82. {
  83. unsigned long bitmask = 0xff, ret;
  84. ret = readl(SLEEP_BASE + cfg_pc_latch.spm_pwr_sts);
  85. bitmask = (ret & 0x3FC00000) >> 22;
  86. return bitmask;
  87. }
  88. static bool dfd_valid = false;
  89. static bool check_dfd_valid(u32* data)
  90. {
  91. if (data != NULL) {
  92. /*
  93. * 0x0 = 16'hAA55
  94. * 0x4 = 16'h0F0F
  95. * 0x8 = 32’h1683-0000
  96. */
  97. if ((((data[0] & 0xffff0000) >> 16) == 0xAA55)
  98. && (((data[1] & 0xffff0000) >> 16) == 0x0F0F)
  99. && data[2] == 0x16830000)
  100. dfd_valid = true;
  101. }
  102. return dfd_valid;
  103. }
  104. void reset_snoop_filter_ctrl(void)
  105. {
  106. #ifdef MTK_SMC_ID_MGMT
  107. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_RESET_SNOOP_FILTER_MAGIC, 0, 0, 0);
  108. #else
  109. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_RESET_SNOOP_FILTER_MAGIC, 0, 0);
  110. #endif
  111. }
  112. static void setup_snoop_filter_ram_ctrl(void)
  113. {
  114. #ifdef MTK_SMC_ID_MGMT
  115. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_SETUP_SNOOP_FILTER_MAGIC, 0, 0, 0);
  116. #else
  117. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_SETUP_SNOOP_FILTER_MAGIC, 0, 0);
  118. #endif
  119. }
  120. static void return_snoop_filter_ram_ctrl(void)
  121. {
  122. #ifdef MTK_SMC_ID_MGMT
  123. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_RETURN_SNOOP_FILTER_MAGIC, 0, 0, 0);
  124. #else
  125. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_RETURN_SNOOP_FILTER_MAGIC, 0, 0);
  126. #endif
  127. }
  128. static void circular_buffer_lock(void)
  129. {
  130. #ifdef MTK_SMC_ID_MGMT
  131. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_CIRCULAR_BUFFER_LOCK, 0, 0, 0);
  132. #else
  133. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_CIRCULAR_BUFFER_LOCK, 0, 0);
  134. #endif
  135. }
  136. static void circular_buffer_unlock(void)
  137. {
  138. #ifdef MTK_SMC_ID_MGMT
  139. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_CIRCULAR_BUFFER_UNLOCK, 0, 0, 0);
  140. #else
  141. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_CIRCULAR_BUFFER_UNLOCK, 0, 0);
  142. #endif
  143. }
  144. unsigned int plt_get_dfd_dump_type(void)
  145. {
  146. return DFD_DUMP_TO_DRAM;
  147. }
  148. static unsigned int save_cpu_bus_data(u64 offset, int *len, CALLBACK dev_write)
  149. {
  150. char *buf = NULL;
  151. int ret;
  152. unsigned int datasize = 0;
  153. /* Save latch buffer */
  154. ret = latch_get((void **)&buf, len);
  155. if (ret && (buf != NULL)) {
  156. if (*len > 0)
  157. datasize = dev_write(buf, *len);
  158. latch_put((void **)&buf);
  159. }
  160. /* Save systracker buffer */
  161. ret = systracker_get((void **)&buf, len, 64);
  162. if (ret && (buf != NULL)) {
  163. if (*len > 0)
  164. datasize += dev_write(buf, *len);
  165. systracker_put((void **)&buf);
  166. }
  167. /* Save etb buffer */
  168. ret = etb_get((void **)&buf, len);
  169. if (buf != NULL) {
  170. if (*len > 0)
  171. datasize += dev_write(buf, *len);
  172. etb_put((void **)&buf);
  173. }
  174. return datasize;
  175. }
  176. static unsigned int save_dfd_data(u64 offset, int *len, CALLBACK dev_write)
  177. {
  178. char *buf = NULL;
  179. int ret;
  180. unsigned int datasize = 0;
  181. /* Save dfd buffer */
  182. ret = dfd_get((void **)&buf, len);
  183. if (buf != NULL) {
  184. if (*len > 0)
  185. datasize = dev_write(buf, *len);
  186. dfd_put((void **)&buf);
  187. }
  188. return datasize;
  189. }
  190. #ifdef MTK_PICACHU_SUPPORT
  191. extern BOOT_ARGUMENT *g_boot_arg; //from platform.c
  192. static unsigned int save_picachu_log(u64 offset, int *len, CALLBACK dev_write)
  193. {
  194. void *buf = NULL;
  195. unsigned int datasize = 0;
  196. unsigned int start = 0;
  197. unsigned int size = 0;
  198. int ret,i;
  199. mblock_info_t *mblock_info = NULL;
  200. reserved_t * p_reserved = NULL;
  201. char * ptr;
  202. mblock_info = &g_boot_arg->mblock_info;
  203. if (g_boot_arg == NULL || mblock_info == NULL) {
  204. return 0;
  205. }
  206. p_reserved = mblock_query_reserved(mblock_info,"PICACHU",0);
  207. if (p_reserved != NULL) {
  208. start = (unsigned int)p_reserved->start;
  209. size = (unsigned int)p_reserved->size;
  210. if (size < SECTION_SIZE) {
  211. ret = arch_mmu_map(start, start,
  212. MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA,
  213. SECTION_SIZE);
  214. } else {
  215. ret = arch_mmu_map(start, start,
  216. MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA,
  217. SECTION_SIZE * ((size/SECTION_SIZE) + 1));
  218. }
  219. if (ret == NO_ERROR)
  220. buf = (void *)start;
  221. }
  222. if (buf) {
  223. /* force dump 512 KB */
  224. ptr = start;
  225. for (i = 0; i < 0x80000; i++) {
  226. ptr[i] = ptr[i] + 0x43;
  227. }
  228. *len = 0x80000;
  229. datasize = dev_write(buf, *len);
  230. }
  231. return datasize;
  232. }
  233. #endif
  234. void platform_clear_all_on_mux(void)
  235. {
  236. /* clear rg_mcu_pwr_iso_dis */
  237. writel(readl(MCU_ALL_PWR_ON_CTRL) & ~(1 << 2), MCU_ALL_PWR_ON_CTRL);
  238. dsb();
  239. /* clear rg_mcu_pwr_on */
  240. writel(readl(MCU_ALL_PWR_ON_CTRL) & ~(1 << 1), MCU_ALL_PWR_ON_CTRL);
  241. dsb();
  242. }
  243. /* SPM Debug Features */
  244. static unsigned int spm_wdt_latch_regs[] = {
  245. SLEEP_BASE + 0x800, /* PCM_WDT_LATCH_0 */
  246. SLEEP_BASE + 0x804, /* PCM_WDT_LATCH_1 */
  247. SLEEP_BASE + 0x808, /* PCM_WDT_LATCH_2 */
  248. SLEEP_BASE + 0x80C, /* PCM_WDT_LATCH_3 */
  249. SLEEP_BASE + 0x810, /* PCM_WDT_LATCH_4 */
  250. SLEEP_BASE + 0x814, /* PCM_WDT_LATCH_5 */
  251. SLEEP_BASE + 0x818, /* PCM_WDT_LATCH_6 */
  252. SLEEP_BASE + 0x81C, /* PCM_WDT_LATCH_7 */
  253. SLEEP_BASE + 0x820, /* PCM_WDT_LATCH_8 */
  254. SLEEP_BASE + 0x824, /* PCM_WDT_LATCH_9 */
  255. SLEEP_BASE + 0x828, /* PCM_WDT_LATCH_10 */
  256. SLEEP_BASE + 0x82C, /* PCM_WDT_LATCH_11 */
  257. SLEEP_BASE + 0x830, /* PCM_WDT_LATCH_12 */
  258. SLEEP_BASE + 0x834, /* PCM_WDT_LATCH_13 */
  259. SLEEP_BASE + 0x838, /* PCM_WDT_LATCH_14 */
  260. SLEEP_BASE + 0x83C, /* PCM_WDT_LATCH_15 */
  261. SLEEP_BASE + 0x840, /* PCM_WDT_LATCH_16 */
  262. SLEEP_BASE + 0x844, /* PCM_WDT_LATCH_17 */
  263. SLEEP_BASE + 0x848, /* PCM_WDT_LATCH_18 */
  264. SLEEP_BASE + 0x8A0, /* DRAMC_GATING_ERR_LATCH_CH0_0 */
  265. SLEEP_BASE + 0x8A4, /* DRAMC_GATING_ERR_LATCH_CH0_1 */
  266. SLEEP_BASE + 0x8A8, /* DRAMC_GATING_ERR_LATCH_CH0_2 */
  267. SLEEP_BASE + 0x8AC, /* DRAMC_GATING_ERR_LATCH_CH0_3 */
  268. SLEEP_BASE + 0x8B0, /* DRAMC_GATING_ERR_LATCH_CH0_4 */
  269. SLEEP_BASE + 0x8B4, /* DRAMC_GATING_ERR_LATCH_CH0_5 */
  270. SLEEP_BASE + 0x8B8, /* DRAMC_GATING_ERR_LATCH_CH0_6 */
  271. SLEEP_BASE + 0x780, /* SYS_TIMER_LATCH_L_00 */
  272. SLEEP_BASE + 0x784, /* SYS_TIMER_LATCH_H_00 */
  273. SLEEP_BASE + 0x788, /* SYS_TIMER_LATCH_L_01 */
  274. SLEEP_BASE + 0x78C, /* SYS_TIMER_LATCH_H_01 */
  275. SLEEP_BASE + 0x790, /* SYS_TIMER_LATCH_L_02 */
  276. SLEEP_BASE + 0x794, /* SYS_TIMER_LATCH_H_02 */
  277. SLEEP_BASE + 0x798, /* SYS_TIMER_LATCH_L_03 */
  278. SLEEP_BASE + 0x79C, /* SYS_TIMER_LATCH_H_03 */
  279. SLEEP_BASE + 0x7A0, /* SYS_TIMER_LATCH_L_04 */
  280. SLEEP_BASE + 0x7A4, /* SYS_TIMER_LATCH_H_04 */
  281. SLEEP_BASE + 0x7A8, /* SYS_TIMER_LATCH_L_05 */
  282. SLEEP_BASE + 0x7AC, /* SYS_TIMER_LATCH_H_05 */
  283. SLEEP_BASE + 0x7B0, /* SYS_TIMER_LATCH_L_06 */
  284. SLEEP_BASE + 0x7B4, /* SYS_TIMER_LATCH_H_06 */
  285. SLEEP_BASE + 0x7B8, /* SYS_TIMER_LATCH_L_07 */
  286. SLEEP_BASE + 0x7BC, /* SYS_TIMER_LATCH_H_07 */
  287. SLEEP_BASE + 0x7C0, /* SYS_TIMER_LATCH_L_08 */
  288. SLEEP_BASE + 0x7C4, /* SYS_TIMER_LATCH_H_08 */
  289. SLEEP_BASE + 0x7C8, /* SYS_TIMER_LATCH_L_09 */
  290. SLEEP_BASE + 0x7CC, /* SYS_TIMER_LATCH_H_09 */
  291. SLEEP_BASE + 0x7D0, /* SYS_TIMER_LATCH_L_10 */
  292. SLEEP_BASE + 0x7D4, /* SYS_TIMER_LATCH_H_10 */
  293. SLEEP_BASE + 0x7D8, /* SYS_TIMER_LATCH_L_11 */
  294. SLEEP_BASE + 0x7DC, /* SYS_TIMER_LATCH_H_11 */
  295. SLEEP_BASE + 0x7E0, /* SYS_TIMER_LATCH_L_12 */
  296. SLEEP_BASE + 0x7E4, /* SYS_TIMER_LATCH_H_12 */
  297. SLEEP_BASE + 0x7E8, /* SYS_TIMER_LATCH_L_13 */
  298. SLEEP_BASE + 0x7EC, /* SYS_TIMER_LATCH_H_13 */
  299. SLEEP_BASE + 0x7F0, /* SYS_TIMER_LATCH_L_14 */
  300. SLEEP_BASE + 0x7F4, /* SYS_TIMER_LATCH_H_14 */
  301. SLEEP_BASE + 0x7F8, /* SYS_TIMER_LATCH_L_15 */
  302. SLEEP_BASE + 0x7FC, /* SYS_TIMER_LATCH_H_15 */
  303. SLEEP_BASE + 0x914, /* SPM_ACK_CHK_SWINT_0 */
  304. SLEEP_BASE + 0x934, /* SPM_ACK_CHK_SWINT_1 */
  305. SLEEP_BASE + 0x954, /* SPM_ACK_CHK_SWINT_2 */
  306. SLEEP_BASE + 0x974, /* SPM_ACK_CHK_SWINT_3 */
  307. };
  308. #define DVFSRC_DUMP (DVFSRC_BASE + 0xBF0)
  309. #define DVFSRC_SIZE 0x100
  310. #define DVFSRC_LAST_L (DVFSRC_BASE + 0xAE8)
  311. #define DVFSRC_SRAM_DUMP (0x0011BBD0)
  312. #define DVFSRC_SRAM_SIZE 0x10
  313. /* need to check aee_db_file_info[] @ app/mt_boot/aee/KEDump.c */
  314. #define SPM_DATA_BUF_LENGTH (4096)
  315. static int spm_dump_data(char *buf, int *wp)
  316. {
  317. unsigned int i;
  318. unsigned val;
  319. #ifdef SPM_FW_USE_PARTITION
  320. char part_name[16] = "spmfw";
  321. #ifdef MTK_AB_OTA_UPDATER
  322. get_AB_OTA_name((void *)&part_name, sizeof(part_name));
  323. #endif /* MTK_AB_OTA_UPDATER */
  324. #endif /* SPM_FW_USE_PARTITION */
  325. if (buf == NULL || wp == NULL)
  326. return -1;
  327. for (i = 0; i < (sizeof(spm_wdt_latch_regs)/sizeof(unsigned int)); i++) {
  328. val = readl(spm_wdt_latch_regs[i]);
  329. *wp += sprintf(buf + *wp,
  330. "SPM regs(0x%x) = 0x%x\n",
  331. spm_wdt_latch_regs[i], val);
  332. }
  333. #ifdef SPM_FW_USE_PARTITION
  334. get_spmfw_version(part_name, "spmfw", buf, wp);
  335. #endif /* SPM_FW_USE_PARTITION */
  336. val = readl(DVFSRC_LAST_L);
  337. *wp += sprintf(buf + *wp,
  338. "DVFSRC(0x%x) = 0x%08x\n", DVFSRC_LAST_L, val);
  339. for (i = 0; i < DVFSRC_SIZE; i += 4) {
  340. val = readl(DVFSRC_DUMP + i);
  341. *wp += sprintf(buf + *wp,
  342. "DVFSRC(0x%x) = 0x%08x\n", DVFSRC_DUMP + i, val);
  343. }
  344. for (i = 0; i < DVFSRC_SRAM_SIZE; i += 4) {
  345. val = readl(DVFSRC_SRAM_DUMP + i);
  346. *wp += sprintf(buf + *wp,
  347. "DVFSRC(0x%x) = 0x%08x\n", DVFSRC_SRAM_DUMP + i, val);
  348. }
  349. if (*wp > SPM_DATA_BUF_LENGTH) {
  350. dprintf(CRITICAL, "[spm] out of range: 0x%x > SPM_DATA_BUF_LENGTH(0x%x)\n", *wp, SPM_DATA_BUF_LENGTH);
  351. assert(0);
  352. }
  353. return 1;
  354. }
  355. int spm_data_get(void **data, int *len)
  356. {
  357. int ret;
  358. *len = 0;
  359. *data = malloc(SPM_DATA_BUF_LENGTH);
  360. if (*data == NULL)
  361. return 0;
  362. ret = spm_dump_data(*data, len);
  363. if (ret < 0 || *len > SPM_DATA_BUF_LENGTH) {
  364. *len = (*len > SPM_DATA_BUF_LENGTH) ? SPM_DATA_BUF_LENGTH : *len;
  365. return ret;
  366. }
  367. return 1;
  368. }
  369. void spm_data_put(void **data)
  370. {
  371. free(*data);
  372. }
  373. static unsigned int save_spm_data(u64 offset, int *len, CALLBACK dev_write)
  374. {
  375. char *buf = NULL;
  376. unsigned int datasize = 0;
  377. /* Save SPM buffer */
  378. spm_data_get((void **)&buf, len);
  379. if (buf != NULL) {
  380. if (*len > 0)
  381. datasize = dev_write(buf, *len);
  382. spm_data_put((void **)&buf);
  383. }
  384. return datasize;
  385. }
  386. /* SRAM for SPM */
  387. #define SPM_SRAM_ADDRESS 0x10021000
  388. #define SPM_SRAM_LENGTH 0x1000 /* 4K bytes */
  389. static int plat_spm_sram_get(void **data, int *len)
  390. {
  391. *data = (void *)SPM_SRAM_ADDRESS;
  392. *len = SPM_SRAM_LENGTH;
  393. return 1;
  394. }
  395. static unsigned int save_spm_sram_data(u64 offset, int *len, CALLBACK dev_write)
  396. {
  397. char *buf = NULL;
  398. unsigned int datasize = 0;
  399. if (plat_spm_sram_get((void **)&buf, len)) {
  400. datasize = dev_write(buf, *len);
  401. }
  402. return datasize;
  403. }
  404. /* FOR DRAMC data and DRAM Calibration Log
  405. *
  406. * This area is applied for DRAM related debug.
  407. */
  408. /* DRAMC data */
  409. static int plat_dram_debug_get(void **data, int *len)
  410. {
  411. sram_plat_dbg_info_addr_size(data, len);
  412. return 1;
  413. }
  414. static unsigned int save_dram_data(u64 offset, int *len, CALLBACK dev_write)
  415. {
  416. char *buf = NULL;
  417. unsigned int datasize = 0;
  418. if (plat_dram_debug_get((void **)&buf, len))
  419. datasize = dev_write(buf, *len);
  420. return datasize;
  421. }
  422. #ifdef MTK_TINYSYS_SSPM_SUPPORT
  423. static unsigned int save_sspm_coredump(u64 offset, int *len, CALLBACK dev_write)
  424. {
  425. unsigned int *buf = NULL;
  426. unsigned int datasize = 0;
  427. int retry = SSPM_COREDUP_RETRY;
  428. if (!(*(unsigned int *)SSPM_BACKUP)) {
  429. return 0;
  430. }
  431. do {
  432. buf = *(unsigned int **)(SSPM_DM_ADDR);
  433. *len = *(int *)SSPM_DM_SZ;
  434. if (*len > 0) {
  435. datasize = dev_write(buf, *len);
  436. break;
  437. } else {
  438. udelay(100);
  439. }
  440. } while ( --retry);
  441. buf = *(unsigned int **)(SSPM_RM_ADDR);
  442. *len = *(int *)SSPM_RM_SZ;
  443. if (*len > 0) {
  444. datasize += dev_write(buf, *len);
  445. }
  446. return datasize;
  447. }
  448. static unsigned int save_sspm_data(u64 offset, int *len, CALLBACK dev_write)
  449. {
  450. char *buf = NULL;
  451. char owner[3] = {'P', 'S', 'L'}; /* Platform, SSPM, SSPM_LAST_LOG */
  452. unsigned int addr = 0, dispatch = 0;
  453. unsigned int axi_status;
  454. unsigned int ahb_status, ahb_addr_m0, ahb_addr_m1, ahb_addr_m2;
  455. unsigned int datasize = 0, tbufl, tbufh, r, i, j;
  456. int length = 0;
  457. buf = malloc(SSPM_DATA_BUF_SZ);
  458. if (!buf) {
  459. return 0;
  460. }
  461. axi_status = DRV_Reg32(SSPM_AXI_STATUS);
  462. ahb_status = DRV_Reg32(SSPM_AHB_STATUS);
  463. ahb_addr_m0 = DRV_Reg32(SSPM_AHB_M0_ADDR);
  464. ahb_addr_m1 = DRV_Reg32(SSPM_AHB_M1_ADDR);
  465. ahb_addr_m2 = DRV_Reg32(SSPM_AHB_M2_ADDR);
  466. /* Set Auto-dispatch rule according by AHB_STATUS[13,10,5,4]. */
  467. if ( (ahb_status & (BIT(13) | BIT(10) | BIT(5) | BIT(4)) ) == 0x0 )
  468. {
  469. /* Bus hang issue. */
  470. if (ahb_status & BIT(2)) /* Master = M0 */
  471. addr = ahb_addr_m0;
  472. else if (ahb_status & BIT(3)) /* Master = M1 */
  473. addr = ahb_addr_m1;
  474. else if ((ahb_status & BIT(17)) == 0) /* Master M2 trans is pending. */
  475. addr = ahb_addr_m2;
  476. if (((addr >= SYSRAM_START) && (addr < SYSRAM_END)) ||
  477. ((addr >= DRAM_START) && (addr < DRAM_END)))
  478. dispatch = TO_PLATFORM;
  479. else
  480. dispatch = TO_SSPM_OWN;
  481. }
  482. else
  483. dispatch = TO_SSPM_LAST_LOG;
  484. memset(buf, 0, SSPM_DATA_BUF_SZ);
  485. length += snprintf(buf + length, SSPM_DATA_BUF_SZ - length,
  486. "STATUS: 0x%x\n"
  487. "M0: 0x%x\n"
  488. "M1: 0x%x\n"
  489. "M2: 0x%x\n"
  490. "SP: 0x%x\n"
  491. "LR: 0x%x\n"
  492. "PC: 0x%x\n"
  493. "AXI_STATUS: 0x%x\n"
  494. "Dispatch: %c\n",
  495. ahb_status, ahb_addr_m0, ahb_addr_m1, ahb_addr_m2,
  496. DRV_Reg32(SSPM_SP), DRV_Reg32(SSPM_LR),
  497. DRV_Reg32(SSPM_PC),
  498. axi_status,
  499. owner[dispatch]);
  500. r = DRV_Reg32(SSPM_TBUF_WPTR);
  501. length += snprintf(buf + length, (SSPM_DATA_BUF_SZ-1) - length, "\nTBUF_WPTR=%u\n", r);
  502. for (i = 0, j = r; i < 16; ++i, j = (j-1) & 0xF) {
  503. DRV_WriteReg32(SSPM_DBG_SEL, j);
  504. tbufl = DRV_Reg32(SSPM_TBUFL);
  505. tbufh = DRV_Reg32(SSPM_TBUFH);
  506. length += snprintf(buf + length, (SSPM_DATA_BUF_SZ-1) - length,
  507. "%u: TBUF[%u] _H=0x%x _L=0x%x\n", i, j, tbufh, tbufl);
  508. }
  509. *len = length;
  510. if (*len > 0) {
  511. datasize = dev_write(buf, (*len > SSPM_DATA_BUF_SZ ? SSPM_DATA_BUF_SZ : *len));
  512. }
  513. free(buf);
  514. return datasize;
  515. }
  516. static unsigned int save_sspm_xfile(u64 offset, int *len, CALLBACK dev_write)
  517. {
  518. unsigned int *buf = NULL;
  519. unsigned int *sspm_info = NULL;
  520. unsigned int datasize = 0;
  521. int ret;
  522. /* Get the information stored in *SSPM_INFO by preloader
  523. struct sspm_info_t {
  524. unsigned int sspm_dm_ofs;
  525. unsigned int sspm_dm_sz;
  526. unsigned int rd_ofs;
  527. unsigned int rd_sz;
  528. unsigned int xfile_addr;
  529. unsigned int xfile_sz;
  530. };
  531. */
  532. #ifdef MTK_3LEVEL_PAGETABLE
  533. ret = arch_mmu_map(ROUNDDOWN(*(uint64_t *)(SSPM_INFO), SECTION_SIZE),
  534. ROUNDDOWN(*(uint32_t *)(SSPM_INFO), SECTION_SIZE),
  535. MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA,
  536. SECTION_SIZE);
  537. if (ret) {
  538. dprintf(CRITICAL, "kedump: mmu map to 0x%llx fail(%d), SSPM dump might fail.\n",
  539. (unsigned long long)ROUNDDOWN(*(uint64_t *)(SSPM_INFO), SECTION_SIZE), ret);
  540. return 0;
  541. }
  542. #endif
  543. sspm_info = *(unsigned int **)(SSPM_INFO);
  544. buf = *(unsigned int **)(sspm_info + 4);
  545. *len = *(int *)(sspm_info + 5);
  546. dprintf(CRITICAL, "sspm buf 0x%x, len:0x%x\n", *buf, *len);
  547. if (*len > 0) {
  548. datasize = dev_write(buf, *len);
  549. }
  550. return datasize;
  551. }
  552. static unsigned int save_sspm_last_log(u64 offset, int *len, CALLBACK dev_write)
  553. {
  554. unsigned int *buf = NULL;
  555. unsigned int datasize = 0;
  556. buf = *(unsigned int **)(SSPM_LASTK_ADDR);
  557. *len = *(int *)SSPM_LASTK_SZ;
  558. if (*len > 0) {
  559. datasize = dev_write( buf, *len);
  560. }
  561. return datasize;
  562. }
  563. #endif /* #ifdef MTK_TINYSYS_SSPM_SUPPORT */
  564. #ifdef MTK_TINYSYS_SCP_SUPPORT
  565. #define SCP_EE_SIZE 0xE0000 //896 KB
  566. static unsigned int save_scp_coredump(u64 offset, int *len, CALLBACK dev_write)
  567. {
  568. int memory_dump_size;
  569. unsigned char *output = malloc(SCP_EE_SIZE + 0x20000); // extra buffer 128 KB
  570. if (!output) {
  571. return 0;
  572. }
  573. memory_dump_size = scp_crash_dump(output);
  574. if ((memory_dump_size > SCP_EE_SIZE) || (memory_dump_size <= Z_NEED_DICT)) {
  575. dprintf(CRITICAL, "SCP memory_dump_size ERR %d\n", memory_dump_size);
  576. memory_dump_size = 0;
  577. } else
  578. memory_dump_size = dev_write(output, memory_dump_size);
  579. free(output);
  580. return memory_dump_size;
  581. }
  582. #endif
  583. #ifdef MTK_AUDIODSP_SUPPORT
  584. #if defined(ADSP_B_ITCM_BASE) && defined(ADSP_B_DTCM_BASE)
  585. #define ADSP_EE_SIZE (ADSP_A_ITCM_SIZE + ADSP_A_DTCM_SIZE + ADSP_B_ITCM_SIZE + ADSP_B_ITCM_SIZE)
  586. #else
  587. #define ADSP_EE_SIZE (ADSP_A_ITCM_SIZE + ADSP_A_DTCM_SIZE) //0x11000 = 68KB
  588. #endif
  589. static int adsp_crash_dump(void *crash_buffer)
  590. {
  591. unsigned int offset = 0;
  592. /* all TCM enable clock and release cpu reset */
  593. switch_adsp_power(true, false);
  594. adsp_sw_reset();
  595. memcpy((void *)crash_buffer,
  596. (void *)(ADSP_A_ITCM_BASE), (ADSP_A_ITCM_SIZE));
  597. offset += ADSP_A_ITCM_SIZE;
  598. memcpy((void *)(crash_buffer + offset),
  599. (void *)(ADSP_A_DTCM_BASE), (ADSP_A_DTCM_SIZE));
  600. offset += ADSP_A_DTCM_SIZE;
  601. #if defined(ADSP_B_ITCM_BASE) && defined(ADSP_B_DTCM_BASE)
  602. memcpy((void *)(crash_buffer + offset),
  603. (void *)(ADSP_B_ITCM_BASE), (ADSP_B_ITCM_SIZE));
  604. offset += ADSP_B_ITCM_SIZE;
  605. memcpy((void *)(crash_buffer + offset),
  606. (void *)(ADSP_B_DTCM_BASE), (ADSP_B_DTCM_SIZE));
  607. offset += ADSP_B_DTCM_SIZE;
  608. #endif
  609. return offset;
  610. }
  611. static unsigned int save_adsp_coredump(u64 offset, int *len, CALLBACK dev_write)
  612. {
  613. int memory_dump_size;
  614. unsigned char *output = malloc(ADSP_EE_SIZE);
  615. if (!output) {
  616. return 0;
  617. }
  618. memory_dump_size = adsp_crash_dump(output);
  619. if (memory_dump_size > ADSP_EE_SIZE) {
  620. dprintf(CRITICAL, "adsp memory_dump_size ERR %d\n", memory_dump_size);
  621. memory_dump_size = 0;
  622. } else
  623. memory_dump_size = dev_write(output, memory_dump_size);
  624. free(output);
  625. return memory_dump_size;
  626. }
  627. #endif
  628. /* SRAM for Hybrid CPU DVFS */
  629. #define HVFS_SRAM_ADDRESS 0x0011bc00
  630. #define HVFS_SRAM_LENGTH 0x1400 /* 5K bytes */
  631. static int plat_hvfs_data_get(void **data, int *len)
  632. {
  633. *data = (void *)HVFS_SRAM_ADDRESS;
  634. *len = HVFS_SRAM_LENGTH;
  635. return 1;
  636. }
  637. static unsigned int save_hvfs_data(u64 offset, int *len, CALLBACK dev_write)
  638. {
  639. char *buf = NULL;
  640. unsigned int datasize = 0;
  641. if (plat_hvfs_data_get((void **)&buf, len)) {
  642. datasize = dev_write(buf, *len);
  643. }
  644. return datasize;
  645. }
  646. static int plat_log_dur_lkdump_get(void **data, int *len)
  647. {
  648. *data = (void *)current_buf_addr_get();
  649. *len = current_buf_pl_lk_log_size_get();
  650. if((*data == 0) || (*len == 0)) {
  651. dprintf(CRITICAL, "[LK_LOG_STORE] invalid current address or log length(addr 0x%x, len 0x%x)\n", (unsigned int)*data, (unsigned int)*len);
  652. return 0;
  653. }
  654. dprintf(CRITICAL, "[LK_LOG_STORE] the current buf addr is 0x%x, log len is 0x%x\n", (unsigned int)*data, (unsigned int)*len);
  655. return 1;
  656. }
  657. static unsigned int save_log_dur_lkdump(u64 offset, int *len, CALLBACK dev_write)
  658. {
  659. char *buf = NULL;
  660. unsigned int datasize = 0;
  661. if (plat_log_dur_lkdump_get((void **)&buf, len)) {
  662. datasize = dev_write(buf, *len);
  663. }
  664. return datasize;
  665. }
  666. static int plat_mcdi_data_get(void **data, int *len)
  667. {
  668. mcdi_setup_file_info_for_kedump();
  669. *data = (void *)MCDI_SRAM_ADDRESS;
  670. *len = MCDI_SRAM_LENGTH;
  671. return 1;
  672. }
  673. static unsigned int save_mcdi_data(u64 offset, int *len, CALLBACK dev_write)
  674. {
  675. char *buf = NULL;
  676. unsigned int datasize = 0;
  677. if (plat_mcdi_data_get((void **)&buf, len)) {
  678. datasize = dev_write(buf, *len);
  679. }
  680. return datasize;
  681. }
  682. int plt_infrasys_init(const struct lastbus_monitor *m)
  683. {
  684. void *base = m->base;
  685. /* mt6853 has 1 dummy check point which caused timeout */
  686. /* let's mask it first */
  687. writel(0x200, base + 0x014);
  688. /* ok, do the normal init with max timeout */
  689. writel(0xffff0008, base);
  690. writel(0xffff000c, base);
  691. return 0;
  692. }
  693. int dfd_set_base_addr(void *fdt)
  694. {
  695. int ret = 0;
  696. int offset;
  697. int cache_dump;
  698. u64 addr;
  699. unsigned int dfd_size;
  700. u32 addr_msb;
  701. unsigned int md_addr;
  702. unsigned long long ap_addr;
  703. DEF_PLAT_SRAM_FLAG *plat = NULL;
  704. if (!fdt)
  705. return -1;
  706. ret = mtk_ccci_get_dfd_smem_info(&ap_addr, &md_addr, &dfd_size);
  707. if (ret < 0)
  708. return ret;
  709. offset = fdt_path_offset(fdt, "/chosen");
  710. if (offset < 0)
  711. return offset;
  712. /* pass base address to kernel */
  713. addr = cpu_to_fdt64(ap_addr);
  714. ret = fdt_setprop(fdt, offset, "dfd,base_addr", &addr, sizeof(addr));
  715. if (ret < 0)
  716. return ret;
  717. addr_msb = cpu_to_fdt32(ap_addr);
  718. ret = fdt_setprop(fdt, offset, "dfd,base_addr_msb", &addr_msb, sizeof(addr_msb));
  719. if (ret < 0)
  720. return ret;
  721. #ifdef MTK_DFD_ENABLE_CACHE_DUMP
  722. cache_dump = 1;
  723. #else
  724. cache_dump = 0;
  725. #endif
  726. cache_dump = cpu_to_fdt32(cache_dump);
  727. ret = fdt_setprop(fdt, offset, "dfd,cache_dump_support", &cache_dump, sizeof(cache_dump));
  728. if (ret < 0)
  729. return ret;
  730. /*
  731. * write base address[31:1] from AP view to plat_sram_flag2[31:1]
  732. * write base address[32:32] from AP view to plat_sram_flag2[0:0]
  733. */
  734. plat = (DEF_PLAT_SRAM_FLAG *)get_dbg_info_base(PLAT_SRAM_FLAG_KEY);
  735. if (!plat) {
  736. dprintf(CRITICAL, "[dfd] error: plat == NULL\n");
  737. return -1;
  738. }
  739. plat->plat_sram_flag2 = (ap_addr & ~(0x1)) | ((ap_addr >> 32) & 0x1);
  740. dprintf(CRITICAL, "[dfd] plat->plat_sram_flag2 = 0x%lx, addr = 0x%llx, addr_msb = 0x%lx\n", plat->plat_sram_flag2,
  741. addr, addr_msb);
  742. return ret;
  743. }
  744. #ifdef MTK_TINYSYS_MCUPM_SUPPORT
  745. #define MCUPM_EE_SIZE 0x40080
  746. static unsigned int save_mcupm_coredump(u64 offset, int *len, CALLBACK dev_write)
  747. {
  748. int memory_dump_size;
  749. unsigned char *output = malloc(MCUPM_EE_SIZE + 0x10000); // extra buffer 64 KB
  750. if (!output)
  751. return 0;
  752. /* in case the mcupm address is invalid */
  753. if (DRV_Reg32(PLT_RD_MAGIC) != 0xdeadbeef) {
  754. dprintf(CRITICAL, "[mcupm] dump failed: invalid address pclrsp = 0x%llx, lastlog = 0x%llx\n", (uint64_t)DRV_Reg32(GPR_BASE_ADDR(21)), (uint64_t)DRV_Reg32(GPR_BASE_ADDR(8)));
  755. free(output);
  756. return 0;
  757. }
  758. dprintf(CRITICAL, "[mcupm] pclrsp = 0x%llx, lastlog = 0x%llx\n", (uint64_t)DRV_Reg32(GPR_BASE_ADDR(21)), (uint64_t)DRV_Reg32(GPR_BASE_ADDR(8)));
  759. memset(output, 0, MCUPM_EE_SIZE + 0x10000);
  760. memory_dump_size = mcupm_crash_dump(output);
  761. if (memory_dump_size > MCUPM_EE_SIZE) {
  762. dprintf(CRITICAL, "MCUPM memory_dump_size ERR %d\n", memory_dump_size);
  763. memory_dump_size = 0;
  764. } else
  765. memory_dump_size = dev_write(output, memory_dump_size);
  766. free(output);
  767. return memory_dump_size;
  768. }
  769. #if 0
  770. static unsigned int save_mcupm_data(u64 offset, int *len, CALLBACK dev_write)
  771. {
  772. char *buf = NULL;
  773. unsigned int datasize = 0, tbufl, tbufh, r, i;
  774. int length = 0;
  775. unsigned int mcupm_ahb_status, mcupm_ahb_addr_m0, mcupm_ahb_addr_m1;
  776. return datasize; //To-Do : data will be merged into coredump
  777. buf = malloc(MCUPM_DATA_BUF_SZ);
  778. if (!buf) {
  779. return 0;
  780. }
  781. mcupm_ahb_status = DRV_Reg32(MCUPM_AHB_STATUS);
  782. mcupm_ahb_addr_m0 = DRV_Reg32(MCUPM_AHB_M0_ADDR);
  783. mcupm_ahb_addr_m1 = DRV_Reg32(MCUPM_AHB_M1_ADDR);
  784. memset(buf, 0, MCUPM_DATA_BUF_SZ);
  785. length += snprintf(buf + length, (MCUPM_DATA_BUF_SZ-1) - length,
  786. "MCUPM_AHB_STATUS: 0x%08x\n"
  787. "MCUPM_AHB_M0_ADDR: 0x%x\n"
  788. "MCUPM_AHB_M1_ADDR: 0x%x\n"
  789. "MCUPM_LastPC: 0x%x\n",
  790. mcupm_ahb_status, mcupm_ahb_addr_m0, mcupm_ahb_addr_m1,
  791. DRV_Reg32(MCUPM_PC));
  792. r = DRV_Reg32(MCUPM_TBUF_WPTR);
  793. length += snprintf(buf + length, (MCUPM_DATA_BUF_SZ-1) - length, "\nTBUF_WPTR=%u\n", r);
  794. for (i = 0; i < 4; ++i) {
  795. tbufl = DRV_Reg32(MCUPM_TBUF0_L + (0x4 * i));
  796. tbufh = DRV_Reg32(MCUPM_TBUF0_H + (0x4 * i));
  797. length += snprintf(buf + length, (MCUPM_DATA_BUF_SZ-1) - length,
  798. "TBUF[%u] H=0x%x L=0x%x\n", i, tbufh, tbufl);
  799. }
  800. *len = length;
  801. if (*len > 0) {
  802. datasize = dev_write(buf, (*len > MCUPM_DATA_BUF_SZ ? MCUPM_DATA_BUF_SZ : *len));
  803. }
  804. free(buf);
  805. return datasize;
  806. }
  807. static unsigned int save_mcupm_xfile(u64 offset, int *len, CALLBACK dev_write)
  808. {
  809. unsigned int *buf = NULL;
  810. unsigned int *mcupm_info = NULL;
  811. unsigned int datasize = 0;
  812. int ret;
  813. return datasize; //To-Do : mt6853 do not have xfile
  814. #ifdef MTK_3LEVEL_PAGETABLE
  815. ret = arch_mmu_map(ROUNDDOWN(*(uint64_t *)(MCUPM_INFO), SECTION_SIZE),
  816. ROUNDDOWN(*(uint32_t *)(MCUPM_INFO), SECTION_SIZE),
  817. MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA,
  818. SECTION_SIZE);
  819. if (ret) {
  820. dprintf(CRITICAL, "kedump: mmu map to 0x%llx fail(%d), MCUPM dump might fail.\n",
  821. (unsigned long long)ROUNDDOWN(*(uint64_t *)(MCUPM_INFO), SECTION_SIZE), ret);
  822. return 0;
  823. }
  824. #endif
  825. mcupm_info = *(unsigned int **)(MCUPM_INFO);
  826. buf = *(unsigned int **)(mcupm_info + 4);
  827. *len = *(int *)(mcupm_info + 5);
  828. dprintf(CRITICAL, "mcupm buf 0x%x, len:0x%x\n", *buf, *len);
  829. if (*len > 0) {
  830. datasize = dev_write( buf, *len);
  831. }
  832. return datasize;
  833. }
  834. #endif
  835. static unsigned int save_mcupm_last_log(u64 offset, int *len, CALLBACK dev_write)
  836. {
  837. unsigned int *buf = NULL;
  838. unsigned int datasize = 0;
  839. unsigned int src_w_pos, src_r_pos;
  840. /* in case the mcupm address is invalid */
  841. if (DRV_Reg32(PLT_RD_MAGIC) != 0xdeadbeef) {
  842. dprintf(CRITICAL, "[mcupm] dump failed: invalid address pclrsp = 0x%llx, lastlog = 0x%llx\n", (uint64_t)DRV_Reg32(GPR_BASE_ADDR(21)), (uint64_t)DRV_Reg32(GPR_BASE_ADDR(8)));
  843. return 0;
  844. }
  845. if (DRV_Reg32(MCUPM_LASTK_ADDR) == 0xdeadbeef) {
  846. dprintf(CRITICAL, "[mcupm] dump failed: mcupm disable logger\n");
  847. return 0;
  848. }
  849. dprintf(CRITICAL, "[mcupm] pclrsp = 0x%llx, lastlog = 0x%llx\n", (uint64_t)DRV_Reg32(GPR_BASE_ADDR(21)), (uint64_t)DRV_Reg32(GPR_BASE_ADDR(8)));
  850. //get logger address
  851. buf = (unsigned int *)(DRV_Reg32(MCUPM_LASTK_ADDR) + MCUPM_SRAM_BASE);
  852. *len = *(int *)MCUPM_LASTK_SZ;
  853. src_w_pos = *(unsigned int **)(MCUPM_LASTK_W_POS);
  854. src_r_pos = *(unsigned int **)(MCUPM_LASTK_R_POS);
  855. src_w_pos = DRV_Reg32(src_w_pos + MCUPM_SRAM_BASE);
  856. src_r_pos = DRV_Reg32(src_r_pos + MCUPM_SRAM_BASE);
  857. if (*len <= 0)
  858. return datasize;
  859. if (src_w_pos > src_r_pos)
  860. datasize = dev_write(buf + src_r_pos, src_w_pos - src_r_pos);
  861. else
  862. {
  863. datasize = dev_write(buf + src_r_pos, *len - src_r_pos);
  864. datasize += dev_write(buf, src_w_pos);
  865. }
  866. dprintf(CRITICAL, "[mcupm] dump last log sueecess datasize = %d\n", datasize);
  867. return datasize;
  868. }
  869. #endif /* #ifdef MTK_TINYSYS_MCUPM_SUPPORT */
  870. #ifdef MTK_DPM_SUPPORT
  871. static unsigned int set_dpm_header(unsigned char *buf)
  872. {
  873. unsigned int version = DPM_VERSION;
  874. unsigned int hw_id = DPM_HWID;
  875. unsigned int nr_dpm = DPM_NUM;
  876. unsigned int nr_channel = DRAM_CHANNEL;
  877. unsigned int coredump_sz = DPM_DM_OFFSET;
  878. unsigned int lpif_sz = DPM_DBG_LEN;
  879. unsigned int cfg_sz = DPM_CFG1_LEN + DPM_CFG2_LEN;
  880. unsigned int dram_sz = DDRPHY_LATCH_LEN*DRAM_CHANNEL;
  881. unsigned int offset = 0;
  882. memcpy(buf + offset, &version, sizeof(version));
  883. offset += sizeof(version);
  884. memcpy(buf + offset, &hw_id, sizeof(hw_id));
  885. offset += sizeof(hw_id);
  886. memcpy(buf + offset, &nr_dpm, sizeof(nr_dpm));
  887. offset += sizeof(nr_dpm);
  888. memcpy(buf + offset, &nr_channel, sizeof(nr_channel));
  889. offset += sizeof(nr_channel);
  890. memcpy(buf + offset, &coredump_sz, sizeof(coredump_sz));
  891. offset += sizeof(coredump_sz);
  892. memcpy(buf + offset, &lpif_sz, sizeof(lpif_sz));
  893. offset += sizeof(lpif_sz);
  894. memcpy(buf + offset, &cfg_sz, sizeof(cfg_sz));
  895. offset += sizeof(cfg_sz);
  896. memcpy(buf + offset, &dram_sz, sizeof(dram_sz));
  897. offset += sizeof(dram_sz);
  898. return offset;
  899. }
  900. static unsigned int save_dpm_data(u64 offset, int *len, CALLBACK dev_write)
  901. {
  902. unsigned int *buf = NULL;
  903. unsigned int headersize = 0;
  904. unsigned int datasize = 0;
  905. unsigned int channel_index = 0;
  906. unsigned char *header = malloc(DPM_HEAD_SIZE);
  907. if (!header) {
  908. return 0;
  909. }
  910. headersize += set_dpm_header(header);
  911. if (headersize > 0) {
  912. datasize += dev_write(header, headersize);
  913. }
  914. free(header);
  915. buf = (unsigned int *)(DPM_DM1_SRAM_BASE);
  916. *len = (unsigned int)(DPM_DM_OFFSET);
  917. datasize += dev_write(buf, *len);
  918. buf = (unsigned int *)(DPM_DBG_LATCH_CH0);
  919. *len = (unsigned int)(DPM_DBG_LEN);
  920. datasize += dev_write(buf, *len);
  921. buf = (unsigned int *)(DPM_CFG1_CH0);
  922. *len = (unsigned int)(DPM_CFG1_LEN);
  923. datasize += dev_write(buf, *len);
  924. buf = (unsigned int *)(DPM_CFG2_CH0);
  925. *len = (unsigned int)(DPM_CFG2_LEN);
  926. datasize += dev_write(buf, *len);
  927. for (channel_index = 0; channel_index < DRAM_CHANNEL; channel_index++) {
  928. //ddrphy RG
  929. buf = (unsigned int *)(DDRPHY_AO_CH0 + channel_index*CHANNEL_OFFSET + DDRPHY_LATCH_OFFSET);
  930. *len = (unsigned int)(DDRPHY_LATCH_LEN);
  931. datasize += dev_write(buf, *len);
  932. }
  933. return datasize;
  934. }
  935. #endif
  936. /* platform initial function */
  937. int platform_debug_init(void)
  938. {
  939. /* function pointer assignment */
  940. plat_spm_data_get = save_spm_data;
  941. /*FIXME: bypass dump sram data */
  942. //plat_spm_sram_data_get = save_spm_sram_data;
  943. plat_dram_get = save_dram_data;
  944. plat_cpu_bus_get = save_cpu_bus_data;
  945. #ifdef MTK_TINYSYS_SSPM_SUPPORT
  946. plat_sspm_coredump_get = save_sspm_coredump;
  947. plat_sspm_data_get = save_sspm_data;
  948. plat_sspm_xfile_get = save_sspm_xfile;
  949. plat_sspm_log_get = save_sspm_last_log;
  950. #endif
  951. #ifdef MTK_TINYSYS_SCP_SUPPORT
  952. plat_scp_coredump_get = save_scp_coredump;
  953. #endif
  954. plat_hvfs_get = save_hvfs_data;
  955. plat_dur_lkdump_get = save_log_dur_lkdump;
  956. plat_mcdi_get = save_mcdi_data;
  957. plat_dfd20_get = save_dfd_data;
  958. #ifdef MTK_PICACHU_SUPPORT
  959. plat_picachu_log_get = save_picachu_log;
  960. #endif
  961. dfd_op.acquire_ram_control = setup_snoop_filter_ram_ctrl;
  962. dfd_op.release_ram_control = return_snoop_filter_ram_ctrl;
  963. dfd_op.check_dfd_valid = check_dfd_valid;
  964. circular_buffer_op.lock = circular_buffer_lock;
  965. circular_buffer_op.unlock = circular_buffer_unlock;
  966. #ifdef MTK_TINYSYS_MCUPM_SUPPORT
  967. plat_mcupm_coredump_get = save_mcupm_coredump;
  968. //plat_mcupm_data_get = save_mcupm_data;
  969. //plat_mcupm_xfile_get = save_mcupm_xfile;
  970. plat_mcupm_log_get = save_mcupm_last_log;
  971. #endif
  972. #ifdef MTK_AUDIODSP_SUPPORT
  973. plat_adsp_coredump_get = save_adsp_coredump;
  974. #endif
  975. #ifdef MTK_DPM_SUPPORT
  976. plat_dpm_data_get = save_dpm_data;
  977. #endif
  978. return 1;
  979. }