Home | History | Annotate | Line # | Download | only in dev
macfb.c revision 1.1.2.10
      1 /* $NetBSD: macfb.c,v 1.1.2.10 1999/12/24 10:07:48 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 int	macfb_show_screen __P((void *, void *, int,
    103 		    void (*)(void *, int, int), void *));
    104 
    105 const struct wsdisplay_accessops macfb_accessops = {
    106 	macfb_ioctl,
    107 	macfb_mmap,
    108 	macfb_alloc_screen,
    109 	macfb_free_screen,
    110 	macfb_show_screen,
    111 	0 /* load_font */
    112 };
    113 
    114 void macfb_init __P((struct macfb_devconfig *));
    115 
    116 paddr_t macfb_consaddr;
    117 static int macfb_is_console __P((paddr_t addr));
    118 #ifdef WSDISPLAY_COMPAT_ITEFONT
    119 static void	init_itefont __P((void));
    120 #endif /* WSDISPLAY_COMPAT_ITEFONT */
    121 
    122 static struct macfb_devconfig macfb_console_dc;
    123 
    124 /* From Booter via locore */
    125 extern long		videoaddr;
    126 extern long		videorowbytes;
    127 extern long		videobitdepth;
    128 extern u_long		videosize;
    129 extern u_int32_t	mac68k_vidlog;
    130 extern u_int32_t	mac68k_vidphys;
    131 extern u_int32_t	mac68k_vidlen;
    132 
    133 static int
    134 macfb_is_console(paddr_t addr)
    135 {
    136 	return ((mac68k_machine.serial_console & 0x03) == 0
    137 	    && (addr == macfb_consaddr));
    138 }
    139 
    140 void
    141 macfb_clear(dc)
    142 	struct macfb_devconfig *dc;
    143 {
    144 	int i, rows;
    145 
    146 	/* clear the display */
    147 	rows = dc->dc_ht;
    148 	for (i = 0; rows-- > 0; i += dc->dc_rowbytes)
    149 		memset((u_char *)dc->dc_vaddr + dc->dc_offset + i,
    150 		    0, dc->dc_rowbytes);
    151 }
    152 
    153 void
    154 macfb_init(dc)
    155 	struct macfb_devconfig *dc;
    156 {
    157 	struct raster *rap;
    158 	struct rcons *rcp;
    159 
    160 	macfb_clear(dc);
    161 
    162 #ifdef WSDISPLAY_COMPAT_ITEFONT
    163 	init_itefont();
    164 #endif /* WSDISPLAY_COMPAT_ITEFONT */
    165 
    166 	rap = &dc->dc_raster;
    167 	rap->width = dc->dc_wid;
    168 	rap->height = dc->dc_ht;
    169 	rap->depth = dc->dc_depth;
    170 	rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
    171 	rap->pixels = (u_int32_t *)(dc->dc_vaddr + dc->dc_offset);
    172 
    173 	/* initialize the raster console blitter */
    174 	rcp = &dc->dc_rcons;
    175 	rcp->rc_sp = rap;
    176 	rcp->rc_crow = rcp->rc_ccol = -1;
    177 	rcp->rc_crowp = &rcp->rc_crow;
    178 	rcp->rc_ccolp = &rcp->rc_ccol;
    179 	rcons_init(rcp, 128, 192);
    180 
    181 	macfb_stdscreen.nrows = dc->dc_rcons.rc_maxrow;
    182 	macfb_stdscreen.ncols = dc->dc_rcons.rc_maxcol;
    183 }
    184 
    185 int
    186 macfb_match(parent, match, aux)
    187 	struct device *parent;
    188 	struct cfdata *match;
    189 	void *aux;
    190 {
    191 	return (1);
    192 }
    193 
    194 void
    195 macfb_attach(parent, self, aux)
    196 	struct device *parent;
    197 	struct device *self;
    198 	void *aux;
    199 {
    200 	struct grfbus_attach_args *ga = aux;
    201 	struct grfmode *gm = ga->ga_grfmode;
    202 	struct macfb_softc *sc;
    203 	struct wsemuldisplaydev_attach_args waa;
    204 	int isconsole;
    205 
    206 	sc = (struct macfb_softc *)self;
    207 
    208 	printf("\n");
    209 
    210 	isconsole = macfb_is_console(ga->ga_phys + ga->ga_grfmode->fboff);
    211 
    212 	if (isconsole) {
    213 		sc->sc_dc = &macfb_console_dc;
    214 		sc->nscreens = 1;
    215 	} else {
    216 		sc->sc_dc = malloc(sizeof(struct macfb_devconfig), M_DEVBUF, M_WAITOK);
    217 		sc->sc_dc->dc_vaddr = (vaddr_t)gm->fbbase;
    218 		sc->sc_dc->dc_paddr = ga->ga_phys;
    219 		sc->sc_dc->dc_size = gm->fbsize;
    220 
    221 		sc->sc_dc->dc_wid = gm->width;
    222 		sc->sc_dc->dc_ht = gm->height;
    223 		sc->sc_dc->dc_depth = gm->psize;
    224 		sc->sc_dc->dc_rowbytes = gm->rowbytes;
    225 
    226 		sc->sc_dc->dc_offset = gm->fboff;
    227 
    228 		macfb_init(sc->sc_dc);
    229 
    230 		sc->nscreens = 1;
    231 	}
    232 
    233 	/* initialize the raster */
    234 	waa.console = isconsole;
    235 	waa.scrdata = &macfb_screenlist;
    236 	waa.accessops = &macfb_accessops;
    237 	waa.accesscookie = sc;
    238 
    239 	config_found(self, &waa, wsemuldisplaydevprint);
    240 
    241 #if NGRF > 0
    242 	grf_attach(sc, self->dv_unit);
    243 #endif
    244 }
    245 
    246 
    247 int
    248 macfb_ioctl(v, cmd, data, flag, p)
    249 	void *v;
    250 	u_long cmd;
    251 	caddr_t data;
    252 	int flag;
    253 	struct proc *p;
    254 {
    255 	struct macfb_softc *sc = v;
    256 	struct macfb_devconfig *dc = sc->sc_dc;
    257 	struct wsdisplay_fbinfo *wdf;
    258 
    259 	switch (cmd) {
    260 	case WSDISPLAYIO_GTYPE:
    261 		*(int *)data = dc->dc_type;
    262 		return 0;
    263 
    264 	case WSDISPLAYIO_GINFO:
    265 		wdf = (struct wsdisplay_fbinfo *)data;
    266 		wdf->height = dc->dc_raster.height;
    267 		wdf->width = dc->dc_raster.width;
    268 		wdf->depth = dc->dc_raster.depth;
    269 		wdf->cmsize = 256;
    270 		return 0;
    271 
    272 	case WSDISPLAYIO_GCURMAX:
    273 	case WSDISPLAYIO_GCURPOS:
    274 	case WSDISPLAYIO_GCURSOR:
    275 	case WSDISPLAYIO_GETCMAP:
    276 	case WSDISPLAYIO_GVIDEO:
    277 	case WSDISPLAYIO_PUTCMAP:
    278 	case WSDISPLAYIO_SCURPOS:
    279 	case WSDISPLAYIO_SCURSOR:
    280 	case WSDISPLAYIO_SVIDEO:
    281 		/* NONE of these operations are supported. */
    282 		return ENOTTY;
    283 
    284 #ifdef WSDISPLAY_COMPAT_ITE
    285 	case ITEIOC_GETBELL:
    286 	case ITEIOC_SETBELL:
    287 	case ITEIOC_RINGBELL:
    288 		/* NONE of these operations are supported. */
    289 		return ENOTTY;
    290 
    291 #endif /* WSDISPLAY_COMPAT_ITE */
    292 	}
    293 
    294 	return -1;
    295 }
    296 
    297 static int
    298 macfb_mmap(v, offset, prot)
    299 	void *v;
    300 	off_t offset;
    301 	int prot;
    302 {
    303 	struct macfb_softc *sc = v;
    304 	struct macfb_devconfig *dc = sc->sc_dc;
    305 	u_long addr;
    306 
    307 	if (offset >= 0 &&
    308 	    offset < m68k_round_page(dc->dc_rowbytes * dc->dc_ht))
    309 		addr = m68k_btop(dc->dc_paddr + dc->dc_offset + offset);
    310 	else
    311 		addr = (-1);	/* XXX bogus */
    312 
    313 	return (int)addr;
    314 }
    315 
    316 int
    317 macfb_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
    318 	void *v;
    319 	const struct wsscreen_descr *type;
    320 	void **cookiep;
    321 	int *curxp, *curyp;
    322 	long *defattrp;
    323 {
    324 	struct macfb_softc *sc = v;
    325 	long defattr;
    326 
    327 	if (sc->nscreens > 0)
    328 		return (ENOMEM);
    329 
    330 	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
    331 	*curxp = 0;
    332 	*curyp = 0;
    333 	rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
    334 	*defattrp = defattr;
    335 	sc->nscreens++;
    336 	return (0);
    337 }
    338 
    339 void
    340 macfb_free_screen(v, cookie)
    341 	void *v;
    342 	void *cookie;
    343 {
    344 	struct macfb_softc *sc = v;
    345 
    346 	if (sc->sc_dc == &macfb_console_dc)
    347 		panic("cfb_free_screen: console");
    348 
    349 	sc->nscreens--;
    350 }
    351 
    352 int
    353 macfb_show_screen(v, cookie, waitok, cb, cbarg)
    354 	void *v;
    355 	void *cookie;
    356 	int waitok;
    357 	void (*cb) __P((void *, int, int));
    358 	void *cbarg;
    359 {
    360 	return 0;
    361 }
    362 
    363 int
    364 macfb_cnattach(addr)
    365 	paddr_t addr;
    366 {
    367 	struct macfb_devconfig *dc = &macfb_console_dc;
    368 	long defattr;
    369 
    370 	dc->dc_vaddr = m68k_trunc_page(videoaddr);
    371 	dc->dc_paddr = m68k_trunc_page(mac68k_vidphys);
    372 
    373 	dc->dc_wid = videosize & 0xffff;
    374 	dc->dc_ht = (videosize >> 16) & 0xffff;
    375 	dc->dc_depth = videobitdepth;
    376 	dc->dc_rowbytes = videorowbytes;
    377 
    378 	dc->dc_size = (mac68k_vidlen > 0) ?
    379 	    mac68k_vidlen : dc->dc_ht * dc->dc_rowbytes;
    380 	dc->dc_offset = m68k_page_offset(mac68k_vidphys);
    381 
    382 	/* set up the display */
    383 	macfb_init(&macfb_console_dc);
    384 
    385 	rcons_alloc_attr(&dc->dc_rcons, 0, 0, 0, &defattr);
    386 
    387 	wsdisplay_cnattach(&macfb_stdscreen, &dc->dc_rcons,
    388 			0, 0, defattr);
    389 
    390 	macfb_consaddr = addr;
    391 	dc->isconsole = 1;
    392 	return (0);
    393 }
    394 
    395 #ifdef WSDISPLAY_COMPAT_ITEFONT
    396 #include <mac68k/dev/6x10.h>
    397 
    398 void
    399 init_itefont()
    400 {
    401 	static int itefont_initted = 0;
    402 	int i, j;
    403 
    404 	extern struct raster_font gallant19;		/* XXX */
    405 
    406 	if (itefont_initted)
    407 		return;
    408 	itefont_initted = 1;
    409 
    410 	/* XXX but we cannot use malloc here... */
    411 	gallant19.width = 6;
    412 	gallant19.height = 10;
    413 	gallant19.ascent = 0;
    414 
    415 	for (i = 32; i < 128; i++) {
    416 		u_int *p;
    417 
    418 		if (gallant19.chars[i].r == NULL)
    419 			continue;
    420 
    421 		gallant19.chars[i].r->width = 6;
    422 		gallant19.chars[i].r->height = 10;
    423 		p = gallant19.chars[i].r->pixels;
    424 
    425 		for (j = 0; j < 10; j++)
    426 			*p++ = Font6x10[i * 10 + j] << 26;
    427 	}
    428 }
    429 #endif /* WSDISPLAY_COMPAT_ITEFONT */
    430