ia64/xen-unstable

changeset 12632:d54bcabd0624

[IA64] Create viosapic handling for IPF.

There are three reasons to do this.
1. IOSAPIC is different with IOAPIC
such as:
1. IOAPIC implement broadcast, but IOSAPIC doesn't
2. IOSAPIC doesn't implement dest_mode and remote irr bits.
3. IOSAPIC implement EOI but IOAPIC doesn't
etc.
2. In IA32 side there are I8259 and LAPIC who are
related to IOAPIC, but In IPF there is no I8259 and has LSAPIC.
3. after creating this file, all header files under asm-ia64/hvm, which
are linked from IA32 side, are not needed.

Signed-off-by: Anthony Xu <anthony.xu@intel.com>
author awilliam@xenbuild.aw
date Wed Nov 29 11:05:02 2006 -0700 (2006-11-29)
parents 775fea0a4f16
children d8c32fa3e3a9
files xen/arch/ia64/Makefile xen/arch/ia64/Rules.mk xen/arch/ia64/vmx/Makefile xen/arch/ia64/vmx/mmio.c xen/arch/ia64/vmx/viosapic.c xen/arch/ia64/vmx/vlsapic.c xen/arch/ia64/vmx/vmx_hypercall.c xen/arch/ia64/vmx/vmx_init.c xen/include/asm-ia64/config.h xen/include/asm-ia64/domain.h xen/include/asm-ia64/viosapic.h xen/include/asm-ia64/vlsapic.h xen/include/asm-ia64/vmx.h xen/include/asm-ia64/vmx_platform.h xen/include/asm-ia64/vmx_vpd.h
line diff
     1.1 --- a/xen/arch/ia64/Makefile	Wed Nov 29 09:16:46 2006 -0700
     1.2 +++ b/xen/arch/ia64/Makefile	Wed Nov 29 11:05:02 2006 -0700
     1.3 @@ -58,17 +58,6 @@ asm-xsi-offsets.s: asm-xsi-offsets.c $(H
     1.4  	 || ln -sf $(BASEDIR)/include/xen $(BASEDIR)/include/linux
     1.5  	[ -e $(BASEDIR)/include/asm-ia64/xen ] \
     1.6  	 || ln -sf $(BASEDIR)/include/asm-ia64/linux $(BASEDIR)/include/asm-ia64/xen
     1.7 -# Link to HVM files in Xen for ia64/vti
     1.8 -	[ -e $(BASEDIR)/include/asm-ia64/hvm/support.h ] \
     1.9 -	 || ln -sf ../../../include/asm-x86/hvm/support.h $(BASEDIR)/include/asm-ia64/hvm/support.h
    1.10 -	[ -e $(BASEDIR)/include/asm-ia64/hvm/io.h ] \
    1.11 -	 || ln -sf ../../../include/asm-x86/hvm/io.h $(BASEDIR)/include/asm-ia64/hvm/io.h
    1.12 -	[ -e $(BASEDIR)/include/asm-ia64/hvm/vpic.h ] \
    1.13 -	 || ln -sf ../../../include/asm-x86/hvm/vpic.h $(BASEDIR)/include/asm-ia64/hvm/vpic.h
    1.14 -	[ -e $(BASEDIR)/include/asm-ia64/hvm/vioapic.h ] \
    1.15 -	 || ln -sf ../../../include/asm-x86/hvm/vioapic.h $(BASEDIR)/include/asm-ia64/hvm/vioapic.h
    1.16 -	[ -e $(BASEDIR)/arch/ia64/vmx/hvm_vioapic.c ] \
    1.17 -	 || ln -sf ../../../arch/x86/hvm/vioapic.c $(BASEDIR)/arch/ia64/vmx/hvm_vioapic.c
    1.18  
    1.19  # I'm sure a Makefile wizard would know a better way to do this
    1.20  xen.lds.s: xen/xen.lds.S
    1.21 @@ -80,8 +69,3 @@ clean::
    1.22  	rm -f *.o *~ core  xen.lds.s $(BASEDIR)/include/asm-ia64/.offsets.h.stamp asm-offsets.s map.out
    1.23  	rm -f asm-xsi-offsets.s $(BASEDIR)/include/asm-ia64/asm-xsi-offsets.h
    1.24  	rm -f $(BASEDIR)/System.map
    1.25 -	rm -f vmx/hvm_*.c
    1.26 -	rm -f $(BASEDIR)/include/asm-ia64/hvm/support.h
    1.27 -	rm -f $(BASEDIR)/include/asm-ia64/hvm/io.h
    1.28 -	rm -f $(BASEDIR)/include/asm-ia64/hvm/vpic.h
    1.29 -	rm -f $(BASEDIR)/include/asm-ia64/hvm/vioapic.h
     2.1 --- a/xen/arch/ia64/Rules.mk	Wed Nov 29 09:16:46 2006 -0700
     2.2 +++ b/xen/arch/ia64/Rules.mk	Wed Nov 29 11:05:02 2006 -0700
     2.3 @@ -33,7 +33,7 @@ CPPFLAGS+= -I$(BASEDIR)/include						\
     2.4  	   -I$(BASEDIR)/arch/ia64/linux -I$(BASEDIR)/arch/ia64/linux-xen
     2.5  CFLAGS	+= $(CPPFLAGS)
     2.6  #CFLAGS  += -Wno-pointer-arith -Wredundant-decls
     2.7 -CFLAGS	+= -DIA64 -DXEN -DLINUX_2_6 -DV_IOSAPIC_READY
     2.8 +CFLAGS	+= -DIA64 -DXEN -DLINUX_2_6
     2.9  CFLAGS	+= -ffixed-r13 -mfixed-range=f2-f5,f12-f127
    2.10  CFLAGS	+= -g
    2.11  #CFLAGS  += -DVTI_DEBUG
     3.1 --- a/xen/arch/ia64/vmx/Makefile	Wed Nov 29 09:16:46 2006 -0700
     3.2 +++ b/xen/arch/ia64/vmx/Makefile	Wed Nov 29 11:05:02 2006 -0700
     3.3 @@ -1,4 +1,4 @@
     3.4 -obj-y += hvm_vioapic.o
     3.5 +obj-y += viosapic.o
     3.6  #obj-y += mm.o
     3.7  obj-y += mmio.o
     3.8  obj-y += pal_emul.o
     4.1 --- a/xen/arch/ia64/vmx/mmio.c	Wed Nov 29 09:16:46 2006 -0700
     4.2 +++ b/xen/arch/ia64/vmx/mmio.c	Wed Nov 29 11:05:02 2006 -0700
     4.3 @@ -36,6 +36,8 @@
     4.4  #include <public/xen.h>
     4.5  #include <linux/event.h>
     4.6  #include <xen/domain.h>
     4.7 +#include <asm/viosapic.h>
     4.8 +
     4.9  /*
    4.10  struct mmio_list *lookup_mmio(u64 gpa, struct mmio_list *mio_base)
    4.11  {
    4.12 @@ -271,13 +273,11 @@ static void legacy_io_access(VCPU *vcpu,
    4.13      return;
    4.14  }
    4.15  
    4.16 -extern struct vmx_mmio_handler vioapic_mmio_handler;
    4.17  static void mmio_access(VCPU *vcpu, u64 src_pa, u64 *dest, size_t s, int ma, int dir)
    4.18  {
    4.19      struct virtual_platform_def *v_plat;
    4.20      //mmio_type_t iot;
    4.21      unsigned long iot;
    4.22 -    struct vmx_mmio_handler *vioapic_handler = &vioapic_mmio_handler;
    4.23      iot=__gpfn_is_io(vcpu->domain, src_pa>>PAGE_SHIFT);
    4.24      v_plat = vmx_vcpu_get_plat(vcpu);
    4.25  
    4.26 @@ -293,9 +293,9 @@ static void mmio_access(VCPU *vcpu, u64 
    4.27          break;
    4.28      case GPFN_IOSAPIC:
    4.29  	if (!dir)
    4.30 -	    vioapic_handler->write_handler(vcpu, src_pa, s, *dest);
    4.31 +	    viosapic_write(vcpu, src_pa, s, *dest);
    4.32  	else
    4.33 -	    *dest = vioapic_handler->read_handler(vcpu, src_pa, s);
    4.34 +	    *dest = viosapic_read(vcpu, src_pa, s);
    4.35  	break;
    4.36      case GPFN_FRAME_BUFFER:
    4.37      case GPFN_LOW_MMIO:
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/xen/arch/ia64/vmx/viosapic.c	Wed Nov 29 11:05:02 2006 -0700
     5.3 @@ -0,0 +1,354 @@
     5.4 +/*
     5.5 + *  Copyright (C) 2001  MandrakeSoft S.A.
     5.6 + *
     5.7 + *    MandrakeSoft S.A.
     5.8 + *    43, rue d'Aboukir
     5.9 + *    75002 Paris - France
    5.10 + *    http://www.linux-mandrake.com/
    5.11 + *    http://www.mandrakesoft.com/
    5.12 + *
    5.13 + *  This library is free software; you can redistribute it and/or
    5.14 + *  modify it under the terms of the GNU Lesser General Public
    5.15 + *  License as published by the Free Software Foundation; either
    5.16 + *  version 2 of the License, or (at your option) any later version.
    5.17 + *
    5.18 + *  This library is distributed in the hope that it will be useful,
    5.19 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.20 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.21 + *  Lesser General Public License for more details.
    5.22 + *
    5.23 + *  You should have received a copy of the GNU Lesser General Public
    5.24 + *  License along with this library; if not, write to the Free Software
    5.25 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    5.26 + *
    5.27 + *  Yunhong Jiang <yunhong.jiang@intel.com>
    5.28 + *  Ported to xen by using virtual IRQ line.
    5.29 + */
    5.30 +
    5.31 +#include <xen/config.h>
    5.32 +#include <xen/types.h>
    5.33 +#include <xen/mm.h>
    5.34 +#include <xen/xmalloc.h>
    5.35 +#include <xen/lib.h>
    5.36 +#include <xen/errno.h>
    5.37 +#include <xen/sched.h>
    5.38 +#include <public/hvm/ioreq.h>
    5.39 +#include <asm/vlsapic.h>
    5.40 +#include <asm/viosapic.h>
    5.41 +#include <asm/current.h>
    5.42 +#include <asm/event.h>
    5.43 +
    5.44 +static void viosapic_deliver(struct viosapic *viosapic, int irq)
    5.45 +{
    5.46 +    uint16_t dest = viosapic->redirtbl[irq].dest_id;
    5.47 +    uint8_t delivery_mode = viosapic->redirtbl[irq].delivery_mode;
    5.48 +    uint8_t vector = viosapic->redirtbl[irq].vector;
    5.49 +    struct vcpu *v;
    5.50 +
    5.51 +    switch ( delivery_mode )
    5.52 +    {
    5.53 +    // don't support interrupt direct currently
    5.54 +    case SAPIC_FIXED:
    5.55 +    case SAPIC_LOWEST_PRIORITY:
    5.56 +    {
    5.57 +        v = vlsapic_lid_to_vcpu(viosapic_domain(viosapic), dest);
    5.58 +        vlsapic_set_irq(v, vector);
    5.59 +        vcpu_kick(v);
    5.60 +        break;
    5.61 +    }
    5.62 +    case SAPIC_PMI:
    5.63 +    case SAPIC_NMI:
    5.64 +    case SAPIC_INIT:
    5.65 +    case SAPIC_EXTINT:
    5.66 +    default:
    5.67 +        gdprintk(XENLOG_WARNING, "Unsupported delivery mode %d\n",
    5.68 +                 delivery_mode);
    5.69 +        break;
    5.70 +    }
    5.71 +}
    5.72 +
    5.73 +
    5.74 +static int iosapic_get_highest_irq(struct viosapic *viosapic)
    5.75 +{
    5.76 +    uint32_t irqs = viosapic->irr | viosapic->irr_xen;
    5.77 +    irqs &= ~viosapic->isr & ~viosapic->imr;
    5.78 +    return fls(irqs) - 1;
    5.79 +}
    5.80 +
    5.81 +
    5.82 +/* XXX If level interrupt, use vector->irq table for performance */
    5.83 +static int get_redir_num(struct viosapic *viosapic, int vector)
    5.84 +{
    5.85 +    int i;
    5.86 +
    5.87 +    for ( i = 0; i < VIOSAPIC_NUM_PINS; i++ )
    5.88 +        if ( viosapic->redirtbl[i].vector == vector )
    5.89 +            return i;
    5.90 +
    5.91 +    return -1;
    5.92 +}
    5.93 +
    5.94 +
    5.95 +static void service_iosapic(struct viosapic *viosapic)
    5.96 +{
    5.97 +    int irq;
    5.98 +
    5.99 +    while ( (irq = iosapic_get_highest_irq(viosapic)) != -1 )
   5.100 +    {
   5.101 +        if ( !test_bit(irq, &viosapic->imr) )
   5.102 +            viosapic_deliver(viosapic, irq);
   5.103 +
   5.104 +        if ( viosapic->redirtbl[irq].trig_mode == SAPIC_LEVEL )
   5.105 +            viosapic->isr |= (1 << irq);
   5.106 +
   5.107 +        viosapic->irr &= ~(1 << irq);
   5.108 +        viosapic->irr_xen &= ~(1 << irq);
   5.109 +    }
   5.110 +}
   5.111 +
   5.112 +
   5.113 +static void viosapic_update_EOI(struct viosapic *viosapic, int vector)
   5.114 +{
   5.115 +    int redir_num;
   5.116 +
   5.117 +    if ( (redir_num = get_redir_num(viosapic, vector)) == -1 )
   5.118 +    {
   5.119 +        gdprintk(XENLOG_WARNING, "Can't find redir item for %d EOI\n", vector);
   5.120 +        return;
   5.121 +    }
   5.122 +
   5.123 +    if ( !test_and_clear_bit(redir_num, &viosapic->isr) )
   5.124 +    {
   5.125 +        gdprintk(XENLOG_WARNING, "redir %d not set for %d EOI\n",
   5.126 +                 redir_num, vector);
   5.127 +        return;
   5.128 +    }
   5.129 +    service_iosapic(viosapic);
   5.130 +}
   5.131 +
   5.132 +
   5.133 +static unsigned long viosapic_read_indirect(struct viosapic *viosapic,
   5.134 +                                            unsigned long addr,
   5.135 +                                            unsigned long length)
   5.136 +{
   5.137 +    unsigned long result = 0;
   5.138 +
   5.139 +    switch ( viosapic->ioregsel )
   5.140 +    {
   5.141 +    case VIOSAPIC_VERSION:
   5.142 +        result = ((((VIOSAPIC_NUM_PINS - 1) & 0xff) << 16)
   5.143 +                  | (VIOSAPIC_VERSION_ID & 0xff));
   5.144 +        break;
   5.145 +
   5.146 +    default:
   5.147 +    {
   5.148 +        uint32_t redir_index = (viosapic->ioregsel - 0x10) >> 1;
   5.149 +        uint64_t redir_content;
   5.150 +
   5.151 +        if ( redir_index >= VIOSAPIC_NUM_PINS )
   5.152 +        {
   5.153 +            gdprintk(XENLOG_WARNING, "viosapic_read_indirect:undefined "
   5.154 +                     "ioregsel %x\n", viosapic->ioregsel);
   5.155 +            break;
   5.156 +        }
   5.157 +
   5.158 +        redir_content = viosapic->redirtbl[redir_index].bits;
   5.159 +        result = (viosapic->ioregsel & 0x1) ?
   5.160 +                 (redir_content >> 32) & 0xffffffff :
   5.161 +                 redir_content & 0xffffffff;
   5.162 +        break;
   5.163 +    }
   5.164 +    }
   5.165 +
   5.166 +    return result;
   5.167 +}
   5.168 +
   5.169 +
   5.170 +unsigned long viosapic_read(struct vcpu *v,
   5.171 +                            unsigned long addr,
   5.172 +                            unsigned long length)
   5.173 +{
   5.174 +    struct viosapic *viosapic = vcpu_viosapic(v);
   5.175 +    uint32_t result;
   5.176 +
   5.177 +    addr &= 0xff;
   5.178 +
   5.179 +    switch ( addr )
   5.180 +    {
   5.181 +    case VIOSAPIC_REG_SELECT:
   5.182 +        result = viosapic->ioregsel;
   5.183 +        break;
   5.184 +
   5.185 +    case VIOSAPIC_WINDOW:
   5.186 +        result = viosapic_read_indirect(viosapic, addr, length);
   5.187 +        break;
   5.188 +
   5.189 +    default:
   5.190 +        result = 0;
   5.191 +        break;
   5.192 +    }
   5.193 +
   5.194 +    return result;
   5.195 +}
   5.196 +
   5.197 +
   5.198 +static inline void viosapic_update_imr(struct viosapic *viosapic, int index)
   5.199 +{
   5.200 +    if ( viosapic->redirtbl[index].mask )
   5.201 +        set_bit(index, &viosapic->imr);
   5.202 +    else
   5.203 +        clear_bit(index, &viosapic->imr);
   5.204 +}
   5.205 +
   5.206 +
   5.207 +static void viosapic_write_indirect(struct viosapic *viosapic,
   5.208 +                                    unsigned long addr,
   5.209 +                                    unsigned long length,
   5.210 +                                    unsigned long val)
   5.211 +{
   5.212 +    switch ( viosapic->ioregsel )
   5.213 +    {
   5.214 +    case VIOSAPIC_VERSION:
   5.215 +        /* Writes are ignored. */
   5.216 +        break;
   5.217 +
   5.218 +    default:
   5.219 +    {
   5.220 +        uint32_t redir_index = (viosapic->ioregsel - 0x10) >> 1;
   5.221 +        uint64_t redir_content;
   5.222 +
   5.223 +        if ( redir_index >= VIOSAPIC_NUM_PINS )
   5.224 +        {
   5.225 +            gdprintk(XENLOG_WARNING, "viosapic_write_indirect "
   5.226 +                     "error register %x\n", viosapic->ioregsel);
   5.227 +            break;
   5.228 +        }
   5.229 +
   5.230 +        redir_content = viosapic->redirtbl[redir_index].bits;
   5.231 +
   5.232 +        if ( viosapic->ioregsel & 0x1 )
   5.233 +        {
   5.234 +            redir_content = (((uint64_t)val & 0xffffffff) << 32) |
   5.235 +                            (redir_content & 0xffffffff);
   5.236 +        }
   5.237 +        else
   5.238 +        {
   5.239 +            redir_content = ((redir_content >> 32) << 32) |
   5.240 +                            (val & 0xffffffff);
   5.241 +        }
   5.242 +        viosapic->redirtbl[redir_index].bits = redir_content;
   5.243 +        viosapic_update_imr(viosapic, redir_index);
   5.244 +        break;
   5.245 +    }
   5.246 +    } /* switch */
   5.247 +}
   5.248 +
   5.249 +
   5.250 +void viosapic_write(struct vcpu *v,
   5.251 +                      unsigned long addr,
   5.252 +                      unsigned long length,
   5.253 +                      unsigned long val)
   5.254 +{
   5.255 +    struct viosapic *viosapic = vcpu_viosapic(v);
   5.256 +
   5.257 +    addr &= 0xff;
   5.258 +
   5.259 +    switch ( addr )
   5.260 +    {
   5.261 +    case VIOSAPIC_REG_SELECT:
   5.262 +        viosapic->ioregsel = val;
   5.263 +        break;
   5.264 +
   5.265 +    case VIOSAPIC_WINDOW:
   5.266 +        viosapic_write_indirect(viosapic, addr, length, val);
   5.267 +        break;
   5.268 +
   5.269 +    case VIOSAPIC_EOI:
   5.270 +        viosapic_update_EOI(viosapic, val);
   5.271 +        break;
   5.272 +
   5.273 +    default:
   5.274 +        break;
   5.275 +    }
   5.276 +}
   5.277 +
   5.278 +
   5.279 +static void viosapic_reset(struct viosapic *viosapic)
   5.280 +{
   5.281 +    int i;
   5.282 +
   5.283 +    memset(viosapic, 0, sizeof(*viosapic));
   5.284 +
   5.285 +    for ( i = 0; i < VIOSAPIC_NUM_PINS; i++ )
   5.286 +    {
   5.287 +        viosapic->redirtbl[i].mask = 0x1;
   5.288 +        viosapic_update_imr(viosapic, i);
   5.289 +    }
   5.290 +    spin_lock_init(&viosapic->lock);
   5.291 +}
   5.292 +
   5.293 +
   5.294 +// this is used by VBD/VNIF to inject interrupt for VTI-domain
   5.295 +void viosapic_set_xen_irq(struct domain *d, int irq, int level)
   5.296 +{
   5.297 +    struct viosapic *viosapic = domain_viosapic(d);
   5.298 +
   5.299 +    spin_lock(&viosapic->lock);
   5.300 +    if ( viosapic->redirtbl[irq].mask )
   5.301 +        goto out;
   5.302 +
   5.303 +    if ( viosapic->redirtbl[irq].trig_mode == SAPIC_EDGE)
   5.304 +        gdprintk(XENLOG_WARNING, "Forcing edge triggered APIC irq %d?\n", irq);
   5.305 +
   5.306 +    if ( level )
   5.307 +        viosapic->irr_xen |= 1 << irq;
   5.308 +    else
   5.309 +        viosapic->irr_xen &= ~(1 << irq);
   5.310 +
   5.311 +    service_iosapic(viosapic);
   5.312 +out:
   5.313 +    spin_unlock(&viosapic->lock);
   5.314 +}
   5.315 +
   5.316 +
   5.317 +void viosapic_set_irq(struct domain *d, int irq, int level)
   5.318 +{
   5.319 +    struct viosapic *viosapic = domain_viosapic(d);
   5.320 +    uint32_t bit;
   5.321 +
   5.322 +    spin_lock(&viosapic->lock);
   5.323 +    if ( (irq < 0) || (irq >= VIOSAPIC_NUM_PINS) )
   5.324 +        goto out;
   5.325 +
   5.326 +    if ( viosapic->redirtbl[irq].mask )
   5.327 +        goto out;
   5.328 +
   5.329 +    bit = 1 << irq;
   5.330 +    if ( viosapic->redirtbl[irq].trig_mode == SAPIC_LEVEL )
   5.331 +    {
   5.332 +        if ( level )
   5.333 +            viosapic->irr |= bit;
   5.334 +        else
   5.335 +            viosapic->irr &= ~bit;
   5.336 +    }
   5.337 +    else
   5.338 +    {
   5.339 +        if ( level )
   5.340 +            /* XXX No irr clear for edge interrupt */
   5.341 +            viosapic->irr |= bit;
   5.342 +    }
   5.343 +
   5.344 +    service_iosapic(viosapic);
   5.345 +out:    
   5.346 +    spin_unlock(&viosapic->lock);
   5.347 +}
   5.348 +
   5.349 +
   5.350 +void viosapic_init(struct domain *d)
   5.351 +{
   5.352 +    struct viosapic *viosapic = domain_viosapic(d);
   5.353 +
   5.354 +    viosapic_reset(viosapic);
   5.355 +
   5.356 +    viosapic->base_address = VIOSAPIC_DEFAULT_BASE_ADDRESS;
   5.357 +}
     6.1 --- a/xen/arch/ia64/vmx/vlsapic.c	Wed Nov 29 09:16:46 2006 -0700
     6.2 +++ b/xen/arch/ia64/vmx/vlsapic.c	Wed Nov 29 11:05:02 2006 -0700
     6.3 @@ -38,7 +38,7 @@
     6.4  #include <asm/vmx_pal_vsa.h>
     6.5  #include <asm/kregs.h>
     6.6  #include <asm/vmx_platform.h>
     6.7 -#include <asm/hvm/vioapic.h>
     6.8 +#include <asm/viosapic.h>
     6.9  #include <asm/linux/jiffies.h>
    6.10  
    6.11  //u64  fire_itc;
    6.12 @@ -330,29 +330,6 @@ void vtm_domain_in(VCPU *vcpu)
    6.13  }
    6.14   */
    6.15  
    6.16 -#ifdef V_IOSAPIC_READY
    6.17 -int vlapic_match_logical_addr(struct vlapic *vlapic, uint16_t dest)
    6.18 -{
    6.19 -    return (VLAPIC_ID(vlapic) == dest);
    6.20 -}
    6.21 -
    6.22 -struct vlapic* apic_round_robin(struct domain *d,
    6.23 -				uint8_t vector,
    6.24 -				uint32_t bitmap)
    6.25 -{
    6.26 -    uint8_t bit = 0;
    6.27 -    
    6.28 -    if (!bitmap) {
    6.29 -	printk("<apic_round_robin> no bit on bitmap\n");
    6.30 -	return NULL;
    6.31 -    }
    6.32 -
    6.33 -    while (!(bitmap & (1 << bit)))
    6.34 -        bit++;
    6.35 -
    6.36 -    return vcpu_vlapic(d->vcpu[bit]);
    6.37 -}
    6.38 -#endif
    6.39  
    6.40  void vlsapic_reset(VCPU *vcpu)
    6.41  {
    6.42 @@ -375,9 +352,6 @@ void vlsapic_reset(VCPU *vcpu)
    6.43          VLSAPIC_INSVC(vcpu,i) = 0;
    6.44      }
    6.45  
    6.46 -#ifdef V_IOSAPIC_READY
    6.47 -    vcpu->arch.arch_vmx.vlapic.vcpu = vcpu;
    6.48 -#endif
    6.49      dprintk(XENLOG_INFO, "VLSAPIC inservice base=%p\n", &VLSAPIC_INSVC(vcpu,0) );
    6.50  }
    6.51  
    6.52 @@ -667,13 +641,12 @@ void vmx_vexirq(VCPU *vcpu)
    6.53      generate_exirq (vcpu);
    6.54  }
    6.55  
    6.56 -
    6.57 -void vmx_vioapic_set_irq(struct domain *d, int irq, int level)
    6.58 +struct vcpu * vlsapic_lid_to_vcpu(struct domain *d, uint16_t dest)
    6.59  {
    6.60 -    unsigned long flags;
    6.61 -
    6.62 -    spin_lock_irqsave(&d->arch.arch_vmx.virq_assist_lock, flags);
    6.63 -    vioapic_set_irq(d, irq, level);
    6.64 -    spin_unlock_irqrestore(&d->arch.arch_vmx.virq_assist_lock, flags);
    6.65 -}
    6.66 -
    6.67 +    struct vcpu * v;
    6.68 +    for_each_vcpu ( d, v ) {
    6.69 +        if ( (v->arch.privregs->lid >> 16) == dest )
    6.70 +            return v;
    6.71 +    }
    6.72 +    return NULL;
    6.73 +}                                     
     7.1 --- a/xen/arch/ia64/vmx/vmx_hypercall.c	Wed Nov 29 09:16:46 2006 -0700
     7.2 +++ b/xen/arch/ia64/vmx/vmx_hypercall.c	Wed Nov 29 11:05:02 2006 -0700
     7.3 @@ -35,6 +35,7 @@
     7.4  #include <asm/dom_fw.h>
     7.5  #include <xen/domain.h>
     7.6  #include <asm/vmx.h> 
     7.7 +#include <asm/viosapic.h> 
     7.8  
     7.9  long
    7.10  do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg)
    7.11 @@ -96,7 +97,7 @@ do_hvm_op(unsigned long op, XEN_GUEST_HA
    7.12  
    7.13          rc = -EINVAL;
    7.14          if (is_hvm_domain(d)) {
    7.15 -            vmx_vioapic_set_irq(d, op.irq, op.level);
    7.16 +            viosapic_set_irq(d, op.irq, op.level);
    7.17              rc = 0;
    7.18          }
    7.19  
     8.1 --- a/xen/arch/ia64/vmx/vmx_init.c	Wed Nov 29 09:16:46 2006 -0700
     8.2 +++ b/xen/arch/ia64/vmx/vmx_init.c	Wed Nov 29 11:05:02 2006 -0700
     8.3 @@ -48,13 +48,12 @@
     8.4  #include <asm/processor.h>
     8.5  #include <asm/vmx.h>
     8.6  #include <xen/mm.h>
     8.7 -#include <asm/hvm/vioapic.h>
     8.8 +#include <asm/viosapic.h>
     8.9  #include <xen/event.h>
    8.10  #include <asm/vlsapic.h>
    8.11  
    8.12  /* Global flag to identify whether Intel vmx feature is on */
    8.13  u32 vmx_enabled = 0;
    8.14 -unsigned int opt_vmx_debug_level = 0;
    8.15  static u32 vm_order;
    8.16  static u64 buffer_size;
    8.17  static u64 vp_env_info;
    8.18 @@ -396,11 +395,8 @@ void vmx_setup_platform(struct domain *d
    8.19  	memset(&d->shared_info->evtchn_mask[0], 0xff,
    8.20  	       sizeof(d->shared_info->evtchn_mask));
    8.21  
    8.22 -	/* initiate spinlock for pass virq */
    8.23 -	spin_lock_init(&d->arch.arch_vmx.virq_assist_lock);
    8.24 -
    8.25  	/* Initialize iosapic model within hypervisor */
    8.26 -	vioapic_init(d);
    8.27 +	viosapic_init(d);
    8.28  }
    8.29  
    8.30  void vmx_do_launch(struct vcpu *v)
     9.1 --- a/xen/include/asm-ia64/config.h	Wed Nov 29 09:16:46 2006 -0700
     9.2 +++ b/xen/include/asm-ia64/config.h	Wed Nov 29 11:05:02 2006 -0700
     9.3 @@ -283,9 +283,4 @@ struct screen_info { };
     9.4  /* Define CONFIG_PRIVIFY to support privified OS (deprecated).  */
     9.5  #undef CONFIG_PRIVIFY
     9.6  
     9.7 -/* Necessary for hvm_vioapic.c */
     9.8 -#define vcpu_vlapic(vcpu)   (&(vcpu)->arch.arch_vmx.vlapic)
     9.9 -#define vlapic_vcpu(vpic)   (container_of((vpic), struct vcpu, \
    9.10 -                                          arch.arch_vmx.vlapic))
    9.11 -
    9.12  #endif	/* _IA64_CONFIG_H_ */
    10.1 --- a/xen/include/asm-ia64/domain.h	Wed Nov 29 09:16:46 2006 -0700
    10.2 +++ b/xen/include/asm-ia64/domain.h	Wed Nov 29 11:05:02 2006 -0700
    10.3 @@ -124,8 +124,6 @@ struct arch_domain {
    10.4  
    10.5      struct last_vcpu last_vcpu[NR_CPUS];
    10.6  
    10.7 -    struct arch_vmx_domain arch_vmx; /* Virtual Machine Extensions */
    10.8 -
    10.9  #ifdef CONFIG_XEN_IA64_TLB_TRACK
   10.10      struct tlb_track*   tlb_track;
   10.11  #endif
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/xen/include/asm-ia64/viosapic.h	Wed Nov 29 11:05:02 2006 -0700
    11.3 @@ -0,0 +1,96 @@
    11.4 +/*
    11.5 + *
    11.6 + *  Copyright (C) 2001  MandrakeSoft S.A.
    11.7 + *
    11.8 + *    MandrakeSoft S.A.
    11.9 + *    43, rue d'Aboukir
   11.10 + *    75002 Paris - France
   11.11 + *    http://www.linux-mandrake.com/
   11.12 + *    http://www.mandrakesoft.com/
   11.13 + *
   11.14 + *  This library is free software; you can redistribute it and/or
   11.15 + *  modify it under the terms of the GNU Lesser General Public
   11.16 + *  License as published by the Free Software Foundation; either
   11.17 + *  version 2 of the License, or (at your option) any later version.
   11.18 + *
   11.19 + *  This library is distributed in the hope that it will be useful,
   11.20 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.21 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11.22 + *  Lesser General Public License for more details.
   11.23 + *
   11.24 + *  You should have received a copy of the GNU Lesser General Public
   11.25 + *  License along with this library; if not, write to the Free Software
   11.26 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   11.27 + */
   11.28 +
   11.29 +#ifndef __ASM_IA64_VMX_VIOSAPIC_H__
   11.30 +#define __ASM_IA64_VMX_VIOSAPIC_H__
   11.31 +
   11.32 +#include <xen/config.h>
   11.33 +#include <xen/types.h>
   11.34 +#include <xen/smp.h>
   11.35 +
   11.36 +/* Direct registers. */
   11.37 +#define VIOSAPIC_REG_SELECT   0x00
   11.38 +#define VIOSAPIC_WINDOW       0x10
   11.39 +#define VIOSAPIC_EOI          0x40
   11.40 +
   11.41 +#define VIOSAPIC_VERSION      0x1
   11.42 +
   11.43 +#define VIOSAPIC_DEST_SHIFT   16
   11.44 +
   11.45 +
   11.46 +#define VIOSAPIC_VERSION_ID   0x21 /* IOSAPIC version */
   11.47 +
   11.48 +#define VIOSAPIC_NUM_PINS     24
   11.49 +
   11.50 +#define VIOSAPIC_DEFAULT_BASE_ADDRESS  0xfec00000
   11.51 +#define VIOSAPIC_MEM_LENGTH            0x100
   11.52 +
   11.53 +#define domain_viosapic(d) (&(d)->arch.hvm_domain.viosapic)
   11.54 +#define viosapic_domain(v) (container_of((v), struct domain, \
   11.55 +                                        arch.hvm_domain.viosapic))
   11.56 +#define vcpu_viosapic(v) (&(v)->domain->arch.hvm_domain.viosapic)
   11.57 +
   11.58 +union viosapic_rte
   11.59 +{
   11.60 +    uint64_t bits;
   11.61 +    struct {
   11.62 +        uint8_t vector;
   11.63 +
   11.64 +        uint8_t delivery_mode  : 3;
   11.65 +        uint8_t reserve1       : 1;
   11.66 +        uint8_t delivery_status: 1;
   11.67 +        uint8_t polarity       : 1;
   11.68 +        uint8_t reserve2       : 1;
   11.69 +        uint8_t trig_mode      : 1;
   11.70 +
   11.71 +        uint8_t mask           : 1;
   11.72 +        uint8_t reserve3       : 7;
   11.73 +
   11.74 +        uint8_t reserved[3];
   11.75 +        uint16_t dest_id;
   11.76 +    }; 
   11.77 +};
   11.78 +
   11.79 +struct viosapic {
   11.80 +    uint32_t irr;
   11.81 +    uint32_t irr_xen; /* interrupts forced on by the hypervisor. */
   11.82 +    uint32_t isr;     /* This is used for level trigger */
   11.83 +    uint32_t imr;
   11.84 +    uint32_t ioregsel;
   11.85 +    spinlock_t lock;
   11.86 +    unsigned long base_address;
   11.87 +    union viosapic_rte redirtbl[VIOSAPIC_NUM_PINS];
   11.88 +};
   11.89 +
   11.90 +void viosapic_init(struct domain *d);
   11.91 +void viosapic_set_xen_irq(struct domain *d, int irq, int level);
   11.92 +void viosapic_set_irq(struct domain *d, int irq, int level);
   11.93 +void viosapic_write(struct vcpu *v, unsigned long addr,
   11.94 +                    unsigned long length, unsigned long val);
   11.95 +
   11.96 +unsigned long viosapic_read(struct vcpu *v, unsigned long addr,
   11.97 +                            unsigned long length);
   11.98 +
   11.99 +#endif /* __ASM_IA64_VMX_VIOSAPIC_H__ */
    12.1 --- a/xen/include/asm-ia64/vlsapic.h	Wed Nov 29 09:16:46 2006 -0700
    12.2 +++ b/xen/include/asm-ia64/vlsapic.h	Wed Nov 29 11:05:02 2006 -0700
    12.3 @@ -23,6 +23,37 @@
    12.4  #ifndef _LSAPIC_H
    12.5  #define _LSAPIC_H
    12.6  #include <xen/sched.h>
    12.7 +#include <asm/vmx_vcpu.h>
    12.8 +/*
    12.9 + *Delivery mode
   12.10 + */
   12.11 +#define SAPIC_DELIV_SHIFT      8
   12.12 +#define SAPIC_FIXED            0x0
   12.13 +#define SAPIC_LOWEST_PRIORITY  0x1
   12.14 +#define SAPIC_PMI              0x2
   12.15 +#define SAPIC_NMI              0x4
   12.16 +#define SAPIC_INIT             0x5
   12.17 +#define SAPIC_EXTINT           0x7
   12.18 +
   12.19 +/*
   12.20 + *Interrupt polarity
   12.21 + */
   12.22 +#define SAPIC_POLARITY_SHIFT   13
   12.23 +#define SAPIC_POL_HIGH         0
   12.24 +#define SAPIC_POL_LOW          1
   12.25 +
   12.26 +/*
   12.27 + *Trigger mode
   12.28 + */
   12.29 +#define SAPIC_TRIGGER_SHIFT    15
   12.30 +#define SAPIC_EDGE             0
   12.31 +#define SAPIC_LEVEL            1
   12.32 +
   12.33 +/*
   12.34 + *Mask bit
   12.35 + */
   12.36 +#define SAPIC_MASK_SHIFT       16
   12.37 +#define SAPIC_MASK             (1 << SAPIC_MASK_SHIFT)
   12.38  
   12.39  extern void vtm_init(struct vcpu *vcpu);
   12.40  extern void vtm_set_itc(struct  vcpu *vcpu, uint64_t new_itc);
   12.41 @@ -30,5 +61,7 @@ extern void vtm_set_itm(struct vcpu *vcp
   12.42  extern void vtm_set_itv(struct vcpu *vcpu, uint64_t val);
   12.43  extern void vmx_vexirq(struct vcpu  *vcpu);
   12.44  extern void vhpi_detection(struct vcpu *vcpu);
   12.45 -
   12.46 +extern int vmx_vcpu_pend_interrupt(VCPU * vcpu, uint8_t vector);
   12.47 +extern struct vcpu * vlsapic_lid_to_vcpu(struct domain *d, uint16_t dest);
   12.48 +#define vlsapic_set_irq vmx_vcpu_pend_interrupt
   12.49  #endif
    13.1 --- a/xen/include/asm-ia64/vmx.h	Wed Nov 29 09:16:46 2006 -0700
    13.2 +++ b/xen/include/asm-ia64/vmx.h	Wed Nov 29 11:05:02 2006 -0700
    13.3 @@ -55,7 +55,6 @@ extern void vmx_relinquish_guest_resourc
    13.4  extern void vmx_relinquish_vcpu_resources(struct vcpu *v);
    13.5  extern void vmx_die_if_kernel(char *str, struct pt_regs *regs, long err);
    13.6  extern void vmx_send_assist_req(struct vcpu *v);
    13.7 -extern void vmx_vioapic_set_irq(struct domain *d, int irq, int level);
    13.8  
    13.9  static inline vcpu_iodata_t *get_vio(struct domain *d, unsigned long cpu)
   13.10  {
    14.1 --- a/xen/include/asm-ia64/vmx_platform.h	Wed Nov 29 09:16:46 2006 -0700
    14.2 +++ b/xen/include/asm-ia64/vmx_platform.h	Wed Nov 29 11:05:02 2006 -0700
    14.3 @@ -21,7 +21,7 @@
    14.4  
    14.5  #include <public/xen.h>
    14.6  #include <public/hvm/params.h>
    14.7 -#include <asm/hvm/vioapic.h>
    14.8 +#include <asm/viosapic.h>
    14.9  struct mmio_list;
   14.10  typedef struct virtual_platform_def {
   14.11      unsigned long          buffered_io_va;
   14.12 @@ -32,7 +32,7 @@ typedef struct virtual_platform_def {
   14.13      unsigned long       params[HVM_NR_PARAMS];
   14.14      struct mmio_list    *mmio;
   14.15      /* One IOSAPIC now... */
   14.16 -    struct vioapic      vioapic;
   14.17 +    struct viosapic     viosapic;
   14.18  } vir_plat_t;
   14.19  
   14.20  static inline int __fls(uint32_t word)
   14.21 @@ -43,47 +43,4 @@ static inline int __fls(uint32_t word)
   14.22      __asm__ __volatile__ ("getf.exp %0=%1" : "=r"(exp) : "f"(d));
   14.23      return word ? (exp - 0xffff) : -1;
   14.24  }
   14.25 -
   14.26 -/* This is a connect structure between vIOSAPIC model and vLSAPIC model.
   14.27 - * vlapic is required by vIOSAPIC model to manipulate pending bits, and
   14.28 - * we just map them into vpd here
   14.29 - */
   14.30 -typedef struct vlapic {
   14.31 -    struct vcpu	*vcpu;	/* Link to current vcpu */
   14.32 -} vlapic_t;
   14.33 -
   14.34 -extern uint64_t dummy_tmr[];
   14.35 -#define VLAPIC_ID(l) (uint16_t)(((l)->vcpu->arch.privregs->lid) >> 16)
   14.36 -#define VLAPIC_IRR(l) ((l)->vcpu->arch.privregs->irr[0])
   14.37 -struct vlapic *apic_round_robin(struct domain *d, uint8_t vector, uint32_t bitmap);
   14.38 -extern int vmx_vcpu_pend_interrupt(struct vcpu *vcpu, uint8_t vector);
   14.39 -static inline int vlapic_set_irq(struct vlapic *t, uint8_t vec, uint8_t trig)
   14.40 -{
   14.41 -    return vmx_vcpu_pend_interrupt(t->vcpu, vec);
   14.42 -}
   14.43 -
   14.44 -enum ioapic_irq_destination_types {
   14.45 -	dest_Fixed = 0,
   14.46 -	dest_LowestPrio = 1,
   14.47 -	dest_SMI = 2,
   14.48 -	dest__reserved_1 = 3,
   14.49 -	dest_NMI = 4,
   14.50 -	dest_INIT = 5,
   14.51 -	dest__reserved_2 = 6,
   14.52 -	dest_ExtINT = 7
   14.53 -};
   14.54 -
   14.55 -#define vlapic_enabled(l) 1
   14.56 -
   14.57 -#define VLAPIC_DELIV_MODE_FIXED		0x0
   14.58 -#define VLAPIC_DELIV_MODE_REDIR		0x1
   14.59 -#define VLAPIC_DELIV_MODE_LPRI		VLAPIC_DELIV_MODE_REDIR
   14.60 -#define VLAPIC_DELIV_MODE_PMI		0x2
   14.61 -#define VLAPIC_DELIV_MODE_SMI		0x2 /* For IA32 */
   14.62 -#define VLAPIC_DELIV_MODE_RESERVED	0x3
   14.63 -#define VLAPIC_DELIV_MODE_NMI		0x4
   14.64 -#define VLAPIC_DELIV_MODE_INIT		0x5
   14.65 -#define VLAPIC_DELIV_MODE_STARTUP	0x6 /* For IA32 */
   14.66 -#define VLAPIC_DELIV_MODE_EXT		0x7
   14.67 -
   14.68  #endif
    15.1 --- a/xen/include/asm-ia64/vmx_vpd.h	Wed Nov 29 09:16:46 2006 -0700
    15.2 +++ b/xen/include/asm-ia64/vmx_vpd.h	Wed Nov 29 11:05:02 2006 -0700
    15.3 @@ -74,14 +74,9 @@ struct ivt_debug{
    15.4  #define IVT_DEBUG_MAX 128
    15.5  #endif
    15.6  
    15.7 -struct arch_vmx_domain {
    15.8 -    spinlock_t virq_assist_lock; /* spinlock for pass virq */
    15.9 -};
   15.10 -
   15.11  struct arch_vmx_struct {
   15.12  //	vpd_t       *vpd;
   15.13      vtime_t	    vtm;
   15.14 -    struct vlapic   vlapic;
   15.15      unsigned long   vrr[8];
   15.16      /* if the corresponding bit is 1, then this page size is
   15.17         used in this region */
   15.18 @@ -118,12 +113,6 @@ struct arch_vmx_struct {
   15.19  #define ARCH_VMX_IO_WAIT        3       /* Waiting for I/O completion */
   15.20  #define ARCH_VMX_DOMAIN         5       /* Need it to indicate VTi domain */
   15.21  
   15.22 -
   15.23 -#define VMX_DEBUG 1
   15.24 -#if VMX_DEBUG
   15.25 -
   15.26 -extern unsigned int opt_vmx_debug_level;
   15.27 -#endif
   15.28  #endif //__ASSEMBLY__
   15.29  
   15.30  // VPD field offset