xref: /netbsd-src/sys/arch/next68k/dev/nextdisplay.c (revision 08c81a9c2dc8c7300e893321eb65c0925d60871c)
1 /* $NetBSD: nextdisplay.c,v 1.10 2002/09/11 07:06:17 mycroft Exp $ */
2 
3 /*
4  * Copyright (c) 1998 Matt DeBergalis
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Matt DeBergalis
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/device.h>
39 #include <sys/malloc.h>
40 
41 #include <machine/bus.h>
42 #include <machine/cpu.h>
43 
44 #include <next68k/next68k/nextrom.h>
45 
46 #include <next68k/dev/intiovar.h>
47 #include <next68k/dev/nextdisplayvar.h>
48 #include <dev/wscons/wsconsio.h>
49 
50 #include <dev/rcons/raster.h>
51 #include <dev/wscons/wscons_raster.h>
52 #include <dev/wscons/wsdisplayvar.h>
53 
54 extern int turbo;
55 
56 int nextdisplay_match __P((struct device *, struct cfdata *, void *));
57 void nextdisplay_attach __P((struct device *, struct device *, void *));
58 
59 struct cfattach nextdisplay_ca = {
60 	sizeof(struct nextdisplay_softc),
61 	nextdisplay_match,
62 	nextdisplay_attach,
63 };
64 
65 const struct wsdisplay_emulops nextdisplay_mono_emulops = {
66 	rcons_cursor,
67 	rcons_mapchar,
68 	rcons_putchar,
69 	rcons_copycols,
70 	rcons_erasecols,
71 	rcons_copyrows,
72 	rcons_eraserows,
73 	rcons_allocattr
74 };
75 
76 struct wsscreen_descr nextdisplay_mono = {
77 	"mono",
78 	0, 0, /* will be filled in -- XXX shouldn't, it's global */
79 	&nextdisplay_mono_emulops,
80 	0, 0
81 };
82 
83 struct wsscreen_descr nextdisplay_color = {
84         "color",
85         0, 0, /* again, filled in */
86         &nextdisplay_mono_emulops,
87         0, 0
88 };
89 
90 const struct wsscreen_descr *_nextdisplay_scrlist_mono[] = {
91 	&nextdisplay_mono,
92 };
93 
94 const struct wsscreen_descr *_nextdisplay_scrlist_color[] = {
95         &nextdisplay_color,
96 };
97 
98 const struct wsscreen_list nextdisplay_screenlist_mono = {
99 	sizeof(_nextdisplay_scrlist_mono) / sizeof(struct wsscreen_descr *),
100 	_nextdisplay_scrlist_mono
101 };
102 
103 const struct wsscreen_list nextdisplay_screenlist_color = {
104 	sizeof(_nextdisplay_scrlist_color) / sizeof(struct wsscreen_descr *),
105 	_nextdisplay_scrlist_color
106 };
107 
108 static int	nextdisplay_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
109 static paddr_t	nextdisplay_mmap __P((void *, off_t, int));
110 static int	nextdisplay_alloc_screen __P((void *, const struct wsscreen_descr *,
111 		void **, int *, int *, long *));
112 static void	nextdisplay_free_screen __P((void *, void *));
113 static int	nextdisplay_show_screen __P((void *, void *, int,
114 					     void (*) (void *, int, int), void *));
115 static int	nextdisplay_load_font __P((void *, void *, struct wsdisplay_font *));
116 
117 const struct wsdisplay_accessops nextdisplay_accessops = {
118 	nextdisplay_ioctl,
119 	nextdisplay_mmap,
120 	nextdisplay_alloc_screen,
121 	nextdisplay_free_screen,
122 	nextdisplay_show_screen,
123 	nextdisplay_load_font
124 };
125 
126 void nextdisplay_init(struct nextdisplay_config *, int);
127 
128 paddr_t nextdisplay_consaddr;
129 static int nextdisplay_is_console __P((paddr_t addr));
130 
131 static struct nextdisplay_config nextdisplay_console_dc;
132 
133 static int
134 nextdisplay_is_console(paddr_t addr)
135 {
136 	return (nextdisplay_console_dc.isconsole
137 			&& (addr == nextdisplay_consaddr));
138 }
139 
140 int
141 nextdisplay_match(parent, match, aux)
142 	struct device *parent;
143 	struct cfdata *match;
144 	void *aux;
145 {
146 	if ((rom_machine_type == NeXT_WARP9)
147 	    || (rom_machine_type == NeXT_X15)
148 	    || (rom_machine_type == NeXT_WARP9C)
149 	    || (rom_machine_type == NeXT_TURBO_MONO)
150 	    || (rom_machine_type == NeXT_TURBO_COLOR))
151 		return (1);
152 	else
153 		return (0);
154 }
155 
156 void
157 nextdisplay_init(dc, color)
158 	struct nextdisplay_config *dc;
159 	int color;
160 {
161 	struct raster *rap;
162 	struct rcons *rcp;
163 	paddr_t addr;
164 	int i;
165 
166 	/* printf("in nextdisplay_init\n"); */
167 
168 	if (color)
169 		addr = (paddr_t)colorbase;
170 	else
171 		addr = (paddr_t)monobase;
172 
173 	dc->dc_vaddr = addr;
174 	dc->dc_paddr = color ? COLORP(addr) : MONOP(addr);
175 	dc->dc_size = color ? NEXT_P_C16_VIDEOSIZE : NEXT_P_VIDEOSIZE;
176 
177 	dc->dc_wid = 1120;
178 	dc->dc_ht = 832;
179 	dc->dc_depth = color ? 16 : 2;
180 	dc->dc_rowbytes = (turbo ? 1120 : 1152) * dc->dc_depth / 8;
181 
182 	dc->dc_videobase = dc->dc_vaddr;
183 
184 #if 0
185 	printf("intiobase at: %08x\n", intiobase);
186 	printf("intiolimit at: %08x\n", intiolimit);
187 	printf("videobase at: %08x\n", color ? colorbase : monobase);
188 	printf("videolimit at: %08x\n", color ? colorlimit : monolimit);
189 
190 	printf("virtual fb at: %08x\n", dc->dc_vaddr);
191 	printf("physical fb at: %08x\n", dc->dc_paddr);
192 	printf("fb size: %08x\n", dc->dc_size);
193 
194 	printf("dc_wid: %08x\n", dc->dc_wid);
195 	printf("dc_ht: %08x\n", dc->dc_ht);
196 	printf("dc_depth: %08x\n", dc->dc_depth);
197 	printf("dc_rowbytes: %08x\n", dc->dc_rowbytes);
198 	printf("dc_videobase: %08x\n", dc->dc_videobase);
199 #endif
200 
201 	/* clear the screen */
202 	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
203 		*(u_int32_t *)(dc->dc_videobase + i) =
204 			(color ? 0x0 : 0xffffffff);
205 
206 	printf("done clearing\n");
207 
208 	rap = &dc->dc_raster;
209 	rap->width = dc->dc_wid;
210 	rap->height = dc->dc_ht;
211 	rap->depth = color ? 16 : 2;
212 	rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
213 	rap->pixels = (u_int32_t *)dc->dc_videobase;
214 
215 	/* initialize the raster console blitter */
216 	rcp = &dc->dc_rcons;
217 	rcp->rc_sp = rap;
218 	rcp->rc_crow = rcp->rc_ccol = -1;
219 	rcp->rc_crowp = &rcp->rc_crow;
220 	rcp->rc_ccolp = &rcp->rc_ccol;
221 	rcons_init(rcp, 34, 80);
222 
223 	if (color) {
224 		nextdisplay_color.nrows = dc->dc_rcons.rc_maxrow;
225 		nextdisplay_color.ncols = dc->dc_rcons.rc_maxcol;
226 	} else {
227 		nextdisplay_mono.nrows = dc->dc_rcons.rc_maxrow;
228 		nextdisplay_mono.ncols = dc->dc_rcons.rc_maxcol;
229 	}
230 }
231 
232 void
233 nextdisplay_attach(parent, self, aux)
234 	struct device *parent;
235 	struct device *self;
236 	void *aux;
237 {
238 	struct nextdisplay_softc *sc;
239 	struct wsemuldisplaydev_attach_args waa;
240 	int isconsole;
241 	int iscolor;
242 	paddr_t addr;
243 
244 	sc = (struct nextdisplay_softc *)self;
245 
246 	if ((rom_machine_type == NeXT_WARP9C)
247 	    || (rom_machine_type == NeXT_TURBO_COLOR)) {
248 		iscolor = 1;
249 		addr = (paddr_t)colorbase;
250 	} else {
251 		iscolor = 0;
252 		addr = (paddr_t)monobase;
253 	}
254 
255 	isconsole = nextdisplay_is_console(addr);
256 
257 	if (isconsole) {
258 		sc->sc_dc = &nextdisplay_console_dc;
259 		sc->nscreens = 1;
260 	} else {
261 		sc->sc_dc = (struct nextdisplay_config *)
262 				malloc(sizeof(struct nextdisplay_config), M_DEVBUF, M_WAITOK);
263 		nextdisplay_init(sc->sc_dc, iscolor);
264 	}
265 
266 	printf(": %d x %d, %dbpp\n", sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
267 	       sc->sc_dc->dc_depth);
268 
269 	/* initialize the raster */
270 	waa.console = isconsole;
271 	waa.scrdata = iscolor ? &nextdisplay_screenlist_color : &nextdisplay_screenlist_mono;
272 	waa.accessops = &nextdisplay_accessops;
273 	waa.accesscookie = sc;
274 #if 0
275 	printf("nextdisplay: access cookie is %p\n", sc);
276 #endif
277 	config_found(self, &waa, wsemuldisplaydevprint);
278 }
279 
280 
281 int
282 nextdisplay_ioctl(v, cmd, data, flag, p)
283 	void *v;
284 	u_long cmd;
285 	caddr_t data;
286 	int flag;
287 	struct proc *p;
288 {
289 	struct nextdisplay_softc *sc = v;
290 	struct nextdisplay_config *dc = sc->sc_dc;
291 
292 	switch (cmd) {
293 	case WSDISPLAYIO_GTYPE:
294 		*(int *)data = dc->dc_type;
295 		return 0;
296 
297 	case WSDISPLAYIO_SCURSOR:
298 		printf("nextdisplay_ioctl: wsdisplayio_scursor\n");
299 		return EPASSTHROUGH;
300 
301 	case WSDISPLAYIO_SCURPOS:
302 		printf("nextdisplay_ioctl: wsdisplayio_scurpos\n");
303 		return EPASSTHROUGH;
304 
305 	case WSDISPLAYIO_GINFO:
306 	case WSDISPLAYIO_GETCMAP:
307 	case WSDISPLAYIO_PUTCMAP:
308 	case WSDISPLAYIO_GVIDEO:
309 	case WSDISPLAYIO_SVIDEO:
310 	case WSDISPLAYIO_GCURPOS:
311 	case WSDISPLAYIO_GCURMAX:
312 	case WSDISPLAYIO_GCURSOR:
313 		printf("nextdisplay_ioctl: listed but unsupported ioctl\n");
314 		return EPASSTHROUGH;
315 	}
316 
317 	return EPASSTHROUGH;
318 }
319 
320 static paddr_t
321 nextdisplay_mmap(v, offset, prot)
322 	void *v;
323 	off_t offset;
324 	int prot;
325 {
326 
327 	/* XXX */
328 	printf("nextdisplay_mmap: failed\n");
329 	return -1;
330 }
331 
332 int
333 nextdisplay_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
334 	void *v;
335 	const struct wsscreen_descr *type;
336 	void **cookiep;
337 	int *curxp, *curyp;
338 	long *defattrp;
339 {
340 	struct nextdisplay_softc *sc = v;
341 	long defattr;
342 
343 	/* only allow one screen */
344 	if (sc->nscreens > 0)
345 		return (ENOMEM);
346 
347 	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
348 	*curxp = 0;
349 	*curyp = 0;
350 	rcons_allocattr(&sc->sc_dc->dc_rcons, 0, 0,
351 			(strcmp(type->name, "color") == 0)
352 			? 0
353 			: WSATTR_REVERSE, &defattr);
354 	*defattrp = defattr;
355 	sc->nscreens++;
356 #if 0
357 	printf("nextdisplay: allocating screen\n");
358 #endif
359 	return (0);
360 }
361 
362 void
363 nextdisplay_free_screen(v, cookie)
364 	void *v;
365 	void *cookie;
366 {
367 	struct nextdisplay_softc *sc = v;
368 
369 	if (sc->sc_dc == &nextdisplay_console_dc)
370 		panic("nextdisplay_free_screen: console");
371 
372 	sc->nscreens--;
373 }
374 
375 int
376 nextdisplay_show_screen(v, cookie, waitok, cb, cbarg)
377 	void *v;
378 	void *cookie;
379 	int waitok;
380 	void (*cb) __P((void *, int, int));
381 	void *cbarg;
382 {
383 
384 	return (0);
385 }
386 
387 static int
388 nextdisplay_load_font(v, cookie, font)
389 	void *v;
390 	void *cookie;
391 	struct wsdisplay_font *font;
392 {
393 	return (EPASSTHROUGH);
394 }
395 
396 int
397 nextdisplay_cnattach(void)
398 {
399 	struct nextdisplay_config *dc = &nextdisplay_console_dc;
400 	long defattr;
401 	int iscolor;
402 
403 	if ((rom_machine_type == NeXT_WARP9C)
404 	    || (rom_machine_type == NeXT_TURBO_COLOR)) {
405 		iscolor = 1;
406 		nextdisplay_consaddr = (paddr_t)colorbase;
407 	} else {
408 		iscolor = 0;
409 		nextdisplay_consaddr = (paddr_t)monobase;
410 	}
411 
412 	/* set up the display */
413 	nextdisplay_init(&nextdisplay_console_dc, iscolor);
414 
415 	rcons_allocattr(&dc->dc_rcons, 0, 0,
416 			iscolor ? 0 : WSATTR_REVERSE, &defattr);
417 
418 	wsdisplay_cnattach(iscolor ? &nextdisplay_color : &nextdisplay_mono,
419 			   &dc->dc_rcons, 0, 0, defattr);
420 
421 	dc->isconsole = 1;
422 	return (0);
423 }
424