ia64/xen-unstable

changeset 11177:3e75d9b1d556

[XEN] vga code cleanups and additions for other architectures.
Based on patches from Hollis Blanchard and Alex Williamson.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Aug 16 18:20:03 2006 +0100 (2006-08-16)
parents 87165e688bc5
children 83003532d71f
files linux-2.6-xen-sparse/arch/ia64/dig/setup.c xen/arch/ia64/Rules.mk xen/arch/ia64/xen/domain.c xen/arch/ia64/xen/mm.c xen/arch/x86/Rules.mk xen/arch/x86/mm.c xen/drivers/Makefile xen/drivers/char/console.c xen/drivers/video/font.h xen/drivers/video/font_8x14.c xen/drivers/video/font_8x16.c xen/drivers/video/font_8x8.c xen/drivers/video/vga.c xen/include/asm-ia64/config.h xen/include/asm-x86/config.h xen/include/asm-x86/io.h xen/include/xen/font.h xen/include/xen/mm.h xen/include/xen/vga.h
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/ia64/dig/setup.c	Wed Aug 16 18:20:03 2006 +0100
     1.3 @@ -0,0 +1,110 @@
     1.4 +/*
     1.5 + * Platform dependent support for DIG64 platforms.
     1.6 + *
     1.7 + * Copyright (C) 1999 Intel Corp.
     1.8 + * Copyright (C) 1999, 2001 Hewlett-Packard Co
     1.9 + * Copyright (C) 1999, 2001, 2003 David Mosberger-Tang <davidm@hpl.hp.com>
    1.10 + * Copyright (C) 1999 VA Linux Systems
    1.11 + * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
    1.12 + * Copyright (C) 1999 Vijay Chander <vijay@engr.sgi.com>
    1.13 + */
    1.14 +#include <linux/config.h>
    1.15 +
    1.16 +#include <linux/init.h>
    1.17 +#include <linux/delay.h>
    1.18 +#include <linux/kernel.h>
    1.19 +#include <linux/kdev_t.h>
    1.20 +#include <linux/string.h>
    1.21 +#include <linux/tty.h>
    1.22 +#include <linux/console.h>
    1.23 +#include <linux/timex.h>
    1.24 +#include <linux/sched.h>
    1.25 +#include <linux/root_dev.h>
    1.26 +
    1.27 +#include <asm/io.h>
    1.28 +#include <asm/machvec.h>
    1.29 +#include <asm/system.h>
    1.30 +
    1.31 +void __init
    1.32 +dig_setup (char **cmdline_p)
    1.33 +{
    1.34 +	unsigned int orig_x, orig_y, num_cols, num_rows, font_height;
    1.35 +
    1.36 +	/*
    1.37 +	 * Default to /dev/sda2.  This assumes that the EFI partition
    1.38 +	 * is physical disk 1 partition 1 and the Linux root disk is
    1.39 +	 * physical disk 1 partition 2.
    1.40 +	 */
    1.41 +	ROOT_DEV = Root_SDA2;		/* default to second partition on first drive */
    1.42 +
    1.43 +#ifdef CONFIG_SMP
    1.44 +	init_smp_config();
    1.45 +#endif
    1.46 +
    1.47 +	memset(&screen_info, 0, sizeof(screen_info));
    1.48 +
    1.49 +	if (!ia64_boot_param->console_info.num_rows
    1.50 +	    || !ia64_boot_param->console_info.num_cols)
    1.51 +	{
    1.52 +		printk(KERN_WARNING "dig_setup: warning: invalid screen-info, guessing 80x25\n");
    1.53 +		orig_x = 0;
    1.54 +		orig_y = 0;
    1.55 +		num_cols = 80;
    1.56 +		num_rows = 25;
    1.57 +		font_height = 16;
    1.58 +	} else {
    1.59 +		orig_x = ia64_boot_param->console_info.orig_x;
    1.60 +		orig_y = ia64_boot_param->console_info.orig_y;
    1.61 +		num_cols = ia64_boot_param->console_info.num_cols;
    1.62 +		num_rows = ia64_boot_param->console_info.num_rows;
    1.63 +		font_height = 400 / num_rows;
    1.64 +	}
    1.65 +
    1.66 +	screen_info.orig_x = orig_x;
    1.67 +	screen_info.orig_y = orig_y;
    1.68 +	screen_info.orig_video_cols  = num_cols;
    1.69 +	screen_info.orig_video_lines = num_rows;
    1.70 +	screen_info.orig_video_points = font_height;
    1.71 +	screen_info.orig_video_mode = 3;	/* XXX fake */
    1.72 +	screen_info.orig_video_isVGA = 1;	/* XXX fake */
    1.73 +	screen_info.orig_video_ega_bx = 3;	/* XXX fake */
    1.74 +#ifdef CONFIG_XEN
    1.75 +	if (!is_running_on_xen())
    1.76 +		return;
    1.77 +
    1.78 +	if (xen_start_info->console.dom0.info_size >=
    1.79 +	    sizeof(struct dom0_vga_console_info)) {
    1.80 +		const struct dom0_vga_console_info *info =
    1.81 +		        (struct dom0_vga_console_info *)(
    1.82 +		                (char *)xen_start_info +
    1.83 +		                xen_start_info->console.dom0.info_off);
    1.84 +		screen_info.orig_video_mode = info->txt_mode;
    1.85 +		screen_info.orig_video_isVGA = info->video_type;
    1.86 +		screen_info.orig_video_lines = info->video_height;
    1.87 +		screen_info.orig_video_cols = info->video_width;
    1.88 +		screen_info.orig_video_points = info->txt_points;
    1.89 +		screen_info.lfb_width = info->video_width;
    1.90 +		screen_info.lfb_height = info->video_height;
    1.91 +		screen_info.lfb_depth = info->lfb_depth;
    1.92 +		screen_info.lfb_base = info->lfb_base;
    1.93 +		screen_info.lfb_size = info->lfb_size;
    1.94 +		screen_info.lfb_linelength = info->lfb_linelen;
    1.95 +		screen_info.red_size = info->red_size;
    1.96 +		screen_info.red_pos = info->red_pos;
    1.97 +		screen_info.green_size = info->green_size;
    1.98 +		screen_info.green_pos = info->green_pos;
    1.99 +		screen_info.blue_size = info->blue_size;
   1.100 +		screen_info.blue_pos = info->blue_pos;
   1.101 +		screen_info.rsvd_size = info->rsvd_size;
   1.102 +		screen_info.rsvd_pos = info->rsvd_pos;
   1.103 +	}
   1.104 +	screen_info.orig_y = screen_info.orig_video_lines - 1;
   1.105 +	xen_start_info->console.domU.mfn = 0;
   1.106 +	xen_start_info->console.domU.evtchn = 0;
   1.107 +#endif
   1.108 +}
   1.109 +
   1.110 +void __init
   1.111 +dig_irq_init (void)
   1.112 +{
   1.113 +}
     2.1 --- a/xen/arch/ia64/Rules.mk	Wed Aug 16 18:11:33 2006 +0100
     2.2 +++ b/xen/arch/ia64/Rules.mk	Wed Aug 16 18:20:03 2006 +0100
     2.3 @@ -2,6 +2,7 @@
     2.4  # ia64-specific definitions
     2.5  
     2.6  HAS_ACPI := y
     2.7 +HAS_VGA  := y
     2.8  VALIDATE_VT	?= n
     2.9  no_warns ?= n
    2.10  
     3.1 --- a/xen/arch/ia64/xen/domain.c	Wed Aug 16 18:11:33 2006 +0100
     3.2 +++ b/xen/arch/ia64/xen/domain.c	Wed Aug 16 18:20:03 2006 +0100
     3.3 @@ -864,6 +864,7 @@ int construct_dom0(struct domain *d,
     3.4  {
     3.5  	int i, rc;
     3.6  	start_info_t *si;
     3.7 +	dom0_vga_console_info_t *ci;
     3.8  	struct vcpu *v = d->vcpu[0];
     3.9  	unsigned long max_pages;
    3.10  
    3.11 @@ -1000,6 +1001,9 @@ int construct_dom0(struct domain *d,
    3.12  	//if ( initrd_len != 0 )
    3.13  	//    memcpy((void *)vinitrd_start, initrd_start, initrd_len);
    3.14  
    3.15 +	BUILD_BUG_ON(sizeof(start_info_t) + sizeof(dom0_vga_console_info_t) +
    3.16 +	             sizeof(struct ia64_boot_param) > PAGE_SIZE);
    3.17 +
    3.18  	/* Set up start info area. */
    3.19  	d->shared_info->arch.start_info_pfn = pstart_info >> PAGE_SHIFT;
    3.20  	start_info_page = assign_new_domain_page(d, pstart_info);
    3.21 @@ -1034,7 +1038,8 @@ int construct_dom0(struct domain *d,
    3.22  	strncpy((char *)si->cmd_line, dom0_command_line, sizeof(si->cmd_line));
    3.23  	si->cmd_line[sizeof(si->cmd_line)-1] = 0;
    3.24  
    3.25 -	bp = (struct ia64_boot_param *)(si + 1);
    3.26 +	bp = (struct ia64_boot_param *)((unsigned char *)si +
    3.27 +	                                sizeof(start_info_t));
    3.28  	bp->command_line = pstart_info + offsetof (start_info_t, cmd_line);
    3.29  
    3.30  	/* We assume console has reached the last line!  */
    3.31 @@ -1048,6 +1053,16 @@ int construct_dom0(struct domain *d,
    3.32  	             (PAGE_ALIGN(ia64_boot_param->initrd_size) + 4*1024*1024);
    3.33  	bp->initrd_size = ia64_boot_param->initrd_size;
    3.34  
    3.35 +	ci = (dom0_vga_console_info_t *)((unsigned char *)si +
    3.36 +			                 sizeof(start_info_t) +
    3.37 +	                                 sizeof(struct ia64_boot_param));
    3.38 +
    3.39 +	if (fill_console_start_info(ci)) {
    3.40 +		si->console.dom0.info_off = sizeof(start_info_t) +
    3.41 +		                            sizeof(struct ia64_boot_param);
    3.42 +		si->console.dom0.info_size = sizeof(dom0_vga_console_info_t);
    3.43 +	}
    3.44 +
    3.45  	vcpu_init_regs (v);
    3.46  
    3.47  	vcpu_regs(v)->r28 = bp_mpa;
     4.1 --- a/xen/arch/ia64/xen/mm.c	Wed Aug 16 18:11:33 2006 +0100
     4.2 +++ b/xen/arch/ia64/xen/mm.c	Wed Aug 16 18:20:03 2006 +0100
     4.3 @@ -1746,6 +1746,11 @@ int get_page_type(struct page_info *page
     4.4      return 1;
     4.5  }
     4.6  
     4.7 +int memory_is_conventional_ram(paddr_t p)
     4.8 +{
     4.9 +    return (efi_mem_type(p) == EFI_CONVENTIONAL_MEMORY);
    4.10 +}
    4.11 +
    4.12  /*
    4.13   * Local variables:
    4.14   * mode: C
     5.1 --- a/xen/arch/x86/Rules.mk	Wed Aug 16 18:11:33 2006 +0100
     5.2 +++ b/xen/arch/x86/Rules.mk	Wed Aug 16 18:20:03 2006 +0100
     5.3 @@ -2,6 +2,7 @@
     5.4  # x86-specific definitions
     5.5  
     5.6  HAS_ACPI := y
     5.7 +HAS_VGA  := y
     5.8  
     5.9  #
    5.10  # If you change any of these configuration options then you must
     6.1 --- a/xen/arch/x86/mm.c	Wed Aug 16 18:11:33 2006 +0100
     6.2 +++ b/xen/arch/x86/mm.c	Wed Aug 16 18:20:03 2006 +0100
     6.3 @@ -234,6 +234,21 @@ void arch_init_memory(void)
     6.4      subarch_init_memory();
     6.5  }
     6.6  
     6.7 +int memory_is_conventional_ram(paddr_t p)
     6.8 +{
     6.9 +    int i;
    6.10 +
    6.11 +    for ( i = 0; i < e820.nr_map; i++ )
    6.12 +    {
    6.13 +        if ( (e820.map[i].type == E820_RAM) &&
    6.14 +             (e820.map[i].addr <= p) &&
    6.15 +             (e820.map[i].size > p) )
    6.16 +            return 1;
    6.17 +    }
    6.18 +
    6.19 +    return 0;
    6.20 +}
    6.21 +
    6.22  void share_xen_page_with_guest(
    6.23      struct page_info *page, struct domain *d, int readonly)
    6.24  {
     7.1 --- a/xen/drivers/Makefile	Wed Aug 16 18:11:33 2006 +0100
     7.2 +++ b/xen/drivers/Makefile	Wed Aug 16 18:20:03 2006 +0100
     7.3 @@ -1,3 +1,3 @@
     7.4  subdir-y += char
     7.5  subdir-$(HAS_ACPI) += acpi
     7.6 -subdir-y += video
     7.7 +subdir-$(HAS_VGA) += video
     8.1 --- a/xen/drivers/char/console.c	Wed Aug 16 18:11:33 2006 +0100
     8.2 +++ b/xen/drivers/char/console.c	Wed Aug 16 18:20:03 2006 +0100
     8.3 @@ -22,7 +22,6 @@
     8.4  #include <xen/delay.h>
     8.5  #include <xen/guest_access.h>
     8.6  #include <xen/shutdown.h>
     8.7 -#include <xen/font.h>
     8.8  #include <xen/vga.h>
     8.9  #include <asm/current.h>
    8.10  #include <asm/debugger.h>
    8.11 @@ -32,10 +31,6 @@
    8.12  static char opt_console[30] = OPT_CONSOLE_STR;
    8.13  string_param("console", opt_console);
    8.14  
    8.15 -/* vga: comma-separated options. */
    8.16 -static char opt_vga[30] = "";
    8.17 -string_param("vga", opt_vga);
    8.18 -
    8.19  /* conswitch: a character pair controlling console switching. */
    8.20  /* Char 1: CTRL+<char1> is used to switch console input between Xen and DOM0 */
    8.21  /* Char 2: If this character is 'x', then do not auto-switch to DOM0 when it */
    8.22 @@ -47,9 +42,6 @@ string_param("conswitch", opt_conswitch)
    8.23  static int opt_sync_console;
    8.24  boolean_param("sync_console", opt_sync_console);
    8.25  
    8.26 -static int xpos, ypos;
    8.27 -static unsigned char *video;
    8.28 -
    8.29  #define CONRING_SIZE 16384
    8.30  #define CONRING_IDX_MASK(i) ((i)&(CONRING_SIZE-1))
    8.31  static char conring[CONRING_SIZE];
    8.32 @@ -58,136 +50,10 @@ static unsigned int conringc, conringp;
    8.33  static char printk_prefix[16] = "";
    8.34  
    8.35  static int sercon_handle = -1;
    8.36 -static int vgacon_enabled = 0;
    8.37 -static int vgacon_keep    = 0;
    8.38 -static int vgacon_lines   = 25;
    8.39 -static const struct font_desc *font;
    8.40  
    8.41  static DEFINE_SPINLOCK(console_lock);
    8.42  
    8.43  /*
    8.44 - * *******************************************************
    8.45 - * *************** OUTPUT TO VGA CONSOLE *****************
    8.46 - * *******************************************************
    8.47 - */
    8.48 -
    8.49 -/* VGA text-mode definitions. */
    8.50 -#define COLUMNS     80
    8.51 -#define LINES       vgacon_lines
    8.52 -#define ATTRIBUTE   7
    8.53 -#define VIDEO_SIZE  (COLUMNS * LINES * 2)
    8.54 -
    8.55 -/* Clear the screen and initialize VIDEO, XPOS and YPOS.  */
    8.56 -static void cls(void)
    8.57 -{
    8.58 -    memset(video, 0, VIDEO_SIZE);
    8.59 -    xpos = ypos = 0;
    8.60 -    vga_cursor_off();
    8.61 -}
    8.62 -
    8.63 -static void init_vga(void)
    8.64 -{
    8.65 -    char *p;
    8.66 -
    8.67 -    if ( !vgacon_enabled )
    8.68 -        return;
    8.69 -
    8.70 -    for ( p = opt_vga; p != NULL; p = strchr(p, ',') )
    8.71 -    {
    8.72 -        if ( *p == ',' )
    8.73 -            p++;
    8.74 -        if ( strncmp(p, "keep", 4) == 0 )
    8.75 -            vgacon_keep = 1;
    8.76 -        else if ( strncmp(p, "text-80x", 8) == 0 )
    8.77 -            vgacon_lines = simple_strtoul(p + 8, NULL, 10);
    8.78 -    }
    8.79 -
    8.80 -    video = setup_vga();
    8.81 -    if ( !video )
    8.82 -    {
    8.83 -        vgacon_enabled = 0;
    8.84 -        return;
    8.85 -    }
    8.86 -
    8.87 -    switch ( vgacon_lines )
    8.88 -    {
    8.89 -    case 25:
    8.90 -    case 30:
    8.91 -        font = &font_vga_8x16;
    8.92 -        break;
    8.93 -    case 28:
    8.94 -    case 34:
    8.95 -        font = &font_vga_8x14;
    8.96 -        break;
    8.97 -    case 43:
    8.98 -    case 50:
    8.99 -    case 60:
   8.100 -        font = &font_vga_8x8;
   8.101 -        break;
   8.102 -    default:
   8.103 -        vgacon_lines = 25;
   8.104 -        break;
   8.105 -    }
   8.106 -
   8.107 -    if ( (font != NULL) && (vga_load_font(font, vgacon_lines) < 0) )
   8.108 -    {
   8.109 -        vgacon_lines = 25;
   8.110 -        font = NULL;
   8.111 -    }
   8.112 -    
   8.113 -    cls();
   8.114 -}
   8.115 -
   8.116 -static void put_newline(void)
   8.117 -{
   8.118 -    xpos = 0;
   8.119 -    ypos++;
   8.120 -
   8.121 -    if ( ypos >= LINES )
   8.122 -    {
   8.123 -        ypos = LINES-1;
   8.124 -        memmove((char*)video, 
   8.125 -                (char*)video + 2*COLUMNS, (LINES-1)*2*COLUMNS);
   8.126 -        memset((char*)video + (LINES-1)*2*COLUMNS, 0, 2*COLUMNS);
   8.127 -    }
   8.128 -}
   8.129 -
   8.130 -static void putchar_console(int c)
   8.131 -{
   8.132 -    if ( !vgacon_enabled )
   8.133 -        return;
   8.134 -
   8.135 -    if ( c == '\n' )
   8.136 -    {
   8.137 -        put_newline();
   8.138 -    }
   8.139 -    else
   8.140 -    {
   8.141 -        if ( xpos >= COLUMNS )
   8.142 -            put_newline();
   8.143 -        video[(xpos + ypos * COLUMNS) * 2]     = c & 0xFF;
   8.144 -        video[(xpos + ypos * COLUMNS) * 2 + 1] = ATTRIBUTE;
   8.145 -        ++xpos;
   8.146 -    }
   8.147 -}
   8.148 -
   8.149 -int fill_console_start_info(struct dom0_vga_console_info *ci)
   8.150 -{
   8.151 -    memset(ci, 0, sizeof(*ci));
   8.152 -
   8.153 -    if ( !vgacon_enabled )
   8.154 -        return 0;
   8.155 -
   8.156 -    ci->video_type   = 1;
   8.157 -    ci->video_width  = COLUMNS;
   8.158 -    ci->video_height = LINES;
   8.159 -    ci->txt_mode     = 3;
   8.160 -    ci->txt_points   = font ? font->height : 16;
   8.161 -
   8.162 -    return 1;
   8.163 -}
   8.164 -
   8.165 -/*
   8.166   * ********************************************************
   8.167   * *************** ACCESS TO CONSOLE RING *****************
   8.168   * ********************************************************
   8.169 @@ -328,7 +194,7 @@ static long guest_console_write(XEN_GUES
   8.170          serial_puts(sercon_handle, kbuf);
   8.171  
   8.172          for ( kptr = kbuf; *kptr != '\0'; kptr++ )
   8.173 -            putchar_console(*kptr);
   8.174 +            vga_putchar(*kptr);
   8.175  
   8.176          guest_handle_add_offset(buffer, kcount);
   8.177          count -= kcount;
   8.178 @@ -395,7 +261,7 @@ static inline void __putstr(const char *
   8.179  
   8.180      while ( (c = *str++) != '\0' )
   8.181      {
   8.182 -        putchar_console(c);
   8.183 +        vga_putchar(c);
   8.184          putchar_console_ring(c);
   8.185      }
   8.186  }
   8.187 @@ -455,11 +321,9 @@ void init_console(void)
   8.188          if ( strncmp(p, "com", 3) == 0 )
   8.189              sercon_handle = serial_parse_handle(p);
   8.190          else if ( strncmp(p, "vga", 3) == 0 )
   8.191 -            vgacon_enabled = 1;
   8.192 +            vga_init();
   8.193      }
   8.194  
   8.195 -    init_vga();
   8.196 -
   8.197      serial_set_rx_handler(sercon_handle, serial_rx);
   8.198  
   8.199      /* HELLO WORLD --- start-of-day banner text. */
   8.200 @@ -510,10 +374,7 @@ void console_endboot(void)
   8.201          printk("\n");
   8.202      }
   8.203  
   8.204 -    if ( !vgacon_keep )
   8.205 -        vgacon_enabled = 0;
   8.206 -    printk("Xen is %s VGA console.\n",
   8.207 -           vgacon_keep ? "keeping" : "relinquishing");
   8.208 +    vga_endboot();
   8.209  
   8.210      /*
   8.211       * If user specifies so, we fool the switch routine to redirect input
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/xen/drivers/video/font.h	Wed Aug 16 18:20:03 2006 +0100
     9.3 @@ -0,0 +1,22 @@
     9.4 +/*
     9.5 + *  font.h -- `Soft' font definitions
     9.6 + *
     9.7 + *  Created 1995 by Geert Uytterhoeven
     9.8 + *
     9.9 + *  This file is subject to the terms and conditions of the GNU General Public
    9.10 + *  License.  See the file COPYING in the main directory of this archive
    9.11 + *  for more details.
    9.12 + */
    9.13 +
    9.14 +#ifndef _XEN_FONT_H
    9.15 +#define _XEN_FONT_H
    9.16 +
    9.17 +struct font_desc {
    9.18 +    const char *name;
    9.19 +    unsigned width, height, count;
    9.20 +    const void *data;
    9.21 +};
    9.22 +
    9.23 +extern const struct font_desc font_vga_8x8, font_vga_8x14, font_vga_8x16;
    9.24 +
    9.25 +#endif /* _XEN_FONT_H */
    10.1 --- a/xen/drivers/video/font_8x14.c	Wed Aug 16 18:11:33 2006 +0100
    10.2 +++ b/xen/drivers/video/font_8x14.c	Wed Aug 16 18:20:03 2006 +0100
    10.3 @@ -5,7 +5,7 @@
    10.4  /**********************************************/
    10.5  
    10.6  #include <xen/types.h>
    10.7 -#include <xen/font.h>
    10.8 +#include "font.h"
    10.9  
   10.10  #define FONTDATAMAX (256*14)
   10.11  
    11.1 --- a/xen/drivers/video/font_8x16.c	Wed Aug 16 18:11:33 2006 +0100
    11.2 +++ b/xen/drivers/video/font_8x16.c	Wed Aug 16 18:20:03 2006 +0100
    11.3 @@ -5,7 +5,7 @@
    11.4  /**********************************************/
    11.5  
    11.6  #include <xen/types.h>
    11.7 -#include <xen/font.h>
    11.8 +#include "font.h"
    11.9  
   11.10  #define FONTDATAMAX (256*16)
   11.11  
    12.1 --- a/xen/drivers/video/font_8x8.c	Wed Aug 16 18:11:33 2006 +0100
    12.2 +++ b/xen/drivers/video/font_8x8.c	Wed Aug 16 18:20:03 2006 +0100
    12.3 @@ -5,7 +5,7 @@
    12.4  /**********************************************/
    12.5  
    12.6  #include <xen/types.h>
    12.7 -#include <xen/font.h>
    12.8 +#include "font.h"
    12.9  
   12.10  #define FONTDATAMAX (256*8)
   12.11  
    13.1 --- a/xen/drivers/video/vga.c	Wed Aug 16 18:11:33 2006 +0100
    13.2 +++ b/xen/drivers/video/vga.c	Wed Aug 16 18:20:03 2006 +0100
    13.3 @@ -8,13 +8,14 @@
    13.4  #include <xen/compile.h>
    13.5  #include <xen/init.h>
    13.6  #include <xen/lib.h>
    13.7 +#include <xen/mm.h>
    13.8  #include <xen/errno.h>
    13.9  #include <xen/event.h>
   13.10  #include <xen/spinlock.h>
   13.11  #include <xen/console.h>
   13.12 -#include <xen/font.h>
   13.13  #include <xen/vga.h>
   13.14  #include <asm/io.h>
   13.15 +#include "font.h"
   13.16  
   13.17  /* Some of the code below is taken from SVGAlib.  The original,
   13.18     unmodified copyright notice for that code is below. */
   13.19 @@ -159,12 +160,8 @@
   13.20   * into a single 16-bit quantity */
   13.21  #define VGA_OUT16VAL(v, r)       (((v) << 8) | (r))
   13.22  
   13.23 -#if defined(__i386__) || defined(__x86_64__)
   13.24 -# define vgabase 0
   13.25 -# define VGA_OUTW_WRITE
   13.26 -# define vga_readb(x) (*(x))
   13.27 -# define vga_writeb(x,y) (*(y) = (x))
   13.28 -#endif
   13.29 +#define vgabase 0         /* use in/out port-access macros  */
   13.30 +#define VGA_OUTW_WRITE    /* can use outw instead of 2xoutb */
   13.31  
   13.32  /*
   13.33   * generic VGA port read/write
   13.34 @@ -187,17 +184,17 @@ static inline void vga_io_w_fast(uint16_
   13.35  
   13.36  static inline uint8_t vga_mm_r(void __iomem *regbase, uint16_t port)
   13.37  {
   13.38 -    return readb(regbase + port);
   13.39 +    return readb((char *)regbase + port);
   13.40  }
   13.41  
   13.42  static inline void vga_mm_w(void __iomem *regbase, uint16_t port, uint8_t val)
   13.43  {
   13.44 -    writeb(val, regbase + port);
   13.45 +    writeb(val, (char *)regbase + port);
   13.46  }
   13.47  
   13.48  static inline void vga_mm_w_fast(void __iomem *regbase, uint16_t port, uint8_t reg, uint8_t val)
   13.49  {
   13.50 -    writew(VGA_OUT16VAL(val, reg), regbase + port);
   13.51 +    writew(VGA_OUT16VAL(val, reg), (char *)regbase + port);
   13.52  }
   13.53  
   13.54  static inline uint8_t vga_r(void __iomem *regbase, uint16_t port)
   13.55 @@ -324,24 +321,8 @@ static int detect_video(void *video_base
   13.56      return video_found;
   13.57  }
   13.58  
   13.59 -static int detect_vga(void)
   13.60 -{
   13.61 -    /*
   13.62 -     * Look at a number of well-known locations. Even if video is not at
   13.63 -     * 0xB8000 right now, it will appear there when we set up text mode 3.
   13.64 -     * 
   13.65 -     * We assume if there is any sign of a video adaptor then it is at least
   13.66 -     * VGA-compatible (surely noone runs CGA, EGA, .... these days?).
   13.67 -     * 
   13.68 -     * These checks are basically to detect headless server boxes.
   13.69 -     */
   13.70 -    return (detect_video(ioremap(0xA0000, 0x1000)) || 
   13.71 -            detect_video(ioremap(0xB0000, 0x1000)) || 
   13.72 -            detect_video(ioremap(0xB8000, 0x1000)));
   13.73 -}
   13.74 -
   13.75  /* This is actually code from vgaHWRestore in an old version of XFree86 :-) */
   13.76 -void *setup_vga(void)
   13.77 +static void *setup_vga(void)
   13.78  {
   13.79      /* The following VGA state was saved from a chip in text mode 3. */
   13.80      static unsigned char regs[] = {
   13.81 @@ -358,13 +339,11 @@ void *setup_vga(void)
   13.82          0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x0c, 0x00, 0x0f, 0x08, 0x00
   13.83      };
   13.84  
   13.85 +    char *video;
   13.86      int i, j;
   13.87  
   13.88 -    if ( !detect_vga() )
   13.89 -    {
   13.90 -        printk("No VGA adaptor detected!\n");
   13.91 -        return NULL;
   13.92 -    }
   13.93 +    if ( memory_is_conventional_ram(0xB8000) )
   13.94 +        goto no_vga;
   13.95  
   13.96      inb(VGA_IS1_RC);
   13.97      outb(0x00, VGA_ATT_IW);
   13.98 @@ -388,12 +367,19 @@ void *setup_vga(void)
   13.99      inb(VGA_IS1_RC);
  13.100      outb(0x20, VGA_ATT_IW);
  13.101  
  13.102 -    return ioremap(0xB8000, 0x8000);
  13.103 -}
  13.104 +    video = ioremap(0xB8000, 0x8000);
  13.105  
  13.106 -void vga_cursor_off(void)
  13.107 -{
  13.108 -    vga_wcrt(vgabase, VGA_CRTC_CURSOR_START, 0x20);
  13.109 +    if ( !detect_video(video) )
  13.110 +    {
  13.111 +        iounmap(video);
  13.112 +        goto no_vga;
  13.113 +    }
  13.114 +
  13.115 +    return video;
  13.116 +
  13.117 + no_vga:
  13.118 +    printk("No VGA adaptor detected!\n");
  13.119 +    return NULL;
  13.120  }
  13.121  
  13.122  static int vga_set_scanlines(unsigned scanlines)
  13.123 @@ -473,7 +459,7 @@ static int vga_set_scanlines(unsigned sc
  13.124  static unsigned font_slot = 0;
  13.125  integer_param("fontslot", font_slot);
  13.126  
  13.127 -int vga_load_font(const struct font_desc *font, unsigned rows)
  13.128 +static int vga_load_font(const struct font_desc *font, unsigned rows)
  13.129  {
  13.130      unsigned fontheight = font ? font->height : 16;
  13.131      uint8_t fsr = vga_rcrt(vgabase, VGA_CRTC_MAX_SCAN); /* Font size register */
  13.132 @@ -515,16 +501,19 @@ int vga_load_font(const struct font_desc
  13.133      {
  13.134          unsigned i, j;
  13.135          const uint8_t *data = font->data;
  13.136 -        uint8_t *map = (uint8_t *)__va(0xA0000) + font_slot*2*CHAR_MAP_SIZE;
  13.137 +        uint8_t *map;
  13.138 +
  13.139 +        map = ioremap(0xA0000 + font_slot*2*CHAR_MAP_SIZE, CHAR_MAP_SIZE);
  13.140  
  13.141          for ( i = j = 0; i < CHAR_MAP_SIZE; )
  13.142          {
  13.143 -            vga_writeb(j < font->count * fontheight ? data[j++] : 0,
  13.144 -                       map + i++);
  13.145 +            writeb(j < font->count * fontheight ? data[j++] : 0, map + i++);
  13.146              if ( !(j % fontheight) )
  13.147                  while ( i & (FONT_HEIGHT_MAX - 1) )
  13.148 -                    vga_writeb(0, map + i++);
  13.149 +                    writeb(0, map + i++);
  13.150          }
  13.151 +
  13.152 +        iounmap(map);
  13.153      }
  13.154  
  13.155      /* First, the sequencer, Synchronous reset */
  13.156 @@ -560,3 +549,142 @@ int vga_load_font(const struct font_desc
  13.157  
  13.158      return 0;
  13.159  }
  13.160 +
  13.161 +
  13.162 +/*
  13.163 + * HIGH-LEVEL INITIALISATION AND TEXT OUTPUT.
  13.164 + */
  13.165 +
  13.166 +static int vgacon_enabled = 0;
  13.167 +static int vgacon_keep    = 0;
  13.168 +static int vgacon_lines   = 25;
  13.169 +static const struct font_desc *font;
  13.170 +
  13.171 +static int xpos, ypos;
  13.172 +static unsigned char *video;
  13.173 +
  13.174 +/* vga: comma-separated options. */
  13.175 +static char opt_vga[30] = "";
  13.176 +string_param("vga", opt_vga);
  13.177 +
  13.178 +/* VGA text-mode definitions. */
  13.179 +#define COLUMNS     80
  13.180 +#define LINES       vgacon_lines
  13.181 +#define ATTRIBUTE   7
  13.182 +#define VIDEO_SIZE  (COLUMNS * LINES * 2)
  13.183 +
  13.184 +void vga_init(void)
  13.185 +{
  13.186 +    char *p;
  13.187 +
  13.188 +    for ( p = opt_vga; p != NULL; p = strchr(p, ',') )
  13.189 +    {
  13.190 +        if ( *p == ',' )
  13.191 +            p++;
  13.192 +        if ( strncmp(p, "keep", 4) == 0 )
  13.193 +            vgacon_keep = 1;
  13.194 +        else if ( strncmp(p, "text-80x", 8) == 0 )
  13.195 +            vgacon_lines = simple_strtoul(p + 8, NULL, 10);
  13.196 +    }
  13.197 +
  13.198 +    video = setup_vga();
  13.199 +    if ( !video )
  13.200 +        return;
  13.201 +
  13.202 +    switch ( vgacon_lines )
  13.203 +    {
  13.204 +    case 25:
  13.205 +    case 30:
  13.206 +        font = &font_vga_8x16;
  13.207 +        break;
  13.208 +    case 28:
  13.209 +    case 34:
  13.210 +        font = &font_vga_8x14;
  13.211 +        break;
  13.212 +    case 43:
  13.213 +    case 50:
  13.214 +    case 60:
  13.215 +        font = &font_vga_8x8;
  13.216 +        break;
  13.217 +    default:
  13.218 +        vgacon_lines = 25;
  13.219 +        break;
  13.220 +    }
  13.221 +
  13.222 +    if ( (font != NULL) && (vga_load_font(font, vgacon_lines) < 0) )
  13.223 +    {
  13.224 +        vgacon_lines = 25;
  13.225 +        font = NULL;
  13.226 +    }
  13.227 +    
  13.228 +    /* Clear the screen. */
  13.229 +    memset(video, 0, VIDEO_SIZE);
  13.230 +    xpos = ypos = 0;
  13.231 +
  13.232 +    /* Disable cursor. */
  13.233 +    vga_wcrt(vgabase, VGA_CRTC_CURSOR_START, 0x20);
  13.234 +
  13.235 +    vgacon_enabled = 1;
  13.236 +}
  13.237 +
  13.238 +void vga_endboot(void)
  13.239 +{
  13.240 +    if ( !vgacon_enabled )
  13.241 +        return;
  13.242 +
  13.243 +    if ( !vgacon_keep )
  13.244 +        vgacon_enabled = 0;
  13.245 +        
  13.246 +    printk("Xen is %s VGA console.\n",
  13.247 +           vgacon_keep ? "keeping" : "relinquishing");
  13.248 +}
  13.249 +
  13.250 +
  13.251 +static void put_newline(void)
  13.252 +{
  13.253 +    xpos = 0;
  13.254 +    ypos++;
  13.255 +
  13.256 +    if ( ypos >= LINES )
  13.257 +    {
  13.258 +        ypos = LINES-1;
  13.259 +        memmove((char*)video, 
  13.260 +                (char*)video + 2*COLUMNS, (LINES-1)*2*COLUMNS);
  13.261 +        memset((char*)video + (LINES-1)*2*COLUMNS, 0, 2*COLUMNS);
  13.262 +    }
  13.263 +}
  13.264 +
  13.265 +void vga_putchar(int c)
  13.266 +{
  13.267 +    if ( !vgacon_enabled )
  13.268 +        return;
  13.269 +
  13.270 +    if ( c == '\n' )
  13.271 +    {
  13.272 +        put_newline();
  13.273 +    }
  13.274 +    else
  13.275 +    {
  13.276 +        if ( xpos >= COLUMNS )
  13.277 +            put_newline();
  13.278 +        video[(xpos + ypos * COLUMNS) * 2]     = c & 0xFF;
  13.279 +        video[(xpos + ypos * COLUMNS) * 2 + 1] = ATTRIBUTE;
  13.280 +        ++xpos;
  13.281 +    }
  13.282 +}
  13.283 +
  13.284 +int fill_console_start_info(struct dom0_vga_console_info *ci)
  13.285 +{
  13.286 +    memset(ci, 0, sizeof(*ci));
  13.287 +
  13.288 +    if ( !vgacon_enabled )
  13.289 +        return 0;
  13.290 +
  13.291 +    ci->video_type   = 1;
  13.292 +    ci->video_width  = COLUMNS;
  13.293 +    ci->video_height = LINES;
  13.294 +    ci->txt_mode     = 3;
  13.295 +    ci->txt_points   = font ? font->height : 16;
  13.296 +
  13.297 +    return 1;
  13.298 +}
    14.1 --- a/xen/include/asm-ia64/config.h	Wed Aug 16 18:11:33 2006 +0100
    14.2 +++ b/xen/include/asm-ia64/config.h	Wed Aug 16 18:20:03 2006 +0100
    14.3 @@ -37,6 +37,8 @@
    14.4  
    14.5  #define MAX_DMADOM_PFN (0x7FFFFFFFUL >> PAGE_SHIFT) /* 31 addressable bits */
    14.6  
    14.7 +#define CONFIG_VGA 1
    14.8 +
    14.9  #ifndef __ASSEMBLY__
   14.10  
   14.11  // can't find where this typedef was before?!?
    15.1 --- a/xen/include/asm-x86/config.h	Wed Aug 16 18:11:33 2006 +0100
    15.2 +++ b/xen/include/asm-x86/config.h	Wed Aug 16 18:20:03 2006 +0100
    15.3 @@ -31,6 +31,8 @@
    15.4  #define CONFIG_ACPI 1
    15.5  #define CONFIG_ACPI_BOOT 1
    15.6  
    15.7 +#define CONFIG_VGA 1
    15.8 +
    15.9  #define HZ 100
   15.10  
   15.11  #define OPT_CONSOLE_STR "com1,vga"
    16.1 --- a/xen/include/asm-x86/io.h	Wed Aug 16 18:11:33 2006 +0100
    16.2 +++ b/xen/include/asm-x86/io.h	Wed Aug 16 18:20:03 2006 +0100
    16.3 @@ -7,6 +7,7 @@
    16.4  
    16.5  /* We don't need real ioremap() on Xen/x86. */
    16.6  #define ioremap(x,l) (__va(x))
    16.7 +#define iounmap(p)   ((void)0)
    16.8  
    16.9  #define readb(x) (*(volatile char *)(x))
   16.10  #define readw(x) (*(volatile short *)(x))
    17.1 --- a/xen/include/xen/font.h	Wed Aug 16 18:11:33 2006 +0100
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,22 +0,0 @@
    17.4 -/*
    17.5 - *  font.h -- `Soft' font definitions
    17.6 - *
    17.7 - *  Created 1995 by Geert Uytterhoeven
    17.8 - *
    17.9 - *  This file is subject to the terms and conditions of the GNU General Public
   17.10 - *  License.  See the file COPYING in the main directory of this archive
   17.11 - *  for more details.
   17.12 - */
   17.13 -
   17.14 -#ifndef _XEN_FONT_H
   17.15 -#define _XEN_FONT_H
   17.16 -
   17.17 -struct font_desc {
   17.18 -    const char *name;
   17.19 -    unsigned width, height, count;
   17.20 -    const void *data;
   17.21 -};
   17.22 -
   17.23 -extern const struct font_desc font_vga_8x8, font_vga_8x14, font_vga_8x16;
   17.24 -
   17.25 -#endif /* _XEN_FONT_H */
    18.1 --- a/xen/include/xen/mm.h	Wed Aug 16 18:11:33 2006 +0100
    18.2 +++ b/xen/include/xen/mm.h	Wed Aug 16 18:20:03 2006 +0100
    18.3 @@ -97,4 +97,7 @@ unsigned long avail_scrub_pages(void);
    18.4  
    18.5  int guest_remove_page(struct domain *d, unsigned long gmfn);
    18.6  
    18.7 +/* Returns TRUE if the memory at address @p is ordinary RAM. */
    18.8 +int memory_is_conventional_ram(paddr_t p);
    18.9 +
   18.10  #endif /* __XEN_MM_H__ */
    19.1 --- a/xen/include/xen/vga.h	Wed Aug 16 18:11:33 2006 +0100
    19.2 +++ b/xen/include/xen/vga.h	Wed Aug 16 18:20:03 2006 +0100
    19.3 @@ -9,10 +9,16 @@
    19.4  #ifndef _XEN_VGA_H
    19.5  #define _XEN_VGA_H
    19.6  
    19.7 -struct font_desc;
    19.8 +#include <xen/config.h>
    19.9  
   19.10 -void *setup_vga(void);
   19.11 -void vga_cursor_off(void);
   19.12 -int vga_load_font(const struct font_desc *, unsigned rows);
   19.13 +#ifdef CONFIG_VGA
   19.14 +void vga_init(void);
   19.15 +void vga_endboot(void);
   19.16 +void vga_putchar(int c);
   19.17 +#else
   19.18 +#define vga_init()     ((void)0)
   19.19 +#define vga_endboot()  ((void)0)
   19.20 +#define vga_putchar(c) ((void)0)
   19.21 +#endif
   19.22  
   19.23  #endif /* _XEN_VGA_H */