direct-io.hg

changeset 12368:fda15861731e

[HVM] Simplify apic dest-matching code. Refactor
across vlapic/vioapic source files to reduce code
duplication.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Nov 10 18:20:49 2006 +0000 (2006-11-10)
parents b7ffbec0e307
children e821c15b7cfe
files xen/arch/x86/hvm/vioapic.c xen/arch/x86/hvm/vlapic.c xen/include/asm-x86/hvm/vlapic.h
line diff
     1.1 --- a/xen/arch/x86/hvm/vioapic.c	Fri Nov 10 17:47:15 2006 +0000
     1.2 +++ b/xen/arch/x86/hvm/vioapic.c	Fri Nov 10 18:20:49 2006 +0000
     1.3 @@ -35,6 +35,7 @@
     1.4  #include <public/hvm/ioreq.h>
     1.5  #include <asm/hvm/io.h>
     1.6  #include <asm/hvm/vpic.h>
     1.7 +#include <asm/hvm/vlapic.h>
     1.8  #include <asm/hvm/support.h>
     1.9  #include <asm/current.h>
    1.10  #include <asm/event.h>
    1.11 @@ -285,42 +286,6 @@ static int ioapic_inj_irq(struct vioapic
    1.12      return result;
    1.13  }
    1.14  
    1.15 -#ifndef __ia64__
    1.16 -static int vlapic_match_logical_addr(struct vlapic *vlapic, uint8_t dest)
    1.17 -{
    1.18 -    int result = 0;
    1.19 -    uint32_t logical_dest;
    1.20 -
    1.21 -    HVM_DBG_LOG(DBG_LEVEL_IOAPIC, "vlapic_match_logical_addr "
    1.22 -                "vcpu=%d vlapic_id=%x dest=%x\n",
    1.23 -                vlapic_vcpu(vlapic)->vcpu_id, VLAPIC_ID(vlapic), dest);
    1.24 -
    1.25 -    logical_dest = vlapic_get_reg(vlapic, APIC_LDR);
    1.26 -
    1.27 -    switch ( vlapic_get_reg(vlapic, APIC_DFR) )
    1.28 -    {
    1.29 -    case APIC_DFR_FLAT:
    1.30 -        result = ((dest & GET_APIC_LOGICAL_ID(logical_dest)) != 0);
    1.31 -        break;
    1.32 -    case APIC_DFR_CLUSTER:
    1.33 -        /* Should we support flat cluster mode ?*/
    1.34 -        if ( (GET_APIC_LOGICAL_ID(logical_dest) >> 4
    1.35 -              == ((dest >> 0x4) & 0xf)) &&
    1.36 -             (logical_dest & (dest  & 0xf)) )
    1.37 -            result = 1;
    1.38 -        break;
    1.39 -    default:
    1.40 -        gdprintk(XENLOG_WARNING, "error DFR value for lapic of vcpu %d\n",
    1.41 -                 vlapic_vcpu(vlapic)->vcpu_id);
    1.42 -        break;
    1.43 -    }
    1.44 -
    1.45 -    return result;
    1.46 -}
    1.47 -#else
    1.48 -extern int vlapic_match_logical_addr(struct vlapic *vlapic, uint16_t dest);
    1.49 -#endif
    1.50 -
    1.51  static uint32_t ioapic_get_delivery_bitmask(struct vioapic *vioapic,
    1.52                                              uint16_t dest,
    1.53                                              uint8_t dest_mode,
     2.1 --- a/xen/arch/x86/hvm/vlapic.c	Fri Nov 10 17:47:15 2006 +0000
     2.2 +++ b/xen/arch/x86/hvm/vlapic.c	Fri Nov 10 18:20:49 2006 +0000
     2.3 @@ -196,63 +196,56 @@ uint32_t vlapic_get_ppr(struct vlapic *v
     2.4      return ppr;
     2.5  }
     2.6  
     2.7 -/* This only for fixed delivery mode */
     2.8 +int vlapic_match_logical_addr(struct vlapic *vlapic, uint8_t mda)
     2.9 +{
    2.10 +    int result = 0;
    2.11 +    uint8_t logical_id;
    2.12 +
    2.13 +    logical_id = GET_APIC_LOGICAL_ID(vlapic_get_reg(vlapic, APIC_LDR));
    2.14 +
    2.15 +    switch ( vlapic_get_reg(vlapic, APIC_DFR) )
    2.16 +    {
    2.17 +    case APIC_DFR_FLAT:
    2.18 +        if ( logical_id & mda )
    2.19 +            result = 1;
    2.20 +        break;
    2.21 +    case APIC_DFR_CLUSTER:
    2.22 +        if ( ((logical_id >> 4) == (mda >> 0x4)) && (logical_id & mda & 0xf) )
    2.23 +            result = 1;
    2.24 +        break;
    2.25 +    default:
    2.26 +        gdprintk(XENLOG_WARNING, "Bad DFR value for lapic of vcpu %d\n",
    2.27 +                 vlapic_vcpu(vlapic)->vcpu_id);
    2.28 +        break;
    2.29 +    }
    2.30 +
    2.31 +    return result;
    2.32 +}
    2.33 +
    2.34  static int vlapic_match_dest(struct vcpu *v, struct vlapic *source,
    2.35 -                             int short_hand, int dest, int dest_mode,
    2.36 -                             int delivery_mode)
    2.37 +                             int short_hand, int dest, int dest_mode)
    2.38  {
    2.39      int result = 0;
    2.40      struct vlapic *target = vcpu_vlapic(v);
    2.41  
    2.42      HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "target %p, source %p, dest 0x%x, "
    2.43 -                "dest_mode 0x%x, short_hand 0x%x, delivery_mode 0x%x.",
    2.44 -                target, source, dest, dest_mode, short_hand, delivery_mode);
    2.45 -
    2.46 -    if ( unlikely(target == NULL) &&
    2.47 -         ((delivery_mode != APIC_DM_INIT) &&
    2.48 -          (delivery_mode != APIC_DM_STARTUP) &&
    2.49 -          (delivery_mode != APIC_DM_NMI)) )
    2.50 -    {
    2.51 -        HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "uninitialized target vcpu %p, "
    2.52 -                    "delivery_mode 0x%x, dest 0x%x.\n",
    2.53 -                    v, delivery_mode, dest);
    2.54 -        return result;
    2.55 -    }
    2.56 +                "dest_mode 0x%x, short_hand 0x%x\n",
    2.57 +                target, source, dest, dest_mode, short_hand);
    2.58  
    2.59      switch ( short_hand )
    2.60      {
    2.61 -    case APIC_DEST_NOSHORT:             /* no shorthand */
    2.62 -        if ( !dest_mode )   /* Physical */
    2.63 -        {
    2.64 -            result = ( ((target != NULL) ?
    2.65 -                         GET_APIC_ID(vlapic_get_reg(target, APIC_ID)):
    2.66 -                         v->vcpu_id)) == dest;
    2.67 -        }
    2.68 -        else                /* Logical */
    2.69 +    case APIC_DEST_NOSHORT:
    2.70 +        if ( dest_mode == 0 )
    2.71          {
    2.72 -            uint32_t ldr;
    2.73 -            if ( target == NULL )
    2.74 -                break;
    2.75 -            ldr = vlapic_get_reg(target, APIC_LDR);
    2.76 -            
    2.77 -            /* Flat mode */
    2.78 -            if ( vlapic_get_reg(target, APIC_DFR) == APIC_DFR_FLAT )
    2.79 -            {
    2.80 -                result = GET_APIC_LOGICAL_ID(ldr) & dest;
    2.81 -            }
    2.82 -            else
    2.83 -            {
    2.84 -                if ( (delivery_mode == APIC_DM_LOWEST) &&
    2.85 -                     (dest == 0xff) )
    2.86 -                {
    2.87 -                    /* What shall we do now? */
    2.88 -                    gdprintk(XENLOG_ERR, "Broadcast IPI with lowest priority "
    2.89 -                             "delivery mode\n");
    2.90 -                    domain_crash_synchronous();
    2.91 -                }
    2.92 -                result = ((GET_APIC_LOGICAL_ID(ldr) == (dest & 0xf)) ?
    2.93 -                          (GET_APIC_LOGICAL_ID(ldr) >> 4) & (dest >> 4) : 0);
    2.94 -            }
    2.95 +            /* Physical mode. */
    2.96 +            if ( (dest == 0xFF) || /* broadcast? */
    2.97 +                 (GET_APIC_ID(vlapic_get_reg(target, APIC_ID)) == dest) )
    2.98 +                result = 1;
    2.99 +        }
   2.100 +        else
   2.101 +        {
   2.102 +            /* Logical mode. */
   2.103 +            result = vlapic_match_logical_addr(target, dest);
   2.104          }
   2.105          break;
   2.106  
   2.107 @@ -271,16 +264,14 @@ static int vlapic_match_dest(struct vcpu
   2.108          break;
   2.109  
   2.110      default:
   2.111 +        gdprintk(XENLOG_WARNING, "Bad dest shorthand value %x\n", short_hand);
   2.112          break;
   2.113      }
   2.114  
   2.115      return result;
   2.116  }
   2.117  
   2.118 -/*
   2.119 - * Add a pending IRQ into lapic.
   2.120 - * Return 1 if successfully added and 0 if discarded.
   2.121 - */
   2.122 +/* Add a pending IRQ into lapic. */
   2.123  static int vlapic_accept_irq(struct vcpu *v, int delivery_mode,
   2.124                               int vector, int level, int trig_mode)
   2.125  {
   2.126 @@ -440,10 +431,9 @@ static void vlapic_ipi(struct vlapic *vl
   2.127  
   2.128      for_each_vcpu ( vlapic_domain(vlapic), v )
   2.129      {
   2.130 -        if ( vlapic_match_dest(v, vlapic, short_hand,
   2.131 -                               dest, dest_mode, delivery_mode) )
   2.132 +        if ( vlapic_match_dest(v, vlapic, short_hand, dest, dest_mode) )
   2.133          {
   2.134 -            if ( delivery_mode == APIC_DM_LOWEST)
   2.135 +            if ( delivery_mode == APIC_DM_LOWEST )
   2.136                  set_bit(v->vcpu_id, &lpr_map);
   2.137              else
   2.138                  vlapic_accept_irq(v, delivery_mode,
     3.1 --- a/xen/include/asm-x86/hvm/vlapic.h	Fri Nov 10 17:47:15 2006 +0000
     3.2 +++ b/xen/include/asm-x86/hvm/vlapic.h	Fri Nov 10 18:20:49 2006 +0000
     3.3 @@ -90,4 +90,6 @@ struct vlapic *apic_round_robin(
     3.4  
     3.5  s_time_t get_apictime_scheduled(struct vcpu *v);
     3.6  
     3.7 +int vlapic_match_logical_addr(struct vlapic *vlapic, uint8_t mda);
     3.8 +
     3.9  #endif /* __ASM_X86_HVM_VLAPIC_H__ */