summaryrefstree
path: root/kernel/lib/debug-snapshot-helper.c
blob: bf6d472747eb9a918d54c16bcaa362c03847651d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
/*
 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com
 *
 * Debug-SnapShot: Debug Framework for Ramdump based debugging method
 * The original code is Exynos-Snapshot for Exynos SoC
 *
 * Author: Hosung Kim <hosung0.kim@samsung.com>
 * Author: Changki Kim <changki.kim@samsung.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/kernel.h>
#include <linux/io.h>
#include <linux/notifier.h>
#include <linux/reboot.h>
#include <linux/delay.h>
#include <linux/kallsyms.h>
#include <linux/input.h>
#include <linux/smc.h>
#include <linux/bitops.h>
#include <linux/sched/clock.h>
#include <linux/sched/debug.h>
#include <linux/nmi.h>
#include <linux/init_task.h>
#include <linux/ftrace.h>

#include <asm/cputype.h>
#include <asm/smp_plat.h>
#include <asm/core_regs.h>

#include "debug-snapshot-local.h"
#include <linux/debug-snapshot-helper.h>

#ifdef CONFIG_SEC_DEBUG
#include <linux/sec_debug.h>
#endif /* CONFIG_SEC_DEBUG */

static void dbg_snapshot_soc_dummy_func(void *dummy) {return;}
static int dbg_snapshot_soc_dummy_func_int(unsigned int dummy) {return 0;}
static int dbg_snapshot_soc_dummy_func_smc(unsigned long dummy1,
					unsigned long dummy2,
					unsigned long dummy3,
					unsigned long dummy4) {return 0;}

static struct dbg_snapshot_helper_ops dss_soc_dummy_ops = {
	.soc_early_panic		= dbg_snapshot_soc_dummy_func,
	.soc_prepare_panic_entry 	= dbg_snapshot_soc_dummy_func,
	.soc_prepare_panic_exit 	= dbg_snapshot_soc_dummy_func,
	.soc_post_panic_entry 		= dbg_snapshot_soc_dummy_func,
	.soc_post_panic_exit 		= dbg_snapshot_soc_dummy_func,
	.soc_post_reboot_entry 		= dbg_snapshot_soc_dummy_func,
	.soc_post_reboot_exit 		= dbg_snapshot_soc_dummy_func,
	.soc_save_context_entry 	= dbg_snapshot_soc_dummy_func,
	.soc_save_context_exit		= dbg_snapshot_soc_dummy_func,
	.soc_save_core			= dbg_snapshot_soc_dummy_func,
	.soc_save_system		= dbg_snapshot_soc_dummy_func,
	.soc_dump_info			= dbg_snapshot_soc_dummy_func,
	.soc_start_watchdog 		= dbg_snapshot_soc_dummy_func,
	.soc_expire_watchdog 		= dbg_snapshot_soc_dummy_func,
	.soc_stop_watchdog 		= dbg_snapshot_soc_dummy_func,
	.soc_kick_watchdog 		= dbg_snapshot_soc_dummy_func,
	.soc_is_power_cpu		= dbg_snapshot_soc_dummy_func_int,
	.soc_smc_call			= dbg_snapshot_soc_dummy_func_smc,
};

struct dbg_snapshot_helper_ops *dss_soc_ops;

void __iomem *dbg_snapshot_get_base_vaddr(void)
{
	return (void __iomem *)(dss_base.vaddr);
}

void __iomem *dbg_snapshot_get_base_paddr(void)
{
	return (void __iomem *)(dss_base.paddr);
}

static void dbg_snapshot_set_core_power_stat(unsigned int val, unsigned cpu)
{
	if (dbg_snapshot_get_enable("header"))
		__raw_writel(val, (dbg_snapshot_get_base_vaddr() +
					DSS_OFFSET_CORE_POWER_STAT + cpu * 4));
}

unsigned int dbg_snapshot_get_core_panic_stat(unsigned cpu)
{
	if (dbg_snapshot_get_enable("header"))
		return __raw_readl(dbg_snapshot_get_base_vaddr() +
					DSS_OFFSET_PANIC_STAT + cpu * 4);
	else
		return 0;
}

void dbg_snapshot_set_core_panic_stat(unsigned int val, unsigned cpu)
{
	if (dbg_snapshot_get_enable("header"))
		__raw_writel(val, (dbg_snapshot_get_base_vaddr() +
					DSS_OFFSET_PANIC_STAT + cpu * 4));
}

