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