Home | History | Annotate | Line # | Download | only in dev
nextdisplay.c revision 1.7
      1 /* $NetBSD: nextdisplay.c,v 1.7 2002/03/17 19:40:46 atatat 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/cpu.h>
     42 #include <machine/bus.h>
     43 
     44 #include <next68k/next68k/nextrom.h>
     45 
     46 #include <next68k/dev/nextdisplayvar.h>
     47 #include <dev/wscons/wsconsio.h>
     48 
     49 #include <dev/rcons/raster.h>
     50 #include <dev/wscons/wscons_raster.h>
     51 #include <dev/wscons/wsdisplayvar.h>
     52 
     53 int nextdisplay_match __P((struct device *, struct cfdata *, void *));
     54 void nextdisplay_attach __P((struct device *, struct device *, void *));
     55 
     56 struct cfattach nextdisplay_ca = {
     57 	sizeof(struct nextdisplay_softc),
     58 	nextdisplay_match,
     59 	nextdisplay_attach,
     60 };
     61 
     62 const struct wsdisplay_emulops nextdisplay_mono_emulops = {
     63 	rcons_cursor,
     64 	rcons_mapchar,
     65 	rcons_putchar,
     66 	rcons_copycols,
     67 	rcons_erasecols,
     68 	rcons_copyrows,
     69 	rcons_eraserows,
     70 	rcons_alloc_attr
     71 };
     72 
     73 struct wsscreen_descr nextdisplay_mono = {
     74 	"mono",
     75 	0, 0, /* will be filled in -- XXX shouldn't, it's global */
     76 	&nextdisplay_mono_emulops,
     77 	0, 0
     78 };
     79 
     80 struct wsscreen_descr nextdisplay_color = {
     81         "color",
     82         0, 0, /* again, filled in */
     83         &nextdisplay_mono_emulops,
     84         0, 0
     85 };
     86 
     87 const struct wsscreen_descr *_nextdisplay_scrlist_mono[] = {
     88 	&nextdisplay_mono,
     89 };
     90 
     91 const struct wsscreen_descr *_nextdisplay_scrlist_color[] = {
     92         &nextdisplay_color,
     93 };
     94 
     95 const struct wsscreen_list nextdisplay_screenlist_mono = {
     96 	sizeof(_nextdisplay_scrlist_mono) / sizeof(struct wsscreen_descr *),
     97 	_nextdisplay_scrlist_mono
     98 };
     99 
    100 const struct wsscreen_list nextdisplay_screenlist_color = {
    101 	sizeof(_nextdisplay_scrlist_color) / sizeof(struct wsscreen_descr *),
    102 	_nextdisplay_scrlist_color
    103 };
    104 
    105 static int	nextdisplay_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
    106 static paddr_t	nextdisplay_mmap __P((void *, off_t, int));
    107 static int	nextdisplay_alloc_screen __P((void *, const struct wsscreen_descr *,
    108 		void **, int *, int *, long *));
    109 static void	nextdisplay_free_screen __P((void *, void *));
    110 static int	nextdisplay_show_screen __P((void *, void *, int,
    111 					     void (*) (void *, int, int), void *));
    112 static int	nextdisplay_load_font __P((void *, void *, struct wsdisplay_font *));
    113 
    114 const struct wsdisplay_accessops nextdisplay_accessops = {
    115 	nextdisplay_ioctl,
    116 	nextdisplay_mmap,
    117 	nextdisplay_alloc_screen,
    118 	nextdisplay_free_screen,
    119 	nextdisplay_show_screen,
    120 	nextdisplay_load_font
    121 };
    122 
    123 void nextdisplay_init(struct nextdisplay_config *, int);
    124 
    125 paddr_t nextdisplay_consaddr;
    126 static int nextdisplay_is_console __P((paddr_t addr));
    127 
    128 static struct nextdisplay_config nextdisplay_console_dc;
    129 
    130 static int
    131 nextdisplay_is_console(paddr_t addr)
    132 {
    133 	return (nextdisplay_console_dc.isconsole
    134 			&& (addr == nextdisplay_consaddr));
    135 }
    136 
    137 int
    138 nextdisplay_match(parent, match, aux)
    139 	struct device *parent;
    140 	struct cfdata *match;
    141 	void *aux;
    142 {
    143 	if ((rom_machine_type == NeXT_WARP9)
    144 	    || (rom_machine_type == NeXT_X15)
    145 	    || (rom_machine_type == NeXT_WARP9C)
    146 	    || (rom_machine_type == NeXT_TURBO_COLOR))
    147 		return (1);
    148 	else
    149 		return (0);
    150 }
    151 
    152 void
    153 nextdisplay_init(dc, color)
    154 	struct nextdisplay_config *dc;
    155 	int color;
    156 {
    157 	struct raster *rap;
    158 	struct rcons *rcp;
    159 	paddr_t addr;
    160 	int i;
    161 
    162 	/* printf("in nextdisplay_init\n"); */
    163 
    164 	if (color)
    165 		addr = (paddr_t)colorbase;
    166 	else
    167 		addr = (paddr_t)monobase;
    168 
    169 	dc->dc_vaddr = addr;
    170 	dc->dc_paddr = color ? COLORP(addr) : MONOP(addr);
    171 	dc->dc_size = color ? NEXT_P_C16_VIDEOSIZE : NEXT_P_VIDEOSIZE;
    172 
    173 	dc->dc_wid = color ? 1152 : 1152;
    174 	dc->dc_ht = color ? 832 : 832;
    175 	dc->dc_depth = color ? 16 : 2;
    176 	dc->dc_rowbytes = dc->dc_wid * dc->dc_depth / 8;
    177 
    178 	dc->dc_videobase = dc->dc_vaddr;
    179 
    180 #if 0
    181 	printf("intiobase at: %08x\n", intiobase);
    182 	printf("intiolimit at: %08x\n", intiolimit);
    183 	printf("videobase at: %08x\n", color ? colorbase : monobase);
    184 	printf("videolimit at: %08x\n", color ? colorlimit : monolimit);
    185 
    186 	printf("virtual fb at: %08x\n", dc->dc_vaddr);
    187 	printf("physical fb at: %08x\n", dc->dc_paddr);
    188 	printf("fb size: %08x\n", dc->dc_size);
    189 
    190 	printf("dc_wid: %08x\n", dc->dc_wid);
    191 	printf("dc_ht: %08x\n", dc->dc_ht);
    192 	printf("dc_depth: %08x\n", dc->dc_depth);
    193 	printf("dc_rowbytes: %08x\n", dc->dc_rowbytes);
    194 	printf("dc_videobase: %08x\n", dc->dc_videobase);
    195 #endif
    196 
    197 	/* clear the screen */
    198 	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
    199 		*(u_int32_t *)(dc->dc_videobase + i) =
    200 			(color ? 0x0 : 0xffffffff);
    201 
    202 	printf("done clearing\n");
    203 
    204 	rap = &dc->dc_raster;
    205 	rap->width = dc->dc_wid;
    206 	rap->height = dc->dc_ht;
    207 	rap->depth = color ? 16 : 2;
    208 	rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
    209 	rap->pixels = (u_int32_t *)dc->dc_videobase;
    210 
    211 	/* initialize the raster console blitter */
    212 	rcp = &dc->dc_rcons;
    213 	rcp->rc_sp = rap;
    214 	rcp->rc_crow = rcp->rc_ccol = -1;
    215 	rcp->rc_crowp = &rcp->rc_crow;
    216 	rcp->rc_ccolp = &rcp->rc_ccol;
    217 	rcons_init(rcp, 34, 80);
    218 
    219 	if (color) {
    220 		nextdisplay_color.nrows = dc->dc_rcons.rc_maxrow;
    221 		nextdisplay_color.ncols = dc->dc_rcons.rc_maxcol;
    222 	} else {
    223 		nextdisplay_mono.nrows = dc->dc_rcons.rc_maxrow;
    224 		nextdisplay_mono.ncols = dc->dc_rcons.rc_maxcol;
    225 	}
    226 }
    227 
    228 void
    229 nextdisplay_attach(parent, self, aux)
    230 	struct device *parent;
    231 	struct device *self;
    232 	void *aux;
    233 {
    234 	struct nextdisplay_softc *sc;
    235 	struct wsemuldisplaydev_attach_args waa;
    236 	int isconsole;
    237 	int iscolor;
    238 	paddr_t addr;
    239 
    240 	sc = (struct nextdisplay_softc *)self;
    241 
    242 	if ((rom_machine_type == NeXT_WARP9C)
    243 	    || (rom_machine_type == NeXT_TURBO_COLOR)) {
    244 		iscolor = 1;
    245 		addr = (paddr_t)colorbase;
    246 	} else {
    247 		iscolor = 0;
    248 		addr = (paddr_t)monobase;
    249 	}
    250 
    251 	isconsole = nextdisplay_is_console(addr);
    252 
    253 	if (isconsole) {
    254 		sc->sc_dc = &nextdisplay_console_dc;
    255 		sc->nscreens = 1;
    256 	} else {
    257 		sc->sc_dc = (struct nextdisplay_config *)
    258 				malloc(sizeof(struct nextdisplay_config), M_DEVBUF, M_WAITOK);
    259 		nextdisplay_init(sc->sc_dc, iscolor);
    260 	}
    261 
    262 	printf(": %d x %d, %dbpp\n", sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
    263 	       sc->sc_dc->dc_depth);
    264 
    265 	/* initialize the raster */
    266 	waa.console = isconsole;
    267 	waa.scrdata = iscolor ? &nextdisplay_screenlist_color : &nextdisplay_screenlist_mono;
    268 	waa.accessops = &nextdisplay_accessops;
    269 	waa.accesscookie = sc;
    270 #if 0
    271 	printf("nextdisplay: access cookie is %p\n", sc);
    272 #endif
    273 	config_found(self, &waa, wsemuldisplaydevprint);
    274 }
    275 
    276 
    277 int
    278 nextdisplay_ioctl(v, cmd, data, flag, p)
    279 	void *v;
    280 	u_long cmd;
    281 	caddr_t data;
    282 	int flag;
    283 	struct proc *p;
    284 {
    285 	struct nextdisplay_softc *sc = v;
    286 	struct nextdisplay_config *dc = sc->sc_dc;
    287 
    288 	switch (cmd) {
    289 	case WSDISPLAYIO_GTYPE:
    290 		*(int *)data = dc->dc_type;
    291 		return 0;
    292 
    293 	case WSDISPLAYIO_SCURSOR:
    294 		printf("nextdisplay_ioctl: wsdisplayio_scursor\n");
    295 		return EPASSTHROUGH;
    296 
    297 	case WSDISPLAYIO_SCURPOS:
    298 		printf("nextdisplay_ioctl: wsdisplayio_scurpos\n");
    299 		return EPASSTHROUGH;
    300 
    301 	case WSDISPLAYIO_GINFO:
    302 	case WSDISPLAYIO_GETCMAP:
    303 	case WSDISPLAYIO_PUTCMAP:
    304 	case WSDISPLAYIO_GVIDEO:
    305 	case WSDISPLAYIO_SVIDEO:
    306 	case WSDISPLAYIO_GCURPOS:
    307 	case WSDISPLAYIO_GCURMAX:
    308 	case WSDISPLAYIO_GCURSOR:
    309 		printf("nextdisplay_ioctl: listed but unsupported ioctl\n");
    310 		return EPASSTHROUGH;
    311 	}
    312 
    313 	return EPASSTHROUGH;
    314 }
    315 
    316 static paddr_t
    317 nextdisplay_mmap(v, offset, prot)
    318 	void *v;
    319 	off_t offset;
    320 	int prot;
    321 {
    322 
    323 	/* XXX */
    324 	printf("nextdisplay_mmap: failed\n");
    325 	return -1;
    326 }
    327 
    328 int
    329 nextdisplay_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
    330 	void *v;
    331 	const struct wsscreen_descr *type;
    332 	void **cookiep;
    333 	int *curxp, *curyp;
    334 	long *defattrp;
    335 {
    336 	struct nextdisplay_softc *sc = v;
    337 	long defattr;
    338 
    339 	/* only allow one screen */
    340 	if (sc->nscreens > 0)
    341 		return (ENOMEM);
    342 
    343 	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
    344 	*curxp = 0;
    345 	*curyp = 0;
    346 	rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0,
    347 			 (strcmp(type->name, "color") == 0)
    348 			 ? 0
    349 			 : WSATTR_REVERSE, &defattr);
    350 	*defattrp = defattr;
    351 	sc->nscreens++;
    352 #if 0
    353 	printf("nextdisplay: allocating screen\n");
    354 #endif
    355 	return (0);
    356 }
    357 
    358 void
    359 nextdisplay_free_screen(v, cookie)
    360 	void *v;
    361 	void *cookie;
    362 {
    363 	struct nextdisplay_softc *sc = v;
    364 
    365 	if (sc->sc_dc == &nextdisplay_console_dc)
    366 		panic("nextdisplay_free_screen: console");
    367 
    368 	sc->nscreens--;
    369 }
    370 
    371 int
    372 nextdisplay_show_screen(v, cookie, waitok, cb, cbarg)
    373 	void *v;
    374 	void *cookie;
    375 	int waitok;
    376 	void (*cb) __P((void *, int, int));
    377 	void *cbarg;
    378 {
    379 
    380 	return (0);
    381 }
    382 
    383 static int
    384 nextdisplay_load_font(v, cookie, font)
    385 	void *v;
    386 	void *cookie;
    387 	struct wsdisplay_font *font;
    388 {
    389 	return (EPASSTHROUGH);
    390 }
    391 
    392 int
    393 nextdisplay_cnattach(void)
    394 {
    395 	struct nextdisplay_config *dc = &nextdisplay_console_dc;
    396 	long defattr;
    397 	int iscolor;
    398 
    399 	if ((rom_machine_type == NeXT_WARP9C)
    400 	    || (rom_machine_type == NeXT_TURBO_COLOR)) {
    401 		iscolor = 1;
    402 		nextdisplay_consaddr = (paddr_t)colorbase;
    403 	} else {
    404 		iscolor = 0;
    405 		nextdisplay_consaddr = (paddr_t)monobase;
    406 	}
    407 
    408 	/* set up the display */
    409 	nextdisplay_init(&nextdisplay_console_dc, iscolor);
    410 
    411 	rcons_alloc_attr(&dc->dc_rcons, 0, 0,
    412 			 iscolor ? 0 : WSATTR_REVERSE, &defattr);
    413 
    414 	wsdisplay_cnattach(iscolor ? &nextdisplay_color : &nextdisplay_mono,
    415 			   &dc->dc_rcons, 0, 0, defattr);
    416 
    417 	dc->isconsole = 1;
    418 	return (0);
    419 }
    420