Home | History | Annotate | Line # | Download | only in dev
nextdisplay.c revision 1.1
      1 /* $NetBSD: nextdisplay.c,v 1.1 1999/01/28 11:46:23 dbj 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 <next68k/dev/nextdisplayvar.h>
     45 #include <dev/wscons/wsconsio.h>
     46 
     47 #include <dev/rcons/raster.h>
     48 #include <dev/wscons/wscons_raster.h>
     49 #include <dev/wscons/wsdisplayvar.h>
     50 
     51 int nextdisplay_match __P((struct device *, struct cfdata *, void *));
     52 void nextdisplay_attach __P((struct device *, struct device *, void *));
     53 
     54 struct cfattach nextdisplay_ca = {
     55 	sizeof(struct nextdisplay_softc),
     56 	nextdisplay_match,
     57 	nextdisplay_attach,
     58 };
     59 
     60 const struct wsdisplay_emulops nextdisplay_mono_emulops = {
     61 	rcons_cursor,
     62 	rcons_mapchar,
     63 	rcons_putchar,
     64 	rcons_copycols,
     65 	rcons_erasecols,
     66 	rcons_copyrows,
     67 	rcons_eraserows,
     68 	rcons_alloc_attr
     69 };
     70 
     71 struct wsscreen_descr nextdisplay_mono = {
     72 	"std",
     73 	0, 0, /* will be filled in -- XXX shouldn't, it's global */
     74 	&nextdisplay_mono_emulops,
     75 	0, 0
     76 };
     77 
     78 const struct wsscreen_descr *_nextdisplay_scrlist_mono[] = {
     79 	&nextdisplay_mono,
     80 };
     81 
     82 const struct wsscreen_list nextdisplay_screenlist_mono = {
     83 	sizeof(_nextdisplay_scrlist_mono) / sizeof(struct wsscreen_descr *),
     84 	_nextdisplay_scrlist_mono
     85 };
     86 
     87 static int	nextdisplay_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
     88 static int	nextdisplay_mmap __P((void *, off_t, int));
     89 static int	nextdisplay_alloc_screen __P((void *, const struct wsscreen_descr *,
     90 		void **, int *, int *, long *));
     91 static void	nextdisplay_free_screen __P((void *, void *));
     92 static void	nextdisplay_show_screen __P((void *, void *));
     93 static int	nextdisplay_load_font __P((void *, void *, struct wsdisplay_font *));
     94 
     95 const struct wsdisplay_accessops nextdisplay_accessops = {
     96 	nextdisplay_ioctl,
     97 	nextdisplay_mmap,
     98 	nextdisplay_alloc_screen,
     99 	nextdisplay_free_screen,
    100 	nextdisplay_show_screen,
    101 	nextdisplay_load_font
    102 };
    103 
    104 void nextdisplay_init(struct nextdisplay_config *, paddr_t);
    105 
    106 paddr_t nextdisplay_consaddr;
    107 static int nextdisplay_is_console __P((paddr_t addr));
    108 
    109 static struct nextdisplay_config nextdisplay_console_dc;
    110 
    111 static int
    112 nextdisplay_is_console(paddr_t addr)
    113 {
    114 	return (nextdisplay_console_dc.isconsole
    115 			&& (addr == nextdisplay_consaddr));
    116 }
    117 
    118 int
    119 nextdisplay_match(parent, match, aux)
    120 	struct device *parent;
    121 	struct cfdata *match;
    122 	void *aux;
    123 {
    124 	return (1);
    125 }
    126 
    127 void
    128 nextdisplay_init(dc, addr)
    129 	struct nextdisplay_config *dc;
    130 	paddr_t addr;
    131 {
    132 	struct raster *rap;
    133 	struct rcons *rcp;
    134 	int i;
    135 
    136 	/* printf("in nextdisplay_init\n"); */
    137 
    138 	dc->dc_vaddr = addr;
    139 	dc->dc_paddr = VIDEOP(addr);
    140 	dc->dc_size = NEXT_P_VIDEOSIZE;
    141 
    142 	dc->dc_wid = 1152;
    143 	dc->dc_ht = 832;
    144 	dc->dc_depth = 2;
    145 	dc->dc_rowbytes = dc->dc_wid * dc->dc_depth / 8;
    146 
    147 	dc->dc_videobase = dc->dc_vaddr;
    148 
    149 #if 0
    150 	printf("intiobase at: %08x\n", intiobase);
    151 	printf("intiolimit at: %08x\n", intiolimit);
    152 	printf("videobase at: %08x\n", videobase);
    153 	printf("videolimit at: %08x\n", videolimit);
    154 
    155 	printf("virtual fb at: %08x\n", dc->dc_vaddr);
    156 	printf("physical fb at: %08x\n", dc->dc_paddr);
    157 	printf("fb size: %08x\n", dc->dc_size);
    158 
    159 	printf("dc_wid: %08x\n", dc->dc_wid);
    160 	printf("dc_ht: %08x\n", dc->dc_ht);
    161 	printf("dc_depth: %08x\n", dc->dc_depth);
    162 	printf("dc_rowbytes: %08x\n", dc->dc_rowbytes);
    163 	printf("dc_videobase: %08x\n", dc->dc_videobase);
    164 #endif
    165 
    166 	/* clear the screen */
    167 	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
    168 		*(u_int32_t *)(dc->dc_videobase + i) = 0x00000000;
    169 
    170 	rap = &dc->dc_raster;
    171 	rap->width = dc->dc_wid;
    172 	rap->height = dc->dc_ht;
    173 	rap->depth = 2;
    174 	rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
    175 	rap->pixels = (u_int32_t *)dc->dc_videobase;
    176 
    177 	/* initialize the raster console blitter */
    178 	rcp = &dc->dc_rcons;
    179 	rcp->rc_sp = rap;
    180 	rcp->rc_crow = rcp->rc_ccol = -1;
    181 	rcp->rc_crowp = &rcp->rc_crow;
    182 	rcp->rc_ccolp = &rcp->rc_ccol;
    183 	rcons_init(rcp, 34, 80);
    184 
    185 	nextdisplay_mono.nrows = dc->dc_rcons.rc_maxrow;
    186 	nextdisplay_mono.ncols = dc->dc_rcons.rc_maxcol;
    187 }
    188 
    189 void
    190 nextdisplay_attach(parent, self, aux)
    191 	struct device *parent;
    192 	struct device *self;
    193 	void *aux;
    194 {
    195 	struct nextdisplay_softc *sc;
    196 	struct wsemuldisplaydev_attach_args waa;
    197 	int isconsole;
    198 
    199 	sc = (struct nextdisplay_softc *)self;
    200 
    201 	printf("\n");
    202 
    203 	isconsole = nextdisplay_is_console(videobase);
    204 
    205 	if( isconsole ) {
    206 		sc->sc_dc = &nextdisplay_console_dc;
    207 		sc->nscreens = 1;
    208 	} else {
    209 		sc->sc_dc = (struct nextdisplay_config *)
    210 				malloc(sizeof(struct nextdisplay_config), M_DEVBUF, M_WAITOK);
    211 		nextdisplay_init(sc->sc_dc, videobase);
    212 	}
    213 
    214 	/* initialize the raster */
    215 	waa.console = isconsole;
    216 	waa.scrdata = &nextdisplay_screenlist_mono;
    217 	waa.accessops = &nextdisplay_accessops;
    218 	waa.accesscookie = sc;
    219 
    220 	config_found(self, &waa, wsemuldisplaydevprint);
    221 }
    222 
    223 
    224 int
    225 nextdisplay_ioctl(v, cmd, data, flag, p)
    226 	void *v;
    227 	u_long cmd;
    228 	caddr_t data;
    229 	int flag;
    230 	struct proc *p;
    231 {
    232 	struct nextdisplay_softc *sc = v;
    233 	struct nextdisplay_config *dc = sc->sc_dc;
    234 
    235 	switch (cmd) {
    236 	case WSDISPLAYIO_GTYPE:
    237 		*(int *)data = dc->dc_type;
    238 		return 0;
    239 
    240 	case WSDISPLAYIO_SCURSOR:
    241 		printf("nextdisplay_ioctl: wsdisplayio_scursor\n");
    242 		return ENOTTY;
    243 
    244 	case WSDISPLAYIO_SCURPOS:
    245 		printf("nextdisplay_ioctl: wsdisplayio_scurpos\n");
    246 		return ENOTTY;
    247 
    248 	case WSDISPLAYIO_GINFO:
    249 	case WSDISPLAYIO_GETCMAP:
    250 	case WSDISPLAYIO_PUTCMAP:
    251 	case WSDISPLAYIO_GVIDEO:
    252 	case WSDISPLAYIO_SVIDEO:
    253 	case WSDISPLAYIO_GCURPOS:
    254 	case WSDISPLAYIO_GCURMAX:
    255 	case WSDISPLAYIO_GCURSOR:
    256 		printf("nextdisplay_ioctl: listed but unsupported ioctl\n");
    257 		return ENOTTY;
    258 	}
    259 	printf("nextdisplay_ioctl: unsupported ioctl\n");
    260 	return -1;
    261 }
    262 
    263 static int
    264 nextdisplay_mmap(v, offset, prot)
    265 	void *v;
    266 	off_t offset;
    267 	int prot;
    268 {
    269 
    270 	/* XXX */
    271 	return -1;
    272 }
    273 
    274 int
    275 nextdisplay_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
    276 	void *v;
    277 	const struct wsscreen_descr *type;
    278 	void **cookiep;
    279 	int *curxp, *curyp;
    280 	long *defattrp;
    281 {
    282 	struct nextdisplay_softc *sc = v;
    283 	long defattr;
    284 
    285 	if (sc->nscreens > 0)
    286 		return (ENOMEM);
    287 
    288 	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
    289 	*curxp = 0;
    290 	*curyp = 0;
    291 	rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
    292 	*defattrp = defattr;
    293 	sc->nscreens++;
    294 	return (0);
    295 }
    296 
    297 void
    298 nextdisplay_free_screen(v, cookie)
    299 	void *v;
    300 	void *cookie;
    301 {
    302 	struct nextdisplay_softc *sc = v;
    303 
    304 	if (sc->sc_dc == &nextdisplay_console_dc)
    305 		panic("cfb_free_screen: console");
    306 
    307 	sc->nscreens--;
    308 }
    309 
    310 void
    311 nextdisplay_show_screen(v, cookie)
    312 	void *v;
    313 	void *cookie;
    314 {
    315 }
    316 
    317 static int
    318 nextdisplay_load_font(v, cookie, font)
    319 	void *v;
    320 	void *cookie;
    321 	struct wsdisplay_font *font;
    322 {
    323 	return (EINVAL);
    324 }
    325 
    326 int
    327 nextdisplay_cnattach(addr)
    328 	paddr_t addr;
    329 {
    330 	struct nextdisplay_config *dc = &nextdisplay_console_dc;
    331 	long defattr;
    332 
    333 	/* set up the display */
    334 	nextdisplay_init(&nextdisplay_console_dc, addr);
    335 
    336 	rcons_alloc_attr(&dc->dc_rcons, 0, 0, 0, &defattr);
    337 
    338 	wsdisplay_cnattach(&nextdisplay_mono, &dc->dc_rcons,
    339 			0, 0, defattr);
    340 
    341 	nextdisplay_consaddr = addr;
    342 	dc->isconsole = 1;
    343 	return (0);
    344 }
    345