From: Ian Campbell Subject: Re: [PATCH 4/5] xen/vgic: vgic: support irq enable/disable Date: Tue, 26 Jun 2012 15:05:06 +0100 Message-ID: <1340719506.3832.124.camel@zakaz.uk.xensource.com> References: <1338981730-14816-1-git-send-email-stefano.stabellini@eu.citrix.com> <1338981730-14816-4-git-send-email-stefano.stabellini@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1338981730-14816-4-git-send-email-stefano.stabellini@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Stefano Stabellini Cc: "xen-devel@lists.xensource.com" , David Vrabel , "Tim Deegan (3P)" List-Id: xen-devel@lists.xenproject.org On Wed, 2012-06-06 at 12:22 +0100, Stefano Stabellini wrote: > If vgic_vcpu_inject_irq is called (for example by a device emulator like > vtimer.c) but the corresponding irq is not enabled in the virtual gicd > just queue it in the inflight_irqs list. > When the irq is enabled make sure to call gic_set_guest_irq. > > Signed-off-by: Stefano Stabellini I had to go reread the comments on inflight_irqs and lr_pending again (I'm perpetually confused by that stuff) but I think this makes sense. Acked-by: Ian Campbell > --- > xen/arch/arm/vgic.c | 23 ++++++++++++++++++++++- > 1 files changed, 22 insertions(+), 1 deletions(-) > > diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c > index 5a624bd..4cdfec5 100644 > --- a/xen/arch/arm/vgic.c > +++ b/xen/arch/arm/vgic.c > @@ -343,6 +343,22 @@ read_as_zero: > return 1; > } > > +static void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n) > +{ > + struct pending_irq *p; > + unsigned int irq; > + int i = 0; > + > + while ( (i = find_next_bit((const long unsigned int *) &r, > + sizeof(uint32_t), i)) < sizeof(uint32_t) ) { > + irq = i + (32 * n); > + p = irq_to_pending(v, irq); > + if ( !list_empty(&p->inflight) ) > + gic_set_guest_irq(v, irq, GICH_LR_PENDING, p->priority); > + i++; what you have here is a for loop ;-) > + } > +} > + > static int vgic_distr_mmio_write(struct vcpu *v, mmio_info_t *info) > { > struct hsr_dabt dabt = info->dabt; > @@ -351,6 +367,7 @@ static int vgic_distr_mmio_write(struct vcpu *v, mmio_info_t *info) > struct vgic_irq_rank *rank; > int offset = (int)(info->gpa - VGIC_DISTR_BASE_ADDRESS); > int gicd_reg = REG(offset); > + uint32_t tr; > > switch ( gicd_reg ) > { > @@ -378,8 +395,10 @@ static int vgic_distr_mmio_write(struct vcpu *v, mmio_info_t *info) > rank = vgic_irq_rank(v, 8, gicd_reg - GICD_ISENABLER); > if ( rank == NULL) goto write_ignore; > vgic_lock_rank(v, rank); > + tr = rank->ienable; > rank->ienable |= *r; > vgic_unlock_rank(v, rank); > + vgic_enable_irqs(v, (*r) & (~tr), gicd_reg - GICD_ISENABLER); > return 1; > > case GICD_ICENABLER ... GICD_ICENABLERN: > @@ -569,7 +588,9 @@ void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq, int virtual) > else > n->desc = NULL; > > - gic_set_guest_irq(v, irq, GICH_LR_PENDING, priority); > + /* the irq is enabled */ > + if ( rank->ienable & (1 << (irq % 32)) ) > + gic_set_guest_irq(v, irq, GICH_LR_PENDING, priority); > > spin_lock_irqsave(&v->arch.vgic.lock, flags); > list_for_each_entry ( iter, &v->arch.vgic.inflight_irqs, inflight )