[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Clean up some VMX IO handler code:



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID 551d099dae3a80ae913377f2de8e008bb88dadf5
# Parent  7155eafc858adc2bb3581cc69793a26fe1bec224
Clean up some VMX IO handler code:
1. Clean up some definitions.
2. change d to v, if it means vcpu.
3. remove some tailing spaces.

TODO:
split current VMX IO handler list to 2, one for port IO,
and the other for MMIO.

Signed-off-by: Xin Li <xin.b.li@xxxxxxxxx>

diff -r 7155eafc858a -r 551d099dae3a xen/arch/x86/vmx_intercept.c
--- a/xen/arch/x86/vmx_intercept.c      Tue Oct 18 10:07:55 2005
+++ b/xen/arch/x86/vmx_intercept.c      Tue Oct 18 10:09:36 2005
@@ -32,31 +32,36 @@
 
 #ifdef CONFIG_VMX
 
-/* Check if the request is handled inside xen
-   return value: 0 --not handled; 1 --handled */
+/*
+ * Check if the request is handled inside xen
+ * return value: 0 --not handled; 1 --handled
+ */
 int vmx_io_intercept(ioreq_t *p, int type)
 {
-    struct vcpu *d = current;
-    struct vmx_handler_t *handler = 
&(d->domain->arch.vmx_platform.vmx_handler);
+    struct vcpu *v = current;
+    struct vmx_io_handler *handler =
+                           &(v->domain->arch.vmx_platform.vmx_io_handler);
     int i;
-    unsigned long addr, offset;
+    unsigned long addr, size;
+
     for (i = 0; i < handler->num_slot; i++) {
         if( type != handler->hdl_list[i].type)
             continue;
-        addr   = handler->hdl_list[i].addr;
-        offset = handler->hdl_list[i].offset;
+        addr = handler->hdl_list[i].addr;
+        size = handler->hdl_list[i].size;
         if (p->addr >= addr &&
-            p->addr <  addr + offset)
+            p->addr <  addr + size)
             return handler->hdl_list[i].action(p);
     }
     return 0;
 }
 
-int register_io_handler(unsigned long addr, unsigned long offset, 
+int register_io_handler(unsigned long addr, unsigned long size,
                         intercept_action_t action, int type)
 {
-    struct vcpu *d = current;
-    struct vmx_handler_t *handler = 
&(d->domain->arch.vmx_platform.vmx_handler);
+    struct vcpu *v = current;
+    struct vmx_io_handler *handler =
+                             &(v->domain->arch.vmx_platform.vmx_io_handler);
     int num = handler->num_slot;
 
     if (num >= MAX_IO_HANDLER) {
@@ -65,15 +70,15 @@
     }
 
     handler->hdl_list[num].addr = addr;
-    handler->hdl_list[num].offset = offset;
+    handler->hdl_list[num].size = size;
     handler->hdl_list[num].action = action;
     handler->hdl_list[num].type = type;
     handler->num_slot++;
+
     return 1;
-
-}
-
-static void pit_cal_count(struct vmx_virpit_t *vpit)
+}
+
+static void pit_cal_count(struct vmx_virpit *vpit)
 {
     u64 nsec_delta = (unsigned int)((NOW() - vpit->inject_point));
     if (nsec_delta > vpit->period)
@@ -81,7 +86,7 @@
     vpit->count = vpit->init_val - ((nsec_delta * PIT_FREQ / 1000000000ULL) % 
vpit->init_val );
 }
 