static void dbg_snapshot_report_reason(unsigned int val)
{
	if (dbg_snapshot_get_enable("header"))
		__raw_writel(val, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_EMERGENCY_REASON);
}

int dbg_snapshot_get_debug_level_reg(void)
{
	int ret = DSS_DEBUG_LEVEL_MID;

	if (dbg_snapshot_get_enable("header")) {
		int val = __raw_readl(dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_LEVEL);

		if ((val & GENMASK(31, 16)) == DSS_DEBUG_LEVEL_PREFIX)
			ret = val & GENMASK(15, 0);
	}

	return ret;
}

void dbg_snapshot_set_sjtag_status(void)
{
	int ret;

	ret = dss_soc_ops->soc_smc_call(SMC_CMD_GET_SJTAG_STATUS, 0x3, 0, 0);

	if (ret == true || ret == false) {
		dss_desc.sjtag_status = ret;
		pr_info("debug-snapshot: SJTAG is %sabled\n",
				ret == true ? "en" : "dis");
		return;
	}

	dss_desc.sjtag_status = -1;
}

int dbg_snapshot_get_sjtag_status(void)
{
	return dss_desc.sjtag_status;
}

void dbg_snapshot_scratch_reg(unsigned int val)
{
	if (dbg_snapshot_get_enable("header"))
		__raw_writel(val, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_SCRATCH);
}

bool dbg_snapshot_is_scratch(void)
{
	return __raw_readl(dbg_snapshot_get_base_vaddr() +
			DSS_OFFSET_SCRATCH) == DSS_SIGN_SCRATCH;
}

void dbg_snapshot_set_debug_test_reg(unsigned int val)
{
	if (dbg_snapshot_get_enable("header")) {
		if (val)
			__raw_writel(DSS_SIGN_DEBUG_TEST, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST);
		else
			__raw_writel(DSS_SIGN_RESET, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST);
	}
}

bool dbg_snapshot_debug_test_enabled(void)
{
	return __raw_readl(dbg_snapshot_get_base_vaddr() +
			DSS_OFFSET_DEBUG_TEST) == DSS_SIGN_DEBUG_TEST;
}

void dbg_snapshot_set_debug_test_case(unsigned int val)
{
	if (dbg_snapshot_get_enable("header"))
		__raw_writel(val, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_CASE);
}

unsigned int dbg_snapshot_get_debug_test_case(void)
{
	unsigned int ret = 0xffffffff;

	if (dbg_snapshot_get_enable("header"))
		ret = __raw_readl(dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_CASE);
	return ret;
}

void dbg_snapshot_set_debug_test_next(unsigned int val)
{
	if (dbg_snapshot_get_enable("header"))
		__raw_writel(val, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_NEXT);
}

unsigned int dbg_snapshot_get_debug_test_next(void)
{
	unsigned int ret = 0xffffffff;

	if (dbg_snapshot_get_enable("header"))
		ret = __raw_readl(dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_NEXT);
	return ret;
}

void dbg_snapshot_set_debug_test_panic(unsigned int val)
{
	if (dbg_snapshot_get_enable("header"))
		__raw_writel(val, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_PANIC);

}

unsigned int dbg_snapshot_get_debug_test_panic(void)
{
	unsigned int ret = 0xffffffff;

	if (dbg_snapshot_get_enable("header"))
		ret = __raw_readl(dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_PANIC);
	return ret;
}

void dbg_snapshot_set_debug_test_wdt(unsigned int val)
{
	if (dbg_snapshot_get_enable("header"))
		__raw_writel(val, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_WDT);

}

unsigned int dbg_snapshot_get_debug_test_wdt(void)
{
	unsigned int ret = 0xffffffff;

	if (dbg_snapshot_get_enable("header"))
		ret = __raw_readl(dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_WDT);
	return ret;
}

void dbg_snapshot_set_debug_test_wtsr(unsigned int val)
{
	if (dbg_snapshot_get_enable("header"))
		__raw_writel(val, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_WTSR);
}

unsigned int dbg_snapshot_get_debug_test_wtsr(void)
{
	unsigned int ret = 0xffffffff;

	if (dbg_snapshot_get_enable("header"))
		ret = __raw_readl(dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_WTSR);
	return ret;
}

