xref: /titanic_52/usr/src/uts/sun4v/promif/promif_mon.c (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
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 2008 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_ISPRINT(c)	(((c) >= ' ') && ((c) <= '~'))
55 
56 static int promif_ask_before_reset =
57 #ifdef _KMDB
58 	1;
59 #else
60 	0;
61 #endif
62 
63 /*ARGSUSED*/
64 int
65 promif_exit_to_mon(void *p)
66 {
67 	PIL_DECL(pil);
68 
69 	PIL_SET7(pil);
70 
71 	prom_printf("Program terminated\n");
72 
73 	if (promif_ask_before_reset) {
74 		prom_printf("Press any key to reboot.");
75 		(void) prom_getchar();
76 	}
77 
78 	(void) hv_mach_sir();
79 
80 	/* should not return */
81 	ASSERT(0);
82 
83 	PIL_REST(pil);
84 
85 	return (0);
86 }
87 
88 /*ARGSUSED*/
89 int
90 promif_enter_mon(void *p)
91 {
92 	char		cmd;
93 	static char	*prompt = "c)ontinue, s)ync, r)eset? ";
94 	PIL_DECL(pil);
95 
96 	PIL_SET7(pil);
97 
98 #ifndef _KMDB
99 	idle_other_cpus();
100 #endif
101 
102 	for (;;) {
103 		prom_printf("%s", prompt);
104 		cmd = promif_getchar();
105 		prom_printf("%c\n", cmd);
106 
107 		switch (cmd) {
108 
109 		case 'r':
110 			prom_printf("Resetting...\n");
111 
112 			(void) hv_mach_sir();
113 
114 			/* should not return */
115 			ASSERT(0);
116 			break;
117 
118 		case '\r':
119 			break;
120 
121 		case 's':
122 			{
123 #ifdef _KMDB
124 				kmdb_dpi_kernpanic(kmdb_dpi_get_master_cpuid());
125 #else
126 				cell_t arg = p1275_ptr2cell("sync");
127 
128 				(void) vx_handler(&arg);
129 #endif
130 			}
131 
132 			/* should not return */
133 			ASSERT(0);
134 			break;
135 
136 		case 'c':
137 #ifndef _KMDB
138 			resume_other_cpus();
139 #endif
140 			PIL_REST(pil);
141 
142 			return (0);
143 
144 		default:
145 			if (PROMIF_ISPRINT(cmd))
146 				prom_printf("invalid option (%c)\n", cmd);
147 			break;
148 		}
149 	}
150 
151 	_NOTE(NOTREACHED)
152 }
153