From patchwork Thu Apr 21 15:17:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 564405 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp595244map; Thu, 21 Apr 2022 09:36:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8kyVYfDp2acPwRZAxkqwOHV1QnEvUNyB8e3ei/Whom7ueRWY6HtgQeAaAXLcuMgvCh3GI X-Received: by 2002:a05:6902:10c1:b0:63e:df54:7095 with SMTP id w1-20020a05690210c100b0063edf547095mr526523ybu.433.1650558996669; Thu, 21 Apr 2022 09:36:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650558996; cv=none; d=google.com; s=arc-20160816; b=GEvFQYLY0K/NoSeHPA+1esjKaSLvyNRJAXAg8eJqH0rHkvd7ICAqVUvIlnJRD7gqwc mKJgu40gR9fkS4BRQhoI7lfC3lutZ3xGhTR9iy/XQJROIPj34bSURrTg/kvZzG1Kp8pv w1bvLuMFNMpxdwtlcuNmorqkFgfBAOaBwAeEoNqcZU39sRB1yrvypmMyG9u+WlFaMjp/ v3gUhq8CHxwX1XCXR2Ce1pIiL+DCWpvtxey8Re0AcsrRNLUjHLtQjvoHh66jQ4DNsoAP vpStyONrRdH7kcrFZ+7pP9HoYoS3nyw5MJm/pF7pCpES6HiKofwJnA64BOm5qent8n/F 37Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=IfWSu9VNafPHp8o0fmuna0CY6dhXpdzmhz+aAiWUWPs=; b=H+9q/iOmQnL66t10d3cs3lQTUbilsSxc/nM3UKYACefKXGT78PXu78TBAMy57BzqHu dMal/8ymrtSvX+4y/mnNbffcegxzvAfy6lje15CJsTPwa3siP+Fue58ymPKyLApjaKK3 FfCaTxFcrXCnV1VLmkyhKz5G9JCkCSMx+nAO6PVOxX774WjQYCElqBMdcIe1mMJduuKZ 2SO5yxGda8N7/yOltJfBB8DMnW1q5XgYN7zGt9qo+T51jrs5N6Bq7ko7SylUr0EzrpLa rXrQcJUlKzrWcT5Rzzkuoq75SBZNVWmHRpCcr7M9dlpkcoS6Y9HpwuOqlNt+xq84qLag gpag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KZyLlJlX; 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 b11-20020a251b0b000000b0064583747c2esi496364ybb.606.2022.04.21.09.36.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Apr 2022 09:36:36 -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=KZyLlJlX; 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]:45386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhZnI-0004RY-2f for patch@linaro.org; Thu, 21 Apr 2022 12:36:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45156) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhYdN-0005o6-IA for qemu-devel@nongnu.org; Thu, 21 Apr 2022 11:22:20 -0400 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]:34702) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhYdI-0007H8-62 for qemu-devel@nongnu.org; Thu, 21 Apr 2022 11:22:13 -0400 Received: by mail-il1-x12d.google.com with SMTP id r11so3269776ila.1 for ; Thu, 21 Apr 2022 08:22:11 -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=IfWSu9VNafPHp8o0fmuna0CY6dhXpdzmhz+aAiWUWPs=; b=KZyLlJlXFcYH0kYmpOQ8OumbMXI/JI7kBBFBwPVFuzZR/Aa/PHu0b9xOGd9W8cvDof IK80ve2N3GY3B2JeYTWkTZ8fM0uDuP6s2ovhvtdSgxTS00b+TOjaWbd+u8yQRngPYupq CXxTTk7T3O38FHEcvPHfdo8e5kMgsErqFYFBlsUHbpNTBde7Vw49rK2v9ORjpz99ssHd OZmdX0yZ0X6lC6P6pulKfLoN3F83xki7N/sUwUq6RYA4yxms7dz/D32cLgIutJi1doRn pLDUZUqSiVfSB1qgwrr4wNzXfxKL4f7IwVtkgL03BxFeEY5bEKGVM0Jnk2Emr1LuYnhT 2xIw== 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=IfWSu9VNafPHp8o0fmuna0CY6dhXpdzmhz+aAiWUWPs=; b=du85pBAjaNBnGX2NtmY96TVQEJ4ZmKPhjkBbvuA5XJ+ZVjRpgVSVN4bpk4pR1lm0V2 1cXsnTAO0/5PZVsGIosL2sNBaO4K7aZ1pRVJyu2iBYoXjshxTkDH+bdf776Pg7ZVBhSL WsqPp3pvTRhUutoaWFqYgcGY6kQIsQ7Btqm22UkGu6XCwnWgdtri7NcJsEv13eYj0i0/ zPSXWJfD4sj8XjHkpZOqdo+UkKDXx8DAooHsTQi3LKPw0J3LyB+JAIAdU/dsr/gU1A8V dIo0Z+FkpVtMoM5zhTtuySyIZB2WLf5qKsoQCju1F7kgDl2O/DUXEYg7DFx7e5cCXyl2 vXIA== X-Gm-Message-State: AOAM530CeF8RPt1HKSmfT+mePdX4Shd4islQmeJ7hwGt5YJhkgKzRKTK ih6MMLTePWOcnfOrBTNdogGxclD1ESZnJQ== X-Received: by 2002:a92:7c11:0:b0:2ca:36df:e2f2 with SMTP id x17-20020a927c11000000b002ca36dfe2f2mr73072ilc.149.1650554531193; Thu, 21 Apr 2022 08:22:11 -0700 (PDT) Received: from stoup.. ([2607:fb90:80c8:6cf3:a91a:4957:ba18:ac18]) by smtp.gmail.com with ESMTPSA id j1-20020a926e01000000b002cc52449a19sm3985402ilc.35.2022.04.21.08.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 08:22:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v7 62/64] hw/nios2: Machine with a Vectored Interrupt Controller Date: Thu, 21 Apr 2022 08:17:33 -0700 Message-Id: <20220421151735.31996-63-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220421151735.31996-1-richard.henderson@linaro.org> References: <20220421151735.31996-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::12d; envelope-from=richard.henderson@linaro.org; helo=mail-il1-x12d.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: , Cc: Amir Gonnen , Mark Cave-Ayland Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Amir Gonnen 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. Reviewed-by: Mark Cave-Ayland Signed-off-by: Amir Gonnen Message-Id: <20220303153906.2024748-6-amir.gonnen@neuroblade.ai> [rth: Put a property on the 10m50-ghrd machine, rather than create a new machine class.] Signed-off-by: Richard Henderson --- 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