wdt-atf.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. #include <linux/module.h>
  2. #include <linux/slab.h>
  3. #include <mt-plat/aee.h>
  4. #include <linux/utsname.h>
  5. #include <linux/sched.h>
  6. #include <linux/list.h>
  7. #include <linux/init.h>
  8. #include <linux/smp.h>
  9. #ifdef CONFIG_MT_SCHED_MONITOR
  10. #include "mt_sched_mon.h"
  11. #endif
  12. #include <linux/io.h>
  13. #include <linux/delay.h>
  14. #include <linux/hardirq.h>
  15. #include <linux/mm.h>
  16. #include <linux/types.h>
  17. #include <mrdump.h>
  18. #include <linux/uaccess.h>
  19. #include <linux/stacktrace.h>
  20. #include <asm/stacktrace.h>
  21. #include <asm/memory.h>
  22. #include <asm/traps.h>
  23. #include <linux/compiler.h>
  24. /* #include <mach/fiq_smp_call.h> */
  25. #include <mach/wd_api.h>
  26. #include <smp.h>
  27. #ifndef CONFIG_ARM64
  28. #include <mach/irqs.h>
  29. #endif
  30. #include "aee-common.h"
  31. #include <mach/mt_secure_api.h>
  32. #define THREAD_INFO(sp) ((struct thread_info *) \
  33. ((unsigned long)(sp) & ~(THREAD_SIZE - 1)))
  34. #define WDT_PERCPU_LOG_SIZE 2048
  35. #define WDT_LOG_DEFAULT_SIZE 4096
  36. #define WDT_SAVE_STACK_SIZE 256
  37. #define MAX_EXCEPTION_FRAME 16
  38. #define PRINTK_BUFFER_SIZE 512
  39. /* NR_CPUS may not eaqual to real cpu numbers, alloc buffer at initialization */
  40. static char *wdt_percpu_log_buf[NR_CPUS];
  41. static int wdt_percpu_log_length[NR_CPUS];
  42. static char wdt_log_buf[WDT_LOG_DEFAULT_SIZE];
  43. static int wdt_percpu_preempt_cnt[NR_CPUS];
  44. static unsigned long wdt_percpu_stackframe[NR_CPUS][MAX_EXCEPTION_FRAME];
  45. static int wdt_log_length;
  46. static atomic_t wdt_enter_fiq;
  47. static char printk_buf[PRINTK_BUFFER_SIZE];
  48. static char str_buf[NR_CPUS][PRINTK_BUFFER_SIZE];
  49. #define ATF_AEE_DEBUG_BUF_LENGTH 0x4000
  50. static void *atf_aee_debug_virt_addr;
  51. struct atf_aee_regs {
  52. __u64 regs[31];
  53. __u64 sp;
  54. __u64 pc;
  55. __u64 pstate;
  56. };
  57. struct stacks_buffer {
  58. char bin_buf[WDT_SAVE_STACK_SIZE];
  59. int real_len;
  60. unsigned long top;
  61. unsigned long bottom;
  62. };
  63. static struct stacks_buffer stacks_buffer_bin[NR_CPUS];
  64. struct regs_buffer {
  65. struct pt_regs regs;
  66. int real_len;
  67. };
  68. static struct regs_buffer regs_buffer_bin[NR_CPUS];
  69. int in_fiq_handler(void)
  70. {
  71. return atomic_read(&wdt_enter_fiq);
  72. }
  73. void aee_wdt_dump_info(void)
  74. {
  75. struct task_struct *task;
  76. int cpu, i;
  77. char *log_buf_ptr;
  78. task = &init_task;
  79. aee_rr_rec_fiq_step(AEE_FIQ_STEP_KE_WDT_INFO);
  80. if (wdt_log_length == 0) {
  81. LOGE("\n No log for WDT\n");
  82. #ifdef CONFIG_MT_SCHED_MONITOR
  83. mt_dump_sched_traces();
  84. #endif
  85. return;
  86. }
  87. aee_rr_rec_fiq_step(AEE_FIQ_STEP_KE_WDT_PERCPU);
  88. LOGE("==========================================\n");
  89. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  90. if ((wdt_percpu_log_buf[cpu]) && (wdt_percpu_log_length[cpu])) {
  91. log_buf_ptr = wdt_percpu_log_buf[cpu];
  92. while (wdt_percpu_log_length[cpu] > 0) {
  93. /* LOGE( "==> wdt_percpu_log_buf[%d], length=%d ", cpu, wdt_percpu_log_length[cpu]); */
  94. if (wdt_percpu_log_length[cpu] > (PRINTK_BUFFER_SIZE - 1)) {
  95. i = PRINTK_BUFFER_SIZE - 1;
  96. printk_buf[PRINTK_BUFFER_SIZE - 1] = 0;
  97. } else {
  98. i = wdt_percpu_log_length[cpu];
  99. printk_buf[i] = 0;
  100. }
  101. memcpy(printk_buf, log_buf_ptr, i);
  102. LOGE("%s", printk_buf);
  103. log_buf_ptr += i;
  104. wdt_percpu_log_length[cpu] -= i;
  105. }
  106. LOGE("Backtrace : ");
  107. for (i = 0; i < MAX_EXCEPTION_FRAME; i++) {
  108. if (wdt_percpu_stackframe[cpu][i] == 0)
  109. break;
  110. #ifdef CONFIG_ARM64
  111. LOGE("%016lx, ", wdt_percpu_stackframe[cpu][i]);
  112. #else
  113. LOGE("%08lx, ", wdt_percpu_stackframe[cpu][i]);
  114. #endif
  115. }
  116. LOGE("\n==========================================\n");
  117. }
  118. }
  119. aee_rr_rec_fiq_step(AEE_FIQ_STEP_KE_WDT_LOG);
  120. /* LOGE( "==> wdt_log_length=%d ", wdt_log_length); */
  121. /* printk temporary buffer only 1024, */
  122. log_buf_ptr = wdt_log_buf;
  123. while (wdt_log_length > 0) {
  124. if (wdt_log_length > (PRINTK_BUFFER_SIZE - 1)) {
  125. i = PRINTK_BUFFER_SIZE - 1;
  126. printk_buf[PRINTK_BUFFER_SIZE - 1] = 0;
  127. } else {
  128. i = wdt_log_length;
  129. printk_buf[i] = 0;
  130. }
  131. memcpy(printk_buf, log_buf_ptr, i);
  132. LOGE("%s", printk_buf);
  133. log_buf_ptr += i;
  134. wdt_log_length -= i;
  135. }
  136. #ifdef CONFIG_SCHED_DEBUG
  137. aee_rr_rec_fiq_step(AEE_FIQ_STEP_KE_SCHED_DEBUG);
  138. /*sysrq_sched_debug_show_at_KE();*/
  139. #endif
  140. for_each_process(task) {
  141. if (task->state == 0) {
  142. LOGE("PID: %d, name: %s\n", task->pid, task->comm);
  143. show_stack(task, NULL);
  144. LOGE("\n");
  145. }
  146. }
  147. aee_rr_rec_fiq_step(AEE_FIQ_STEP_KE_WDT_DONE);
  148. }
  149. void aee_wdt_percpu_printf(int cpu, const char *fmt, ...)
  150. {
  151. va_list args;
  152. if (wdt_percpu_log_buf[cpu] == NULL)
  153. return;
  154. va_start(args, fmt);
  155. wdt_percpu_log_length[cpu] +=
  156. vsnprintf((wdt_percpu_log_buf[cpu] + wdt_percpu_log_length[cpu]),
  157. (WDT_PERCPU_LOG_SIZE - wdt_percpu_log_length[cpu]), fmt, args);
  158. va_end(args);
  159. }
  160. void aee_wdt_printf(const char *fmt, ...)
  161. {
  162. va_list args;
  163. va_start(args, fmt);
  164. wdt_log_length += vsnprintf((wdt_log_buf + wdt_log_length),
  165. (sizeof(wdt_log_buf) - wdt_log_length), fmt, args);
  166. va_end(args);
  167. }
  168. /* save registers in bin buffer, may comes from various cpu */
  169. static void aee_dump_cpu_reg_bin(int cpu, struct pt_regs *regs)
  170. {
  171. #ifdef CONFIG_ARM64
  172. int i;
  173. aee_wdt_percpu_printf(cpu, "pc : %016llx, lr : %016llx, pstate : %016llx\n",
  174. regs->pc, regs->regs[30], regs->pstate);
  175. aee_wdt_percpu_printf(cpu, "sp : %016llx\n", regs->sp);
  176. for (i = 29; i >= 0; i--) {
  177. aee_wdt_percpu_printf(cpu, "x%-2d: %016llx ", i, regs->regs[i]);
  178. if (i % 2 == 0)
  179. aee_wdt_percpu_printf(cpu, "\n");
  180. }
  181. aee_wdt_percpu_printf(cpu, "\n");
  182. #else
  183. aee_wdt_percpu_printf(cpu, "pc : %08lx, lr : %08lx, cpsr : %08lx\n",
  184. regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr);
  185. aee_wdt_percpu_printf(cpu, "sp : %08lx, ip : %08lx, fp : %08lx\n",
  186. regs->ARM_sp, regs->ARM_ip, regs->ARM_fp);
  187. aee_wdt_percpu_printf(cpu, "r10 : %08lx, r9 : %08lx, r8 : %08lx\n",
  188. regs->ARM_r10, regs->ARM_r9, regs->ARM_r8);
  189. aee_wdt_percpu_printf(cpu, "r7 : %08lx, r6 : %08lx, r5 : %08lx\n",
  190. regs->ARM_r7, regs->ARM_r6, regs->ARM_r5);
  191. aee_wdt_percpu_printf(cpu, "r4 : %08lx, r3 : %08lx, r2 : %08lx\n",
  192. regs->ARM_r4, regs->ARM_r3, regs->ARM_r2);
  193. aee_wdt_percpu_printf(cpu, "r1 : %08lx, r0 : %08lx\n", regs->ARM_r1, regs->ARM_r0);
  194. #endif
  195. memcpy(&(regs_buffer_bin[cpu].regs), regs, sizeof(struct pt_regs));
  196. regs_buffer_bin[cpu].real_len = sizeof(struct pt_regs);
  197. }
  198. /* dump the stack into per CPU buffer */
  199. static void aee_wdt_dump_stack_bin(unsigned int cpu, unsigned long bottom, unsigned long top)
  200. {
  201. int i;
  202. unsigned long p;
  203. unsigned long first;
  204. unsigned int val;
  205. char str[sizeof(" 12345678") * 8 + 1];
  206. stacks_buffer_bin[cpu].real_len =
  207. aee_dump_stack_top_binary(stacks_buffer_bin[cpu].bin_buf,
  208. sizeof(stacks_buffer_bin[cpu].bin_buf), bottom, top);
  209. stacks_buffer_bin[cpu].top = top;
  210. stacks_buffer_bin[cpu].bottom = bottom;
  211. /* should check stack address in kernel range */
  212. if (bottom & 3) {
  213. aee_wdt_percpu_printf(cpu, "%s bottom unaligned %08lx\n", __func__, bottom);
  214. return;
  215. }
  216. if (!((bottom >= (PAGE_OFFSET + THREAD_SIZE)) && virt_addr_valid(bottom))) {
  217. aee_wdt_percpu_printf(cpu, "%s bottom out of kernel addr space %08lx\n", __func__,
  218. bottom);
  219. return;
  220. }
  221. if (!((top >= (PAGE_OFFSET + THREAD_SIZE)) && virt_addr_valid(bottom))) {
  222. aee_wdt_percpu_printf(cpu, "%s top out of kernel addr space %08lx\n", __func__,
  223. top);
  224. return;
  225. }
  226. #ifdef CONFIG_ARM64
  227. aee_wdt_percpu_printf(cpu, "stack (0x%016lx to 0x%016lx)\n", bottom, top);
  228. #else
  229. aee_wdt_percpu_printf(cpu, "stack (0x%08lx to 0x%08lx)\n", bottom, top);
  230. #endif
  231. for (first = bottom & ~31; first < top; first += 32) {
  232. memset_io(str, ' ', sizeof(str));
  233. str[sizeof(str) - 1] = '\0';
  234. for (p = first, i = 0; i < 8 && p < top; i++, p += 4) {
  235. if (p >= bottom && p < top) {
  236. if (__get_user(val, (unsigned int *)p) == 0)
  237. sprintf(str + i * 9, " %08x", val);
  238. else
  239. sprintf(str + i * 9, " ????????");
  240. }
  241. }
  242. aee_wdt_percpu_printf(cpu, "%04lx:%s\n", first & 0xffff, str);
  243. }
  244. }
  245. /* dump the backtrace into per CPU buffer */
  246. static void aee_wdt_dump_backtrace(unsigned int cpu, struct pt_regs *regs)
  247. {
  248. int i;
  249. unsigned long high, bottom, fp;
  250. struct stackframe cur_frame;
  251. struct pt_regs *excp_regs;
  252. bottom = regs->reg_sp;
  253. if (!virt_addr_valid(bottom)) {
  254. aee_wdt_percpu_printf(cpu, "invalid sp[%lx]\n", bottom);
  255. return;
  256. }
  257. high = ALIGN(bottom, THREAD_SIZE);
  258. cur_frame.fp = regs->reg_fp;
  259. cur_frame.pc = regs->reg_pc;
  260. cur_frame.sp = regs->reg_sp;
  261. wdt_percpu_stackframe[cpu][0] = regs->reg_lr;
  262. for (i = 1; i < MAX_EXCEPTION_FRAME; i++) {
  263. fp = cur_frame.fp;
  264. if ((fp < bottom) || (fp >= (high + THREAD_SIZE))) {
  265. /* aee_wdt_percpu_printf(cpu, "i=%d, fp=%lx, bottom=%lx\n", i, fp, bottom); */
  266. break;
  267. }
  268. if (unwind_frame(&cur_frame) < 0) {
  269. aee_wdt_percpu_printf(cpu, "unwind_frame < 0\n");
  270. break;
  271. }
  272. if (!((cur_frame.pc >= (PAGE_OFFSET + THREAD_SIZE))
  273. && virt_addr_valid(cur_frame.pc))) {
  274. aee_wdt_percpu_printf(cpu, "virt_addr_valid fail\n");
  275. break;
  276. }
  277. if (in_exception_text(cur_frame.pc)) {
  278. #ifdef CONFIG_ARM64
  279. /* work around for unknown reason do_mem_abort stack abnormal */
  280. excp_regs = (void *)(cur_frame.fp + 0x10 + 0xa0);
  281. unwind_frame(&cur_frame); /* skip do_mem_abort & el1_da */
  282. #else
  283. excp_regs = (void *)(cur_frame.fp + 4);
  284. #endif
  285. cur_frame.pc = excp_regs->reg_pc;
  286. }
  287. wdt_percpu_stackframe[cpu][i] = cur_frame.pc;
  288. }
  289. }
  290. /* save binary register and stack value into ram console */
  291. static void aee_save_reg_stack_sram(int cpu)
  292. {
  293. int i;
  294. int len = 0;
  295. if (regs_buffer_bin[cpu].real_len != 0) {
  296. snprintf(str_buf[cpu], sizeof(str_buf[cpu]),
  297. "\n\ncpu %d preempt=%lx, softirq=%lx, hardirq=%lx ", cpu,
  298. ((wdt_percpu_preempt_cnt[cpu] & PREEMPT_MASK) >> PREEMPT_SHIFT),
  299. ((wdt_percpu_preempt_cnt[cpu] & SOFTIRQ_MASK) >> SOFTIRQ_SHIFT),
  300. ((wdt_percpu_preempt_cnt[cpu] & HARDIRQ_MASK) >> HARDIRQ_SHIFT));
  301. aee_sram_fiq_log(str_buf[cpu]);
  302. memset_io(str_buf[cpu], 0, sizeof(str_buf[cpu]));
  303. #ifdef CONFIG_ARM64
  304. snprintf(str_buf[cpu], sizeof(str_buf[cpu]), "\ncpu %d x0->x30 sp pc pstate\n", cpu);
  305. #else
  306. snprintf(str_buf[cpu], sizeof(str_buf[cpu]),
  307. "\ncpu %d r0->r10 fp ip sp lr pc cpsr orig_r0\n", cpu);
  308. #endif
  309. aee_sram_fiq_log(str_buf[cpu]);
  310. aee_sram_fiq_save_bin((char *)&(regs_buffer_bin[cpu].regs),
  311. regs_buffer_bin[cpu].real_len);
  312. }
  313. if (stacks_buffer_bin[cpu].real_len > 0) {
  314. memset_io(str_buf[cpu], 0, sizeof(str_buf[cpu]));
  315. #ifdef CONFIG_ARM64
  316. snprintf(str_buf[cpu], sizeof(str_buf[cpu]), "\ncpu %d stack [%016lx %016lx]\n",
  317. cpu, stacks_buffer_bin[cpu].bottom, stacks_buffer_bin[cpu].top);
  318. #else
  319. snprintf(str_buf[cpu], sizeof(str_buf[cpu]), "\ncpu %d stack [%08lx %08lx]\n",
  320. cpu, stacks_buffer_bin[cpu].bottom, stacks_buffer_bin[cpu].top);
  321. #endif
  322. aee_sram_fiq_log(str_buf[cpu]);
  323. aee_sram_fiq_save_bin(stacks_buffer_bin[cpu].bin_buf,
  324. stacks_buffer_bin[cpu].real_len);
  325. memset_io(str_buf[cpu], 0, sizeof(str_buf[cpu]));
  326. len = snprintf(str_buf[cpu], sizeof(str_buf[cpu]), "\ncpu %d backtrace : ", cpu);
  327. for (i = 0; i < MAX_EXCEPTION_FRAME; i++) {
  328. if (wdt_percpu_stackframe[cpu][i] == 0)
  329. break;
  330. len += snprintf((str_buf[cpu] + len), (sizeof(str_buf[cpu]) - len),
  331. "%08lx, ", wdt_percpu_stackframe[cpu][i]);
  332. }
  333. aee_sram_fiq_log(str_buf[cpu]);
  334. }
  335. mrdump_mini_per_cpu_regs(cpu, &regs_buffer_bin[cpu].regs);
  336. }
  337. void aee_wdt_irq_info(void)
  338. {
  339. /* obsolete, to be removed */
  340. BUG();
  341. }
  342. void aee_wdt_atf_info(unsigned int cpu, struct pt_regs *regs)
  343. {
  344. unsigned long long t;
  345. unsigned long nanosec_rem;
  346. int res = 0;
  347. struct wd_api *wd_api = NULL;
  348. /* LOGD("\n ===> aee_wdt_atf_info : cpu %d\n", cpu); */
  349. if (!cpu_possible(cpu)) {
  350. aee_wdt_printf("FIQ: Watchdog time out at incorrect CPU %d ?\n", cpu);
  351. cpu = 0;
  352. }
  353. aee_wdt_percpu_printf(cpu, "CPU %d FIQ: Watchdog time out\n", cpu);
  354. wdt_percpu_preempt_cnt[cpu] = preempt_count();
  355. aee_wdt_percpu_printf(cpu, "preempt=%lx, softirq=%lx, hardirq=%lx\n",
  356. ((wdt_percpu_preempt_cnt[cpu] & PREEMPT_MASK) >> PREEMPT_SHIFT),
  357. ((wdt_percpu_preempt_cnt[cpu] & SOFTIRQ_MASK) >> SOFTIRQ_SHIFT),
  358. ((wdt_percpu_preempt_cnt[cpu] & HARDIRQ_MASK) >> HARDIRQ_SHIFT));
  359. if (regs) {
  360. aee_dump_cpu_reg_bin(cpu, regs);
  361. aee_rr_rec_fiq_step(AEE_FIQ_STEP_WDT_FIQ_STACK);
  362. aee_wdt_dump_stack_bin(cpu, regs->reg_sp, regs->reg_sp + WDT_SAVE_STACK_SIZE);
  363. aee_wdt_dump_backtrace(cpu, regs);
  364. }
  365. if (atomic_xchg(&wdt_enter_fiq, 1) != 0) {
  366. aee_rr_rec_fiq_step(AEE_FIQ_STEP_WDT_FIQ_LOOP);
  367. /* aee_wdt_percpu_printf(cpu, "Other CPU already enter WDT FIQ handler\n"); */
  368. set_cpu_online(cpu, false);
  369. local_fiq_disable();
  370. local_irq_disable();
  371. while (1)
  372. cpu_relax();
  373. }
  374. /* Wait for other cpu dump */
  375. mdelay(1000);
  376. if (regs) {
  377. aee_rr_rec_fiq_step(AEE_FIQ_STEP_WDT_IRQ_STACK);
  378. for (cpu = 0; cpu < NR_CPUS; cpu++)
  379. aee_save_reg_stack_sram(cpu);
  380. aee_sram_fiq_log("\n\n");
  381. } else {
  382. aee_wdt_printf("Invalid atf_aee_debug_virt_addr, no register dump\n");
  383. }
  384. aee_rr_rec_fiq_step(AEE_FIQ_STEP_WDT_IRQ_KICK);
  385. res = get_wd_api(&wd_api);
  386. if (res) {
  387. aee_wdt_printf("aee_wdt_irq_info, get wd api error\n");
  388. } else {
  389. wd_api->wd_restart(WD_TYPE_NOLOCK);
  390. aee_wdt_printf("kick=0x%08x,check=0x%08x", wd_api->wd_get_kick_bit(),
  391. wd_api->wd_get_check_bit());
  392. }
  393. aee_rr_rec_fiq_step(AEE_FIQ_STEP_WDT_IRQ_TIME);
  394. t = cpu_clock(smp_processor_id());
  395. nanosec_rem = do_div(t, 1000000000);
  396. aee_wdt_printf("\nQwdt at [%5lu.%06lu]\n", (unsigned long)t, nanosec_rem / 1000);
  397. #ifdef CONFIG_MT_SCHED_MONITOR
  398. aee_rr_rec_fiq_step(AEE_FIQ_STEP_WDT_IRQ_SCHED);
  399. mt_aee_dump_sched_traces();
  400. #endif
  401. aee_sram_fiq_log(wdt_log_buf);
  402. /* avoid lock prove to dump_stack in __debug_locks_off() */
  403. xchg(&debug_locks, 0);
  404. aee_rr_rec_fiq_step(AEE_FIQ_STEP_WDT_IRQ_DONE);
  405. aee_rr_rec_exp_type(1);
  406. BUG();
  407. }
  408. void notrace aee_wdt_atf_entry(void)
  409. {
  410. #ifdef CONFIG_ARM64
  411. int i;
  412. #endif
  413. void *regs;
  414. struct pt_regs pregs;
  415. int cpu = get_HW_cpuid();
  416. if (atf_aee_debug_virt_addr) {
  417. regs = (void *)(atf_aee_debug_virt_addr + (cpu * sizeof(struct atf_aee_regs)));
  418. #ifdef CONFIG_ARM64
  419. pregs.pstate = ((struct atf_aee_regs *)regs)->pstate;
  420. pregs.pc = ((struct atf_aee_regs *)regs)->pc;
  421. pregs.sp = ((struct atf_aee_regs *)regs)->sp;
  422. for (i = 0; i < 31; i++)
  423. pregs.regs[i] = ((struct atf_aee_regs *)regs)->regs[i];
  424. #else
  425. pregs.ARM_cpsr = (unsigned long)((struct atf_aee_regs *)regs)->pstate;
  426. pregs.ARM_pc = (unsigned long)((struct atf_aee_regs *)regs)->pc;
  427. pregs.ARM_sp = (unsigned long)((struct atf_aee_regs *)regs)->regs[19];
  428. pregs.ARM_lr = (unsigned long)((struct atf_aee_regs *)regs)->regs[18];
  429. pregs.ARM_ip = (unsigned long)((struct atf_aee_regs *)regs)->regs[12];
  430. pregs.ARM_fp = (unsigned long)((struct atf_aee_regs *)regs)->regs[11];
  431. pregs.ARM_r10 = (unsigned long)((struct atf_aee_regs *)regs)->regs[10];
  432. pregs.ARM_r9 = (unsigned long)((struct atf_aee_regs *)regs)->regs[9];
  433. pregs.ARM_r8 = (unsigned long)((struct atf_aee_regs *)regs)->regs[8];
  434. pregs.ARM_r7 = (unsigned long)((struct atf_aee_regs *)regs)->regs[7];
  435. pregs.ARM_r6 = (unsigned long)((struct atf_aee_regs *)regs)->regs[6];
  436. pregs.ARM_r5 = (unsigned long)((struct atf_aee_regs *)regs)->regs[5];
  437. pregs.ARM_r4 = (unsigned long)((struct atf_aee_regs *)regs)->regs[4];
  438. pregs.ARM_r3 = (unsigned long)((struct atf_aee_regs *)regs)->regs[3];
  439. pregs.ARM_r2 = (unsigned long)((struct atf_aee_regs *)regs)->regs[2];
  440. pregs.ARM_r1 = (unsigned long)((struct atf_aee_regs *)regs)->regs[1];
  441. pregs.ARM_r0 = (unsigned long)((struct atf_aee_regs *)regs)->regs[0];
  442. #endif
  443. aee_wdt_atf_info(cpu, &pregs);
  444. } else {
  445. aee_wdt_atf_info(cpu, 0);
  446. }
  447. }
  448. static int __init aee_wdt_init(void)
  449. {
  450. int i;
  451. phys_addr_t atf_aee_debug_phy_addr;
  452. atomic_set(&wdt_enter_fiq, 0);
  453. for (i = 0; i < NR_CPUS; i++) {
  454. wdt_percpu_log_buf[i] = kzalloc(WDT_PERCPU_LOG_SIZE, GFP_KERNEL);
  455. if (wdt_percpu_log_buf[i] == NULL)
  456. LOGE("\n aee_common_init : kmalloc fail\n");
  457. wdt_percpu_log_length[i] = 0;
  458. wdt_percpu_preempt_cnt[i] = 0;
  459. }
  460. memset_io(wdt_log_buf, 0, sizeof(wdt_log_buf));
  461. memset_io(regs_buffer_bin, 0, sizeof(regs_buffer_bin));
  462. memset_io(stacks_buffer_bin, 0, sizeof(stacks_buffer_bin));
  463. memset_io(wdt_percpu_stackframe, 0, sizeof(wdt_percpu_stackframe));
  464. /* send SMC to ATF to register call back function */
  465. #ifdef CONFIG_ARM64
  466. atf_aee_debug_phy_addr = (phys_addr_t) (0x00000000FFFFFFFF &
  467. mt_secure_call(MTK_SIP_KERNEL_WDT,
  468. (u64) &aee_wdt_atf_entry, 0, 0));
  469. #else
  470. atf_aee_debug_phy_addr = (phys_addr_t)
  471. mt_secure_call(MTK_SIP_KERNEL_WDT, (u32) &aee_wdt_atf_entry, 0, 0);
  472. #endif
  473. LOGD("\n MTK_SIP_KERNEL_WDT - 0x%p\n", &aee_wdt_atf_entry);
  474. if ((atf_aee_debug_phy_addr == 0) || (atf_aee_debug_phy_addr == 0xFFFFFFFF)) {
  475. LOGE("\n invalid atf_aee_debug_phy_addr\n");
  476. } else {
  477. /* use the last 16KB in ATF log buffer */
  478. atf_aee_debug_virt_addr = ioremap(atf_aee_debug_phy_addr, ATF_AEE_DEBUG_BUF_LENGTH);
  479. LOGD("\n atf_aee_debug_virt_addr = 0x%p\n", atf_aee_debug_virt_addr);
  480. if (atf_aee_debug_virt_addr)
  481. memset_io(atf_aee_debug_virt_addr, 0, ATF_AEE_DEBUG_BUF_LENGTH);
  482. }
  483. return 0;
  484. }
  485. module_init(aee_wdt_init);