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