xref: /titanic_52/usr/src/uts/sun4v/promif/promif_mon.c (revision 5699897cfc22a71e1441854892e3659f179ee0bc)
11ae08745Sheppo /*
21ae08745Sheppo  * CDDL HEADER START
31ae08745Sheppo  *
41ae08745Sheppo  * The contents of this file are subject to the terms of the
51ae08745Sheppo  * Common Development and Distribution License (the "License").
61ae08745Sheppo  * You may not use this file except in compliance with the License.
71ae08745Sheppo  *
81ae08745Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91ae08745Sheppo  * or http://www.opensolaris.org/os/licensing.
101ae08745Sheppo  * See the License for the specific language governing permissions
111ae08745Sheppo  * and limitations under the License.
121ae08745Sheppo  *
131ae08745Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
141ae08745Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151ae08745Sheppo  * If applicable, add the following below this CDDL HEADER, with the
161ae08745Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
171ae08745Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
181ae08745Sheppo  *
191ae08745Sheppo  * CDDL HEADER END
201ae08745Sheppo  */
211ae08745Sheppo 
221ae08745Sheppo /*
23*5699897cSHaik Aftandilian  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
241ae08745Sheppo  * Use is subject to license terms.
251ae08745Sheppo  */
261ae08745Sheppo 
271ae08745Sheppo #include <sys/promif_impl.h>
281ae08745Sheppo #include <sys/uadmin.h>
291ae08745Sheppo #include <sys/machsystm.h>
301ae08745Sheppo #include <sys/hypervisor_api.h>
311ae08745Sheppo 
321ae08745Sheppo #ifdef _KMDB
331ae08745Sheppo 
341ae08745Sheppo extern int kmdb_dpi_get_master_cpuid(void);
351ae08745Sheppo extern void kmdb_dpi_kernpanic(int cpuid);
361ae08745Sheppo extern void prom_reboot(char *bootstr);
371ae08745Sheppo 
381ae08745Sheppo #define	PIL_DECL(p)
391ae08745Sheppo #define	PIL_SET7(p)
401ae08745Sheppo #define	PIL_REST(p)
411ae08745Sheppo 
421ae08745Sheppo #else
431ae08745Sheppo 
441ae08745Sheppo extern int vx_handler(cell_t *argument_array);
45*5699897cSHaik Aftandilian extern void kldc_debug_enter(void);
461ae08745Sheppo 
471ae08745Sheppo #define	PIL_DECL(p) int p
481ae08745Sheppo #define	PIL_SET7(p) (p = spl7())
491ae08745Sheppo #define	PIL_REST(p) (splx(p))
501ae08745Sheppo 
511ae08745Sheppo #endif
521ae08745Sheppo 
531ae08745Sheppo #define	PROMIF_ISPRINT(c)	(((c) >= ' ') && ((c) <= '~'))
541ae08745Sheppo 
551b83305cSjm22469 static int promif_ask_before_reset =
561ae08745Sheppo #ifdef _KMDB
571b83305cSjm22469 	1;
581ae08745Sheppo #else
591b83305cSjm22469 	0;
601ae08745Sheppo #endif
611ae08745Sheppo 
621ae08745Sheppo /*ARGSUSED*/
631ae08745Sheppo int
641ae08745Sheppo promif_exit_to_mon(void *p)
651ae08745Sheppo {
661ae08745Sheppo 	PIL_DECL(pil);
671ae08745Sheppo 
681ae08745Sheppo 	PIL_SET7(pil);
691ae08745Sheppo 
701ae08745Sheppo 	prom_printf("Program terminated\n");
711ae08745Sheppo 
721b83305cSjm22469 	if (promif_ask_before_reset) {
731b83305cSjm22469 		prom_printf("Press any key to reboot.");
741b83305cSjm22469 		(void) prom_getchar();
751b83305cSjm22469 	}
761b83305cSjm22469 
771b83305cSjm22469 	(void) hv_mach_sir();
781b83305cSjm22469 
791b83305cSjm22469 	/* should not return */
801b83305cSjm22469 	ASSERT(0);
811ae08745Sheppo 
821ae08745Sheppo 	PIL_REST(pil);
831ae08745Sheppo 
841ae08745Sheppo 	return (0);
851ae08745Sheppo }
861ae08745Sheppo 
871b83305cSjm22469 /*ARGSUSED*/
881b83305cSjm22469 int
891b83305cSjm22469 promif_enter_mon(void *p)
901ae08745Sheppo {
911ae08745Sheppo 	char		cmd;
921b83305cSjm22469 	static char	*prompt = "c)ontinue, s)ync, r)eset? ";
931b83305cSjm22469 	PIL_DECL(pil);
941ae08745Sheppo 
951b83305cSjm22469 	PIL_SET7(pil);
961b83305cSjm22469 
971b83305cSjm22469 #ifndef _KMDB
981b83305cSjm22469 	idle_other_cpus();
99*5699897cSHaik Aftandilian 	kldc_debug_enter();
1001b83305cSjm22469 #endif
1011ae08745Sheppo 
1021ae08745Sheppo 	for (;;) {
1031ae08745Sheppo 		prom_printf("%s", prompt);
1041b83305cSjm22469 		cmd = promif_getchar();
1051ae08745Sheppo 		prom_printf("%c\n", cmd);
1061ae08745Sheppo 
1071ae08745Sheppo 		switch (cmd) {
1081ae08745Sheppo 
1091ae08745Sheppo 		case 'r':
11020046e4cSjm22469 			prom_printf("Resetting...\n");
11120046e4cSjm22469 
11220046e4cSjm22469 			(void) hv_mach_sir();
11320046e4cSjm22469 
11420046e4cSjm22469 			/* should not return */
11520046e4cSjm22469 			ASSERT(0);
1161ae08745Sheppo 			break;
1171ae08745Sheppo 
1181ae08745Sheppo 		case '\r':
1191ae08745Sheppo 			break;
1201ae08745Sheppo 
1211ae08745Sheppo 		case 's':
1221b83305cSjm22469 			{
1231ae08745Sheppo #ifdef _KMDB
1241ae08745Sheppo 				kmdb_dpi_kernpanic(kmdb_dpi_get_master_cpuid());
1251ae08745Sheppo #else
1261ae08745Sheppo 				cell_t arg = p1275_ptr2cell("sync");
1271b83305cSjm22469 
1281ae08745Sheppo 				(void) vx_handler(&arg);
1291ae08745Sheppo #endif
1301ae08745Sheppo 			}
1311b83305cSjm22469 
1321b83305cSjm22469 			/* should not return */
1331b83305cSjm22469 			ASSERT(0);
1341ae08745Sheppo 			break;
1351ae08745Sheppo 
1361ae08745Sheppo 		case 'c':
1371b83305cSjm22469 #ifndef _KMDB
1381b83305cSjm22469 			resume_other_cpus();
1391b83305cSjm22469 #endif
1401b83305cSjm22469 			PIL_REST(pil);
1411b83305cSjm22469 
1421b83305cSjm22469 			return (0);
1431ae08745Sheppo 
1441ae08745Sheppo 		default:
1451b83305cSjm22469 			if (PROMIF_ISPRINT(cmd))
1461b83305cSjm22469 				prom_printf("invalid option (%c)\n", cmd);
1471ae08745Sheppo 			break;
1481ae08745Sheppo 		}
1491ae08745Sheppo 	}
1501ae08745Sheppo 
1511ae08745Sheppo 	_NOTE(NOTREACHED)
1521ae08745Sheppo }
153