Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *  linux/drivers/video/console/sticon.c - console driver using HP's STI firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *	Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *	Copyright (C) 2002-2020 Helge Deller <deller@gmx.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Based on linux/drivers/video/vgacon.c and linux/drivers/video/fbcon.c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  which were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *	Created 28 Sep 1997 by Geert Uytterhoeven
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *	Rewritten by Martin Mares <mj@ucw.cz>, July 1998
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *	Copyright (C) 1991, 1992  Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *			    1995  Jay Estabrook
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *	Copyright (C) 1995 Geert Uytterhoeven
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *	Copyright (C) 1993 Bjoern Brauel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *			   Roman Hodek
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *	Copyright (C) 1993 Hamish Macdonald
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *			   Greg Harp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *	Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *	      with work by William Rucklidge (wjr@cs.cornell.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *			   Geert Uytterhoeven
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *			   Jes Sorensen (jds@kom.auc.dk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *			   Martin Apel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *	      with work by Guenther Kelleter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *			   Martin Schaller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *			   Andreas Schwab
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *			   Emmanuel Marty (core@ggi-project.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *			   Jakub Jelinek (jj@ultra.linux.cz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *			   Martin Mares <mj@ucw.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *  This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *  License.  See the file COPYING in the main directory of this archive for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *  more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <linux/vt_kern.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <linux/kd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <linux/selection.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <linux/font.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #include "../fbdev/sticore.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) /* switching to graphics mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define BLANK 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static int vga_is_gfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define STI_DEF_FONT	sticon_sti->font
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) /* borrowed from fbcon.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define FNTREFCOUNT(fd)	(fd->refcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define FNTCRC(fd)	(fd->crc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static struct sti_cooked_font *font_data[MAX_NR_CONSOLES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) /* this is the sti_struct used for this console */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static struct sti_struct *sticon_sti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static const char *sticon_startup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)     return "STI console";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static void sticon_putc(struct vc_data *conp, int c, int ypos, int xpos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)     if (vga_is_gfx || console_blanked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	    return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)     if (conp->vc_mode != KD_TEXT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)     	    return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)     sti_putc(sticon_sti, c, ypos, xpos, font_data[conp->vc_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static void sticon_putcs(struct vc_data *conp, const unsigned short *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			 int count, int ypos, int xpos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)     if (vga_is_gfx || console_blanked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	    return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)     if (conp->vc_mode != KD_TEXT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)     	    return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)     while (count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	sti_putc(sticon_sti, scr_readw(s++), ypos, xpos++,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		 font_data[conp->vc_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static void sticon_cursor(struct vc_data *conp, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)     unsigned short car1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)     /* no cursor update if screen is blanked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)     if (vga_is_gfx || console_blanked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)     car1 = conp->vc_screenbuf[conp->state.x + conp->state.y * conp->vc_cols];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)     switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)     case CM_ERASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	sti_putc(sticon_sti, car1, conp->state.y, conp->state.x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		 font_data[conp->vc_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)     case CM_MOVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)     case CM_DRAW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	switch (CUR_SIZE(conp->vc_cursor_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	case CUR_UNDERLINE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	case CUR_LOWER_THIRD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	case CUR_LOWER_HALF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	case CUR_TWO_THIRDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	case CUR_BLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	    sti_putc(sticon_sti, (car1 & 255) + (0 << 8) + (7 << 11),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		     conp->state.y, conp->state.x, font_data[conp->vc_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	    break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static bool sticon_scroll(struct vc_data *conp, unsigned int t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		unsigned int b, enum con_scroll dir, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)     struct sti_struct *sti = sticon_sti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)     if (vga_is_gfx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)         return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)     sticon_cursor(conp, CM_ERASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)     switch (dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)     case SM_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	sti_bmove(sti, t + count, 0, t, 0, b - t - count, conp->vc_cols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		  font_data[conp->vc_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	sti_clear(sti, b - count, 0, count, conp->vc_cols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		  conp->vc_video_erase_char, font_data[conp->vc_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)     case SM_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	sti_bmove(sti, t, 0, t + count, 0, b - t - count, conp->vc_cols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		  font_data[conp->vc_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	sti_clear(sti, t, 0, count, conp->vc_cols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		  conp->vc_video_erase_char, font_data[conp->vc_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)     return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int sticon_set_def_font(int unit, struct console_font *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (font_data[unit] != STI_DEF_FONT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		if (--FNTREFCOUNT(font_data[unit]) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			kfree(font_data[unit]->raw_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			kfree(font_data[unit]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		font_data[unit] = STI_DEF_FONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static int sticon_set_font(struct vc_data *vc, struct console_font *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct sti_struct *sti = sticon_sti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	int vc_cols, vc_rows, vc_old_cols, vc_old_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	int unit = vc->vc_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	int w = op->width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	int h = op->height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	int size, i, bpc, pitch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct sti_rom_font *new_font;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct sti_cooked_font *cooked_font;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	unsigned char *data = op->data, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if ((w < 6) || (h < 6) || (w > 32) || (h > 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	    || (op->charcount != 256 && op->charcount != 512))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	pitch = ALIGN(w, 8) / 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	bpc = pitch * h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	size = bpc * op->charcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	new_font = kmalloc(sizeof(*new_font) + size, STI_LOWMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (!new_font)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	new_font->first_char = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	new_font->last_char = op->charcount - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	new_font->width = w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	new_font->height = h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	new_font->font_type = STI_FONT_HPROMAN8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	new_font->bytes_per_char = bpc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	new_font->underline_height = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	new_font->underline_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (!cooked_font) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		kfree(new_font);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	cooked_font->raw = new_font;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	cooked_font->raw_ptr = new_font;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	cooked_font->width = w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	cooked_font->height = h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	FNTREFCOUNT(cooked_font) = 0;	/* usage counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	p = (unsigned char *) new_font;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	p += sizeof(*new_font);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	for (i = 0; i < op->charcount; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		memcpy(p, data, bpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		data += pitch*32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		p += bpc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	FNTCRC(cooked_font) = crc32(0, new_font, size + sizeof(*new_font));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	sti_font_convert_bytemode(sti, cooked_font);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	new_font = cooked_font->raw_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	/* check if font is already used by other console */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	for (i = 0; i < MAX_NR_CONSOLES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		if (font_data[i] != STI_DEF_FONT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		    && (FNTCRC(font_data[i]) == FNTCRC(cooked_font))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			kfree(new_font);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			kfree(cooked_font);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			/* current font is the same as the new one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			if (i == unit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			cooked_font = font_data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			new_font = cooked_font->raw_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	/* clear screen with old font: we now may have less rows */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	vc_old_rows = vc->vc_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	vc_old_cols = vc->vc_cols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	sti_clear(sticon_sti, 0, 0, vc_old_rows, vc_old_cols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		  vc->vc_video_erase_char, font_data[vc->vc_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	/* delete old font in case it is a user font */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	sticon_set_def_font(unit, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	FNTREFCOUNT(cooked_font)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	font_data[unit] = cooked_font;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	vc_cols = sti_onscreen_x(sti) / cooked_font->width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	vc_rows = sti_onscreen_y(sti) / cooked_font->height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	vc_resize(vc, vc_cols, vc_rows);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	/* need to repaint screen if cols & rows are same as old font */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (vc_cols == vc_old_cols && vc_rows == vc_old_rows)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		update_screen(vc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static int sticon_font_default(struct vc_data *vc, struct console_font *op, char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	return sticon_set_def_font(vc->vc_num, op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static int sticon_font_set(struct vc_data *vc, struct console_font *font,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			   unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	return sticon_set_font(vc, font);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static void sticon_init(struct vc_data *c, int init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)     struct sti_struct *sti = sticon_sti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)     int vc_cols, vc_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)     sti_set(sti, 0, 0, sti_onscreen_y(sti), sti_onscreen_x(sti), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)     vc_cols = sti_onscreen_x(sti) / sti->font->width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)     vc_rows = sti_onscreen_y(sti) / sti->font->height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)     c->vc_can_do_color = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)     if (init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	c->vc_cols = vc_cols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	c->vc_rows = vc_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	vc_resize(c, vc_cols, vc_rows);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static void sticon_deinit(struct vc_data *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)     int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)     /* free memory used by user font */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)     for (i = 0; i < MAX_NR_CONSOLES; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	sticon_set_def_font(i, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static void sticon_clear(struct vc_data *conp, int sy, int sx, int height,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			 int width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)     if (!height || !width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)     sti_clear(sticon_sti, sy, sx, height, width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	      conp->vc_video_erase_char, font_data[conp->vc_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static int sticon_switch(struct vc_data *conp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)     return 1;	/* needs refreshing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) static int sticon_blank(struct vc_data *c, int blank, int mode_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)     if (blank == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (mode_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	    vga_is_gfx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)     sti_clear(sticon_sti, 0, 0, c->vc_rows, c->vc_cols, BLANK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	      font_data[c->vc_num]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)     if (mode_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	vga_is_gfx = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)     return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static u8 sticon_build_attr(struct vc_data *conp, u8 color,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			    enum vc_intensity intens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			    bool blink, bool underline, bool reverse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			    bool italic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	u8 fg = color & 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	u8 bg = (color & 0x70) >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	if (reverse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		return (fg << 3) | bg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		return (bg << 3) | fg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static void sticon_invert_region(struct vc_data *conp, u16 *p, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)     int col = 1; /* vga_can_do_color; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)     while (count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	u16 a = scr_readw(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	if (col)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		a = ((a & 0x0700) == 0x0100) ? 0x7000 : 0x7700;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	scr_writew(a, p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static const struct consw sti_con = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	.owner			= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	.con_startup		= sticon_startup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	.con_init		= sticon_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	.con_deinit		= sticon_deinit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	.con_clear		= sticon_clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	.con_putc		= sticon_putc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	.con_putcs		= sticon_putcs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	.con_cursor		= sticon_cursor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	.con_scroll		= sticon_scroll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	.con_switch		= sticon_switch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	.con_blank		= sticon_blank,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	.con_font_set		= sticon_font_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	.con_font_default	= sticon_font_default,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	.con_build_attr		= sticon_build_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	.con_invert_region	= sticon_invert_region, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static int __init sticonsole_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)     int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)     /* already initialized ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)     if (sticon_sti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	 return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)     sticon_sti = sti_get_rom(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)     if (!sticon_sti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)     for (i = 0; i < MAX_NR_CONSOLES; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	font_data[i] = STI_DEF_FONT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)     pr_info("sticon: Initializing STI text console.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)     console_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)     err = do_take_over_console(&sti_con, 0, MAX_NR_CONSOLES - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		PAGE0->mem_cons.cl_class != CL_DUPLEX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)     console_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)     return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) module_init(sticonsole_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) MODULE_LICENSE("GPL");