^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * linux/drivers/video/mdacon.c -- Low level MDA based console driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * (c) 1998 Andrew Apted <ajapted@netspace.net.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * including portions (c) 1995-1998 Patrick Caulfield.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * slight improvements (c) 2000 Edward Betts <edward@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This file is based on the VGA console driver (vgacon.c):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Created 28 Sep 1997 by Geert Uytterhoeven
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Rewritten by Martin Mares <mj@ucw.cz>, July 1998
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * and on the old console.c, vga.c and vesa_blank.c drivers:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * 1995 Jay Estabrook
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * License. See the file COPYING in the main directory of this archive for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * Changelog:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Paul G. (03/2001) Fix mdacon= boot prompt to use __setup().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/kd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/vt_kern.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/vt_buffer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/selection.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <asm/vga.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static DEFINE_SPINLOCK(mda_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* description of the hardware layout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static u16 *mda_vram_base; /* Base of video memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static unsigned long mda_vram_len; /* Size of video memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static unsigned int mda_num_columns; /* Number of text columns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static unsigned int mda_num_lines; /* Number of text lines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static unsigned int mda_index_port; /* Register select port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static unsigned int mda_value_port; /* Register value port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static unsigned int mda_mode_port; /* Mode control port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static unsigned int mda_status_port; /* Status and Config port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static unsigned int mda_gfx_port; /* Graphics control port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* current hardware state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static int mda_cursor_loc=-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static int mda_cursor_size_from=-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static int mda_cursor_size_to=-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static enum { TYPE_MDA, TYPE_HERC, TYPE_HERCPLUS, TYPE_HERCCOLOR } mda_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static char *mda_type_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* console information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static int mda_first_vc = 13;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static int mda_last_vc = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static struct vc_data *mda_display_fg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) module_param(mda_first_vc, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) MODULE_PARM_DESC(mda_first_vc, "First virtual console. Default: 13");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) module_param(mda_last_vc, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) MODULE_PARM_DESC(mda_last_vc, "Last virtual console. Default: 16");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* MDA register values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define MDA_CURSOR_BLINKING 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define MDA_CURSOR_OFF 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define MDA_CURSOR_SLOWBLINK 0x60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define MDA_MODE_GRAPHICS 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define MDA_MODE_VIDEO_EN 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define MDA_MODE_BLINK_EN 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define MDA_MODE_GFX_PAGE1 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define MDA_STATUS_HSYNC 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define MDA_STATUS_VSYNC 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define MDA_STATUS_VIDEO 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define MDA_CONFIG_COL132 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define MDA_GFX_MODE_EN 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define MDA_GFX_PAGE_EN 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * MDA could easily be classified as "pre-dinosaur hardware".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static void write_mda_b(unsigned int val, unsigned char reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) spin_lock_irqsave(&mda_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) outb_p(reg, mda_index_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) outb_p(val, mda_value_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) spin_unlock_irqrestore(&mda_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static void write_mda_w(unsigned int val, unsigned char reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) spin_lock_irqsave(&mda_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) outb_p(reg, mda_index_port); outb_p(val >> 8, mda_value_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) outb_p(reg+1, mda_index_port); outb_p(val & 0xff, mda_value_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) spin_unlock_irqrestore(&mda_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #ifdef TEST_MDA_B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static int test_mda_b(unsigned char val, unsigned char reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) spin_lock_irqsave(&mda_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) outb_p(reg, mda_index_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) outb (val, mda_value_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) udelay(20); val = (inb_p(mda_value_port) == val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) spin_unlock_irqrestore(&mda_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static inline void mda_set_cursor(unsigned int location)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (mda_cursor_loc == location)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) write_mda_w(location >> 1, 0x0e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) mda_cursor_loc = location;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static inline void mda_set_cursor_size(int from, int to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (mda_cursor_size_from==from && mda_cursor_size_to==to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (from > to) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) write_mda_b(MDA_CURSOR_OFF, 0x0a); /* disable cursor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) write_mda_b(from, 0x0a); /* cursor start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) write_mda_b(to, 0x0b); /* cursor end */
^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) mda_cursor_size_from = from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) mda_cursor_size_to = to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #ifndef MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int __init mdacon_setup(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /* command line format: mdacon=<first>,<last> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int ints[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) str = get_options(str, ARRAY_SIZE(ints), ints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (ints[0] < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (ints[1] < 1 || ints[1] > MAX_NR_CONSOLES ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) ints[2] < 1 || ints[2] > MAX_NR_CONSOLES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) mda_first_vc = ints[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) mda_last_vc = ints[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) __setup("mdacon=", mdacon_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int mda_detect(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int count=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) u16 *p, p_save;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) u16 *q, q_save;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* do a memory check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) p = mda_vram_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) q = mda_vram_base + 0x01000 / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) p_save = scr_readw(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) q_save = scr_readw(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) scr_writew(0xAA55, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (scr_readw(p) == 0xAA55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) scr_writew(0x55AA, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (scr_readw(p) == 0x55AA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) scr_writew(p_save, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (count != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* check if we have 4K or 8K */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) scr_writew(0xA55A, q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) scr_writew(0x0000, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (scr_readw(q) == 0xA55A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) scr_writew(0x5AA5, q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) scr_writew(0x0000, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (scr_readw(q) == 0x5AA5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) scr_writew(p_save, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) scr_writew(q_save, q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (count == 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) mda_vram_len = 0x02000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* Ok, there is definitely a card registering at the correct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * memory location, so now we do an I/O port test.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) #ifdef TEST_MDA_B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* Edward: These two mess `tests' mess up my cursor on bootup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* cursor low register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (!test_mda_b(0x66, 0x0f))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /* cursor low register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (!test_mda_b(0x99, 0x0f))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /* See if the card is a Hercules, by checking whether the vsync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * bit of the status register is changing. This test lasts for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * approximately 1/10th of a second.
^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) p_save = q_save = inb_p(mda_status_port) & MDA_STATUS_VSYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) for (count = 0; count < 50000 && p_save == q_save; count++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) q_save = inb(mda_status_port) & MDA_STATUS_VSYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (p_save != q_save) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) switch (inb_p(mda_status_port) & 0x70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) case 0x10:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) mda_type = TYPE_HERCPLUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) mda_type_name = "HerculesPlus";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) case 0x50:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) mda_type = TYPE_HERCCOLOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) mda_type_name = "HerculesColor";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) mda_type = TYPE_HERC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) mda_type_name = "Hercules";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) break;
^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) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static void mda_initialize(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) write_mda_b(97, 0x00); /* horizontal total */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) write_mda_b(80, 0x01); /* horizontal displayed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) write_mda_b(82, 0x02); /* horizontal sync pos */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) write_mda_b(15, 0x03); /* horizontal sync width */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) write_mda_b(25, 0x04); /* vertical total */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) write_mda_b(6, 0x05); /* vertical total adjust */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) write_mda_b(25, 0x06); /* vertical displayed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) write_mda_b(25, 0x07); /* vertical sync pos */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) write_mda_b(2, 0x08); /* interlace mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) write_mda_b(13, 0x09); /* maximum scanline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) write_mda_b(12, 0x0a); /* cursor start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) write_mda_b(13, 0x0b); /* cursor end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) write_mda_w(0x0000, 0x0c); /* start address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) write_mda_w(0x0000, 0x0e); /* cursor location */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) outb_p(MDA_MODE_VIDEO_EN | MDA_MODE_BLINK_EN, mda_mode_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) outb_p(0x00, mda_status_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) outb_p(0x00, mda_gfx_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static const char *mdacon_startup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) mda_num_columns = 80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) mda_num_lines = 25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) mda_vram_len = 0x01000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) mda_vram_base = (u16 *)VGA_MAP_MEM(0xb0000, mda_vram_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) mda_index_port = 0x3b4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) mda_value_port = 0x3b5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) mda_mode_port = 0x3b8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) mda_status_port = 0x3ba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) mda_gfx_port = 0x3bf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) mda_type = TYPE_MDA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) mda_type_name = "MDA";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (! mda_detect()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) printk("mdacon: MDA card not detected.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (mda_type != TYPE_MDA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) mda_initialize();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* cursor looks ugly during boot-up, so turn it off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) mda_set_cursor(mda_vram_len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) printk("mdacon: %s with %ldK of memory detected.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) mda_type_name, mda_vram_len/1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return "MDA-2";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static void mdacon_init(struct vc_data *c, int init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) c->vc_complement_mask = 0x0800; /* reverse video */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) c->vc_display_fg = &mda_display_fg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) c->vc_cols = mda_num_columns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) c->vc_rows = mda_num_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) vc_resize(c, mda_num_columns, mda_num_lines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /* make the first MDA console visible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (mda_display_fg == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) mda_display_fg = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) static void mdacon_deinit(struct vc_data *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) /* con_set_default_unimap(c->vc_num); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (mda_display_fg == c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) mda_display_fg = NULL;
^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 inline u16 mda_convert_attr(u16 ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) u16 attr = 0x0700;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /* Underline and reverse-video are mutually exclusive on MDA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) * Since reverse-video is used for cursors and selected areas,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * it takes precedence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (ch & 0x0800) attr = 0x7000; /* reverse */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) else if (ch & 0x0400) attr = 0x0100; /* underline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return ((ch & 0x0200) << 2) | /* intensity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) (ch & 0x8000) | /* blink */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) (ch & 0x00ff) | attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static u8 mdacon_build_attr(struct vc_data *c, u8 color,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) enum vc_intensity intensity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) bool blink, bool underline, bool reverse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) bool italic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /* The attribute is just a bit vector:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) * Bit 0..1 : intensity (0..2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) * Bit 2 : underline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) * Bit 3 : reverse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) * Bit 7 : blink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) return (intensity & VCI_MASK) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) (underline << 2) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) (reverse << 3) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) (italic << 4) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) (blink << 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static void mdacon_invert_region(struct vc_data *c, u16 *p, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) for (; count > 0; count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) scr_writew(scr_readw(p) ^ 0x0800, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static inline u16 *mda_addr(unsigned int x, unsigned int y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return mda_vram_base + y * mda_num_columns + x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static void mdacon_putc(struct vc_data *c, int ch, int y, int x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) scr_writew(mda_convert_attr(ch), mda_addr(x, y));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static void mdacon_putcs(struct vc_data *c, const unsigned short *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) int count, int y, int x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) u16 *dest = mda_addr(x, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) for (; count > 0; count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) scr_writew(mda_convert_attr(scr_readw(s++)), dest++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static void mdacon_clear(struct vc_data *c, int y, int x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) int height, int width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) u16 *dest = mda_addr(x, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) u16 eattr = mda_convert_attr(c->vc_video_erase_char);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (width <= 0 || height <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (x==0 && width==mda_num_columns) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) scr_memsetw(dest, eattr, height*width*2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) for (; height > 0; height--, dest+=mda_num_columns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) scr_memsetw(dest, eattr, width*2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) static int mdacon_switch(struct vc_data *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) return 1; /* redrawing needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static int mdacon_blank(struct vc_data *c, int blank, int mode_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if (mda_type == TYPE_MDA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (blank)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) scr_memsetw(mda_vram_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) mda_convert_attr(c->vc_video_erase_char),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) c->vc_screenbuf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) /* Tell console.c that it has to restore the screen itself */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (blank)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) outb_p(0x00, mda_mode_port); /* disable video */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) outb_p(MDA_MODE_VIDEO_EN | MDA_MODE_BLINK_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) mda_mode_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) static void mdacon_cursor(struct vc_data *c, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (mode == CM_ERASE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) mda_set_cursor(mda_vram_len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) mda_set_cursor(c->state.y * mda_num_columns * 2 + c->state.x * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) switch (CUR_SIZE(c->vc_cursor_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) case CUR_LOWER_THIRD: mda_set_cursor_size(10, 13); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) case CUR_LOWER_HALF: mda_set_cursor_size(7, 13); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) case CUR_TWO_THIRDS: mda_set_cursor_size(4, 13); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) case CUR_BLOCK: mda_set_cursor_size(1, 13); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) case CUR_NONE: mda_set_cursor_size(14, 13); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) default: mda_set_cursor_size(12, 13); break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) static bool mdacon_scroll(struct vc_data *c, unsigned int t, unsigned int b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) enum con_scroll dir, unsigned int lines)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) u16 eattr = mda_convert_attr(c->vc_video_erase_char);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (!lines)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (lines > c->vc_rows) /* maximum realistic size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) lines = c->vc_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) switch (dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) case SM_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) scr_memmovew(mda_addr(0, t), mda_addr(0, t + lines),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) (b-t-lines)*mda_num_columns*2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) scr_memsetw(mda_addr(0, b - lines), eattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) lines*mda_num_columns*2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) case SM_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) scr_memmovew(mda_addr(0, t + lines), mda_addr(0, t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) (b-t-lines)*mda_num_columns*2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) scr_memsetw(mda_addr(0, t), eattr, lines*mda_num_columns*2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) * The console `switch' structure for the MDA based console
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) static const struct consw mda_con = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) .con_startup = mdacon_startup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) .con_init = mdacon_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) .con_deinit = mdacon_deinit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) .con_clear = mdacon_clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) .con_putc = mdacon_putc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) .con_putcs = mdacon_putcs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) .con_cursor = mdacon_cursor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) .con_scroll = mdacon_scroll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) .con_switch = mdacon_switch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) .con_blank = mdacon_blank,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) .con_build_attr = mdacon_build_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) .con_invert_region = mdacon_invert_region,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) int __init mda_console_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if (mda_first_vc > mda_last_vc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) console_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) err = do_take_over_console(&mda_con, mda_first_vc-1, mda_last_vc-1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) console_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static void __exit mda_console_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) give_up_console(&mda_con);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) module_init(mda_console_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) module_exit(mda_console_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)