/* * linux/drivers/video/vgacon.c -- Low level VGA based console driver * * Created 28 Sep 1997 by Geert Uytterhoeven * * Rewritten by Martin Mares <mj@ucw.cz>, July 1998 * * This file is based on the old console.c, vga.c and vesa_blank.c drivers. * * Copyright (C) 1991, 1992 Linus Torvalds * 1995 Jay Estabrook * * User definable mapping table and font loading by Eugene G. Crosser, * <crosser@average.org> * * Improved loadable font/UTF-8 support by H. Peter Anvin * Feb-Sep 1995 <peter.anvin@linux.org> * * Colour palette handling, by Simon Tatham * 17-Jun-95 <sgt20@cam.ac.uk> * * if 512 char mode is already enabled don't re-enable it, * because it causes screen to flicker, by Mitja Horvat * 5-May-96 <mitja.horvat@guest.arnes.si> * * Use 2 outw instead of 4 outb_p to reduce erroneous text * flashing on RHS of screen during heavy console scrolling . * Oct 1996, Paul Gortmaker. * * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive for * more details.
*/
/* Description of the hardware situation */ staticunsignedlong vga_vram_base __read_mostly; /* Base of video memory */ staticunsignedlong vga_vram_end __read_mostly; /* End of video memory */ staticunsignedint vga_vram_size __read_mostly; /* Size of video memory */ static u16 vga_video_port_reg __read_mostly; /* Video register select port */ static u16 vga_video_port_val __read_mostly; /* Video register value port */ staticunsignedint vga_video_num_columns; /* Number of text columns */ staticunsignedint vga_video_num_lines; /* Number of text lines */ staticbool vga_can_do_color; /* Do we support colors? */ staticunsignedint vga_default_font_height __read_mostly; /* Height of default screen font */ staticunsignedchar vga_video_type __read_mostly; /* Card type */ staticenum vesa_blank_mode vga_vesa_blanked; staticbool vga_palette_blanked; staticbool vga_is_gfx; staticbool vga_512_chars; staticint vga_video_font_height; staticint vga_scan_lines __read_mostly; staticunsignedint vga_rolled_over; /* last vc_origin offset before wrap */
staticint __init no_scroll(char *str)
{ /* * Disabling scrollback is required for the Braillex ib80-piezo * Braille reader made by F.H. Papenmeier (Germany). * Use the "no-scroll" bootflag.
*/
vga_hardscroll_user_enable = vga_hardscroll_enabled = false; return 1;
}
__setup("no-scroll", no_scroll);
/* * By replacing the four outb_p with two back to back outw, we can reduce * the window of opportunity to see text mislocated to the RHS of the * console during heavy scrolling activity. However there is the remote * possibility that some pre-dinosaur hardware won't like the back to back * I/O. Since the Xservers get away with it, we should be able to as well.
*/ staticinlinevoid write_vga(unsignedchar reg, unsignedint val)
{ unsignedint v1, v2; unsignedlong flags;
/* * ddprintk might set the console position from interrupt * handlers, thus the write has to be IRQ-atomic.
*/
raw_spin_lock_irqsave(&vga_lock, flags);
v1 = reg + (val & 0xff00);
v2 = reg + 1 + ((val << 8) & 0xff00);
outw(v1, vga_video_port_reg);
outw(v2, vga_video_port_reg);
raw_spin_unlock_irqrestore(&vga_lock, flags);
}
/* Turn scrollback off */ if (!lines) {
c->vc_visible_origin = c->vc_origin; return;
}
/* Do we have already enough to allow jumping from 0 to the end? */ if (vga_rolled_over > scr_end + margin) {
from = scr_end;
wrap = vga_rolled_over + c->vc_size_row;
} else {
from = 0;
wrap = vga_vram_size;
}
/* Only a little piece would be left? Show all incl. the piece! */ if (avail < 2 * margin)
margin = 0; if (from_off < margin)
from_off = 0; if (from_off > avail - margin)
from_off = avail;
/* * Find out if there is a graphics card present. * Are there smarter methods around?
*/
p = (volatile u16 *) vga_vram_base;
saved1 = scr_readw(p);
saved2 = scr_readw(p + 1);
scr_writew(0xAA55, p);
scr_writew(0x55AA, p + 1); if (scr_readw(p) != 0xAA55 || scr_readw(p + 1) != 0x55AA) {
scr_writew(saved1, p);
scr_writew(saved2, p + 1); goto no_vga;
}
scr_writew(0x55AA, p);
scr_writew(0xAA55, p + 1); if (scr_readw(p) != 0x55AA || scr_readw(p + 1) != 0xAA55) {
scr_writew(saved1, p);
scr_writew(saved2, p + 1); goto no_vga;
}
scr_writew(saved1, p);
scr_writew(saved2, p + 1);
if (vga_video_type == VIDEO_TYPE_EGAC
|| vga_video_type == VIDEO_TYPE_VGAC
|| vga_video_type == VIDEO_TYPE_EGAM) {
vga_hardscroll_enabled = vga_hardscroll_user_enable;
vga_default_font_height = vga_si->orig_video_points;
vga_video_font_height = vga_si->orig_video_points; /* This may be suboptimal but is a safe bet - go with it */
vga_scan_lines =
vga_video_font_height * vga_video_num_lines;
}
/* * We cannot be loaded as a module, therefore init will be 1 * if we are the default console, however if we are a fallback * console, for example if fbcon has failed registration, then * init will be 0, so we need to make sure our boot parameters * have been copied to the console structure for vgacon_resize * ultimately called by vc_resize. Any subsequent calls to * vgacon_init init will have init set to 0 too.
*/
c->vc_can_do_color = vga_can_do_color;
c->vc_scan_lines = vga_scan_lines;
c->vc_font.height = c->vc_cell_height = vga_video_font_height;
/* set dimensions manually if init is true since vc_resize() will fail */ if (init) {
c->vc_cols = vga_video_num_columns;
c->vc_rows = vga_video_num_lines;
} else
vc_resize(c, vga_video_num_columns, vga_video_num_lines);
c->vc_complement_mask = 0x7700; if (vga_512_chars)
c->vc_hi_font_mask = 0x0800;
p = *c->uni_pagedict_loc; if (c->uni_pagedict_loc != &vgacon_uni_pagedir) {
con_free_unimap(c);
c->uni_pagedict_loc = &vgacon_uni_pagedir;
vgacon_refcount++;
} if (!vgacon_uni_pagedir && p)
con_set_default_unimap(c);
/* Only set the default if the user didn't deliberately override it */ if (global_cursor_default == -1)
global_cursor_default =
!(vga_si->flags & VIDEO_FLAGS_NOCURSOR);
}
staticvoid vgacon_deinit(struct vc_data *c)
{ /* When closing the active console, reset video origin */ if (con_is_visible(c)) {
c->vc_visible_origin = vga_vram_base;
vga_set_mem_top(c);
}
if (!--vgacon_refcount)
con_free_unimap(c);
c->uni_pagedict_loc = &c->uni_pagedict;
con_set_default_unimap(c);
}
staticbool vgacon_switch(struct vc_data *c)
{ int x = c->vc_cols * VGA_FONTWIDTH; int y = c->vc_rows * c->vc_cell_height; int rows = vga_si->orig_video_lines * vga_default_font_height/
c->vc_cell_height; /* * We need to save screen size here as it's the only way * we can spot the screen has been resized and we need to * set size of freshly allocated screens ourselves.
*/
vga_video_num_columns = c->vc_cols;
vga_video_num_lines = c->vc_rows;
/* We can only copy out the size of the video buffer here,
* otherwise we get into VGA BIOS */
/* assure that video is enabled */ /* "0x20" is VIDEO_ENABLE_bit in register 01 of sequencer */
raw_spin_lock_irq(&vga_lock);
vga_wseq(state->vgabase, VGA_SEQ_CLOCK_MODE, vga_state.ClockingMode | 0x20);
/* test for vertical retrace in process.... */ if ((vga_state.CrtMiscIO & 0x80) == 0x80)
vga_w(state->vgabase, VGA_MIS_W, vga_state.CrtMiscIO & 0xEF);
/* * Set <End of vertical retrace> to minimum (0) and * <Start of vertical Retrace> to maximum (incl. overflow) * Result: turn off vertical sync (VSync) pulse.
*/ if (mode & VESA_VSYNC_SUSPEND) {
outb_p(0x10, vga_video_port_reg); /* StartVertRetrace */
outb_p(0xff, vga_video_port_val); /* maximum value */
outb_p(0x11, vga_video_port_reg); /* EndVertRetrace */
outb_p(0x40, vga_video_port_val); /* minimum (bits 0..3) */
outb_p(0x07, vga_video_port_reg); /* Overflow */
outb_p(vga_state.Overflow | 0x84, vga_video_port_val); /* bits 9,10 of vert. retrace */
}
if (mode & VESA_HSYNC_SUSPEND) { /* * Set <End of horizontal retrace> to minimum (0) and * <Start of horizontal Retrace> to maximum * Result: turn off horizontal sync (HSync) pulse.
*/
outb_p(0x04, vga_video_port_reg); /* StartHorizRetrace */
outb_p(0xff, vga_video_port_val); /* maximum */
outb_p(0x05, vga_video_port_reg); /* EndHorizRetrace */
outb_p(0x00, vga_video_port_val); /* minimum (0) */
}
/* restore both index registers */
vga_w(state->vgabase, VGA_SEQ_I, vga_state.SeqCtrlIndex);
outb_p(vga_state.CrtCtrlIndex, vga_video_port_reg);
raw_spin_unlock_irq(&vga_lock);
}
staticvoid vga_vesa_unblank(struct vgastate *state)
{ /* restore original values of VGA controller registers */
raw_spin_lock_irq(&vga_lock);
vga_w(state->vgabase, VGA_MIS_W, vga_state.CrtMiscIO);
staticvoid vga_pal_blank(struct vgastate *state)
{ int i;
vga_w(state->vgabase, VGA_PEL_MSK, 0xff); for (i = 0; i < 16; i++) {
vga_w(state->vgabase, VGA_PEL_IW, i);
vga_w(state->vgabase, VGA_PEL_D, 0);
vga_w(state->vgabase, VGA_PEL_D, 0);
vga_w(state->vgabase, VGA_PEL_D, 0);
}
}
staticbool vgacon_blank(struct vc_data *c, enum vesa_blank_mode blank, bool mode_switch)
{ switch (blank) { case VESA_NO_BLANKING: /* Unblank */ if (vga_vesa_blanked) {
vga_vesa_unblank(&vgastate);
vga_vesa_blanked = VESA_NO_BLANKING;
} if (vga_palette_blanked) {
vga_set_palette(c, color_table);
vga_palette_blanked = false; return 0;
}
vga_is_gfx = false; /* Tell console.c that it has to restore the screen itself */ return 1; case VESA_VSYNC_SUSPEND: /* Normal blanking */ if (!mode_switch && vga_video_type == VIDEO_TYPE_VGAC) {
vga_pal_blank(&vgastate);
vga_palette_blanked = true; return 0;
}
vgacon_set_origin(c);
scr_memsetw((void *) vga_vram_base, BLANK,
c->vc_screenbuf_size); if (mode_switch)
vga_is_gfx = true; return 1; default: /* VESA blanking */ if (vga_video_type == VIDEO_TYPE_VGAC) {
vga_vesa_blank(&vgastate, blank - 1);
vga_vesa_blanked = blank;
} return 0;
}
}
/* * PIO_FONT support. * * The font loading code goes back to the codepage package by * Joel Hoffman (joel@wam.umd.edu). (He reports that the original * reference is: "From: p. 307 of _Programmer's Guide to PC & PS/2 * Video Systems_ by Richard Wilton. 1987. Microsoft Press".) * * Change for certain monochrome monitors by Yury Shevchuck * (sizif@botik.yaroslavl.su).
*/
#define colourmap 0xa0000 /* Pauline Middelink <middelin@polyware.iaf.nl> reports that we
should use 0xA0000 for the bwmap as well.. */ #define blackwmap 0xa0000 #define cmapsz 8192
if (arg) { if (set) for (i = 0; i < cmapsz; i++) {
vga_writeb(arg[i], charmap + i);
cond_resched();
} else for (i = 0; i < cmapsz; i++) {
arg[i] = vga_readb(charmap + i);
cond_resched();
}
/* * In 512-character mode, the character map is not contiguous if * we want to remain EGA compatible -- which we do
*/
if (ch512) {
charmap += 2 * cmapsz;
arg += cmapsz; if (set) for (i = 0; i < cmapsz; i++) {
vga_writeb(arg[i], charmap + i);
cond_resched();
} else for (i = 0; i < cmapsz; i++) {
arg[i] = vga_readb(charmap + i);
cond_resched();
}
}
}
raw_spin_lock_irq(&vga_lock); /* First, the sequencer, Synchronous reset */
vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x01); /* CPU writes to maps 0 and 1 */
vga_wseq(state->vgabase, VGA_SEQ_PLANE_WRITE, 0x03); /* odd-even addressing */
vga_wseq(state->vgabase, VGA_SEQ_MEMORY_MODE, 0x03); /* Character Map Select */ if (set)
vga_wseq(state->vgabase, VGA_SEQ_CHARACTER_MAP, font_select); /* clear synchronous reset */
vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x03);
/* Now, the graphics controller, select map 0 for CPU */
vga_wgfx(state->vgabase, VGA_GFX_PLANE_READ, 0x00); /* enable even-odd addressing */
vga_wgfx(state->vgabase, VGA_GFX_MODE, 0x10); /* map starts at b800:0 or b000:0 */
vga_wgfx(state->vgabase, VGA_GFX_MISC, beg);
/* if 512 char mode is already enabled don't re-enable it. */ if ((set) && (ch512 != vga_512_chars)) {
vga_512_chars = ch512; /* 256-char: enable intensity bit
512-char: disable intensity bit */
inb_p(video_port_status); /* clear address flip-flop */ /* color plane enable register */
vga_wattr(state->vgabase, VGA_ATC_PLANE_ENABLE, ch512 ? 0x07 : 0x0f); /* Wilton (1987) mentions the following; I don't know what
it means, but it works, and it appears necessary */
inb_p(video_port_status);
vga_wattr(state->vgabase, VGA_AR_ENABLE_DISPLAY, 0);
clear_attribs = true;
}
raw_spin_unlock_irq(&vga_lock);
if (clear_attribs) { for (i = 0; i < MAX_NR_CONSOLES; i++) { struct vc_data *c = vc_cons[i].d; if (c && c->vc_sw == &vga_con) { /* force hi font mask to 0, so we always clear
the bit on either transition */
c->vc_hi_font_mask = 0x00;
clear_buffer_attributes(c);
c->vc_hi_font_mask = ch512 ? 0x0800 : 0;
}
}
} return 0;
}
/* * Adjust the screen to fit a font of a certain height
*/ staticint vgacon_adjust_height(struct vc_data *vc, unsigned fontheight)
{ unsignedchar ovr, vde, fsr; int rows, maxscan, i;
rows = vc->vc_scan_lines / fontheight; /* Number of video rows we end up with */
maxscan = rows * fontheight - 1; /* Scan lines to actually display-1 */
/* Reprogram the CRTC for the new font size Note: the attempt to read the overflow register will fail on an EGA, but using 0xff for the previous value appears to be OK for EGA text modes in the range 257-512 scan lines, so I guess we don't need to worry about it.
The same applies for the spill bits in the font size and cursor registers; they are write-only on EGA, but it appears that they
are all don't care bits on EGA, so I guess it doesn't matter. */
if (from_user) { /* * Ho ho! Someone (svgatextmode, eh?) may have reprogrammed * the video mode! Set the new defaults then and go away.
*/
vga_si->orig_video_cols = width;
vga_si->orig_video_lines = height;
vga_default_font_height = c->vc_cell_height; return 0;
} if (width % 2 || width > vga_si->orig_video_cols ||
height > (vga_si->orig_video_lines * vga_default_font_height)/
c->vc_cell_height) return -EINVAL;
if (con_is_visible(c) && !vga_is_gfx) /* who knows */
vgacon_doresize(c, width, height); return 0;
}
staticbool vgacon_set_origin(struct vc_data *c)
{ if (vga_is_gfx || /* We don't play origin tricks in graphic modes */
(console_blanked && !vga_palette_blanked)) /* Nor we write to blanked screens */ returnfalse;
c->vc_origin = c->vc_visible_origin = vga_vram_base;
vga_set_mem_top(c);
vga_rolled_over = 0; returntrue;
}
if (!vga_bootup_console) { /* This is a gross hack, but here is the only place we can * set bootup console parameters without messing up generic * console initialization routines.
*/
vga_bootup_console = 1;
c->state.x = vga_si->orig_x;
c->state.y = vga_si->orig_y;
}
/* We can't copy in more than the size of the video buffer,
* or we'll be copying in VGA BIOS */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.