All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: Amir Gonnen <amir.gonnen@neuroblade.ai>,
	Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Subject: [PULL 66/68] hw/nios2: Machine with a Vectored Interrupt Controller
Date: Tue, 26 Apr 2022 11:19:05 -0700	[thread overview]
Message-ID: <20220426181907.103691-67-richard.henderson@linaro.org> (raw)
In-Reply-To: <20220426181907.103691-1-richard.henderson@linaro.org>

From: Amir Gonnen <amir.gonnen@neuroblade.ai>

Demonstrate how to use nios2 VIC on a machine.
Introduce a new machine property to attach a VIC.

When VIC is present, let the CPU know that it should use the
External Interrupt Interface instead of the Internal Interrupt Interface.
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.

[rth: Put a property on the 10m50-ghrd machine, rather than
      create a new machine class.]

Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Amir Gonnen <amir.gonnen@neuroblade.ai>
Message-Id: <20220303153906.2024748-6-amir.gonnen@neuroblade.ai>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20220421151735.31996-63-richard.henderson@linaro.org>
---
 hw/nios2/10m50_devboard.c | 61 +++++++++++++++++++++++++++++++++------
 hw/nios2/Kconfig          |  1 +
 2 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c
index dda4ab2bf5..91383fb097 100644
--- a/hw/nios2/10m50_devboard.c
+++ b/hw/nios2/10m50_devboard.c
@@ -27,6 +27,7 @@
 
 #include "hw/sysbus.h"
 #include "hw/char/serial.h"
+#include "hw/intc/nios2_vic.h"
 #include "hw/qdev-properties.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
@@ -43,6 +44,8 @@ struct Nios2MachineState {
     MemoryRegion phys_tcm_alias;
     MemoryRegion phys_ram;
     MemoryRegion phys_ram_alias;
+
+    bool vic;
 };
 
 #define TYPE_NIOS2_MACHINE  MACHINE_TYPE_NAME("10m50-ghrd")
@@ -81,10 +84,39 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
     memory_region_add_subregion(address_space_mem, 0xc0000000 + ram_base,
                                 &nms->phys_ram_alias);
 
-    /* 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);
+    /* Create CPU.  We need to set eic_present between init and realize. */
+    cpu = NIOS2_CPU(object_new(TYPE_NIOS2_CPU));
+
+    /* Enable the External Interrupt Controller within the CPU. */
+    cpu->eic_present = nms->vic;
+
+    /* Configure new exception vectors. */
+    cpu->reset_addr = 0xd4000000;
+    cpu->exception_addr = 0xc8000120;
+    cpu->fast_tlb_miss_addr = 0xc0000100;
+
+    qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal);
+
+    if (nms->vic) {
+        DeviceState *dev = qdev_new(TYPE_NIOS2_VIC);
+        MemoryRegion *dev_mr;
+        qemu_irq cpu_irq;
+
+        object_property_set_link(OBJECT(dev), "cpu", OBJECT(cpu), &error_fatal);
+        sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+
+        cpu_irq = qdev_get_gpio_in_named(DEVICE(cpu), "EIC", 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);
+        }
+
+        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,15 +137,22 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0xe0000880);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[5]);
 
-    /* Configure new exception vectors and reset CPU for it to take effect. */
-    cpu->reset_addr = 0xd4000000;
-    cpu->exception_addr = 0xc8000120;
-    cpu->fast_tlb_miss_addr = 0xc0000100;
-
     nios2_load_kernel(cpu, ram_base, ram_size, machine->initrd_filename,
                       BINARY_DEVICE_TREE_FILE, NULL);
 }
 
+static bool get_vic(Object *obj, Error **errp)
+{
+    Nios2MachineState *nms = NIOS2_MACHINE(obj);
+    return nms->vic;
+}
+
+static void set_vic(Object *obj, bool value, Error **errp)
+{
+    Nios2MachineState *nms = NIOS2_MACHINE(obj);
+    nms->vic = value;
+}
+
 static void nios2_10m50_ghrd_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -121,6 +160,10 @@ static void nios2_10m50_ghrd_class_init(ObjectClass *oc, void *data)
     mc->desc = "Altera 10M50 GHRD Nios II design";
     mc->init = nios2_10m50_ghrd_init;
     mc->is_default = true;
