qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Shannon Zhao <zhaoshenglong@huawei.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: patches@linaro.org, Shlomo Pongratz <shlomo.pongratz@huawei.com>,
	Shlomo Pongratz <shlomopongratz@gmail.com>,
	Pavel Fedin <p.fedin@samsung.com>,
	Shannon Zhao <shannon.zhao@linaro.org>,
	Christoffer Dall <christoffer.dall@linaro.org>
Subject: Re: [Qemu-devel] [PATCH v3 16/20] hw/intc/arm_gicv3: Implement gicv3_cpuif_update()
Date: Wed, 15 Jun 2016 10:47:36 +0800	[thread overview]
Message-ID: <5760C1C8.5010504@huawei.com> (raw)
In-Reply-To: <1465915112-29272-17-git-send-email-peter.maydell@linaro.org>



On 2016/6/14 22:38, Peter Maydell wrote:
> Implement the gicv3_cpuif_update() function which deals with correctly
> asserting IRQ and FIQ based on the current running priority of the CPU,
> the priority of the highest priority pending interrupt and the CPU's
> current exception level and security state.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Shannon Zhao <shannon.zhao@linaro.org>

> ---
>  hw/intc/arm_gicv3_cpuif.c | 140 +++++++++++++++++++++++++++++++++++++++++++++-
>  hw/intc/gicv3_internal.h  |   5 +-
>  trace-events              |   2 +
>  3 files changed, 142 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c
> index e112646..7faf3c0 100644
> --- a/hw/intc/arm_gicv3_cpuif.c
> +++ b/hw/intc/arm_gicv3_cpuif.c
> @@ -36,6 +36,142 @@ static bool gicv3_use_ns_bank(CPUARMState *env)
>      return !arm_is_secure_below_el3(env);
>  }
>  
> +static int icc_highest_active_prio(GICv3CPUState *cs)
> +{
> +    /* Calculate the current running priority based on the set bits
> +     * in the Active Priority Registers.
> +     */
> +    int i;
> +
> +    for (i = 0; i < ARRAY_SIZE(cs->icc_apr[0]); i++) {
> +        uint32_t apr = cs->icc_apr[GICV3_G0][i] |
> +            cs->icc_apr[GICV3_G1][i] | cs->icc_apr[GICV3_G1NS][i];
> +
> +        if (!apr) {
> +            continue;
> +        }
> +        return (i * 32 + ctz32(apr)) << (GIC_MIN_BPR + 1);
> +    }
> +    /* No current active interrupts: return idle priority */
> +    return 0xff;
> +}
> +
> +static uint32_t icc_gprio_mask(GICv3CPUState *cs, int group)
> +{
> +    /* Return a mask word which clears the subpriority bits from
> +     * a priority value for an interrupt in the specified group.
> +     * This depends on the BPR value:
> +     *  a BPR of 0 means the group priority bits are [7:1];
> +     *  a BPR of 1 means they are [7:2], and so on down to
> +     *  a BPR of 7 meaning no group priority bits at all.
> +     * Which BPR to use depends on the group of the interrupt and
> +     * the current ICC_CTLR.CBPR settings.
> +     */
> +    if ((group == GICV3_G1 && cs->icc_ctlr_el1[GICV3_S] & ICC_CTLR_EL1_CBPR) ||
> +        (group == GICV3_G1NS &&
> +         cs->icc_ctlr_el1[GICV3_NS] & ICC_CTLR_EL1_CBPR)) {
> +        group = GICV3_G0;
> +    }
> +
> +    return ~0U << ((cs->icc_bpr[group] & 7) + 1);
> +}
> +
> +static bool icc_no_enabled_hppi(GICv3CPUState *cs)
> +{
> +    /* Return true if there is no pending interrupt, or the
> +     * highest priority pending interrupt is in a group which has been
> +     * disabled at the CPU interface by the ICC_IGRPEN* register enable bits.
> +     */
> +    return cs->hppi.prio == 0xff || (cs->icc_igrpen[cs->hppi.grp] == 0);
> +}
> +
> +static bool icc_hppi_can_preempt(GICv3CPUState *cs)
> +{
> +    /* Return true if we have a pending interrupt of sufficient
> +     * priority to preempt.
> +     */
> +    int rprio;
> +    uint32_t mask;
> +
> +    if (icc_no_enabled_hppi(cs)) {
> +        return false;
> +    }
> +
> +    if (cs->hppi.prio >= cs->icc_pmr_el1) {
> +        /* Priority mask masks this interrupt */
> +        return false;
> +    }
> +
> +    rprio = icc_highest_active_prio(cs);
> +    if (rprio == 0xff) {
> +        /* No currently running interrupt so we can preempt */
> +        return true;
> +    }
> +
> +    mask = icc_gprio_mask(cs, cs->hppi.grp);
> +
> +    /* We only preempt a running interrupt if the pending interrupt's
> +     * group priority is sufficient (the subpriorities are not considered).
> +     */
> +    if ((cs->hppi.prio & mask) < (rprio & mask)) {
> +        return true;
> +    }
> +
> +    return false;
> +}
> +
> +void gicv3_cpuif_update(GICv3CPUState *cs)
> +{
> +    /* Tell the CPU about its highest priority pending interrupt */
> +    int irqlevel = 0;
> +    int fiqlevel = 0;
> +    ARMCPU *cpu = ARM_CPU(cs->cpu);
> +    CPUARMState *env = &cpu->env;
> +
> +    trace_gicv3_cpuif_update(gicv3_redist_affid(cs), cs->hppi.irq,
> +                             cs->hppi.grp, cs->hppi.prio);
> +
> +    if (cs->hppi.grp == GICV3_G1 && !arm_feature(env, ARM_FEATURE_EL3)) {
> +        /* If a Security-enabled GIC sends a G1S interrupt to a
> +         * Security-disabled CPU, we must treat it as if it were G0.
> +         */
> +        cs->hppi.grp = GICV3_G0;
> +    }
> +
> +    if (icc_hppi_can_preempt(cs)) {
> +        /* We have an interrupt: should we signal it as IRQ or FIQ?
> +         * This is described in the GICv3 spec section 4.6.2.
> +         */
> +        bool isfiq;
> +
> +        switch (cs->hppi.grp) {
> +        case GICV3_G0:
> +            isfiq = true;
> +            break;
> +        case GICV3_G1:
> +            isfiq = (!arm_is_secure(env) ||
> +                     (arm_current_el(env) == 3 && arm_el_is_aa64(env, 3)));
> +            break;
> +        case GICV3_G1NS:
> +            isfiq = arm_is_secure(env);
> +            break;
> +        default:
> +            g_assert_not_reached();
> +        }
> +
> +        if (isfiq) {
> +            fiqlevel = 1;
> +        } else {
> +            irqlevel = 1;
> +        }
> +    }
> +
> +    trace_gicv3_cpuif_set_irqs(gicv3_redist_affid(cs), fiqlevel, irqlevel);
> +
> +    qemu_set_irq(cs->parent_fiq, fiqlevel);
> +    qemu_set_irq(cs->parent_irq, irqlevel);
> +}
> +
>  static uint64_t icc_pmr_read(CPUARMState *env, const ARMCPRegInfo *ri)
>  {
>      GICv3CPUState *cs = icc_cs_from_env(env);
> @@ -617,7 +753,9 @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = {
>  
>  static void gicv3_cpuif_el_change_hook(ARMCPU *cpu, void *opaque)
>  {
> -    /* Do nothing for now. */
> +    GICv3CPUState *cs = opaque;
> +
> +    gicv3_cpuif_update(cs);
>  }
>  
>  void gicv3_init_cpuif(GICv3State *s)
> diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h
> index 13f951c..e469599 100644
> --- a/hw/intc/gicv3_internal.h
> +++ b/hw/intc/gicv3_internal.h
> @@ -222,10 +222,7 @@ void gicv3_init_cpuif(GICv3State *s);
>   * current running priority or the CPU's current exception level or
>   * security state.
>   */
> -static inline void gicv3_cpuif_update(GICv3CPUState *cs)
> -{
> -    /* This will be implemented in a later commit. */
> -}
> +void gicv3_cpuif_update(GICv3CPUState *cs);
>  
>  static inline uint32_t gicv3_iidr(void)
>  {
> diff --git a/trace-events b/trace-events
> index baf12ba..c8fb467 100644
> --- a/trace-events
> +++ b/trace-events
> @@ -2179,6 +2179,8 @@ gicv3_icc_ctlr_read(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR read cpu %x valu
>  gicv3_icc_ctlr_write(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR write cpu %x value 0x%" PRIx64
>  gicv3_icc_ctlr_el3_read(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR_EL3 read cpu %x value 0x%" PRIx64
>  gicv3_icc_ctlr_el3_write(uint32_t cpu, uint64_t val) "GICv3 ICC_CTLR_EL3 write cpu %x value 0x%" PRIx64
> +gicv3_cpuif_update(uint32_t cpuid, int irq, int grp, int prio) "GICv3 CPU i/f %x HPPI update: irq %d group %d prio %d"
> +gicv3_cpuif_set_irqs(uint32_t cpuid, int fiqlevel, int irqlevel) "GICv3 CPU i/f %x HPPI update: setting FIQ %d IRQ %d"
>  
>  # hw/intc/arm_gicv3_dist.c
>  gicv3_dist_read(uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 distributor read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d"
> 

-- 
Shannon

  reply	other threads:[~2016-06-15  2:48 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-14 14:38 [Qemu-devel] [PATCH v3 00/20] GICv3 emulation Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 01/20] migration: Define VMSTATE_UINT64_2DARRAY Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 02/20] bitops.h: Implement half-shuffle and half-unshuffle ops Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 03/20] target-arm: Define new arm_is_el3_or_mon() function Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 04/20] target-arm: Provide hook to tell GICv3 about changes of security state Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 05/20] target-arm: Add mp-affinity property for ARM CPU class Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 06/20] hw/intc/arm_gicv3: Add state information Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 07/20] hw/intc/arm_gicv3: Move irq lines into GICv3CPUState structure Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 08/20] hw/intc/arm_gicv3: Add vmstate descriptors Peter Maydell