void dbg_snapshot_set_debug_test_smpl(unsigned int val)
{
	if (dbg_snapshot_get_enable("header"))
		__raw_writel(val, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_SMPL);
}

unsigned int dbg_snapshot_get_debug_test_smpl(void)
{
	unsigned int ret = 0xffffffff;

	if (dbg_snapshot_get_enable("header"))
		ret = __raw_readl(dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_SMPL);
	return ret;
}

void dbg_snapshot_set_debug_test_curr(unsigned int val)
{
	if (dbg_snapshot_get_enable("header"))
		__raw_writel(val, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_CURR);
}

unsigned int dbg_snapshot_get_debug_test_curr(void)
{
	unsigned int ret = 0xffffffff;

	if (dbg_snapshot_get_enable("header"))
		ret = __raw_readl(dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_CURR);
	return ret;
}

void dbg_snapshot_set_debug_test_total(unsigned int val)
{
	if (dbg_snapshot_get_enable("header"))
		__raw_writel(val, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_TOTAL);
}

unsigned int dbg_snapshot_get_debug_test_total(void)
{
	unsigned int ret = 0xffffffff;

	if (dbg_snapshot_get_enable("header"))
		ret = __raw_readl(dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_TOTAL);
	return ret;
}

void dbg_snapshot_set_debug_test_run(unsigned int test_id, unsigned int var)
{
	unsigned int ret;

	if (dbg_snapshot_get_enable("header")) {
		ret = __raw_readl(dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_RUN);
		if (!var)
			ret &= ~(1 << test_id);
		else
			ret |= (1 << test_id);
		__raw_writel(ret, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_RUN);
	}
}

unsigned int dbg_snapshot_get_debug_test_run(unsigned int test_id)
{
	unsigned int ret;

	if (!dbg_snapshot_get_enable("header"))
		return 0;

	ret = __raw_readl(dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_RUN);
	return ret & (1 << test_id);
}

void dbg_snapshot_clear_debug_test_runflag(void)
{
	if (!dbg_snapshot_get_enable("header"))
		return;

	__raw_writel(0, dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_RUN);
}

unsigned int dbg_snapshot_get_debug_test_runflag(void)
{
	if (!dbg_snapshot_get_enable("header"))
		return 0;

	return __raw_readl(dbg_snapshot_get_base_vaddr() + DSS_OFFSET_DEBUG_TEST_RUN);
}

unsigned long dbg_snapshot_get_last_pc_paddr(void)
{
	/*
	 * Basically we want to save the pc value to non-cacheable region
	 * if ESS is enabled. But we should also consider cases that are not so.
	 */

	if (dbg_snapshot_get_enable("header"))
		return ((unsigned long)dbg_snapshot_get_base_paddr() + DSS_OFFSET_CORE_LAST_PC);
	else
		return virt_to_phys((void *)dss_desc.hardlockup_core_pc);
}

unsigned long dbg_snapshot_get_last_pc(unsigned int cpu)
{
	if (dbg_snapshot_get_enable("header"))
		return __raw_readq(dbg_snapshot_get_base_vaddr() +
				DSS_OFFSET_CORE_LAST_PC + cpu * 8);
	else
		return dss_desc.hardlockup_core_pc[cpu];
}

unsigned long dbg_snapshot_get_spare_vaddr(unsigned int offset)
{
	return (unsigned long)(dbg_snapshot_get_base_vaddr() +
				DSS_OFFSET_SPARE_BASE + offset);
}

unsigned long dbg_snapshot_get_spare_paddr(unsigned int offset)
{
	unsigned long base_vaddr = 0;
	unsigned long base_paddr = (unsigned long)dbg_snapshot_get_base_paddr();

	if (base_paddr)
		base_vaddr = (unsigned long)(base_paddr +
				DSS_OFFSET_SPARE_BASE + offset);

	return base_vaddr;
}

unsigned int dbg_snapshot_get_item_size(char* name)
{
	unsigned long i;

	for (i = 0; i < dss_desc.log_cnt; i++) {
		if (!strncmp(dss_items[i].name, name, strlen(name)))
			return dss_items[i].entry.size;
	}
	return 0;
}
EXPORT_SYMBOL(dbg_snapshot_get_item_size);

