All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alistair Francis <alistair23@gmail.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: "open list:RISC-V" <qemu-riscv@nongnu.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Alistair Francis <alistair.francis@wdc.com>,
	"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>
Subject: Re: [PATCH v2 6/9] hw/intc: Initial commit of lowRISC Ibex PLIC
Date: Thu, 14 May 2020 14:53:07 -0700	[thread overview]
Message-ID: <CAKmqyKOhoMG+Gc1FwJBRJe1DC5TEHFBDN1pdtR-YtHLEEc3EEw@mail.gmail.com> (raw)
In-Reply-To: <50effad3-3f41-2d36-e4dd-d14c05e6ea8c@redhat.com>

On Thu, May 14, 2020 at 11:40 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> On 5/7/20 9:13 PM, Alistair Francis wrote:
> > The Ibex core contains a PLIC that although similar to the RISC-V spec
> > is not RISC-V spec compliant.
> >
> > This patch implements a Ibex PLIC in a somewhat generic way.
> >
> > As the current RISC-V PLIC needs tidying up, my hope is that as the Ibex
> > PLIC move towards spec compliance this PLIC implementation can be
> > updated until it can replace the current PLIC.
> >
> > Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> > ---
> >   MAINTAINERS                 |   2 +
> >   hw/intc/Makefile.objs       |   1 +
> >   hw/intc/ibex_plic.c         | 261 ++++++++++++++++++++++++++++++++++++
> >   include/hw/intc/ibex_plic.h |  63 +++++++++
> >   4 files changed, 327 insertions(+)
> >   create mode 100644 hw/intc/ibex_plic.c
> >   create mode 100644 include/hw/intc/ibex_plic.h
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index d3d47564ce..f8c3cf6182 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -1237,8 +1237,10 @@ L: qemu-riscv@nongnu.org
> >   S: Supported
> >   F: hw/riscv/opentitan.c
> >   F: hw/char/ibex_uart.c
> > +F: hw/intc/ibex_plic.c
> >   F: include/hw/riscv/opentitan.h
> >   F: include/hw/char/ibex_uart.h
> > +F: include/hw/intc/ibex_plic.h
> >
> >
> >   SH4 Machines
> > diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs
> > index f726d87532..a61e6728fe 100644
> > --- a/hw/intc/Makefile.objs
> > +++ b/hw/intc/Makefile.objs
> > @@ -49,3 +49,4 @@ obj-$(CONFIG_ARM_GIC) += arm_gicv3_cpuif.o
> >   obj-$(CONFIG_MIPS_CPS) += mips_gic.o
> >   obj-$(CONFIG_NIOS2) += nios2_iic.o
> >   obj-$(CONFIG_OMPIC) += ompic.o
> > +obj-$(CONFIG_IBEX) += ibex_plic.o
> > diff --git a/hw/intc/ibex_plic.c b/hw/intc/ibex_plic.c
> > new file mode 100644
> > index 0000000000..35c52d9d16
> > --- /dev/null
> > +++ b/hw/intc/ibex_plic.c
> > @@ -0,0 +1,261 @@
> > +/*
> > + * QEMU RISC-V lowRISC Ibex PLIC
> > + *
> > + * Copyright (c) 2020 Western Digital
> > + *
> > + * Documentation avaliable: https://docs.opentitan.org/hw/ip/rv_plic/doc/
> > + *
> > + * This program is free software; you can redistribute it and/or modify it
> > + * under the terms and conditions of the GNU General Public License,
> > + * version 2 or later, as published by the Free Software Foundation.
> > + *
> > + * This program is distributed in the hope it will be useful, but WITHOUT
> > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> > + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> > + * more details.
> > + *
> > + * You should have received a copy of the GNU General Public License along with
> > + * this program.  If not, see <http://www.gnu.org/licenses/>.
> > + */
> > +
> > +#include "qemu/osdep.h"
> > +#include "qemu/log.h"
> > +#include "hw/qdev-properties.h"
> > +#include "hw/core/cpu.h"
> > +#include "hw/boards.h"
> > +#include "hw/pci/msi.h"
> > +#include "target/riscv/cpu_bits.h"
> > +#include "target/riscv/cpu.h"
> > +#include "hw/intc/ibex_plic.h"
> > +
> > +static bool addr_between(uint32_t addr, uint32_t base, uint32_t num)
> > +{
> > +    uint32_t end = base + (num * 0x04);
> > +
> > +    if (addr >= base && addr < end) {
> > +        return true;
> > +    }
> > +
> > +    return false;
> > +}
> > +
> > +static void ibex_plic_irqs_set_pending(IbexPlicState *s, int irq, bool level)
> > +{
> > +    int pending_num = irq / 32;
> > +
> > +    s->pending[pending_num] |= level << (irq % 32);
> > +}
> > +
> > +static bool ibex_plic_irqs_pending(IbexPlicState *s, uint32_t context)
> > +{
> > +    int i;
> > +
> > +    for (i = 0; i < s->pending_num; i++) {
> > +        uint32_t irq_num = ctz64(s->pending[i]) + (i * 32);
> > +
> > +        if (!(s->pending[i] & s->enable[i])) {
> > +            /* No pending and enabled IRQ */
> > +            continue;
> > +        }
> > +
> > +        if (s->priority[irq_num] > s->threshold) {
> > +            if (!s->claim) {
> > +                s->claim = irq_num;
> > +            }
> > +            return true;
> > +        }
> > +    }
> > +
> > +    return 0;
>
> return 'false'.

Fixed.

>
> > +}
> > +
> > +static void ibex_plic_update(IbexPlicState *s)
> > +{
> > +    CPUState *cpu;
> > +    int level, i;
> > +
> > +    for (i = 0; i < s->num_cpus; i++) {
> > +        cpu = qemu_get_cpu(i);
> > +
> > +        if (!cpu) {
> > +            continue;
> > +        }
> > +
> > +        level = ibex_plic_irqs_pending(s, 0);
> > +
> > +        riscv_cpu_update_mip(RISCV_CPU(cpu), MIP_MEIP, BOOL_TO_MASK(level));
> > +    }
> > +}
> > +
> > +static void ibex_plic_reset(DeviceState *dev)
> > +{
> > +    IbexPlicState *s = IBEX_PLIC(dev);
> > +
> > +    s->threshold = 0x00000000;
> > +    s->claim = 0x00000000;
>
> I haven't check the datasheet reset values, for the rest:
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Thanks for reviewing these :)

