Home | History | Annotate | Line # | Download | only in dev
macfb.c revision 1.1.2.1
      1 /* $NetBSD: macfb.c,v 1.1.2.1 1999/03/08 02:06:13 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 
     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 <machine/grfioctl.h>
     45 #include <mac68k/nubus/nubus.h>
     46 #include <mac68k/dev/grfvar.h>
     47 #include <mac68k/dev/macfbvar.h>
     48 #include <dev/wscons/wsconsio.h>
     49 
     50 #include <dev/rcons/raster.h>
     51 #include <dev/wscons/wscons_raster.h>
     52 #include <dev/wscons/wsdisplayvar.h>
     53 
     54 int macfb_match __P((struct device *, struct cfdata *, void *));
     55 void macfb_attach __P((struct device *, struct device *, void *));
     56 
     57 struct cfattach macfb_ca = {
     58 	sizeof(struct macfb_softc),
     59 	macfb_match,
     60 	macfb_attach,
     61 };
     62 
     63 const struct wsdisplay_emulops macfb_emulops = {
     64 	rcons_cursor,
     65 	rcons_mapchar,
     66 	rcons_putchar,
     67 	rcons_copycols,
     68 	rcons_erasecols,
     69 	rcons_copyrows,
     70 	rcons_eraserows,
     71 	rcons_alloc_attr
     72 };
     73 
     74 struct wsscreen_descr macfb_stdscreen = {
     75 	"std",
     76 	0, 0, /* will be filled in -- XXX shouldn't, it's global */
     77 	&macfb_emulops,
     78 	0, 0,
     79 	WSSCREEN_REVERSE
     80 };
     81 
     82 const struct wsscreen_descr *_macfb_scrlist[] = {
     83 	&macfb_stdscreen,
     84 };
     85 
     86 const struct wsscreen_list macfb_screenlist = {
     87 	sizeof(_macfb_scrlist) / sizeof(struct wsscreen_descr *),
     88 	_macfb_scrlist
     89 };
     90 
     91 static int	macfb_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
     92 static int	macfb_mmap __P((void *, off_t, int));
     93 static int	macfb_alloc_screen __P((void *, const struct wsscreen_descr *,
     94 		void **, int *, int *, long *));
     95 static void	macfb_free_screen __P((void *, void *));
     96 static void	macfb_show_screen __P((void *, void *));
     97 
     98 const struct wsdisplay_accessops macfb_accessops = {
     99 	macfb_ioctl,
    100 	macfb_mmap,
    101 	macfb_alloc_screen,
    102 	macfb_free_screen,
    103 	macfb_show_screen,
    104 	0 /* load_font */
    105 };
    106 
    107 void macfb_init __P((struct macfb_devconfig *));
    108 
    109 paddr_t macfb_consaddr;
    110 static int macfb_is_console __P((paddr_t addr));
    111 static void	init_font __P((void));
    112 
    113 static struct macfb_devconfig macfb_console_dc;
    114 
    115 /* From Booter via locore */
    116 extern long		videoaddr;
    117 extern long		videorowbytes;
    118 extern long		videobitdepth;
    119 extern u_long		videosize;
    120 extern u_int32_t	mac68k_vidlog;
    121 extern u_int32_t	mac68k_vidphys;
    122 extern u_int32_t	mac68k_vidlen;
    123 
    124 static int
    125 macfb_is_console(paddr_t addr)
    126 {
    127 	return ((mac68k_machine.serial_console & 0x03) == 0
    128 	    && (addr == macfb_consaddr));
    129 }
    130 
    131 void
    132 macfb_init(dc)
    133 	struct macfb_devconfig *dc;
    134 {
    135 	struct raster *rap;
    136 	struct rcons *rcp;
    137 	int i;
    138 
    139 	/* clear the screen */
    140 	for (i = 0; i < (dc->dc_ht * dc->dc_rowbytes); i += dc->dc_rowbytes)
    141 		bzero((u_char *)dc->dc_videobase + i, dc->dc_rowbytes);
    142 
    143 	init_font();
    144 
    145 	rap = &dc->dc_raster;
    146 	rap->width = dc->dc_wid;
    147 	rap->height = dc->dc_ht;
    148 	rap->depth = dc->dc_depth;
    149 	rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
    150 	rap->pixels = (u_int32_t *)dc->dc_videobase;
    151 
    152 	/* initialize the raster console blitter */
    153 	rcp = &dc->dc_rcons;
    154 	rcp->rc_sp = rap;
    155 	rcp->rc_crow = rcp->rc_ccol = -1;
    156 	rcp->rc_crowp = &rcp->rc_crow;
    157 	rcp->rc_ccolp = &rcp->rc_ccol;
    158 	rcons_init(rcp, 128, 128);
    159 
    160 	macfb_stdscreen.nrows = dc->dc_rcons.rc_maxrow;
    161 	macfb_stdscreen.ncols = dc->dc_rcons.rc_maxcol;
    162 }
    163 
    164 int
    165 macfb_match(parent, match, aux)
    166 	struct device *parent;
    167 	struct cfdata *match;
    168 	void *aux;
    169 {
    170 	return (1);
    171 }
    172 
    173 void
    174 macfb_attach(parent, self, aux)
    175 	struct device *parent;
    176 	struct device *self;
    177 	void *aux;
    178 {
    179 	struct grfbus_attach_args *ga = aux;
    180 	struct grfmode *gm = ga->ga_grfmode;
    181 	struct macfb_softc *sc;
    182 	struct wsemuldisplaydev_attach_args waa;
    183 	int isconsole;
    184 
    185 	sc = (struct macfb_softc *)self;
    186 
    187 	printf("\n");
    188 
    189 	isconsole = macfb_is_console(ga->ga_phys);
    190 
    191 	if (isconsole) {
    192 		sc->sc_dc = &macfb_console_dc;
    193 		sc->nscreens = 1;
    194 	} else {
    195 		sc->sc_dc = (struct macfb_devconfig *)
    196 		    malloc(sizeof(struct macfb_devconfig), M_DEVBUF, M_WAITOK);
    197 		sc->sc_dc->dc_vaddr = (vaddr_t)gm->fbbase;
    198 		sc->sc_dc->dc_paddr = ga->ga_phys;
    199 		sc->sc_dc->dc_size = gm->fbsize;
    200 
    201 		sc->sc_dc->dc_wid = gm->width;
    202 		sc->sc_dc->dc_ht = gm->height;
    203 		sc->sc_dc->dc_depth = gm->psize;
    204 		sc->sc_dc->dc_rowbytes = gm->rowbytes;
    205 
    206 		sc->sc_dc->dc_videobase = (u_int32_t)gm->fbbase + gm->fboff;
    207 
    208 		macfb_init(sc->sc_dc);
    209 	}
    210 
    211 	/* initialize the raster */
    212 	waa.console = isconsole;
    213 	waa.scrdata = &macfb_screenlist;
    214 	waa.accessops = &macfb_accessops;
    215 	waa.accesscookie = sc;
    216 
    217 	config_found(self, &waa, wsemuldisplaydevprint);
    218 }
    219 
    220 
    221 int
    222 macfb_ioctl(v, cmd, data, flag, p)
    223 	void *v;
    224 	u_long cmd;
    225 	caddr_t data;
    226 	int flag;
    227 	struct proc *p;
    228 {
    229 	struct macfb_softc *sc = v;
    230 	struct macfb_devconfig *dc = sc->sc_dc;
    231 	struct wsdisplay_fbinfo *wdf;
    232 
    233 	switch (cmd) {
    234 	case WSDISPLAYIO_GTYPE:
    235 		*(int *)data = dc->dc_type;
    236 		return 0;
    237 
    238 	case WSDISPLAYIO_GINFO:
    239 		wdf = (void *)data;
    240 		wdf->height = sc->sc_dc->dc_raster.height;
    241 		wdf->width = sc->sc_dc->dc_raster.width;
    242 		wdf->depth = sc->sc_dc->dc_raster.depth;
    243 		wdf->cmsize = 256;
    244 		return 0;
    245 
    246 	case WSDISPLAYIO_GCURMAX:
    247 	case WSDISPLAYIO_GCURPOS:
    248 	case WSDISPLAYIO_GCURSOR:
    249 	case WSDISPLAYIO_GETCMAP:
    250 	case WSDISPLAYIO_GVIDEO:
    251 	case WSDISPLAYIO_PUTCMAP:
    252 	case WSDISPLAYIO_SCURPOS:
    253 	case WSDISPLAYIO_SCURSOR:
    254 	case WSDISPLAYIO_SVIDEO:
    255 		/* NONE of these operations are supported. */
    256 		return ENOTTY;
    257 	}
    258 
    259 	return -1;
    260 }
    261 
    262 static int
    263 macfb_mmap(v, offset, prot)
    264 	void *v;
    265 	off_t offset;
    266 	int prot;
    267 {
    268 
    269 	/* XXX */
    270 	return -1;
    271 }
    272 
    273 int
    274 macfb_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
    275 	void *v;
    276 	const struct wsscreen_descr *type;
    277 	void **cookiep;
    278 	int *curxp, *curyp;
    279 	long *defattrp;
    280 {
    281 	struct macfb_softc *sc = v;
    282 	long defattr;
    283 
    284 	if (sc->nscreens > 0)
    285 		return (ENOMEM);
    286 
    287 	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
    288 	*curxp = 0;
    289 	*curyp = 0;
    290 	rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
    291 	*defattrp = defattr;
    292 	sc->nscreens++;
    293 	return (0);
    294 }
    295 
    296 void
    297 macfb_free_screen(v, cookie)
    298 	void *v;
    299 	void *cookie;
    300 {
    301 	struct macfb_softc *sc = v;
    302 
    303 	if (sc->sc_dc == &macfb_console_dc)
    304 		panic("cfb_free_screen: console");
    305 
    306 	sc->nscreens--;
    307 }
    308 
    309 void
    310 macfb_show_screen(v, cookie)
    311 	void *v;
    312 	void *cookie;
    313 {
    314 }
    315 
    316 int
    317 macfb_cnattach(addr)
    318 	paddr_t addr;
    319 {
    320 	struct macfb_devconfig *dc = &macfb_console_dc;
    321 	long defattr;
    322 
    323 	dc->dc_vaddr = videoaddr;
    324 	dc->dc_paddr = mac68k_vidphys;
    325 	dc->dc_size = mac68k_vidlen;
    326 
    327 	dc->dc_wid = videosize & 0xffff;
    328 	dc->dc_ht = (videosize >> 16) & 0xffff;
    329 	dc->dc_depth = videobitdepth;
    330 	dc->dc_rowbytes = videorowbytes;
    331 
    332 	dc->dc_videobase = videoaddr;
    333 
    334 	/* set up the display */
    335 	macfb_init(&macfb_console_dc);
    336 
    337 	rcons_alloc_attr(&dc->dc_rcons, 0, 0, 0, &defattr);
    338 
    339 	wsdisplay_cnattach(&macfb_stdscreen, &dc->dc_rcons,
    340 			0, 0, defattr);
    341 
    342 	macfb_consaddr = addr;
    343 	dc->isconsole = 1;
    344 	return (0);
    345 }
    346 
    347 
    348 #include <mac68k/dev/6x10.h>
    349 
    350 void
    351 init_font()
    352 {
    353 	int i, j;
    354 
    355 	extern struct raster_font gallant19;		/* XXX */
    356 
    357 	/* XXX but we cannot use malloc here... */
    358 	gallant19.width = 6;
    359 	gallant19.height = 10;
    360 	gallant19.ascent = 0;
    361 
    362 	for (i = 32; i < 128; i++) {
    363 		u_int *p;
    364 
    365 		if (gallant19.chars[i].r == NULL)
    366 			continue;
    367 
    368 		gallant19.chars[i].r->width = 6;
    369 		gallant19.chars[i].r->height = 10;
    370 		p = gallant19.chars[i].r->pixels;
    371 
    372 		for (j = 0; j < 10; j++)
    373 			*p++ = Font6x10[i * 10 + j] << 26;
    374 	}
    375 }
    376