ofw_rascons.c revision 1.1 1 1.1 garbled /* $NetBSD: ofw_rascons.c,v 1.1 2007/11/26 19:58:31 garbled Exp $ */
2 1.1 garbled
3 1.1 garbled /*
4 1.1 garbled * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 1.1 garbled * All rights reserved.
6 1.1 garbled *
7 1.1 garbled * Author: Chris G. Demetriou
8 1.1 garbled *
9 1.1 garbled * Permission to use, copy, modify and distribute this software and
10 1.1 garbled * its documentation is hereby granted, provided that both the copyright
11 1.1 garbled * notice and this permission notice appear in all copies of the
12 1.1 garbled * software, derivative works or modified versions, and any portions
13 1.1 garbled * thereof, and that both notices appear in supporting documentation.
14 1.1 garbled *
15 1.1 garbled * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.1 garbled * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 1.1 garbled * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.1 garbled *
19 1.1 garbled * Carnegie Mellon requests users of this software to return to
20 1.1 garbled *
21 1.1 garbled * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 garbled * School of Computer Science
23 1.1 garbled * Carnegie Mellon University
24 1.1 garbled * Pittsburgh PA 15213-3890
25 1.1 garbled *
26 1.1 garbled * any improvements or extensions that they make and grant Carnegie the
27 1.1 garbled * rights to redistribute these changes.
28 1.1 garbled */
29 1.1 garbled
30 1.1 garbled #include <sys/cdefs.h>
31 1.1 garbled __KERNEL_RCSID(0, "$NetBSD: ofw_rascons.c,v 1.1 2007/11/26 19:58:31 garbled Exp $");
32 1.1 garbled
33 1.1 garbled #include <sys/param.h>
34 1.1 garbled #include <sys/buf.h>
35 1.1 garbled #include <sys/conf.h>
36 1.1 garbled #include <sys/device.h>
37 1.1 garbled #include <sys/ioctl.h>
38 1.1 garbled #include <sys/kernel.h>
39 1.1 garbled #include <sys/malloc.h>
40 1.1 garbled #include <sys/systm.h>
41 1.1 garbled #include <powerpc/oea/bat.h>
42 1.1 garbled
43 1.1 garbled #include <dev/ofw/openfirm.h>
44 1.1 garbled #include <uvm/uvm_extern.h>
45 1.1 garbled
46 1.1 garbled #include <machine/bus.h>
47 1.1 garbled #include <machine/autoconf.h>
48 1.1 garbled
49 1.1 garbled #include <dev/wscons/wsconsio.h>
50 1.1 garbled #include <dev/wscons/wsdisplayvar.h>
51 1.1 garbled #include <dev/rasops/rasops.h>
52 1.1 garbled #include <dev/wsfont/wsfont.h>
53 1.1 garbled #include <dev/wscons/wsdisplay_vconsvar.h>
54 1.1 garbled
55 1.1 garbled #include <powerpc/oea/ofw_rasconsvar.h>
56 1.1 garbled #include "wsdisplay.h"
57 1.1 garbled
58 1.1 garbled /* we need a wsdisplay to do anything halfway useful */
59 1.1 garbled #if NWSDISPLAY > 0
60 1.1 garbled
61 1.1 garbled #if defined(PPC_OEA64) || defined (PPC_OEA64_BRIDGE)
62 1.1 garbled int rascons_enable_cache = 0;
63 1.1 garbled #else
64 1.1 garbled #ifdef OFB_ENABLE_CACHE
65 1.1 garbled int rascons_enable_cache = 1;
66 1.1 garbled #else
67 1.1 garbled int rascons_enable_cache = 0;
68 1.1 garbled #endif
69 1.1 garbled #endif /* PPC_OEA64 */
70 1.1 garbled
71 1.1 garbled static int copy_rom_font(void);
72 1.1 garbled static struct wsdisplay_font openfirm6x11;
73 1.1 garbled static vaddr_t fbaddr;
74 1.1 garbled static int romfont_loaded = 0;
75 1.1 garbled
76 1.1 garbled struct vcons_screen rascons_console_screen;
77 1.1 garbled
78 1.1 garbled struct wsscreen_descr rascons_stdscreen = {
79 1.1 garbled "std",
80 1.1 garbled 0, 0, /* will be filled in -- XXX shouldn't, it's global */
81 1.1 garbled 0,
82 1.1 garbled 0, 0,
83 1.1 garbled WSSCREEN_REVERSE
84 1.1 garbled };
85 1.1 garbled
86 1.1 garbled int
87 1.1 garbled rascons_cnattach(void)
88 1.1 garbled {
89 1.1 garbled struct rasops_info *ri = &rascons_console_screen.scr_ri;
90 1.1 garbled long defattr;
91 1.1 garbled int crow = 0;
92 1.1 garbled char type[16];
93 1.1 garbled
94 1.1 garbled OF_getprop(console_node, "device_type", type, sizeof(type));
95 1.1 garbled if (strcmp(type, "display") != 0)
96 1.1 garbled return -1;
97 1.1 garbled
98 1.1 garbled /* get current cursor position */
99 1.1 garbled OF_interpret("line#", 0, 1, &crow);
100 1.1 garbled
101 1.1 garbled /* move (rom monitor) cursor to the lowest line - 1 */
102 1.1 garbled OF_interpret("#lines 2 - to line#", 0, 0);
103 1.1 garbled
104 1.1 garbled wsfont_init();
105 1.1 garbled if (copy_rom_font() == 0) {
106 1.1 garbled romfont_loaded = 1;
107 1.1 garbled }
108 1.1 garbled
109 1.1 garbled /* set up rasops */
110 1.1 garbled rascons_init_rasops(console_node, ri);
111 1.1 garbled
112 1.1 garbled /*
113 1.1 garbled * no need to clear the screen here when we're mimicing firmware
114 1.1 garbled * output anyway
115 1.1 garbled */
116 1.1 garbled #if 0
117 1.1 garbled if (ri->ri_width >= 1024 && ri->ri_height >= 768) {
118 1.1 garbled int i, screenbytes = ri->ri_stride * ri->ri_height;
119 1.1 garbled
120 1.1 garbled for (i = 0; i < screenbytes; i += sizeof(u_int32_t))
121 1.1 garbled *(u_int32_t *)(fbaddr + i) = 0xffffffff;
122 1.1 garbled crow = 0;
123 1.1 garbled }
124 1.1 garbled #endif
125 1.1 garbled
126 1.1 garbled rascons_stdscreen.nrows = ri->ri_rows;
127 1.1 garbled rascons_stdscreen.ncols = ri->ri_cols;
128 1.1 garbled rascons_stdscreen.textops = &ri->ri_ops;
129 1.1 garbled rascons_stdscreen.capabilities = ri->ri_caps;
130 1.1 garbled
131 1.1 garbled ri->ri_ops.allocattr(ri, 0, 0, 0, &defattr);
132 1.1 garbled wsdisplay_preattach(&rascons_stdscreen, ri, 0, max(0,
133 1.1 garbled min(crow, ri->ri_rows - 1)), defattr);
134 1.1 garbled
135 1.1 garbled #if notyet
136 1.1 garbled rascons_init_cmap(NULL);
137 1.1 garbled #endif
138 1.1 garbled
139 1.1 garbled return 0;
140 1.1 garbled }
141 1.1 garbled
142 1.1 garbled static int
143 1.1 garbled copy_rom_font()
144 1.1 garbled {
145 1.1 garbled u_char *romfont;
146 1.1 garbled int char_width, char_height;
147 1.1 garbled int chosen, mmu, m, e;
148 1.1 garbled
149 1.1 garbled /* Get ROM FONT address. */
150 1.1 garbled OF_interpret("font-adr", 0, 1, &romfont);
151 1.1 garbled if (romfont == NULL)
152 1.1 garbled return -1;
153 1.1 garbled
154 1.1 garbled chosen = OF_finddevice("/chosen");
155 1.1 garbled OF_getprop(chosen, "mmu", &mmu, 4);
156 1.1 garbled
157 1.1 garbled /*
158 1.1 garbled * Convert to physcal address. We cannot access to Open Firmware's
159 1.1 garbled * virtual address space.
160 1.1 garbled */
161 1.1 garbled OF_call_method("translate", mmu, 1, 3, romfont, &romfont, &m, &e);
162 1.1 garbled
163 1.1 garbled /* Get character size */
164 1.1 garbled OF_interpret("char-width", 0, 1, &char_width);
165 1.1 garbled OF_interpret("char-height", 0, 1, &char_height);
166 1.1 garbled
167 1.1 garbled openfirm6x11.name = "Open Firmware";
168 1.1 garbled openfirm6x11.firstchar = 32;
169 1.1 garbled openfirm6x11.numchars = 96;
170 1.1 garbled openfirm6x11.encoding = WSDISPLAY_FONTENC_ISO;
171 1.1 garbled openfirm6x11.fontwidth = char_width;
172 1.1 garbled openfirm6x11.fontheight = char_height;
173 1.1 garbled openfirm6x11.stride = 1;
174 1.1 garbled openfirm6x11.bitorder = WSDISPLAY_FONTORDER_L2R;
175 1.1 garbled openfirm6x11.byteorder = WSDISPLAY_FONTORDER_L2R;
176 1.1 garbled openfirm6x11.data = romfont;
177 1.1 garbled
178 1.1 garbled return 0;
179 1.1 garbled }
180 1.1 garbled
181 1.1 garbled int
182 1.1 garbled rascons_init_rasops(int node, struct rasops_info *ri)
183 1.1 garbled {
184 1.1 garbled int32_t width, height, linebytes, depth;
185 1.1 garbled
186 1.1 garbled /* XXX /chaos/control doesn't have "width", "height", ... */
187 1.1 garbled width = height = -1;
188 1.1 garbled if (OF_getprop(node, "width", &width, 4) != 4)
189 1.1 garbled OF_interpret("screen-width", 0, 1, &width);
190 1.1 garbled if (OF_getprop(node, "height", &height, 4) != 4)
191 1.1 garbled OF_interpret("screen-height", 0, 1, &height);
192 1.1 garbled if (OF_getprop(node, "linebytes", &linebytes, 4) != 4)
193 1.1 garbled linebytes = width; /* XXX */
194 1.1 garbled if (OF_getprop(node, "depth", &depth, 4) != 4)
195 1.1 garbled depth = 8; /* XXX */
196 1.1 garbled if (OF_getprop(node, "address", &fbaddr, 4) != 4)
197 1.1 garbled OF_interpret("frame-buffer-adr", 0, 1, &fbaddr);
198 1.1 garbled
199 1.1 garbled if (width == -1 || height == -1 || fbaddr == 0 || fbaddr == -1)
200 1.1 garbled return false;
201 1.1 garbled
202 1.1 garbled /* Enable write-through cache. */
203 1.1 garbled #if defined (PPC_OEA) && !defined (PPC_OEA64) && !defined (PPC_OEA64_BRIDGE)
204 1.1 garbled if (rascons_enable_cache) {
205 1.1 garbled vaddr_t va;
206 1.1 garbled /*
207 1.1 garbled * Let's try to find an empty BAT to use
208 1.1 garbled */
209 1.1 garbled for (va = SEGMENT_LENGTH; va < (USER_SR << ADDR_SR_SHFT);
210 1.1 garbled va += SEGMENT_LENGTH) {
211 1.1 garbled if (battable[va >> ADDR_SR_SHFT].batu == 0) {
212 1.1 garbled battable[va >> ADDR_SR_SHFT].batl =
213 1.1 garbled BATL(fbaddr & 0xf0000000,
214 1.1 garbled BAT_G | BAT_W | BAT_M, BAT_PP_RW);
215 1.1 garbled battable[va >> ADDR_SR_SHFT].batu =
216 1.1 garbled BATL(va, BAT_BL_256M, BAT_Vs);
217 1.1 garbled fbaddr &= 0x0fffffff;
218 1.1 garbled fbaddr |= va;
219 1.1 garbled break;
220 1.1 garbled }
221 1.1 garbled }
222 1.1 garbled }
223 1.1 garbled #endif /* PPC_OEA64 */
224 1.1 garbled
225 1.1 garbled /* initialize rasops */
226 1.1 garbled ri->ri_width = width;
227 1.1 garbled ri->ri_height = height;
228 1.1 garbled ri->ri_depth = depth;
229 1.1 garbled ri->ri_stride = linebytes;
230 1.1 garbled ri->ri_bits = (char *)fbaddr;
231 1.1 garbled ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
232 1.1 garbled
233 1.1 garbled /* mimic firmware output if we can find the ROM font */
234 1.1 garbled if (romfont_loaded) {
235 1.1 garbled int cols, rows;
236 1.1 garbled
237 1.1 garbled /*
238 1.1 garbled * XXX this assumes we're the console which may or may not
239 1.1 garbled * be the case
240 1.1 garbled */
241 1.1 garbled OF_interpret("#lines", 0, 1, &rows);
242 1.1 garbled OF_interpret("#columns", 0, 1, &cols);
243 1.1 garbled ri->ri_font = &openfirm6x11;
244 1.1 garbled ri->ri_wsfcookie = -1; /* not using wsfont */
245 1.1 garbled rasops_init(ri, rows, cols);
246 1.1 garbled
247 1.1 garbled ri->ri_xorigin = (width - cols * ri->ri_font->fontwidth) >> 1;
248 1.1 garbled ri->ri_yorigin = (height - rows * ri->ri_font->fontheight)
249 1.1 garbled >> 1;
250 1.1 garbled ri->ri_bits = (char *)fbaddr + ri->ri_xorigin +
251 1.1 garbled ri->ri_stride * ri->ri_yorigin;
252 1.1 garbled } else {
253 1.1 garbled /* use as much of the screen as the font permits */
254 1.1 garbled rasops_init(ri, height/8, width/8);
255 1.1 garbled ri->ri_caps = WSSCREEN_WSCOLORS;
256 1.1 garbled rasops_reconfig(ri, height / ri->ri_font->fontheight,
257 1.1 garbled width / ri->ri_font->fontwidth);
258 1.1 garbled }
259 1.1 garbled
260 1.1 garbled return true;
261 1.1 garbled }
262 1.1 garbled #else /* NWSDISPLAY > 0 */
263 1.1 garbled int
264 1.1 garbled rascons_cnattach()
265 1.1 garbled {
266 1.1 garbled return -1;
267 1.1 garbled }
268 1.1 garbled #endif
269