Alistair


WARNING: multiple messages have this Message-ID (diff)
From: Alistair Francis <alistair23@gmail.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: Alistair Francis <alistair.francis@wdc.com>,
	 "qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
	"open list:RISC-V" <qemu-riscv@nongnu.org>,
	 Palmer Dabbelt <palmer@dabbelt.com>
Subject: Re: [PATCH v2 6/9] hw/intc: Initial commit of lowRISC Ibex PLIC
Date: Thu, 14 May 2020 14:53:07 -0700	[thread overview]
Message-ID: <CAKmqyKOhoMG+Gc1FwJBRJe1DC5TEHFBDN1pdtR-YtHLEEc3EEw@mail.gmail.com> (raw)
In-Reply-To: <50effad3-3f41-2d36-e4dd-d14c05e6ea8c@redhat.com>

On Thu, May 14, 2020 at 11:40 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> On 5/7/20 9:13 PM, Alistair Francis wrote:
> > The Ibex core contains a PLIC that although similar to the RISC-V spec
> > is not RISC-V spec compliant.
> >
> > This patch implements a Ibex PLIC in a somewhat generic way.
> >
> > As the current RISC-V PLIC needs tidying up, my hope is that as the Ibex
> > PLIC move towards spec compliance this PLIC implementation can be
> > updated until it can replace the current PLIC.
> >
> > Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> > ---
> >   MAINTAINERS                 |   2 +
> >   hw/intc/Makefile.objs       |   1 +
> >   hw/intc/ibex_plic.c         | 261 ++++++++++++++++++++++++++++++++++++
> >   include/hw/intc/ibex_plic.h |  63 +++++++++
> >   4 files changed, 327 insertions(+)
> >   create mode 100644 hw/intc/ibex_plic.c
> >   create mode 100644 include/hw/intc/ibex_plic.h
> >
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index d3d47564ce..f8c3cf6182 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -1237,8 +1237,10 @@ L: qemu-riscv@nongnu.org
> >   S: Supported
> >   F: hw/riscv/opentitan.c
> >   F: hw/char/ibex_uart.c
> > +F: hw/intc/ibex_plic.c
> >   F: include/hw/riscv/opentitan.h
> >   F: include/hw/char/ibex_uart.h
> > +F: include/hw/intc/ibex_plic.h
> >
> >
> >   SH4 Machines
> > diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs
> > index f726d87532..a61e6728fe 100644
> > --- a/hw/intc/Makefile.objs
> > +++ b/hw/intc/Makefile.objs
> > @@ -49,3 +49,4 @@ obj-$(CONFIG_ARM_GIC) += arm_gicv3_cpuif.o
> >   obj-$(CONFIG_MIPS_CPS) += mips_gic.o
> >   obj-$(CONFIG_NIOS2) += nios2_iic.o
> >   obj-$(CONFIG_OMPIC) += ompic.o
> > +obj-$(CONFIG_IBEX) += ibex_plic.o
> > diff --git a/hw/intc/ibex_plic.c b/hw/intc/ibex_plic.c
> > new file mode 100644
> > index 0000000000..35c52d9d16
> > --- /dev/null
> > +++ b/hw/intc/ibex_plic.c
> > @@ -0,0 +1,261 @@
> > +/*
> > + * QEMU RISC-V lowRISC Ibex PLIC
> > + *
> > + * Copyright (c) 2020 Western Digital
> > + *
> > + * Documentation avaliable: https://docs.opentitan.org/hw/ip/rv_plic/doc/
> > + *
> > + * This program is free software; you can redistribute it and/or modify it
> > + * under the terms and conditions of the GNU General Public License,
> > + * version 2 or later, as published by the Free Software Foundation.
> > + *
> > + * This program is distributed in the hope it will be useful, but WITHOUT
> > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> > + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> > + * more details.
> > + *
> > + * You should have received a copy of the GNU General Public License along with
> > + * this program.  If not, see <http://www.gnu.org/licenses/>.
> > + */
> > +
> > +#include "qemu/osdep.h"
> > +#include "qemu/log.h"
> > +#include "hw/qdev-properties.h"
> > +#include "hw/core/cpu.h"
> > +#include "hw/boards.h"
> > +#include "hw/pci/msi.h"
> > +#include "target/riscv/cpu_bits.h"
> > +#include "target/riscv/cpu.h"
> > +#include "hw/intc/ibex_plic.h"
> > +
> > +static bool addr_between(uint32_t addr, uint32_t base, uint32_t num)
> > +{
> > +    uint32_t end = base + (num * 0x04);
> > +
> > +    if (addr >= base && addr < end) {
> > +        return true;
> > +    }
> > +
> > +    return false;
> > +}
> > +
> > +static void ibex_plic_irqs_set_pending(IbexPlicState *s, int irq, bool level)
> > +{
> > +    int pending_num = irq / 32;
> > +
> > +    s->pending[pending_num] |= level << (irq % 32);
> > +}
> > +
> > +static bool ibex_plic_irqs_pending(IbexPlicState *s, uint32_t context)
> > +{
> > +    int i;
> > +
> > +    for (i = 0; i < s->pending_num; i++) {
> > +        uint32_t irq_num = ctz64(s->pending[i]) + (i * 32);
> > +
> > +        if (!(s->pending[i] & s->enable[i])) {
> > +            /* No pending and enabled IRQ */
> > +            continue;
> > +        }
> > +
> > +        if (s->priority[irq_num] > s->threshold) {
> > +            if (!s->claim) {
> > +                s->claim = irq_num;
> > +            }
> > +            return true;
> > +        }
> > +    }
> > +
> > +    return 0;
>
> return 'false'.

Fixed.

>
> > +}
> > +
> > +static void ibex_plic_update(IbexPlicState *s)
> > +{
> > +    CPUState *cpu;
> > +    int level, i;
> > +
> > +    for (i = 0; i < s->num_cpus; i++) {
> > +        cpu = qemu_get_cpu(i);
> > +
> > +        if (!cpu) {
> > +            continue;
> > +        }
> > +
> > +        level = ibex_plic_irqs_pending(s, 0);
> > +
> > +        riscv_cpu_update_mip(RISCV_CPU(cpu), MIP_MEIP, BOOL_TO_MASK(level));
> > +    }
> > +}
> > +
> > +static void ibex_plic_reset(DeviceState *dev)
> > +{
> > +    IbexPlicState *s = IBEX_PLIC(dev);
> > +
> > +    s->threshold = 0x00000000;
> > +    s->claim = 0x00000000;
>
> I haven't check the datasheet reset values, for the rest:
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Thanks for reviewing these :)