+
+    object_class_property_add_bool(oc, "vic", get_vic, set_vic);
+    object_class_property_set_description(oc, "vic",
+        "Set on/off to enable/disable the Vectored Interrupt Controller");
 }
 
 static const TypeInfo nios2_10m50_ghrd_type_info = {
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.34.1



  parent reply	other threads:[~2022-04-26 19:31 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-26 18:17 [PULL 00/68] nios2 patch queue Richard Henderson
2022-04-26 18:18 ` [PULL 01/68] linux-user/nios2: Hoist pc advance to the top of EXCP_TRAP Richard Henderson
2022-04-26 18:18 ` [PULL 02/68] linux-user/nios2: Fix clone child return Richard Henderson
2022-04-26 18:18 ` [PULL 03/68] linux-user/nios2: Drop syscall 0 "workaround" Richard Henderson
2022-04-26 18:18 ` [PULL 04/68] linux-user/nios2: Adjust error return Richard Henderson
2022-04-26 18:18 ` [PULL 05/68] linux-user/nios2: Handle special qemu syscall return values Richard Henderson
2022-04-26 18:18 ` [PULL 06/68] linux-user/nios2: Remove do_sigreturn Richard Henderson
2022-04-26 18:18 ` [PULL 07/68] linux-user/nios2: Use QEMU_ESIGRETURN from do_rt_sigreturn Richard Henderson
2022-04-26 18:18 ` [PULL 08/68] tests/tcg/nios2: Re-enable linux-user tests Richard Henderson
2022-04-26 18:18 ` [PULL 09/68] target/nios2: Remove user-only nios2_cpu_do_interrupt Richard Henderson
2022-04-26 18:18 ` [PULL 10/68] target/nios2: Remove nios2_cpu_record_sigsegv Richard Henderson
2022-04-26 18:18 ` [PULL 11/68] target/nios2: Build helper.c for system only Richard Henderson
2022-04-26 18:18 ` [PULL 12/68] linux-user/nios2: Use force_sig_fault for EXCP_DEBUG Richard Henderson
2022-04-26 18:18 ` [PULL 13/68] target/nios2: Check supervisor on eret Richard Henderson
2022-04-26 18:18 ` [PULL 14/68] target/nios2: Stop generating code if gen_check_supervisor fails Richard Henderson
2022-04-26 18:18 ` [PULL 15/68] target/nios2: Add NUM_GP_REGS and NUM_CP_REGS Richard Henderson
2022-04-26 18:18 ` [PULL 16/68] target/nios2: Split PC out of env->regs[] Richard Henderson
2022-04-26 18:18 ` [PULL 17/68] target/nios2: Split out helper for eret instruction Richard Henderson
2022-04-26 18:18 ` [PULL 18/68] target/nios2: Fix BRET instruction Richard Henderson
2022-04-26 18:18 ` [PULL 19/68] target/nios2: Do not create TCGv for control registers Richard Henderson
2022-04-26 18:18 ` [PULL 20/68] linux-user/nios2: Only initialize SP and PC in target_cpu_copy_regs Richard Henderson
2022-04-26 18:18 ` [PULL 21/68] target/nios2: Remove cpu_interrupts_enabled Richard Henderson
2022-04-26 18:18 ` [PULL 22/68] target/nios2: Split control registers away from general registers Richard Henderson
2022-04-26 18:18 ` [PULL 23/68] target/nios2: Clean up nios2_cpu_dump_state Richard Henderson
2022-04-26 18:18 ` [PULL 24/68] target/nios2: Use hw/registerfields.h for CR_STATUS fields Richard Henderson
2022-04-26 18:18 ` [PULL 25/68] target/nios2: Use hw/registerfields.h for CR_EXCEPTION fields Richard Henderson
2022-04-26 18:18 ` [PULL 26/68] target/nios2: Use hw/registerfields.h for CR_TLBADDR fields Richard Henderson
2022-04-26 18:18 ` [PULL 27/68] target/nios2: Use hw/registerfields.h for CR_TLBACC fields Richard Henderson
2022-04-26 18:18 ` [PULL 28/68] target/nios2: Rename CR_TLBMISC_WR to CR_TLBMISC_WE Richard Henderson
2022-04-26 18:18 ` [PULL 29/68] target/nios2: Use hw/registerfields.h for CR_TLBMISC fields Richard Henderson
2022-04-26 18:18 ` [PULL 30/68] target/nios2: Move R_FOO and CR_BAR into enumerations Richard Henderson
2022-04-26 18:18 ` [PULL 31/68] target/nios2: Create EXCP_SEMIHOST for semi-hosting Richard Henderson
2022-04-26 18:18 ` [PULL 32/68] target/nios2: Clean up nios2_cpu_do_interrupt Richard Henderson
2022-04-26 18:18 ` [PULL 33/68] target/nios2: Hoist CPU_LOG_INT logging Richard Henderson
2022-04-26 18:18 ` [PULL 34/68] target/nios2: Handle EXCP_UNALIGN and EXCP_UNALIGND Richard Henderson
2022-04-26 18:18 ` [PULL 35/68] target/nios2: Cleanup set of CR_EXCEPTION for do_interrupt Richard Henderson
2022-04-26 18:18 ` [PULL 36/68] target/nios2: Clean up handling of tlbmisc in do_exception Richard Henderson
2022-04-26 18:18 ` [PULL 37/68] target/nios2: Prevent writes to read-only or reserved control fields Richard Henderson
2022-04-26 18:18 ` [PULL 38/68] target/nios2: Implement cpuid Richard Henderson
2022-04-26 18:18 ` [PULL 39/68] target/nios2: Implement CR_STATUS.RSIE Richard Henderson
2022-04-26 18:18 ` [PULL 40/68] target/nios2: Remove CPU_INTERRUPT_NMI Richard Henderson
2022-04-26 18:18 ` [PULL 41/68] target/nios2: Support division error exception Richard Henderson
2022-04-26 18:18 ` [PULL 42/68] target/nios2: Use tcg_constant_tl Richard Henderson
2022-04-26 18:18 ` [PULL 43/68] target/nios2: Split out named structs for [IRJ]_TYPE Richard Henderson
2022-04-26 18:18 ` [PULL 44/68] target/nios2: Split out helpers for gen_i_cmpxx Richard Henderson
2022-04-26 18:18 ` [PULL 45/68] target/nios2: Split out helpers for gen_i_math_logic Richard Henderson
2022-04-26 18:18 ` [PULL 46/68] target/nios2: Split out helpers for gen_r_math_logic Richard Henderson
2022-04-26 18:18 ` [PULL 47/68] target/nios2: Split out helpers for gen_rr_mul_high Richard Henderson
2022-04-26 18:18 ` [PULL 48/68] target/nios2: Split out helpers for gen_rr_shift Richard Henderson
2022-04-26 18:18 ` [PULL 49/68] target/nios2: Introduce dest_gpr Richard Henderson
2022-04-26 18:18 ` [PULL 50/68] target/nios2: Drop CR_STATUS_EH from tb->flags Richard Henderson
2022-04-26 18:18 ` [PULL 51/68] target/nios2: Enable unaligned traps for system mode Richard Henderson
2022-04-26 18:18 ` [PULL 52/68] target/nios2: Create gen_jumpr Richard Henderson
2022-04-26 18:18 ` [PULL 53/68] target/nios2: Hoist set of is_jmp into gen_goto_tb Richard Henderson
2022-04-26 18:18 ` [PULL 54/68] target/nios2: Use gen_goto_tb for DISAS_TOO_MANY Richard Henderson
2022-04-26 18:18 ` [PULL 55/68] target/nios2: Use tcg_gen_lookup_and_goto_ptr Richard Henderson
2022-04-26 18:18 ` [PULL 56/68] target/nios2: Implement Misaligned destination exception Richard Henderson
2022-04-26 18:18 ` [PULL 57/68] target/nios2: Introduce shadow register sets Richard Henderson
2022-04-26 18:18 ` [PULL 58/68] target/nios2: Implement rdprs, wrprs Richard Henderson
2022-04-26 18:18 ` [PULL 59/68] target/nios2: Update helper_eret for shadow registers Richard Henderson
2022-04-26 18:18 ` [PULL 60/68] target/nios2: Implement EIC interrupt processing Richard Henderson
2022-04-26 18:19 ` [PULL 61/68] target/nios2: Advance pc when raising exceptions Richard Henderson
2022-04-26 18:19 ` [PULL 62/68] linux-user/nios2: Handle various SIGILL exceptions Richard Henderson
2022-04-26 18:19 ` [PULL 63/68] hw/intc: Vectored Interrupt Controller (VIC) Richard Henderson
2022-04-26 18:19 ` [PULL 64/68] hw/nios2: Introduce Nios2MachineState Richard Henderson
2022-04-26 18:19 ` [PULL 65/68] hw/nios2: Move memory regions into Nios2Machine Richard Henderson
2022-04-26 18:19 ` Richard Henderson [this message]
2022-04-26 18:19 ` [PULL 67/68] tests/tcg/nios2: Add semihosting multiarch tests Richard Henderson
2022-04-26 18:19 ` [PULL 68/68] tests/tcg/nios2: Add test-shadow-1 Richard Henderson
2022-04-26 21:38 ` [PULL 00/68] nios2 patch queue Richard Henderson

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=20220426181907.103691-67-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=amir.gonnen@neuroblade.ai \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=qemu-devel@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.