From: Amir Gonnen <amir.gonnen@neuroblade.ai>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>,
Chris Wulff <crwulff@gmail.com>, Marek Vasut <marex@denx.de>,
Richard Henderson <richard.henderson@linaro.org>
Cc: Amir Gonnen <amir.gonnen@neuroblade.ai>
Subject: [PATCH v3 5/5] hw/nios2: Machine with a Vectored Interrupt Controller
Date: Thu, 3 Mar 2022 17:39:06 +0200 [thread overview]
Message-ID: <20220303153906.2024748-6-amir.gonnen@neuroblade.ai> (raw)
In-Reply-To: <20220303153906.2024748-1-amir.gonnen@neuroblade.ai>
Demonstrate how to use nios2 VIC on a machine.
Introduce a new machine "10m50-ghrd-vic" which is based on "10m50-ghrd"
with a VIC attached and internal interrupt controller removed.
When VIC is present, irq0 connects the VIC to the cpu, intc_present
is set to false to disable the internal interrupt controller, and the
devices on the machine are attached to the VIC (and not directly to cpu).
To allow VIC update EIC fields, we set the "cpu" property of the VIC
with a reference to the nios2 cpu.
Signed-off-by: Amir Gonnen <amir.gonnen@neuroblade.ai>
---
hw/nios2/10m50_devboard.c | 64 ++++++++++++++++++++++++++++++++++++---
hw/nios2/Kconfig | 1 +
2 files changed, 61 insertions(+), 4 deletions(-)
diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c
index 3d1205b8bd..9f62a2993f 100644
--- a/hw/nios2/10m50_devboard.c
+++ b/hw/nios2/10m50_devboard.c
@@ -36,10 +36,23 @@
#include "boot.h"
+#define TYPE_NIOS2_MACHINE MACHINE_TYPE_NAME("10m50-ghrd")
+typedef struct Nios2MachineClass Nios2MachineClass;
+DECLARE_OBJ_CHECKERS(MachineState, Nios2MachineClass,
+ NIOS2_MACHINE, TYPE_NIOS2_MACHINE)
+
#define BINARY_DEVICE_TREE_FILE "10m50-devboard.dtb"
+struct Nios2MachineClass {
+ MachineClass parent_obj;
+
+ bool vic;
+};
+
static void nios2_10m50_ghrd_init(MachineState *machine)
{
+ Nios2MachineClass *nmc = NIOS2_MACHINE_GET_CLASS(machine);
+
Nios2CPU *cpu;
DeviceState *dev;
MemoryRegion *address_space_mem = get_system_memory();
@@ -74,8 +87,24 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
/* Create CPU -- FIXME */
cpu = NIOS2_CPU(cpu_create(TYPE_NIOS2_CPU));
- for (i = 0; i < 32; i++) {
- irq[i] = qdev_get_gpio_in_named(DEVICE(cpu), "IRQ", i);
+
+ if (nmc->vic) {
+ DeviceState *dev = qdev_new("nios2-vic");
+
+ object_property_set_link(OBJECT(dev), "cpu", OBJECT(cpu), &error_fatal);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+ cpu->intc_present = false;
+ qemu_irq cpu_irq = qdev_get_gpio_in_named(DEVICE(cpu), "IRQ", 0);
+ sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, cpu_irq);
+ for (int i = 0; i < 32; i++) {
+ irq[i] = qdev_get_gpio_in(dev, i);
+ }
+ MemoryRegion *dev_mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0);
+ memory_region_add_subregion(address_space_mem, 0x18002000, dev_mr);
+ } else {
+ for (i = 0; i < 32; i++) {
+ irq[i] = qdev_get_gpio_in_named(DEVICE(cpu), "IRQ", i);
+ }
}
/* Register: Altera 16550 UART */
@@ -105,11 +134,38 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
BINARY_DEVICE_TREE_FILE, NULL);
}
-static void nios2_10m50_ghrd_machine_init(struct MachineClass *mc)
+static void nios2_10m50_ghrd_machine_class_init(ObjectClass *oc, void *data)
{
+ MachineClass *mc = MACHINE_CLASS(oc);
+ Nios2MachineClass *nmc = NIOS2_MACHINE_CLASS(oc);
mc->desc = "Altera 10M50 GHRD Nios II design";
mc->init = nios2_10m50_ghrd_init;
mc->is_default = true;
+ nmc->vic = false;
}
-DEFINE_MACHINE("10m50-ghrd", nios2_10m50_ghrd_machine_init);
+static void nios2_10m50_ghrd_vic_machine_class_init(ObjectClass *oc, void *data)
+{
+ MachineClass *mc = MACHINE_CLASS(oc);
+ Nios2MachineClass *nmc = NIOS2_MACHINE_CLASS(oc);
+ mc->desc = "Altera 10M50 GHRD Nios II design with VIC";
+ mc->init = nios2_10m50_ghrd_init;
+ mc->is_default = false;
+ nmc->vic = true;
+}
+
+static const TypeInfo nios_machine_types[] = {
+ {
+ .name = MACHINE_TYPE_NAME("10m50-ghrd"),
+ .parent = TYPE_MACHINE,
+ .class_size = sizeof(Nios2MachineClass),
+ .class_init = nios2_10m50_ghrd_machine_class_init,
+ }, {
+ .name = MACHINE_TYPE_NAME("10m50-ghrd-vic"),
+ .parent = TYPE_MACHINE,
+ .class_size = sizeof(Nios2MachineClass),
+ .class_init = nios2_10m50_ghrd_vic_machine_class_init,
+ }
+};
+
+DEFINE_TYPES(nios_machine_types)
diff --git a/hw/nios2/Kconfig b/hw/nios2/Kconfig
index b10ea640da..4748ae27b6 100644
--- a/hw/nios2/Kconfig
+++ b/hw/nios2/Kconfig
@@ -3,6 +3,7 @@ config NIOS2_10M50
select NIOS2
select SERIAL
select ALTERA_TIMER
+ select NIOS2_VIC
config NIOS2_GENERIC_NOMMU
bool
--
2.25.1
next prev parent reply other threads:[~2022-03-03 16:11 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-03 15:39 [PATCH v3 0/5] target/nios2: Shadow register set, EIC and VIC Amir Gonnen
2022-03-03 15:39 ` [PATCH v3 1/5] target/nios2: Check supervisor on eret Amir Gonnen
2022-03-04 12:57 ` Peter Maydell
2022-03-04 20:58 ` Richard Henderson
2022-03-03 15:39 ` [PATCH v3 2/5] target/nios2: Shadow register set Amir Gonnen
2022-03-04 21:45 ` Richard Henderson
2022-03-03 15:39 ` [PATCH v3 3/5] target/nios2: Exteral Interrupt Controller (EIC) Amir Gonnen
2022-03-04 22:25 ` Richard Henderson
2022-03-03 15:39 ` [PATCH v3 4/5] hw/intc: Vectored Interrupt Controller (VIC) Amir Gonnen
2022-03-04 12:55 ` Peter Maydell
2022-03-03 15:39 ` Amir Gonnen [this message]
2022-03-04 12:58 ` [PATCH v3 5/5] hw/nios2: Machine with a Vectored Interrupt Controller Peter Maydell
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=20220303153906.2024748-6-amir.gonnen@neuroblade.ai \
--to=amir.gonnen@neuroblade.ai \
--cc=crwulff@gmail.com \
--cc=marex@denx.de \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).