From nobody Thu Apr 3 11:42:16 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1741140140; cv=none; d=zohomail.com; s=zohoarc; b=eZkAmxlMcFiZzgoAc42psIISJVxs6VrKgfaEKiZsa3UzwGRIpM7w0S+fFYidsojg2P/jI7/+WkdDaWhvTEwrHqiV31vkAkVzn/ufwYIamoHdJYFDtf7Wk3DAH8gNH0MveLjLyPYVvREL4nbsaxm0l/QQDzZdxLY30F72fhAYGxE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741140140; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uA9/qkL7QiKfu9QsEJoocWtmDkHHjX3b28F0moNSlvo=; b=YYtg9AhUDay2Rb23lYSo19Tc46dr6l+DJKogD14FeVi/vkrOvNm74cXOM3mnqpMlUFQ0LCl+wSJDxhDHUoxjz6FlI63mY/ArmmKjBp4Aot7ZufMLk9KGxHCbPRZUgRYyjLDlA+xOnXX1Bn+U77dYbb9mclZKyxh86IZeB28hI6U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1741140140972792.0773016933706; Tue, 4 Mar 2025 18:02:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tpe0L-0003IZ-AL; Tue, 04 Mar 2025 20:57:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tpdzL-00082M-QV for qemu-devel@nongnu.org; Tue, 04 Mar 2025 20:55:59 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tpdzK-0000WV-0T for qemu-devel@nongnu.org; Tue, 04 Mar 2025 20:55:59 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-22349dc31bcso110917995ad.3 for ; Tue, 04 Mar 2025 17:55:57 -0800 (PST) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-223501f9e04sm102583695ad.87.2025.03.04.17.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 17:55:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741139756; x=1741744556; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uA9/qkL7QiKfu9QsEJoocWtmDkHHjX3b28F0moNSlvo=; b=ZgP8cZ98cdXiXxqE4R3zFs5EDVlHG7FtGIuv7VyFuQxzLzWn+vOwOEeiJnvT37Fafa LuUGlqGbub3EZNqMuRAf/dRf7mGAfUHqJO7jhAAz1wkvZAySDRW03DNUEESIp+fgAXyL s25IEeIPv1B94q+Q2Z3GucMPCRty1e0pYz7oAwpHdaVisPHKh/W+Evux4mT5VXdobiIf qDm2HgidwAX59uoGPuA+ob+ehcdBZ+i10co+IMJFbtJ+zqTcSJZm4/EwIjeJDH4y8rbw 3hLVqLjVWUfTwz02a0nZjkSTuyflnhs7nWvlPrSiIaIN+dIfclkX3Iw6AhFfP3OFtwA0 dELQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741139756; x=1741744556; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uA9/qkL7QiKfu9QsEJoocWtmDkHHjX3b28F0moNSlvo=; b=fKeQYyDDoX3dN3yoBieskWUVhFS4CGjvq1u7N8yVJtQzQmBpBIG4bp+XNHZeop4Z5P 6unRoWRZa24di9xsWnkEXZpWH67nfxN/MK6GEh+h+w0g4W2HsDxu4sPvqTUFt7IiKHjJ j7d204iL5wZZKPhf5pqjHj0jdcu/ZE2iI1PMacIwD+u6UIqdbAr0HR+SO6X7I+vKo4fc IMDtpGHzzOtNth8TA8mO20sUShFbAbGmhuTxPVOq6UugI9MKuThS3T86D+QlidNJBeKN ZymiyhDzavo9R1/0iaKaUFKANhocySyF59JmMJ3cK1K2RkWAg5DBrZRb3uJ9pAfj1Vc8 eERg== X-Gm-Message-State: AOJu0YzdGMt0aM1OXTZHO42pHf3BH5fYmog0XB1l3eINyrOCEvgqhmpJ x0ESdICWKjZa6FdjY14og4phi9X578zdiXJ0gn4khP8zuxwTebj14lfGm+RRAOM= X-Gm-Gg: ASbGncvPsTTVDqGkBbhUgTmXj+p47w3FeUHcRucECIqY0hghBcg6vzSVpE/RvyHxGlX nQopXTHbGHcDcqo3coBzqd7y8A5OE+58HAglDo9gzxvPo4HivWJKOVSaOnB+h4sIj+3V8kz0dlN XK7N8b5kNGhh2o/XouAMz1Z2itkI4kT6HYkvOcB8NoO+l3if+hCu3QkCXEQEYWfMJIo38EYwOpM r3sl92KeqE9zpRCTe0utD+PXMpV/kVlrwWlaq28qDW4OGqgot6xTMWDUUuApgpnoEAv+ORLwPsD KBCYIq9a8IiPwlCmiBZz8S96Zgr0nxhKaMMeFoIlOB7GlsvOvBMB9VkG3SKw9TjnSlh546vABqG 5YEWjAW06oUN/BJZTsH8LCE9QLYkMTbp4XQCUNcNEVRnAeIJRjNE= X-Google-Smtp-Source: AGHT+IGkS27zoc6gJSs9Ai4ZPrg2LUumSWCx6JnjxHRri6uF909kQpCIqom0nvXDPc3PXxHn+dfnJg== X-Received: by 2002:a17:902:db0c:b0:220:fb23:48dd with SMTP id d9443c01a7336-223f1d18c76mr21495755ad.50.1741139756353; Tue, 04 Mar 2025 17:55:56 -0800 (PST) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Yong-Xuan Wang , Daniel Henrique Barboza , Alistair Francis Subject: [PULL 55/59] hw/intc/aplic: refine the APLIC realize Date: Wed, 5 Mar 2025 11:53:03 +1000 Message-ID: <20250305015307.1463560-56-alistair.francis@wdc.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250305015307.1463560-1-alistair.francis@wdc.com> References: <20250305015307.1463560-1-alistair.francis@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=alistair23@gmail.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1741140142575019000 Content-Type: text/plain; charset="utf-8" From: Yong-Xuan Wang When the APLIC is emulated in the kernel, the GPIO output lines to CPUs can be remove. In this case the APLIC trigger CPU interrupts by KVM APIs. This patch also move the code that claim the CPU interrupts to the beginning of APLIC realization. This can avoid the unnecessary resource allocation before checking failed. Signed-off-by: Yong-Xuan Wang Reviewed-by: Daniel Henrique Barboza Message-ID: <20250224025722.3999-3-yongxuan.wang@sifive.com> Signed-off-by: Alistair Francis --- hw/intc/riscv_aplic.c | 49 +++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c index 0974c6a5db..e5714267c0 100644 --- a/hw/intc/riscv_aplic.c +++ b/hw/intc/riscv_aplic.c @@ -893,6 +893,26 @@ static void riscv_aplic_realize(DeviceState *dev, Erro= r **errp) RISCVAPLICState *aplic =3D RISCV_APLIC(dev); =20 if (riscv_use_emulated_aplic(aplic->msimode)) { + /* Create output IRQ lines for non-MSI mode */ + if (!aplic->msimode) { + /* Claim the CPU interrupt to be triggered by this APLIC */ + for (i =3D 0; i < aplic->num_harts; i++) { + RISCVCPU *cpu; + + cpu =3D RISCV_CPU(cpu_by_arch_id(aplic->hartid_base + i)); + if (riscv_cpu_claim_interrupts(cpu, + (aplic->mmode) ? MIP_MEIP : MIP_SEIP) < 0) { + error_report("%s already claimed", + (aplic->mmode) ? "MEIP" : "SEIP"); + exit(1); + } + } + + aplic->external_irqs =3D g_malloc(sizeof(qemu_irq) * + aplic->num_harts); + qdev_init_gpio_out(dev, aplic->external_irqs, aplic->num_harts= ); + } + aplic->bitfield_words =3D (aplic->num_irqs + 31) >> 5; aplic->sourcecfg =3D g_new0(uint32_t, aplic->num_irqs); aplic->state =3D g_new0(uint32_t, aplic->num_irqs); @@ -927,23 +947,6 @@ static void riscv_aplic_realize(DeviceState *dev, Erro= r **errp) } } =20 - /* Create output IRQ lines for non-MSI mode */ - if (!aplic->msimode) { - aplic->external_irqs =3D g_malloc(sizeof(qemu_irq) * aplic->num_ha= rts); - qdev_init_gpio_out(dev, aplic->external_irqs, aplic->num_harts); - - /* Claim the CPU interrupt to be triggered by this APLIC */ - for (i =3D 0; i < aplic->num_harts; i++) { - RISCVCPU *cpu =3D RISCV_CPU(cpu_by_arch_id(aplic->hartid_base = + i)); - if (riscv_cpu_claim_interrupts(cpu, - (aplic->mmode) ? MIP_MEIP : MIP_SEIP) < 0) { - error_report("%s already claimed", - (aplic->mmode) ? "MEIP" : "SEIP"); - exit(1); - } - } - } - msi_nonbroken =3D true; } =20 @@ -1067,15 +1070,15 @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr= size, =20 if (riscv_use_emulated_aplic(msimode)) { sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); - } =20 - if (!msimode) { - for (i =3D 0; i < num_harts; i++) { - CPUState *cpu =3D cpu_by_arch_id(hartid_base + i); + if (!msimode) { + for (i =3D 0; i < num_harts; i++) { + CPUState *cpu =3D cpu_by_arch_id(hartid_base + i); =20 - qdev_connect_gpio_out_named(dev, NULL, i, - qdev_get_gpio_in(DEVICE(cpu), + qdev_connect_gpio_out_named(dev, NULL, i, + qdev_get_gpio_in(DEVICE(cpu), (mmode) ? IRQ_M_EXT : IRQ_S_EX= T)); + } } } =20 --=20 2.48.1