aee_platform_debug.c 32 KB

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