Home | History | Annotate | Line # | Download | only in dev
nextdisplay.c revision 1.12.6.4
      1 /* $NetBSD: nextdisplay.c,v 1.12.6.4 2005/01/17 19:29:58 skrll 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.12.6.4 2005/01/17 19:29:58 skrll 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 	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 = (void *)self;
    239 	struct wsemuldisplaydev_attach_args waa;
    240 	int isconsole;
    241 	int iscolor;
    242 	paddr_t addr;
    243 
    244 	if (rom_machine_type == NeXT_WARP9C ||
    245 	    rom_machine_type == NeXT_TURBO_COLOR) {
    246 		iscolor = 1;
    247 		addr = colorbase;
    248 	} else {
    249 		iscolor = 0;
    250 		addr = monobase;
    251 	}
    252 
    253 	isconsole = nextdisplay_is_console(addr);
    254 
    255 	if (isconsole) {
    256 		sc->sc_dc = &nextdisplay_console_dc;
    257 		sc->nscreens = 1;
    258 	} else {
    259 		sc->sc_dc = (struct nextdisplay_config *)
    260 				malloc(sizeof(struct nextdisplay_config), M_DEVBUF, M_WAITOK);
    261 		nextdisplay_init(sc->sc_dc, iscolor);
    262 	}
    263 
    264 	printf(": %d x %d, %dbpp\n", sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
    265 	       sc->sc_dc->dc_depth);
    266 
    267 	if (iscolor) {
    268 #if 0
    269 		uint8_t x;
    270 
    271 		x = *(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG);
    272 		printf("%s: cmd=%02x\n", sc->sc_dev.dv_xname, x);
    273 #endif
    274 		*(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG) = 0x05;
    275 		isrlink_autovec(nextdisplay_intr, sc, NEXT_I_IPL(NEXT_I_C16_VIDEO), 1, NULL);
    276 		INTR_ENABLE(NEXT_I_C16_VIDEO);
    277 	}
    278 
    279 	/* initialize the raster */
    280 	waa.console = isconsole;
    281 	waa.scrdata = iscolor ? &nextdisplay_screenlist_color : &nextdisplay_screenlist_mono;
    282 	waa.accessops = &nextdisplay_accessops;
    283 	waa.accesscookie = sc;
    284 #if 0
    285 	printf("nextdisplay: access cookie is %p\n", sc);
    286 #endif
    287 	config_found(self, &waa, wsemuldisplaydevprint);
    288 }
    289 
    290 int
    291 nextdisplay_intr(arg)
    292 	void *arg;
    293 {
    294 #if 0
    295 	uint8_t x;
    296 #endif
    297 
    298 	if (!INTR_OCCURRED(NEXT_I_C16_VIDEO))
    299 		return (0);
    300 #if 0
    301 	x = *(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG);
    302 	printf("I%02x", x);
    303 #endif
    304 	*(volatile uint8_t *)IIOV(NEXT_P_C16_CMD_REG) = 0x05;
    305 	return (1);
    306 }
    307 
    308 int
    309 nextdisplay_ioctl(v, cmd, data, flag, p)
    310 	void *v;
    311 	u_long cmd;
    312 	caddr_t data;
    313 	int flag;
    314 	struct proc *p;
    315 {
    316 	struct nextdisplay_softc *sc = v;
    317 	struct nextdisplay_config *dc = sc->sc_dc;
    318 
    319 	switch (cmd) {
    320 	case WSDISPLAYIO_GTYPE:
    321 		*(int *)data = dc->dc_type;
    322 		return 0;
    323 
    324 	case WSDISPLAYIO_SCURSOR:
    325 		printf("nextdisplay_ioctl: wsdisplayio_scursor\n");
    326 		return EPASSTHROUGH;
    327 
    328 	case WSDISPLAYIO_SCURPOS:
    329 		printf("nextdisplay_ioctl: wsdisplayio_scurpos\n");
    330 		return EPASSTHROUGH;
    331 
    332 	case WSDISPLAYIO_GINFO:
    333 	case WSDISPLAYIO_GETCMAP:
    334 	case WSDISPLAYIO_PUTCMAP:
    335 	case WSDISPLAYIO_GVIDEO:
    336 	case WSDISPLAYIO_SVIDEO:
    337 	case WSDISPLAYIO_GCURPOS:
    338 	case WSDISPLAYIO_GCURMAX:
    339 	case WSDISPLAYIO_GCURSOR:
    340 		printf("nextdisplay_ioctl: listed but unsupported ioctl\n");
    341 		return EPASSTHROUGH;
    342 	}
    343 
    344 	return EPASSTHROUGH;
    345 }
    346 
    347 static paddr_t
    348 nextdisplay_mmap(v, offset, prot)
    349 	void *v;
    350 	off_t offset;
    351 	int prot;
    352 {
    353 
    354 	/* XXX */
    355 	printf("nextdisplay_mmap: failed\n");
    356 	return -1;
    357 }
    358 
    359 int
    360 nextdisplay_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
    361 	void *v;
    362 	const struct wsscreen_descr *type;
    363 	void **cookiep;
    364 	int *curxp, *curyp;
    365 	long *defattrp;
    366 {
    367 	struct nextdisplay_softc *sc = v;
    368 	long defattr;
    369 
    370 	/* only allow one screen */
    371 	if (sc->nscreens > 0)
    372 		return (ENOMEM);
    373 
    374 	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
    375 	*curxp = 0;
    376 	*curyp = 0;
    377 	rcons_allocattr(&sc->sc_dc->dc_rcons, 0, 0,
    378 			(strcmp(type->name, "color") == 0)
    379 			? 0
    380 			: WSATTR_REVERSE, &defattr);
    381 	*defattrp = defattr;
    382 	sc->nscreens++;
    383 #if 0
    384 	printf("nextdisplay: allocating screen\n");
    385 #endif
    386 	return (0);
    387 }
    388 
    389 void
    390 nextdisplay_free_screen(v, cookie)
    391 	void *v;
    392 	void *cookie;
    393 {
    394 	struct nextdisplay_softc *sc = v;
    395 
    396 	if (sc->sc_dc == &nextdisplay_console_dc)
    397 		panic("nextdisplay_free_screen: console");
    398 
    399 	sc->nscreens--;
    400 }
    401 
    402 int
    403 nextdisplay_show_screen(v, cookie, waitok, cb, cbarg)
    404 	void *v;
    405 	void *cookie;
    406 	int waitok;
    407 	void (*cb) __P((void *, int, int));
    408 	void *cbarg;
    409 {
    410 
    411 	return (0);
    412 }
    413 
    414 static int
    415 nextdisplay_load_font(v, cookie, font)
    416 	void *v;
    417 	void *cookie;
    418 	struct wsdisplay_font *font;
    419 {
    420 	return (EPASSTHROUGH);
    421 }
    422 
    423 int
    424 nextdisplay_cnattach(void)
    425 {
    426 	struct nextdisplay_config *dc = &nextdisplay_console_dc;
    427 	long defattr;
    428 	int iscolor;
    429 
    430 	if (rom_machine_type == NeXT_WARP9C ||
    431 	    rom_machine_type == NeXT_TURBO_COLOR)
    432 		iscolor = 1;
    433 	else
    434 		iscolor = 0;
    435 
    436 	/* set up the display */
    437 	nextdisplay_init(&nextdisplay_console_dc, iscolor);
    438 	nextdisplay_consaddr = nextdisplay_console_dc.dc_vaddr;
    439 
    440 	rcons_allocattr(&dc->dc_rcons, 0, 0,
    441 			iscolor ? 0 : WSATTR_REVERSE, &defattr);
    442 
    443 	wsdisplay_cnattach(iscolor ? &nextdisplay_color : &nextdisplay_mono,
    444 			   &dc->dc_rcons, 0, 0, defattr);
    445 
    446 	dc->isconsole = 1;
    447 	return (0);
    448 }
    449