Home | History | Annotate | Line # | Download | only in dev
nextdisplay.c revision 1.9
      1 /* $NetBSD: nextdisplay.c,v 1.9 2002/09/11 01:46:32 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_COLOR))
    150 		return (1);
    151 	else
    152 		return (0);
    153 }
    154 
    155 void
    156 nextdisplay_init(dc, color)
    157 	struct nextdisplay_config *dc;
    158 	int color;
    159 {
    160 	struct raster *rap;
    161 	struct rcons *rcp;
    162 	paddr_t addr;
    163 	int i;
    164 
    165 	/* printf("in nextdisplay_init\n"); */
    166 
    167 	if (color)
    168 		addr = (paddr_t)colorbase;
    169 	else
    170 		addr = (paddr_t)monobase;
    171 
    172 	dc->dc_vaddr = addr;
    173 	dc->dc_paddr = color ? COLORP(addr) : MONOP(addr);
    174 	dc->dc_size = color ? NEXT_P_C16_VIDEOSIZE : NEXT_P_VIDEOSIZE;
    175 
    176 	dc->dc_wid = 1120;
    177 	dc->dc_ht = 832;
    178 	dc->dc_depth = color ? 16 : 2;
    179 	dc->dc_rowbytes = (turbo ? 1120 : 1152) * dc->dc_depth / 8;
    180 
    181 	dc->dc_videobase = dc->dc_vaddr;
    182 
    183 #if 0
    184 	printf("intiobase at: %08x\n", intiobase);
    185 	printf("intiolimit at: %08x\n", intiolimit);
    186 	printf("videobase at: %08x\n", color ? colorbase : monobase);
    187 	printf("videolimit at: %08x\n", color ? colorlimit : monolimit);
    188 
    189 	printf("virtual fb at: %08x\n", dc->dc_vaddr);
    190 	printf("physical fb at: %08x\n", dc->dc_paddr);
    191 	printf("fb size: %08x\n", dc->dc_size);
    192 
    193 	printf("dc_wid: %08x\n", dc->dc_wid);
    194 	printf("dc_ht: %08x\n", dc->dc_ht);
    195 	printf("dc_depth: %08x\n", dc->dc_depth);
    196 	printf("dc_rowbytes: %08x\n", dc->dc_rowbytes);
    197 	printf("dc_videobase: %08x\n", dc->dc_videobase);
    198 #endif
    199 
    200 	/* clear the screen */
    201 	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
    202 		*(u_int32_t *)(dc->dc_videobase + i) =
    203 			(color ? 0x0 : 0xffffffff);
    204 
    205 	printf("done clearing\n");
    206 
    207 	rap = &dc->dc_raster;
    208 	rap->width = dc->dc_wid;
    209 	rap->height = dc->dc_ht;
    210 	rap->depth = color ? 16 : 2;
    211 	rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
    212 	rap->pixels = (u_int32_t *)dc->dc_videobase;
    213 
    214 	/* initialize the raster console blitter */
    215 	rcp = &dc->dc_rcons;
    216 	rcp->rc_sp = rap;
    217 	rcp->rc_crow = rcp->rc_ccol = -1;
    218 	rcp->rc_crowp = &rcp->rc_crow;
    219 	rcp->rc_ccolp = &rcp->rc_ccol;
    220 	rcons_init(rcp, 34, 80);
    221 
    222 	if (color) {
    223 		nextdisplay_color.nrows = dc->dc_rcons.rc_maxrow;
    224 		nextdisplay_color.ncols = dc->dc_rcons.rc_maxcol;
    225 	} else {
    226 		nextdisplay_mono.nrows = dc->dc_rcons.rc_maxrow;
    227 		nextdisplay_mono.ncols = dc->dc_rcons.rc_maxcol;
    228 	}
    229 }
    230 
    231 void
    232 nextdisplay_attach(parent, self, aux)
    233 	struct device *parent;
    234 	struct device *self;
    235 	void *aux;
    236 {
    237 	struct nextdisplay_softc *sc;
    238 	struct wsemuldisplaydev_attach_args waa;
    239 	int isconsole;
    240 	int iscolor;
    241 	paddr_t addr;
    242 
    243 	sc = (struct nextdisplay_softc *)self;
    244 
    245 	if ((rom_machine_type == NeXT_WARP9C)
    246 	    || (rom_machine_type == NeXT_TURBO_COLOR)) {
    247 		iscolor = 1;
    248 		addr = (paddr_t)colorbase;
    249 	} else {
    250 		iscolor = 0;
    251 		addr = (paddr_t)monobase;
    252 	}
    253 
    254 	isconsole = nextdisplay_is_console(addr);
    255 
    256 	if (isconsole) {
    257 		sc->sc_dc = &nextdisplay_console_dc;
    258 		sc->nscreens = 1;
    259 	} else {
    260 		sc->sc_dc = (struct nextdisplay_config *)
    261 				malloc(sizeof(struct nextdisplay_config), M_DEVBUF, M_WAITOK);
    262 		nextdisplay_init(sc->sc_dc, iscolor);
    263 	}
    264 
    265 	printf(": %d x %d, %dbpp\n", sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
    266 	       sc->sc_dc->dc_depth);
    267 
    268 	/* initialize the raster */
    269 	waa.console = isconsole;
    270 	waa.scrdata = iscolor ? &nextdisplay_screenlist_color : &nextdisplay_screenlist_mono;
    271 	waa.accessops = &nextdisplay_accessops;
    272 	waa.accesscookie = sc;
    273 #if 0
    274 	printf("nextdisplay: access cookie is %p\n", sc);
    275 #endif
    276 	config_found(self, &waa, wsemuldisplaydevprint);
    277 }
    278 
    279 
    280 int
    281 nextdisplay_ioctl(v, cmd, data, flag, p)
    282 	void *v;
    283 	u_long cmd;
    284 	caddr_t data;
    285 	int flag;
    286 	struct proc *p;
    287 {
    288 	struct nextdisplay_softc *sc = v;
    289 	struct nextdisplay_config *dc = sc->sc_dc;
    290 
    291 	switch (cmd) {
    292 	case WSDISPLAYIO_GTYPE:
    293 		*(int *)data = dc->dc_type;
    294 		return 0;
    295 
    296 	case WSDISPLAYIO_SCURSOR:
    297 		printf("nextdisplay_ioctl: wsdisplayio_scursor\n");
    298 		return EPASSTHROUGH;
    299 
    300 	case WSDISPLAYIO_SCURPOS:
    301 		printf("nextdisplay_ioctl: wsdisplayio_scurpos\n");
    302 		return EPASSTHROUGH;
    303 
    304 	case WSDISPLAYIO_GINFO:
    305 	case WSDISPLAYIO_GETCMAP:
    306 	case WSDISPLAYIO_PUTCMAP:
    307 	case WSDISPLAYIO_GVIDEO:
    308 	case WSDISPLAYIO_SVIDEO:
    309 	case WSDISPLAYIO_GCURPOS:
    310 	case WSDISPLAYIO_GCURMAX:
    311 	case WSDISPLAYIO_GCURSOR:
    312 		printf("nextdisplay_ioctl: listed but unsupported ioctl\n");
    313 		return EPASSTHROUGH;
    314 	}
    315 
    316 	return EPASSTHROUGH;
    317 }
    318 
    319 static paddr_t
    320 nextdisplay_mmap(v, offset, prot)
    321 	void *v;
    322 	off_t offset;
    323 	int prot;
    324 {
    325 
    326 	/* XXX */
    327 	printf("nextdisplay_mmap: failed\n");
    328 	return -1;
    329 }
    330 
    331 int
    332 nextdisplay_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
    333 	void *v;
    334 	const struct wsscreen_descr *type;
    335 	void **cookiep;
    336 	int *curxp, *curyp;
    337 	long *defattrp;
    338 {
    339 	struct nextdisplay_softc *sc = v;
    340 	long defattr;
    341 
    342 	/* only allow one screen */
    343 	if (sc->nscreens > 0)
    344 		return (ENOMEM);
    345 
    346 	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
    347 	*curxp = 0;
    348 	*curyp = 0;
    349 	rcons_allocattr(&sc->sc_dc->dc_rcons, 0, 0,
    350 			(strcmp(type->name, "color") == 0)
    351 			? 0
    352 			: WSATTR_REVERSE, &defattr);
    353 	*defattrp = defattr;
    354 	sc->nscreens++;
    355 #if 0
    356 	printf("nextdisplay: allocating screen\n");
    357 #endif
    358 	return (0);
    359 }
    360 
    361 void
    362 nextdisplay_free_screen(v, cookie)
    363 	void *v;
    364 	void *cookie;
    365 {
    366 	struct nextdisplay_softc *sc = v;
    367 
    368 	if (sc->sc_dc == &nextdisplay_console_dc)
    369 		panic("nextdisplay_free_screen: console");
    370 
    371 	sc->nscreens--;
    372 }
    373 
    374 int
    375 nextdisplay_show_screen(v, cookie, waitok, cb, cbarg)
    376 	void *v;
    377 	void *cookie;
    378 	int waitok;
    379 	void (*cb) __P((void *, int, int));
    380 	void *cbarg;
    381 {
    382 
    383 	return (0);
    384 }
    385 
    386 static int
    387 nextdisplay_load_font(v, cookie, font)
    388 	void *v;
    389 	void *cookie;
    390 	struct wsdisplay_font *font;
    391 {
    392 	return (EPASSTHROUGH);
    393 }
    394 
    395 int
    396 nextdisplay_cnattach(void)
    397 {
    398 	struct nextdisplay_config *dc = &nextdisplay_console_dc;
    399 	long defattr;
    400 	int iscolor;
    401 
    402 	if ((rom_machine_type == NeXT_WARP9C)
    403 	    || (rom_machine_type == NeXT_TURBO_COLOR)) {
    404 		iscolor = 1;
    405 		nextdisplay_consaddr = (paddr_t)colorbase;
    406 	} else {
    407 		iscolor = 0;
    408 		nextdisplay_consaddr = (paddr_t)monobase;
    409 	}
    410 
    411 	/* set up the display */
    412 	nextdisplay_init(&nextdisplay_console_dc, iscolor);
    413 
    414 	rcons_allocattr(&dc->dc_rcons, 0, 0,
    415 			iscolor ? 0 : WSATTR_REVERSE, &defattr);
    416 
    417 	wsdisplay_cnattach(iscolor ? &nextdisplay_color : &nextdisplay_mono,
    418 			   &dc->dc_rcons, 0, 0, defattr);
    419 
    420 	dc->isconsole = 1;
    421 	return (0);
    422 }
    423