aee_platform_debug.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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. #ifdef MTK_TINYSYS_SSPM_SUPPORT
  45. #include <platform/mt_sspm.h>
  46. #endif
  47. #include <mtk_mcdi.h>
  48. #ifdef MTK_SMC_ID_MGMT
  49. #include "mtk_secure_api.h"
  50. #endif
  51. #ifdef MTK_AB_OTA_UPDATER
  52. #include <mt_boot.h>
  53. #endif
  54. int plt_get_cluster_id(unsigned int cpu_id, unsigned int *core_id_in_cluster)
  55. {
  56. if (core_id_in_cluster == NULL)
  57. return -1;
  58. *core_id_in_cluster = (cpu_id % 4);
  59. return (cpu_id / 4);
  60. }
  61. unsigned long plt_get_cpu_power_status_at_wdt(void)
  62. {
  63. unsigned long bitmask = 0, ret;
  64. ret = readl(SLEEP_BASE + cfg_pc_latch.spm_pwr_sts);
  65. /* CPU0 ~ CPU3 */
  66. bitmask |= (ret & (0xf << 9)) >> 9;
  67. /* CPU4 ~ CPU7 */
  68. bitmask |= (ret & (0xf << 16)) >> 12;
  69. return bitmask;
  70. }
  71. void reset_snoop_filter_ctrl(void)
  72. {
  73. #ifdef MTK_SMC_ID_MGMT
  74. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_RESET_SNOOP_FILTER_MAGIC, 0, 0, 0);
  75. #else
  76. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_RESET_SNOOP_FILTER_MAGIC, 0, 0);
  77. #endif
  78. }
  79. static void setup_snoop_filter_ram_ctrl(void)
  80. {
  81. #ifdef MTK_SMC_ID_MGMT
  82. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_SETUP_SNOOP_FILTER_MAGIC, 0, 0, 0);
  83. #else
  84. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_SETUP_SNOOP_FILTER_MAGIC, 0, 0);
  85. #endif
  86. }
  87. static void return_snoop_filter_ram_ctrl(void)
  88. {
  89. #ifdef MTK_SMC_ID_MGMT
  90. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_RETURN_SNOOP_FILTER_MAGIC, 0, 0, 0);
  91. #else
  92. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_DFD_RETURN_SNOOP_FILTER_MAGIC, 0, 0);
  93. #endif
  94. }
  95. static void circular_buffer_lock(void)
  96. {
  97. #ifdef MTK_SMC_ID_MGMT
  98. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_CIRCULAR_BUFFER_LOCK, 0, 0, 0);
  99. #else
  100. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_CIRCULAR_BUFFER_LOCK, 0, 0);
  101. #endif
  102. }
  103. static void circular_buffer_unlock(void)
  104. {
  105. #ifdef MTK_SMC_ID_MGMT
  106. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_CIRCULAR_BUFFER_UNLOCK, 0, 0, 0);
  107. #else
  108. mt_secure_call(MTK_SIP_LK_PLAT_DEBUG, PLAT_MTK_CIRCULAR_BUFFER_UNLOCK, 0, 0);
  109. #endif
  110. }
  111. static bool dfd_valid = false;
  112. static bool check_dfd_valid(u32* data)
  113. {
  114. if (data != NULL) {
  115. /*
  116. * 0x0 = {16’h0, 1’b0, 1’b1, 14’hx}
  117. * 0x4 = 32’h0
  118. * 0x8 = 32’h0
  119. * 0xC = 32’h0
  120. */
  121. if (((data[0] & 0xffff4000) == 0x4000)
  122. && data[1] == 0x0 && data[2] == 0x0 && data[3] == 0x0)
  123. dfd_valid = true;
  124. }
  125. return dfd_valid;
  126. }
  127. unsigned int plt_get_dfd_dump_type(void)
  128. {
  129. return DFD_DUMP_TO_SRAM;
  130. }
  131. static unsigned int save_cpu_bus_data(u64 offset, int *len, CALLBACK dev_write)
  132. {
  133. char *buf = NULL;
  134. int ret;
  135. unsigned int datasize = 0;
  136. /* Save latch buffer */
  137. ret = latch_get((void **)&buf, len);
  138. if (ret && (buf != NULL)) {
  139. if (*len > 0)
  140. datasize = dev_write(buf, *len);
  141. latch_put((void **)&buf);
  142. }
  143. /* Save systracker buffer */
  144. ret = systracker_get((void **)&buf, len, 8);
  145. if (buf != NULL) {
  146. if (*len > 0)
  147. datasize += dev_write(buf, *len);
  148. systracker_put((void **)&buf);
  149. }
  150. return datasize;
  151. }
  152. static unsigned int save_dfd_data(u64 offset, int *len, CALLBACK dev_write)
  153. {
  154. char *buf = NULL;
  155. int ret;
  156. unsigned int datasize = 0;
  157. /* Save dfd buffer */
  158. ret = dfd_get((void **)&buf, len);
  159. if (buf != NULL) {
  160. if (*len > 0)
  161. datasize = dev_write(buf, *len);
  162. dfd_put((void **)&buf);
  163. }
  164. return datasize;
  165. }
  166. void platform_clear_all_on_mux(void)
  167. {
  168. /* clear rg_mcu_pwr_iso_dis */
  169. writel(readl(MCU_ALL_PWR_ON_CTRL) & ~(1 << 2), MCU_ALL_PWR_ON_CTRL);
  170. dsb();
  171. /* clear rg_mcu_pwr_on */
  172. writel(readl(MCU_ALL_PWR_ON_CTRL) & ~(1 << 1), MCU_ALL_PWR_ON_CTRL);
  173. dsb();
  174. }
  175. /* SPM Debug Features */
  176. static unsigned int spm_wdt_latch_regs[] = {
  177. SLEEP_BASE + 0x800, /* PCM_WDT_LATCH_0 */
  178. SLEEP_BASE + 0x804, /* PCM_WDT_LATCH_1 */
  179. SLEEP_BASE + 0x808, /* PCM_WDT_LATCH_2 */
  180. SLEEP_BASE + 0x80c, /* PCM_WDT_LATCH_3 */
  181. SLEEP_BASE + 0x810, /* PCM_WDT_LATCH_4 */
  182. SLEEP_BASE + 0x814, /* PCM_WDT_LATCH_5 */
  183. SLEEP_BASE + 0x818, /* PCM_WDT_LATCH_6 */
  184. SLEEP_BASE + 0x81c, /* PCM_WDT_LATCH_7 */
  185. SLEEP_BASE + 0x820, /* PCM_WDT_LATCH_8 */
  186. SLEEP_BASE + 0x824, /* PCM_WDT_LATCH_9 */
  187. SLEEP_BASE + 0x838, /* PCM_WDT_LATCH_10 */
  188. SLEEP_BASE + 0x83c, /* PCM_WDT_LATCH_11 */
  189. SLEEP_BASE + 0x888, /* PCM_WDT_LATCH_12 */
  190. SLEEP_BASE + 0x88c, /* PCM_WDT_LATCH_13 */
  191. SLEEP_BASE + 0x828, /* WDT_LATCH_SPARE0 */
  192. SLEEP_BASE + 0x82c, /* WDT_LATCH_SPARE1 */
  193. SLEEP_BASE + 0x830, /* WDT_LATCH_SPARE2 */
  194. SLEEP_BASE + 0x834, /* WDT_LATCH_SPARE3 */
  195. SLEEP_BASE + 0x780, /* WDT_LATCH_SPARE0_FIX */
  196. SLEEP_BASE + 0x784, /* WDT_LATCH_SPARE1_FIX */
  197. SLEEP_BASE + 0x788, /* WDT_LATCH_SPARE2_FIX */
  198. SLEEP_BASE + 0x78C, /* WDT_LATCH_SPARE3_FIX */
  199. SLEEP_BASE + 0x914, /* SPM_ACK_CHK_LATCH */
  200. SLEEP_BASE + 0x934, /* SPM_ACK_CHK_LATCH2 */
  201. SLEEP_BASE + 0x954, /* SPM_ACK_CHK_LATCH3 */
  202. SLEEP_BASE + 0x974, /* SPM_ACK_CHK_LATCH4 */
  203. SLEEP_BASE + 0x840, /* DCHA_GATING_LATCH_0 */
  204. SLEEP_BASE + 0x844, /* DCHA_GATING_LATCH_1 */
  205. SLEEP_BASE + 0x848, /* DCHA_GATING_LATCH_2 */
  206. SLEEP_BASE + 0x84c, /* DCHA_GATING_LATCH_3 */
  207. SLEEP_BASE + 0x850, /* DCHA_GATING_LATCH_4 */
  208. SLEEP_BASE + 0x854, /* DCHA_GATING_LATCH_5 */
  209. SLEEP_BASE + 0x858, /* DCHA_GATING_LATCH_6 */
  210. SLEEP_BASE + 0x85c, /* DCHA_GATING_LATCH_7 */
  211. SLEEP_BASE + 0x860, /* DCHB_GATING_LATCH_0 */
  212. SLEEP_BASE + 0x864, /* DCHB_GATING_LATCH_1 */
  213. SLEEP_BASE + 0x868, /* DCHB_GATING_LATCH_2 */
  214. SLEEP_BASE + 0x86c, /* DCHB_GATING_LATCH_3 */
  215. SLEEP_BASE + 0x870, /* DCHB_GATING_LATCH_4 */
  216. SLEEP_BASE + 0x874, /* DCHB_GATING_LATCH_5 */
  217. SLEEP_BASE + 0x878, /* DCHB_GATING_LATCH_6 */
  218. SLEEP_BASE + 0x87c, /* DCHB_GATING_LATCH_7 */
  219. SLEEP_BASE + 0x880, /* DCHA_LATCH_RSV0 */
  220. SLEEP_BASE + 0x884, /* DCHB_LATCH_RSV0 */
  221. SLEEP_BASE + 0x794, /* DCHA_LATCH_RSV0_FIX */
  222. SLEEP_BASE + 0x79c, /* DCHB_LATCH_RSV0_FIX */
  223. };
  224. #define DVFSRC_DUMP (DVFSRC_BASE + 0x400)
  225. #define DVFSRC_SIZE 0xE0
  226. /* need to check aee_db_file_info[] @ app/mt_boot/aee/KEDump.c */
  227. #define SPM_DATA_BUF_LENGTH (4096)
  228. static int spm_dump_data(char *buf, int *wp)
  229. {
  230. unsigned int i;
  231. unsigned val;
  232. #ifdef SPM_FW_USE_PARTITION
  233. char part_name[16] = "spmfw";
  234. #ifdef MTK_AB_OTA_UPDATER
  235. get_AB_OTA_name((void *)&part_name, sizeof(part_name));
  236. #endif /* MTK_AB_OTA_UPDATER */
  237. #endif /* SPM_FW_USE_PARTITION */
  238. if (buf == NULL || wp == NULL)
  239. return -1;
  240. for (i = 0; i < (sizeof(spm_wdt_latch_regs)/sizeof(unsigned int)); i++) {
  241. val = readl(spm_wdt_latch_regs[i]);
  242. *wp += sprintf(buf + *wp,
  243. "SPM regs(0x%x) = 0x%x\n",
  244. spm_wdt_latch_regs[i], val);
  245. }
  246. #ifdef SPM_FW_USE_PARTITION
  247. get_spmfw_version(part_name, "spmfw", buf, wp);
  248. #endif /* SPM_FW_USE_PARTITION */
  249. for (i = 0; i < DVFSRC_SIZE; i += 4) {
  250. val = readl(DVFSRC_DUMP + i);
  251. *wp += sprintf(buf + *wp,
  252. "DVFSRC regs(0x%x) = 0x%08x\n", DVFSRC_DUMP + i, val);
  253. }
  254. if (*wp > SPM_DATA_BUF_LENGTH) {
  255. dprintf(CRITICAL, "[spm] out of range: 0x%x > SPM_DATA_BUF_LENGTH(0x%x)\n", *wp, SPM_DATA_BUF_LENGTH);
  256. assert(0);
  257. }
  258. return 1;
  259. }
  260. int spm_data_get(void **data, int *len)
  261. {
  262. int ret;
  263. *len = 0;
  264. *data = malloc(SPM_DATA_BUF_LENGTH);
  265. if (*data == NULL)
  266. return 0;
  267. ret = spm_dump_data(*data, len);
  268. if (ret < 0 || *len > SPM_DATA_BUF_LENGTH) {
  269. *len = (*len > SPM_DATA_BUF_LENGTH) ? SPM_DATA_BUF_LENGTH : *len;
  270. return ret;
  271. }
  272. return 1;
  273. }
  274. void spm_data_put(void **data)
  275. {
  276. free(*data);
  277. }
  278. static unsigned int save_spm_data(u64 offset, int *len, CALLBACK dev_write)
  279. {
  280. char *buf = NULL;
  281. unsigned int datasize = 0;
  282. /* Save SPM buffer */
  283. spm_data_get((void **)&buf, len);
  284. if (buf != NULL) {
  285. if (*len > 0)
  286. datasize = dev_write(buf, *len);
  287. spm_data_put((void **)&buf);
  288. }
  289. return datasize;
  290. }
  291. /* FOR DRAMC data and DRAM Calibration Log
  292. *
  293. * This area is applied for DRAM related debug.
  294. */
  295. /* DRAMC data */
  296. #define DRAM_DEBUG_SRAM_ADDRESS 0x11D800
  297. #define DRAM_DEBUG_SRAM_LENGTH 1024
  298. static int plat_dram_debug_get(void **data, int *len)
  299. {
  300. *data = (void *)DRAM_DEBUG_SRAM_ADDRESS;
  301. *len = DRAM_DEBUG_SRAM_LENGTH;
  302. return 1;
  303. }
  304. /* shared SRAM for DRAMLOG calibration log */
  305. #define DRAM_KLOG_SRAM_ADDRESS 0x0011E000
  306. #define DRAM_KLOG_SRAM_LENGTH 8192
  307. #define DRAM_KLOG_VALID_ADDRESS 0x0011E00C
  308. static int plat_dram_klog_get(void **data, int *len)
  309. {
  310. *data = (void *)DRAM_KLOG_SRAM_ADDRESS;
  311. *len = DRAM_KLOG_SRAM_LENGTH;
  312. return 1;
  313. }
  314. static bool plat_dram_has_klog(void)
  315. {
  316. if (*(volatile unsigned int*)DRAM_KLOG_VALID_ADDRESS)
  317. return true;
  318. return false;
  319. }
  320. static unsigned int save_dram_data(u64 offset, int *len, CALLBACK dev_write)
  321. {
  322. char *buf = NULL;
  323. unsigned int datasize = 0, allsize = 0;
  324. if (plat_dram_debug_get((void **)&buf, len)) {
  325. datasize = dev_write(buf, *len);
  326. allsize = datasize;
  327. }
  328. if (plat_dram_klog_get((void **)&buf, len)) {
  329. buf = malloc(*len);
  330. if (buf) {
  331. mrdump_read_log(buf, *len, MRDUMP_EXPDB_DRAM_KLOG_OFFSET);
  332. datasize = dev_write(buf, *len);
  333. allsize += datasize;
  334. free(buf);
  335. }
  336. }
  337. return allsize;
  338. }
  339. #ifdef MTK_TINYSYS_SSPM_SUPPORT
  340. void udelay (unsigned long usec);
  341. #define SSPM_RETRY 10
  342. static unsigned int save_sspm_coredump(u64 offset, int *len, CALLBACK dev_write)
  343. {
  344. unsigned int buf = 0;
  345. unsigned int datasize = 0;
  346. int retry = SSPM_RETRY;
  347. if (!(*(unsigned int *)SSPM_BACKUP)) {
  348. return 0;
  349. }
  350. do {
  351. buf = *(unsigned int *)(SSPM_DM_ADDR);
  352. *len = *(int *)SSPM_DM_SZ;
  353. if ( (buf != 0) && (*len > 0) ) {
  354. datasize = dev_write( (unsigned int *)buf, *len);
  355. break;
  356. } else {
  357. udelay(100);
  358. }
  359. } while ( --retry);
  360. buf = *(unsigned int *)(SSPM_RM_ADDR);
  361. *len = *(int *)SSPM_RM_SZ;
  362. if ( (buf != 0) && (*len > 0) ) {
  363. datasize += dev_write( (unsigned int *)buf, *len);
  364. }
  365. return datasize;
  366. }
  367. static unsigned int save_sspm_data(u64 offset, int *len, CALLBACK dev_write)
  368. {
  369. #define SSPM_BUF_LEN 768
  370. char *buf = NULL;
  371. unsigned int datasize = 0, tbufl, tbufh, r, i, j;
  372. int length = 0;
  373. buf = malloc(SSPM_BUF_LEN);
  374. if (!buf) {
  375. return 0;
  376. }
  377. memset(buf, 0, SSPM_BUF_LEN);
  378. length += snprintf(buf + length, SSPM_BUF_LEN - length,
  379. "AHB_STATUS: 0x%x\n"
  380. "AHB_M0_ADDR: 0x%x\n"
  381. "AHB_M1_ADDR: 0x%x\n"
  382. "AHB_M2_ADDR: 0x%x\n"
  383. "LastSP: 0x%x\n"
  384. "LastLR: 0x%x\n"
  385. "LastPC: 0x%x\n",
  386. DRV_Reg32(SSPM_AHB_STATUS), DRV_Reg32(SSPM_AHB_M0_ADDR),
  387. DRV_Reg32(SSPM_AHB_M1_ADDR), DRV_Reg32(SSPM_AHB_M2_ADDR),
  388. DRV_Reg32(SSPM_MD32_SP), DRV_Reg32(SSPM_MD32_LR),
  389. DRV_Reg32(SSPM_MD32_PC));
  390. r = DRV_Reg32(SSPM_TBUF_WPTR);
  391. length += snprintf(buf + length, SSPM_BUF_LEN - length, "\nSSPM_TBUF_WPTR=%u\n", r);
  392. for (i = 0, j = r; i < 16; ++i, j = (j-1) & 0xF) {
  393. DRV_WriteReg32(SSPM_DBG_SEL, j);
  394. tbufl = DRV_Reg32(SSPM_TBUFL);
  395. tbufh = DRV_Reg32(SSPM_TBUFH);
  396. length += snprintf(buf + length, SSPM_BUF_LEN - length, "%u: TBUF=%u TBUFH=0x%x TBUFL=0x%x\n", i, j, tbufh, tbufl);
  397. }
  398. *len = length;
  399. if (*len > 0) {
  400. datasize = dev_write(buf, (*len > SSPM_BUF_LEN ? SSPM_BUF_LEN : *len));
  401. }
  402. free(buf);
  403. return datasize;
  404. }
  405. static unsigned int save_sspm_xfile(u64 offset, int *len, CALLBACK dev_write)
  406. {
  407. unsigned int buf = 0;
  408. unsigned int datasize = 0;
  409. unsigned int sspm_info;
  410. int ret;
  411. /* Get the information stored in SSPM_INFO by preloader
  412. struct sspm_info_t {
  413. unsigned int sspm_dm_ofs;
  414. unsigned int sspm_dm_sz;
  415. unsigned int rd_ofs;
  416. unsigned int rd_sz;
  417. unsigned int xfile_addr;
  418. unsigned int xfile_sz;
  419. };
  420. */
  421. sspm_info = *(unsigned int *)SSPM_INFO;
  422. #ifdef MTK_3LEVEL_PAGETABLE
  423. ret = arch_mmu_map(ROUNDDOWN((uint64_t)sspm_info, SECTION_SIZE),
  424. ROUNDDOWN((uint32_t)sspm_info, SECTION_SIZE),
  425. MMU_MEMORY_TYPE_NORMAL_WRITE_BACK | MMU_MEMORY_AP_P_RW_U_NA,
  426. SECTION_SIZE);
  427. if (ret) {
  428. dprintf(CRITICAL, "kedump: mmu map to 0x%llx fail(%d), SSPM dump might fail.\n",
  429. ROUNDDOWN((uint64_t)sspm_info, SECTION_SIZE), ret);
  430. return 0;
  431. }
  432. #endif
  433. buf = *((unsigned int *)sspm_info + 4);
  434. *len = *((int *)sspm_info + 5);
  435. dprintf(CRITICAL, "buf 0x%x, len:0x%x\n", buf, *len);
  436. if ( (buf != 0) && (*len > 0) ) {
  437. datasize = dev_write( (unsigned int *)buf, *len);
  438. }
  439. return datasize;
  440. }
  441. static unsigned int save_sspm_last_log(u64 offset, int *len, CALLBACK dev_write)
  442. {
  443. unsigned int buf = 0;
  444. unsigned int datasize = 0;
  445. buf = *(unsigned int *)(SSPM_LASTK_ADDR);
  446. *len = *(int *)SSPM_LASTK_SZ;
  447. if ( (buf != 0) && (*len > 0) ) {
  448. datasize = dev_write( (unsigned int *)buf, *len);
  449. }
  450. return datasize;
  451. }
  452. #endif
  453. static int plat_write_dram_klog(void)
  454. {
  455. char *sram_base = NULL;
  456. int len = 0;
  457. if (plat_dram_klog_get((void **)&sram_base, (int *)&len)) {
  458. if (plat_dram_has_klog()) {
  459. mrdump_write_log(MRDUMP_EXPDB_DRAM_KLOG_OFFSET, sram_base, len);
  460. }
  461. }
  462. return 0;
  463. }
  464. /* SRAM for Hybrid CPU DVFS */
  465. #define HVFS_SRAM_ADDRESS 0x0011bc00
  466. #define HVFS_SRAM_LENGTH 0x1400 /* 5K bytes */
  467. static int plat_hvfs_data_get(void **data, int *len)
  468. {
  469. *data = (void *)HVFS_SRAM_ADDRESS;
  470. *len = HVFS_SRAM_LENGTH;
  471. return 1;
  472. }
  473. static unsigned int save_hvfs_data(u64 offset, int *len, CALLBACK dev_write)
  474. {
  475. char *buf = NULL;
  476. unsigned int datasize = 0;
  477. if (plat_hvfs_data_get((void **)&buf, len)) {
  478. datasize = dev_write(buf, *len);
  479. }
  480. return datasize;
  481. }
  482. static int plat_log_dur_lkdump_get(void **data, int *len)
  483. {
  484. *data = (void *)current_buf_addr_get();
  485. *len = current_buf_pl_lk_log_size_get();
  486. if((*data == 0) || (*len == 0)) {
  487. dprintf(CRITICAL, "[LK_LOG_STORE] invalid current address or log length(addr 0x%x, len 0x%x)\n", (unsigned int)*data, (unsigned int)*len);
  488. return 0;
  489. }
  490. dprintf(CRITICAL, "[LK_LOG_STORE] the current buf addr is 0x%x, log len is 0x%x\n", (unsigned int)*data, (unsigned int)*len);
  491. return 1;
  492. }
  493. static unsigned int save_log_dur_lkdump(u64 offset, int *len, CALLBACK dev_write)
  494. {
  495. char *buf = NULL;
  496. unsigned int datasize = 0;
  497. if (plat_log_dur_lkdump_get((void **)&buf, len)) {
  498. datasize = dev_write(buf, *len);
  499. }
  500. return datasize;
  501. }
  502. static int plat_mcdi_data_get(void **data, int *len)
  503. {
  504. mcdi_setup_file_info_for_kedump();
  505. *data = (void *)MCDI_SRAM_ADDRESS;
  506. *len = MCDI_SRAM_LENGTH;
  507. return 1;
  508. }
  509. static unsigned int save_mcdi_data(u64 offset, int *len, CALLBACK dev_write)
  510. {
  511. char *buf = NULL;
  512. unsigned int datasize = 0;
  513. if (plat_mcdi_data_get((void **)&buf, len)) {
  514. datasize = dev_write(buf, *len);
  515. }
  516. return datasize;
  517. }
  518. /* platform initial function */
  519. int platform_debug_init(void)
  520. {
  521. /* function pointer assignment */
  522. plat_spm_data_get = save_spm_data;
  523. plat_dram_get = save_dram_data;
  524. plat_cpu_bus_get = save_cpu_bus_data;
  525. #ifdef MTK_TINYSYS_SSPM_SUPPORT
  526. plat_sspm_coredump_get = save_sspm_coredump;
  527. plat_sspm_data_get = save_sspm_data;
  528. plat_sspm_xfile_get = save_sspm_xfile;
  529. plat_sspm_log_get = save_sspm_last_log;
  530. #endif
  531. plat_hvfs_get = save_hvfs_data;
  532. plat_dur_lkdump_get = save_log_dur_lkdump;
  533. plat_mcdi_get = save_mcdi_data;
  534. plat_dfd20_get = save_dfd_data;
  535. dfd_op.acquire_ram_control = setup_snoop_filter_ram_ctrl;
  536. dfd_op.release_ram_control = return_snoop_filter_ram_ctrl;
  537. dfd_op.check_dfd_valid = check_dfd_valid;
  538. circular_buffer_op.lock = circular_buffer_lock;
  539. circular_buffer_op.unlock = circular_buffer_unlock;
  540. /* routine tasks */
  541. plat_write_dram_klog();
  542. return 1;
  543. }