2016-06-15  2:30   ` Shannon Zhao
2016-06-16  2:12   ` Shannon Zhao
2016-06-16 14:23     ` Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 09/20] hw/intc/arm_gicv3: ARM GICv3 device framework Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 10/20] hw/intc/arm_gicv3: Implement functions to identify next pending irq Peter Maydell
2016-06-15  2:35   ` Shannon Zhao
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 11/20] hw/intc/arm_gicv3: Implement GICv3 distributor registers Peter Maydell
2016-06-15  2:36   ` Shannon Zhao
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 12/20] hw/intc/arm_gicv3: Implement GICv3 redistributor registers Peter Maydell
2016-06-15  2:42   ` Shannon Zhao
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 13/20] hw/intc/arm_gicv3: Wire up distributor and redistributor MMIO regions Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 14/20] hw/intc/arm_gicv3: Implement gicv3_set_irq() Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 15/20] hw/intc/arm_gicv3: Implement GICv3 CPU interface registers Peter Maydell
2016-06-15  2:45   ` Shannon Zhao
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 16/20] hw/intc/arm_gicv3: Implement gicv3_cpuif_update() Peter Maydell
2016-06-15  2:47   ` Shannon Zhao [this message]
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 17/20] hw/intc/arm_gicv3: Implement CPU i/f SGI generation registers Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 18/20] hw/intc/arm_gicv3: Add IRQ handling CPU interface registers Peter Maydell
2016-06-15  3:15   ` Shannon Zhao
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 19/20] target-arm/machine.c: Allow user to request GICv3 emulation Peter Maydell
2016-06-14 14:38 ` [Qemu-devel] [PATCH v3 20/20] target-arm/monitor.c: Advertise emulated GICv3 in capabilities Peter Maydell
2016-06-15  2:52 ` [Qemu-devel] [PATCH v3 00/20] GICv3 emulation Shannon Zhao
2016-06-15  8:53 ` Shannon Zhao
2016-06-15  9:20   ` Andrew Jones
2016-06-15 10:06     ` Peter Maydell
2016-06-15 10:10       ` Peter Maydell
2016-06-15 14:02         ` Shannon Zhao
2016-06-15 14:06           ` Peter Maydell
2016-06-16  2:17         ` Shannon Zhao
2016-06-22 18:09         ` Ed Maste
2016-06-22 20:53           ` Peter Maydell
2016-06-22 21:45             ` Ed Maste
2016-06-22 21:56               ` Peter Maydell
2016-06-23  1:42               ` Shannon Zhao
2016-06-23 11:36             ` Laszlo Ersek
2016-06-23 12:07               ` Andrew Jones
2016-06-23 14:18               ` Ed Maste
2016-06-23 14:52                 ` Laszlo Ersek
2016-06-23 20:03                   ` Ard Biesheuvel
2016-06-23 20:33                     ` Peter Maydell
2016-06-24  8:16                       ` Ard Biesheuvel
2016-06-21 14:45   ` Andrew Jones
2016-06-21 14:55     ` Peter Maydell
2016-06-21 15:12       ` Andrew Jones
2016-06-21 17:15         ` Andrew Jones
2016-06-21 17:17           ` Peter Maydell
2016-06-21 17:18           ` Andrew Jones
2016-06-21 17:21             ` Peter Maydell
2016-06-21 19:45               ` Laszlo Ersek
2016-06-21 19:53                 ` Peter Maydell
2016-06-22  1:42                   ` Shannon Zhao
2016-06-22  7:43                     ` Andrew Jones
2016-06-22  8:27                       ` Shannon Zhao
2016-06-22  9:09                         ` Andrew Jones
2016-06-22 15:23                           ` Laszlo Ersek

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=5760C1C8.5010504@huawei.com \
    --to=zhaoshenglong@huawei.com \
    --cc=christoffer.dall@linaro.org \
    --cc=p.fedin@samsung.com \
    --cc=patches@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=shannon.zhao@linaro.org \
    --cc=shlomo.pongratz@huawei.com \
    --cc=shlomopongratz@gmail.com \
    /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).