From patchwork Mon Jun 6 23:14:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 579279 Delivered-To: patch@linaro.org Received: by 2002:a5d:6706:0:0:0:0:0 with SMTP id o6csp3066830wru; Mon, 6 Jun 2022 16:47:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUOvE6+zn2hGptADFpZ9KvRC4E9uK3zuRB8zngpgZhrsYJ7hVliaj8cnir7YD2oc1TWzc6 X-Received: by 2002:a05:6214:2a89:b0:464:b97d:b686 with SMTP id jr9-20020a0562142a8900b00464b97db686mr22092566qvb.65.1654559258475; Mon, 06 Jun 2022 16:47:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654559258; cv=none; d=google.com; s=arc-20160816; b=GJ5v4dT1GOmmmExKODxBhtf5Fxw7FiDpq1bcswxCOLgCNNgfVNqvH7jwZDmVV1tGSh +D9tnetWIY6/X9DYk90Qa70gm3QQSYrXb1//CI9X+6hBr1L0UVhBEBC4xRCpGXZBaofC MZhrzBnqDESFhM4w8w33mlXEbQ54Wd8fBWXn1P7qW6fmIQG6WhBlJ21cYpjABKrkbcXn j+UYbAjMFk6QIAWt1Q2+FVSzl8i6ryWsucKTYXgsNQs5rWzUme8ARn5dGc6+wIa7MUb9 AIp5i13rW0geJ98CDgXvUAtDaTHcYkUDHKA/K7MYvKBvfsdsz+g7kZXla7NTKOEukqVT KAPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gmzoDobHUlo4eBCpJn9QL/bMJx0ITvLegs/aBds/jhw=; b=lzvzQgbnpMMKwBUAcE+CYFu+ZqpwB7GEHk49DhjzcNNXrlg6EuAdC/X+aeQLUSaRIm aSK4wh+mcCzHzdzDTbWipul1Z9jnyuTVhDP4IFfRV8itQOgx9f6rii6H28JzW5hIMgNV E/K8uEiDX4wRoUx04P2auJF3+Qn4EDypOtxxRmUwbAJpIWPUNLTcdT9yO+wgVLMn9aZq Co3K58IkDpln8MXEC7pYBXYC8xPGAu6dVNaqv4vYQekqxjcZY/hlXoLPPCOamA6oL0zr OV/Ft4ZCcFrCvJ1buPrzu03GVT0KSwMKCiV+J9ZHpRSOeNtisUJqls8GJBfFeJFEuPW+ iBxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kFeNjrP2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b3-20020a05622a020300b00304dac6aa87si6770843qtx.20.2022.06.06.16.47.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Jun 2022 16:47:38 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kFeNjrP2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyMRe-0002LI-0O for patch@linaro.org; Mon, 06 Jun 2022 19:47:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyLwW-0001lb-1v for qemu-devel@nongnu.org; Mon, 06 Jun 2022 19:15:32 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:34812) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyLwU-00042w-7n for qemu-devel@nongnu.org; Mon, 06 Jun 2022 19:15:27 -0400 Received: by mail-pf1-x435.google.com with SMTP id c196so13949697pfb.1 for ; Mon, 06 Jun 2022 16:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gmzoDobHUlo4eBCpJn9QL/bMJx0ITvLegs/aBds/jhw=; b=kFeNjrP22iqKS3WA0IQOfCZ4xh31WvZwCM3/RypA49M3x54vuah1mMbXOAObM+G+To hPT+hzrM1XQdD8Zx96eKcg2M01A7WRQSMHTVXWQEiTK8hio6BlwpK7BuvE2nVcdI55aW ++4eElKic8RLmqmgKjfJJsFu+LwIGpFiy4RB2FxXUXS53BIicvUa9R0OortBlFWK8hF9 XkgO9E3oLKmLaaygjkxOBxUnMQ1YYUaR/4IJwgp0EerLiI04yoIx1HWw1DVgub2X2KCw UEjJN0dEnE4PnEEpGc2NXh1SI79MUfDas9ssdnzY5Tbo1fhTsuhzuwQ5hNjMnwaMAvre vg7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gmzoDobHUlo4eBCpJn9QL/bMJx0ITvLegs/aBds/jhw=; b=VesD1PFg2iUQS1z9oSLmcSbGE8K5Bh4qBtqUGKZGF+IM7XKvu9OKJQNgt+oIzBsXJn fUaadQXSR1OZuqvqxIU8jgCX6DkkVvTr/B/DCaWlMkcR7oEIBt7cF8P9fg48qTTEyPCi cyziGLTQgERbReZqmthNtK6C374NQyr+nY9TWj4RFwN+h3tfJb6B/7cgiEhjgrc1TUZp 8FOaC0/RoQ7dUupUe64up5VXkxVb7OJRTrh/NmWCqrzpS4mIqmiqFYi8XHSGvb1/GN5a DiGhHR4RM2EX7K72QGPNdyVKlNeRruG2fmcyO5lYHbrugFjj7IQiNiXuEYN4ulqFv00Z n7NA== X-Gm-Message-State: AOAM530LgEvdoh27fifi0UHUkS1T34/6Ze+dbbmd52ECxav4JaCty3qO iZi9fd0Phx/lABwpTr3e2ZEqcvM+Vz4O9w== X-Received: by 2002:a63:4418:0:b0:3fd:af26:a795 with SMTP id r24-20020a634418000000b003fdaf26a795mr7372058pga.331.1654557324862; Mon, 06 Jun 2022 16:15:24 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:dd1c:9738:3e40:ffe0]) by smtp.gmail.com with ESMTPSA id 2-20020a170902c24200b00162523fdb8fsm10954623plg.252.2022.06.06.16.15.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 16:15:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =gaosong@loongson.cn, yangxiaojuan@loongson.cn, Song Gao Subject: [PULL 35/43] hw/loongarch: Add irq hierarchy for the system Date: Mon, 6 Jun 2022 16:14:42 -0700 Message-Id: <20220606231450.448443-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220606231450.448443-1-richard.henderson@linaro.org> References: <20220606231450.448443-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Xiaojuan Yang This patch add the irq hierarchy for the virt board. Signed-off-by: Xiaojuan Yang Signed-off-by: Song Gao Reviewed-by: Richard Henderson Message-Id: <20220606124333.2060567-36-yangxiaojuan@loongson.cn> Signed-off-by: Richard Henderson --- hw/loongarch/loongson3.c | 104 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/hw/loongarch/loongson3.c b/hw/loongarch/loongson3.c index 7df32f777e..7a5c61e2df 100644 --- a/hw/loongarch/loongson3.c +++ b/hw/loongarch/loongson3.c @@ -16,8 +16,110 @@ #include "sysemu/rtc.h" #include "hw/loongarch/virt.h" #include "exec/address-spaces.h" +#include "hw/intc/loongarch_ipi.h" +#include "hw/intc/loongarch_extioi.h" +#include "hw/intc/loongarch_pch_pic.h" +#include "hw/intc/loongarch_pch_msi.h" +#include "hw/pci-host/ls7a.h" + #include "target/loongarch/cpu.h" +static void loongarch_irq_init(LoongArchMachineState *lams) +{ + MachineState *ms = MACHINE(lams); + DeviceState *pch_pic, *pch_msi, *cpudev; + DeviceState *ipi, *extioi; + SysBusDevice *d; + LoongArchCPU *lacpu; + CPULoongArchState *env; + CPUState *cpu_state; + int cpu, pin, i; + + ipi = qdev_new(TYPE_LOONGARCH_IPI); + sysbus_realize_and_unref(SYS_BUS_DEVICE(ipi), &error_fatal); + + extioi = qdev_new(TYPE_LOONGARCH_EXTIOI); + sysbus_realize_and_unref(SYS_BUS_DEVICE(extioi), &error_fatal); + + /* + * The connection of interrupts: + * +-----+ +---------+ +-------+ + * | IPI |--> | CPUINTC | <-- | Timer | + * +-----+ +---------+ +-------+ + * ^ + * | + * +---------+ + * | EIOINTC | + * +---------+ + * ^ ^ + * | | + * +---------+ +---------+ + * | PCH-PIC | | PCH-MSI | + * +---------+ +---------+ + * ^ ^ ^ + * | | | + * +--------+ +---------+ +---------+ + * | UARTs | | Devices | | Devices | + * +--------+ +---------+ +---------+ + */ + for (cpu = 0; cpu < ms->smp.cpus; cpu++) { + cpu_state = qemu_get_cpu(cpu); + cpudev = DEVICE(cpu_state); + lacpu = LOONGARCH_CPU(cpu_state); + env = &(lacpu->env); + + /* connect ipi irq to cpu irq */ + qdev_connect_gpio_out(ipi, cpu, qdev_get_gpio_in(cpudev, IRQ_IPI)); + /* IPI iocsr memory region */ + memory_region_add_subregion(&env->system_iocsr, SMP_IPI_MAILBOX, + sysbus_mmio_get_region(SYS_BUS_DEVICE(ipi), + cpu)); + /* extioi iocsr memory region */ + memory_region_add_subregion(&env->system_iocsr, APIC_BASE, + sysbus_mmio_get_region(SYS_BUS_DEVICE(extioi), + cpu)); + } + + /* + * connect ext irq to the cpu irq + * cpu_pin[9:2] <= intc_pin[7:0] + */ + for (cpu = 0; cpu < ms->smp.cpus; cpu++) { + cpudev = DEVICE(qemu_get_cpu(cpu)); + for (pin = 0; pin < LS3A_INTC_IP; pin++) { + qdev_connect_gpio_out(extioi, (cpu * 8 + pin), + qdev_get_gpio_in(cpudev, pin + 2)); + } + } + + pch_pic = qdev_new(TYPE_LOONGARCH_PCH_PIC); + d = SYS_BUS_DEVICE(pch_pic); + sysbus_realize_and_unref(d, &error_fatal); + memory_region_add_subregion(get_system_memory(), LS7A_IOAPIC_REG_BASE, + sysbus_mmio_get_region(d, 0)); + memory_region_add_subregion(get_system_memory(), + LS7A_IOAPIC_REG_BASE + PCH_PIC_ROUTE_ENTRY_OFFSET, + sysbus_mmio_get_region(d, 1)); + memory_region_add_subregion(get_system_memory(), + LS7A_IOAPIC_REG_BASE + PCH_PIC_INT_STATUS_LO, + sysbus_mmio_get_region(d, 2)); + + /* Connect 64 pch_pic irqs to extioi */ + for (int i = 0; i < PCH_PIC_IRQ_NUM; i++) { + qdev_connect_gpio_out(DEVICE(d), i, qdev_get_gpio_in(extioi, i)); + } + + pch_msi = qdev_new(TYPE_LOONGARCH_PCH_MSI); + d = SYS_BUS_DEVICE(pch_msi); + sysbus_realize_and_unref(d, &error_fatal); + sysbus_mmio_map(d, 0, LS7A_PCH_MSI_ADDR_LOW); + for (i = 0; i < PCH_MSI_IRQ_NUM; i++) { + /* Connect 192 pch_msi irqs to extioi */ + qdev_connect_gpio_out(DEVICE(d), i, + qdev_get_gpio_in(extioi, i + PCH_MSI_IRQ_START)); + } +} + static void loongarch_init(MachineState *machine) { const char *cpu_model = machine->cpu_type; @@ -63,6 +165,8 @@ static void loongarch_init(MachineState *machine) get_system_io(), 0, LOONGARCH_ISA_IO_SIZE); memory_region_add_subregion(address_space_mem, LOONGARCH_ISA_IO_BASE, &lams->isa_io); + /* Initialize the IO interrupt subsystem */ + loongarch_irq_init(lams); } static void loongarch_class_init(ObjectClass *oc, void *data)