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

[Xen-changelog] [xen-unstable] [HVM] Simplify apic dest-matching code. Refactor



# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Node ID fda15861731e39f27d3423c31a0220c2fe2f1efb
# Parent  b7ffbec0e307f38e8d2322169cccbec699f12d2f
[HVM] Simplify apic dest-matching code. Refactor
across vlapic/vioapic source files to reduce code
duplication.
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
 xen/arch/x86/hvm/vioapic.c       |   37 --------------
 xen/arch/x86/hvm/vlapic.c        |  102 +++++++++++++++++----------------------
 xen/include/asm-x86/hvm/vlapic.h |    2 
 3 files changed, 49 insertions(+), 92 deletions(-)

diff -r b7ffbec0e307 -r fda15861731e xen/arch/x86/hvm/vioapic.c
--- a/xen/arch/x86/hvm/vioapic.c        Fri Nov 10 17:47:15 2006 +0000
+++ b/xen/arch/x86/hvm/vioapic.c        Fri Nov 10 18:20:49 2006 +0000
@@ -35,6 +35,7 @@
 #include <public/hvm/ioreq.h>
 #include <asm/hvm/io.h>
 #include <asm/hvm/vpic.h>
+#include <asm/hvm/vlapic.h>
 #include <asm/hvm/support.h>
 #include <asm/current.h>
 #include <asm/event.h>
@@ -285,42 +286,6 @@ static int ioapic_inj_irq(struct vioapic
     return result;
 }
 
