ia64/xen-unstable

changeset 4724:e8c18dee0bb6

bitkeeper revision 1.1389.1.21 (4275e5dbz3R_E1mjaxcOhfE7cYQy0w)

[PATCH] [PATCH] update evtchn for SMP

# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
# 2005/05/01 17:01:17-07:00 kmacy@curly.lab.netapp.com
# add SMP support to evtchn
# Signed-off-by: Kip Macy <kmacy@netapp.com>
#
# freebsd-5.3-xen-sparse/i386-xen/include/xen_intr.h
# 2005/05/01 17:01:15-07:00 kmacy@curly.lab.netapp.com +3 -0
# add SMP interfaces
#
# freebsd-5.3-xen-sparse/i386-xen/i386-xen/evtchn.c
# 2005/05/01 17:01:15-07:00 kmacy@curly.lab.netapp.com +85 -9
# add SMP support
#
author kmacy@netapp.com[kaf24]
date Mon May 02 08:33:31 2005 +0000 (2005-05-02)
parents e1bb98b5ffa6
children 23682e5da945
files freebsd-5.3-xen-sparse/i386-xen/i386-xen/evtchn.c freebsd-5.3-xen-sparse/i386-xen/include/xen_intr.h
line diff
     1.1 --- a/freebsd-5.3-xen-sparse/i386-xen/i386-xen/evtchn.c	Mon May 02 08:33:19 2005 +0000
     1.2 +++ b/freebsd-5.3-xen-sparse/i386-xen/i386-xen/evtchn.c	Mon May 02 08:33:31 2005 +0000
     1.3 @@ -31,8 +31,9 @@ static struct mtx irq_mapping_update_loc
     1.4  static int evtchn_to_irq[NR_EVENT_CHANNELS];
     1.5  static int irq_to_evtchn[NR_IRQS];
     1.6  
     1.7 -/* IRQ <-> VIRQ mapping. */
     1.8 -static int virq_to_irq[NR_VIRQS];
     1.9 +static int virq_to_irq[MAX_VIRT_CPUS][NR_VIRQS];
    1.10 +static int ipi_to_evtchn[MAX_VIRT_CPUS][NR_VIRQS];
    1.11 +
    1.12  
    1.13  /* Reference counts for bindings to IRQs. */
    1.14  static int irq_bindcount[NR_IRQS];
    1.15 @@ -120,7 +121,7 @@ bind_virq_to_irq(int virq)
    1.16  
    1.17      mtx_lock(&irq_mapping_update_lock);
    1.18  
    1.19 -    if ( (irq = virq_to_irq[virq]) == -1 )
    1.20 +    if ( (irq = PCPU_GET(virq_to_irq)[virq]) == -1 )
    1.21      {
    1.22          op.cmd              = EVTCHNOP_bind_virq;
    1.23          op.u.bind_virq.virq = virq;
    1.24 @@ -132,7 +133,7 @@ bind_virq_to_irq(int virq)
    1.25          evtchn_to_irq[evtchn] = irq;
    1.26          irq_to_evtchn[irq]    = evtchn;
    1.27  
    1.28 -        virq_to_irq[virq] = irq;
    1.29 +        PCPU_GET(virq_to_irq)[virq] = irq;
    1.30      }
    1.31  
    1.32      irq_bindcount[irq]++;
    1.33 @@ -146,7 +147,7 @@ void
    1.34  unbind_virq_from_irq(int virq)
    1.35  {
    1.36      evtchn_op_t op;
    1.37 -    int irq    = virq_to_irq[virq];
    1.38 +    int irq    = PCPU_GET(virq_to_irq)[virq];
    1.39      int evtchn = irq_to_evtchn[irq];
    1.40  
    1.41      mtx_lock(&irq_mapping_update_lock);
    1.42 @@ -161,7 +162,64 @@ unbind_virq_from_irq(int virq)
    1.43  
    1.44          evtchn_to_irq[evtchn] = -1;
    1.45          irq_to_evtchn[irq]    = -1;
    1.46 -        virq_to_irq[virq]     = -1;
    1.47 +        PCPU_GET(virq_to_irq)[virq]     = -1;
    1.48 +    }
    1.49 +
    1.50 +    mtx_unlock(&irq_mapping_update_lock);
    1.51 +}
    1.52 +
    1.53 +
    1.54 +int 
    1.55 +bind_ipi_on_cpu_to_irq(int cpu, int ipi)
    1.56 +{
    1.57 +    evtchn_op_t op;
    1.58 +    int evtchn, irq;
    1.59 +
    1.60 +    mtx_lock(&irq_mapping_update_lock);
    1.61 +
    1.62 +    if ( (evtchn = PCPU_GET(ipi_to_evtchn)[ipi]) == 0 )
    1.63 +    {
    1.64 +        op.cmd                 = EVTCHNOP_bind_ipi;
    1.65 +        op.u.bind_ipi.ipi_edom = cpu;
    1.66 +        if ( HYPERVISOR_event_channel_op(&op) != 0 )
    1.67 +            panic("Failed to bind virtual IPI %d on cpu %d\n", ipi, cpu);
    1.68 +        evtchn = op.u.bind_ipi.port;
    1.69 +
    1.70 +        irq = find_unbound_irq();
    1.71 +        evtchn_to_irq[evtchn] = irq;
    1.72 +        irq_to_evtchn[irq]    = evtchn;
    1.73 +
    1.74 +        PCPU_GET(ipi_to_evtchn)[ipi] = evtchn;
    1.75 +    } else
    1.76 +	irq = evtchn_to_irq[evtchn];
    1.77 +
    1.78 +    irq_bindcount[irq]++;
    1.79 +
    1.80 +    mtx_unlock(&irq_mapping_update_lock);
    1.81 +
    1.82 +    return irq;
    1.83 +}
    1.84 +
    1.85 +void 
    1.86 +unbind_ipi_on_cpu_from_irq(int cpu, int ipi)
    1.87 +{
    1.88 +    evtchn_op_t op;
    1.89 +    int evtchn = PCPU_GET(ipi_to_evtchn)[ipi];
    1.90 +    int irq    = irq_to_evtchn[evtchn];
    1.91 +
    1.92 +    mtx_lock(&irq_mapping_update_lock);
    1.93 +
    1.94 +    if ( --irq_bindcount[irq] == 0 )
    1.95 +    {
    1.96 +	op.cmd          = EVTCHNOP_close;
    1.97 +	op.u.close.dom  = DOMID_SELF;
    1.98 +	op.u.close.port = evtchn;
    1.99 +	if ( HYPERVISOR_event_channel_op(&op) != 0 )
   1.100 +	    panic("Failed to unbind virtual IPI %d on cpu %d\n", ipi, cpu);
   1.101 +
   1.102 +        evtchn_to_irq[evtchn] = -1;
   1.103 +        irq_to_evtchn[irq]    = -1;
   1.104 +	PCPU_GET(ipi_to_evtchn)[ipi] = 0;
   1.105      }
   1.106  
   1.107      mtx_unlock(&irq_mapping_update_lock);
   1.108 @@ -464,7 +522,7 @@ void irq_suspend(void)
   1.109      /* Unbind VIRQs from event channels. */
   1.110      for ( virq = 0; virq < NR_VIRQS; virq++ )
   1.111      {
   1.112 -        if ( (irq = virq_to_irq[virq]) == -1 )
   1.113 +        if ( (irq = PCPU_GET(virq_to_irq)[virq]) == -1 )
   1.114              continue;
   1.115          evtchn = irq_to_evtchn[irq];
   1.116  
   1.117 @@ -493,7 +551,7 @@ void irq_resume(void)
   1.118  
   1.119      for ( virq = 0; virq < NR_VIRQS; virq++ )
   1.120      {
   1.121 -        if ( (irq = virq_to_irq[virq]) == -1 )
   1.122 +        if ( (irq = PCPU_GET(virq_to_irq)[virq]) == -1 )
   1.123              continue;
   1.124  
   1.125          /* Get a new binding from Xen. */
   1.126 @@ -512,6 +570,20 @@ void irq_resume(void)
   1.127      }
   1.128  }
   1.129  
   1.130 +void
   1.131 +ap_evtchn_init(int cpu)
   1.132 +{
   1.133 +    int i;
   1.134 +
   1.135 +    /* XXX -- expedience hack */
   1.136 +    PCPU_SET(virq_to_irq, (int  *)&virq_to_irq[cpu]);
   1.137 +    PCPU_SET(ipi_to_evtchn, (int *)&ipi_to_evtchn[cpu]);
   1.138 +
   1.139 +    /* No VIRQ -> IRQ mappings. */
   1.140 +    for ( i = 0; i < NR_VIRQS; i++ )
   1.141 +        PCPU_GET(virq_to_irq)[i] = -1;
   1.142 +}
   1.143 +
   1.144  static void 
   1.145  evtchn_init(void *dummy __unused)
   1.146  {
   1.147 @@ -527,9 +599,13 @@ evtchn_init(void *dummy __unused)
   1.148       */
   1.149      mtx_init(&irq_mapping_update_lock, "xp", NULL, MTX_DEF);
   1.150  
   1.151 +    /* XXX -- expedience hack */
   1.152 +    PCPU_SET(virq_to_irq, (int *)&virq_to_irq[0]);
   1.153 +    PCPU_SET(ipi_to_evtchn, (int *)&ipi_to_evtchn[0]);
   1.154 +
   1.155      /* No VIRQ -> IRQ mappings. */
   1.156      for ( i = 0; i < NR_VIRQS; i++ )
   1.157 -        virq_to_irq[i] = -1;
   1.158 +        PCPU_GET(virq_to_irq)[i] = -1;
   1.159  
   1.160      /* No event-channel -> IRQ mappings. */
   1.161      for ( i = 0; i < NR_EVENT_CHANNELS; i++ )
     2.1 --- a/freebsd-5.3-xen-sparse/i386-xen/include/xen_intr.h	Mon May 02 08:33:19 2005 +0000
     2.2 +++ b/freebsd-5.3-xen-sparse/i386-xen/include/xen_intr.h	Mon May 02 08:33:31 2005 +0000
     2.3 @@ -31,6 +31,9 @@ extern int  bind_virq_to_irq(int virq);
     2.4  extern void unbind_virq_from_irq(int virq);
     2.5  extern int  bind_evtchn_to_irq(int evtchn);
     2.6  extern void unbind_evtchn_from_irq(int evtchn);
     2.7 +extern int bind_ipi_on_cpu_to_irq(int cpu, int ipi);
     2.8 +extern void unbind_ipi_on_cpu_from_irq(int cpu, int ipi);
     2.9 +extern void ap_evtchn_init(int cpu);
    2.10  
    2.11  static __inline__ int irq_cannonicalize(int irq)
    2.12  {