Home | History | Annotate | Line # | Download | only in dev
nextdisplay.c revision 1.1
      1  1.1  dbj /* $NetBSD: nextdisplay.c,v 1.1 1999/01/28 11:46:23 dbj Exp $ */
      2  1.1  dbj /*
      3  1.1  dbj  * Copyright (c) 1998 Matt DeBergalis
      4  1.1  dbj  * All rights reserved.
      5  1.1  dbj  *
      6  1.1  dbj  * Redistribution and use in source and binary forms, with or without
      7  1.1  dbj  * modification, are permitted provided that the following conditions
      8  1.1  dbj  * are met:
      9  1.1  dbj  * 1. Redistributions of source code must retain the above copyright
     10  1.1  dbj  *    notice, this list of conditions and the following disclaimer.
     11  1.1  dbj  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  dbj  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  dbj  *    documentation and/or other materials provided with the distribution.
     14  1.1  dbj  * 3. All advertising materials mentioning features or use of this software
     15  1.1  dbj  *    must display the following acknowledgement:
     16  1.1  dbj  *      This product includes software developed by Matt DeBergalis
     17  1.1  dbj  * 4. The name of the author may not be used to endorse or promote products
     18  1.1  dbj  *    derived from this software without specific prior written permission
     19  1.1  dbj  *
     20  1.1  dbj  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1  dbj  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1  dbj  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1  dbj  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1  dbj  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1  dbj  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1  dbj  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1  dbj  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1  dbj  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1  dbj  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1  dbj  */
     31  1.1  dbj 
     32  1.1  dbj 
     33  1.1  dbj #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     34  1.1  dbj 
     35  1.1  dbj #include <sys/param.h>
     36  1.1  dbj #include <sys/systm.h>
     37  1.1  dbj #include <sys/kernel.h>
     38  1.1  dbj #include <sys/device.h>
     39  1.1  dbj #include <sys/malloc.h>
     40  1.1  dbj 
     41  1.1  dbj #include <machine/cpu.h>
     42  1.1  dbj #include <machine/bus.h>
     43  1.1  dbj 
     44  1.1  dbj #include <next68k/dev/nextdisplayvar.h>
     45  1.1  dbj #include <dev/wscons/wsconsio.h>
     46  1.1  dbj 
     47  1.1  dbj #include <dev/rcons/raster.h>
     48  1.1  dbj #include <dev/wscons/wscons_raster.h>
     49  1.1  dbj #include <dev/wscons/wsdisplayvar.h>
     50  1.1  dbj 
     51  1.1  dbj int nextdisplay_match __P((struct device *, struct cfdata *, void *));
     52  1.1  dbj void nextdisplay_attach __P((struct device *, struct device *, void *));
     53  1.1  dbj 
     54  1.1  dbj struct cfattach nextdisplay_ca = {
     55  1.1  dbj 	sizeof(struct nextdisplay_softc),
     56  1.1  dbj 	nextdisplay_match,
     57  1.1  dbj 	nextdisplay_attach,
     58  1.1  dbj };
     59  1.1  dbj 
     60  1.1  dbj const struct wsdisplay_emulops nextdisplay_mono_emulops = {
     61  1.1  dbj 	rcons_cursor,
     62  1.1  dbj 	rcons_mapchar,
     63  1.1  dbj 	rcons_putchar,
     64  1.1  dbj 	rcons_copycols,
     65  1.1  dbj 	rcons_erasecols,
     66  1.1  dbj 	rcons_copyrows,
     67  1.1  dbj 	rcons_eraserows,
     68  1.1  dbj 	rcons_alloc_attr
     69  1.1  dbj };
     70  1.1  dbj 
     71  1.1  dbj struct wsscreen_descr nextdisplay_mono = {
     72  1.1  dbj 	"std",
     73  1.1  dbj 	0, 0, /* will be filled in -- XXX shouldn't, it's global */
     74  1.1  dbj 	&nextdisplay_mono_emulops,
     75  1.1  dbj 	0, 0
     76  1.1  dbj };
     77  1.1  dbj 
     78  1.1  dbj const struct wsscreen_descr *_nextdisplay_scrlist_mono[] = {
     79  1.1  dbj 	&nextdisplay_mono,
     80  1.1  dbj };
     81  1.1  dbj 
     82  1.1  dbj const struct wsscreen_list nextdisplay_screenlist_mono = {
     83  1.1  dbj 	sizeof(_nextdisplay_scrlist_mono) / sizeof(struct wsscreen_descr *),
     84  1.1  dbj 	_nextdisplay_scrlist_mono
     85  1.1  dbj };
     86  1.1  dbj 
     87  1.1  dbj static int	nextdisplay_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
     88  1.1  dbj static int	nextdisplay_mmap __P((void *, off_t, int));
     89  1.1  dbj static int	nextdisplay_alloc_screen __P((void *, const struct wsscreen_descr *,
     90  1.1  dbj 		void **, int *, int *, long *));
     91  1.1  dbj static void	nextdisplay_free_screen __P((void *, void *));
     92  1.1  dbj static void	nextdisplay_show_screen __P((void *, void *));
     93  1.1  dbj static int	nextdisplay_load_font __P((void *, void *, struct wsdisplay_font *));
     94  1.1  dbj 
     95  1.1  dbj const struct wsdisplay_accessops nextdisplay_accessops = {
     96  1.1  dbj 	nextdisplay_ioctl,
     97  1.1  dbj 	nextdisplay_mmap,
     98  1.1  dbj 	nextdisplay_alloc_screen,
     99  1.1  dbj 	nextdisplay_free_screen,
    100  1.1  dbj 	nextdisplay_show_screen,
    101  1.1  dbj 	nextdisplay_load_font
    102  1.1  dbj };
    103  1.1  dbj 
    104  1.1  dbj void nextdisplay_init(struct nextdisplay_config *, paddr_t);
    105  1.1  dbj 
    106  1.1  dbj paddr_t nextdisplay_consaddr;
    107  1.1  dbj static int nextdisplay_is_console __P((paddr_t addr));
    108  1.1  dbj 
    109  1.1  dbj static struct nextdisplay_config nextdisplay_console_dc;
    110  1.1  dbj 
    111  1.1  dbj static int
    112  1.1  dbj nextdisplay_is_console(paddr_t addr)
    113  1.1  dbj {
    114  1.1  dbj 	return (nextdisplay_console_dc.isconsole
    115  1.1  dbj 			&& (addr == nextdisplay_consaddr));
    116  1.1  dbj }
    117  1.1  dbj 
    118  1.1  dbj int
    119  1.1  dbj nextdisplay_match(parent, match, aux)
    120  1.1  dbj 	struct device *parent;
    121  1.1  dbj 	struct cfdata *match;
    122  1.1  dbj 	void *aux;
    123  1.1  dbj {
    124  1.1  dbj 	return (1);
    125  1.1  dbj }
    126  1.1  dbj 
    127  1.1  dbj void
    128  1.1  dbj nextdisplay_init(dc, addr)
    129  1.1  dbj 	struct nextdisplay_config *dc;
    130  1.1  dbj 	paddr_t addr;
    131  1.1  dbj {
    132  1.1  dbj 	struct raster *rap;
    133  1.1  dbj 	struct rcons *rcp;
    134  1.1  dbj 	int i;
    135  1.1  dbj 
    136  1.1  dbj 	/* printf("in nextdisplay_init\n"); */
    137  1.1  dbj 
    138  1.1  dbj 	dc->dc_vaddr = addr;
    139  1.1  dbj 	dc->dc_paddr = VIDEOP(addr);
    140  1.1  dbj 	dc->dc_size = NEXT_P_VIDEOSIZE;
    141  1.1  dbj 
    142  1.1  dbj 	dc->dc_wid = 1152;
    143  1.1  dbj 	dc->dc_ht = 832;
    144  1.1  dbj 	dc->dc_depth = 2;
    145  1.1  dbj 	dc->dc_rowbytes = dc->dc_wid * dc->dc_depth / 8;
    146  1.1  dbj 
    147  1.1  dbj 	dc->dc_videobase = dc->dc_vaddr;
    148  1.1  dbj 
    149  1.1  dbj #if 0
    150  1.1  dbj 	printf("intiobase at: %08x\n", intiobase);
    151  1.1  dbj 	printf("intiolimit at: %08x\n", intiolimit);
    152  1.1  dbj 	printf("videobase at: %08x\n", videobase);
    153  1.1  dbj 	printf("videolimit at: %08x\n", videolimit);
    154  1.1  dbj 
    155  1.1  dbj 	printf("virtual fb at: %08x\n", dc->dc_vaddr);
    156  1.1  dbj 	printf("physical fb at: %08x\n", dc->dc_paddr);
    157  1.1  dbj 	printf("fb size: %08x\n", dc->dc_size);
    158  1.1  dbj 
    159  1.1  dbj 	printf("dc_wid: %08x\n", dc->dc_wid);
    160  1.1  dbj 	printf("dc_ht: %08x\n", dc->dc_ht);
    161  1.1  dbj 	printf("dc_depth: %08x\n", dc->dc_depth);
    162  1.1  dbj 	printf("dc_rowbytes: %08x\n", dc->dc_rowbytes);
    163  1.1  dbj 	printf("dc_videobase: %08x\n", dc->dc_videobase);
    164  1.1  dbj #endif
    165  1.1  dbj 
    166  1.1  dbj 	/* clear the screen */
    167  1.1  dbj 	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
    168  1.1  dbj 		*(u_int32_t *)(dc->dc_videobase + i) = 0x00000000;
    169  1.1  dbj 
    170  1.1  dbj 	rap = &dc->dc_raster;
    171  1.1  dbj 	rap->width = dc->dc_wid;
    172  1.1  dbj 	rap->height = dc->dc_ht;
    173  1.1  dbj 	rap->depth = 2;
    174  1.1  dbj 	rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
    175  1.1  dbj 	rap->pixels = (u_int32_t *)dc->dc_videobase;
    176  1.1  dbj 
    177  1.1  dbj 	/* initialize the raster console blitter */
    178  1.1  dbj 	rcp = &dc->dc_rcons;
    179  1.1  dbj 	rcp->rc_sp = rap;
    180  1.1  dbj 	rcp->rc_crow = rcp->rc_ccol = -1;
    181  1.1  dbj 	rcp->rc_crowp = &rcp->rc_crow;
    182  1.1  dbj 	rcp->rc_ccolp = &rcp->rc_ccol;
    183  1.1  dbj 	rcons_init(rcp, 34, 80);
    184  1.1  dbj 
    185  1.1  dbj 	nextdisplay_mono.nrows = dc->dc_rcons.rc_maxrow;
    186  1.1  dbj 	nextdisplay_mono.ncols = dc->dc_rcons.rc_maxcol;
    187  1.1  dbj }
    188  1.1  dbj 
    189  1.1  dbj void
    190  1.1  dbj nextdisplay_attach(parent, self, aux)
    191  1.1  dbj 	struct device *parent;
    192  1.1  dbj 	struct device *self;
    193  1.1  dbj 	void *aux;
    194  1.1  dbj {
    195  1.1  dbj 	struct nextdisplay_softc *sc;
    196  1.1  dbj 	struct wsemuldisplaydev_attach_args waa;
    197  1.1  dbj 	int isconsole;
    198  1.1  dbj 
    199  1.1  dbj 	sc = (struct nextdisplay_softc *)self;
    200  1.1  dbj 
    201  1.1  dbj 	printf("\n");
    202  1.1  dbj 
    203  1.1  dbj 	isconsole = nextdisplay_is_console(videobase);
    204  1.1  dbj 
    205  1.1  dbj 	if( isconsole ) {
    206  1.1  dbj 		sc->sc_dc = &nextdisplay_console_dc;
    207  1.1  dbj 		sc->nscreens = 1;
    208  1.1  dbj 	} else {
    209  1.1  dbj 		sc->sc_dc = (struct nextdisplay_config *)
    210  1.1  dbj 				malloc(sizeof(struct nextdisplay_config), M_DEVBUF, M_WAITOK);
    211  1.1  dbj 		nextdisplay_init(sc->sc_dc, videobase);
    212  1.1  dbj 	}
    213  1.1  dbj 
    214  1.1  dbj 	/* initialize the raster */
    215  1.1  dbj 	waa.console = isconsole;
    216  1.1  dbj 	waa.scrdata = &nextdisplay_screenlist_mono;
    217  1.1  dbj 	waa.accessops = &nextdisplay_accessops;
    218  1.1  dbj 	waa.accesscookie = sc;
    219  1.1  dbj 
    220  1.1  dbj 	config_found(self, &waa, wsemuldisplaydevprint);
    221  1.1  dbj }
    222  1.1  dbj 
    223  1.1  dbj 
    224  1.1  dbj int
    225  1.1  dbj nextdisplay_ioctl(v, cmd, data, flag, p)
    226  1.1  dbj 	void *v;
    227  1.1  dbj 	u_long cmd;
    228  1.1  dbj 	caddr_t data;
    229  1.1  dbj 	int flag;
    230  1.1  dbj 	struct proc *p;
    231  1.1  dbj {
    232  1.1  dbj 	struct nextdisplay_softc *sc = v;
    233  1.1  dbj 	struct nextdisplay_config *dc = sc->sc_dc;
    234  1.1  dbj 
    235  1.1  dbj 	switch (cmd) {
    236  1.1  dbj 	case WSDISPLAYIO_GTYPE:
    237  1.1  dbj 		*(int *)data = dc->dc_type;
    238  1.1  dbj 		return 0;
    239  1.1  dbj 
    240  1.1  dbj 	case WSDISPLAYIO_SCURSOR:
    241  1.1  dbj 		printf("nextdisplay_ioctl: wsdisplayio_scursor\n");
    242  1.1  dbj 		return ENOTTY;
    243  1.1  dbj 
    244  1.1  dbj 	case WSDISPLAYIO_SCURPOS:
    245  1.1  dbj 		printf("nextdisplay_ioctl: wsdisplayio_scurpos\n");
    246  1.1  dbj 		return ENOTTY;
    247  1.1  dbj 
    248  1.1  dbj 	case WSDISPLAYIO_GINFO:
    249  1.1  dbj 	case WSDISPLAYIO_GETCMAP:
    250  1.1  dbj 	case WSDISPLAYIO_PUTCMAP:
    251  1.1  dbj 	case WSDISPLAYIO_GVIDEO:
    252  1.1  dbj 	case WSDISPLAYIO_SVIDEO:
    253  1.1  dbj 	case WSDISPLAYIO_GCURPOS:
    254  1.1  dbj 	case WSDISPLAYIO_GCURMAX:
    255  1.1  dbj 	case WSDISPLAYIO_GCURSOR:
    256  1.1  dbj 		printf("nextdisplay_ioctl: listed but unsupported ioctl\n");
    257  1.1  dbj 		return ENOTTY;
    258  1.1  dbj 	}
    259  1.1  dbj 	printf("nextdisplay_ioctl: unsupported ioctl\n");
    260  1.1  dbj 	return -1;
    261  1.1  dbj }
    262  1.1  dbj 
    263  1.1  dbj static int
    264  1.1  dbj nextdisplay_mmap(v, offset, prot)
    265  1.1  dbj 	void *v;
    266  1.1  dbj 	off_t offset;
    267  1.1  dbj 	int prot;
    268  1.1  dbj {
    269  1.1  dbj 
    270  1.1  dbj 	/* XXX */
    271  1.1  dbj 	return -1;
    272  1.1  dbj }
    273  1.1  dbj 
    274  1.1  dbj int
    275  1.1  dbj nextdisplay_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
    276  1.1  dbj 	void *v;
    277  1.1  dbj 	const struct wsscreen_descr *type;
    278  1.1  dbj 	void **cookiep;
    279  1.1  dbj 	int *curxp, *curyp;
    280  1.1  dbj 	long *defattrp;
    281  1.1  dbj {
    282  1.1  dbj 	struct nextdisplay_softc *sc = v;
    283  1.1  dbj 	long defattr;
    284  1.1  dbj 
    285  1.1  dbj 	if (sc->nscreens > 0)
    286  1.1  dbj 		return (ENOMEM);
    287  1.1  dbj 
    288  1.1  dbj 	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
    289  1.1  dbj 	*curxp = 0;
    290  1.1  dbj 	*curyp = 0;
    291  1.1  dbj 	rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
    292  1.1  dbj 	*defattrp = defattr;
    293  1.1  dbj 	sc->nscreens++;
    294  1.1  dbj 	return (0);
    295  1.1  dbj }
    296  1.1  dbj 
    297  1.1  dbj void
    298  1.1  dbj nextdisplay_free_screen(v, cookie)
    299  1.1  dbj 	void *v;
    300  1.1  dbj 	void *cookie;
    301  1.1  dbj {
    302  1.1  dbj 	struct nextdisplay_softc *sc = v;
    303  1.1  dbj 
    304  1.1  dbj 	if (sc->sc_dc == &nextdisplay_console_dc)
    305  1.1  dbj 		panic("cfb_free_screen: console");
    306  1.1  dbj 
    307  1.1  dbj 	sc->nscreens--;
    308  1.1  dbj }
    309  1.1  dbj 
    310  1.1  dbj void
    311  1.1  dbj nextdisplay_show_screen(v, cookie)
    312  1.1  dbj 	void *v;
    313  1.1  dbj 	void *cookie;
    314  1.1  dbj {
    315  1.1  dbj }
    316  1.1  dbj 
    317  1.1  dbj static int
    318  1.1  dbj nextdisplay_load_font(v, cookie, font)
    319  1.1  dbj 	void *v;
    320  1.1  dbj 	void *cookie;
    321  1.1  dbj 	struct wsdisplay_font *font;
    322  1.1  dbj {
    323  1.1  dbj 	return (EINVAL);
    324  1.1  dbj }
    325  1.1  dbj 
    326  1.1  dbj int
    327  1.1  dbj nextdisplay_cnattach(addr)
    328  1.1  dbj 	paddr_t addr;
    329  1.1  dbj {
    330  1.1  dbj 	struct nextdisplay_config *dc = &nextdisplay_console_dc;
    331  1.1  dbj 	long defattr;
    332  1.1  dbj 
    333  1.1  dbj 	/* set up the display */
    334  1.1  dbj 	nextdisplay_init(&nextdisplay_console_dc, addr);
    335  1.1  dbj 
    336  1.1  dbj 	rcons_alloc_attr(&dc->dc_rcons, 0, 0, 0, &defattr);
    337  1.1  dbj 
    338  1.1  dbj 	wsdisplay_cnattach(&nextdisplay_mono, &dc->dc_rcons,
    339  1.1  dbj 			0, 0, defattr);
    340  1.1  dbj 
    341  1.1  dbj 	nextdisplay_consaddr = addr;
    342  1.1  dbj 	dc->isconsole = 1;
    343  1.1  dbj 	return (0);
    344  1.1  dbj }
    345