xref: /linux/arch/xtensa/platforms/iss/setup.c (revision ff57d59200baadfdb41f94a49fed7d161a9a8124)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *
4  * arch/xtensa/platform-iss/setup.c
5  *
6  * Platform specific initialization.
7  *
8  * Authors: Chris Zankel <chris@zankel.net>
9  *          Joe Taylor <joe@tensilica.com>
10  *
11  * Copyright 2001 - 2005 Tensilica Inc.
12  * Copyright 2017 Cadence Design Systems Inc.
13  */
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/notifier.h>
17 #include <linux/panic_notifier.h>
18 #include <linux/printk.h>
19 #include <linux/reboot.h>
20 #include <linux/string.h>
21 
22 #include <asm/platform.h>
23 #include <asm/setup.h>
24 
25 #include <platform/simcall.h>
26 
27 
28 static int iss_power_off(struct sys_off_data *unused)
29 {
30 	pr_info(" ** Called platform_power_off() **\n");
31 	simc_exit(0);
32 	return NOTIFY_DONE;
33 }
34 
35 static int iss_restart(struct sys_off_data *unused)
36 {
37 	/* Flush and reset the mmu, simulate a processor reset, and
38 	 * jump to the reset vector. */
39 	cpu_reset();
40 
41 	return NOTIFY_DONE;
42 }
43 
44 static int
45 iss_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
46 {
47 	simc_exit(1);
48 	return NOTIFY_DONE;
49 }
50 
51 static struct notifier_block iss_panic_block = {
52 	.notifier_call = iss_panic_event,
53 };
54 
55 void __init platform_setup(char **p_cmdline)
56 {
57 	static void *argv[COMMAND_LINE_SIZE / sizeof(void *)] __initdata;
58 	static char cmdline[COMMAND_LINE_SIZE] __initdata;
59 	int argc = simc_argc();
60 	int argv_size = simc_argv_size();
61 
62 	if (argc > 1) {
63 		if (argv_size > sizeof(argv)) {
64 			pr_err("%s: command line too long: argv_size = %d\n",
65 			       __func__, argv_size);
66 		} else {
67 			int i;
68 
69 			cmdline[0] = 0;
70 			simc_argv((void *)argv);
71 
72 			for (i = 1; i < argc; ++i) {
73 				if (i > 1)
74 					strcat(cmdline, " ");
75 				strcat(cmdline, argv[i]);
76 			}
77 			*p_cmdline = cmdline;
78 		}
79 	}
80 
81 	atomic_notifier_chain_register(&panic_notifier_list, &iss_panic_block);
82 	register_sys_off_handler(SYS_OFF_MODE_RESTART,
83 				 SYS_OFF_PRIO_PLATFORM,
84 				 iss_restart, NULL);
85 	register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
86 				 SYS_OFF_PRIO_PLATFORM,
87 				 iss_power_off, NULL);
88 }
89