mt_mcupm_excep.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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) 2015. 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 <stdint.h>
  32. #include <string.h>
  33. #include <debug.h>
  34. #include <platform/boot_mode.h>
  35. #include <platform/partition.h>
  36. #include <platform/verified_boot.h>
  37. #include <platform/sec_policy.h>
  38. #include <assert.h>
  39. #include <platform/mt_mcupm.h>
  40. #include <platform/errno.h>
  41. #include <mt_mcupm.h>
  42. #include <mt_mcupm_excep.h>
  43. #include <reg.h>
  44. #include <malloc.h>
  45. #include <lib/crc.h>
  46. #include <lib/zutil.h>
  47. #include <lib/zlib.h>
  48. #include <platform/mtk_wdt.h>
  49. #ifdef MTK_3LEVEL_PAGETABLE
  50. #include <arch/arm/mmu.h>
  51. #include <stdlib.h>
  52. #include <err.h>
  53. #endif
  54. struct mcupm_reg_save_st {
  55. uint32_t addr;
  56. uint32_t size;
  57. };
  58. struct mcupm_reg_save_st mcupm_reg_save_list[] = {
  59. {0x0C560000, 0x1000},
  60. {0x0C562000, 0x100},
  61. };
  62. void mcupm_do_regdump(uint32_t *out, uint32_t *out_end)
  63. {
  64. int i = 0;
  65. void *from;
  66. uint32_t *buf = out;
  67. int size_limit = sizeof(mcupm_reg_save_list) / sizeof(struct mcupm_reg_save_st);
  68. uint32_t *update = NULL;
  69. int totalsize = 0, dfd_status = 0;
  70. dprintf(CRITICAL, "mcupm mcupm_do_regdump\n");
  71. for (i = 0; i < size_limit; i++) {
  72. if (((uint32_t)buf + mcupm_reg_save_list[i].size
  73. + sizeof(struct mcupm_reg_save_st)) > (uint32_t)out_end) {
  74. dprintf(CRITICAL, "[MCUPM] %s overflow\n", __func__);
  75. break;
  76. }
  77. *buf = mcupm_reg_save_list[i].addr;
  78. buf++;
  79. *buf = mcupm_reg_save_list[i].size;
  80. buf++;
  81. totalsize += 2;
  82. from = (void *)mcupm_reg_save_list[i].addr;
  83. memcpy(buf, from, mcupm_reg_save_list[i].size);
  84. buf += (mcupm_reg_save_list[i].size / sizeof(uint32_t));
  85. totalsize += (mcupm_reg_save_list[i].size / sizeof(uint32_t));
  86. }
  87. buf = buf - totalsize + 2;
  88. update = (unsigned int *)(DRV_Reg32(MCUPM_LAST_PCLRSP) + MCUPM_SRAM_BASE);
  89. buf = buf + (CPUEB_CFGREG_DBG_MON_PC/sizeof(uint32_t));
  90. dfd_status = DRV_Reg32(DFD_STATUS);
  91. if (dfd_status == 0) {
  92. DRV_WriteReg32(buf, DRV_Reg32(MCUPM_SW_RSTN +
  93. CPUEB_CFGREG_DBG_MON_PC));
  94. DRV_WriteReg32(buf+1, DRV_Reg32(MCUPM_SW_RSTN +
  95. CPUEB_CFGREG_DBG_MON_LR));
  96. DRV_WriteReg32(buf+2, DRV_Reg32(MCUPM_SW_RSTN +
  97. CPUEB_CFGREG_DBG_MON_SP));
  98. }
  99. else {
  100. DRV_WriteReg32(buf, DRV_Reg32(update));
  101. DRV_WriteReg32(buf+1, DRV_Reg32(update + 1));
  102. DRV_WriteReg32(buf+2, DRV_Reg32(update + 2));
  103. }
  104. }
  105. #if 0
  106. void mcupm_do_l1cdump(uint32_t *out, uint32_t *out_end)
  107. {
  108. uint32_t *buf = out;
  109. uint32_t tmp;
  110. tmp = readl(R_SEC_CTRL);
  111. /* enable cache debug */
  112. writel(tmp | B_CORE0_CACHE_DBG_EN | B_CORE1_CACHE_DBG_EN, R_SEC_CTRL);
  113. if ((uint32_t)buf + MDUMP_L1C_SIZE > (uint32_t)out_end) {
  114. dprintf(CRITICAL, "[MCUPM] %s overflow\n", __func__);
  115. return;
  116. }
  117. memcpy(buf, (void *)R_CORE0_CACHE_RAM, MDUMP_L1C_SIZE);
  118. /* disable cache debug */
  119. writel(tmp, R_SEC_CTRL);
  120. }
  121. #endif
  122. void mcupm_do_tbufdump(uint32_t *out, uint32_t *out_end)
  123. {
  124. uint32_t *buf = out;
  125. unsigned int tbuf[8*4];
  126. #if 0
  127. uint32_t tmp;
  128. int i;
  129. tmp = readl(MCUPM_TBUF_WPTR);
  130. for (i = 0; i < 7; i++) {
  131. //writel(tmp | (i << S_CORE_TBUF_DBG_SEL), R_CORE0_DBG_CTRL);
  132. writel(tmp, MCUPM_TBUF_ADDR);
  133. *(buf + 0) = readl(MCUPM_TBUF_DATA31_0);
  134. *(buf + 1) = readl(MCUPM_TBUF_DATA63_32);
  135. *(buf + 2) = readl(MCUPM_TBUF_DATA95_64);
  136. *(buf + 3) = readl(MCUPM_TBUF_DATA127_96);
  137. buf += 4;
  138. if (tmp == 0)
  139. tmp = 7;
  140. else tmp--;
  141. }
  142. for (i = 0; i < 32; i++) {
  143. dprintf(CRITICAL, "[MCUPM] tbuf %02d:0x%08x::0x%08x\n",
  144. i, *(out + i), *(out + i + 1));
  145. }
  146. #endif
  147. memcpy(buf, (DRV_Reg32(MCUPM_LAST_TBUF) + MCUPM_SRAM_BASE), sizeof(tbuf));
  148. }
  149. /*
  150. * this function need MCUPM to keeping awaken
  151. * mcupm_crash_dump: dump mcupm tcm info.
  152. * @param MemoryDump: mcupm dump struct
  153. * @param mcupm_core_id: core id
  154. * @return: mcupm dump size
  155. */
  156. int mcupm_crash_dump(void *crash_buffer)
  157. {
  158. unsigned int mcupm_dump_size;
  159. int datasize, ret = 0;
  160. struct MemoryDumpMCUPM *pMemoryDump;
  161. void *tmp_ptr;
  162. uint32_t dram_start = 0;
  163. uint32_t dram_size = 0;
  164. uint32_t tmp;
  165. tmp = DRV_Reg32(GPR_BASE_ADDR(0));
  166. /* region_info will be null when recovery boot fail, skip coredump */
  167. if (tmp == NULL) {
  168. dprintf(CRITICAL, "[mcupm] mcupm_region_info = 0, skip coredump\n");
  169. return 0;
  170. }
  171. //set mmu
  172. ret = arch_mmu_map((uint64_t)tmp, (uint32_t)tmp,
  173. MMU_MEMORY_TYPE_NORMAL_WRITE_BACK |
  174. MMU_MEMORY_AP_P_RW_U_NA, BLOCK_SIZE);
  175. if (ret != NO_ERROR) {
  176. dprintf(CRITICAL, "kedump: mmu map to 0x%llx fail(%d), MCUPM dump might fail.\n", (uint64_t)tmp, ret);
  177. return 0;
  178. }
  179. pMemoryDump = (void *)crash_buffer;
  180. memcpy((void *)&(pMemoryDump->l2tcm), DRV_Reg32(MCUPM_DM_ADDR),DRV_Reg32(MCUPM_DM_SZ));
  181. /* dump sys registers */
  182. mcupm_do_regdump((void *)&(pMemoryDump->regdump),
  183. (void *)&(pMemoryDump->tbuf));
  184. mcupm_do_tbufdump((void *)&(pMemoryDump->tbuf), (void *)&(pMemoryDump->dram));
  185. mcupm_dump_size = MDUMP_L2TCM_SIZE + MDUMP_REGDUMP_SIZE + MDUMP_TBUF_SIZE;
  186. dprintf(CRITICAL, "[mcupm] mcupm_crash_dump success.\n");
  187. return mcupm_dump_size;
  188. }