xref: /titanic_50/usr/src/psm/promif/ieee1275/common/prom_fb.c (revision a237e38e9161f0acd6451439d4a7dd597e66291d)
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 2007 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.h>
30 #include <sys/promimpl.h>
31 
32 /*
33  * Because kmdb links prom_stdout_is_framebuffer into its own
34  * module and coherent console adds "device-type=console" for
35  * /os-io node, we also check if the device-type is "console",
36  * (if not "display"), so that prom_stdout_is_framebuffer still
37  * works corrrectly after /os-io node is registered into OBP.
38  */
39 int
40 prom_stdout_is_framebuffer(void)
41 {
42 	static int remember = -1;
43 
44 	if (remember != -1)
45 		return (remember);
46 
47 	remember = prom_devicetype((pnode_t)prom_stdout_node(),
48 		OBP_DISPLAY);
49 
50 	if (remember == 0)
51 		remember = prom_devicetype((pnode_t)prom_stdout_node(),
52 			OBP_DISPLAY_CONSOLE);
53 
54 	return (remember);
55 }
56 
57 /*
58  * get current cursor position from the stdout handle, which
59  * containing the instance handle of the OBP console output device.
60  */
61 void
62 prom_get_tem_pos(uint32_t *row, uint32_t *col)
63 {
64 	prom_interpret(
65 	    "my-self >r stdout @ is my-self "
66 	    "line# swap l! column# swap l! "
67 	    "r> is my-self",
68 	    (uintptr_t)row, (uintptr_t)col, 0, 0, 0);
69 }
70 
71 
72 /*
73  * get the font size and the start window top of
74  * OBP terminal emulator
75  */
76 void
77 prom_get_term_font_size(int *charheight, int *window_top)
78 {
79 	prom_interpret(
80 	    "my-self >r stdout @ is my-self "
81 	    "char-height swap l! window-top swap l! "
82 	    "r> is my-self",
83 	    (uintptr_t)charheight, (uintptr_t)window_top, 0, 0, 0);
84 
85 }
86 
87 /* Clear the spining "|" character and hide the PROM cursor. */
88 void
89 prom_hide_cursor(void)
90 {
91 	prom_interpret(
92 	    "my-self >r stdout @ is my-self "
93 	    "toggle-cursor "
94 	    "1 delete-characters "
95 	    "r> is my-self",
96 	    0, 0, 0, 0, 0);
97 }
98 
99 static size_t
100 prom_atol(const char *str, int len)
101 {
102 	size_t n = 0;
103 
104 	while (len-- && (*str != '\0')) {
105 		n = n * 10 + (*str - '0');
106 		str++;
107 	}
108 
109 	return (n);
110 }
111 
112 /*
113  * Here we use the "screen-#columns" and "screen-#rows" settings of
114  * PROM to help us decide the console size and cursor position. The
115  * actual sizes of PROM's TEM and the console might be different with
116  * those "screen-#.." settings, in cases that they are too big to
117  * accommodate.
118  */
119 void
120 prom_get_tem_size(size_t *height, size_t *width)
121 {
122 	char buf[MAXPATHLEN];
123 	char name[16];
124 	pnode_t node;
125 	int len;
126 
127 	if ((node = prom_optionsnode()) == OBP_BADNODE)
128 		return;
129 
130 	(void) prom_strcpy(name, "screen-#rows");
131 	if ((len = prom_getproplen(node, (caddr_t)name)) > 0) {
132 		(void) prom_getprop(node, (caddr_t)name, (caddr_t)buf);
133 		*height = prom_atol(buf, len);
134 	}
135 
136 	(void) prom_strcpy(name, "screen-#columns");
137 	if ((len = prom_getproplen(node, (caddr_t)name)) > 0) {
138 		(void) prom_getprop(node, (caddr_t)name, (caddr_t)buf);
139 		*width = prom_atol(buf, len);
140 	}
141 }
142