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