unsigned long dbg_snapshot_get_item_vaddr(char *name)
{
	unsigned long i;

	for (i = 0; i < dss_desc.log_cnt; i++) {
		if (!strncmp(dss_items[i].name, name, strlen(name)))
			return dss_items[i].entry.vaddr;
	}
	return 0;
}
EXPORT_SYMBOL(dbg_snapshot_get_item_vaddr);

unsigned int dbg_snapshot_get_item_paddr(char* name)
{
	unsigned long i;

	for (i = 0; i < dss_desc.log_cnt; i++) {
		if (!strncmp(dss_items[i].name, name, strlen(name)))
			return dss_items[i].entry.paddr;
	}
	return 0;
}
EXPORT_SYMBOL(dbg_snapshot_get_item_paddr);

unsigned long dbg_snapshot_get_item_curr_ptr(char *name)
{
	unsigned long i;

	for (i = 0; i < dss_desc.log_cnt; i++) {
		if (!strncmp(dss_items[i].name, name, strlen(name))) {
			if (dss_items[i].entry.enabled)
				return (unsigned long)dss_items[i].curr_ptr;
			break;
		}
	}
	return 0;
}
EXPORT_SYMBOL(dbg_snapshot_get_item_curr_ptr);

int dbg_snapshot_get_hardlockup(void)
{
	return dss_desc.hardlockup_detected;
}
EXPORT_SYMBOL(dbg_snapshot_get_hardlockup);

int dbg_snapshot_set_hardlockup(int val)
{
	unsigned long flags;

	if (unlikely(!dss_base.enabled))
		return 0;

	raw_spin_lock_irqsave(&dss_desc.ctrl_lock, flags);
	dss_desc.hardlockup_detected = val;
	raw_spin_unlock_irqrestore(&dss_desc.ctrl_lock, flags);
	return 0;
}
EXPORT_SYMBOL(dbg_snapshot_set_hardlockup);

int dbg_snapshot_early_panic(void)
{
	dss_soc_ops->soc_early_panic(NULL);
	return 0;
}

int dbg_snapshot_prepare_panic(void)
{
	unsigned long cpu;

	if (unlikely(!dss_base.enabled))
		return 0;
	/*
	 * kick watchdog to prevent unexpected reset during panic sequence
	 * and it prevents the hang during panic sequence by watchedog
	 */
	dss_soc_ops->soc_start_watchdog(NULL);

	dss_soc_ops->soc_prepare_panic_entry(NULL);

	/* Again disable log_kevents */
	dbg_snapshot_set_enable("log_kevents", false);

	for_each_possible_cpu(cpu) {
		if (dss_soc_ops->soc_is_power_cpu(cpu))
			dbg_snapshot_set_core_power_stat(DSS_SIGN_ALIVE, cpu);
		else
			dbg_snapshot_set_core_power_stat(DSS_SIGN_DEAD, cpu);
	}
	dss_soc_ops->soc_prepare_panic_exit(NULL);

	return 0;
}
EXPORT_SYMBOL(dbg_snapshot_prepare_panic);

int dbg_snapshot_post_panic(void)
{
	if (dss_base.enabled) {
		dbg_snapshot_recall_hardlockup_core();
#ifdef CONFIG_DEBUG_SNAPSHOT_PMU
		dbg_snapshot_dump_sfr();
#endif
		dbg_snapshot_save_context(NULL);

		dbg_snapshot_print_panic_report();

		dss_soc_ops->soc_post_panic_entry(NULL);

#ifdef CONFIG_DEBUG_SNAPSHOT_PANIC_REBOOT
		if (!dss_desc.no_wdt_dev) {
#ifdef CONFIG_DEBUG_SNAPSHOT_WATCHDOG_RESET
			if (dss_desc.hardlockup_detected || num_online_cpus() > 1) {
				/* for stall cpu */
				dbg_snapshot_spin_func();
			}
#endif
		}
#endif
	}
	dss_soc_ops->soc_post_panic_exit(NULL);

#ifdef CONFIG_SEC_DEBUG
	sec_debug_post_panic_handler();
#endif

	/* for stall cpu when not enabling panic reboot */
	dbg_snapshot_spin_func();

	/* Never run this function */
	pr_emerg("debug-snapshot: %s DO NOT RUN this function (CPU:%d)\n",
					__func__, raw_smp_processor_id());
	return 0;
}
EXPORT_SYMBOL(dbg_snapshot_post_panic);