-static void pit_latch_io(struct vmx_virpit_t *vpit)
+static void pit_latch_io(struct vmx_virpit *vpit)
 {
     pit_cal_count(vpit);
 
@@ -103,11 +108,11 @@
         vpit->count_MSB_latched=1;
         break;
     default:
-        BUG();
-    }
-}
-
-static int pit_read_io(struct vmx_virpit_t *vpit)
+        domain_crash_synchronous();
+    }
+}
+
+static int pit_read_io(struct vmx_virpit *vpit)
 {
     if(vpit->count_LSB_latched) {
         /* Read Least Significant Byte */
@@ -168,8 +173,8 @@
 /* the intercept action for PIT DM retval:0--not handled; 1--handled */
 int intercept_pit_io(ioreq_t *p)
 {
-    struct vcpu *d = current;
-    struct vmx_virpit_t *vpit = &(d->domain->arch.vmx_platform.vmx_pit);
+    struct vcpu *v = current;
+    struct vmx_virpit *vpit = &(v->domain->arch.vmx_platform.vmx_pit);
 
     if (p->size != 1 ||
         p->pdata_valid ||
@@ -197,7 +202,7 @@
 /* hooks function for the PIT initialization response iopacket */
 static void pit_timer_fn(void *data)
 {
-    struct vmx_virpit_t *vpit = data;
+    struct vmx_virpit *vpit = data;
     s_time_t   next;
     int        missed_ticks;
 
@@ -221,18 +226,18 @@
 /* Only some PIT operations such as load init counter need a hypervisor hook.
  * leave all other operations in user space DM
  */
-void vmx_hooks_assist(struct vcpu *d)
-{
-    vcpu_iodata_t * vio = get_vio(d->domain, d->vcpu_id);
+void vmx_hooks_assist(struct vcpu *v)
+{
+    vcpu_iodata_t *vio = get_vio(v->domain, v->vcpu_id);
     ioreq_t *p = &vio->vp_ioreq;
-    shared_iopage_t *sp = get_sp(d->domain);
+    shared_iopage_t *sp = get_sp(v->domain);
     u64 *intr = &(sp->sp_global.pic_intr[0]);
-    struct vmx_virpit_t *vpit = &(d->domain->arch.vmx_platform.vmx_pit);
+    struct vmx_virpit *vpit = &(v->domain->arch.vmx_platform.vmx_pit);
     int rw_mode, reinit = 0;
     int oldvec = 0;
 
     /* load init count*/
-    if (p->state == STATE_IORESP_HOOK) { 
+    if (p->state == STATE_IORESP_HOOK) {
         /* set up actimer, handle re-init */
         if ( active_ac_timer(&(vpit->pit_timer)) ) {
             VMX_DBG_LOG(DBG_LEVEL_1, "VMX_PIT: guest reset PIT with channel 
%lx!\n", (unsigned long) ((p->u.data >> 24) & 0x3) );
@@ -241,12 +246,12 @@
             oldvec = vpit->vector;
         }
         else
-            init_ac_timer(&vpit->pit_timer, pit_timer_fn, vpit, d->processor);
+            init_ac_timer(&vpit->pit_timer, pit_timer_fn, vpit, v->processor);
 
         /* init count for this channel */
-        vpit->init_val = (p->u.data & 0xFFFF) ; 
+        vpit->init_val = (p->u.data & 0xFFFF) ;
         /* frequency(ns) of pit */
-        vpit->period = DIV_ROUND(((vpit->init_val) * 1000000000ULL), 
PIT_FREQ); 
+        vpit->period = DIV_ROUND(((vpit->init_val) * 1000000000ULL), PIT_FREQ);
         VMX_DBG_LOG(DBG_LEVEL_1,"VMX_PIT: guest set init pit freq:%u ns, 
initval:0x%x\n", vpit->period, vpit->init_val);
         if (vpit->period < 900000) { /* < 0.9 ms */
             printk("VMX_PIT: guest programmed too small an init_val: %x\n",
@@ -283,7 +288,7 @@
         }
 
         vpit->intr_bitmap = intr;
-        vpit->v = d;
+        vpit->v = v;
 
         vpit->scheduled = NOW() + vpit->period;
         set_ac_timer(&vpit->pit_timer, vpit->scheduled);
diff -r 7155eafc858a -r 551d099dae3a xen/arch/x86/vmx_io.c
--- a/xen/arch/x86/vmx_io.c     Tue Oct 18 10:07:55 2005
+++ b/xen/arch/x86/vmx_io.c     Tue Oct 18 10:09:36 2005
@@ -848,7 +848,8 @@
 static inline void
 interrupt_post_injection(struct vcpu * v, int vector, int type)
 {
-    struct vmx_virpit_t *vpit = &(v->domain->arch.vmx_platform.vmx_pit);
+    struct vmx_virpit *vpit = &(v->domain->arch.vmx_platform.vmx_pit);
+
     switch(type)
     {
     case VLAPIC_DELIV_MODE_EXT:
diff -r 7155eafc858a -r 551d099dae3a xen/arch/x86/vmx_vmcs.c
--- a/xen/arch/x86/vmx_vmcs.c   Tue Oct 18 10:07:55 2005
+++ b/xen/arch/x86/vmx_vmcs.c   Tue Oct 18 10:09:36 2005
@@ -142,7 +142,7 @@
 #endif
 };
 
-static void vmx_setup_platform(struct vcpu *v)
+static void get_io_shared_page(struct vcpu *v)
 {
     int i;
     unsigned char e820_map_nr;
@@ -150,6 +150,9 @@
     unsigned char *p;
     unsigned long mpfn;
     unsigned long gpfn = 0;
+
+    if (!(VMX_DOMAIN(v) && (v->vcpu_id == 0)))
+        return;
 
     local_flush_tlb_pge();
 
@@ -203,6 +206,12 @@
 
     clear_bit(iopacket_port(v->domain),
               &v->domain->shared_info->evtchn_mask[0]);
+}
+
+static void vmx_setup_platform(struct vcpu *v)
+{
+    if (v->vcpu_id == 0)
+        get_io_shared_page(v);
 }
 
 static void vmx_set_host_env(struct vcpu *v)
diff -r 7155eafc858a -r 551d099dae3a xen/include/asm-x86/vmx_intercept.h
--- a/xen/include/asm-x86/vmx_intercept.h       Tue Oct 18 10:07:55 2005
+++ b/xen/include/asm-x86/vmx_intercept.h       Tue Oct 18 10:09:36 2005
@@ -8,49 +8,52 @@
 #include <xen/errno.h>
 #include <public/io/ioreq.h>
 
-#define MAX_IO_HANDLER 10
+#define MAX_IO_HANDLER              4
 
-typedef int (*intercept_action_t)(ioreq_t*);
+#define VMX_PORTIO                  0
+#define VMX_MMIO                    1
 
-enum {PORTIO, MMIO};
+typedef int (*intercept_action_t)(ioreq_t *);
 
-struct vmx_handler_t {
-    int num_slot;
-    struct {
-        unsigned long       addr;
-        int type;
-        unsigned long       offset;
-        intercept_action_t  action;
-    } hdl_list[MAX_IO_HANDLER];
+struct io_handler {
+    int                 type;
+    unsigned long       addr;
+    unsigned long       size;
+    intercept_action_t  action;
+};
+
+struct vmx_io_handler {
+    int     num_slot;
+    struct  io_handler hdl_list[MAX_IO_HANDLER];
 };
 
 /* global io interception point in HV */
 extern int vmx_io_intercept(ioreq_t *p, int type);
-extern int register_io_handler(unsigned long addr, unsigned long offset, 
+extern int register_io_handler(unsigned long addr, unsigned long size,
                                intercept_action_t action, int type);
 
 static inline int vmx_portio_intercept(ioreq_t *p)
 {
-    return vmx_io_intercept(p, PORTIO);
+    return vmx_io_intercept(p, VMX_PORTIO);
 }
 
 static inline int vmx_mmio_intercept(ioreq_t *p)
 {
-    return vmx_io_intercept(p, MMIO);
+    return vmx_io_intercept(p, VMX_MMIO);
 }
 
-static inline int register_portio_handler(unsigned long addr, 
-                                          unsigned long offset, 
+static inline int register_portio_handler(unsigned long addr,
+                                          unsigned long size,
                                           intercept_action_t action)
 {
-    return register_io_handler(addr, offset, action, PORTIO);
+    return register_io_handler(addr, size, action, VMX_PORTIO);
 }
 
-static inline int register_mmio_handler(unsigned long addr, 
-                                        unsigned long offset, 
+static inline int register_mmio_handler(unsigned long addr,
+                                        unsigned long size,
                                         intercept_action_t action)
 {
-    return register_io_handler(addr, offset, action, MMIO);
+    return register_io_handler(addr, size, action, VMX_MMIO);
 }
 
 #endif /* _VMX_INTERCEPT_H */
diff -r 7155eafc858a -r 551d099dae3a xen/include/asm-x86/vmx_platform.h
--- a/xen/include/asm-x86/vmx_platform.h        Tue Oct 18 10:07:55 2005
+++ b/xen/include/asm-x86/vmx_platform.h        Tue Oct 18 10:09:36 2005
@@ -77,10 +77,9 @@
 #define MAX_INST_LEN      32
 
 struct virtual_platform_def {
-    unsigned long          *real_mode_data; /* E820, etc. */
     unsigned long          shared_page_va;
-    struct vmx_virpit_t    vmx_pit;
-    struct vmx_handler_t   vmx_handler;
+    struct vmx_virpit      vmx_pit;
+    struct vmx_io_handler  vmx_io_handler;
 };
 
 extern void handle_mmio(unsigned long, unsigned long);
diff -r 7155eafc858a -r 551d099dae3a xen/include/asm-x86/vmx_virpit.h
--- a/xen/include/asm-x86/vmx_virpit.h  Tue Oct 18 10:07:55 2005
+++ b/xen/include/asm-x86/vmx_virpit.h  Tue Oct 18 10:09:36 2005
@@ -16,7 +16,7 @@
 #define LSByte_multiple 2
 #define MSByte_multiple 3
 
-struct vmx_virpit_t {
+struct vmx_virpit {
     /* for simulation of counter 0 in mode 2*/
     int vector;    /* the pit irq vector */
     unsigned int period;  /* the frequency. e.g. 10ms*/
@@ -39,6 +39,6 @@
 };
 
 /* to hook the ioreq packet to get the PIT initializaiton info */
-extern void vmx_hooks_assist(struct vcpu *d);
+extern void vmx_hooks_assist(struct vcpu *v);
 
 #endif /* _VMX_VIRPIT_H_ */
diff -r 7155eafc858a -r 551d099dae3a xen/include/asm-x86/vmx_vmcs.h
--- a/xen/include/asm-x86/vmx_vmcs.h    Tue Oct 18 10:07:55 2005
+++ b/xen/include/asm-x86/vmx_vmcs.h    Tue Oct 18 10:09:36 2005
@@ -29,7 +29,7 @@
 
 #if defined (__x86_64__)
 extern void vmx_load_msrs(struct vcpu *n);
-void vmx_restore_msrs(struct vcpu *d);
+void vmx_restore_msrs(struct vcpu *v);
 #else
 #define vmx_load_msrs(_n)          ((void)0)
 #define vmx_restore_msrs(_v)       ((void)0)
@@ -55,7 +55,7 @@
 
 extern int vmcs_size;
 
-enum { 
+enum {
     VMX_INDEX_MSR_LSTAR = 0,
     VMX_INDEX_MSR_STAR,
     VMX_INDEX_MSR_CSTAR,
@@ -79,7 +79,7 @@
     struct cpu_user_regs   *inst_decoder_regs; /* current context */
 };
 
-#define PC_DEBUG_PORT   0x80 
+#define PC_DEBUG_PORT   0x80
 
 struct arch_vmx_struct {
     struct vmcs_struct      *vmcs;  /* VMCS pointer in virtual */
@@ -98,7 +98,7 @@
 #define vmx_schedule_tail(next)         \
     (next)->thread.arch_vmx.arch_vmx_schedule_tail((next))
 
-#define VMX_DOMAIN(ed)   ((ed)->arch.arch_vmx.flags)
+#define VMX_DOMAIN(v)   ((v)->arch.arch_vmx.flags)
 
 #define ARCH_VMX_VMCS_LOADED    0       /* VMCS has been loaded and active */
 #define ARCH_VMX_VMCS_LAUNCH    1       /* Needs VMCS launch */
@@ -278,7 +278,8 @@
 extern unsigned int opt_vmx_debug_level;
 #define VMX_DBG_LOG(level, _f, _a...)           \
     if ((level) & opt_vmx_debug_level)          \
-        printk("[VMX]" _f "\n", ## _a )
+        printk("[VMX:%d.%d] " _f "\n",          \
+                current->domain->domain_id, current->vcpu_id, ## _a)
 #else
 #define VMX_DBG_LOG(level, _f, _a...)
 #endif

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.