macfb.c revision 1.1.2.5 1 /* $NetBSD: macfb.c,v 1.1.2.5 1999/11/15 23:31:16 scottr Exp $ */
2 /*
3 * Copyright (c) 1998 Matt DeBergalis
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Matt DeBergalis
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "opt_wsdisplay_compat.h"
33 #include "grf.h"
34
35 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/device.h>
41 #include <sys/malloc.h>
42
43 #include <machine/cpu.h>
44 #include <machine/bus.h>
45
46 #include <machine/grfioctl.h>
47 #include <mac68k/nubus/nubus.h>
48 #include <mac68k/dev/grfvar.h>
49 #include <mac68k/dev/macfbvar.h>
50 #include <dev/wscons/wsconsio.h>
51
52 #ifdef WSDISPLAY_COMPAT_ITE
53 #include <machine/iteioctl.h>
54 #endif /* WSDISPLAY_COMPAT_ITE */
55
56 #include <dev/rcons/raster.h>
57 #include <dev/wscons/wscons_raster.h>
58 #include <dev/wscons/wsdisplayvar.h>
59
60 int macfb_match __P((struct device *, struct cfdata *, void *));
61 void macfb_attach __P((struct device *, struct device *, void *));
62
63 struct cfattach macfb_ca = {
64 sizeof(struct macfb_softc),
65 macfb_match,
66 macfb_attach,
67 };
68
69 const struct wsdisplay_emulops macfb_emulops = {
70 rcons_cursor,
71 rcons_mapchar,
72 rcons_putchar,
73 rcons_copycols,
74 rcons_erasecols,
75 rcons_copyrows,
76 rcons_eraserows,
77 rcons_alloc_attr
78 };
79
80 struct wsscreen_descr macfb_stdscreen = {
81 "std",
82 0, 0, /* will be filled in -- XXX shouldn't, it's global */
83 &macfb_emulops,
84 0, 0,
85 WSSCREEN_REVERSE
86 };
87
88 const struct wsscreen_descr *_macfb_scrlist[] = {
89 &macfb_stdscreen,
90 };
91
92 const struct wsscreen_list macfb_screenlist = {
93 sizeof(_macfb_scrlist) / sizeof(struct wsscreen_descr *),
94 _macfb_scrlist
95 };
96
97 static int macfb_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
98 static int macfb_mmap __P((void *, off_t, int));
99 static int macfb_alloc_screen __P((void *, const struct wsscreen_descr *,
100 void **, int *, int *, long *));
101 static void macfb_free_screen __P((void *, void *));
102 static void macfb_show_screen __P((void *, void *));
103
104 const struct wsdisplay_accessops macfb_accessops = {
105 macfb_ioctl,
106 macfb_mmap,
107 macfb_alloc_screen,
108 macfb_free_screen,
109 macfb_show_screen,
110 0 /* load_font */
111 };
112
113 void macfb_init __P((struct macfb_devconfig *));
114
115 paddr_t macfb_consaddr;
116 static int macfb_is_console __P((paddr_t addr));
117 #ifdef WSDISPLAY_COMPAT_ITEFONT
118 static void init_itefont __P((void));
119 #endif /* WSDISPLAY_COMPAT_ITEFONT */
120
121 static struct macfb_devconfig macfb_console_dc;
122
123 /* From Booter via locore */
124 extern long videoaddr;
125 extern long videorowbytes;
126 extern long videobitdepth;
127 extern u_long videosize;
128 extern u_int32_t mac68k_vidlog;
129 extern u_int32_t mac68k_vidphys;
130 extern u_int32_t mac68k_vidlen;
131
132 static int
133 macfb_is_console(paddr_t addr)
134 {
135 return ((mac68k_machine.serial_console & 0x03) == 0
136 && (addr == macfb_consaddr));
137 }
138
139 void
140 macfb_init(dc)
141 struct macfb_devconfig *dc;
142 {
143 struct raster *rap;
144 struct rcons *rcp;
145 int i;
146
147 /* clear the display */
148 for (i = 0; i < (dc->dc_ht * dc->dc_rowbytes); i += dc->dc_rowbytes)
149 bzero((u_char *)dc->dc_vaddr + dc->dc_offset + i,
150 dc->dc_rowbytes);
151
152 #ifdef WSDISPLAY_COMPAT_ITEFONT
153 init_itefont();
154 #endif /* WSDISPLAY_COMPAT_ITEFONT */
155
156 rap = &dc->dc_raster;
157 rap->width = dc->dc_wid;
158 rap->height = dc->dc_ht;
159 rap->depth = dc->dc_depth;
160 rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
161 rap->pixels = (u_int32_t *)dc->dc_vaddr + dc->dc_offset;
162
163 /* initialize the raster console blitter */
164 rcp = &dc->dc_rcons;
165 rcp->rc_sp = rap;
166 rcp->rc_crow = rcp->rc_ccol = -1;
167 rcp->rc_crowp = &rcp->rc_crow;
168 rcp->rc_ccolp = &rcp->rc_ccol;
169 rcons_init(rcp, 128, 128);
170
171 macfb_stdscreen.nrows = dc->dc_rcons.rc_maxrow;
172 macfb_stdscreen.ncols = dc->dc_rcons.rc_maxcol;
173 }
174
175 int
176 macfb_match(parent, match, aux)
177 struct device *parent;
178 struct cfdata *match;
179 void *aux;
180 {
181 return (1);
182 }
183
184 void
185 macfb_attach(parent, self, aux)
186 struct device *parent;
187 struct device *self;
188 void *aux;
189 {
190 struct grfbus_attach_args *ga = aux;
191 struct grfmode *gm = ga->ga_grfmode;
192 struct macfb_softc *sc;
193 struct wsemuldisplaydev_attach_args waa;
194 int isconsole;
195
196 sc = (struct macfb_softc *)self;
197
198 printf("\n");
199
200 isconsole = macfb_is_console(ga->ga_phys + ga->ga_grfmode->fboff);
201
202 if (isconsole) {
203 sc->sc_dc = &macfb_console_dc;
204 sc->nscreens = 1;
205 } else {
206 sc->sc_dc = malloc(sizeof(struct macfb_devconfig), M_DEVBUF, M_WAITOK);
207 sc->sc_dc->dc_vaddr = (vaddr_t)gm->fbbase;
208 sc->sc_dc->dc_paddr = ga->ga_phys;
209 sc->sc_dc->dc_size = gm->fbsize;
210
211 sc->sc_dc->dc_wid = gm->width;
212 sc->sc_dc->dc_ht = gm->height;
213 sc->sc_dc->dc_depth = gm->psize;
214 sc->sc_dc->dc_rowbytes = gm->rowbytes;
215
216 sc->sc_dc->dc_offset = gm->fboff;
217
218 macfb_init(sc->sc_dc);
219
220 sc->nscreens = 1;
221 }
222
223 /* initialize the raster */
224 waa.console = isconsole;
225 waa.scrdata = &macfb_screenlist;
226 waa.accessops = &macfb_accessops;
227 waa.accesscookie = sc;
228
229 config_found(self, &waa, wsemuldisplaydevprint);
230
231 #if NGRF > 0
232 grf_attach(sc, self->dv_unit);
233 #endif
234 }
235
236
237 int
238 macfb_ioctl(v, cmd, data, flag, p)
239 void *v;
240 u_long cmd;
241 caddr_t data;
242 int flag;
243 struct proc *p;
244 {
245 struct macfb_softc *sc = v;
246 struct macfb_devconfig *dc = sc->sc_dc;
247 struct wsdisplay_fbinfo *wdf;
248
249 switch (cmd) {
250 case WSDISPLAYIO_GTYPE:
251 *(int *)data = dc->dc_type;
252 return 0;
253
254 case WSDISPLAYIO_GINFO:
255 wdf = (struct wsdisplay_fbinfo *)data;
256 wdf->height = dc->dc_raster.height;
257 wdf->width = dc->dc_raster.width;
258 wdf->depth = dc->dc_raster.depth;
259 wdf->cmsize = 256;
260 return 0;
261
262 case WSDISPLAYIO_GCURMAX:
263 case WSDISPLAYIO_GCURPOS:
264 case WSDISPLAYIO_GCURSOR:
265 case WSDISPLAYIO_GETCMAP:
266 case WSDISPLAYIO_GVIDEO:
267 case WSDISPLAYIO_PUTCMAP:
268 case WSDISPLAYIO_SCURPOS:
269 case WSDISPLAYIO_SCURSOR:
270 case WSDISPLAYIO_SVIDEO:
271 /* NONE of these operations are supported. */
272 return ENOTTY;
273
274 #ifdef WSDISPLAY_COMPAT_ITE
275 case ITEIOC_GETBELL:
276 case ITEIOC_SETBELL:
277 case ITEIOC_RINGBELL:
278 /* NONE of these operations are supported. */
279 return ENOTTY;
280
281 #endif /* WSDISPLAY_COMPAT_ITE */
282 }
283
284 return -1;
285 }
286
287 static int
288 macfb_mmap(v, offset, prot)
289 void *v;
290 off_t offset;
291 int prot;
292 {
293 struct macfb_softc *sc = v;
294 struct macfb_devconfig *dc = sc->sc_dc;
295 u_long addr;
296
297 if (offset >= 0 &&
298 offset < m68k_round_page(dc->dc_rowbytes * dc->dc_ht))
299 addr = m68k_btop(dc->dc_paddr + dc->dc_offset + offset);
300 else
301 addr = (-1); /* XXX bogus */
302
303 return (int)addr;
304 }
305
306 int
307 macfb_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
308 void *v;
309 const struct wsscreen_descr *type;
310 void **cookiep;
311 int *curxp, *curyp;
312 long *defattrp;
313 {
314 struct macfb_softc *sc = v;
315 long defattr;
316
317 if (sc->nscreens > 0)
318 return (ENOMEM);
319
320 *cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
321 *curxp = 0;
322 *curyp = 0;
323 rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
324 *defattrp = defattr;
325 sc->nscreens++;
326 return (0);
327 }
328
329 void
330 macfb_free_screen(v, cookie)
331 void *v;
332 void *cookie;
333 {
334 struct macfb_softc *sc = v;
335
336 if (sc->sc_dc == &macfb_console_dc)
337 panic("cfb_free_screen: console");
338
339 sc->nscreens--;
340 }
341
342 void
343 macfb_show_screen(v, cookie)
344 void *v;
345 void *cookie;
346 {
347 }
348
349 int
350 macfb_cnattach(addr)
351 paddr_t addr;
352 {
353 struct macfb_devconfig *dc = &macfb_console_dc;
354 long defattr;
355
356 dc->dc_vaddr = videoaddr;
357 dc->dc_paddr = mac68k_vidphys;
358
359 dc->dc_wid = videosize & 0xffff;
360 dc->dc_ht = (videosize >> 16) & 0xffff;
361 dc->dc_depth = videobitdepth;
362 dc->dc_rowbytes = videorowbytes;
363
364 dc->dc_size = (mac68k_vidlen > 0) ?
365 mac68k_vidlen : dc->dc_ht * dc->dc_rowbytes;
366 dc->dc_offset = 0;
367
368 /* set up the display */
369 macfb_init(&macfb_console_dc);
370
371 rcons_alloc_attr(&dc->dc_rcons, 0, 0, 0, &defattr);
372
373 wsdisplay_cnattach(&macfb_stdscreen, &dc->dc_rcons,
374 0, 0, defattr);
375
376 macfb_consaddr = addr;
377 dc->isconsole = 1;
378 return (0);
379 }
380
381 #ifdef WSDISPLAY_COMPAT_ITEFONT
382 #include <mac68k/dev/6x10.h>
383
384 void
385 init_itefont()
386 {
387 static int itefont_initted = 0;
388 int i, j;
389
390 extern struct raster_font gallant19; /* XXX */
391
392 if (itefont_initted)
393 return;
394 itefont_initted = 1;
395
396 /* XXX but we cannot use malloc here... */
397 gallant19.width = 6;
398 gallant19.height = 10;
399 gallant19.ascent = 0;
400
401 for (i = 32; i < 128; i++) {
402 u_int *p;
403
404 if (gallant19.chars[i].r == NULL)
405 continue;
406
407 gallant19.chars[i].r->width = 6;
408 gallant19.chars[i].r->height = 10;
409 p = gallant19.chars[i].r->pixels;
410
411 for (j = 0; j < 10; j++)
412 *p++ = Font6x10[i * 10 + j] << 26;
413 }
414 }
415 #endif /* WSDISPLAY_COMPAT_ITEFONT */
416