Home | History | Annotate | Line # | Download | only in dev
macfb.c revision 1.1.2.6
      1 /* $NetBSD: macfb.c,v 1.1.2.6 1999/11/20 08:34:14 scottr Exp $ */
      2 /*
      3  * Copyright (c) 1998 Matt DeBergalis
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed by Matt DeBergalis
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include "opt_wsdisplay_compat.h"
     33 #include "grf.h"
     34 
     35 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/kernel.h>
     40 #include <sys/device.h>
     41 #include <sys/malloc.h>
     42 
     43 #include <machine/cpu.h>
     44 #include <machine/bus.h>
     45 
     46 #include <machine/grfioctl.h>
     47 #include <mac68k/nubus/nubus.h>
     48 #include <mac68k/dev/grfvar.h>
     49 #include <mac68k/dev/macfbvar.h>
     50 #include <dev/wscons/wsconsio.h>
     51 
     52 #ifdef WSDISPLAY_COMPAT_ITE
     53 #include <machine/iteioctl.h>
     54 #endif /* WSDISPLAY_COMPAT_ITE */
     55 
     56 #include <dev/rcons/raster.h>
     57 #include <dev/wscons/wscons_raster.h>
     58 #include <dev/wscons/wsdisplayvar.h>
     59 
     60 int macfb_match __P((struct device *, struct cfdata *, void *));
     61 void macfb_attach __P((struct device *, struct device *, void *));
     62 
     63 struct cfattach macfb_ca = {
     64 	sizeof(struct macfb_softc),
     65 	macfb_match,
     66 	macfb_attach,
     67 };
     68 
     69 const struct wsdisplay_emulops macfb_emulops = {
     70 	rcons_cursor,
     71 	rcons_mapchar,
     72 	rcons_putchar,
     73 	rcons_copycols,
     74 	rcons_erasecols,
     75 	rcons_copyrows,
     76 	rcons_eraserows,
     77 	rcons_alloc_attr
     78 };
     79 
     80 struct wsscreen_descr macfb_stdscreen = {
     81 	"std",
     82 	0, 0, /* will be filled in -- XXX shouldn't, it's global */
     83 	&macfb_emulops,
     84 	0, 0,
     85 	WSSCREEN_REVERSE
     86 };
     87 
     88 const struct wsscreen_descr *_macfb_scrlist[] = {
     89 	&macfb_stdscreen,
     90 };
     91 
     92 const struct wsscreen_list macfb_screenlist = {
     93 	sizeof(_macfb_scrlist) / sizeof(struct wsscreen_descr *),
     94 	_macfb_scrlist
     95 };
     96 
     97 static int	macfb_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
     98 static int	macfb_mmap __P((void *, off_t, int));
     99 static int	macfb_alloc_screen __P((void *, const struct wsscreen_descr *,
    100 		void **, int *, int *, long *));
    101 static void	macfb_free_screen __P((void *, void *));
    102 static void	macfb_show_screen __P((void *, void *));
    103 
    104 const struct wsdisplay_accessops macfb_accessops = {
    105 	macfb_ioctl,
    106 	macfb_mmap,
    107 	macfb_alloc_screen,
    108 	macfb_free_screen,
    109 	macfb_show_screen,
    110 	0 /* load_font */
    111 };
    112 
    113 void macfb_init __P((struct macfb_devconfig *));
    114 
    115 paddr_t macfb_consaddr;
    116 static int macfb_is_console __P((paddr_t addr));
    117 #ifdef WSDISPLAY_COMPAT_ITEFONT
    118 static void	init_itefont __P((void));
    119 #endif /* WSDISPLAY_COMPAT_ITEFONT */
    120 
    121 static struct macfb_devconfig macfb_console_dc;
    122 
    123 /* From Booter via locore */
    124 extern long		videoaddr;
    125 extern long		videorowbytes;
    126 extern long		videobitdepth;
    127 extern u_long		videosize;
    128 extern u_int32_t	mac68k_vidlog;
    129 extern u_int32_t	mac68k_vidphys;
    130 extern u_int32_t	mac68k_vidlen;
    131 
    132 static int
    133 macfb_is_console(paddr_t addr)
    134 {
    135 	return ((mac68k_machine.serial_console & 0x03) == 0
    136 	    && (addr == macfb_consaddr));
    137 }
    138 
    139 void
    140 macfb_clear(dc)
    141 	struct macfb_devconfig *dc;
    142 {
    143 	int i, rows;
    144 
    145 	/* clear the display */
    146 	rows = dc->dc_ht;
    147 	for (i = 0; rows-- > 0; i += dc->dc_rowbytes)
    148 		memset((u_char *)dc->dc_vaddr + dc->dc_offset + i,
    149 		    0, dc->dc_rowbytes);
    150 }
    151 
    152 void
    153 macfb_init(dc)
    154 	struct macfb_devconfig *dc;
    155 {
    156 	struct raster *rap;
    157 	struct rcons *rcp;
    158 
    159 	macfb_clear(dc);
    160 
    161 #ifdef WSDISPLAY_COMPAT_ITEFONT
    162 	init_itefont();
    163 #endif /* WSDISPLAY_COMPAT_ITEFONT */
    164 
    165 	rap = &dc->dc_raster;
    166 	rap->width = dc->dc_wid;
    167 	rap->height = dc->dc_ht;
    168 	rap->depth = dc->dc_depth;
    169 	rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
    170 	rap->pixels = (u_int32_t *)dc->dc_vaddr + dc->dc_offset;
    171 
    172 	/* initialize the raster console blitter */
    173 	rcp = &dc->dc_rcons;
    174 	rcp->rc_sp = rap;
    175 	rcp->rc_crow = rcp->rc_ccol = -1;
    176 	rcp->rc_crowp = &rcp->rc_crow;
    177 	rcp->rc_ccolp = &rcp->rc_ccol;
    178 	rcons_init(rcp, 128, 128);
    179 
    180 	macfb_stdscreen.nrows = dc->dc_rcons.rc_maxrow;
    181 	macfb_stdscreen.ncols = dc->dc_rcons.rc_maxcol;
    182 }
    183 
    184 int
    185 macfb_match(parent, match, aux)
    186 	struct device *parent;
    187 	struct cfdata *match;
    188 	void *aux;
    189 {
    190 	return (1);
    191 }
    192 
    193 void
    194 macfb_attach(parent, self, aux)
    195 	struct device *parent;
    196 	struct device *self;
    197 	void *aux;
    198 {
    199 	struct grfbus_attach_args *ga = aux;
    200 	struct grfmode *gm = ga->ga_grfmode;
    201 	struct macfb_softc *sc;
    202 	struct wsemuldisplaydev_attach_args waa;
    203 	int isconsole;
    204 
    205 	sc = (struct macfb_softc *)self;
    206 
    207 	printf("\n");
    208 
    209 	isconsole = macfb_is_console(ga->ga_phys + ga->ga_grfmode->fboff);
    210 
    211 	if (isconsole) {
    212 		sc->sc_dc = &macfb_console_dc;
    213 		sc->nscreens = 1;
    214 	} else {
    215 		sc->sc_dc = malloc(sizeof(struct macfb_devconfig), M_DEVBUF, M_WAITOK);
    216 		sc->sc_dc->dc_vaddr = (vaddr_t)gm->fbbase;
    217 		sc->sc_dc->dc_paddr = ga->ga_phys;
    218 		sc->sc_dc->dc_size = gm->fbsize;
    219 
    220 		sc->sc_dc->dc_wid = gm->width;
    221 		sc->sc_dc->dc_ht = gm->height;
    222 		sc->sc_dc->dc_depth = gm->psize;
    223 		sc->sc_dc->dc_rowbytes = gm->rowbytes;
    224 
    225 		sc->sc_dc->dc_offset = gm->fboff;
    226 
    227 		macfb_init(sc->sc_dc);
    228 
    229 		sc->nscreens = 1;
    230 	}
    231 
    232 	/* initialize the raster */
    233 	waa.console = isconsole;
    234 	waa.scrdata = &macfb_screenlist;
    235 	waa.accessops = &macfb_accessops;
    236 	waa.accesscookie = sc;
    237 
    238 	config_found(self, &waa, wsemuldisplaydevprint);
    239 
    240 #if NGRF > 0
    241 	grf_attach(sc, self->dv_unit);
    242 #endif
    243 }
    244 
    245 
    246 int
    247 macfb_ioctl(v, cmd, data, flag, p)
    248 	void *v;
    249 	u_long cmd;
    250 	caddr_t data;
    251 	int flag;
    252 	struct proc *p;
    253 {
    254 	struct macfb_softc *sc = v;
    255 	struct macfb_devconfig *dc = sc->sc_dc;
    256 	struct wsdisplay_fbinfo *wdf;
    257 
    258 	switch (cmd) {
    259 	case WSDISPLAYIO_GTYPE:
    260 		*(int *)data = dc->dc_type;
    261 		return 0;
    262 
    263 	case WSDISPLAYIO_GINFO:
    264 		wdf = (struct wsdisplay_fbinfo *)data;
    265 		wdf->height = dc->dc_raster.height;
    266 		wdf->width = dc->dc_raster.width;
    267 		wdf->depth = dc->dc_raster.depth;
    268 		wdf->cmsize = 256;
    269 		return 0;
    270 
    271 	case WSDISPLAYIO_GCURMAX:
    272 	case WSDISPLAYIO_GCURPOS:
    273 	case WSDISPLAYIO_GCURSOR:
    274 	case WSDISPLAYIO_GETCMAP:
    275 	case WSDISPLAYIO_GVIDEO:
    276 	case WSDISPLAYIO_PUTCMAP:
    277 	case WSDISPLAYIO_SCURPOS:
    278 	case WSDISPLAYIO_SCURSOR:
    279 	case WSDISPLAYIO_SVIDEO:
    280 		/* NONE of these operations are supported. */
    281 		return ENOTTY;
    282 
    283 #ifdef WSDISPLAY_COMPAT_ITE
    284 	case ITEIOC_GETBELL:
    285 	case ITEIOC_SETBELL:
    286 	case ITEIOC_RINGBELL:
    287 		/* NONE of these operations are supported. */
    288 		return ENOTTY;
    289 
    290 #endif /* WSDISPLAY_COMPAT_ITE */
    291 	}
    292 
    293 	return -1;
    294 }
    295 
    296 static int
    297 macfb_mmap(v, offset, prot)
    298 	void *v;
    299 	off_t offset;
    300 	int prot;
    301 {
    302 	struct macfb_softc *sc = v;
    303 	struct macfb_devconfig *dc = sc->sc_dc;
    304 	u_long addr;
    305 
    306 	if (offset >= 0 &&
    307 	    offset < m68k_round_page(dc->dc_rowbytes * dc->dc_ht))
    308 		addr = m68k_btop(dc->dc_paddr + dc->dc_offset + offset);
    309 	else
    310 		addr = (-1);	/* XXX bogus */
    311 
    312 	return (int)addr;
    313 }
    314 
    315 int
    316 macfb_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
    317 	void *v;
    318 	const struct wsscreen_descr *type;
    319 	void **cookiep;
    320 	int *curxp, *curyp;
    321 	long *defattrp;
    322 {
    323 	struct macfb_softc *sc = v;
    324 	long defattr;
    325 
    326 	if (sc->nscreens > 0)
    327 		return (ENOMEM);
    328 
    329 	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
    330 	*curxp = 0;
    331 	*curyp = 0;
    332 	rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
    333 	*defattrp = defattr;
    334 	sc->nscreens++;
    335 	return (0);
    336 }
    337 
    338 void
    339 macfb_free_screen(v, cookie)
    340 	void *v;
    341 	void *cookie;
    342 {
    343 	struct macfb_softc *sc = v;
    344 
    345 	if (sc->sc_dc == &macfb_console_dc)
    346 		panic("cfb_free_screen: console");
    347 
    348 	sc->nscreens--;
    349 }
    350 
    351 void
    352 macfb_show_screen(v, cookie)
    353 	void *v;
    354 	void *cookie;
    355 {
    356 }
    357 
    358 int
    359 macfb_cnattach(addr)
    360 	paddr_t addr;
    361 {
    362 	struct macfb_devconfig *dc = &macfb_console_dc;
    363 	long defattr;
    364 
    365 	dc->dc_vaddr = videoaddr;
    366 	dc->dc_paddr = mac68k_vidphys;
    367 
    368 	dc->dc_wid = videosize & 0xffff;
    369 	dc->dc_ht = (videosize >> 16) & 0xffff;
    370 	dc->dc_depth = videobitdepth;
    371 	dc->dc_rowbytes = videorowbytes;
    372 
    373 	dc->dc_size = (mac68k_vidlen > 0) ?
    374 	    mac68k_vidlen : dc->dc_ht * dc->dc_rowbytes;
    375 	dc->dc_offset = 0;
    376 
    377 	/* set up the display */
    378 	macfb_init(&macfb_console_dc);
    379 
    380 	rcons_alloc_attr(&dc->dc_rcons, 0, 0, 0, &defattr);
    381 
    382 	wsdisplay_cnattach(&macfb_stdscreen, &dc->dc_rcons,
    383 			0, 0, defattr);
    384 
    385 	macfb_consaddr = addr;
    386 	dc->isconsole = 1;
    387 	return (0);
    388 }
    389 
    390 #ifdef WSDISPLAY_COMPAT_ITEFONT
    391 #include <mac68k/dev/6x10.h>
    392 
    393 void
    394 init_itefont()
    395 {
    396 	static int itefont_initted = 0;
    397 	int i, j;
    398 
    399 	extern struct raster_font gallant19;		/* XXX */
    400 
    401 	if (itefont_initted)
    402 		return;
    403 	itefont_initted = 1;
    404 
    405 	/* XXX but we cannot use malloc here... */
    406 	gallant19.width = 6;
    407 	gallant19.height = 10;
    408 	gallant19.ascent = 0;
    409 
    410 	for (i = 32; i < 128; i++) {
    411 		u_int *p;
    412 
    413 		if (gallant19.chars[i].r == NULL)
    414 			continue;
    415 
    416 		gallant19.chars[i].r->width = 6;
    417 		gallant19.chars[i].r->height = 10;
    418 		p = gallant19.chars[i].r->pixels;
    419 
    420 		for (j = 0; j < 10; j++)
    421 			*p++ = Font6x10[i * 10 + j] << 26;
    422 	}
    423 }
    424 #endif /* WSDISPLAY_COMPAT_ITEFONT */
    425