Alistair


  reply	other threads:[~2020-05-14 22:02 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-07 19:12 [PATCH v2 0/9] RISC-V Add the OpenTitan Machine Alistair Francis
2020-05-07 19:12 ` Alistair Francis
2020-05-07 19:13 ` [PATCH v2 1/9] riscv/boot: Add a missing header include Alistair Francis
2020-05-07 19:13   ` Alistair Francis
2020-05-14 15:33   ` Bin Meng
2020-05-14 15:33     ` Bin Meng
2020-05-14 15:30     ` Alistair Francis
2020-05-14 15:30       ` Alistair Francis
2020-05-14 15:46       ` Bin Meng
2020-05-14 15:46         ` Bin Meng
2020-05-14 17:51         ` Philippe Mathieu-Daudé
2020-05-14 17:51           ` Philippe Mathieu-Daudé
2020-05-15  5:00       ` Bin Meng
2020-05-15  5:00         ` Bin Meng
2020-05-07 19:13 ` [PATCH v2 2/9] target/riscv: Don't overwrite the reset vector Alistair Francis
2020-05-07 19:13   ` Alistair Francis
2020-05-14 17:54   ` Philippe Mathieu-Daudé
2020-05-14 17:54     ` Philippe Mathieu-Daudé
2020-05-14 21:42     ` Alistair Francis
2020-05-14 21:42       ` Alistair Francis
2020-05-15  4:54       ` Bin Meng
2020-05-15  4:54         ` Bin Meng
2020-05-15 19:43         ` Alistair Francis
2020-05-15 19:43           ` Alistair Francis
2020-05-16  9:03           ` Bin Meng
2020-05-16  9:03             ` Bin Meng
2020-05-19 18:03             ` Alistair Francis
2020-05-19 18:03               ` Alistair Francis
2020-05-07 19:13 ` [PATCH v2 3/9] target/riscv: Add the lowRISC Ibex CPU Alistair Francis
2020-05-07 19:13   ` Alistair Francis
2020-05-15  4:57   ` Bin Meng
2020-05-15  4:57     ` Bin Meng
2020-05-07 19:13 ` [PATCH v2 4/9] riscv: Initial commit of OpenTitan machine Alistair Francis
2020-05-07 19:13   ` Alistair Francis
2020-05-15  5:14   ` Bin Meng
2020-05-15  5:14     ` Bin Meng
2020-05-07 19:13 ` [PATCH v2 5/9] hw/char: Initial commit of Ibex UART Alistair Francis
2020-05-07 19:13   ` Alistair Francis
2020-05-14 17:59   ` Philippe Mathieu-Daudé
2020-05-14 17:59     ` Philippe Mathieu-Daudé
2020-05-14 21:59     ` Alistair Francis
2020-05-14 21:59       ` Alistair Francis
2020-05-15  7:25       ` Philippe Mathieu-Daudé
2020-05-15  7:25         ` Philippe Mathieu-Daudé
2020-05-15  7:28   ` Philippe Mathieu-Daudé
2020-05-15  7:28     ` Philippe Mathieu-Daudé
2020-05-15 19:46     ` Alistair Francis
2020-05-15 19:46       ` Alistair Francis
2020-05-07 19:13 ` [PATCH v2 6/9] hw/intc: Initial commit of lowRISC Ibex PLIC Alistair Francis
2020-05-07 19:13   ` Alistair Francis
2020-05-14 18:40   ` Philippe Mathieu-Daudé
2020-05-14 18:40     ` Philippe Mathieu-Daudé
2020-05-14 21:53     ` Alistair Francis [this message]
2020-05-14 21:53       ` Alistair Francis
2020-05-07 19:13 ` [PATCH v2 7/9] riscv/opentitan: Connect the PLIC device Alistair Francis
2020-05-07 19:13   ` Alistair Francis
2020-05-15  6:29   ` Bin Meng
2020-05-15  6:29     ` Bin Meng
2020-05-07 19:13 ` [PATCH v2 8/9] riscv/opentitan: Connect the UART device Alistair Francis
2020-05-07 19:13   ` Alistair Francis
2020-05-15  6:29   ` Bin Meng
2020-05-15  6:29     ` Bin Meng
2020-05-07 19:13 ` [PATCH v2 9/9] target/riscv: Use a smaller guess size for no-MMU PMP Alistair Francis
2020-05-07 19:13   ` Alistair Francis
2020-05-15  6:28   ` Bin Meng
2020-05-15  6:28     ` Bin Meng
2020-05-13 18:18 ` [PATCH v2 0/9] RISC-V Add the OpenTitan Machine Alistair Francis
2020-05-13 18:18   ` Alistair Francis

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=CAKmqyKOhoMG+Gc1FwJBRJe1DC5TEHFBDN1pdtR-YtHLEEc3EEw@mail.gmail.com \
    --to=alistair23@gmail.com \
    --cc=alistair.francis@wdc.com \
    --cc=palmer@dabbelt.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.