Home | History | Annotate | Line # | Download | only in vsa
smg.c revision 1.1
      1 /*	$NetBSD: smg.c,v 1.1 1998/06/04 15:51:12 ragge Exp $ */
      2 /*
      3  * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
      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 at Ludd, University of
     17  *      Lule}, Sweden and its contributors.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 
     34 
     35 
     36 #include <sys/types.h>
     37 #include <sys/param.h>
     38 #include <sys/device.h>
     39 #include <sys/systm.h>
     40 #include <sys/time.h>
     41 #include <sys/malloc.h>
     42 #include <sys/conf.h>
     43 
     44 #include <dev/cons.h>
     45 
     46 #include <dev/wscons/wsdisplayvar.h>
     47 #include <dev/wscons/wsconsio.h>
     48 #include <dev/wscons/wscons_callbacks.h>
     49 
     50 #include <machine/vsbus.h>
     51 #include <machine/sid.h>
     52 
     53 #include "lkc.h"
     54 
     55 #define	SM_COLS		128	/* char width of screen */
     56 #define	SM_ROWS		57	/* rows of char on screen */
     57 #define	SM_CHEIGHT	15	/* lines a char consists of */
     58 #define	SM_NEXTROW	(SM_COLS * SM_CHEIGHT)
     59 
     60 static	int smg_match __P((struct device *, struct cfdata *, void *));
     61 static	void smg_attach __P((struct device *, struct device *, void *));
     62 
     63 struct	smg_softc {
     64 	struct	device ss_dev;
     65 };
     66 
     67 struct cfattach smg_ca = {
     68 	sizeof(struct smg_softc), smg_match, smg_attach,
     69 };
     70 
     71 static void	smg_cursor __P((void *, int, int, int));
     72 static void	smg_putstr __P((void *, int, int, char *, int, long));
     73 static void	smg_copycols __P((void *, int, int, int,int));
     74 static void	smg_erasecols __P((void *, int, int, int, long));
     75 static void	smg_copyrows __P((void *, int, int, int));
     76 static void	smg_eraserows __P((void *, int, int, long));
     77 static int	smg_alloc_attr __P((void *, int, int, int, long *));
     78 
     79 const struct wsdisplay_emulops smg_emulops = {
     80 	smg_cursor,
     81 	smg_putstr,
     82 	smg_copycols,
     83 	smg_erasecols,
     84 	smg_copyrows,
     85 	smg_eraserows,
     86 	smg_alloc_attr
     87 };
     88 
     89 const struct wsscreen_descr smg_stdscreen = {
     90         "128x57", 128, 57,
     91         &smg_emulops,
     92         8, 15,
     93         0, /* WSSCREEN_UNDERLINE??? */
     94 };
     95 
     96 const struct wsscreen_descr *_smg_scrlist[] = {
     97 	&smg_stdscreen,
     98 };
     99 
    100 const struct wsscreen_list smg_screenlist = {
    101 	sizeof(_smg_scrlist) / sizeof(struct wsscreen_descr *),
    102 	_smg_scrlist,
    103 };
    104 
    105 static int	smg_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
    106 static int	smg_mmap __P((void *, off_t, int));
    107 static int	smg_alloc_screen __P((void *, const struct wsscreen_descr *,
    108                                       void **, int *, int *, long *));
    109 static void	smg_free_screen __P((void *, void *));
    110 static void	smg_show_screen __P((void *, void *));
    111 static int	smg_load_font __P((void *, void *, int, int, int, void *));
    112 
    113 const struct wsdisplay_accessops smg_accessops = {
    114 	smg_ioctl,
    115 	smg_mmap,
    116 	smg_alloc_screen,
    117 	smg_free_screen,
    118 	smg_show_screen,
    119 	smg_load_font
    120 };
    121 
    122 struct	smg_screen {
    123 	int	ss_curx;
    124 	int	ss_cury;
    125 };
    126 
    127 struct	smg_config {
    128 	struct	smg_screen ss_devs[8]; /* XXX */
    129 };
    130 
    131 int
    132 smg_match(parent, match, aux)
    133 	struct device *parent;
    134 	struct cfdata *match;
    135 	void *aux;
    136 {
    137 	struct  vsbus_attach_args *va = aux;
    138 
    139 	if (va->va_type != INR_VF)
    140 		return 0;
    141 #ifdef DIAGNOSTIC
    142 	if (sm_addr == 0)
    143 		panic("smg: inconsistency in smg address mapping");
    144 #endif
    145 	return 1;
    146 }
    147 
    148 void
    149 smg_attach(parent, self, aux)
    150 	struct device *parent, *self;
    151 	void *aux;
    152 {
    153 	struct wsemuldisplaydev_attach_args aa;
    154 	struct smg_config *sc;
    155 
    156 	printf("\n");
    157         sc = malloc(sizeof(struct smg_config), M_DEVBUF, M_WAITOK);
    158 	aa.console = !(vax_confdata & 0x20);
    159 	aa.scrdata = &smg_screenlist;
    160 	aa.accessops = &smg_accessops;
    161         aa.accesscookie = sc;
    162 
    163 	config_found(self, &aa, wsemuldisplaydevprint);
    164 }
    165 
    166 void
    167 smg_cursor(id, on, row, col)
    168 	void *id;
    169 	int on, row, col;
    170 {
    171 	sm_addr[(row * 15 * 128) + col + (14 * 128)] = on ? 255 : 0;
    172 }
    173 
    174 static void
    175 smg_putstr(id, row, col, cp, len, attr)
    176 	void *id;
    177 	int row, col;
    178 	char *cp;
    179 	int len;
    180 	long attr;
    181 {
    182 	int i, j;
    183 	extern char q_font[];
    184 
    185 	for (i = 0; i < len; i++)
    186 		for (j = 0; j < 15; j++)
    187 			sm_addr[col + i + (row * 15 * 128) + j * 128] =
    188 			    q_font[(cp[i] - 32) * 15 + j];
    189 }
    190 
    191 /*
    192  * copies columns inside a row.
    193  */
    194 static void
    195 smg_copycols(id, row, srccol, dstcol, ncols)
    196 	void *id;
    197 	int row, srccol, dstcol, ncols;
    198 {
    199 	int i;
    200 
    201 	for (i = 0; i < SM_CHEIGHT; i++)
    202 		bcopy(&sm_addr[(row * SM_NEXTROW) + srccol + (i * 128)],
    203 		    &sm_addr[(row * SM_NEXTROW) + dstcol + i*128], ncols);
    204 
    205 }
    206 
    207 /*
    208  * Erases a bunch of chars inside one row.
    209  */
    210 static void
    211 smg_erasecols(id, row, startcol, ncols, fillattr)
    212 	void *id;
    213 	int row, startcol, ncols;
    214 	long fillattr;
    215 {
    216 	int i;
    217 
    218 	for (i = 0; i < SM_CHEIGHT; i++)
    219 		bzero(&sm_addr[(row * SM_NEXTROW) + startcol + i * 128], ncols);
    220 }
    221 
    222 static void
    223 smg_copyrows(id, srcrow, dstrow, nrows)
    224 	void *id;
    225 	int srcrow, dstrow, nrows;
    226 {
    227 	int frows;
    228 
    229 	if (nrows > 25) {
    230 		frows = nrows >> 1;
    231 		if (srcrow > dstrow) {
    232 			bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    233 			    &sm_addr[(dstrow * SM_NEXTROW)],
    234 			    frows * SM_NEXTROW);
    235 			bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
    236 			    &sm_addr[((dstrow + frows) * SM_NEXTROW)],
    237 			    (nrows - frows) * SM_NEXTROW);
    238 		} else {
    239 			bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
    240 			    &sm_addr[((dstrow + frows) * SM_NEXTROW)],
    241 			    (nrows - frows) * SM_NEXTROW);
    242 			bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    243 			    &sm_addr[(dstrow * SM_NEXTROW)],
    244 			    frows * SM_NEXTROW);
    245 		}
    246 	} else
    247 		bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
    248 		    &sm_addr[(dstrow * SM_NEXTROW)], nrows * SM_NEXTROW);
    249 }
    250 
    251 static void
    252 smg_eraserows(id, startrow, nrows, fillattr)
    253 	void *id;
    254 	int startrow, nrows;
    255 	long fillattr;
    256 {
    257 	int frows;
    258 
    259 	if (nrows > 25) {
    260 		frows = nrows >> 1;
    261 		bzero(&sm_addr[(startrow * SM_NEXTROW)], frows * SM_NEXTROW);
    262 		bzero(&sm_addr[((startrow + frows) * SM_NEXTROW)],
    263 		    (nrows - frows) * SM_NEXTROW);
    264 	} else
    265 		bzero(&sm_addr[(startrow * SM_NEXTROW)], nrows * SM_NEXTROW);
    266 }
    267 
    268 static int
    269 smg_alloc_attr(id, fg, bg, flags, attrp)
    270 	void *id;
    271 	int fg, bg;
    272 	int flags;
    273 	long *attrp;
    274 {
    275 	return 0;
    276 }
    277 
    278 int
    279 smg_ioctl(v, cmd, data, flag, p)
    280 	void *v;
    281 	u_long cmd;
    282 	caddr_t data;
    283 	int flag;
    284 	struct proc *p;
    285 {
    286 	return -1;
    287 }
    288 
    289 static int
    290 smg_mmap(v, offset, prot)
    291 	void *v;
    292 	off_t offset;
    293 	int prot;
    294 {
    295 	return -1;
    296 }
    297 
    298 int
    299 smg_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
    300 	void *v;
    301 	const struct wsscreen_descr *type;
    302 	void **cookiep;
    303 	int *curxp, *curyp;
    304 	long *defattrp;
    305 {
    306 	return 0;
    307 }
    308 
    309 void
    310 smg_free_screen(v, cookie)
    311 	void *v;
    312 	void *cookie;
    313 {
    314 }
    315 
    316 void
    317 smg_show_screen(v, cookie)
    318 	void *v;
    319 	void *cookie;
    320 {
    321 }
    322 
    323 static int
    324 smg_load_font(v, cookie, first, num, stride, data)
    325 	void *v;
    326 	void *cookie;
    327 	int first, num, stride;
    328 	void *data;
    329 {
    330 	return 0;
    331 }
    332 
    333 cons_decl(smg);
    334 
    335 #define	WSCONSOLEMAJOR 68
    336 
    337 void
    338 smgcninit(cndev)
    339 	struct  consdev *cndev;
    340 {
    341 	extern void lkccninit __P((struct consdev *));
    342 	extern int lkccngetc __P((dev_t));
    343 	/* Clear screen */
    344 	blkclr(sm_addr, 128*864);
    345 
    346 	wsdisplay_cnattach(&smg_stdscreen, 0, 0, 0, 0);
    347 	cn_tab->cn_dev = makedev(WSCONSOLEMAJOR, 0);
    348 #if NLKC
    349 	lkccninit(cndev);
    350 	wsdisplay_set_cons_kbd(lkccngetc, nullcnpollc);
    351 #endif
    352 }
    353 
    354 int smgprobe(void);
    355 int
    356 smgprobe()
    357 {
    358 	switch (vax_boardtype) {
    359 	case VAX_BTYP_410:
    360 	case VAX_BTYP_420:
    361 	case VAX_BTYP_43:
    362 		if (vax_confdata & 0x20) /* doesn't use graphics console */
    363 			break;
    364 		if (sm_addr == 0) /* Haven't mapped graphic area */
    365 			break;
    366 
    367 		return 1;
    368 
    369 	default:
    370 		break;
    371 	}
    372 	return 0;
    373 }
    374