/* * linux/drivers/char/vga.c * * Copyright (C) 1991, 1992 Linus Torvalds * 1995 Jay Estabrook */ /* * vga.c * * This module exports the console low-level io support for VGA * * 'int con_get_font(char *data)' * 'int con_set_font(char *data, int ch512)' * 'int con_adjust_height(int fontheight)' * * 'int con_get_cmap(char *)' * 'int con_set_cmap(char *)' * * 'int reset_palette(int currcons)' * 'void set_palette(void)' * * User definable mapping table and font loading by Eugene G. Crosser, * * * Improved loadable font/UTF-8 support by H. Peter Anvin * Feb-Sep 1995 * * Colour palette handling, by Simon Tatham * 17-Jun-95 * * if 512 char mode is already enabled don't re-enable it, * because it causes screen to flicker, by Mitja Horvat * 5-May-96 * * 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. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef __mips__ #include #include #include /* * The video control ports are mapped at virtual address * 0xe0200000 for the onboard S3 card */ #define PORT_BASE video_port_base unsigned long video_port_base; #endif #include #include #include #include #include #include #include #include #include #define CAN_LOAD_EGA_FONTS /* undefine if the user must not do this */ #define CAN_LOAD_PALETTE /* undefine if the user must not do this */ #define dac_reg (0x3c8) #define dac_val (0x3c9) #ifdef __powerpc__ #define VGA_OFFSET 0xC0000000; #else #define VGA_OFFSET 0x0 #endif /* * 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. */ static inline void write_vga(unsigned char reg, unsigned int val) { #ifndef SLOW_VGA unsigned int v1, v2; v1 = reg + (val & 0xff00); v2 = reg + 1 + ((val << 8) & 0xff00); outw(v1, video_port_reg); outw(v2, video_port_reg); #else outb_p(reg, video_port_reg); outb_p(val >> 8, video_port_val); outb_p(reg+1, video_port_reg); outb_p(val & 0xff, video_port_val); #endif } void set_palette (void) { int i, j ; if ((video_type != VIDEO_TYPE_VGAC && video_type != VIDEO_TYPE_PICA_S3 && video_type != VIDEO_TYPE_SNI_RM) || console_blanked || vt_cons[fg_console]->vc_mode == KD_GRAPHICS) return ; for (i=j=0; i<16; i++) { outb_p (color_table[i], dac_reg) ; outb_p (vc_cons[fg_console].d->vc_palette[j++]>>2, dac_val) ; outb_p (vc_cons[fg_console].d->vc_palette[j++]>>2, dac_val) ; outb_p (vc_cons[fg_console].d->vc_palette[j++]>>2, dac_val) ; } } void __set_origin(unsigned short offset) { clear_selection(); __origin = offset; write_vga(12, offset); } /* * Put the cursor just beyond the end of the display adaptor memory. */ void hide_cursor(void) { /* This is inefficient, we could just put the cursor at 0xffff, but perhaps the delays due to the inefficiency are useful for some hardware... */ write_vga(14, (video_mem_term - video_mem_base - 1)>>1); } void set_cursor(int currcons) { if (currcons != fg_console || console_blanked || vcmode == KD_GRAPHICS) return; if (__real_origin != __origin) __set_origin(__real_origin); if (deccm) { write_vga(14, (pos - video_mem_base)>>1); } else hide_cursor(); } __initfunc(unsigned long con_type_init(unsigned long kmem_start, const char **display_desc)) { #ifdef CONFIG_ACER_PICA_61 /* * This type of video is only available as 64bit on board display for * MIPS machines based on the PICA chipset. If the loader has detected * such a machine assume that we use that type of video. */ if (mips_machgroup == MACH_GROUP_JAZZ && mips_machtype == MACH_ACER_PICA_61) { can_do_color = 1; video_port_base = 0xe0200000; video_port_reg = 0x3d4; video_port_val = 0x3d5; video_type = VIDEO_TYPE_PICA_S3; video_mem_base = mips_vram_base; video_mem_term = video_mem_base + 0x8000; *display_desc = "PICA-S3"; /* * Don't request a region - the video ports are outside of * the normal port address range. * Initialize the cursor; the rest of the console code assumes * this has already been done by the BIOS ... */ outb_p(10, video_port_reg); outb_p(14, video_port_val); outb_p(11, video_port_reg); outb_p(15, video_port_val); } else #endif #ifdef CONFIG_SNI_RM200_PCI if (mips_machgroup == MACH_GROUP_SNI_RM && mips_machtype == MACH_SNI_RM200_PCI) { can_do_color = 1; video_port_base = SNI_PORT_BASE; video_port_reg = 0x3d4; video_port_val = 0x3d5; video_type = VIDEO_TYPE_SNI_RM; video_mem_base = 0xb00b8000; video_mem_term = video_mem_base + 0x8000; *display_desc = "VGA+"; /* * The SNI machine is pretty much a simple RISC PC; we * need to request the ports. */ request_region(0x3c0,32,"vga+"); } else #endif #ifdef CONFIG_DESKSTATION_RPC44 /* * KLUDGE -- imp */ if (mips_machgroup == MACH_GROUP_ARC && mips_machtype == MACH_DESKSTATION_RPC44) { /* XXX */ can_do_color = 1; video_port_base = RPC44_PORT_BASE; video_port_reg = 0x3d4; video_port_val = 0x3d5; video_type = VIDEO_TYPE_VGAC; video_mem_base = 0xa00a000; video_mem_term = video_mem_base + 0x8000; *display_desc = "IMP-HACK"; screen_info.orig_video_ega_bx = 0x11; screen_info.orig_video_mode = 8; /* not 7 */ screen_info.orig_video_isVGA = 1; /* * Don't request a region - the video ports are outside of * the normal port address range. */ } else #endif if (ORIG_VIDEO_MODE == 7) /* Is this a monochrome display? */ { video_mem_base = 0xb0000 + VGA_OFFSET; video_port_reg = 0x3b4; video_port_val = 0x3b5; if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10) { video_type = VIDEO_TYPE_EGAM; video_mem_term = 0xb8000 + VGA_OFFSET; *display_desc = "EGA+"; request_region(0x3b0,16,"ega"); } else { video_type = VIDEO_TYPE_MDA; video_mem_term = 0xb2000 + VGA_OFFSET; *display_desc = "*MDA"; request_region(0x3b0,12,"mda"); request_region(0x3bf, 1,"mda"); } } else /* If not, it is color. */ { can_do_color = 1; video_mem_term = 0xb8000 + VGA_OFFSET; video_port_reg = 0x3d4; video_port_val = 0x3d5; if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10) { int i ; video_mem_term = 0xc0000 + VGA_OFFSET; if (!ORIG_VIDEO_ISVGA) { video_type = VIDEO_TYPE_EGAC; *display_desc = "EGA"; request_region(0x3c0,32,"ega"); } else { video_type = VIDEO_TYPE_VGAC; *display_desc = "VGA+"; request_region(0x3c0,32,"vga+"); #ifdef VGA_CAN_DO_64KB /* * get 64K rather than 32K of video RAM. * This doesn't actually work on all "VGA" * controllers (it seems like setting MM=01 * and COE=1 isn't necessarily a good idea) */ video_mem_base = 0xa0000 + VGA_OFFSET; video_mem_term = 0xb0000 + VGA_OFFSET; outb_p (6, 0x3ce) ; outb_p (6, 0x3cf) ; #endif /* * Normalise the palette registers, to point * the 16 screen colours to the first 16 * DAC entries. */ for (i=0; i<16; i++) { inb_p (0x3da) ; outb_p (i, 0x3c0) ; outb_p (i, 0x3c0) ; } outb_p (0x20, 0x3c0) ; /* now set the DAC registers back to their * default values */ for (i=0; i<16; i++) { outb_p (color_table[i], 0x3c8) ; outb_p (default_red[i], 0x3c9) ; outb_p (default_grn[i], 0x3c9) ; outb_p (default_blu[i], 0x3c9) ; } } } else { video_type = VIDEO_TYPE_CGA; video_mem_term = 0xba000 + VGA_OFFSET; *display_desc = "*CGA"; request_region(0x3d4,2,"cga"); } } return kmem_start; } __initfunc(void con_type_init_finish(void)) { } void get_scrmem(int currcons) { memcpyw((unsigned short *)vc_scrbuf[currcons], (unsigned short *)origin, video_screen_size); origin = video_mem_start = (unsigned long)vc_scrbuf[currcons]; scr_end = video_mem_end = video_mem_start + video_screen_size; pos = origin + y*video_size_row + (x<<1); } void set_scrmem(int currcons, long offset) { #ifdef CONFIG_HGA /* This works with XFree86 1.2, 1.3 and 2.0 This code could be extended and made more generally useful if we could determine the actual video mode. It appears that this should be possible on a genuine Hercules card, but I (WM) haven't been able to read from any of the required registers on my clone card. */ /* This code should work with Hercules and MDA cards. */ if (video_type == VIDEO_TYPE_MDA) { if (vcmode == KD_TEXT) { /* Ensure that the card is in text mode. */ int i; static char herc_txt_tbl[12] = { 0x61,0x50,0x52,0x0f,0x19,6,0x19,0x19,2,0x0d,0x0b,0x0c }; outb_p(0, 0x3bf); /* Back to power-on defaults */ outb_p(0, 0x3b8); /* Blank the screen, select page 0, etc */ for ( i = 0 ; i < 12 ; i++ ) { outb_p(i, 0x3b4); outb_p(herc_txt_tbl[i], 0x3b5); } } #define HGA_BLINKER_ON 0x20 #define HGA_SCREEN_ON 8 /* Make sure that the hardware is not blanked */ outb_p(HGA_BLINKER_ON | HGA_SCREEN_ON, 0x3b8); } #endif CONFIG_HGA if (video_mem_term - video_mem_base < offset + video_screen_size) offset = 0; /* strange ... */ memcpyw((unsigned short *)(video_mem_base + offset), (unsigned short *) origin, video_screen_size); video_mem_start = video_mem_base; video_mem_end = video_mem_term; origin = video_mem_base + offset; scr_end = origin + video_screen_size; pos = origin + y*video_size_row + (x<<1); has_wrapped = 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 ((char *)(0xa0000)) /* Pauline Middelink reports that we should use 0xA0000 for the bwmap as well.. */ #define blackwmap ((char *)(0xa0000)) #define cmapsz 8192 #define attrib_port (0x3c0) #define seq_port_reg (0x3c4) #define seq_port_val (0x3c5) #define gr_port_reg (0x3ce) #define gr_port_val (0x3cf) int set_get_font(char * arg, int set, int ch512) { #ifdef CAN_LOAD_EGA_FONTS static int ch512enabled = 0; int i; char *charmap; int beg; unsigned short video_port_status = video_port_reg + 6; int font_select = 0x00; /* no use to "load" CGA... */ if (video_type == VIDEO_TYPE_EGAC || video_type == VIDEO_TYPE_VGAC || video_type == VIDEO_TYPE_PICA_S3 || video_type == VIDEO_TYPE_SNI_RM) { charmap = colourmap; beg = 0x0e; #ifdef VGA_CAN_DO_64KB if (video_type == VIDEO_TYPE_VGAC || video_type == VIDEO_TYPE_PICA_S3 || video_type == VIDEO_TYPE_SNI_RM) beg = 0x06; #endif } else if (video_type == VIDEO_TYPE_EGAM) { charmap = blackwmap; beg = 0x0a; } else return -EINVAL; if (arg) { i = verify_area(set ? VERIFY_READ : VERIFY_WRITE, (void *)arg, ch512 ? 2*cmapsz : cmapsz); if (i) return i; } else ch512 = 0; /* Default font is always 256 */ #ifdef BROKEN_GRAPHICS_PROGRAMS /* * All fonts are loaded in slot 0 (0:1 for 512 ch) */ if (!arg) return -EINVAL; /* Return to default font not supported */ video_font_is_default = 0; font_select = ch512 ? 0x04 : 0x00; #else /* * The default font is kept in slot 0 and is never touched. * A custom font is loaded in slot 2 (256 ch) or 2:3 (512 ch) */ if (set) { video_font_is_default = !arg; font_select = arg ? (ch512 ? 0x0e : 0x0a) : 0x00; } if ( !video_font_is_default ) charmap += 4*cmapsz; #endif cli(); outb_p( 0x00, seq_port_reg ); /* First, the sequencer */ outb_p( 0x01, seq_port_val ); /* Synchronous reset */ outb_p( 0x02, seq_port_reg ); outb_p( 0x04, seq_port_val ); /* CPU writes only to map 2 */ outb_p( 0x04, seq_port_reg ); outb_p( 0x07, seq_port_val ); /* Sequential addressing */ outb_p( 0x00, seq_port_reg ); outb_p( 0x03, seq_port_val ); /* Clear synchronous reset */ outb_p( 0x04, gr_port_reg ); /* Now, the graphics controller */ outb_p( 0x02, gr_port_val ); /* select map 2 */ outb_p( 0x05, gr_port_reg ); outb_p( 0x00, gr_port_val ); /* disable odd-even addressing */ outb_p( 0x06, gr_port_reg ); outb_p( 0x00, gr_port_val ); /* map start at A000:0000 */ sti(); if (arg) { if (set) for (i=0; i 32 || (video_type != VIDEO_TYPE_VGAC && video_type != VIDEO_TYPE_EGAC && video_type != VIDEO_TYPE_EGAM && video_type != VIDEO_TYPE_PICA_S3 && video_type != VIDEO_TYPE_SNI_RM)) return -EINVAL; if ( fontheight == video_font_height || fontheight == 0 ) return 0; video_font_height = fontheight; rows = video_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. */ cli(); outb_p( 0x07, video_port_reg ); /* CRTC overflow register */ ovr = inb_p(video_port_val); outb_p( 0x09, video_port_reg ); /* Font size register */ fsr = inb_p(video_port_val); outb_p( 0x0a, video_port_reg ); /* Cursor start */ curs = inb_p(video_port_val); outb_p( 0x0b, video_port_reg ); /* Cursor end */ cure = inb_p(video_port_val); sti(); vde = maxscan & 0xff; /* Vertical display end reg */ ovr = (ovr & 0xbd) + /* Overflow register */ ((maxscan & 0x100) >> 7) + ((maxscan & 0x200) >> 3); fsr = (fsr & 0xe0) + (fontheight-1); /* Font size register */ curs = (curs & 0xc0) + fontheight - (fontheight < 10 ? 2 : 3); cure = (cure & 0xe0) + fontheight - (fontheight < 10 ? 1 : 2); cli(); outb_p( 0x07, video_port_reg ); /* CRTC overflow register */ outb_p( ovr, video_port_val ); outb_p( 0x09, video_port_reg ); /* Font size */ outb_p( fsr, video_port_val ); outb_p( 0x0a, video_port_reg ); /* Cursor start */ outb_p( curs, video_port_val ); outb_p( 0x0b, video_port_reg ); /* Cursor end */ outb_p( cure, video_port_val ); outb_p( 0x12, video_port_reg ); /* Vertical display limit */ outb_p( vde, video_port_val ); sti(); if ( rows == video_num_lines ) { /* Change didn't affect number of lines -- no need to scare the rest of the world */ return 0; } vc_resize(rows, 0); /* Adjust console size */ return rows; } int set_get_cmap(unsigned char * arg, int set) { #ifdef CAN_LOAD_PALETTE int i; /* no use to set colourmaps in less than colour VGA */ if (video_type != VIDEO_TYPE_PICA_S3 && video_type != VIDEO_TYPE_SNI_RM && video_type != VIDEO_TYPE_VGAC) return -EINVAL; i = verify_area(set ? VERIFY_READ : VERIFY_WRITE, (void *)arg, 16*3); if (i) return i; for (i=0; i<16; i++) { if (set) { get_user(default_red[i], arg++) ; get_user(default_grn[i], arg++) ; get_user(default_blu[i], arg++) ; } else { put_user (default_red[i], arg++) ; put_user (default_grn[i], arg++) ; put_user (default_blu[i], arg++) ; } } if (set) { for (i=0; ivc_palette[k++] = default_red[j]; vc_cons[i].d->vc_palette[k++] = default_grn[j]; vc_cons[i].d->vc_palette[k++] = default_blu[j]; } } set_palette() ; } return 0; #else return -EINVAL; #endif }