All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiaojuan Yang <yangxiaojuan@loongson.cn>
To: qemu-devel@nongnu.org
Cc: mark.cave-ayland@ilande.co.uk, richard.henderson@linaro.org,
	Song Gao <gaosong@loongson.cn>
Subject: [RFC PATCH v5 16/30] hw/loongarch: Add LoongArch cpu interrupt support(CPUINTC)
Date: Thu, 27 Jan 2022 22:43:58 -0500	[thread overview]
Message-ID: <20220128034412.1262452-17-yangxiaojuan@loongson.cn> (raw)
In-Reply-To: <20220128034412.1262452-1-yangxiaojuan@loongson.cn>

Loongson-3A5000 support 14 interrupts from 64 - 77(Timer->75 IPI->76)
Loongson-3A5000 and ls7a form a legacy model and extended model irq
hierarchy.Tcg mode emulate a simplified extended model which
has no Legacy I/O Interrupt Controller(LIOINTC) and LPC.
e.g:

 |    +-----+    +---------+     +-------+             |
 |    | IPI |--> | CPUINTC | <-- | Timer |             |
 |    +-----+    +---------+     +-------+             |
 |                    ^                                |
 |                    |                                |
 |               +---------+
 |               | EIOINTC |
 |               +---------+
 |                ^       ^                            |
 |                |       |                            |
 |         +---------+ +---------+                     |
 |         | PCH-PIC | | PCH-MSI |                     |
 |         +---------+ +---------+                     |
 |           ^     ^           ^                       |
 |           |     |           |                       |
 |   +---------+ +---------+ +---------+               |
 |   | UARTs | | Devices | | Devices |                 |
 |   +---------+ +---------+ +---------+               |
 |        ^                                            |

The following series patch will realize the interrupt
controller in this model.

More detailed info can be found at the kernel doc or manual
1.https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/
linux-loongson.git/tree/Documentation/loongarch?h=loongarch-next
2.https://github.com/loongson/LoongArch-Documentation

Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 hw/loongarch/loongson3.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/hw/loongarch/loongson3.c b/hw/loongarch/loongson3.c
index 83c464899b..e79d86928d 100644
--- a/hw/loongarch/loongson3.c
+++ b/hw/loongarch/loongson3.c
@@ -64,6 +64,29 @@ static const MemoryRegionOps loongarch_qemu_ops = {
     },
 };
 
