xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@linaro.org>
To: vijay.kilari@gmail.com
Cc: Ian.Campbell@citrix.com, stefano.stabellini@eu.citrix.com,
	Prasun.Kapoor@caviumnetworks.com,
	vijaya.kumar@caviumnetworks.com, xen-devel@lists.xen.org,
	stefano.stabellini@citrix.com
Subject: Re: [PATCH v3 12/16] xen/arm: split vgic driver into generic and vgic-v2 driver
Date: Tue, 15 Apr 2014 21:05:09 +0100	[thread overview]
Message-ID: <534D90F5.1060909@linaro.org> (raw)
In-Reply-To: <1397560675-29861-13-git-send-email-vijay.kilari@gmail.com>

Hello Vijaya,

Thank you for the patch.

On 04/15/2014 12:17 PM, vijay.kilari@gmail.com wrote:

[..]

> +/*
> + * Offset of GICD_<FOO><n> with its rank, for GICD_<FOO> with
> + * <b>-bits-per-interrupt.
> + */
> +#define REG_RANK_INDEX(b, n) ((n) & ((b)-1))
> +
> +/*
> + * Returns rank corresponding to a GICD_<FOO><n> register for
> + * GICD_<FOO> with <b>-bits-per-interrupt.
> + */
> +static struct vgic_irq_rank *vgic_irq_rank(struct vcpu *v, int b, int n)

I think all the functions have to be named vgic_v2_...

It will improve readability for backtrace.

> +{
> +    int rank = REG_RANK_NR(b, n);
> +    return vgic_get_irqrank(v, rank);
> +}
> +
> +static int vgic_read_priority(struct vcpu *v, int irq)
> +{
> +   int idx = irq >> 2;
> +   struct vgic_irq_rank *rank = vgic_irq_rank(v, 8, idx);

New line here for clarity.

> +   return byte_read(rank->ipriority[REG_RANK_INDEX(8, idx)], 0, irq & 0x3);
> +}

[..]

> +static int vgic_vcpu_init(struct vcpu *v)
> +{
> +    int i;
> +
> +    /* For SGI and PPI the target is always this CPU */
> +    for ( i = 0 ; i < 8 ; i++ )
> +        v->arch.vgic.private_irqs->itargets[i] =
> +              (1<<(v->vcpu_id+0))
> +            | (1<<(v->vcpu_id+8))
> +            | (1<<(v->vcpu_id+16))
> +            | (1<<(v->vcpu_id+24));

Newline here for clarity.

> +    return 0;
> +}
> +
> +static int vgic_domain_init(struct domain *d)
> +{
> +    vgic_distr_mmio_handler.addr = d->arch.vgic.dbase;
> +    vgic_distr_mmio_handler.size = PAGE_SIZE;
> +    register_mmio_handler(d, &vgic_distr_mmio_handler);
> +    return 0;
> +}
> +
> +static struct vgic_ops ops = {

This function as to be const.

> +    .vgic_vcpu_init   = vgic_vcpu_init,
> +    .vgic_domain_init = vgic_domain_init,
> +    .read_priority    = vgic_read_priority,
> +};
> +
> +int vgic_v2_init(struct domain *d)
> +{

What domain is used for if you unconditionally register the ops?

> +    register_vgic_ops(&ops);

I think you need to pass the domain here. And register the ops per domain.

Will be easier for a later change to support V2 on V3.

> +    return 0;
> +}
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
> diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c
> index 7e258ae..f487784 100644
> --- a/xen/arch/arm/vgic.c
> +++ b/xen/arch/arm/vgic.c
> @@ -28,29 +28,20 @@
>  #include <asm/current.h>
>  
>  #include <asm/mmio.h>
> -#include <asm/gic_v2_defs.h>
>  #include <asm/gic.h>
>  #include <asm/vgic.h>
>  
> -#define REG(n) (n/4)
>  
> -static struct mmio_handler vgic_distr_mmio_handler;
> +static struct vgic_ops *vgic_ops;

static const ?

>  
> -/*
> - * Offset of GICD_<FOO><n> with its rank, for GICD_<FOO> with
> - * <b>-bits-per-interrupt.
> - */
> -#define REG_RANK_INDEX(b, n) ((n) & ((b)-1))
> -
> -/*
> - * Returns rank corresponding to a GICD_<FOO><n> register for
> - * GICD_<FOO> with <b>-bits-per-interrupt.
> - */
> -static struct vgic_irq_rank *vgic_irq_rank(struct vcpu *v, int b, int n)
> +void register_vgic_ops(struct vgic_ops *ops)

const struct vgic_ops *ops ?

