--- linux/drivers/char/console.c Mon May 28 09:03:04 2001 +++ linux/drivers/char/console.c Sun May 27 12:01:15 2001 @@ -2379,6 +2379,8 @@ if (conswitchp) display_desc = conswitchp->con_startup(); if (!display_desc) { + printk("WARNING: CONSOLE: no console driver initialized/available !\n"); + fg_console = 0; return; } --- linux/drivers/video/vgacon.c Sat May 26 23:13:23 2001 +++ linux/drivers/video/vgacon.c Mon May 28 09:40:42 2001 @@ -170,162 +170,228 @@ spin_unlock_irqrestore(&vga_lock, flags); } +/* + * Reorganized by Pdoru (Doru Petrescu pdoru@kappa.ro) + * + Added test to check the presence of vram/vcard before + * allocating any I/O resource + * + Added WARNING message if no VGA/EGA/MDA/CGA card was detected + * + * + * - vgacon_config_adapter() is called by vgacon_detect_adapter() + * - vgacon_detect_adapter() is called by vgacon_startup() + * - vgacon_startup() is called from console.c ... + * + * ** vgacon_startup() + * - see if we open a VGA console or just a DUMMY console untill + * the FrameBuffer console initialize + * - calls vgacon_detect_adapter() to attempt to detect a graphics card + * - warn if none was found + * + * ** vgacon_detect_adapter() + * - is this a monocrome video mode (mode 7) ? + * - YES: probes for EGA_MONO or MDA + * - NO: probes for EGA_COLOR or VGA_COLOR or CGA + * + * ** vgacon_config_adapter() + * - FIRST check to see if there is any VIDEO MEMORY present + * - generic configuration + * - per VIDEO_TYPE configuration + */ + +static const char __init *vgacon_config_adapter( + unsigned char video_type, + unsigned long vram_base, + unsigned long vram_end + ) { + + volatile u16 *p = (volatile u16 *) VGA_MAP_MEM(vram_base); + u16 saved1, saved2; + int ok = 0; + + + /* + * BEFORE we go any further, + * FIRST make sure there is a graphics card present. + * Are there smarter methods around? + */ + + saved1 = scr_readw(p); + saved2 = scr_readw(p + 1); + + scr_writew(0xAA55, p); + scr_writew(0x55AA, p + 1); + if (scr_readw(p) == 0xAA55) ok++; + if (scr_readw(p + 1) == 0x55AA) ok++; + + scr_writew(0x55AA, p); + scr_writew(0xAA55, p + 1); + if (scr_readw(p) == 0x55AA) ok++; + if (scr_readw(p + 1) == 0xAA55) ok++; + + scr_writew(saved1, p); + scr_writew(saved2, p + 1); + + if (ok < 4) return NULL; /* something is wrong with the video memory ... */ + + /* OK, it passed the test .... Huston, we have a video card ... */ + + + /* Generic VGA/EGA/MDA/CGA configuration part ... */ + + vga_vram_base = VGA_MAP_MEM( vram_base ); + vga_vram_end = VGA_MAP_MEM( vram_end ); + vga_video_type = video_type; + + vga_video_num_lines = ORIG_VIDEO_LINES; + vga_video_num_columns = ORIG_VIDEO_COLS; + + if ( vga_video_type == VIDEO_TYPE_EGAM || + vga_video_type == VIDEO_TYPE_MDA ) { + vga_can_do_color = 0; + vga_video_port_reg = 0x3b4; + vga_video_port_val = 0x3b5; + }else{ + vga_can_do_color = 1; + vga_video_port_reg = 0x3d4; + vga_video_port_val = 0x3d5; + } + + 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 = ORIG_VIDEO_POINTS; + vga_video_font_height = ORIG_VIDEO_POINTS; + /* This may be suboptimal but is a safe bet - go with it */ + video_scan_lines = vga_video_font_height * vga_video_num_lines; + } + video_font_height = vga_video_font_height; + + + /* Per adapter configuration part */ + + if (vga_video_type == VIDEO_TYPE_EGAM) { + static struct resource ega_console_resource = { "ega", 0x3B0, 0x3BF }; + request_resource(&ioport_resource, &ega_console_resource); + return "EGA+"; + } /* endif VIDEO_TYPE_EGAM */ + else + + if (vga_video_type == VIDEO_TYPE_MDA) { + static struct resource mda1_console_resource = { "mda", 0x3B0, 0x3BB }; + static struct resource mda2_console_resource = { "mda", 0x3BF, 0x3BF }; + vga_video_font_height = vga_default_font_height = 14; + + request_resource(&ioport_resource, &mda1_console_resource); + request_resource(&ioport_resource, &mda2_console_resource); + return "*MDA"; + } /* endif VIDEO_TYPE_MDA */ + else + + if (vga_video_type == VIDEO_TYPE_CGA) { + static struct resource cga_console_resource = { "cga", 0x3D4, 0x3D5 }; + vga_video_font_height = vga_default_font_height = 8; + request_resource(&ioport_resource, &cga_console_resource); + return "*CGA"; + } /* endif VIDEO_TYPE_CGA */ + else + + if (vga_video_type == VIDEO_TYPE_EGAC) { + static struct resource ega_console_resource = { "ega", 0x3C0, 0x3DF }; + request_resource(&ioport_resource, &ega_console_resource); + return "EGA"; + } /* endif VIDEO_TYPE_EGAC */ + else + + if (vga_video_type == VIDEO_TYPE_VGAC) { + int i; + static struct resource vga_console_resource = { "vga+", 0x3C0, 0x3DF }; + request_resource(&ioport_resource, &vga_console_resource); + + /* since we've got a VGA adapter, configure it a little more ... */ +#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) + */ + vga_vram_base = 0xa0000; + vga_vram_end = 0xb0000; + 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) ; + } + return "VGA+"; + } /* end if VIDEO_TYPE_VGAC */ + + return NULL; /* imposible case ... */ +} + +static const char __init *vgacon_detect_adapter(void) +{ + /* Is this a monochrome display ? */ + if (ORIG_VIDEO_MODE == 7) { + if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10) + return vgacon_config_adapter( VIDEO_TYPE_EGAM, 0xb0000, 0xb8000 ); + else return vgacon_config_adapter( VIDEO_TYPE_MDA, 0xb0000, 0xb2000 ); + } + + /* Then it is color display ! */ + if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10) { + if (!ORIG_VIDEO_ISVGA) + return vgacon_config_adapter( VIDEO_TYPE_EGAC, 0xb8000, 0xc0000 ); + else return vgacon_config_adapter( VIDEO_TYPE_VGAC, 0xb8000, 0xc0000 ); + } + + /* our last hope is to be a CGA ... */ + return vgacon_config_adapter( VIDEO_TYPE_CGA, 0xb8000, 0xba000 ); +} + static const char __init *vgacon_startup(void) { - const char *display_desc = NULL; - u16 saved1, saved2; - volatile u16 *p; + const char *display_desc = NULL; - if (ORIG_VIDEO_ISVGA == VIDEO_TYPE_VLFB) { - no_vga: + if (ORIG_VIDEO_ISVGA == VIDEO_TYPE_VLFB) { +no_vga: #ifdef CONFIG_DUMMY_CONSOLE - conswitchp = &dummy_con; - return conswitchp->con_startup(); + conswitchp = &dummy_con; + return conswitchp->con_startup(); #else - return NULL; + return NULL; #endif - } - - - vga_video_num_lines = ORIG_VIDEO_LINES; - vga_video_num_columns = ORIG_VIDEO_COLS; - - if (ORIG_VIDEO_MODE == 7) /* Is this a monochrome display? */ - { - vga_vram_base = 0xb0000; - vga_video_port_reg = 0x3b4; - vga_video_port_val = 0x3b5; - if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10) - { - static struct resource ega_console_resource = { "ega", 0x3B0, 0x3BF }; - vga_video_type = VIDEO_TYPE_EGAM; - vga_vram_end = 0xb8000; - display_desc = "EGA+"; - request_resource(&ioport_resource, &ega_console_resource); - } - else - { - static struct resource mda1_console_resource = { "mda", 0x3B0, 0x3BB }; - static struct resource mda2_console_resource = { "mda", 0x3BF, 0x3BF }; - vga_video_type = VIDEO_TYPE_MDA; - vga_vram_end = 0xb2000; - display_desc = "*MDA"; - request_resource(&ioport_resource, &mda1_console_resource); - request_resource(&ioport_resource, &mda2_console_resource); - vga_video_font_height = 14; - } - } - else /* If not, it is color. */ - { - vga_can_do_color = 1; - vga_vram_base = 0xb8000; - vga_video_port_reg = 0x3d4; - vga_video_port_val = 0x3d5; - if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10) - { - int i; - - vga_vram_end = 0xc0000; - - if (!ORIG_VIDEO_ISVGA) { - static struct resource ega_console_resource = { "ega", 0x3C0, 0x3DF }; - vga_video_type = VIDEO_TYPE_EGAC; - display_desc = "EGA"; - request_resource(&ioport_resource, &ega_console_resource); - } else { - static struct resource vga_console_resource = { "vga+", 0x3C0, 0x3DF }; - vga_video_type = VIDEO_TYPE_VGAC; - display_desc = "VGA+"; - request_resource(&ioport_resource, &vga_console_resource); - -#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) - */ - vga_vram_base = 0xa0000; - vga_vram_end = 0xb0000; - 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 - { - static struct resource cga_console_resource = { "cga", 0x3D4, 0x3D5 }; - vga_video_type = VIDEO_TYPE_CGA; - vga_vram_end = 0xba000; - display_desc = "*CGA"; - request_resource(&ioport_resource, &cga_console_resource); - vga_video_font_height = 8; - } - } - - vga_vram_base = VGA_MAP_MEM(vga_vram_base); - vga_vram_end = VGA_MAP_MEM(vga_vram_end); - - /* - * 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 = ORIG_VIDEO_POINTS; - vga_video_font_height = ORIG_VIDEO_POINTS; - /* This may be suboptimal but is a safe bet - go with it */ - video_scan_lines = - vga_video_font_height * vga_video_num_lines; - } - video_font_height = vga_video_font_height; + } - return display_desc; + display_desc = vgacon_detect_adapter(); + + if (display_desc == NULL) { + printk("WARNING: No VGA/EGA/MDA/CGA video adapter detected => VGA CONSOLE disabled\n"); + goto no_vga; + } + + return display_desc; } static void vgacon_init(struct vc_data *c, int init)