int dbg_snapshot_dump_panic(char *str, size_t len)
{
	if (unlikely(!dss_base.enabled) ||
		!dbg_snapshot_get_enable("header"))
		return 0;

	/*  This function is only one which runs in panic funcion */
	if (str && len && len < SZ_1K)
		memcpy(dbg_snapshot_get_base_vaddr() + DSS_OFFSET_PANIC_STRING, str, len);

	return 0;
}
EXPORT_SYMBOL(dbg_snapshot_dump_panic);

int dbg_snapshot_post_reboot(char *cmd)
{
	int cpu;

	if (unlikely(!dss_base.enabled))
		return 0;

	dss_soc_ops->soc_post_reboot_entry(NULL);

	dbg_snapshot_report_reason(DSS_SIGN_NORMAL_REBOOT);

	if (!cmd)
		dbg_snapshot_scratch_reg(DSS_SIGN_RESET);
	else if (strcmp((char *)cmd, "bootloader") && strcmp((char *)cmd, "ramdump"))
		dbg_snapshot_scratch_reg(DSS_SIGN_RESET);

	pr_emerg("debug-snapshot: normal reboot done\n");

	/* clear DSS_SIGN_PANIC when normal reboot */
	for_each_possible_cpu(cpu) {
		dbg_snapshot_set_core_panic_stat(DSS_SIGN_RESET, cpu);
	}

	dss_soc_ops->soc_post_reboot_exit(NULL);

	return 0;
}
EXPORT_SYMBOL(dbg_snapshot_post_reboot);

static int dbg_snapshot_reboot_handler(struct notifier_block *nb,
				    unsigned long l, void *p)
{
	if (unlikely(!dss_base.enabled))
		return 0;

	pr_emerg("debug-snapshot: normal reboot starting\n");

#ifdef CONFIG_SEC_DEBUG
	sec_debug_reboot_handler(p);
#endif

	return 0;
}

static int dbg_snapshot_panic_handler(struct notifier_block *nb,
				   unsigned long l, void *buf)
{
	dbg_snapshot_report_reason(DSS_SIGN_PANIC);
	if (unlikely(!dss_base.enabled))
		return 0;

#ifdef CONFIG_DEBUG_SNAPSHOT_PANIC_REBOOT
	local_irq_disable();
	pr_emerg("debug-snapshot: panic - reboot[%s]\n", __func__);
#else
	pr_emerg("debug-snapshot: panic - normal[%s]\n", __func__);
#endif
	dbg_snapshot_dump_task_info();
	pr_emerg("linux_banner: %s\n", linux_banner);

#ifdef CONFIG_SEC_DEBUG
	sec_debug_panic_handler(buf, true);
#endif

	return 0;
}

static struct notifier_block nb_reboot_block = {
	.notifier_call = dbg_snapshot_reboot_handler
};

static struct notifier_block nb_panic_block = {
	.notifier_call = dbg_snapshot_panic_handler,
};

void dbg_snapshot_panic_handler_safe(void)
{
	char *cpu_num[SZ_16] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
	char text[SZ_32] = "safe panic handler at cpu ";
	int cpu = raw_smp_processor_id();
	size_t len;

	if (unlikely(!dss_base.enabled))
		return;

	strncat(text, cpu_num[cpu], 1);
	len = strnlen(text, SZ_32);

	dbg_snapshot_report_reason(DSS_SIGN_SAFE_FAULT);
	dbg_snapshot_dump_panic(text, len);
#ifdef CONFIG_SEC_DEBUG
	dss_soc_ops->soc_expire_watchdog((void *)_RET_IP_);
#else
	dss_soc_ops->soc_expire_watchdog((void *)NULL);
#endif
}

void dbg_snapshot_register_soc_ops(struct dbg_snapshot_helper_ops *ops)
{
	if (ops)
		dss_soc_ops = ops;
}

void __init dbg_snapshot_init_helper(void)
{
	register_reboot_notifier(&nb_reboot_block);
	atomic_notifier_chain_register(&panic_notifier_list, &nb_panic_block);
	dss_soc_ops = &dss_soc_dummy_ops;

	/* hardlockup_detector function should be called before secondary booting */
	dbg_snapshot_soc_helper_init();
}