1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51#include <linux/mutex.h>
52#include <linux/module.h>
53#include <linux/kernel.h>
54#include <linux/signal.h>
55#include <linux/fs.h>
56#include <linux/usb.h>
57#include <linux/tty.h>
58#include <linux/console.h>
59#include <linux/string.h>
60#include <linux/kd.h>
61#include <linux/init.h>
62#include <linux/vt_kern.h>
63#include <linux/selection.h>
64#include <linux/spinlock.h>
65#include <linux/kref.h>
66#include <linux/ioport.h>
67#include <linux/interrupt.h>
68#include <linux/vmalloc.h>
69
70#include "sisusb.h"
71#include "sisusb_init.h"
72
73#ifdef INCL_SISUSB_CON
74
75#define sisusbcon_writew(val, addr) (*(addr) = (val))
76#define sisusbcon_readw(addr) (*(addr))
77#define sisusbcon_memmovew(d, s, c) memmove(d, s, c)
78#define sisusbcon_memcpyw(d, s, c) memcpy(d, s, c)
79
80
81static struct sisusb_usb_data *mysisusbs[MAX_NR_CONSOLES];
82
83
84static const struct consw sisusb_con;
85
86static inline void
87sisusbcon_memsetw(u16 *s, u16 c, unsigned int count)
88{
89 count /= 2;
90 while (count--)
91 sisusbcon_writew(c, s++);
92}
93
94static inline void
95sisusb_initialize(struct sisusb_usb_data *sisusb)
96{
97
98 if (sisusb_setidxreg(sisusb, SISCR, 0x0c, 0x00))
99 return;
100 if (sisusb_setidxreg(sisusb, SISCR, 0x0d, 0x00))
101 return;
102 if (sisusb_setidxreg(sisusb, SISCR, 0x0e, 0x00))
103 return;
104 sisusb_setidxreg(sisusb, SISCR, 0x0f, 0x00);
105}
106
107static inline void
108sisusbcon_set_start_address(struct sisusb_usb_data *sisusb, struct vc_data *c)
109{
110 sisusb->cur_start_addr = (c->vc_visible_origin - sisusb->scrbuf) / 2;
111
112 sisusb_setidxreg(sisusb, SISCR, 0x0c, (sisusb->cur_start_addr >> 8));
113 sisusb_setidxreg(sisusb, SISCR, 0x0d, (sisusb->cur_start_addr & 0xff));
114}
115
116void
117sisusb_set_cursor(struct sisusb_usb_data *sisusb, unsigned int location)
118{
119 if (sisusb->sisusb_cursor_loc == location)
120 return;
121
122 sisusb->sisusb_cursor_loc = location;
123
124
125
126
127
128
129 if ((location & 0x0007) == 0x0007) {
130 sisusb->bad_cursor_pos = 1;
131 location--;
132 if (sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0x1f, 0x20))
133 return;
134 } else if (sisusb->bad_cursor_pos) {
135 if (sisusb_setidxregand(sisusb, SISCR, 0x0b, 0x1f))
136 return;
137 sisusb->bad_cursor_pos = 0;
138 }
139
140 if (sisusb_setidxreg(sisusb, SISCR, 0x0e, (location >> 8)))
141 return;
142 sisusb_setidxreg(sisusb, SISCR, 0x0f, (location & 0xff));
143}
144
145static inline struct sisusb_usb_data *
146sisusb_get_sisusb(unsigned short console)
147{
148 return mysisusbs[console];
149}
150
151static inline int
152sisusb_sisusb_valid(struct sisusb_usb_data *sisusb)
153{
154 if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev)
155 return 0;
156
157 return 1;
158}
159
160static struct sisusb_usb_data *
161sisusb_get_sisusb_lock_and_check(unsigned short console)
162{
163 struct sisusb_usb_data *sisusb;
164
165
166
167
168
169
170 if (in_atomic())
171 return NULL;
172
173 sisusb = sisusb_get_sisusb(console);
174 if (!sisusb)
175 return NULL;
176
177 mutex_lock(&sisusb->lock);
178
179 if (!sisusb_sisusb_valid(sisusb) ||
180 !sisusb->havethisconsole[console]) {
181 mutex_unlock(&sisusb->lock);
182 return NULL;
183 }
184
185 return sisusb;
186}
187
188static int
189sisusb_is_inactive(struct vc_data *c, struct sisusb_usb_data *sisusb)
190{
191 if (sisusb->is_gfx ||
192 sisusb->textmodedestroyed ||
193 c->vc_mode != KD_TEXT)
194 return 1;
195
196 return 0;
197}
198
199
200static const char *
201sisusbcon_startup(void)
202{
203 return "SISUSBCON";
204}
205
206
207static void
208sisusbcon_init(struct vc_data *c, int init)
209{
210 struct sisusb_usb_data *sisusb;
211 int cols, rows;
212
213
214
215
216
217
218
219 sisusb = sisusb_get_sisusb(c->vc_num);
220 if (!sisusb)
221 return;
222
223 mutex_lock(&sisusb->lock);
224
225 if (!sisusb_sisusb_valid(sisusb)) {
226 mutex_unlock(&sisusb->lock);
227 return;
228 }
229
230 c->vc_can_do_color = 1;
231
232 c->vc_complement_mask = 0x7700;
233
234 c->vc_hi_font_mask = sisusb->current_font_512 ? 0x0800 : 0;
235
236 sisusb->haveconsole = 1;
237
238 sisusb->havethisconsole[c->vc_num] = 1;
239
240
241 c->vc_scan_lines = 400;
242
243 c->vc_font.height = sisusb->current_font_height;
244
245
246 cols = 80;
247 rows = c->vc_scan_lines / c->vc_font.height;
248
249
250
251
252
253
254
255
256
257
258 kref_get(&sisusb->kref);
259
260 if (!*c->vc_uni_pagedir_loc)
261 con_set_default_unimap(c);
262
263 mutex_unlock(&sisusb->lock);
264
265 if (init) {
266 c->vc_cols = cols;
267 c->vc_rows = rows;
268 } else
269 vc_resize(c, cols, rows);
270}
271
272
273static void
274sisusbcon_deinit(struct vc_data *c)
275{
276 struct sisusb_usb_data *sisusb;
277 int i;
278
279
280
281
282
283 sisusb = sisusb_get_sisusb(c->vc_num);
284 if (!sisusb)
285 return;
286
287 mutex_lock(&sisusb->lock);
288
289
290 mysisusbs[c->vc_num] = NULL;
291
292 sisusb->havethisconsole[c->vc_num] = 0;
293
294
295 if (sisusb->font_backup) {
296 for(i = 0; i < MAX_NR_CONSOLES; i++) {
297 if (sisusb->havethisconsole[c->vc_num])
298 break;
299 }
300 if (i == MAX_NR_CONSOLES) {
301 vfree(sisusb->font_backup);
302 sisusb->font_backup = NULL;
303 }
304 }
305
306 mutex_unlock(&sisusb->lock);
307
308
309 kref_put(&sisusb->kref, sisusb_delete);
310}
311
312
313static u8
314sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity,
315 u8 blink, u8 underline, u8 reverse, u8 unused)
316{
317 u8 attr = color;
318
319 if (underline)
320 attr = (attr & 0xf0) | c->vc_ulcolor;
321 else if (intensity == 0)
322 attr = (attr & 0xf0) | c->vc_halfcolor;
323
324 if (reverse)
325 attr = ((attr) & 0x88) |
326 ((((attr) >> 4) |
327 ((attr) << 4)) & 0x77);
328
329 if (blink)
330 attr ^= 0x80;
331
332 if (intensity == 2)
333 attr ^= 0x08;
334
335 return attr;
336}
337
338
339static void
340sisusbcon_invert_region(struct vc_data *vc, u16 *p, int count)
341{
342
343
344
345
346
347
348 while (count--) {
349 u16 a = sisusbcon_readw(p);
350
351 a = ((a) & 0x88ff) |
352 (((a) & 0x7000) >> 4) |
353 (((a) & 0x0700) << 4);
354
355 sisusbcon_writew(a, p++);
356 }
357}
358
359#define SISUSB_VADDR(x,y) \
360 ((u16 *)c->vc_origin + \
361 (y) * sisusb->sisusb_num_columns + \
362 (x))
363
364#define SISUSB_HADDR(x,y) \
365 ((u16 *)(sisusb->vrambase + (c->vc_origin - sisusb->scrbuf)) + \
366 (y) * sisusb->sisusb_num_columns + \
367 (x))
368
369
370static void
371sisusbcon_putc(struct vc_data *c, int ch, int y, int x)
372{
373 struct sisusb_usb_data *sisusb;
374
375 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
376 if (!sisusb)
377 return;
378
379
380 if (sisusb_is_inactive(c, sisusb)) {
381 mutex_unlock(&sisusb->lock);
382 return;
383 }
384
385
386 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
387 (long)SISUSB_HADDR(x, y), 2);
388
389 mutex_unlock(&sisusb->lock);
390}
391
392
393static void
394sisusbcon_putcs(struct vc_data *c, const unsigned short *s,
395 int count, int y, int x)
396{
397 struct sisusb_usb_data *sisusb;
398 u16 *dest;
399 int i;
400
401 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
402 if (!sisusb)
403 return;
404
405
406
407
408
409
410
411 dest = SISUSB_VADDR(x, y);
412
413 for (i = count; i > 0; i--)
414 sisusbcon_writew(sisusbcon_readw(s++), dest++);
415
416 if (sisusb_is_inactive(c, sisusb)) {
417 mutex_unlock(&sisusb->lock);
418 return;
419 }
420
421 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
422 (long)SISUSB_HADDR(x, y), count * 2);
423
424 mutex_unlock(&sisusb->lock);
425}
426
427
428static void
429sisusbcon_clear(struct vc_data *c, int y, int x, int height, int width)
430{
431 struct sisusb_usb_data *sisusb;
432 u16 eattr = c->vc_video_erase_char;
433 int i, length, cols;
434 u16 *dest;
435
436 if (width <= 0 || height <= 0)
437 return;
438
439 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
440 if (!sisusb)
441 return;
442
443
444
445
446
447
448
449 dest = SISUSB_VADDR(x, y);
450
451 cols = sisusb->sisusb_num_columns;
452
453 if (width > cols)
454 width = cols;
455
456 if (x == 0 && width >= c->vc_cols) {
457
458 sisusbcon_memsetw(dest, eattr, height * cols * 2);
459
460 } else {
461
462 for (i = height; i > 0; i--, dest += cols)
463 sisusbcon_memsetw(dest, eattr, width * 2);
464
465 }
466
467 if (sisusb_is_inactive(c, sisusb)) {
468 mutex_unlock(&sisusb->lock);
469 return;
470 }
471
472 length = ((height * cols) - x - (cols - width - x)) * 2;
473
474
475 sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(x, y),
476 (long)SISUSB_HADDR(x, y), length);
477
478 mutex_unlock(&sisusb->lock);
479}
480
481
482static int
483sisusbcon_switch(struct vc_data *c)
484{
485 struct sisusb_usb_data *sisusb;
486 int length;
487
488
489
490
491
492
493 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
494 if (!sisusb)
495 return 0;
496
497
498
499
500 if (sisusb_is_inactive(c, sisusb)) {
501 mutex_unlock(&sisusb->lock);
502 return 0;
503 }
504
505
506
507
508
509 if (c->vc_origin == (unsigned long)c->vc_screenbuf) {
510 mutex_unlock(&sisusb->lock);
511 dev_dbg(&sisusb->sisusb_dev->dev, "ASSERT ORIGIN != SCREENBUF!\n");
512 return 0;
513 }
514
515
516 length = min((int)c->vc_screenbuf_size,
517 (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
518
519
520 sisusbcon_memcpyw((u16 *)c->vc_origin, (u16 *)c->vc_screenbuf,
521 length);
522
523 sisusb_copy_memory(sisusb, (unsigned char *)c->vc_origin,
524 (long)SISUSB_HADDR(0, 0),
525 length);
526
527 mutex_unlock(&sisusb->lock);
528
529 return 0;
530}
531
532
533static void
534sisusbcon_save_screen(struct vc_data *c)
535{
536 struct sisusb_usb_data *sisusb;
537 int length;
538
539
540
541
542
543 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
544 if (!sisusb)
545 return;
546
547
548
549 if (sisusb_is_inactive(c, sisusb)) {
550 mutex_unlock(&sisusb->lock);
551 return;
552 }
553
554
555 length = min((int)c->vc_screenbuf_size,
556 (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
557
558
559 sisusbcon_memcpyw((u16 *)c->vc_screenbuf, (u16 *)c->vc_origin,
560 length);
561
562 mutex_unlock(&sisusb->lock);
563}
564
565
566static void
567sisusbcon_set_palette(struct vc_data *c, const unsigned char *table)
568{
569 struct sisusb_usb_data *sisusb;
570 int i, j;
571
572
573
574 if (!con_is_visible(c))
575 return;
576
577 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
578 if (!sisusb)
579 return;
580
581
582
583 if (sisusb_is_inactive(c, sisusb)) {
584 mutex_unlock(&sisusb->lock);
585 return;
586 }
587
588 for (i = j = 0; i < 16; i++) {
589 if (sisusb_setreg(sisusb, SISCOLIDX, table[i]))
590 break;
591 if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
592 break;
593 if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
594 break;
595 if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
596 break;
597 }
598
599 mutex_unlock(&sisusb->lock);
600}
601
602
603static int
604sisusbcon_blank(struct vc_data *c, int blank, int mode_switch)
605{
606 struct sisusb_usb_data *sisusb;
607 u8 sr1, cr17, pmreg, cr63;
608 int ret = 0;
609
610 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
611 if (!sisusb)
612 return 0;
613
614
615
616 if (mode_switch)
617 sisusb->is_gfx = blank ? 1 : 0;
618
619 if (sisusb_is_inactive(c, sisusb)) {
620 mutex_unlock(&sisusb->lock);
621 return 0;
622 }
623
624 switch (blank) {
625
626 case 1:
627 case -1:
628 sisusbcon_memsetw((u16 *)c->vc_origin,
629 c->vc_video_erase_char,
630 c->vc_screenbuf_size);
631 sisusb_copy_memory(sisusb,
632 (unsigned char *)c->vc_origin,
633 (u32)(sisusb->vrambase +
634 (c->vc_origin - sisusb->scrbuf)),
635 c->vc_screenbuf_size);
636 sisusb->con_blanked = 1;
637 ret = 1;
638 break;
639
640 default:
641 switch (blank) {
642 case 0:
643 sr1 = 0x00;
644 cr17 = 0x80;
645 pmreg = 0x00;
646 cr63 = 0x00;
647 ret = 1;
648 sisusb->con_blanked = 0;
649 break;
650 case VESA_VSYNC_SUSPEND + 1:
651 sr1 = 0x20;
652 cr17 = 0x80;
653 pmreg = 0x80;
654 cr63 = 0x40;
655 break;
656 case VESA_HSYNC_SUSPEND + 1:
657 sr1 = 0x20;
658 cr17 = 0x80;
659 pmreg = 0x40;
660 cr63 = 0x40;
661 break;
662 case VESA_POWERDOWN + 1:
663 sr1 = 0x20;
664 cr17 = 0x00;
665 pmreg = 0xc0;
666 cr63 = 0x40;
667 break;
668 default:
669 mutex_unlock(&sisusb->lock);
670 return -EINVAL;
671 }
672
673 sisusb_setidxregandor(sisusb, SISSR, 0x01, ~0x20, sr1);
674 sisusb_setidxregandor(sisusb, SISCR, 0x17, 0x7f, cr17);
675 sisusb_setidxregandor(sisusb, SISSR, 0x1f, 0x3f, pmreg);
676 sisusb_setidxregandor(sisusb, SISCR, 0x63, 0xbf, cr63);
677
678 }
679
680 mutex_unlock(&sisusb->lock);
681
682 return ret;
683}
684
685
686static void
687sisusbcon_scrolldelta(struct vc_data *c, int lines)
688{
689 struct sisusb_usb_data *sisusb;
690
691 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
692 if (!sisusb)
693 return;
694
695
696
697 if (sisusb_is_inactive(c, sisusb)) {
698 mutex_unlock(&sisusb->lock);
699 return;
700 }
701
702 vc_scrolldelta_helper(c, lines, sisusb->con_rolled_over,
703 (void *)sisusb->scrbuf, sisusb->scrbuf_size);
704
705 sisusbcon_set_start_address(sisusb, c);
706
707 mutex_unlock(&sisusb->lock);
708}
709
710
711static void
712sisusbcon_cursor(struct vc_data *c, int mode)
713{
714 struct sisusb_usb_data *sisusb;
715 int from, to, baseline;
716
717 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
718 if (!sisusb)
719 return;
720
721
722
723 if (sisusb_is_inactive(c, sisusb)) {
724 mutex_unlock(&sisusb->lock);
725 return;
726 }
727
728 if (c->vc_origin != c->vc_visible_origin) {
729 c->vc_visible_origin = c->vc_origin;
730 sisusbcon_set_start_address(sisusb, c);
731 }
732
733 if (mode == CM_ERASE) {
734 sisusb_setidxregor(sisusb, SISCR, 0x0a, 0x20);
735 sisusb->sisusb_cursor_size_to = -1;
736 mutex_unlock(&sisusb->lock);
737 return;
738 }
739
740 sisusb_set_cursor(sisusb, (c->vc_pos - sisusb->scrbuf) / 2);
741
742 baseline = c->vc_font.height - (c->vc_font.height < 10 ? 1 : 2);
743
744 switch (c->vc_cursor_type & 0x0f) {
745 case CUR_BLOCK: from = 1;
746 to = c->vc_font.height;
747 break;
748 case CUR_TWO_THIRDS: from = c->vc_font.height / 3;
749 to = baseline;
750 break;
751 case CUR_LOWER_HALF: from = c->vc_font.height / 2;
752 to = baseline;
753 break;
754 case CUR_LOWER_THIRD: from = (c->vc_font.height * 2) / 3;
755 to = baseline;
756 break;
757 case CUR_NONE: from = 31;
758 to = 30;
759 break;
760 default:
761 case CUR_UNDERLINE: from = baseline - 1;
762 to = baseline;
763 break;
764 }
765
766 if (sisusb->sisusb_cursor_size_from != from ||
767 sisusb->sisusb_cursor_size_to != to) {
768
769 sisusb_setidxreg(sisusb, SISCR, 0x0a, from);
770 sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0xe0, to);
771
772 sisusb->sisusb_cursor_size_from = from;
773 sisusb->sisusb_cursor_size_to = to;
774 }
775
776 mutex_unlock(&sisusb->lock);
777}
778
779static bool
780sisusbcon_scroll_area(struct vc_data *c, struct sisusb_usb_data *sisusb,
781 unsigned int t, unsigned int b, enum con_scroll dir,
782 unsigned int lines)
783{
784 int cols = sisusb->sisusb_num_columns;
785 int length = ((b - t) * cols) * 2;
786 u16 eattr = c->vc_video_erase_char;
787
788
789
790
791
792
793
794
795
796 switch (dir) {
797
798 case SM_UP:
799 sisusbcon_memmovew(SISUSB_VADDR(0, t),
800 SISUSB_VADDR(0, t + lines),
801 (b - t - lines) * cols * 2);
802 sisusbcon_memsetw(SISUSB_VADDR(0, b - lines), eattr,
803 lines * cols * 2);
804 break;
805
806 case SM_DOWN:
807 sisusbcon_memmovew(SISUSB_VADDR(0, t + lines),
808 SISUSB_VADDR(0, t),
809 (b - t - lines) * cols * 2);
810 sisusbcon_memsetw(SISUSB_VADDR(0, t), eattr,
811 lines * cols * 2);
812 break;
813 }
814
815 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(0, t),
816 (long)SISUSB_HADDR(0, t), length);
817
818 mutex_unlock(&sisusb->lock);
819
820 return true;
821}
822
823
824static bool
825sisusbcon_scroll(struct vc_data *c, unsigned int t, unsigned int b,
826 enum con_scroll dir, unsigned int lines)
827{
828 struct sisusb_usb_data *sisusb;
829 u16 eattr = c->vc_video_erase_char;
830 int copyall = 0;
831 unsigned long oldorigin;
832 unsigned int delta = lines * c->vc_size_row;
833 u32 originoffset;
834
835
836
837
838
839
840
841
842 if (!lines)
843 return true;
844
845 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
846 if (!sisusb)
847 return false;
848
849
850
851 if (sisusb_is_inactive(c, sisusb)) {
852 mutex_unlock(&sisusb->lock);
853 return false;
854 }
855
856
857 if (t || b != c->vc_rows)
858 return sisusbcon_scroll_area(c, sisusb, t, b, dir, lines);
859
860 if (c->vc_origin != c->vc_visible_origin) {
861 c->vc_visible_origin = c->vc_origin;
862 sisusbcon_set_start_address(sisusb, c);
863 }
864
865
866 if (lines > c->vc_rows)
867 lines = c->vc_rows;
868
869 oldorigin = c->vc_origin;
870
871 switch (dir) {
872
873 case SM_UP:
874
875 if (c->vc_scr_end + delta >=
876 sisusb->scrbuf + sisusb->scrbuf_size) {
877 sisusbcon_memcpyw((u16 *)sisusb->scrbuf,
878 (u16 *)(oldorigin + delta),
879 c->vc_screenbuf_size - delta);
880 c->vc_origin = sisusb->scrbuf;
881 sisusb->con_rolled_over = oldorigin - sisusb->scrbuf;
882 copyall = 1;
883 } else
884 c->vc_origin += delta;
885
886 sisusbcon_memsetw(
887 (u16 *)(c->vc_origin + c->vc_screenbuf_size - delta),
888 eattr, delta);
889
890 break;
891
892 case SM_DOWN:
893
894 if (oldorigin - delta < sisusb->scrbuf) {
895 sisusbcon_memmovew((u16 *)(sisusb->scrbuf +
896 sisusb->scrbuf_size -
897 c->vc_screenbuf_size +
898 delta),
899 (u16 *)oldorigin,
900 c->vc_screenbuf_size - delta);
901 c->vc_origin = sisusb->scrbuf +
902 sisusb->scrbuf_size -
903 c->vc_screenbuf_size;
904 sisusb->con_rolled_over = 0;
905 copyall = 1;
906 } else
907 c->vc_origin -= delta;
908
909 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
910
911 scr_memsetw((u16 *)(c->vc_origin), eattr, delta);
912
913 break;
914 }
915
916 originoffset = (u32)(c->vc_origin - sisusb->scrbuf);
917
918 if (copyall)
919 sisusb_copy_memory(sisusb,
920 (char *)c->vc_origin,
921 (u32)(sisusb->vrambase + originoffset),
922 c->vc_screenbuf_size);
923 else if (dir == SM_UP)
924 sisusb_copy_memory(sisusb,
925 (char *)c->vc_origin + c->vc_screenbuf_size - delta,
926 (u32)sisusb->vrambase + originoffset +
927 c->vc_screenbuf_size - delta,
928 delta);
929 else
930 sisusb_copy_memory(sisusb,
931 (char *)c->vc_origin,
932 (u32)(sisusb->vrambase + originoffset),
933 delta);
934
935 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
936 c->vc_visible_origin = c->vc_origin;
937
938 sisusbcon_set_start_address(sisusb, c);
939
940 c->vc_pos = c->vc_pos - oldorigin + c->vc_origin;
941
942 mutex_unlock(&sisusb->lock);
943
944 return true;
945}
946
947
948static int
949sisusbcon_set_origin(struct vc_data *c)
950{
951 struct sisusb_usb_data *sisusb;
952
953
954
955
956
957
958 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
959 if (!sisusb)
960 return 0;
961
962
963
964 if (sisusb_is_inactive(c, sisusb) || sisusb->con_blanked) {
965 mutex_unlock(&sisusb->lock);
966 return 0;
967 }
968
969 c->vc_origin = c->vc_visible_origin = sisusb->scrbuf;
970
971 sisusbcon_set_start_address(sisusb, c);
972
973 sisusb->con_rolled_over = 0;
974
975 mutex_unlock(&sisusb->lock);
976
977 return true;
978}
979
980
981static int
982sisusbcon_resize(struct vc_data *c, unsigned int newcols, unsigned int newrows,
983 unsigned int user)
984{
985 struct sisusb_usb_data *sisusb;
986 int fh;
987
988 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
989 if (!sisusb)
990 return -ENODEV;
991
992 fh = sisusb->current_font_height;
993
994 mutex_unlock(&sisusb->lock);
995
996
997
998
999
1000
1001
1002
1003 if (newcols != 80 || c->vc_scan_lines / fh != newrows)
1004 return -EINVAL;
1005
1006 return 0;
1007}
1008
1009int
1010sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot,
1011 u8 *arg, int cmapsz, int ch512, int dorecalc,
1012 struct vc_data *c, int fh, int uplock)
1013{
1014 int font_select = 0x00, i, err = 0;
1015 u32 offset = 0;
1016 u8 dummy;
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026 if ((slot != 0 && slot != 2) || !fh) {
1027 if (uplock)
1028 mutex_unlock(&sisusb->lock);
1029 return -EINVAL;
1030 }
1031
1032 if (set)
1033 sisusb->font_slot = slot;
1034
1035
1036 if (slot == 0)
1037 ch512 = 0;
1038 else
1039 offset = 4 * cmapsz;
1040
1041 font_select = (slot == 0) ? 0x00 : (ch512 ? 0x0e : 0x0a);
1042
1043 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01);
1044 err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x04);
1045 err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x07);
1046 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03);
1047
1048 if (err)
1049 goto font_op_error;
1050
1051 err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x03);
1052 err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x00);
1053 err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x00);
1054
1055 if (err)
1056 goto font_op_error;
1057
1058 if (arg) {
1059 if (set)
1060 for (i = 0; i < cmapsz; i++) {
1061 err |= sisusb_writeb(sisusb,
1062 sisusb->vrambase + offset + i,
1063 arg[i]);
1064 if (err)
1065 break;
1066 }
1067 else
1068 for (i = 0; i < cmapsz; i++) {
1069 err |= sisusb_readb(sisusb,
1070 sisusb->vrambase + offset + i,
1071 &arg[i]);
1072 if (err)
1073 break;
1074 }
1075
1076
1077
1078
1079
1080
1081 if (ch512) {
1082 if (set)
1083 for (i = 0; i < cmapsz; i++) {
1084 err |= sisusb_writeb(sisusb,
1085 sisusb->vrambase + offset +
1086 (2 * cmapsz) + i,
1087 arg[cmapsz + i]);
1088 if (err)
1089 break;
1090 }
1091 else
1092 for (i = 0; i < cmapsz; i++) {
1093 err |= sisusb_readb(sisusb,
1094 sisusb->vrambase + offset +
1095 (2 * cmapsz) + i,
1096 &arg[cmapsz + i]);
1097 if (err)
1098 break;
1099 }
1100 }
1101 }
1102
1103 if (err)
1104 goto font_op_error;
1105
1106 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01);
1107 err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x03);
1108 err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x03);
1109 if (set)
1110 sisusb_setidxreg(sisusb, SISSR, 0x03, font_select);
1111 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03);
1112
1113 if (err)
1114 goto font_op_error;
1115
1116 err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x00);
1117 err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x10);
1118 err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x06);
1119
1120 if (err)
1121 goto font_op_error;
1122
1123 if ((set) && (ch512 != sisusb->current_font_512)) {
1124
1125
1126
1127
1128 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1129 struct vc_data *d = vc_cons[i].d;
1130 if (d && d->vc_sw == &sisusb_con)
1131 d->vc_hi_font_mask = ch512 ? 0x0800 : 0;
1132 }
1133
1134 sisusb->current_font_512 = ch512;
1135
1136
1137
1138
1139 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1140 sisusb_setreg(sisusb, SISAR, 0x12);
1141 sisusb_setreg(sisusb, SISAR, ch512 ? 0x07 : 0x0f);
1142
1143 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1144 sisusb_setreg(sisusb, SISAR, 0x20);
1145 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1146 }
1147
1148 if (dorecalc) {
1149
1150
1151
1152
1153
1154 unsigned char ovr, vde, fsr;
1155 int rows = 0, maxscan = 0;
1156
1157 if (c) {
1158
1159
1160 rows = c->vc_scan_lines / fh;
1161
1162 maxscan = rows * fh - 1;
1163
1164
1165
1166
1167 sisusb_getidxreg(sisusb, SISCR, 0x07, &ovr);
1168 vde = maxscan & 0xff;
1169 ovr = (ovr & 0xbd) |
1170 ((maxscan & 0x100) >> 7) |
1171 ((maxscan & 0x200) >> 3);
1172 sisusb_setidxreg(sisusb, SISCR, 0x07, ovr);
1173 sisusb_setidxreg(sisusb, SISCR, 0x12, vde);
1174
1175 }
1176
1177 sisusb_getidxreg(sisusb, SISCR, 0x09, &fsr);
1178 fsr = (fsr & 0xe0) | (fh - 1);
1179 sisusb_setidxreg(sisusb, SISCR, 0x09, fsr);
1180 sisusb->current_font_height = fh;
1181
1182 sisusb->sisusb_cursor_size_from = -1;
1183 sisusb->sisusb_cursor_size_to = -1;
1184
1185 }
1186
1187 if (uplock)
1188 mutex_unlock(&sisusb->lock);
1189
1190 if (dorecalc && c) {
1191 int rows = c->vc_scan_lines / fh;
1192
1193
1194
1195 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1196 struct vc_data *vc = vc_cons[i].d;
1197
1198 if (vc && vc->vc_sw == &sisusb_con) {
1199 if (con_is_visible(vc)) {
1200 vc->vc_sw->con_cursor(vc, CM_DRAW);
1201 }
1202 vc->vc_font.height = fh;
1203 vc_resize(vc, 0, rows);
1204 }
1205 }
1206 }
1207
1208 return 0;
1209
1210font_op_error:
1211 if (uplock)
1212 mutex_unlock(&sisusb->lock);
1213
1214 return -EIO;
1215}
1216
1217
1218static int
1219sisusbcon_font_set(struct vc_data *c, struct console_font *font,
1220 unsigned int flags)
1221{
1222 struct sisusb_usb_data *sisusb;
1223 unsigned charcount = font->charcount;
1224
1225 if (font->width != 8 || (charcount != 256 && charcount != 512))
1226 return -EINVAL;
1227
1228 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
1229 if (!sisusb)
1230 return -ENODEV;
1231
1232
1233
1234
1235
1236
1237
1238 if (sisusb->font_backup) {
1239 if (sisusb->font_backup_size < charcount) {
1240 vfree(sisusb->font_backup);
1241 sisusb->font_backup = NULL;
1242 }
1243 }
1244
1245 if (!sisusb->font_backup)
1246 sisusb->font_backup = vmalloc(array_size(charcount, 32));
1247
1248 if (sisusb->font_backup) {
1249 memcpy(sisusb->font_backup, font->data, charcount * 32);
1250 sisusb->font_backup_size = charcount;
1251 sisusb->font_backup_height = font->height;
1252 sisusb->font_backup_512 = (charcount == 512) ? 1 : 0;
1253 }
1254
1255
1256
1257 return sisusbcon_do_font_op(sisusb, 1, 2, font->data,
1258 8192, (charcount == 512),
1259 (!(flags & KD_FONT_FLAG_DONT_RECALC)) ? 1 : 0,
1260 c, font->height, 1);
1261}
1262
1263
1264static int
1265sisusbcon_font_get(struct vc_data *c, struct console_font *font)
1266{
1267 struct sisusb_usb_data *sisusb;
1268
1269 sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num);
1270 if (!sisusb)
1271 return -ENODEV;
1272
1273
1274
1275 font->width = 8;
1276 font->height = c->vc_font.height;
1277 font->charcount = 256;
1278
1279 if (!font->data) {
1280 mutex_unlock(&sisusb->lock);
1281 return 0;
1282 }
1283
1284 if (!sisusb->font_backup) {
1285 mutex_unlock(&sisusb->lock);
1286 return -ENODEV;
1287 }
1288
1289
1290 memcpy(font->data, sisusb->font_backup, 256 * 32);
1291
1292 mutex_unlock(&sisusb->lock);
1293
1294 return 0;
1295}
1296
1297
1298
1299
1300
1301static const struct consw sisusb_con = {
1302 .owner = THIS_MODULE,
1303 .con_startup = sisusbcon_startup,
1304 .con_init = sisusbcon_init,
1305 .con_deinit = sisusbcon_deinit,
1306 .con_clear = sisusbcon_clear,
1307 .con_putc = sisusbcon_putc,
1308 .con_putcs = sisusbcon_putcs,
1309 .con_cursor = sisusbcon_cursor,
1310 .con_scroll = sisusbcon_scroll,
1311 .con_switch = sisusbcon_switch,
1312 .con_blank = sisusbcon_blank,
1313 .con_font_set = sisusbcon_font_set,
1314 .con_font_get = sisusbcon_font_get,
1315 .con_set_palette = sisusbcon_set_palette,
1316 .con_scrolldelta = sisusbcon_scrolldelta,
1317 .con_build_attr = sisusbcon_build_attr,
1318 .con_invert_region = sisusbcon_invert_region,
1319 .con_set_origin = sisusbcon_set_origin,
1320 .con_save_screen = sisusbcon_save_screen,
1321 .con_resize = sisusbcon_resize,
1322};
1323
1324
1325
1326static const char *sisusbdummycon_startup(void)
1327{
1328 return "SISUSBVGADUMMY";
1329}
1330
1331static void sisusbdummycon_init(struct vc_data *vc, int init)
1332{
1333 vc->vc_can_do_color = 1;
1334 if (init) {
1335 vc->vc_cols = 80;
1336 vc->vc_rows = 25;
1337 } else
1338 vc_resize(vc, 80, 25);
1339}
1340
1341static void sisusbdummycon_deinit(struct vc_data *vc) { }
1342static void sisusbdummycon_clear(struct vc_data *vc, int sy, int sx,
1343 int height, int width) { }
1344static void sisusbdummycon_putc(struct vc_data *vc, int c, int ypos,
1345 int xpos) { }
1346static void sisusbdummycon_putcs(struct vc_data *vc, const unsigned short *s,
1347 int count, int ypos, int xpos) { }
1348static void sisusbdummycon_cursor(struct vc_data *vc, int mode) { }
1349
1350static bool sisusbdummycon_scroll(struct vc_data *vc, unsigned int top,
1351 unsigned int bottom, enum con_scroll dir,
1352 unsigned int lines)
1353{
1354 return false;
1355}
1356
1357static int sisusbdummycon_switch(struct vc_data *vc)
1358{
1359 return 0;
1360}
1361
1362static int sisusbdummycon_blank(struct vc_data *vc, int blank, int mode_switch)
1363{
1364 return 0;
1365}
1366
1367static int sisusbdummycon_font_set(struct vc_data *vc,
1368 struct console_font *font,
1369 unsigned int flags)
1370{
1371 return 0;
1372}
1373
1374static int sisusbdummycon_font_default(struct vc_data *vc,
1375 struct console_font *font, char *name)
1376{
1377 return 0;
1378}
1379
1380static int sisusbdummycon_font_copy(struct vc_data *vc, int con)
1381{
1382 return 0;
1383}
1384
1385static const struct consw sisusb_dummy_con = {
1386 .owner = THIS_MODULE,
1387 .con_startup = sisusbdummycon_startup,
1388 .con_init = sisusbdummycon_init,
1389 .con_deinit = sisusbdummycon_deinit,
1390 .con_clear = sisusbdummycon_clear,
1391 .con_putc = sisusbdummycon_putc,
1392 .con_putcs = sisusbdummycon_putcs,
1393 .con_cursor = sisusbdummycon_cursor,
1394 .con_scroll = sisusbdummycon_scroll,
1395 .con_switch = sisusbdummycon_switch,
1396 .con_blank = sisusbdummycon_blank,
1397 .con_font_set = sisusbdummycon_font_set,
1398 .con_font_default = sisusbdummycon_font_default,
1399 .con_font_copy = sisusbdummycon_font_copy,
1400};
1401
1402int
1403sisusb_console_init(struct sisusb_usb_data *sisusb, int first, int last)
1404{
1405 int i, ret;
1406
1407 mutex_lock(&sisusb->lock);
1408
1409
1410 if (sisusb->haveconsole || !sisusb->SiS_Pr) {
1411 mutex_unlock(&sisusb->lock);
1412 return 1;
1413 }
1414
1415 sisusb->con_first = first;
1416 sisusb->con_last = last;
1417
1418 if (first > last ||
1419 first > MAX_NR_CONSOLES ||
1420 last > MAX_NR_CONSOLES) {
1421 mutex_unlock(&sisusb->lock);
1422 return 1;
1423 }
1424
1425
1426 if (!sisusb->gfxinit || first < 1 || last < 1) {
1427 mutex_unlock(&sisusb->lock);
1428 return 0;
1429 }
1430
1431 sisusb->sisusb_cursor_loc = -1;
1432 sisusb->sisusb_cursor_size_from = -1;
1433 sisusb->sisusb_cursor_size_to = -1;
1434
1435
1436 if (sisusb_reset_text_mode(sisusb, 1)) {
1437 mutex_unlock(&sisusb->lock);
1438 dev_err(&sisusb->sisusb_dev->dev, "Failed to set up text mode\n");
1439 return 1;
1440 }
1441
1442
1443 sisusb_initialize(sisusb);
1444
1445 for (i = first - 1; i <= last - 1; i++) {
1446
1447 mysisusbs[i] = sisusb;
1448 }
1449
1450
1451 sisusb->sisusb_num_columns = 80;
1452
1453
1454 sisusb->scrbuf_size = 32 * 1024;
1455
1456
1457 if (!(sisusb->scrbuf = (unsigned long)vmalloc(sisusb->scrbuf_size))) {
1458 mutex_unlock(&sisusb->lock);
1459 dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate screen buffer\n");
1460 return 1;
1461 }
1462
1463 mutex_unlock(&sisusb->lock);
1464
1465
1466 console_lock();
1467 ret = do_take_over_console(&sisusb_con, first - 1, last - 1, 0);
1468 console_unlock();
1469 if (!ret)
1470 sisusb->haveconsole = 1;
1471 else {
1472 for (i = first - 1; i <= last - 1; i++)
1473 mysisusbs[i] = NULL;
1474 }
1475
1476 return ret;
1477}
1478
1479void
1480sisusb_console_exit(struct sisusb_usb_data *sisusb)
1481{
1482 int i;
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510 if (sisusb->haveconsole) {
1511 for (i = 0; i < MAX_NR_CONSOLES; i++)
1512 if (sisusb->havethisconsole[i]) {
1513 console_lock();
1514 do_take_over_console(&sisusb_dummy_con, i, i, 0);
1515 console_unlock();
1516
1517
1518
1519 }
1520 sisusb->haveconsole = 0;
1521 }
1522
1523 vfree((void *)sisusb->scrbuf);
1524 sisusb->scrbuf = 0;
1525
1526 vfree(sisusb->font_backup);
1527 sisusb->font_backup = NULL;
1528}
1529
1530void __init sisusb_init_concode(void)
1531{
1532 int i;
1533
1534 for (i = 0; i < MAX_NR_CONSOLES; i++)
1535 mysisusbs[i] = NULL;
1536}
1537
1538#endif
1539
1540
1541
1542