17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5c7d88479Slq  * Common Development and Distribution License (the "License").
6c7d88479Slq  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21c7d88479Slq 
227c478bd9Sstevel@tonic-gate /*
23c7d88479Slq  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * "PROM" interface
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/promif.h>
33*888d78e9SToomas Soome #include <sys/salib.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_promif_impl.h>
367c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_kdi.h>
377c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_dpi.h>
387c478bd9Sstevel@tonic-gate #include <mdb/mdb_err.h>
397c478bd9Sstevel@tonic-gate #include <mdb/mdb_debug.h>
407c478bd9Sstevel@tonic-gate #include <mdb/mdb_string.h>
417c478bd9Sstevel@tonic-gate #include <mdb/mdb.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate struct boot_syscalls *kmdb_sysp;
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate ssize_t
kmdb_prom_obp_writer(caddr_t buf,size_t len)467c478bd9Sstevel@tonic-gate kmdb_prom_obp_writer(caddr_t buf, size_t len)
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate 	int i;
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate 	for (i = 0; i < len; i++)
517c478bd9Sstevel@tonic-gate 		prom_putchar(*buf++);
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	return (len);
547c478bd9Sstevel@tonic-gate }
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*ARGSUSED*/
577c478bd9Sstevel@tonic-gate ihandle_t
kmdb_prom_get_handle(char * name)587c478bd9Sstevel@tonic-gate kmdb_prom_get_handle(char *name)
597c478bd9Sstevel@tonic-gate {
607c478bd9Sstevel@tonic-gate 	/* no handles here */
617c478bd9Sstevel@tonic-gate 	return (0);
627c478bd9Sstevel@tonic-gate }
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate char *
kmdb_prom_get_ddi_prop(kmdb_auxv_t * kav,char * propname)65c7d88479Slq kmdb_prom_get_ddi_prop(kmdb_auxv_t *kav, char *propname)
667c478bd9Sstevel@tonic-gate {
677c478bd9Sstevel@tonic-gate 	int i;
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 	if (kav->kav_pcache != NULL) {
707c478bd9Sstevel@tonic-gate 		for (i = 0; i < kav->kav_nprops; i++) {
717c478bd9Sstevel@tonic-gate 			kmdb_auxv_nv_t *nv = &kav->kav_pcache[i];
727c478bd9Sstevel@tonic-gate 			if (strcmp(nv->kanv_name, propname) == 0)
737c478bd9Sstevel@tonic-gate 				return (nv->kanv_val);
747c478bd9Sstevel@tonic-gate 		}
757c478bd9Sstevel@tonic-gate 	}
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	return (NULL);
787c478bd9Sstevel@tonic-gate }
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate /*ARGSUSED*/
817c478bd9Sstevel@tonic-gate void
kmdb_prom_free_ddi_prop(char * val)82c7d88479Slq kmdb_prom_free_ddi_prop(char *val)
837c478bd9Sstevel@tonic-gate {
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate 
86bfc95affSToomas Soome /*
87bfc95affSToomas Soome  * This function is actually about checking if we are using
88bfc95affSToomas Soome  * local console versus serial console. Serial console can be named
89bfc95affSToomas Soome  * "ttyX" where X is [a-d], or "usb-serial".
90bfc95affSToomas Soome  */
917c478bd9Sstevel@tonic-gate int
kmdb_prom_stdout_is_framebuffer(kmdb_auxv_t * kav)927c478bd9Sstevel@tonic-gate kmdb_prom_stdout_is_framebuffer(kmdb_auxv_t *kav)
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate 	char *dev;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	/*
97bfc95affSToomas Soome 	 * The property "output-device" value is set in property cache, and
98bfc95affSToomas Soome 	 * is based on either "output-device" or "console" properties from
99bfc95affSToomas Soome 	 * the actual system. We can't use the official promif version, as we
100bfc95affSToomas Soome 	 * need to ensure that property lookups come from our property cache.
1017c478bd9Sstevel@tonic-gate 	 */
1027c478bd9Sstevel@tonic-gate 
103c7d88479Slq 	if ((dev = kmdb_prom_get_ddi_prop(kav, "output-device")) == NULL)
1047c478bd9Sstevel@tonic-gate 		return (0);
1057c478bd9Sstevel@tonic-gate 
106bfc95affSToomas Soome 	if (strncmp(dev, "tty", 3) == 0)
107bfc95affSToomas Soome 		return (0);
108bfc95affSToomas Soome 	if (strcmp(dev, "usb-serial") == 0)
109bfc95affSToomas Soome 		return (0);
110bfc95affSToomas Soome 
111bfc95affSToomas Soome 	/* Anything else is classified as local console. */
112bfc95affSToomas Soome 	return (1);
1137c478bd9Sstevel@tonic-gate }
114*888d78e9SToomas Soome 
115*888d78e9SToomas Soome void
kmdb_prom_get_tem_size(kmdb_auxv_t * kav,ushort_t * rows,ushort_t * cols)116*888d78e9SToomas Soome kmdb_prom_get_tem_size(kmdb_auxv_t *kav, ushort_t *rows, ushort_t *cols)
117*888d78e9SToomas Soome {
118*888d78e9SToomas Soome 	char *val;
119*888d78e9SToomas Soome 	unsigned long u;
120*888d78e9SToomas Soome 
121*888d78e9SToomas Soome 	val = kmdb_prom_get_ddi_prop(kav, "screen-#rows");
122*888d78e9SToomas Soome 	if (val != NULL) {
123*888d78e9SToomas Soome 		u = strtoul(val, NULL, 10);
124*888d78e9SToomas Soome 		*rows = (ushort_t)u;
125*888d78e9SToomas Soome 	}
126*888d78e9SToomas Soome 	val = kmdb_prom_get_ddi_prop(kav, "screen-#cols");
127*888d78e9SToomas Soome 	if (val != NULL) {
128*888d78e9SToomas Soome 		u = strtoul(val, NULL, 10);
129*888d78e9SToomas Soome 		*cols = (ushort_t)u;
130*888d78e9SToomas Soome 	}
131*888d78e9SToomas Soome }
132