aee_platform_debug.c 17 KB

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