+static void loongarch_cpu_set_irq(void *opaque, int irq, int level)
+{
+    LoongArchCPU *cpu = opaque;
+    CPULoongArchState *env = &cpu->env;
+    CPUState *cs = CPU(cpu);
+
+    if (irq < 0 || irq > N_IRQS) {
+        return;
+    }
+
+    if (level) {
+        env->CSR_ESTAT |= 1 << irq;
+    } else {
+        env->CSR_ESTAT &= ~(1 << irq);
+    }
+
+    if (FIELD_EX64(env->CSR_ESTAT, CSR_ESTAT, IS)) {
+        cpu_interrupt(cs, CPU_INTERRUPT_HARD);
+    } else {
+        cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
+    }
+}
+
 static void loongarch_init(MachineState *machine)
 {
     const char *cpu_model = machine->cpu_type;
@@ -88,6 +111,9 @@ static void loongarch_init(MachineState *machine)
     /* Init CPUs */
     for (i = 0; i < machine->smp.cpus; i++) {
         la_cpu = LOONGARCH_CPU(cpu_create(machine->cpu_type));
+        timer_init_ns(&la_cpu->timer, QEMU_CLOCK_VIRTUAL,
+                      &loongarch_constant_timer_cb, la_cpu);
+        qdev_init_gpio_in(DEVICE(la_cpu), loongarch_cpu_set_irq, N_IRQS);
 
         timer_init_ns(&la_cpu->timer, QEMU_CLOCK_VIRTUAL,
                       &loongarch_constant_timer_cb, la_cpu);
-- 
2.27.0



  parent reply	other threads:[~2022-01-28  4:11 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-28  3:43 [RFC PATCH v5 00/30] Add LoongArch softmmu support Xiaojuan Yang
2022-01-28  3:43 ` [RFC PATCH v5 01/30] target/loongarch: Add system emulation introduction Xiaojuan Yang
2022-02-05 13:24   ` Mark Cave-Ayland
2022-01-28  3:43 ` [RFC PATCH v5 02/30] target/loongarch: Add CSRs definition Xiaojuan Yang
2022-01-28  3:43 ` [RFC PATCH v5 03/30] target/loongarch: Add basic vmstate description of CPU Xiaojuan Yang
2022-01-28  3:43 ` [RFC PATCH v5 04/30] target/loongarch: Implement qmp_query_cpu_definitions() Xiaojuan Yang
2022-01-28  3:43 ` [RFC PATCH v5 05/30] target/loongarch: Add constant timer support Xiaojuan Yang
2022-01-28  3:43 ` [RFC PATCH v5 06/30] target/loongarch: Add MMU support for LoongArch CPU Xiaojuan Yang
2022-01-28  3:43 ` [RFC PATCH v5 07/30] target/loongarch: Add LoongArch CSR instruction Xiaojuan Yang
2022-01-28  3:43 ` [RFC PATCH v5 08/30] target/loongarch: Add LoongArch IOCSR instruction Xiaojuan Yang
2022-02-05 12:06   ` Mark Cave-Ayland
2022-01-28  3:43 ` [RFC PATCH v5 09/30] target/loongarch: Add TLB instruction support Xiaojuan Yang
2022-01-28  3:43 ` [RFC PATCH v5 10/30] target/loongarch: Add other core instructions support Xiaojuan Yang
2022-01-28  3:43 ` [RFC PATCH v5 11/30] target/loongarch: Add LoongArch interrupt and exception handle Xiaojuan Yang
2022-01-28  3:43 ` [RFC PATCH v5 12/30] target/loongarch: Add timer related instructions support Xiaojuan Yang
2022-01-28  3:43 ` [RFC PATCH v5 13/30] target/loongarch: Add gdb support Xiaojuan Yang
2022-01-28  3:43 ` [RFC PATCH v5 14/30] hw/pci-host: Add ls7a1000 PCIe Host bridge support for Loongson3 Platform Xiaojuan Yang
2022-01-28  3:43 ` [RFC PATCH v5 15/30] hw/loongarch: Add support loongson3-ls7a machine type Xiaojuan Yang
2022-01-28  3:43 ` Xiaojuan Yang [this message]
2022-02-05 12:13   ` [RFC PATCH v5 16/30] hw/loongarch: Add LoongArch cpu interrupt support(CPUINTC) Mark Cave-Ayland
2022-01-28  3:43 ` [RFC PATCH v5 17/30] hw/loongarch: Add LoongArch ipi interrupt support(IPI) Xiaojuan Yang
2022-02-05 12:22   ` Mark Cave-Ayland
2022-01-28  3:44 ` [RFC PATCH v5 18/30] hw/intc: Add LoongArch ls7a interrupt controller support(PCH-PIC) Xiaojuan Yang
2022-01-28  3:44 ` [RFC PATCH v5 19/30] hw/intc: Add LoongArch ls7a msi interrupt controller support(PCH-MSI) Xiaojuan Yang
2022-01-28  3:44 ` [RFC PATCH v5 20/30] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC) Xiaojuan Yang
2022-02-05 13:08   ` Mark Cave-Ayland
2022-01-28  3:44 ` [RFC PATCH v5 21/30] hw/loongarch: Add irq hierarchy for the system Xiaojuan Yang
2022-02-05 13:16   ` Mark Cave-Ayland
2022-01-28  3:44 ` [RFC PATCH v5 22/30] Enable common virtio pci support for LoongArch Xiaojuan Yang
2022-01-28  3:44 ` [RFC PATCH v5 23/30] hw/loongarch: Add some devices support for 3A5000 Xiaojuan Yang
2022-02-05 13:20   ` Mark Cave-Ayland
2022-01-28  3:44 ` [RFC PATCH v5 24/30] hw/loongarch: Add LoongArch ls7a rtc device support Xiaojuan Yang
2022-01-28  3:44 ` [RFC PATCH v5 25/30] hw/loongarch: Add default bios startup support Xiaojuan Yang
2022-01-28  3:44 ` [RFC PATCH v5 26/30] hw/loongarch: Add -kernel and -initrd options support Xiaojuan Yang
2022-01-28  3:44 ` [RFC PATCH v5 27/30] hw/loongarch: Add LoongArch smbios support Xiaojuan Yang
2022-01-28  3:44 ` [RFC PATCH v5 28/30] hw/loongarch: Add LoongArch acpi support Xiaojuan Yang
2022-01-28  3:44 ` [RFC PATCH v5 29/30] hw/loongarch: Add fdt support Xiaojuan Yang
2022-01-28  3:44 ` [RFC PATCH v5 30/30] tests/tcg/loongarch64: Add hello/memory test in loongarch64 system Xiaojuan Yang

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=20220128034412.1262452-17-yangxiaojuan@loongson.cn \
    --to=yangxiaojuan@loongson.cn \
    --cc=gaosong@loongson.cn \
    --cc=mark.cave-ayland@ilande.co.uk \
    --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 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.