qv.c revision 1.31 1 /*$Header: /tank/opengrok/rsync2/NetBSD/src/sys/arch/vax/uba/qv.c,v 1.31 2015/07/05 03:07:21 matt Exp $*/
2 /*
3 * Copyright (c) 2015 Charles H. Dickman. All rights reserved.
4 * Derived from smg.c
5 * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed at Ludd, University of
19 * Lule}, Sweden and its contributors.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34 /* 1 2 3 4 5 6 7 */
35 /*3456789012345678901234567890123456789012345678901234567890123456789012345678*/
36
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$Header: /tank/opengrok/rsync2/NetBSD/src/sys/arch/vax/uba/qv.c,v 1.31 2015/07/05 03:07:21 matt Exp $");
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/callout.h>
43 #include <sys/conf.h>
44 #include <sys/cpu.h>
45 #include <sys/device.h>
46 #include <sys/kernel.h>
47 #include <sys/malloc.h>
48 #include <sys/extent.h> /***/
49 #include <sys/time.h>
50 #include <sys/bus.h>
51 #include <vax/include/pte.h> /* temporary */
52 #include <machine/sid.h>
53 #include <dev/cons.h>
54 #include <dev/qbus/ubavar.h>
55 #include <dev/wscons/wsdisplayvar.h>
56 #include <dev/wscons/wsconsio.h>
57 #include <dev/wscons/wscons_callbacks.h>
58 #include <dev/wsfont/wsfont.h>
59 #include <dev/wsfb/genfbvar.h>
60 #include <vax/include/sgmap.h> /***/
61
62 #include "uba_common.h" /***/
63 #include "qv.h"
64 #include "qv_ic.h"
65 #include "qvaux.h"
66 #include "opt_wsfont.h"
67
68 #define QMEMBASE 0x30000000
69 #define QVSIZE 0x40000
70 #define QV_SCANMAP 0x3F800
71 #define QV_CURSRAM 0x3FFE0
72
73 #define QV_CSR 0
74 #define QV_CSR_1 (1 << 2)
75 #define QV_CSR_2 (1 << 3)
76 #define QV_CSR_BANK (15 << 11)
77 #define QV_CUR_X 2
78 #define QV_CRTC_AR 8
79 #define QV_CRTC_DR 10
80 #define QV_IC 12
81 #define QV_ICDR QV_ICDR
82 #define QV_ICSR (QV_ICDR + 2)
83
84 /* Screen hardware defs */
85 #define QV_COLS 128 /* char width of screen */
86 #define QV_ROWS 57 /* rows of char on screen */
87 #define QV_CHEIGHT 15 /* lines a char consists of */
88 #define QV_NEXTROW (QV_COLS * QV_CHEIGHT)
89 #define QV_YWIDTH 864
90 #define QV_XWIDTH 1024
91
92 /* hardware cursor */
93 #define CUR_BLINKN 0x00
94 #define CUR_BLANK 0x20
95 #define CUR_BLINKS 0x40
96 #define CUR_BLINKF 0x60
97 #define CUR_BLINKM 0x60
98 #define CUR_OFF CUR_BLANK
99 #define CUR_ON CUR_BLINKS
100 #define CUR_START 10
101 #define CUR_END 11
102 #define CUR_HI 14
103 #define CUR_LO 15
104
105 //static uint16_t curcmd, curx, cury, hotX, hotY;
106 static int bgmask, fgmask;
107
108 static int qv_match(device_t, cfdata_t, void *);
109 static void qv_attach(device_t, device_t, void *);
110
111 static void qv_cursor(void *, int, int, int);
112 static int qv_mapchar(void *, int, unsigned int *);
113 static void qv_putchar(void *, int, int, u_int, long);
114 static void qv_copycols(void *, int, int, int,int);
115 static void qv_erasecols(void *, int, int, int, long);
116 static void qv_copyrows(void *, int, int, int);
117 static void qv_eraserows(void *, int, int, long);
118 static int qv_allocattr(void *, int, int, int, long *);
119
120 const struct wsdisplay_emulops qv_emulops = {
121 .cursor = qv_cursor,
122 .mapchar = qv_mapchar,
123 .putchar = qv_putchar,
124 .copycols = qv_copycols,
125 .erasecols = qv_erasecols,
126 .copyrows = qv_copyrows,
127 .eraserows = qv_eraserows,
128 .allocattr = qv_allocattr
129 };
130
131 struct _wsscreen_descr {
132 const struct wsscreen_descr qv_stdscreen; /* MUST BE FIRST */
133 const uint16_t qv_crtc_param[16];
134 };
135
136 /*
137 * Notes from the original Ultrix drivers
138 *
139 * Screen controller initialization parameters. The definations [sic] and use
140 * of these parameters can be found in the Motorola 68045 [sic] crtc specs. In
141 * essence they set the display parameters for the chip. The first set is
142 * for the 15" screen and the second is for the 19" separate sync. There
143 * is also a third set for a 19" composite sync monitor which we have not
144 * tested and which is not supported.
145 */
146
147 const struct _wsscreen_descr qv_stdscreen[] = {
148 { { "80x30", 80, 30, &qv_emulops, 8,
149 QV_CHEIGHT, WSSCREEN_UNDERLINE|WSSCREEN_REVERSE },
150 { 31, 25, 27, 0142, 31, 13, 30, 31, 4, 15, 040, 0, 0, 0, 0, 0 } },
151 { { "120x55", 120, 55, &qv_emulops, 8,
152 QV_CHEIGHT, WSSCREEN_UNDERLINE|WSSCREEN_REVERSE },
153 { 39, 30, 32, 0262, 55, 5, 54, 54, 4, 15, 040, 0, 0, 0, 0, 0 } },
154 { { "128x57", QV_COLS, QV_ROWS, &qv_emulops, 8,
155 QV_CHEIGHT, WSSCREEN_UNDERLINE|WSSCREEN_REVERSE },
156 { 39, 32, 33, 0264, 56, 5, 54, 54, 4, 15, 040, 0, 0, 0, 0, 0 } },
157 };
158
159 const struct wsscreen_descr *_qv_scrlist[] = {
160 &qv_stdscreen[2].qv_stdscreen, /* default */
161 &qv_stdscreen[1].qv_stdscreen,
162 &qv_stdscreen[0].qv_stdscreen,
163 };
164
165 const struct wsscreen_list qv_screenlist = {
166 .nscreens = __arraycount(_qv_scrlist),
167 .screens = _qv_scrlist,
168 };
169
170 struct qv_softc {
171 device_t sc_dev; /* device pointer */
172 bus_space_tag_t sc_iot; /* register base */
173 bus_space_handle_t sc_ioh;
174 bus_space_tag_t sc_fbt; /* frame buffer base */
175 bus_space_handle_t sc_fbh;
176 paddr_t sc_fbphys; /* frame buffer phys addr */
177 char *sc_fb; /* frame buffer virt addr */
178 uint16_t *sc_scanmap; /* scan map virt addr */
179 char *sc_font; /* font glyph table */
180
181 uint8_t sc_curon; /* cursor on */
182 uint16_t sc_curx; /* cursor x position */
183 uint16_t sc_cury; /* cursor y position */
184 uint16_t sc_curhotX; /* cursor x hot spot */
185 uint16_t sc_curhotY; /* cursor y hot spot */
186
187 struct qv_screen *sc_curscr; /* current screen */
188 };
189
190 #if 0
191 struct genfb_qv_softc {
192 struct genfb_softc sc_gen;
193 bus_space_tag_t sc_iot;
194 bus_space_handle_t sc_ioh;
195 uint32_t sc_wstype;
196 };
197 #endif
198
199 static void qv_crtc_wr(struct qv_softc *, uint16_t, uint16_t);
200 static void qv_setcrtc(struct qv_softc *, const uint16_t *);
201
202 static int qv_ioctl(void *, void *, u_long, void *, int, struct lwp *);
203 static paddr_t qv_mmap(void *, void *, off_t, int);
204 static int qv_alloc_screen(void *, const struct wsscreen_descr *,
205 void **, int *, int *, long *);
206 static void qv_free_screen(void *, void *);
207 static int qv_show_screen(void *, void *, int,
208 void (*) (void *, int, int), void *);
209 //static void qv_crsr_blink(void *);
210
211 int qvauxprint(void *, const char *);
212
213 const struct wsdisplay_accessops qv_accessops = {
214 .ioctl = qv_ioctl,
215 .mmap = qv_mmap,
216 .alloc_screen = qv_alloc_screen,
217 .free_screen = qv_free_screen,
218 .show_screen = qv_show_screen,
219 };
220
221 struct qv_screen {
222 struct qv_softc *ss_sc;
223 const struct wsscreen_descr *ss_type;
224 int ss_curx;
225 int ss_cury;
226 u_char ss_image[QV_ROWS][QV_COLS]; /* Image of screen */
227 u_char ss_attr[QV_ROWS][QV_COLS]; /* Reversed etc... */
228 };
229
230 static struct qv_screen qv_conscreen; /* XXX no console support */
231
232 static callout_t qv_cursor_ch;
233
234 CFATTACH_DECL_NEW(qv, sizeof(struct qv_softc),
235 qv_match, qv_attach, NULL, NULL);
236 #if 0
237 static int genfb_match_qv(device_t, cfdata_t, void *);
238 static void genfb_attach_qv(device_t, device_t, void *);
239 static int genfb_ioctl_qv(void *, void *, u_long, void *, int, struct lwp*);
240 static paddr_t genfb_mmap_qv(void *, void *, off_t, int);
241 static int genfb_borrow_qv(void *, bus_addr_t, bus_space_handle_t *);
242
243 CFATTACH_DECL_NEW(genfb_qv, sizeof(struct genfb_qv_softc),
244 genfb_match_qv, genfb_attach_qv, NULL, NULL);
245 #endif
246
247 /*
248 * autoconf match function
249 */
250 int
251 qv_match(device_t parent, cfdata_t match, void *aux)
252 {
253 struct uba_attach_args *ua = aux;
254 struct uba_softc *uh = device_private(parent);
255
256 /* set up interrupts so the vector can be detected */
257
258 /* initialize qv interrupt controller */
259 qv_ic_init(ua, QV_IC);
260
261 /* set vertical retrace interrupt */
262 qv_ic_setvec(ua, QV_IC, QV_SYNC_VEC, uh->uh_lastiv - 4);
263 qv_ic_enable(ua, QV_IC, QV_SYNC_VEC, QV_IC_ENA);
264 qv_ic_arm(ua, QV_IC, QV_SYNC_VEC);
265
266 /* enable interrupts */
267 bus_space_write_2(ua->ua_iot, ua->ua_ioh, QV_CSR,
268 bus_space_read_2(ua->ua_iot, ua->ua_ioh, QV_CSR) | (1 << 6));
269
270 qv_ic_force(ua, QV_IC, QV_SYNC_VEC);
271
272 DELAY(20000);
273
274 /* disable interrupts */
275 qv_ic_enable(ua, QV_IC, QV_SYNC_VEC, QV_IC_DIS);
276
277 return 1;
278 }
279
280 /* controller register write helper function */
281 static inline void
282 qv_reg_wr(struct qv_softc *sc, uint16_t addr, uint16_t data)
283 {
284 bus_space_write_2(sc->sc_iot, sc->sc_ioh, addr, data);
285 }
286
287 /* controller register read helper function */
288 static inline uint16_t
289 qv_reg_rd(struct qv_softc *sc, uint16_t addr)
290 {
291 return bus_space_read_2(sc->sc_iot, sc->sc_ioh, addr);
292 }
293
294 /*
295 * write a 6845 CRT controller register
296 */
297 static void
298 qv_crtc_wr(struct qv_softc *sc, uint16_t addr, uint16_t data)
299 {
300 qv_reg_wr(sc, QV_CRTC_AR, addr);
301 qv_reg_wr(sc, QV_CRTC_DR, data);
302 }
303
304 /*
305 * write a set of a set of video timing parameters to the CRTC
306 */
307 static void
308 qv_setcrtc(struct qv_softc *sc, const uint16_t *pp)
309 {
310 int i;
311
312 for (i = 0; i < 14; i++)
313 qv_crtc_wr(sc, i, pp[i]);
314 }
315
316 static void inline
317 qv_ic_write(struct uba_attach_args *ua, bus_size_t offs, uint16_t value)
318 {
319 bus_space_write_2(ua->ua_iot, ua->ua_ioh, offs, value);
320 }
321
322 void
323 qv_ic_init(struct uba_attach_args *ua, bus_size_t offs)
324 {
325 static int initted;
326 int i;
327
328 if (!initted) {
329 /* init the interrupt controller */
330 qv_ic_write(ua, QV_IC_SR + offs, QV_IC_RESET);
331 /* reset irr */
332 qv_ic_write(ua, QV_IC_SR + offs, QV_IC_CLRIRR);
333 /* specify individual vectors */
334 qv_ic_write(ua, QV_IC_SR + offs, QV_IC_MODE);
335 /* preset autoclear data */
336 qv_ic_write(ua, QV_IC_SR + offs, QV_IC_ACREG);
337 /* all setup as autoclear */
338 qv_ic_write(ua, QV_IC_DR + offs, 0xff);
339
340 /* clear all vector addresses */
341 for (i = 0; i < 8; i++)
342 qv_ic_setvec(ua, offs, i, 0);
343
344 initted = 1;
345 }
346 }
347
348 void
349 qv_ic_setvec(struct uba_attach_args *ua, bus_size_t offs, int ic_vec, int vecnum)
350 {
351 /* preset vector address */
352 qv_ic_write(ua, QV_IC_SR + offs, QV_IC_RMEM | RMEM_BC_1 | ic_vec);
353 /* give it the vector number */
354 qv_ic_write(ua, QV_IC_DR + offs, vecnum);
355 }
356
357 void
358 qv_ic_enable(struct uba_attach_args *ua, bus_size_t offs, int ic_vec, int enable)
359 {
360 if (enable)
361 /* enable the interrupt */
362 qv_ic_write(ua, QV_IC_SR + offs, QV_IC_CIMR | ic_vec);
363 else
364 /* disable the interrupt */
365 qv_ic_write(ua, QV_IC_SR + offs, QV_IC_SIMR | ic_vec);
366 }
367
368 void
369 qv_ic_arm(struct uba_attach_args *ua, bus_size_t offs, int arm)
370 {
371 if (arm)
372 /* arm the interrupt ctrl */
373 qv_ic_write(ua, QV_IC_SR + offs, QV_IC_ARM);
374 else
375 /* disarm the interrupt ctrl */
376 qv_ic_write(ua, QV_IC_SR + offs, QV_IC_DISARM);
377 }
378
379 void
380 qv_ic_force(struct uba_attach_args *ua, bus_size_t offs, int ic_vec)
381 {
382 /* force an interrupt */
383 qv_ic_write(ua, QV_IC_SR + offs, QV_IC_SIRR | ic_vec);
384 }
385
386 /*
387 * print attachment message
388 */
389 int
390 qvauxprint(void *aux, const char *pnp)
391 {
392 if (pnp) {
393 aprint_normal("qvaux at %s", pnp);
394 return (UNCONF);
395 }
396 return 0;
397 }
398
399 /*
400 * autoconf attach function
401 */
402 void
403 qv_attach(device_t parent, device_t self, void *aux)
404 {
405 struct qv_softc *sc = device_private(self);
406 struct uba_softc *uh = device_private(parent);
407 struct uba_attach_args *ua = aux;
408 struct uba_attach_args aa;
409 int fcookie;
410 struct wsemuldisplaydev_attach_args emulaa;
411 // struct wsdisplaydev_attach_args dispaa;
412 struct wsdisplay_font *console_font;
413 int line;
414
415 sc->sc_dev = self;
416 sc->sc_iot = ua->ua_iot;
417 sc->sc_ioh = ua->ua_ioh;
418 sc->sc_fbt = sc->sc_iot;
419 sc->sc_fbphys = QMEMBASE + ((qv_reg_rd(sc, QV_CSR) & QV_CSR_BANK) << 7);
420 if (bus_space_map(sc->sc_fbt, sc->sc_fbphys, QVSIZE,
421 BUS_SPACE_MAP_LINEAR, &sc->sc_fbh)) {
422 aprint_error_dev(self, "Couldn't alloc graphics memory.\n");
423 return;
424 }
425
426 aprint_normal(": fb %8lo", sc->sc_fbphys & 0x3fffff);
427 sc->sc_fb = bus_space_vaddr(sc->sc_fbt, sc->sc_fbh);
428 sc->sc_scanmap = (uint16_t *)&sc->sc_fb[QV_SCANMAP];
429 #if 0
430 if (extent_alloc_region(((struct uba_vsoftc*)uh)->uv_sgmap.aps_ex,
431 sc->sc_fbphys & 0x3fffff, QVSIZE, EX_NOWAIT)) {
432 aprint_error_dev(self,
433 "Couldn't alloc graphics memory in sgmap.\n");
434 return;
435 }
436 #endif
437 //aprint_normal(": fb 0x%08lx", sc->sc_fbphys & 0x3fffff);
438
439 bzero(sc->sc_fb, QVSIZE);
440
441 for (line = 0; line < QV_YWIDTH; line++) {
442 sc->sc_scanmap[line] = line;
443 }
444
445 /* program crtc */
446 qv_setcrtc(sc, qv_stdscreen[2].qv_crtc_param);
447
448 /* enable video output */
449 qv_reg_wr(sc, QV_CSR, qv_reg_rd(sc, QV_CSR) | (1 << 2) | (1 << 3));
450 #if 0
451 if (sc->sc_curscr == NULL)
452 callout_init(&qv_cursor_ch, 0);
453 sc->sc_curscr = &qv_conscreen;
454
455 callout_reset(&qv_cursor_ch, hz / 2, qv_crsr_blink, sc);
456 #endif
457 /* interrupt handlers - XXX */
458
459 uh->uh_lastiv -= 4;
460
461 wsfont_init();
462 if ((fcookie = wsfont_find(NULL, 8, 15, 0, WSDISPLAY_FONTORDER_R2L,
463 WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP)) < 0) {
464 aprint_error_dev(self, "could not find 8x15 font\n");
465 return;
466 }
467 if (wsfont_lock(fcookie, &console_font) != 0) {
468 aprint_error_dev(self, "could not lock 8x15 font\n");
469 return;
470 }
471 sc->sc_font = console_font->data;
472
473 aprint_normal("\n");
474
475 aa.ua_iot = ua->ua_iot;
476 aa.ua_ioh = ua->ua_ioh + 32; // offset
477 aa.ua_cvec = ua->ua_cvec - 4;
478 if (config_search_ia(NULL, self, "qv", &aa) != NULL) {
479 config_found_ia(self, "qv", &aa, qvauxprint);
480 uh->uh_lastiv -= 4;
481 }
482
483 emulaa.console = 0; /* Not console */
484 emulaa.scrdata = &qv_screenlist;
485 emulaa.accessops = &qv_accessops;
486 emulaa.accesscookie = self;
487 if (config_search_ia(NULL, self, "wsemuldisplaydev", &emulaa) != NULL) {
488 config_found_ia(self, "wsemuldisplaydev", &emulaa,
489 wsemuldisplaydevprint);
490 }
491
492 //console_debugger();
493 return;
494 }
495
496 /* QVSS frame buffer */
497
498 /* uint_32 is stored little endian in frame buffer */
499 /* bits are stored little endian in frame buffer */
500
501 /* uint_32 *fb; */
502 /* fb = (int *)phystova(0x303c0000); */
503 /* *fb = 0x00000001; */ /* sets bit in first column */
504
505 /* Frame Buffer Usage */
506
507 /* characters are 8 bits wide and QVHEIGHT high */
508 /* the scan map is allocated in terms of character height, */
509 /* so a pointer to the top line of a character can step to the */
510 /* next row without looking up the memory location in the scan map */
511
512 static char *cursor;
513 static int cur_on;
514
515 /*
516 * return pointer to line in character glyph
517 */
518 static inline char *
519 qv_font(struct qv_softc *sc, int c, int line)
520 {
521 /* map char to font table offset */
522 if (c < 32)
523 c = 32;
524 else if (c > 127)
525 c -= 66;
526 else
527 c -= 32;
528
529 /* return pointer line in font glyph */
530 return &sc->sc_font[c*QV_CHEIGHT + line];
531 }
532
533 /*
534 * return pointer to character line in frame buffer
535 */
536 static inline char *
537 qv_fbp(struct qv_softc *sc, int row, int col, int line)
538 {
539 return &sc->sc_fb[col + sc->sc_scanmap[row*QV_CHEIGHT + line]*QV_COLS];
540 }
541
542 /*
543 * callout callback function to blink cursor
544 */
545 #if 0
546 static void
547 qv_crsr_blink(void *arg)
548 {
549 struct qv_softc *sc = arg;
550
551 if (cur_on)
552 *cursor ^= 255;
553 callout_reset(&qv_cursor_ch, hz / 2, qv_crsr_blink, sc);
554 }
555 #endif
556 /*
557 * emulop cursor
558 */
559 void
560 qv_cursor(void *id, int on, int row, int col)
561 {
562 struct qv_screen * const ss = id;
563
564 if (ss == ss->ss_sc->sc_curscr) {
565 *qv_fbp(ss->ss_sc, ss->ss_cury, ss->ss_curx, 14)
566 = *qv_font(ss->ss_sc,
567 ss->ss_image[ss->ss_cury][ss->ss_curx], 14);
568 cursor = qv_fbp(ss->ss_sc, row, col, 14);
569 if ((cur_on = on))
570 *cursor ^= 255;
571 }
572 ss->ss_curx = col;
573 ss->ss_cury = row;
574 }
575
576 /*
577 * emulop mapchar
578 */
579 int
580 qv_mapchar(void *id, int uni, unsigned int *index)
581 {
582 if (uni < 256) {
583 *index = uni;
584 return (5);
585 }
586 *index = ' ';
587 return (0);
588 }
589
590 /*
591 * emulop putchar
592 */
593 static void
594 qv_putchar(void *id, int row, int col, u_int c, long attr)
595 {
596 struct qv_screen * const ss = id;
597 int i;
598 char *gp;
599 char *fp;
600 char rvid;
601
602 c &= 0xff;
603
604 ss->ss_image[row][col] = c;
605 ss->ss_attr[row][col] = attr;
606 if (ss != ss->ss_sc->sc_curscr)
607 return;
608
609 gp = qv_font(ss->ss_sc, c, 0);
610 fp = qv_fbp(ss->ss_sc, row, col, 0);
611 rvid = (attr & WSATTR_REVERSE) ? 0xff : 0x00;
612 for (i = 0; i < QV_CHEIGHT; i++) {
613 *fp = *gp++ ^ rvid;
614 fp += QV_COLS;
615 }
616
617 if (attr & WSATTR_UNDERLINE)
618 *qv_fbp(ss->ss_sc, row, col, 14)
619 ^= *qv_fbp(ss->ss_sc, row, col, 14);
620 }
621
622 /*
623 * emulop copy columns - copies columns inside a row
624 */
625 static void
626 qv_copycols(void *id, int row, int srccol, int dstcol, int ncols)
627 {
628 struct qv_screen * const ss = id;
629 int i;
630
631 memcpy(&ss->ss_image[row][dstcol], &ss->ss_image[row][srccol], ncols);
632 memcpy(&ss->ss_attr[row][dstcol], &ss->ss_attr[row][srccol], ncols);
633 if (ss != ss->ss_sc->sc_curscr)
634 return;
635 for (i = 0; i < QV_CHEIGHT; i++)
636 memcpy(qv_fbp(ss->ss_sc, row, dstcol, i),
637 qv_fbp(ss->ss_sc, row, srccol, i), ncols);
638 }
639
640 /*
641 * emulop erase columns - erases a bunch of chars inside one row
642 */
643 static void
644 qv_erasecols(void *id, int row, int startcol, int ncols, long fillattr)
645 {
646 struct qv_screen * const ss = id;
647 int i;
648
649 memset(&ss->ss_image[row][startcol], 0, ncols);
650 memset(&ss->ss_attr[row][startcol], 0, ncols);
651 if (ss != ss->ss_sc->sc_curscr)
652 return;
653 for (i = 0; i < QV_CHEIGHT; i++)
654 memset(qv_fbp(ss->ss_sc, row, startcol, i), 0, ncols);
655 }
656
657 /*
658 * overlap check
659 * return 0 if no overlap
660 * -1 if overlap and dst is less than src (move up)
661 * +1 if overlap and src is less than dst (move down)
662 */
663 static inline int
664 qv_rows_overlap(int srcrow, int dstrow, int nrows)
665 {
666 if (dstrow < srcrow) {
667 if (dstrow + nrows <= srcrow)
668 return 0;
669 else
670 return -1;
671 }
672 else {
673 if (srcrow + nrows <= dstrow)
674 return 0;
675 else
676 return 1;
677 }
678 }
679
680 /*
681 * emulop copyrows - copy entire rows
682 */
683 static void
684 qv_copyrows(void *id, int srcrow, int dstrow, int nrows)
685 {
686 struct qv_screen * const ss = id;
687 int ol;
688 int n;
689 int line;
690 int tmp;
691 uint16_t *sp;
692 uint16_t *dp;
693
694 memcpy(&ss->ss_image[dstrow][0], &ss->ss_image[srcrow][0],
695 nrows * QV_COLS);
696 memcpy(&ss->ss_attr[dstrow][0], &ss->ss_attr[srcrow][0],
697 nrows * QV_COLS);
698 if (ss != ss->ss_sc->sc_curscr)
699 return;
700
701 ol = qv_rows_overlap(srcrow, dstrow, nrows);
702 if (ol == 0)
703 for (n = 0; n < nrows; n++)
704 bcopy(qv_fbp(ss->ss_sc, srcrow + n, 0, 0),
705 qv_fbp(ss->ss_sc, dstrow + n, 0, 0), QV_NEXTROW);
706 else if (ol < 0) {
707 for (n = 0; n < nrows; n++) {
708 dp = &ss->ss_sc->sc_scanmap[(dstrow + n)*QV_CHEIGHT];
709 sp = &ss->ss_sc->sc_scanmap[(srcrow + n)*QV_CHEIGHT];
710 for (line = 0; line < QV_CHEIGHT; line++) {
711 tmp = *dp;
712 *dp = *sp;
713 *sp = tmp;
714 dp++;
715 sp++;
716 }
717 }
718 qv_copyrows(id, dstrow + nrows - srcrow + dstrow,
719 dstrow + nrows, srcrow - dstrow);
720 }
721 else {
722 for (n = nrows - 1; n >= 0; n--) {
723 dp = &ss->ss_sc->sc_scanmap[(dstrow + n)*QV_CHEIGHT];
724 sp = &ss->ss_sc->sc_scanmap[(srcrow + n)*QV_CHEIGHT];
725 for (line = 0; line < QV_CHEIGHT; line++) {
726 tmp = *dp;
727 *dp = *sp;
728 *sp = tmp;
729 dp++;
730 sp++;
731 }
732 }
733 qv_copyrows(id, srcrow, dstrow, dstrow - srcrow);
734 }
735 }
736
737 /*
738 * emulop eraserows - erase a number of entire rows
739 */
740 static void
741 qv_eraserows(void *id, int startrow, int nrows, long fillattr)
742 {
743 struct qv_screen * const ss = id;
744 int row;
745
746 memset(&ss->ss_image[startrow][0], 0, nrows * QV_COLS);
747 memset(&ss->ss_attr[startrow][0], 0, nrows * QV_COLS);
748 if (ss != ss->ss_sc->sc_curscr)
749 return;
750
751 for (row = startrow; row < startrow + nrows; row++) {
752 memset(qv_fbp(ss->ss_sc, row, 0, 0), 0, QV_NEXTROW);
753 }
754 }
755
756 /*
757 * emulop allocattr
758 */
759 static int
760 qv_allocattr(void *id, int fg, int bg, int flags, long *attrp)
761 {
762 *attrp = flags;
763 return 0;
764 }
765
766 /*
767 * emulop setcursor
768 */
769 static void
770 qv_setcursor(struct qv_softc *sc, struct wsdisplay_cursor *v)
771 {
772 uint16_t red, green, blue;
773 uint32_t curfg[16], curmask[16];
774 uint16_t *curp;
775 int i;
776
777 /* Enable cursor */
778 if (v->which & WSDISPLAY_CURSOR_DOCUR) {
779 sc->sc_curon = (v->enable) ? CUR_ON : CUR_OFF;
780 qv_crtc_wr(sc, CUR_START, sc->sc_curon | (sc->sc_cury & 0x0f));
781 }
782 if (v->which & WSDISPLAY_CURSOR_DOHOT) {
783 sc->sc_curhotX = v->hot.x;
784 sc->sc_curhotY = v->hot.y;
785 }
786 if (v->which & WSDISPLAY_CURSOR_DOCMAP) {
787 /* First background */
788 red = fusword(v->cmap.red);
789 green = fusword(v->cmap.green);
790 blue = fusword(v->cmap.blue);
791 bgmask = (((30L * red + 59L * green + 11L * blue) >> 8) >=
792 (((1<<8)-1)*50)) ? ~0 : 0;
793 red = fusword(v->cmap.red+2);
794 green = fusword(v->cmap.green+2);
795 blue = fusword(v->cmap.blue+2);
796 fgmask = (((30L * red + 59L * green + 11L * blue) >> 8) >=
797 (((1<<8)-1)*50)) ? ~0 : 0;
798 }
799 if (v->which & WSDISPLAY_CURSOR_DOSHAPE) {
800 copyin(v->image, curfg, sizeof(curfg));
801 copyin(v->mask, curmask, sizeof(curmask)); /* not used */
802 curp = (uint16_t *) &(sc->sc_fb)[QV_CURSRAM];
803 for (i = 0; i < sizeof(curfg)/sizeof(curfg[0]); i++) {
804 curp[i] = (uint16_t)curfg[i];
805 }
806 }
807 }
808
809 /*
810 * emulop ioctl
811 */
812 int
813 qv_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
814 {
815 struct wsdisplay_fbinfo *fb = (void *)data;
816 //static uint16_t curc;
817 struct qv_softc *sc = device_private(v);
818
819 switch (cmd) {
820 case WSDISPLAYIO_GTYPE:
821 *(u_int *)data = WSDISPLAY_TYPE_VAX_MONO;
822 break;
823
824 case WSDISPLAYIO_GINFO:
825 fb->height = QV_YWIDTH;
826 fb->width = QV_XWIDTH;
827 fb->depth = 1;
828 fb->cmsize = 2;
829 break;
830
831 case WSDISPLAYIO_SVIDEO:
832 if (*(u_int *)data == WSDISPLAYIO_VIDEO_ON) {
833 /* enable video output */
834 qv_reg_wr(sc, QV_CSR,
835 qv_reg_rd(sc, QV_CSR) | (1 << 2));
836 } else {
837 /* disable video output */
838 qv_reg_wr(sc, QV_CSR,
839 qv_reg_rd(sc, QV_CSR) & ~(1 << 2));
840 }
841 break;
842
843 case WSDISPLAYIO_GVIDEO:
844 *(u_int *)data = (qv_reg_rd(sc, QV_CSR) & (1 << 2))
845 ? WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
846 break;
847
848 case WSDISPLAYIO_SCURSOR:
849 qv_setcursor(sc, (struct wsdisplay_cursor *)data);
850 break;
851
852 case WSDISPLAYIO_SCURPOS:
853 sc->sc_curx = ((struct wsdisplay_curpos *)data)->x;
854 sc->sc_cury = ((struct wsdisplay_curpos *)data)->y;
855 qv_crtc_wr(sc, CUR_START, CUR_OFF | (sc->sc_cury & 0x0f));
856 qv_crtc_wr(sc, CUR_HI, sc->sc_cury >> 4);
857 qv_reg_wr(sc, QV_CUR_X, sc->sc_curx);
858 qv_crtc_wr(sc, CUR_START,
859 sc->sc_curon | (sc->sc_cury & 0x0f));
860 break;
861
862 case WSDISPLAYIO_GCURPOS:
863 ((struct wsdisplay_curpos *)data)->x = sc->sc_curx;
864 ((struct wsdisplay_curpos *)data)->y = sc->sc_cury;
865 break;
866
867 case WSDISPLAYIO_GCURMAX:
868 ((struct wsdisplay_curpos *)data)->x = 16;
869 ((struct wsdisplay_curpos *)data)->y = 16;
870 break;
871
872 default:
873 return EPASSTHROUGH;
874 }
875 return 0;
876 }
877
878 /*
879 * emulop mmap
880 */
881 static paddr_t
882 qv_mmap(void *v, void *vs, off_t offset, int prot)
883 {
884 struct qv_softc *sc = device_private(v);
885
886 if (offset >= QVSIZE || offset < 0)
887 return -1;
888 return (sc->sc_fbphys) >> PGSHIFT;
889 }
890
891 /*
892 * emulop allocate screen
893 */
894 int
895 qv_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
896 int *curxp, int *curyp, long *defattrp)
897 {
898 struct qv_softc *sc = device_private(v);
899 struct qv_screen *ss;
900
901 ss = malloc(sizeof(struct qv_screen), M_DEVBUF, M_WAITOK|M_ZERO);
902 ss->ss_sc = sc;
903 ss->ss_type = type;
904 *cookiep = ss;
905 *curxp = *curyp = *defattrp = 0;
906 printf("qv_alloc_screen: \"%s\" %p\n", type->name, ss);
907 return 0;
908 }
909
910 /*
911 * emulop free screen
912 */
913 void
914 qv_free_screen(void *v, void *cookie)
915 {
916 printf("qv_free_screen: %p\n", cookie);
917 free(cookie, M_DEVBUF);
918 }
919
920 /*
921 * emulop show screen
922 */
923 int
924 qv_show_screen(void *v, void *cookie, int waitok,
925 void (*cb)(void *, int, int), void *cbarg)
926 {
927 struct qv_screen *ss = cookie;
928 const struct _wsscreen_descr *descr;
929 int row, col, line;
930 printf("qv_show_screen: %p\n", cookie);
931
932 if (ss == ss->ss_sc->sc_curscr)
933 return (0);
934
935 descr = (const struct _wsscreen_descr *)(ss->ss_type);
936 qv_setcrtc(ss->ss_sc, descr->qv_crtc_param);
937 for (row = 0; row < QV_ROWS; row++)
938 for (line = 0; line < QV_CHEIGHT; line++) {
939 for (col = 0; col < QV_COLS; col++) {
940 u_char s, c = ss->ss_image[row][col];
941
942 if (c < 32)
943 c = 32;
944 s = *qv_font(ss->ss_sc, c, line);
945 if (ss->ss_attr[row][col] & WSATTR_REVERSE)
946 s ^= 255;
947 *qv_fbp(ss->ss_sc, row, col, line) = s;
948
949 if (ss->ss_attr[row][col] & WSATTR_UNDERLINE)
950 *qv_fbp(ss->ss_sc, row, col, line)
951 = 255;
952 }
953 }
954 cursor = qv_fbp(ss->ss_sc, ss->ss_cury, ss->ss_curx, 14);
955 ss->ss_sc->sc_curscr = ss;
956 return (0);
957 }
958
959 #if 0
960 void
961 qv_reset_establish(void (*reset)(device_t), device_t dev)
962 {
963 uba_reset_establish(reset, device_parent(dev));
964 }
965 #endif
966 cons_decl(qv);
967
968 void
969 qvcninit(struct consdev *cndev)
970 {
971 int fcookie;
972 struct wsdisplay_font *console_font;
973 extern void lkccninit(struct consdev *);
974 extern int lkccngetc(dev_t);
975 extern int dz_vsbus_lk201_cnattach(int);
976
977 //printf("qvcninit: \n");
978 /* Clear screen */
979 //memset(qv_addr, 0, 128*864);
980
981 callout_init(&qv_cursor_ch, 0);
982 //curscr = &qv_conscreen;
983 wsdisplay_cnattach(&qv_stdscreen[0].qv_stdscreen,
984 &qv_conscreen, 0, 0, 0);
985 cn_tab->cn_pri = CN_INTERNAL;
986 wsfont_init();
987 if ((fcookie = wsfont_find(NULL, 8, 15, 0, WSDISPLAY_FONTORDER_R2L,
988 WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP)) < 0)
989 {
990 printf("qv: could not find 8x15 font\n");
991 return;
992 }
993 if (wsfont_lock(fcookie, &console_font) != 0) {
994 printf("qv: could not lock 8x15 font\n");
995 return;
996 }
997 //qf = console_font->data;
998
999 #if NQVKBD > 0 && 0
1000 qvkbd_cnattach(0); /* Connect keyboard and screen together */
1001 #endif
1002 }
1003
1004 /*
1005 * Called very early to setup the glass tty as console.
1006 * Because it's called before the VM system is inited, virtual memory
1007 * for the framebuffer can be stolen directly without disturbing anything.
1008 */
1009 void
1010 qvcnprobe(struct consdev *cndev)
1011 {
1012 printf("qvcnprobe: \n");
1013 #if 0
1014 extern vaddr_t virtual_avail;
1015 extern const struct cdevsw wsdisplay_cdevsw;
1016
1017 switch (vax_boardtype) {
1018 case VAX_BTYP_410:
1019 case VAX_BTYP_420:
1020 case VAX_BTYP_43:
1021 if ((vax_confdata & KA420_CFG_L3CON) ||
1022 (vax_confdata & KA420_CFG_MULTU))
1023 break; /* doesn't use graphics console */
1024 qv_addr = (void *)virtual_avail;
1025 virtual_avail += QVSIZE;
1026 ioaccess((vaddr_t)qv_addr, QVADDR, (QVSIZE/VAX_NBPG));
1027 cndev->cn_pri = CN_INTERNAL;
1028 cndev->cn_dev = makedev(cdevsw_lookup_major(&wsdisplay_cdevsw),
1029 0);
1030 break;
1031 default:
1032 break;
1033 }
1034 #endif
1035 }
1036