>  {
> -    int rank = REG_RANK_NR(b, n);
> +   vgic_ops = ops;
> +}
>  
> -    if ( rank == 0 )
> +struct vgic_irq_rank *vgic_get_irqrank(struct vcpu *v, int rank)
> +{
> +    if ( rank == 0 ) /* Rank 0 is nothing but GICR registers in GICv3 */
>          return v->arch.vgic.private_irqs;
>      else if ( rank <= DOMAIN_NR_RANKS(v->domain) )
>          return &v->domain->arch.vgic.shared_irqs[rank - 1];
> @@ -61,7 +52,6 @@ static struct vgic_irq_rank *vgic_irq_rank(struct vcpu *v, int b, int n)
>  int domain_vgic_init(struct domain *d)
>  {
>      int i;
> -
>      d->arch.vgic.ctlr = 0;
>  
>      /* Currently nr_lines in vgic and gic doesn't have the same meanings
> @@ -72,21 +62,34 @@ int domain_vgic_init(struct domain *d)
>      else
>          d->arch.vgic.nr_lines = 0; /* We don't need SPIs for the guest */
>  
> +    if ( gic_hw_version() == GIC_V2 )
> +        vgic_v2_init(d);
> +    else
> +        panic("No VGIC found\n");

panic when a domain is creating is not the right thing to do... You
should return here.

> +
>      d->arch.vgic.shared_irqs =
>          xzalloc_array(struct vgic_irq_rank, DOMAIN_NR_RANKS(d));
> +    if ( d->arch.vgic.shared_irqs == NULL )
> +        return -ENOMEM;
> +

Which version of Xen are you using? A patch to check shared_irqs has
been upstreamed a while ago.


> +    for ( i = 0; i < DOMAIN_NR_RANKS(d); i++ )
> +        spin_lock_init(&d->arch.vgic.shared_irqs[i].lock);
> +

Why did you move this code earlier?

> +    vgic_ops->vgic_domain_init(d);
> +

I think vgic_domain_init should be called at the end. Not in middle of
the initialization...

>      d->arch.vgic.pending_irqs =
>          xzalloc_array(struct pending_irq, d->arch.vgic.nr_lines);
> -    for (i=0; i<d->arch.vgic.nr_lines; i++)
> +    if ( d->arch.vgic.pending_irqs == NULL )
> +    {
> +        xfree(d->arch.vgic.shared_irqs);
> +        return -ENOMEM;
> +    }
> +

Patch already sent to fix this.

> +    for ( i = 0; i < d->arch.vgic.nr_lines; i++)

for ( ... )

>      {
>          INIT_LIST_HEAD(&d->arch.vgic.pending_irqs[i].inflight);
>          INIT_LIST_HEAD(&d->arch.vgic.pending_irqs[i].lr_queue);
>      }
> -    for (i=0; i<DOMAIN_NR_RANKS(d); i++)
> -        spin_lock_init(&d->arch.vgic.shared_irqs[i].lock);
> -
> -    vgic_distr_mmio_handler.addr = d->arch.vgic.dbase;
> -    vgic_distr_mmio_handler.size = PAGE_SIZE;
> -    register_mmio_handler(d, &vgic_distr_mmio_handler);
>      return 0;
>  }
>  
> @@ -105,9 +108,13 @@ int vcpu_vgic_init(struct vcpu *v)
>        return -ENOMEM;
>  
>      memset(v->arch.vgic.private_irqs, 0, sizeof(v->arch.vgic.private_irqs));
> -

Spurious change?

>      spin_lock_init(&v->arch.vgic.private_irqs->lock);
>  
> +    if ( vgic_ops )
> +       vgic_ops->vgic_vcpu_init(v);
> +    else
> +       panic("No VGIC ops found\n");
> +

No panic here... vgic_ops has been set before. So why should you check here?


Same question as for vgic_vpcu_init. Why did you move this code early?

>      memset(&v->arch.vgic.pending_irqs, 0, sizeof(v->arch.vgic.pending_irqs));
>      for (i = 0; i < 32; i++)
>      {
> @@ -115,13 +122,6 @@ int vcpu_vgic_init(struct vcpu *v)
>          INIT_LIST_HEAD(&v->arch.vgic.pending_irqs[i].lr_queue);
>      }
>  
> -    /* For SGI and PPI the target is always this CPU */
> -    for ( i = 0 ; i < 8 ; i++ )
> -        v->arch.vgic.private_irqs->itargets[i] =
> -              (1<<(v->vcpu_id+0))
> -            | (1<<(v->vcpu_id+8))
> -            | (1<<(v->vcpu_id+16))
> -            | (1<<(v->vcpu_id+24));
>      INIT_LIST_HEAD(&v->arch.vgic.inflight_irqs);
>      INIT_LIST_HEAD(&v->arch.vgic.lr_pending);
>      spin_lock_init(&v->arch.vgic.lock);
> @@ -135,7 +135,7 @@ int vcpu_vgic_free(struct vcpu *v)
>      return 0;
>  }
>  
> -static uint32_t byte_read(uint32_t val, int sign, int offset)
> +uint32_t byte_read(uint32_t val, int sign, int offset)