-#ifndef __ia64__
-static int vlapic_match_logical_addr(struct vlapic *vlapic, uint8_t dest)
-{
-    int result = 0;
-    uint32_t logical_dest;
-
-    HVM_DBG_LOG(DBG_LEVEL_IOAPIC, "vlapic_match_logical_addr "
-                "vcpu=%d vlapic_id=%x dest=%x\n",
-                vlapic_vcpu(vlapic)->vcpu_id, VLAPIC_ID(vlapic), dest);
-
-    logical_dest = vlapic_get_reg(vlapic, APIC_LDR);
-
-    switch ( vlapic_get_reg(vlapic, APIC_DFR) )
-    {
-    case APIC_DFR_FLAT:
-        result = ((dest & GET_APIC_LOGICAL_ID(logical_dest)) != 0);
-        break;
-    case APIC_DFR_CLUSTER:
-        /* Should we support flat cluster mode ?*/
-        if ( (GET_APIC_LOGICAL_ID(logical_dest) >> 4
-              == ((dest >> 0x4) & 0xf)) &&
-             (logical_dest & (dest  & 0xf)) )
-            result = 1;
-        break;
-    default:
-        gdprintk(XENLOG_WARNING, "error DFR value for lapic of vcpu %d\n",
-                 vlapic_vcpu(vlapic)->vcpu_id);
-        break;
-    }
-
-    return result;
-}
-#else
-extern int vlapic_match_logical_addr(struct vlapic *vlapic, uint16_t dest);
-#endif
-
 static uint32_t ioapic_get_delivery_bitmask(struct vioapic *vioapic,
                                             uint16_t dest,
                                             uint8_t dest_mode,
diff -r b7ffbec0e307 -r fda15861731e xen/arch/x86/hvm/vlapic.c
--- a/xen/arch/x86/hvm/vlapic.c Fri Nov 10 17:47:15 2006 +0000
+++ b/xen/arch/x86/hvm/vlapic.c Fri Nov 10 18:20:49 2006 +0000
@@ -196,63 +196,56 @@ uint32_t vlapic_get_ppr(struct vlapic *v
     return ppr;
 }
 
-/* This only for fixed delivery mode */
+int vlapic_match_logical_addr(struct vlapic *vlapic, uint8_t mda)
+{
+    int result = 0;
+    uint8_t logical_id;
+
+    logical_id = GET_APIC_LOGICAL_ID(vlapic_get_reg(vlapic, APIC_LDR));
+
+    switch ( vlapic_get_reg(vlapic, APIC_DFR) )
+    {
+    case APIC_DFR_FLAT:
+        if ( logical_id & mda )
+            result = 1;
+        break;
+    case APIC_DFR_CLUSTER:
+        if ( ((logical_id >> 4) == (mda >> 0x4)) && (logical_id & mda & 0xf) )
+            result = 1;
+        break;
+    default:
+        gdprintk(XENLOG_WARNING, "Bad DFR value for lapic of vcpu %d\n",
+                 vlapic_vcpu(vlapic)->vcpu_id);
+        break;
+    }
+
+    return result;
+}
+
 static int vlapic_match_dest(struct vcpu *v, struct vlapic *source,
-                             int short_hand, int dest, int dest_mode,
-                             int delivery_mode)
+                             int short_hand, int dest, int dest_mode)
 {
     int result = 0;
     struct vlapic *target = vcpu_vlapic(v);
 
     HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "target %p, source %p, dest 0x%x, "
-                "dest_mode 0x%x, short_hand 0x%x, delivery_mode 0x%x.",
-                target, source, dest, dest_mode, short_hand, delivery_mode);
-
-    if ( unlikely(target == NULL) &&
-         ((delivery_mode != APIC_DM_INIT) &&
-          (delivery_mode != APIC_DM_STARTUP) &&
-          (delivery_mode != APIC_DM_NMI)) )
-    {
-        HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "uninitialized target vcpu %p, "
-                    "delivery_mode 0x%x, dest 0x%x.\n",
-                    v, delivery_mode, dest);
-        return result;
-    }
+                "dest_mode 0x%x, short_hand 0x%x\n",
+                target, source, dest, dest_mode, short_hand);
 
     switch ( short_hand )
     {
-    case APIC_DEST_NOSHORT:             /* no shorthand */
-        if ( !dest_mode )   /* Physical */
-        {
-            result = ( ((target != NULL) ?
-                         GET_APIC_ID(vlapic_get_reg(target, APIC_ID)):
-                         v->vcpu_id)) == dest;
-        }
-        else                /* Logical */
-        {
-            uint32_t ldr;
-            if ( target == NULL )
-                break;
-            ldr = vlapic_get_reg(target, APIC_LDR);
-            
-            /* Flat mode */
-            if ( vlapic_get_reg(target, APIC_DFR) == APIC_DFR_FLAT )
-            {
-                result = GET_APIC_LOGICAL_ID(ldr) & dest;
-            }
-            else
-            {
-                if ( (delivery_mode == APIC_DM_LOWEST) &&
-                     (dest == 0xff) )
-                {
-                    /* What shall we do now? */
-                    gdprintk(XENLOG_ERR, "Broadcast IPI with lowest priority "
-                             "delivery mode\n");
-                    domain_crash_synchronous();
-                }
-                result = ((GET_APIC_LOGICAL_ID(ldr) == (dest & 0xf)) ?
-                          (GET_APIC_LOGICAL_ID(ldr) >> 4) & (dest >> 4) : 0);
-            }
+    case APIC_DEST_NOSHORT:
+        if ( dest_mode == 0 )
+        {
+            /* Physical mode. */
+            if ( (dest == 0xFF) || /* broadcast? */
+                 (GET_APIC_ID(vlapic_get_reg(target, APIC_ID)) == dest) )
+                result = 1;
+        }
+        else
+        {
+            /* Logical mode. */
+            result = vlapic_match_logical_addr(target, dest);
         }
         break;
 
@@ -271,16 +264,14 @@ static int vlapic_match_dest(struct vcpu
         break;
 
     default:
+        gdprintk(XENLOG_WARNING, "Bad dest shorthand value %x\n", short_hand);
         break;
     }
 
     return result;
 }
 
-/*
- * Add a pending IRQ into lapic.
- * Return 1 if successfully added and 0 if discarded.
- */
+/* Add a pending IRQ into lapic. */
 static int vlapic_accept_irq(struct vcpu *v, int delivery_mode,
                              int vector, int level, int trig_mode)
 {
@@ -440,10 +431,9 @@ static void vlapic_ipi(struct vlapic *vl
 
     for_each_vcpu ( vlapic_domain(vlapic), v )
     {
-        if ( vlapic_match_dest(v, vlapic, short_hand,
-                               dest, dest_mode, delivery_mode) )
-        {
-            if ( delivery_mode == APIC_DM_LOWEST)
+        if ( vlapic_match_dest(v, vlapic, short_hand, dest, dest_mode) )
+        {
+            if ( delivery_mode == APIC_DM_LOWEST )
                 set_bit(v->vcpu_id, &lpr_map);
             else
                 vlapic_accept_irq(v, delivery_mode,
diff -r b7ffbec0e307 -r fda15861731e xen/include/asm-x86/hvm/vlapic.h
--- a/xen/include/asm-x86/hvm/vlapic.h  Fri Nov 10 17:47:15 2006 +0000
+++ b/xen/include/asm-x86/hvm/vlapic.h  Fri Nov 10 18:20:49 2006 +0000
@@ -90,4 +90,6 @@ struct vlapic *apic_round_robin(
 
 s_time_t get_apictime_scheduled(struct vcpu *v);
 
+int vlapic_match_logical_addr(struct vlapic *vlapic, uint8_t mda);
+
 #endif /* __ASM_X86_HVM_VLAPIC_H__ */

_______________________________________________
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®.