aee_platform_debug.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 <spm_common.h>
  34. #include <platform/mt_reg_base.h>
  35. #include <platform/mt_typedefs.h>
  36. #include <platform/mtk_wdt.h>
  37. #include <platform/partition.h>
  38. #include <platform/platform_debug.h>
  39. #include "log_store_lk.h"
  40. #include <plat_debug_interface.h>
  41. #include <reg.h>
  42. #include <fdt.h>
  43. #include <libfdt.h>
  44. #include <debug.h>
  45. #include <mtk_mcdi.h>
  46. #ifdef MTK_AB_OTA_UPDATER
  47. #include <mt_boot.h>
  48. #endif
  49. int plt_get_cluster_id(unsigned int cpu_id, unsigned int *core_id_in_cluster)
  50. {
  51. if (core_id_in_cluster == NULL)
  52. return -1;
  53. *core_id_in_cluster = (cpu_id % 4);
  54. return (cpu_id / 4);
  55. }
  56. unsigned long plt_get_cpu_power_status_at_wdt(void)
  57. {
  58. unsigned long bitmask = 0, ret;
  59. ret = readl(SLEEP_BASE + cfg_pc_latch.spm_pwr_sts);
  60. /* CPU0 ~ CPU3 */
  61. bitmask |= (ret & (0xf << 9)) >> 9;
  62. /* CPU4 ~ CPU7 */
  63. bitmask |= (ret & (0xf << 16)) >> 12;
  64. return bitmask;
  65. }
  66. unsigned int plt_get_dfd_dump_type(void)
  67. {
  68. /* for mt6739 with DFD 3.0 -> always dump to DRAM*/
  69. if (cfg_dfd.version >= DFD_V3_0)
  70. return DFD_DUMP_TO_DRAM;
  71. else
  72. return DFD_DUMP_NOT_SUPPORT;
  73. }
  74. static unsigned int save_cpu_bus_data(u64 offset, int *len, CALLBACK dev_write)
  75. {
  76. char *buf = NULL;
  77. int ret;
  78. unsigned int datasize = 0;
  79. /* Save latch buffer */
  80. ret = latch_get((void **)&buf, len);
  81. if (ret && (buf != NULL)) {
  82. if (*len > 0)
  83. datasize = dev_write(buf, *len);
  84. latch_put((void **)&buf);
  85. }
  86. /* Save systracker buffer */
  87. ret = systracker_get((void **)&buf, len, 8);
  88. if (ret && (buf != NULL)) {
  89. if (*len > 0)
  90. datasize += dev_write(buf, *len);
  91. systracker_put((void **)&buf);
  92. }
  93. return datasize;
  94. }
  95. static unsigned int save_dfd_data(u64 offset, int *len, CALLBACK dev_write)
  96. {
  97. char *buf = NULL;
  98. unsigned int datasize = 0;
  99. /* Save dfd buffer */
  100. if (dfd_get((void **)&buf, len)) {
  101. datasize = dev_write(buf, *len);
  102. dfd_put((void **)&buf);
  103. }
  104. return datasize;
  105. }
  106. void platform_lastpc_postinit(void)
  107. {
  108. mt_secure_call(MTK_SIP_LK_LASTPC_AARCH32, 0, 0, 0);
  109. }
  110. /* SPM Debug Features */
  111. static unsigned int spm_wdt_latch_regs[] = {
  112. SLEEP_BASE + 0x800, /* PCM_WDT_LATCH_0 */
  113. SLEEP_BASE + 0x804, /* PCM_WDT_LATCH_1 */
  114. SLEEP_BASE + 0x808, /* PCM_WDT_LATCH_2 */
  115. SLEEP_BASE + 0x80c, /* PCM_WDT_LATCH_3 */
  116. SLEEP_BASE + 0x810, /* PCM_WDT_LATCH_4 */
  117. SLEEP_BASE + 0x814, /* PCM_WDT_LATCH_5 */
  118. SLEEP_BASE + 0x818, /* PCM_WDT_LATCH_6 */
  119. SLEEP_BASE + 0x81c, /* PCM_WDT_LATCH_7 */
  120. SLEEP_BASE + 0x820, /* PCM_WDT_LATCH_8 */
  121. SLEEP_BASE + 0x824, /* PCM_WDT_LATCH_9 */
  122. SLEEP_BASE + 0x838, /* PCM_WDT_LATCH_10 */
  123. SLEEP_BASE + 0x83c, /* PCM_WDT_LATCH_11 */
  124. SLEEP_BASE + 0x828, /* WDT_LATCH_SPARE0 */
  125. SLEEP_BASE + 0x82c, /* WDT_LATCH_SPARE1 */
  126. SLEEP_BASE + 0x830, /* WDT_LATCH_SPARE2 */
  127. SLEEP_BASE + 0x834, /* WDT_LATCH_SPARE3 */
  128. SLEEP_BASE + 0x840, /* DCHA_GATING_LATCH_0 */
  129. SLEEP_BASE + 0x844, /* DCHA_GATING_LATCH_1 */
  130. SLEEP_BASE + 0x848, /* DCHA_GATING_LATCH_2 */
  131. SLEEP_BASE + 0x84C, /* DCHA_GATING_LATCH_3 */
  132. SLEEP_BASE + 0x850, /* DCHA_GATING_LATCH_4 */
  133. SLEEP_BASE + 0x854, /* DCHA_GATING_LATCH_5 */
  134. SLEEP_BASE + 0x858, /* DCHA_GATING_LATCH_6 */
  135. SLEEP_BASE + 0x85C, /* DCHA_GATING_LATCH_7 */
  136. SLEEP_BASE + 0x880, /* DCHA_LATCH_RSV0 */
  137. };
  138. #define DVFSRC_DUMP (DVFSRC_BASE + 0x100)
  139. #define DVFSRC_SIZE 0xA0
  140. #define SPM_DATA_BUF_LENGTH (4096)
  141. static int spm_dump_data(char *buf, int *wp)
  142. {
  143. unsigned int i;
  144. unsigned val;
  145. #ifdef SPM_FW_USE_PARTITION
  146. char part_name[16] = "spmfw";
  147. #ifdef MTK_AB_OTA_UPDATER
  148. get_AB_OTA_name((void *)&part_name, sizeof(part_name));
  149. #endif /* MTK_AB_OTA_UPDATER */
  150. #endif /* SPM_FW_USE_PARTITION */
  151. if (buf == NULL || wp == NULL)
  152. return -1;
  153. /*
  154. * Example output:
  155. * SPM Suspend debug regs(index 1) = 0x8320535
  156. * SPM Suspend debug regs(index 2) = 0xfe114200
  157. * SPM Suspend debug regs(index 3) = 0x3920fffe
  158. * SPM Suspend debug regs(index 4) = 0x3ac06f4f
  159. */
  160. for (i = 0; i < (sizeof(spm_wdt_latch_regs)/sizeof(unsigned int)); i++) {
  161. val = readl(spm_wdt_latch_regs[i]);
  162. *wp += sprintf(buf + *wp,
  163. "SPM debug regs(0x%x) = 0x%x\n",
  164. spm_wdt_latch_regs[i], val);
  165. }
  166. #ifdef SPM_FW_USE_PARTITION
  167. get_spmfw_version(part_name, "spmfw", buf, wp);
  168. #endif /* SPM_FW_USE_PARTITION */
  169. for (i = 0; i < DVFSRC_SIZE; i+=4) {
  170. val = readl(DVFSRC_DUMP+i);
  171. *wp += sprintf(buf + *wp,
  172. "DVFSRC debug regs(0x%x) = 0x%08x\n", DVFSRC_DUMP+i, val);
  173. }
  174. return 1;
  175. }
  176. int spm_data_get(void **data, int *len)
  177. {
  178. int ret;
  179. *len = 0;
  180. *data = malloc(SPM_DATA_BUF_LENGTH);
  181. if (*data == NULL)
  182. return 0;
  183. ret = spm_dump_data(*data, len);
  184. if (ret < 0 || *len > SPM_DATA_BUF_LENGTH) {
  185. *len = (*len > SPM_DATA_BUF_LENGTH) ? SPM_DATA_BUF_LENGTH : *len;
  186. return ret;
  187. }
  188. return 1;
  189. }
  190. void spm_data_put(void **data)
  191. {
  192. free(*data);
  193. }
  194. static unsigned int save_spm_data(u64 offset, int *len, CALLBACK dev_write)
  195. {
  196. char *buf = NULL;
  197. unsigned int datasize = 0;
  198. /* Save SPM buffer */
  199. spm_data_get((void **)&buf, len);
  200. if (buf != NULL) {
  201. if (*len > 0)
  202. datasize = dev_write(buf, *len);
  203. spm_data_put((void **)&buf);
  204. }
  205. return datasize;
  206. }
  207. /* FOR DRAMC data and DRAM Calibration Log
  208. *
  209. * This area is applied for DRAM related debug.
  210. */
  211. /* DRAMC data */
  212. #define DRAM_DEBUG_SRAM_ADDRESS 0x0010E400
  213. #define DRAM_DEBUG_SRAM_LENGTH 1024
  214. static int plat_dram_debug_get(void **data, int *len)
  215. {
  216. *data = (void *)DRAM_DEBUG_SRAM_ADDRESS;
  217. *len = DRAM_DEBUG_SRAM_LENGTH;
  218. return 1;
  219. }
  220. /* shared SRAM for DRAMLOG calibration log */
  221. #define DRAM_KLOG_SRAM_ADDRESS 0x0010EA00
  222. #define DRAM_KLOG_SRAM_LENGTH 4608
  223. #define DRAM_KLOG_VALID_ADDRESS (DRAM_KLOG_SRAM_ADDRESS +0xC)
  224. static int plat_dram_klog_get(void **data, int *len)
  225. {
  226. *data = (void *)DRAM_KLOG_SRAM_ADDRESS;
  227. *len = DRAM_KLOG_SRAM_LENGTH;
  228. return 1;
  229. }
  230. static bool plat_dram_has_klog(void)
  231. {
  232. if (*(volatile unsigned int*)DRAM_KLOG_VALID_ADDRESS)
  233. return true;
  234. return false;
  235. }
  236. static unsigned int save_dram_data(u64 offset, int *len, CALLBACK dev_write)
  237. {
  238. char *buf = NULL;
  239. unsigned int datasize = 0, allsize = 0;
  240. if (plat_dram_debug_get((void **)&buf, len)) {
  241. datasize = dev_write(buf, *len);
  242. allsize = datasize;
  243. }
  244. if (plat_dram_klog_get((void **)&buf, len)) {
  245. buf = malloc(*len);
  246. if (buf) {
  247. mrdump_read_log(buf, *len, MRDUMP_EXPDB_DRAM_KLOG_OFFSET);
  248. datasize = dev_write(buf, *len);
  249. allsize += datasize;
  250. free(buf);
  251. }
  252. }
  253. return allsize;
  254. }
  255. static int plat_write_dram_klog(void)
  256. {
  257. char *sram_base = NULL;
  258. int len = 0;
  259. if (plat_dram_klog_get((void **)&sram_base, (int *)&len)) {
  260. if (plat_dram_has_klog()) {
  261. mrdump_write_log(MRDUMP_EXPDB_DRAM_KLOG_OFFSET, sram_base, len);
  262. }
  263. }
  264. return 0;
  265. }
  266. /* SRAM for Hybrid CPU DVFS */
  267. #define HVFS_SRAM_ADDRESS 0x0011bc00
  268. #define HVFS_SRAM_LENGTH 0x1400 /* 5K bytes */
  269. static int plat_hvfs_data_get(void **data, int *len)
  270. {
  271. *data = (void *)HVFS_SRAM_ADDRESS;
  272. *len = HVFS_SRAM_LENGTH;
  273. return 1;
  274. }
  275. static unsigned int save_hvfs_data(u64 offset, int *len, CALLBACK dev_write)
  276. {
  277. char *buf = NULL;
  278. unsigned int datasize = 0;
  279. if (plat_hvfs_data_get((void **)&buf, len)) {
  280. datasize = dev_write(buf, *len);
  281. }
  282. return datasize;
  283. }
  284. static int plat_mcdi_data_get(void **data, int *len)
  285. {
  286. mcdi_setup_file_info_for_kedump();
  287. *data = (void *)MCDI_SRAM_ADDRESS;
  288. *len = MCDI_SRAM_LENGTH;
  289. return 1;
  290. }
  291. static unsigned int save_mcdi_data(u64 offset, int *len, CALLBACK dev_write)
  292. {
  293. char *buf = NULL;
  294. unsigned int datasize = 0;
  295. if (plat_mcdi_data_get((void **)&buf, len)) {
  296. datasize = dev_write(buf, *len);
  297. }
  298. return datasize;
  299. }
  300. /* platform initial function */
  301. int platform_debug_init(void)
  302. {
  303. /* function pointer assignment */
  304. plat_spm_data_get = save_spm_data;
  305. plat_dram_get = save_dram_data;
  306. plat_hvfs_get = save_hvfs_data;
  307. plat_cpu_bus_get = save_cpu_bus_data;
  308. plat_mcdi_get = save_mcdi_data;
  309. /* check dfd_valid_before_reboot and efuse for DFD 3.0 */
  310. if ((readl(cfg_dfd.plat_sram_flag1) & 0x2) && (get_efuse_dfd_disabled() == 0x0)) {
  311. plat_dfd20_get = save_dfd_data;
  312. }
  313. /* routine tasks */
  314. plat_write_dram_klog();
  315. return 1;
  316. }
  317. extern int get_ccci_md_view_smem_addr(unsigned long long *ap_addr, unsigned int *md_addr);
  318. int dfd_set_base_addr(void *fdt)
  319. {
  320. int ret = 0;
  321. int offset;
  322. u64 addr;
  323. unsigned int md_addr;
  324. unsigned long long ap_addr;
  325. if (!fdt)
  326. return -1;
  327. ret = get_ccci_md_view_smem_addr(&ap_addr, &md_addr);
  328. if (ret < 0)
  329. return ret;
  330. offset = fdt_path_offset(fdt, "/chosen");
  331. if (offset < 0)
  332. return offset;
  333. /* pass base address to kernel */
  334. addr = cpu_to_fdt64(md_addr);
  335. ret = fdt_setprop(fdt, offset, "dfd,base_addr", &addr, sizeof(addr));
  336. if (ret < 0)
  337. return ret;
  338. /*
  339. * write base address[31:1] from AP view to plat_sram_flag2[31:1]
  340. * write base address[32:32] from AP view to plat_sram_flag2[0:0]
  341. */
  342. writel((ap_addr & ~(0x1)) | ((ap_addr >> 32) & 0x1),
  343. cfg_dfd.plat_sram_flag2);
  344. return ret;
  345. }