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