If you export this function, please rename it.

Also, I think it can be moved static inline in vgic.h.

>  {
>      int byte = offset & 0x3;
>  
> @@ -147,7 +147,7 @@ static uint32_t byte_read(uint32_t val, int sign, int offset)
>      return val;
>  }
>  
> -static void byte_write(uint32_t *reg, uint32_t var, int offset)
> +void byte_write(uint32_t *reg, uint32_t var, int offset)

Same remarks here.

[..]

>  struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq)
>  {
>      struct pending_irq *n;
> @@ -666,10 +229,9 @@ void vgic_clear_pending_irqs(struct vcpu *v)
>  
>  void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq)
>  {
> -    int idx = irq >> 2, byte = irq & 0x3;
>      uint8_t priority;
> -    struct vgic_irq_rank *rank = vgic_irq_rank(v, 8, idx);
> -    struct pending_irq *iter, *n = irq_to_pending(v, irq);
> +    struct pending_irq *iter;
> +    struct pending_irq  *n = irq_to_pending(v, irq);
>      unsigned long flags;
>      bool_t running;
>  
> @@ -682,7 +244,7 @@ void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq)
>          return;
>      }
>  
> -    priority = byte_read(rank->ipriority[REG_RANK_INDEX(8, idx)], 0, byte);
> +    priority = vgic_ops->read_priority(v, irq);
>  
>      n->irq = irq;
>      set_bit(GIC_IRQ_GUEST_PENDING, &n->status);
> diff --git a/xen/include/asm-arm/vgic.h b/xen/include/asm-arm/vgic.h
> index f9d6549..187846e 100644
> --- a/xen/include/asm-arm/vgic.h
> +++ b/xen/include/asm-arm/vgic.h
> @@ -28,6 +28,12 @@ struct vgic_irq_rank {
>      uint32_t itargets[8];
>  };
>  
> +struct vgic_ops {

Please describe every callbacks of this structure.

> +    int (*vgic_vcpu_init)(struct vcpu *v);
> +    int (*vgic_domain_init)(struct domain *d);
> +    int (*read_priority)(struct vcpu *v, int irq);

I saw this function is assuming that some locks are used. Please write a
comment about it.

Regards,

-- 
Julien Grall

  reply	other threads:[~2014-04-15 20:05 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-15 11:17 [PATCH v3 00/16] xen/arm: Add GICv3 support vijay.kilari
2014-04-15 11:17 ` [PATCH v3 01/16] xen/arm: move io.h as mmio.h to include folder vijay.kilari
2014-04-15 16:36   ` Julien Grall
2014-04-23 14:16   ` Ian Campbell
2014-04-15 11:17 ` [PATCH v3 02/16] xen/arm: make mmio handlers domain specific vijay.kilari
2014-04-15 17:07   ` Julien Grall
2014-04-23 14:27     ` Ian Campbell
2014-04-15 11:17 ` [PATCH v3 03/16] xen/arm: make sgi handling generic vijay.kilari
2014-04-15 17:51   ` Julien Grall
2014-04-15 17:57     ` Julien Grall
2014-04-23 14:31     ` Ian Campbell
2014-04-15 11:17 ` [PATCH v3 04/16] xen/arm: remove unused parameter in do_sgi call vijay.kilari
2014-04-15 17:52   ` Julien Grall
2014-04-23 14:32   ` Ian Campbell
2014-04-25  9:28     ` Vijay Kilari
2014-04-15 11:17 ` [PATCH v3 05/16] xen/arm: move gic definitions to seperate file vijay.kilari
2014-04-23 14:34   ` Ian Campbell
2014-04-15 11:17 ` [PATCH v3 06/16] xen/arm: move gic lock out of gic data structure vijay.kilari
2014-04-23 14:35   ` Ian Campbell
2014-05-12 13:49   ` Julien Grall
2014-04-15 11:17 ` [PATCH v3 07/16] xen/arm: segregate and split GIC low level functionality vijay.kilari
2014-04-15 18:35   ` Julien Grall
2014-04-23 14:55     ` Ian Campbell
2014-04-23 15:01       ` Julien Grall
2014-04-23 16:47         ` Julien Grall
2014-04-23 17:03           ` Ian Campbell
2014-04-23 17:09             ` Julien Grall
2014-04-24  8:58               ` Ian Campbell
2014-04-24  8:19           ` Ian Campbell
2014-04-28 11:48     ` Vijay Kilari
2014-04-28 12:06       ` Julien Grall
2014-04-28 13:10         ` Vijay Kilari
2014-04-28 13:12           ` Julien Grall
2014-04-15 21:00   ` Julien Grall
2014-04-23 14:52   ` Ian Campbell
2014-04-28 14:41     ` Vijay Kilari
2014-04-28 14:58       ` Ian Campbell
2014-04-28 15:10       ` Julien Grall
2014-04-15 11:17 ` [PATCH v3 08/16] arm/xen: move GIC context data structure to gic driver vijay.kilari
2014-04-15 18:41   ` Julien Grall
2014-04-23 14:57     ` Ian Campbell
2014-04-23 14:58   ` Ian Campbell
2014-04-15 11:17 ` [PATCH v3 09/16] xen/arm: use device api to detect GIC version vijay.kilari
2014-04-15 18:49   ` Julien Grall
2014-04-23 15:01   ` Ian Campbell
2014-04-29  7:07     ` Vijay Kilari
2014-04-29  8:55       ` Ian Campbell
2014-04-29 10:13         ` Julien Grall
2014-04-15 11:17 ` [PATCH v3 10/16] xen/arm: move vgic rank data to gic header file vijay.kilari
2014-04-15 19:10   ` Julien Grall
2014-04-17  6:48     ` Vijay Kilari
2014-05-07 15:03   ` Julien Grall
2014-04-15 11:17 ` [PATCH v3 11/16] xen/arm: move vgic defines to vgic " vijay.kilari
2014-04-16 17:01   ` Julien Grall
2014-04-23 15:07     ` Ian Campbell
2014-04-23 15:11       ` Julien Grall
2014-04-23 15:15         ` Ian Campbell
2014-04-15 11:17 ` [PATCH v3 12/16] xen/arm: split vgic driver into generic and vgic-v2 driver vijay.kilari
2014-04-15 20:05   ` Julien Grall [this message]
2014-04-23 15:12   ` Ian Campbell
2014-04-15 11:17 ` [PATCH v3 13/16] xen/arm: Add support for GIC v3 vijay.kilari
2014-04-15 20:43   ` Julien Grall
2014-04-17  7:09     ` Vijay Kilari
2014-04-17  8:58       ` Ian Campbell
2014-04-17  9:02       ` Julien Grall
2014-04-17  9:57   ` Julien Grall
2014-04-17 11:00     ` Vijay Kilari
2014-04-17 11:17       ` Julien Grall
2014-04-17 14:54         ` Vijay Kilari
2014-04-17 15:12           ` Julien Grall
2014-04-23 17:01   ` Ian Campbell
2014-04-23 17:24     ` Julien Grall
2014-04-29 12:35       ` Vijay Kilari
2014-05-05 12:08     ` Vijay Kilari
2014-05-06  8:55       ` Ian Campbell
2014-05-06 14:11         ` Vijay Kilari
2014-05-06 14:18           ` Julien Grall
2014-05-06 15:47             ` Julien Grall
2014-05-22  5:58               ` Vijay Kilari
2014-05-22  9:26                 ` Julien Grall
2014-05-22 12:36                   ` Stefano Stabellini
2014-05-07 16:30           ` Ian Campbell
2014-05-27 18:17     ` Julien Grall
2014-04-15 11:17 ` [PATCH v3 14/16] xen/arm: Add virtual GICv3 support vijay.kilari
2014-04-17  9:27   ` Julien Grall
2014-04-24 10:37     ` Ian Campbell
2014-04-24 11:39       ` Julien Grall
2014-04-24 10:30   ` Ian Campbell
2014-05-02  9:43     ` Vijay Kilari
2014-05-02  9:56       ` Ian Campbell
2014-04-15 11:17 ` [PATCH v3 15/16] xen/arm: Update Dom0 GIC dt node with GICv3 information vijay.kilari
2014-04-18 19:57   ` Julien Grall
2014-04-24 10:46   ` Ian Campbell
2014-04-15 11:17 ` [PATCH v3 16/16] xen/arm: add SGI handling for GICv3 vijay.kilari
2014-04-18 20:20   ` Julien Grall
2014-05-02 12:57     ` Vijay Kilari
2014-05-02 14:26       ` Julien Grall
2014-05-02 15:18         ` Ian Campbell
2014-05-02 15:24           ` Julien Grall
2014-05-05  6:53             ` Vijay Kilari
2014-05-05 18:40               ` Julien Grall
2014-05-06  8:58                 ` Ian Campbell
2014-05-06  9:42                   ` Julien Grall
2014-05-06 10:10                     ` Ian Campbell
2014-05-06 16:06                       ` Julien Grall
2014-04-24 10:57   ` Ian Campbell
2014-04-24 11:43     ` Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=534D90F5.1060909@linaro.org \
    --to=julien.grall@linaro.org \
    --cc=Ian.Campbell@citrix.com \
    --cc=Prasun.Kapoor@caviumnetworks.com \
    --cc=stefano.stabellini@citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=vijay.kilari@gmail.com \
    --cc=vijaya.kumar@caviumnetworks.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).