ia64/xen-unstable

changeset 12892:1ad7dff99968

[qemu patches] Update patches upto changeset 12814:c3ad3fcfe3.

Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
author Christian Limpach <Christian.Limpach@xensource.com>
date Fri Dec 08 18:37:19 2006 +0000 (2006-12-08)
parents c3ad3fcfe364
children 8cddaee4a51c
files tools/ioemu/patches/domain-timeoffset tools/ioemu/patches/series tools/ioemu/patches/tpm-tis-device tools/ioemu/patches/usb-mouse-tablet-status-check tools/ioemu/patches/xen-mapcache
line diff
     1.1 --- a/tools/ioemu/patches/domain-timeoffset	Fri Dec 08 18:31:01 2006 +0000
     1.2 +++ b/tools/ioemu/patches/domain-timeoffset	Fri Dec 08 18:37:19 2006 +0000
     1.3 @@ -1,7 +1,7 @@
     1.4  Index: ioemu/hw/mc146818rtc.c
     1.5  ===================================================================
     1.6 ---- ioemu.orig/hw/mc146818rtc.c	2006-12-08 18:23:40.000000000 +0000
     1.7 -+++ ioemu/hw/mc146818rtc.c	2006-12-08 18:23:46.000000000 +0000
     1.8 +--- ioemu.orig/hw/mc146818rtc.c	2006-12-08 18:36:31.000000000 +0000
     1.9 ++++ ioemu/hw/mc146818rtc.c	2006-12-08 18:36:36.000000000 +0000
    1.10  @@ -178,10 +178,27 @@
    1.11       }
    1.12   }
    1.13 @@ -46,8 +46,8 @@ Index: ioemu/hw/mc146818rtc.c
    1.14   static void rtc_copy_date(RTCState *s)
    1.15  Index: ioemu/hw/pc.c
    1.16  ===================================================================
    1.17 ---- ioemu.orig/hw/pc.c	2006-12-08 18:23:46.000000000 +0000
    1.18 -+++ ioemu/hw/pc.c	2006-12-08 18:23:46.000000000 +0000
    1.19 +--- ioemu.orig/hw/pc.c	2006-12-08 18:36:35.000000000 +0000
    1.20 ++++ ioemu/hw/pc.c	2006-12-08 18:36:36.000000000 +0000
    1.21  @@ -159,7 +159,7 @@
    1.22   }
    1.23   
    1.24 @@ -117,8 +117,8 @@ Index: ioemu/hw/pc.c
    1.25   QEMUMachine pc_machine = {
    1.26  Index: ioemu/vl.c
    1.27  ===================================================================
    1.28 ---- ioemu.orig/vl.c	2006-12-08 18:23:46.000000000 +0000
    1.29 -+++ ioemu/vl.c	2006-12-08 18:23:46.000000000 +0000
    1.30 +--- ioemu.orig/vl.c	2006-12-08 18:36:35.000000000 +0000
    1.31 ++++ ioemu/vl.c	2006-12-08 18:36:36.000000000 +0000
    1.32  @@ -163,6 +163,8 @@
    1.33   
    1.34   int xc_handle;
    1.35 @@ -174,8 +174,8 @@ Index: ioemu/vl.c
    1.36       if (usb_enabled) {
    1.37  Index: ioemu/vl.h
    1.38  ===================================================================
    1.39 ---- ioemu.orig/vl.h	2006-12-08 18:23:46.000000000 +0000
    1.40 -+++ ioemu/vl.h	2006-12-08 18:23:46.000000000 +0000
    1.41 +--- ioemu.orig/vl.h	2006-12-08 18:36:35.000000000 +0000
    1.42 ++++ ioemu/vl.h	2006-12-08 18:36:36.000000000 +0000
    1.43  @@ -576,7 +576,7 @@
    1.44                                    int boot_device,
    1.45                DisplayState *ds, const char **fd_filename, int snapshot,
     2.1 --- a/tools/ioemu/patches/series	Fri Dec 08 18:31:01 2006 +0000
     2.2 +++ b/tools/ioemu/patches/series	Fri Dec 08 18:37:19 2006 +0000
     2.3 @@ -67,3 +67,5 @@ usb-uhci-buffer-size
     2.4  vnc-monitor-shift-key-processing
     2.5  ide-error-reporting
     2.6  vnc-numpad-handling
     2.7 +xen-mapcache -p3
     2.8 +usb-mouse-tablet-status-check -p3
     3.1 --- a/tools/ioemu/patches/tpm-tis-device	Fri Dec 08 18:31:01 2006 +0000
     3.2 +++ b/tools/ioemu/patches/tpm-tis-device	Fri Dec 08 18:37:19 2006 +0000
     3.3 @@ -22,8 +22,8 @@ Signed-off-by: Stefan Berger <stefanb@us
     3.4  
     3.5  Index: ioemu/Makefile.target
     3.6  ===================================================================
     3.7 ---- ioemu.orig/Makefile.target	2006-12-08 18:20:53.000000000 +0000
     3.8 -+++ ioemu/Makefile.target	2006-12-08 18:21:18.000000000 +0000
     3.9 +--- ioemu.orig/Makefile.target	2006-12-08 18:33:48.000000000 +0000
    3.10 ++++ ioemu/Makefile.target	2006-12-08 18:35:14.000000000 +0000
    3.11  @@ -369,6 +369,7 @@
    3.12   VL_OBJS+= piix4acpi.o
    3.13   VL_OBJS+= xenstore.o
    3.14 @@ -34,8 +34,8 @@ Index: ioemu/Makefile.target
    3.15   ifeq ($(TARGET_BASE_ARCH), ppc)
    3.16  Index: ioemu/hw/pc.c
    3.17  ===================================================================
    3.18 ---- ioemu.orig/hw/pc.c	2006-12-08 18:20:52.000000000 +0000
    3.19 -+++ ioemu/hw/pc.c	2006-12-08 18:21:18.000000000 +0000
    3.20 +--- ioemu.orig/hw/pc.c	2006-12-08 18:33:47.000000000 +0000
    3.21 ++++ ioemu/hw/pc.c	2006-12-08 18:33:48.000000000 +0000
    3.22  @@ -875,6 +875,9 @@
    3.23           }
    3.24       }
    3.25 @@ -49,8 +49,8 @@ Index: ioemu/hw/pc.c
    3.26  Index: ioemu/hw/tpm_tis.c
    3.27  ===================================================================
    3.28  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
    3.29 -+++ ioemu/hw/tpm_tis.c	2006-12-08 18:21:18.000000000 +0000
    3.30 -@@ -0,0 +1,1114 @@
    3.31 ++++ ioemu/hw/tpm_tis.c	2006-12-08 18:35:25.000000000 +0000
    3.32 +@@ -0,0 +1,1120 @@
    3.33  +/*
    3.34  + * tpm_tis.c - QEMU emulator for a 1.2 TPM with TIS interface
    3.35  + *
    3.36 @@ -185,7 +185,7 @@ Index: ioemu/hw/tpm_tis.c
    3.37  +
    3.38  +
    3.39  +/* local prototypes */
    3.40 -+static int TPM_Send(tpmState *s, tpmBuffer *buffer, char *msg);
    3.41 ++static int TPM_Send(tpmState *s, tpmBuffer *buffer, uint8_t locty, char *msg);
    3.42  +static int TPM_Receive(tpmState *s, tpmBuffer *buffer);
    3.43  +static uint32_t vtpm_instance_from_xenstore(void);
    3.44  +static void tis_poll_timer(void *opaque);
    3.45 @@ -324,6 +324,8 @@ Index: ioemu/hw/tpm_tis.c
    3.46  +/*
    3.47  + * the 'write' method for sending requests to the vTPM
    3.48  + * four bytes with the vTPM instance number are prepended to each request
    3.49 ++ * the locality in which the command was sent is transmitted in the
    3.50 ++ * highest 3 bits
    3.51  + */
    3.52  +static int write_local_socket(tpmState *s, const tpmBuffer *buffer)
    3.53  +{
    3.54 @@ -661,7 +663,7 @@ Index: ioemu/hw/tpm_tis.c
    3.55  +            }
    3.56  +        }
    3.57  +        if (val & STS_TPM_GO) {
    3.58 -+            n = TPM_Send(s, &s->buffer,"tpm_data_write");
    3.59 ++            n = TPM_Send(s, &s->buffer, locty, "tpm_data_write");
    3.60  +            if (n > 0) {
    3.61  +                /* sending of data was successful */
    3.62  +                s->offset = 0;
    3.63 @@ -968,7 +970,7 @@ Index: ioemu/hw/tpm_tis.c
    3.64  +/*
    3.65  + * Send a TPM request.
    3.66  + */
    3.67 -+static int TPM_Send(tpmState *s, tpmBuffer *buffer, char *msg)
    3.68 ++static int TPM_Send(tpmState *s, tpmBuffer *buffer, uint8_t locty, char *msg)
    3.69  +{
    3.70  +    int len;
    3.71  +    uint32_t size = tpm_get_size_from_buffer(buffer->buf);
    3.72 @@ -998,6 +1000,10 @@ Index: ioemu/hw/tpm_tis.c
    3.73  +    showBuff(buffer->buf, "To TPM");
    3.74  +#endif
    3.75  +
    3.76 ++    /* transmit the locality in the highest 3 bits */
    3.77 ++    buffer->instance[0] &= 0x1f;
    3.78 ++    buffer->instance[0] |= (locty << 5);
    3.79 ++
    3.80  +    len = vTPMTransmit[s->Transmitlayer].write(s, buffer);
    3.81  +    if (len < 0) {
    3.82  +        s->Transmitlayer = -1;
    3.83 @@ -1167,8 +1173,8 @@ Index: ioemu/hw/tpm_tis.c
    3.84  +}
    3.85  Index: ioemu/vl.h
    3.86  ===================================================================
    3.87 ---- ioemu.orig/vl.h	2006-12-08 18:20:53.000000000 +0000
    3.88 -+++ ioemu/vl.h	2006-12-08 18:21:18.000000000 +0000
    3.89 +--- ioemu.orig/vl.h	2006-12-08 18:33:48.000000000 +0000
    3.90 ++++ ioemu/vl.h	2006-12-08 18:35:14.000000000 +0000
    3.91  @@ -932,6 +932,10 @@
    3.92   void piix4_pm_init(PCIBus *bus, int devfn);
    3.93   void acpi_bios_init(void);
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/ioemu/patches/usb-mouse-tablet-status-check	Fri Dec 08 18:37:19 2006 +0000
     4.3 @@ -0,0 +1,168 @@
     4.4 +# HG changeset patch
     4.5 +# User kfraser@localhost.localdomain
     4.6 +# Node ID 60bbcf799384d779c2a561b9d9ba30f28e31d970
     4.7 +# Parent  fb3cb6f52a2905be938559529ae43b6ba990c878
     4.8 +[HVM] qemu mouse: Adds support for USB mouse/tablet status check and
     4.9 +restricts Universal Host Controller interrupt generating when received
    4.10 +NAK in interrupt transfer.
    4.11 +
    4.12 +According to usb spec, USB mouse/tablet device returns NAK to host
    4.13 +controller if its status does not alter in interrupt transfer.
    4.14 +And UHC should leave a TD active when receiving NAK and execute this
    4.15 +incompleted TD in a subseqent frame. UHC only generates an interrupt
    4.16 +on complete after the TD with ICO bit is completed.
    4.17 +
    4.18 +This patch make UHC & USB mouse/tablet behave consistently with spec.
    4.19 +
    4.20 +Signed-off-by: Xinmei Huang <xinmei.huang@intel.com>
    4.21 +
    4.22 +diff -r fb3cb6f52a29 -r 60bbcf799384 tools/ioemu/hw/usb-hid.c
    4.23 +--- a/tools/ioemu/hw/usb-hid.c	Thu Dec 07 11:51:22 2006 +0000
    4.24 ++++ b/tools/ioemu/hw/usb-hid.c	Thu Dec 07 11:52:26 2006 +0000
    4.25 +@@ -39,6 +39,7 @@ typedef struct USBMouseState {
    4.26 +     int x, y;
    4.27 +     int kind;
    4.28 +     int mouse_grabbed;
    4.29 ++    int status_changed;
    4.30 + } USBMouseState;
    4.31 + 
    4.32 + /* mostly the same values as the Bochs USB Mouse device */
    4.33 +@@ -231,6 +232,7 @@ static void usb_mouse_event(void *opaque
    4.34 +     s->dy += dy1;
    4.35 +     s->dz += dz1;
    4.36 +     s->buttons_state = buttons_state;
    4.37 ++    s->status_changed = 1;
    4.38 + }
    4.39 + 
    4.40 + static void usb_tablet_event(void *opaque,
    4.41 +@@ -242,6 +244,7 @@ static void usb_tablet_event(void *opaqu
    4.42 +     s->y = y;
    4.43 +     s->dz += dz;
    4.44 +     s->buttons_state = buttons_state;
    4.45 ++    s->status_changed = 1;
    4.46 + }
    4.47 + 
    4.48 + static inline int int_clamp(int val, int vmin, int vmax)
    4.49 +@@ -483,10 +486,16 @@ static int usb_mouse_handle_data(USBDevi
    4.50 +     switch(pid) {
    4.51 +     case USB_TOKEN_IN:
    4.52 +         if (devep == 1) {
    4.53 +-	    if (s->kind == USB_MOUSE)
    4.54 +-		ret = usb_mouse_poll(s, data, len);
    4.55 +-	    else if (s->kind == USB_TABLET)
    4.56 +-		ret = usb_tablet_poll(s, data, len);
    4.57 ++            if (s->kind == USB_MOUSE)
    4.58 ++                ret = usb_mouse_poll(s, data, len);
    4.59 ++            else if (s->kind == USB_TABLET)
    4.60 ++                ret = usb_tablet_poll(s, data, len);
    4.61 ++
    4.62 ++            if (!s->status_changed)
    4.63 ++                ret = USB_RET_NAK;
    4.64 ++            else
    4.65 ++                s->status_changed = 0;
    4.66 ++
    4.67 +         } else {
    4.68 +             goto fail;
    4.69 +         }
    4.70 +@@ -523,6 +532,7 @@ USBDevice *usb_tablet_init(void)
    4.71 +     s->dev.handle_data = usb_mouse_handle_data;
    4.72 +     s->dev.handle_destroy = usb_mouse_handle_destroy;
    4.73 +     s->kind = USB_TABLET;
    4.74 ++    s->status_changed = 0;
    4.75 + 
    4.76 +     pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Tablet");
    4.77 + 
    4.78 +@@ -544,6 +554,7 @@ USBDevice *usb_mouse_init(void)
    4.79 +     s->dev.handle_data = usb_mouse_handle_data;
    4.80 +     s->dev.handle_destroy = usb_mouse_handle_destroy;
    4.81 +     s->kind = USB_MOUSE;
    4.82 ++    s->status_changed = 0;
    4.83 + 
    4.84 +     pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Mouse");
    4.85 + 
    4.86 +diff -r fb3cb6f52a29 -r 60bbcf799384 tools/ioemu/hw/usb-uhci.c
    4.87 +--- a/tools/ioemu/hw/usb-uhci.c	Thu Dec 07 11:51:22 2006 +0000
    4.88 ++++ b/tools/ioemu/hw/usb-uhci.c	Thu Dec 07 11:52:26 2006 +0000
    4.89 +@@ -424,12 +424,10 @@ static int uhci_handle_td(UHCIState *s, 
    4.90 +     uint8_t buf[2048];
    4.91 +     int len, max_len, err, ret;
    4.92 + 
    4.93 +-    if (td->ctrl & TD_CTRL_IOC) {
    4.94 +-        *int_mask |= 0x01;
    4.95 +-    }
    4.96 +-    
    4.97 +-    if (!(td->ctrl & TD_CTRL_ACTIVE))
    4.98 +-        return 1;
    4.99 ++    if (!(td->ctrl & TD_CTRL_ACTIVE)){
   4.100 ++        ret = 1;
   4.101 ++        goto out;
   4.102 ++    }
   4.103 + 
   4.104 +     /* TD is active */
   4.105 +     max_len = ((td->token >> 21) + 1) & 0x7ff;
   4.106 +@@ -467,7 +465,8 @@ static int uhci_handle_td(UHCIState *s, 
   4.107 +         /* invalid pid : frame interrupted */
   4.108 +         s->status |= UHCI_STS_HCPERR;
   4.109 +         uhci_update_irq(s);
   4.110 +-        return -1;
   4.111 ++        ret = -1;
   4.112 ++        goto out;
   4.113 +     }
   4.114 +     if (td->ctrl & TD_CTRL_IOS)
   4.115 +         td->ctrl &= ~TD_CTRL_ACTIVE;
   4.116 +@@ -479,10 +478,12 @@ static int uhci_handle_td(UHCIState *s, 
   4.117 +             len < max_len) {
   4.118 +             *int_mask |= 0x02;
   4.119 +             /* short packet: do not update QH */
   4.120 +-            return 1;
   4.121 ++            ret = 1;
   4.122 ++            goto out;
   4.123 +         } else {
   4.124 +             /* success */
   4.125 +-            return 0;
   4.126 ++            ret = 0;
   4.127 ++            goto out;
   4.128 +         }
   4.129 +     } else {
   4.130 +         switch(ret) {
   4.131 +@@ -501,23 +502,34 @@ static int uhci_handle_td(UHCIState *s, 
   4.132 +             }
   4.133 +             td->ctrl = (td->ctrl & ~(3 << TD_CTRL_ERROR_SHIFT)) | 
   4.134 +                 (err << TD_CTRL_ERROR_SHIFT);
   4.135 +-            return 1;
   4.136 ++            ret = 1;
   4.137 ++            goto out;
   4.138 +         case USB_RET_NAK:
   4.139 +             td->ctrl |= TD_CTRL_NAK;
   4.140 +             if (pid == USB_TOKEN_SETUP)
   4.141 +                 goto do_timeout;
   4.142 +-            return 1;
   4.143 ++            ret = 1;
   4.144 ++            goto out;
   4.145 +         case USB_RET_STALL:
   4.146 +             td->ctrl |= TD_CTRL_STALL;
   4.147 +             td->ctrl &= ~TD_CTRL_ACTIVE;
   4.148 +-            return 1;
   4.149 ++            ret = 1;
   4.150 ++            goto out;
   4.151 +         case USB_RET_BABBLE:
   4.152 +             td->ctrl |= TD_CTRL_BABBLE | TD_CTRL_STALL;
   4.153 +             td->ctrl &= ~TD_CTRL_ACTIVE;
   4.154 +             /* frame interrupted */
   4.155 +-            return -1;
   4.156 +-        }
   4.157 +-    }
   4.158 ++            ret = -1;
   4.159 ++            goto out;
   4.160 ++        }
   4.161 ++    }
   4.162 ++   
   4.163 ++out:
   4.164 ++    /* If TD is inactive and IOC bit set to 1 then update int_mask */ 
   4.165 ++    if ((td->ctrl & TD_CTRL_IOC) && (!(td->ctrl & TD_CTRL_ACTIVE))) {
   4.166 ++        *int_mask |= 0x01;
   4.167 ++    }
   4.168 ++    return ret;
   4.169 + }
   4.170 + 
   4.171 + static void uhci_frame_timer(void *opaque)
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/ioemu/patches/xen-mapcache	Fri Dec 08 18:37:19 2006 +0000
     5.3 @@ -0,0 +1,300 @@
     5.4 +# HG changeset patch
     5.5 +# User kfraser@localhost.localdomain
     5.6 +# Node ID 67a06a9b7b1dca707e1cd3b08ae0a341d6e97b3d
     5.7 +# Parent  3f0ca90351e268084fbdb733d70fc596cb46537d
     5.8 +[HVM] qemu: Add guest address-space mapping cache.
     5.9 +
    5.10 +On IA32 host or IA32 PAE host, at present, generally, we can't create
    5.11 +an HVM guest with more than 2G memory, because generally it's almost
    5.12 +impossible for Qemu to find a large enough and consecutive virtual
    5.13 +address space to map an HVM guest's whole physical address space.
    5.14 +The attached patch fixes this issue using dynamic mapping based on
    5.15 +little blocks of memory.
    5.16 +
    5.17 +Signed-off-by: Jun Nakajima <jun.nakajima@intel.com>
    5.18 +Signed-off-by: Dexuan Cui <dexuan.cui@intel.com>
    5.19 +Signed-off-by: Keir Fraser <keir@xensource.com>
    5.20 +
    5.21 +diff -r 3f0ca90351e2 -r 67a06a9b7b1d tools/ioemu/target-i386-dm/cpu.h
    5.22 +--- a/tools/ioemu/target-i386-dm/cpu.h	Thu Dec 07 10:54:43 2006 +0000
    5.23 ++++ b/tools/ioemu/target-i386-dm/cpu.h	Thu Dec 07 11:12:52 2006 +0000
    5.24 +@@ -25,7 +25,8 @@
    5.25 + #ifdef TARGET_X86_64
    5.26 + #define TARGET_LONG_BITS 64
    5.27 + #else
    5.28 +-#define TARGET_LONG_BITS 32
    5.29 ++/* #define TARGET_LONG_BITS 32 */
    5.30 ++#define TARGET_LONG_BITS 64 /* for Qemu map cache */
    5.31 + #endif
    5.32 + 
    5.33 + /* target supports implicit self modifying code */
    5.34 +diff -r 3f0ca90351e2 -r 67a06a9b7b1d tools/ioemu/target-i386-dm/exec-dm.c
    5.35 +--- a/tools/ioemu/target-i386-dm/exec-dm.c	Thu Dec 07 10:54:43 2006 +0000
    5.36 ++++ b/tools/ioemu/target-i386-dm/exec-dm.c	Thu Dec 07 11:12:52 2006 +0000
    5.37 +@@ -36,6 +36,7 @@
    5.38 + 
    5.39 + #include "cpu.h"
    5.40 + #include "exec-all.h"
    5.41 ++#include "vl.h"
    5.42 + 
    5.43 + //#define DEBUG_TB_INVALIDATE
    5.44 + //#define DEBUG_FLUSH
    5.45 +@@ -426,6 +427,12 @@ static inline int paddr_is_ram(target_ph
    5.46 + #endif
    5.47 + }
    5.48 + 
    5.49 ++#if defined(__i386__) || defined(__x86_64__)
    5.50 ++#define phys_ram_addr(x) (qemu_map_cache(x))
    5.51 ++#elif defined(__ia64__)
    5.52 ++#define phys_ram_addr(x) (phys_ram_base + (x))
    5.53 ++#endif
    5.54 ++
    5.55 + void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, 
    5.56 +                             int len, int is_write)
    5.57 + {
    5.58 +@@ -438,7 +445,7 @@ void cpu_physical_memory_rw(target_phys_
    5.59 +         l = TARGET_PAGE_SIZE - (addr & ~TARGET_PAGE_MASK); 
    5.60 +         if (l > len)
    5.61 +             l = len;
    5.62 +-	
    5.63 ++
    5.64 +         io_index = iomem_index(addr);
    5.65 +         if (is_write) {
    5.66 +             if (io_index) {
    5.67 +@@ -460,9 +467,10 @@ void cpu_physical_memory_rw(target_phys_
    5.68 +                 }
    5.69 +             } else if (paddr_is_ram(addr)) {
    5.70 +                 /* Reading from RAM */
    5.71 +-                memcpy(phys_ram_base + addr, buf, l);
    5.72 ++                ptr = phys_ram_addr(addr);
    5.73 ++                memcpy(ptr, buf, l);
    5.74 + #ifdef __ia64__
    5.75 +-                sync_icache((unsigned long)(phys_ram_base + addr), l);
    5.76 ++                sync_icache(ptr, l);
    5.77 + #endif 
    5.78 +             }
    5.79 +         } else {
    5.80 +@@ -485,7 +493,8 @@ void cpu_physical_memory_rw(target_phys_
    5.81 +                 }
    5.82 +             } else if (paddr_is_ram(addr)) {
    5.83 +                 /* Reading from RAM */
    5.84 +-                memcpy(buf, phys_ram_base + addr, l);
    5.85 ++                ptr = phys_ram_addr(addr);
    5.86 ++                memcpy(buf, ptr, l);
    5.87 +             } else {
    5.88 +                 /* Neither RAM nor known MMIO space */
    5.89 +                 memset(buf, 0xff, len); 
    5.90 +diff -r 3f0ca90351e2 -r 67a06a9b7b1d tools/ioemu/vl.c
    5.91 +--- a/tools/ioemu/vl.c	Thu Dec 07 10:54:43 2006 +0000
    5.92 ++++ b/tools/ioemu/vl.c	Thu Dec 07 11:12:52 2006 +0000
    5.93 +@@ -5807,6 +5807,92 @@ int set_mm_mapping(int xc_handle, uint32
    5.94 + 
    5.95 +     return 0;
    5.96 + }
    5.97 ++
    5.98 ++#if defined(__i386__) || defined(__x86_64__)
    5.99 ++static struct map_cache *mapcache_entry;
   5.100 ++static unsigned long nr_buckets;
   5.101 ++
   5.102 ++static int qemu_map_cache_init(unsigned long nr_pages)
   5.103 ++{
   5.104 ++    unsigned long max_pages = MAX_MCACHE_SIZE >> PAGE_SHIFT;
   5.105 ++    int i;
   5.106 ++
   5.107 ++    if (nr_pages < max_pages)
   5.108 ++        max_pages = nr_pages;
   5.109 ++
   5.110 ++    nr_buckets = (max_pages << PAGE_SHIFT) >> MCACHE_BUCKET_SHIFT;
   5.111 ++
   5.112 ++    fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx\n", nr_buckets);
   5.113 ++
   5.114 ++    mapcache_entry = malloc(nr_buckets * sizeof(struct map_cache));
   5.115 ++    if (mapcache_entry == NULL) {
   5.116 ++        errno = ENOMEM;
   5.117 ++        return -1;
   5.118 ++    }
   5.119 ++
   5.120 ++    memset(mapcache_entry, 0, nr_buckets * sizeof(struct map_cache));
   5.121 ++
   5.122 ++    /*
   5.123 ++     * To avoid ENOMEM from xc_map_foreign_batch() at runtime, we
   5.124 ++     * pre-fill all the map caches in advance.
   5.125 ++     */
   5.126 ++    for (i = 0; i < nr_buckets; i++)
   5.127 ++       (void)qemu_map_cache(((target_phys_addr_t)i) << MCACHE_BUCKET_SHIFT);
   5.128 ++
   5.129 ++    return 0;
   5.130 ++}
   5.131 ++
   5.132 ++uint8_t *qemu_map_cache(target_phys_addr_t phys_addr)
   5.133 ++{
   5.134 ++    struct map_cache *entry;
   5.135 ++    unsigned long address_index  = phys_addr >> MCACHE_BUCKET_SHIFT;
   5.136 ++    unsigned long address_offset = phys_addr & (MCACHE_BUCKET_SIZE-1);
   5.137 ++
   5.138 ++    /* For most cases (>99.9%), the page address is the same. */
   5.139 ++    static unsigned long last_address_index = ~0UL;
   5.140 ++    static uint8_t      *last_address_vaddr;
   5.141 ++
   5.142 ++    if (address_index == last_address_index)
   5.143 ++        return last_address_vaddr + address_offset;
   5.144 ++
   5.145 ++    entry = &mapcache_entry[address_index % nr_buckets];
   5.146 ++
   5.147 ++    if (entry->vaddr_base == NULL || entry->paddr_index != address_index)
   5.148 ++    { 
   5.149 ++        /* We need to remap a bucket. */
   5.150 ++        uint8_t *vaddr_base;
   5.151 ++        unsigned long pfns[MCACHE_BUCKET_SIZE >> PAGE_SHIFT];
   5.152 ++        unsigned int i;
   5.153 ++
   5.154 ++        if (entry->vaddr_base != NULL) {
   5.155 ++            errno = munmap(entry->vaddr_base, MCACHE_BUCKET_SIZE);
   5.156 ++            if (errno) {
   5.157 ++                fprintf(logfile, "unmap fails %d\n", errno);
   5.158 ++                exit(-1);
   5.159 ++            }
   5.160 ++        }
   5.161 ++
   5.162 ++        for (i = 0; i < MCACHE_BUCKET_SIZE >> PAGE_SHIFT; i++)
   5.163 ++            pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-PAGE_SHIFT)) + i;
   5.164 ++
   5.165 ++        vaddr_base = xc_map_foreign_batch(
   5.166 ++            xc_handle, domid, PROT_READ|PROT_WRITE,
   5.167 ++            pfns, MCACHE_BUCKET_SIZE >> PAGE_SHIFT);
   5.168 ++        if (vaddr_base == NULL) {
   5.169 ++            fprintf(logfile, "xc_map_foreign_batch error %d\n", errno);
   5.170 ++            exit(-1);
   5.171 ++        }
   5.172 ++
   5.173 ++        entry->vaddr_base  = vaddr_base;
   5.174 ++        entry->paddr_index = address_index;;
   5.175 ++    }
   5.176 ++
   5.177 ++    last_address_index = address_index;
   5.178 ++    last_address_vaddr = entry->vaddr_base;
   5.179 ++
   5.180 ++    return last_address_vaddr + address_offset;
   5.181 ++}
   5.182 ++#endif
   5.183 + 
   5.184 + int main(int argc, char **argv)
   5.185 + {
   5.186 +@@ -6130,6 +6216,7 @@ int main(int argc, char **argv)
   5.187 +                 break;
   5.188 +             case QEMU_OPTION_m:
   5.189 +                 ram_size = atol(optarg) * 1024 * 1024;
   5.190 ++                ram_size = (uint64_t)atol(optarg) * 1024 * 1024;
   5.191 +                 if (ram_size <= 0)
   5.192 +                     help();
   5.193 + #ifndef CONFIG_DM
   5.194 +@@ -6400,50 +6487,41 @@ int main(int argc, char **argv)
   5.195 +         shared_page_nr = nr_pages - 1;
   5.196 + #endif
   5.197 + 
   5.198 ++#if defined(__i386__) || defined(__x86_64__)
   5.199 ++
   5.200 ++    if ( qemu_map_cache_init(tmp_nr_pages) )
   5.201 ++    {
   5.202 ++        fprintf(logfile, "qemu_map_cache_init returned: error %d\n", errno);
   5.203 ++        exit(-1);
   5.204 ++    }
   5.205 ++
   5.206 ++    shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   5.207 ++                                       PROT_READ|PROT_WRITE, shared_page_nr);
   5.208 ++    if (shared_page == NULL) {
   5.209 ++        fprintf(logfile, "map shared IO page returned error %d\n", errno);
   5.210 ++        exit(-1);
   5.211 ++    }
   5.212 ++
   5.213 ++    fprintf(logfile, "shared page at pfn:%lx\n", shared_page_nr);
   5.214 ++
   5.215 ++    buffered_io_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   5.216 ++                                            PROT_READ|PROT_WRITE,
   5.217 ++                                            shared_page_nr - 2);
   5.218 ++    if (buffered_io_page == NULL) {
   5.219 ++        fprintf(logfile, "map buffered IO page returned error %d\n", errno);
   5.220 ++        exit(-1);
   5.221 ++    }
   5.222 ++
   5.223 ++    fprintf(logfile, "buffered io page at pfn:%lx\n", shared_page_nr - 2);
   5.224 ++
   5.225 ++#elif defined(__ia64__)
   5.226 ++
   5.227 +     page_array = (xen_pfn_t *)malloc(tmp_nr_pages * sizeof(xen_pfn_t));
   5.228 +     if (page_array == NULL) {
   5.229 +         fprintf(logfile, "malloc returned error %d\n", errno);
   5.230 +         exit(-1);
   5.231 +     }
   5.232 + 
   5.233 +-#if defined(__i386__) || defined(__x86_64__)
   5.234 +-    for ( i = 0; i < tmp_nr_pages; i++)
   5.235 +-        page_array[i] = i;
   5.236 +-
   5.237 +-    phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
   5.238 +-                                         PROT_READ|PROT_WRITE, page_array,
   5.239 +-                                         tmp_nr_pages);
   5.240 +-    if (phys_ram_base == NULL) {
   5.241 +-        fprintf(logfile, "batch map guest memory returned error %d\n", errno);
   5.242 +-        exit(-1);
   5.243 +-    }
   5.244 +-
   5.245 +-    shared_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   5.246 +-                                       PROT_READ|PROT_WRITE,
   5.247 +-                                       page_array[shared_page_nr]);
   5.248 +-    if (shared_page == NULL) {
   5.249 +-        fprintf(logfile, "map shared IO page returned error %d\n", errno);
   5.250 +-        exit(-1);
   5.251 +-    }
   5.252 +-
   5.253 +-    fprintf(logfile, "shared page at pfn:%lx, mfn: %"PRIx64"\n",
   5.254 +-            shared_page_nr, (uint64_t)(page_array[shared_page_nr]));
   5.255 +-
   5.256 +-    buffered_io_page = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
   5.257 +-                                            PROT_READ|PROT_WRITE,
   5.258 +-                                            page_array[shared_page_nr - 2]);
   5.259 +-    if (buffered_io_page == NULL) {
   5.260 +-        fprintf(logfile, "map buffered IO page returned error %d\n", errno);
   5.261 +-        exit(-1);
   5.262 +-    }
   5.263 +-
   5.264 +-    fprintf(logfile, "buffered io page at pfn:%lx, mfn: %"PRIx64"\n",
   5.265 +-            shared_page_nr - 2, (uint64_t)(page_array[shared_page_nr - 2]));
   5.266 +-
   5.267 +-    free(page_array);
   5.268 +-
   5.269 +-#elif defined(__ia64__)
   5.270 +-  
   5.271 +     if (xc_ia64_get_pfn_list(xc_handle, domid, page_array,
   5.272 +                              IO_PAGE_START >> PAGE_SHIFT, 3) != 3) {
   5.273 +         fprintf(logfile, "xc_ia64_get_pfn_list returned error %d\n", errno);
   5.274 +diff -r 3f0ca90351e2 -r 67a06a9b7b1d tools/ioemu/vl.h
   5.275 +--- a/tools/ioemu/vl.h	Thu Dec 07 10:54:43 2006 +0000
   5.276 ++++ b/tools/ioemu/vl.h	Thu Dec 07 11:12:52 2006 +0000
   5.277 +@@ -156,6 +156,26 @@ extern void *shared_vram;
   5.278 + 
   5.279 + extern FILE *logfile;
   5.280 + 
   5.281 ++
   5.282 ++#if defined(__i386__) || defined(__x86_64__)
   5.283 ++#if defined(__i386__) 
   5.284 ++#define MAX_MCACHE_SIZE    0x40000000 /* 1GB max for x86 */
   5.285 ++#define MCACHE_BUCKET_SHIFT 16
   5.286 ++#elif defined(__x86_64__)
   5.287 ++#define MAX_MCACHE_SIZE    0x1000000000 /* 64GB max for x86_64 */
   5.288 ++#define MCACHE_BUCKET_SHIFT 20
   5.289 ++#endif
   5.290 ++
   5.291 ++#define MCACHE_BUCKET_SIZE (1UL << MCACHE_BUCKET_SHIFT)
   5.292 ++
   5.293 ++struct map_cache {
   5.294 ++    unsigned long paddr_index;
   5.295 ++    uint8_t      *vaddr_base;
   5.296 ++};
   5.297 ++
   5.298 ++uint8_t *qemu_map_cache(target_phys_addr_t phys_addr);
   5.299 ++#endif
   5.300 ++
   5.301 + extern int xc_handle;
   5.302 + extern int domid;
   5.303 +