ia64/xen-unstable

changeset 17348:b5fea3aeb04b

hvm: Code cleanups.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Mar 28 14:12:33 2008 +0000 (2008-03-28)
parents d686808b3169
children 4e2e98c2098e
files xen/arch/x86/hvm/emulate.c xen/arch/x86/hvm/hvm.c xen/arch/x86/hvm/vmx/vmx.c xen/include/asm-x86/hvm/io.h xen/include/asm-x86/hvm/support.h xen/include/asm-x86/hvm/vmx/vmx.h
line diff
     1.1 --- a/xen/arch/x86/hvm/emulate.c	Fri Mar 28 11:17:11 2008 +0000
     1.2 +++ b/xen/arch/x86/hvm/emulate.c	Fri Mar 28 14:12:33 2008 +0000
     1.3 @@ -522,12 +522,6 @@ static int hvmemul_write_io(
     1.4      unsigned long val,
     1.5      struct x86_emulate_ctxt *ctxt)
     1.6  {
     1.7 -    if ( port == 0xe9 )
     1.8 -    {
     1.9 -        hvm_print_line(current, val);
    1.10 -        return X86EMUL_OKAY;
    1.11 -    }
    1.12 -
    1.13      return hvmemul_do_pio(port, 1, bytes, val, IOREQ_WRITE, 0, 0, NULL);
    1.14  }
    1.15  
     2.1 --- a/xen/arch/x86/hvm/hvm.c	Fri Mar 28 11:17:11 2008 +0000
     2.2 +++ b/xen/arch/x86/hvm/hvm.c	Fri Mar 28 14:12:33 2008 +0000
     2.3 @@ -255,6 +255,30 @@ static int hvm_set_ioreq_page(
     2.4      return 0;
     2.5  }
     2.6  
     2.7 +static int hvm_print_line(
     2.8 +    int dir, uint32_t port, uint32_t bytes, uint32_t *val)
     2.9 +{
    2.10 +    struct vcpu *curr = current;
    2.11 +    struct hvm_domain *hd = &curr->domain->arch.hvm_domain;
    2.12 +    char c = *val;
    2.13 +
    2.14 +    BUG_ON(bytes != 1);
    2.15 +
    2.16 +    spin_lock(&hd->pbuf_lock);
    2.17 +    hd->pbuf[hd->pbuf_idx++] = c;
    2.18 +    if ( (hd->pbuf_idx == (sizeof(hd->pbuf) - 2)) || (c == '\n') )
    2.19 +    {
    2.20 +        if ( c != '\n' )
    2.21 +            hd->pbuf[hd->pbuf_idx++] = '\n';
    2.22 +        hd->pbuf[hd->pbuf_idx] = '\0';
    2.23 +        printk(XENLOG_G_DEBUG "HVM%u: %s", curr->domain->domain_id, hd->pbuf);
    2.24 +        hd->pbuf_idx = 0;
    2.25 +    }
    2.26 +    spin_unlock(&hd->pbuf_lock);
    2.27 +
    2.28 +    return 1;
    2.29 +}
    2.30 +
    2.31  int hvm_domain_initialise(struct domain *d)
    2.32  {
    2.33      int rc;
    2.34 @@ -289,6 +313,8 @@ int hvm_domain_initialise(struct domain 
    2.35      hvm_init_ioreq_page(d, &d->arch.hvm_domain.ioreq);
    2.36      hvm_init_ioreq_page(d, &d->arch.hvm_domain.buf_ioreq);
    2.37  
    2.38 +    register_portio_handler(d, 0xe9, 1, hvm_print_line);
    2.39 +
    2.40      rc = hvm_funcs.domain_initialise(d);
    2.41      if ( rc != 0 )
    2.42          goto fail2;
    2.43 @@ -1579,24 +1605,6 @@ unsigned long copy_from_user_hvm(void *t
    2.44      return rc ? len : 0; /* fake a copy_from_user() return code */
    2.45  }
    2.46  
    2.47 -/* HVM specific printbuf. Mostly used for hvmloader chit-chat. */
    2.48 -void hvm_print_line(struct vcpu *v, const char c)
    2.49 -{
    2.50 -    struct hvm_domain *hd = &v->domain->arch.hvm_domain;
    2.51 -
    2.52 -    spin_lock(&hd->pbuf_lock);
    2.53 -    hd->pbuf[hd->pbuf_idx++] = c;
    2.54 -    if ( (hd->pbuf_idx == (sizeof(hd->pbuf) - 2)) || (c == '\n') )
    2.55 -    {
    2.56 -        if ( c != '\n' )
    2.57 -            hd->pbuf[hd->pbuf_idx++] = '\n';
    2.58 -        hd->pbuf[hd->pbuf_idx] = '\0';
    2.59 -        printk(XENLOG_G_DEBUG "HVM%u: %s", v->domain->domain_id, hd->pbuf);
    2.60 -        hd->pbuf_idx = 0;
    2.61 -    }
    2.62 -    spin_unlock(&hd->pbuf_lock);
    2.63 -}
    2.64 -
    2.65  #define bitmaskof(idx)  (1U << ((idx) & 31))
    2.66  void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx,
    2.67                                     unsigned int *ecx, unsigned int *edx)
     3.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Fri Mar 28 11:17:11 2008 +0000
     3.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Fri Mar 28 14:12:33 2008 +0000
     3.3 @@ -1240,23 +1240,6 @@ static void vmx_do_cpuid(struct cpu_user
     3.4      regs->edx = edx;
     3.5  }
     3.6  
     3.7 -#define CASE_GET_REG_P(REG, reg)    \
     3.8 -    case REG_ ## REG: reg_p = (unsigned long *)&(regs->reg); break
     3.9 -
    3.10 -#ifdef __i386__
    3.11 -#define CASE_EXTEND_GET_REG_P
    3.12 -#else
    3.13 -#define CASE_EXTEND_GET_REG_P       \
    3.14 -    CASE_GET_REG_P(R8, r8);         \
    3.15 -    CASE_GET_REG_P(R9, r9);         \
    3.16 -    CASE_GET_REG_P(R10, r10);       \
    3.17 -    CASE_GET_REG_P(R11, r11);       \
    3.18 -    CASE_GET_REG_P(R12, r12);       \
    3.19 -    CASE_GET_REG_P(R13, r13);       \
    3.20 -    CASE_GET_REG_P(R14, r14);       \
    3.21 -    CASE_GET_REG_P(R15, r15)
    3.22 -#endif
    3.23 -
    3.24  static void vmx_dr_access(unsigned long exit_qualification,
    3.25                            struct cpu_user_regs *regs)
    3.26  {
    3.27 @@ -1280,9 +1263,9 @@ static void vmx_invlpg_intercept(unsigne
    3.28  }
    3.29  
    3.30  #define CASE_SET_REG(REG, reg)      \
    3.31 -    case REG_ ## REG: regs->reg = value; break
    3.32 +    case VMX_CONTROL_REG_ACCESS_GPR_ ## REG: regs->reg = value; break
    3.33  #define CASE_GET_REG(REG, reg)      \
    3.34 -    case REG_ ## REG: value = regs->reg; break
    3.35 +    case VMX_CONTROL_REG_ACCESS_GPR_ ## REG: value = regs->reg; break
    3.36  
    3.37  #define CASE_EXTEND_SET_REG         \
    3.38      CASE_EXTEND_REG(S)
    3.39 @@ -1408,26 +1391,25 @@ static int vmx_cr_access(unsigned long e
    3.40      unsigned long value;
    3.41      struct vcpu *v = current;
    3.42  
    3.43 -    switch ( exit_qualification & CONTROL_REG_ACCESS_TYPE )
    3.44 +    switch ( exit_qualification & VMX_CONTROL_REG_ACCESS_TYPE )
    3.45      {
    3.46 -    case TYPE_MOV_TO_CR:
    3.47 -        gp = exit_qualification & CONTROL_REG_ACCESS_REG;
    3.48 -        cr = exit_qualification & CONTROL_REG_ACCESS_NUM;
    3.49 +    case VMX_CONTROL_REG_ACCESS_TYPE_MOV_TO_CR:
    3.50 +        gp = exit_qualification & VMX_CONTROL_REG_ACCESS_GPR;
    3.51 +        cr = exit_qualification & VMX_CONTROL_REG_ACCESS_NUM;
    3.52          return mov_to_cr(gp, cr, regs);
    3.53 -    case TYPE_MOV_FROM_CR:
    3.54 -        gp = exit_qualification & CONTROL_REG_ACCESS_REG;
    3.55 -        cr = exit_qualification & CONTROL_REG_ACCESS_NUM;
    3.56 +    case VMX_CONTROL_REG_ACCESS_TYPE_MOV_FROM_CR:
    3.57 +        gp = exit_qualification & VMX_CONTROL_REG_ACCESS_GPR;
    3.58 +        cr = exit_qualification & VMX_CONTROL_REG_ACCESS_NUM;
    3.59          mov_from_cr(cr, gp, regs);
    3.60          break;
    3.61 -    case TYPE_CLTS:
    3.62 +    case VMX_CONTROL_REG_ACCESS_TYPE_CLTS:
    3.63          v->arch.hvm_vcpu.guest_cr[0] &= ~X86_CR0_TS;
    3.64          vmx_update_guest_cr(v, 0);
    3.65          HVMTRACE_0D(CLTS, current);
    3.66          break;
    3.67 -    case TYPE_LMSW:
    3.68 +    case VMX_CONTROL_REG_ACCESS_TYPE_LMSW:
    3.69          value = v->arch.hvm_vcpu.guest_cr[0];
    3.70 -        value = (value & ~0xF) |
    3.71 -            (((exit_qualification & LMSW_SOURCE_DATA) >> 16) & 0xF);
    3.72 +        value = (value & ~0xFFFF) | ((exit_qualification >> 16) & 0xFFFF);
    3.73          HVMTRACE_1D(LMSW, current, value);
    3.74          return !hvm_set_cr0(value);
    3.75      default:
     4.1 --- a/xen/include/asm-x86/hvm/io.h	Fri Mar 28 11:17:11 2008 +0000
     4.2 +++ b/xen/include/asm-x86/hvm/io.h	Fri Mar 28 14:12:33 2008 +0000
     4.3 @@ -25,10 +25,9 @@
     4.4  #include <public/hvm/ioreq.h>
     4.5  #include <public/event_channel.h>
     4.6  
     4.7 -#define MAX_IO_HANDLER             12
     4.8 +#define MAX_IO_HANDLER             16
     4.9  
    4.10  #define HVM_PORTIO                  0
    4.11 -#define HVM_MMIO                    1
    4.12  #define HVM_BUFFERED_IO             2
    4.13  
    4.14  typedef unsigned long (*hvm_mmio_read_t)(struct vcpu *v,
     5.1 --- a/xen/include/asm-x86/hvm/support.h	Fri Mar 28 11:17:11 2008 +0000
     5.2 +++ b/xen/include/asm-x86/hvm/support.h	Fri Mar 28 14:12:33 2008 +0000
     5.3 @@ -27,12 +27,6 @@
     5.4  #include <asm/regs.h>
     5.5  #include <asm/processor.h>
     5.6  
     5.7 -#ifndef NDEBUG
     5.8 -#define HVM_DEBUG 1
     5.9 -#else
    5.10 -#define HVM_DEBUG 1
    5.11 -#endif
    5.12 -
    5.13  static inline vcpu_iodata_t *get_ioreq(struct vcpu *v)
    5.14  {
    5.15      struct domain *d = v->domain;
    5.16 @@ -42,17 +36,9 @@ static inline vcpu_iodata_t *get_ioreq(s
    5.17      return &p->vcpu_iodata[v->vcpu_id];
    5.18  }
    5.19  
    5.20 -/* XXX these are really VMX specific */
    5.21 -#define TYPE_MOV_TO_DR          (0 << 4)
    5.22 -#define TYPE_MOV_FROM_DR        (1 << 4)
    5.23 -#define TYPE_MOV_TO_CR          (0 << 4)
    5.24 -#define TYPE_MOV_FROM_CR        (1 << 4)
    5.25 -#define TYPE_CLTS               (2 << 4)
    5.26 -#define TYPE_LMSW               (3 << 4)
    5.27 -
    5.28  #define HVM_DELIVER_NO_ERROR_CODE  -1
    5.29  
    5.30 -#if HVM_DEBUG
    5.31 +#ifndef NDEBUG
    5.32  #define DBG_LEVEL_0                 (1 << 0)
    5.33  #define DBG_LEVEL_1                 (1 << 1)
    5.34  #define DBG_LEVEL_2                 (1 << 2)
    5.35 @@ -131,9 +117,6 @@ enum hvm_copy_result hvm_copy_from_guest
    5.36  enum hvm_copy_result hvm_fetch_from_guest_virt_nofault(
    5.37      void *buf, unsigned long vaddr, int size, uint32_t pfec);
    5.38  
    5.39 -void hvm_print_line(struct vcpu *v, const char c);
    5.40 -void hlt_timer_fn(void *data);
    5.41 -
    5.42  #define HVM_HCALL_completed  0 /* hypercall completed - no further action */
    5.43  #define HVM_HCALL_preempted  1 /* hypercall preempted - re-execute VMCALL */
    5.44  #define HVM_HCALL_invalidate 2 /* invalidate ioemu-dm memory cache        */
     6.1 --- a/xen/include/asm-x86/hvm/vmx/vmx.h	Fri Mar 28 11:17:11 2008 +0000
     6.2 +++ b/xen/include/asm-x86/hvm/vmx/vmx.h	Fri Mar 28 14:12:33 2008 +0000
     6.3 @@ -95,35 +95,32 @@ void vmx_realmode(struct cpu_user_regs *
     6.4  /*
     6.5   * Exit Qualifications for MOV for Control Register Access
     6.6   */
     6.7 -#define CONTROL_REG_ACCESS_NUM          0xf     /* 3:0, number of control register */
     6.8 -#define CONTROL_REG_ACCESS_TYPE         0x30    /* 5:4, access type */
     6.9 -#define CONTROL_REG_ACCESS_REG          0xf00   /* 10:8, general purpose register */
    6.10 -#define LMSW_SOURCE_DATA                (0xFFFF << 16)  /* 16:31 lmsw source */
    6.11 -#define REG_EAX                         (0 << 8)
    6.12 -#define REG_ECX                         (1 << 8)
    6.13 -#define REG_EDX                         (2 << 8)
    6.14 -#define REG_EBX                         (3 << 8)
    6.15 -#define REG_ESP                         (4 << 8)
    6.16 -#define REG_EBP                         (5 << 8)
    6.17 -#define REG_ESI                         (6 << 8)
    6.18 -#define REG_EDI                         (7 << 8)
    6.19 -#define REG_R8                          (8 << 8)
    6.20 -#define REG_R9                          (9 << 8)
    6.21 -#define REG_R10                         (10 << 8)
    6.22 -#define REG_R11                         (11 << 8)
    6.23 -#define REG_R12                         (12 << 8)
    6.24 -#define REG_R13                         (13 << 8)
    6.25 -#define REG_R14                         (14 << 8)
    6.26 -#define REG_R15                         (15 << 8)
    6.27 -
    6.28 -/*
    6.29 - * Exit Qualifications for MOV for Debug Register Access
    6.30 - */
    6.31 -#define DEBUG_REG_ACCESS_NUM            0x7     /* 2:0, number of debug register */
    6.32 -#define DEBUG_REG_ACCESS_TYPE           0x10    /* 4, direction of access */
    6.33 -#define TYPE_MOV_TO_DR                  (0 << 4)
    6.34 -#define TYPE_MOV_FROM_DR                (1 << 4)
    6.35 -#define DEBUG_REG_ACCESS_REG            0xf00   /* 11:8, general purpose register */
    6.36 + /* 3:0 - control register number (CRn) */
    6.37 +#define VMX_CONTROL_REG_ACCESS_NUM      0xf
    6.38 + /* 5:4 - access type (CR write, CR read, CLTS, LMSW) */
    6.39 +#define VMX_CONTROL_REG_ACCESS_TYPE     0x30
    6.40 + /* 10:8 - general purpose register operand */
    6.41 +#define VMX_CONTROL_REG_ACCESS_GPR      0xf00
    6.42 +#define VMX_CONTROL_REG_ACCESS_TYPE_MOV_TO_CR   (0 << 4)
    6.43 +#define VMX_CONTROL_REG_ACCESS_TYPE_MOV_FROM_CR (1 << 4)
    6.44 +#define VMX_CONTROL_REG_ACCESS_TYPE_CLTS        (2 << 4)
    6.45 +#define VMX_CONTROL_REG_ACCESS_TYPE_LMSW        (3 << 4)
    6.46 +#define VMX_CONTROL_REG_ACCESS_GPR_EAX  (0 << 8)
    6.47 +#define VMX_CONTROL_REG_ACCESS_GPR_ECX  (1 << 8)
    6.48 +#define VMX_CONTROL_REG_ACCESS_GPR_EDX  (2 << 8)
    6.49 +#define VMX_CONTROL_REG_ACCESS_GPR_EBX  (3 << 8)
    6.50 +#define VMX_CONTROL_REG_ACCESS_GPR_ESP  (4 << 8)
    6.51 +#define VMX_CONTROL_REG_ACCESS_GPR_EBP  (5 << 8)
    6.52 +#define VMX_CONTROL_REG_ACCESS_GPR_ESI  (6 << 8)
    6.53 +#define VMX_CONTROL_REG_ACCESS_GPR_EDI  (7 << 8)
    6.54 +#define VMX_CONTROL_REG_ACCESS_GPR_R8   (8 << 8)
    6.55 +#define VMX_CONTROL_REG_ACCESS_GPR_R9   (9 << 8)
    6.56 +#define VMX_CONTROL_REG_ACCESS_GPR_R10  (10 << 8)
    6.57 +#define VMX_CONTROL_REG_ACCESS_GPR_R11  (11 << 8)
    6.58 +#define VMX_CONTROL_REG_ACCESS_GPR_R12  (12 << 8)
    6.59 +#define VMX_CONTROL_REG_ACCESS_GPR_R13  (13 << 8)
    6.60 +#define VMX_CONTROL_REG_ACCESS_GPR_R14  (14 << 8)
    6.61 +#define VMX_CONTROL_REG_ACCESS_GPR_R15  (15 << 8)
    6.62  
    6.63  /*
    6.64   * Access Rights
    6.65 @@ -155,72 +152,72 @@ void vmx_realmode(struct cpu_user_regs *
    6.66  
    6.67  static inline void __vmptrld(u64 addr)
    6.68  {
    6.69 -    __asm__ __volatile__ ( VMPTRLD_OPCODE
    6.70 -                           MODRM_EAX_06
    6.71 -                           /* CF==1 or ZF==1 --> crash (ud2) */
    6.72 -                           "ja 1f ; ud2 ; 1:\n"
    6.73 -                           :
    6.74 -                           : "a" (&addr)
    6.75 -                           : "memory");
    6.76 +    asm volatile ( VMPTRLD_OPCODE
    6.77 +                   MODRM_EAX_06
    6.78 +                   /* CF==1 or ZF==1 --> crash (ud2) */
    6.79 +                   "ja 1f ; ud2 ; 1:\n"
    6.80 +                   :
    6.81 +                   : "a" (&addr)
    6.82 +                   : "memory");
    6.83  }
    6.84  
    6.85  static inline void __vmptrst(u64 addr)
    6.86  {
    6.87 -    __asm__ __volatile__ ( VMPTRST_OPCODE
    6.88 -                           MODRM_EAX_07
    6.89 -                           :
    6.90 -                           : "a" (&addr)
    6.91 -                           : "memory");
    6.92 +    asm volatile ( VMPTRST_OPCODE
    6.93 +                   MODRM_EAX_07
    6.94 +                   :
    6.95 +                   : "a" (&addr)
    6.96 +                   : "memory");
    6.97  }
    6.98  
    6.99  static inline void __vmpclear(u64 addr)
   6.100  {
   6.101 -    __asm__ __volatile__ ( VMCLEAR_OPCODE
   6.102 -                           MODRM_EAX_06
   6.103 -                           /* CF==1 or ZF==1 --> crash (ud2) */
   6.104 -                           "ja 1f ; ud2 ; 1:\n"
   6.105 -                           :
   6.106 -                           : "a" (&addr)
   6.107 -                           : "memory");
   6.108 +    asm volatile ( VMCLEAR_OPCODE
   6.109 +                   MODRM_EAX_06
   6.110 +                   /* CF==1 or ZF==1 --> crash (ud2) */
   6.111 +                   "ja 1f ; ud2 ; 1:\n"
   6.112 +                   :
   6.113 +                   : "a" (&addr)
   6.114 +                   : "memory");
   6.115  }
   6.116  
   6.117  static inline unsigned long __vmread(unsigned long field)
   6.118  {
   6.119      unsigned long ecx;
   6.120  
   6.121 -    __asm__ __volatile__ ( VMREAD_OPCODE
   6.122 -                           MODRM_EAX_ECX
   6.123 -                           /* CF==1 or ZF==1 --> crash (ud2) */
   6.124 -                           "ja 1f ; ud2 ; 1:\n"
   6.125 -                           : "=c" (ecx)
   6.126 -                           : "a" (field)
   6.127 -                           : "memory");
   6.128 +    asm volatile ( VMREAD_OPCODE
   6.129 +                   MODRM_EAX_ECX
   6.130 +                   /* CF==1 or ZF==1 --> crash (ud2) */
   6.131 +                   "ja 1f ; ud2 ; 1:\n"
   6.132 +                   : "=c" (ecx)
   6.133 +                   : "a" (field)
   6.134 +                   : "memory");
   6.135  
   6.136      return ecx;
   6.137  }
   6.138  
   6.139  static inline void __vmwrite(unsigned long field, unsigned long value)
   6.140  {
   6.141 -    __asm__ __volatile__ ( VMWRITE_OPCODE
   6.142 -                           MODRM_EAX_ECX
   6.143 -                           /* CF==1 or ZF==1 --> crash (ud2) */
   6.144 -                           "ja 1f ; ud2 ; 1:\n"
   6.145 -                           : 
   6.146 -                           : "a" (field) , "c" (value)
   6.147 -                           : "memory");
   6.148 +    asm volatile ( VMWRITE_OPCODE
   6.149 +                   MODRM_EAX_ECX
   6.150 +                   /* CF==1 or ZF==1 --> crash (ud2) */
   6.151 +                   "ja 1f ; ud2 ; 1:\n"
   6.152 +                   : 
   6.153 +                   : "a" (field) , "c" (value)
   6.154 +                   : "memory");
   6.155  }
   6.156  
   6.157  static inline unsigned long __vmread_safe(unsigned long field, int *error)
   6.158  {
   6.159      unsigned long ecx;
   6.160  
   6.161 -    __asm__ __volatile__ ( VMREAD_OPCODE
   6.162 -                           MODRM_EAX_ECX
   6.163 -                           /* CF==1 or ZF==1 --> rc = -1 */
   6.164 -                           "setna %b0 ; neg %0"
   6.165 -                           : "=q" (*error), "=c" (ecx)
   6.166 -                           : "0" (0), "a" (field)
   6.167 -                           : "memory");
   6.168 +    asm volatile ( VMREAD_OPCODE
   6.169 +                   MODRM_EAX_ECX
   6.170 +                   /* CF==1 or ZF==1 --> rc = -1 */
   6.171 +                   "setna %b0 ; neg %0"
   6.172 +                   : "=q" (*error), "=c" (ecx)
   6.173 +                   : "0" (0), "a" (field)
   6.174 +                   : "memory");
   6.175  
   6.176      return ecx;
   6.177  }