xref: /titanic_50/usr/src/uts/sun4v/promif/promif_mon.c (revision 60c807700988885656502665e0cf8afd4b4346f7)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/promif_impl.h>
30 #include <sys/uadmin.h>
31 #include <sys/machsystm.h>
32 #include <sys/hypervisor_api.h>
33 
34 #ifdef _KMDB
35 
36 extern int kmdb_dpi_get_master_cpuid(void);
37 extern void kmdb_dpi_kernpanic(int cpuid);
38 extern void prom_reboot(char *bootstr);
39 
40 #define	PIL_DECL(p)
41 #define	PIL_SET7(p)
42 #define	PIL_REST(p)
43 
44 #else
45 
46 extern int vx_handler(cell_t *argument_array);
47 
48 #define	PIL_DECL(p) int p
49 #define	PIL_SET7(p) (p = spl7())
50 #define	PIL_REST(p) (splx(p))
51 
52 #endif
53 
54 #define	PROMIF_ENTER	0
55 #define	PROMIF_EXIT	1
56 
57 #define	PROMIF_ISPRINT(c)	(((c) >= ' ') && ((c) <= '~'))
58 
59 static void promif_mon(int mode);
60 
61 /*ARGSUSED*/
62 int
63 promif_enter_mon(void *p)
64 {
65 	PIL_DECL(pil);
66 
67 	PIL_SET7(pil);
68 
69 	prom_printf("\n");
70 
71 #ifdef _KMDB
72 	promif_mon(PROMIF_ENTER);
73 #else
74 	idle_other_cpus();
75 	promif_mon(PROMIF_ENTER);
76 	resume_other_cpus();
77 #endif
78 
79 	PIL_REST(pil);
80 
81 	return (0);
82 }
83 
84 /*ARGSUSED*/
85 int
86 promif_exit_to_mon(void *p)
87 {
88 	PIL_DECL(pil);
89 
90 	PIL_SET7(pil);
91 
92 	prom_printf("Program terminated\n");
93 
94 	promif_mon(PROMIF_EXIT);
95 
96 	PIL_REST(pil);
97 
98 	return (0);
99 }
100 
101 static void
102 promif_mon(int mode)
103 {
104 	char		cmd;
105 	char		*prompt;
106 	boolean_t	invalid_option;
107 #ifdef _KMDB
108 	static char	*exit_prompt  = "r)eboot, h)alt? ";
109 #else
110 	char		value[ 8 ];	/* holds "true" or "false" */
111 	char		*boot_msg;
112 	static char	*null_msg = ".\" \"";
113 	static char	*ignore_msg =
114 	    "cr .\" Ignoring auto-boot? setting for this boot.\" cr";
115 	static char	*exit_prompt  = "r)eboot, o)k prompt, h)alt? ";
116 #endif
117 	static char	*enter_prompt = "c)ontinue, s)ync, r)eboot, h)alt? ";
118 
119 	prompt = (mode == PROMIF_EXIT) ? exit_prompt : enter_prompt;
120 
121 	for (;;) {
122 		prom_printf("%s", prompt);
123 
124 		while (hv_cngetchar((uint8_t *)&cmd) != H_EOK)
125 			;
126 
127 		prom_printf("%c\n", cmd);
128 
129 		invalid_option = B_FALSE;
130 
131 		switch (cmd) {
132 
133 		case 'r':
134 			prom_reboot("");
135 			break;
136 
137 		case 'h':
138 			(void) hv_mach_exit(0);
139 			ASSERT(0);
140 
141 			break;
142 
143 #ifndef _KMDB
144 		case 'o':
145 			/*
146 			 * This option gives the user an "ok" prompt after
147 			 * the system reset regardless of the value of
148 			 * auto-boot?  We offer this option because halt(1m)
149 			 * doesn't leave the user at the ok prompt (as it
150 			 * does on non-ldoms systems).  If auto-boot? is
151 			 * true tell user we are overriding the setting
152 			 * for this boot only.
153 			 */
154 			if (mode == PROMIF_EXIT) {
155 				bzero(value, sizeof (value));
156 				(void) promif_stree_getprop(prom_optionsnode(),
157 				    "auto-boot?", value);
158 				boot_msg = strcmp(value, "true") ? null_msg :
159 					ignore_msg;
160 				(void) promif_ldom_setprop("reboot-command",
161 				    boot_msg, strlen(boot_msg) + 1);
162 				(void) hv_mach_sir();
163 			} else {
164 				invalid_option = B_TRUE;
165 			}
166 			break;
167 #endif
168 
169 		case '\r':
170 			break;
171 
172 		case 's':
173 			if (mode == PROMIF_ENTER) {
174 #ifdef _KMDB
175 				kmdb_dpi_kernpanic(kmdb_dpi_get_master_cpuid());
176 #else
177 				cell_t arg = p1275_ptr2cell("sync");
178 				(void) vx_handler(&arg);
179 #endif
180 			} else {
181 				invalid_option = B_TRUE;
182 			}
183 			break;
184 
185 		case 'c':
186 			if (mode == PROMIF_ENTER) {
187 				return;
188 			} else {
189 				invalid_option = B_TRUE;
190 			}
191 			break;
192 
193 		default:
194 			invalid_option = B_TRUE;
195 			break;
196 		}
197 
198 		if (invalid_option && PROMIF_ISPRINT(cmd))
199 			prom_printf("invalid option (%c)\n", cmd);
200 	}
201 
202 	_NOTE(NOTREACHED)
203 }
204