From patchwork Fri Apr 8 14:15:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 558839 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp385332map; Fri, 8 Apr 2022 07:44:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywUF48CfF7dsMGKx/9i/YurMzYtbFG/Nq/grJfmllelLrNYbXh1PkoyWlsPNNbjdSWe4Hf X-Received: by 2002:a81:368a:0:b0:2ea:f500:ab99 with SMTP id d132-20020a81368a000000b002eaf500ab99mr16427508ywa.70.1649429059158; Fri, 08 Apr 2022 07:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649429059; cv=none; d=google.com; s=arc-20160816; b=kXF+6hDwNwnrirR9u/E6xgU46pRrBMqg3IzXzGL+1QfGiN2Z8EYpIZ+fA+ezr3+Jfx 6u+GEIOv2zwObZztABL2gO/0kGtadi0RK/JczzlBRLwqvFNiwPTo8L5aKgJbFiWRfgbR CbVKCvyX1TbLM+GqNIJjPlPIXPjBsFbuR25vkf182Kv3knSzCI6mE8KsycDi3MnX1tbg tf2esJGneAtA3RX6X1cchejzVWlhepi6/kQ2zqt5ABO4zXawCZaXNu/QLSIARmplX6SH ZG1qvOFoq7e7aXkXL3ULymjRQSHO4rLlTMKjS9aossCr5hYRbFekar6PiDOQ0oY4gC/1 dWBQ== 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=dkdiantr7+5+MkqtF+jpkZPTMHRoOYAGUVHwgCU5zUs=; b=Jby2le6Hj37w4M4wiwTWaxGJqCojyXMLKi0QHr380qHXOTFgQlXbkmdjzDY+zUrcPi oNc6dnvpgwVAH6DMxBGPUJ9qqfX40HumWjJXclqGPWitlv8mCVnEFBnPRjoLdvKgjvLL NmL9DKtCt2lSi3zYl5yv0WWlYR+4K52C4bPV6AJ48+4dvR7HAAvffL1M18VseWo2D8oz /3jNmGfXeS0TJGBj1qZCzrEI8QGP5t7JodpfQR6Ij1/IStzBDH7D5+Vm2Lj+oBqoMbU0 glpuMeUCHpaGY0HIho1ht5jAr4FCP4Ymj4O/X41EhNoqP7bvFX/uGG2nZHRn5i9eAbgP R4BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=awDZuFVi; 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 133-20020a25198b000000b0064110017a2asi516524ybz.515.2022.04.08.07.44.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Apr 2022 07:44:19 -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=awDZuFVi; 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]:34624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncpqU-00048Q-Ku for patch@linaro.org; Fri, 08 Apr 2022 10:44:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncpPc-0007So-Ko for qemu-devel@nongnu.org; Fri, 08 Apr 2022 10:16:32 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:34180) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncpPa-0002UK-BQ for qemu-devel@nongnu.org; Fri, 08 Apr 2022 10:16:32 -0400 Received: by mail-wm1-x330.google.com with SMTP id j5-20020a05600c1c0500b0038ea8b53580so809197wms.1 for ; Fri, 08 Apr 2022 07:16:29 -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=dkdiantr7+5+MkqtF+jpkZPTMHRoOYAGUVHwgCU5zUs=; b=awDZuFViW4CzES0ipTulLrOFw5PZHjsIpQ8/O5kqBzCUjYLhz3EtP9oPtibVtZ+y8h Nc0vychcetchJio0VczJF9flW+jEfQCKQkr4ywJqsmgEd+aiCGDPRf1Rc0U6EbMGxFq4 JaBf7YxEmYy0gj01ld2wLQK0cVtJR/ogN8SkPpsgfv0CL3cwKQnY64o9PhJeGX2H5Za/ XnkpICuZueXeS/RCyD4DxTodojzo+fRoTitsI7O6qLTEmnS6q0JQgC02YE5X83qcnZgS OtBXo5tUYtt3xoiF8k1osau/OvdJricHKTd/Gd1YQWSJ12xR7BkKXA8RX25izOgqThMg GzoQ== 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=dkdiantr7+5+MkqtF+jpkZPTMHRoOYAGUVHwgCU5zUs=; b=H13mWpfbs0rMHRJ2uQTwxCen5ponYXHcqEPu2V8q9WNSfDQMpSytPW/rbZ/kInAn2x k0/ueJYzEcBfkh8EoVhM57MxDonL5qd+IXBG5jYt8FaMK+XSU1uyvNVYpDciB7yqckVu ZikbRxC5BvHM9Dw0ru/bQeMP+5VgoXQ0919keUAG5PneLOq64/567mBGcjvoodD+/Ki2 Q+bTG3hdCbrBcjzUu6a9fROebz+9Qpxu8r4hIaar1FO8fHG7Gxxv4ZfKPzgKyulUHyl5 neFFpG29r8qTZ5E626Snzel9XLHEVjv0if1CGYqGfMl15xQWPd8ibHbUY1h0ObbIRRGW fQcw== X-Gm-Message-State: AOAM530PBzmJs+rI+5WOJ4/tVAcOeiy8UEmToyjnE1YJbo8KdJqCChJL GmMRUbqleXMBlRdsBrNrq9QrSwISnc3wbw== X-Received: by 2002:a1c:7517:0:b0:38c:8722:9bc6 with SMTP id o23-20020a1c7517000000b0038c87229bc6mr17170265wmc.2.1649427389031; Fri, 08 Apr 2022 07:16:29 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id i3-20020adffc03000000b0020616ee90dbsm11498849wrr.42.2022.04.08.07.16.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Apr 2022 07:16:28 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 39/41] hw/arm/virt: Use VIRT_GIC_VERSION_* enum values in create_gic() Date: Fri, 8 Apr 2022 15:15:48 +0100 Message-Id: <20220408141550.1271295-40-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220408141550.1271295-1-peter.maydell@linaro.org> References: <20220408141550.1271295-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x330.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=unavailable 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: Marc Zyngier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Everywhere we need to check which GIC version we're using, we look at vms->gic_version and use the VIRT_GIC_VERSION_* enum values, except in create_gic(), which copies vms->gic_version into a local 'int' variable and makes direct comparisons against values 2 and 3. For consistency, change this function to check the GIC version the same way we do elsewhere. This includes not implicitly relying on the enumeration type values happening to match the integer 'revision' values the GIC device object wants. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- hw/arm/virt.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index d2e5ecd234a..594a3d0660a 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -690,14 +690,29 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) /* We create a standalone GIC */ SysBusDevice *gicbusdev; const char *gictype; - int type = vms->gic_version, i; + int i; unsigned int smp_cpus = ms->smp.cpus; uint32_t nb_redist_regions = 0; + int revision; - gictype = (type == 3) ? gicv3_class_name() : gic_class_name(); + if (vms->gic_version == VIRT_GIC_VERSION_2) { + gictype = gic_class_name(); + } else { + gictype = gicv3_class_name(); + } + switch (vms->gic_version) { + case VIRT_GIC_VERSION_2: + revision = 2; + break; + case VIRT_GIC_VERSION_3: + revision = 3; + break; + default: + g_assert_not_reached(); + } vms->gic = qdev_new(gictype); - qdev_prop_set_uint32(vms->gic, "revision", type); + qdev_prop_set_uint32(vms->gic, "revision", revision); qdev_prop_set_uint32(vms->gic, "num-cpu", smp_cpus); /* Note that the num-irq property counts both internal and external * interrupts; there are always 32 of the former (mandated by GIC spec). @@ -707,7 +722,7 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) qdev_prop_set_bit(vms->gic, "has-security-extensions", vms->secure); } - if (type == 3) { + if (vms->gic_version == VIRT_GIC_VERSION_3) { uint32_t redist0_capacity = vms->memmap[VIRT_GIC_REDIST].size / GICV3_REDIST_SIZE; uint32_t redist0_count = MIN(smp_cpus, redist0_capacity); @@ -742,7 +757,7 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) gicbusdev = SYS_BUS_DEVICE(vms->gic); sysbus_realize_and_unref(gicbusdev, &error_fatal); sysbus_mmio_map(gicbusdev, 0, vms->memmap[VIRT_GIC_DIST].base); - if (type == 3) { + if (vms->gic_version == VIRT_GIC_VERSION_3) { sysbus_mmio_map(gicbusdev, 1, vms->memmap[VIRT_GIC_REDIST].base); if (nb_redist_regions == 2) { sysbus_mmio_map(gicbusdev, 2, @@ -780,7 +795,7 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) ppibase + timer_irq[irq])); } - if (type == 3) { + if (vms->gic_version == VIRT_GIC_VERSION_3) { qemu_irq irq = qdev_get_gpio_in(vms->gic, ppibase + ARCH_GIC_MAINT_IRQ); qdev_connect_gpio_out_named(cpudev, "gicv3-maintenance-interrupt", @@ -806,9 +821,9 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) fdt_add_gic_node(vms); - if (type == 3 && vms->its) { + if (vms->gic_version == VIRT_GIC_VERSION_3 && vms->its) { create_its(vms); - } else if (type == 2) { + } else if (vms->gic_version == VIRT_GIC_VERSION_2) { create_v2m(vms); } }