From nobody Thu Nov 28 09:35:50 2024 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=1694153387; cv=none; d=zohomail.com; s=zohoarc; b=iIGqtGb0fD1PfqVOxfz7IXQmhdf5DgjnAs4yErG/UVshXkkDACoCf6tOHqzC7b/5KAG0nAiy9gOy79rT2rDOivMMhNHwSFdpdbbWkazVa9rC0rpwUkKaePE7acbdlk2FiAbn8CfifgRx3+rXKiD6Fk9FfvYk4M4Z+uo1RYKLaDs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694153387; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HQFAilQXwavviYSAdbF8h1VfNWuIPepi8QcpnGv5OOw=; b=Zql4SZHDWCsZg4XqeypQLhNwTPoWdQk+QL0OR/mlvngv8r0u7icuP9Ugb8tKN6M6l1V4g6Wb2oSlbc8Io6tdq8Q6A8JMKikYGBFQNz4fFCGDHRDTVeh+1iil7v5Ib8qr5bdqLEkuqiOV8rvjCb5E0B3s49ilGeRUXnYyBwF9p74= 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 1694153387322436.51097492729264; Thu, 7 Sep 2023 23:09:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeUe5-0004zb-Ny; Fri, 08 Sep 2023 02:07:09 -0400 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 1qeUe3-0004kK-Ja for qemu-devel@nongnu.org; Fri, 08 Sep 2023 02:07:07 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeUe0-0006ic-Ub for qemu-devel@nongnu.org; Fri, 08 Sep 2023 02:07:07 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1bdc19b782aso13623125ad.0 for ; Thu, 07 Sep 2023 23:07:04 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id q1-20020a170902dac100b001c3267ae31bsm715231plx.301.2023.09.07.23.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 23:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694153223; x=1694758023; 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=HQFAilQXwavviYSAdbF8h1VfNWuIPepi8QcpnGv5OOw=; b=QtYmuc81Bj03PzU2qpXL2DuSOl+Pi2a+DT2Xgq23ZipW6MS3A0/Dzfjg+O3eJIByx6 1wuMbsjKMAE/LStren0Z3y2hdRl5TTwYSgxdwXZgm9430q7SqoX37/j2vE7OuEdD1Iji x3Avlqv9RPl+o/hSGF4xoznSVLbp+stAY2U/pYFshKePz3n1PSXTyZsUVubIryTWO196 aObXy0Mko98ItrdoPj58Zyle/JqW/Zi3HsFobRE47hEHj/Yj890hKmAqousOm8mNhHWC jwLM4UJ4CF45YqKxL7PaeLNfeEEyTYK7kB3LnM7cAtqsYPfcNfxEx5IVdI0Nq0/OtsKC ++9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694153223; x=1694758023; 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=HQFAilQXwavviYSAdbF8h1VfNWuIPepi8QcpnGv5OOw=; b=oRuvHNZjSwXqBlj6zptkVLV6fJWLFR6LnoC4Z0RTYYl7phC92wl9vRioCOrs3PzaCK R+2z/R3cOU6aPS9J8xBH7oN20HoGBwjzeK9nNfe4eie+OKrIkNLeC0A1shegSovCwewQ eNqLME+AoHZc28UAfp+JUBf8mhQCDk/yBhlrbXeUZj97o5CPV53kltzswcHaEPTxf9Rc iDeYgkrmr8EBHC3xmbBiP2NaU6rt4yC1wCDGwoTxZnntYf9NqRJtSuZOqHAdqscwpIzb qvgNngc93jPgIV+TBt3gPcXkY7i3rbaEPl2xom0AKdg6anyFdYP6uKq76MSNWDbZR5yL FBqA== X-Gm-Message-State: AOJu0YyLXdkXwlqFR7ILAy9nQ0jMn6qLOoUv1Wilb+1MhCO4zeqaYFyf Io2llqgdZTS7LpOUyG5z57Ud97p/s+Sy8C84 X-Google-Smtp-Source: AGHT+IFfE+aWr6CxXfQlJunOmEVwYwCAKW1TAUXLHJvnUDNMN+LWheU5aV2VAjs8nWDOWY+ea972Tw== X-Received: by 2002:a17:903:1104:b0:1bd:c105:e07e with SMTP id n4-20020a170903110400b001bdc105e07emr2115663plh.6.1694153222780; Thu, 07 Sep 2023 23:07:02 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Yong-Xuan Wang , Jim Shu , Daniel Henrique Barboza , Andrew Jones , Alistair Francis Subject: [PULL 33/65] target/riscv: select KVM AIA in riscv virt machine Date: Fri, 8 Sep 2023 16:03:59 +1000 Message-ID: <20230908060431.1903919-34-alistair.francis@wdc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230908060431.1903919-1-alistair.francis@wdc.com> References: <20230908060431.1903919-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::62a; envelope-from=alistair23@gmail.com; helo=mail-pl1-x62a.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: 1694153388580100003 Content-Type: text/plain; charset="utf-8" From: Yong-Xuan Wang Select KVM AIA when the host kernel has in-kernel AIA chip support. Since KVM AIA only has one APLIC instance, we map the QEMU APLIC devices to KVM APLIC. Signed-off-by: Yong-Xuan Wang Reviewed-by: Jim Shu Reviewed-by: Daniel Henrique Barboza Reviewed-by: Andrew Jones Message-ID: <20230727102439.22554-6-yongxuan.wang@sifive.com> Signed-off-by: Alistair Francis --- hw/riscv/virt.c | 94 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 31 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 693b2df8df..a0f7b5abf9 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -35,6 +35,7 @@ #include "hw/riscv/virt.h" #include "hw/riscv/boot.h" #include "hw/riscv/numa.h" +#include "kvm_riscv.h" #include "hw/intc/riscv_aclint.h" #include "hw/intc/riscv_aplic.h" #include "hw/intc/riscv_imsic.h" @@ -75,6 +76,12 @@ #error "Can't accomodate all IMSIC groups in address space" #endif =20 +/* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU= . */ +static bool virt_use_kvm_aia(RISCVVirtState *s) +{ + return kvm_irqchip_in_kernel() && s->aia_type =3D=3D VIRT_AIA_TYPE_APL= IC_IMSIC; +} + static const MemMapEntry virt_memmap[] =3D { [VIRT_DEBUG] =3D { 0x0, 0x100 }, [VIRT_MROM] =3D { 0x1000, 0xf000 }, @@ -609,16 +616,16 @@ static void create_fdt_one_aplic(RISCVVirtState *s, i= nt socket, uint32_t *intc_phandles, uint32_t aplic_phandle, uint32_t aplic_child_phandle, - bool m_mode) + bool m_mode, int num_harts) { int cpu; char *aplic_name; uint32_t *aplic_cells; MachineState *ms =3D MACHINE(s); =20 - aplic_cells =3D g_new0(uint32_t, s->soc[socket].num_harts * 2); + aplic_cells =3D g_new0(uint32_t, num_harts * 2); =20 - for (cpu =3D 0; cpu < s->soc[socket].num_harts; cpu++) { + for (cpu =3D 0; cpu < num_harts; cpu++) { aplic_cells[cpu * 2 + 0] =3D cpu_to_be32(intc_phandles[cpu]); aplic_cells[cpu * 2 + 1] =3D cpu_to_be32(m_mode ? IRQ_M_EXT : IRQ_= S_EXT); } @@ -632,8 +639,7 @@ static void create_fdt_one_aplic(RISCVVirtState *s, int= socket, =20 if (s->aia_type =3D=3D VIRT_AIA_TYPE_APLIC) { qemu_fdt_setprop(ms->fdt, aplic_name, "interrupts-extended", - aplic_cells, - s->soc[socket].num_harts * sizeof(uint32_t) * 2); + aplic_cells, num_harts * sizeof(uint32_t) * 2); } else { qemu_fdt_setprop_cell(ms->fdt, aplic_name, "msi-parent", msi_phand= le); } @@ -664,7 +670,8 @@ static void create_fdt_socket_aplic(RISCVVirtState *s, uint32_t msi_s_phandle, uint32_t *phandle, uint32_t *intc_phandles, - uint32_t *aplic_phandles) + uint32_t *aplic_phandles, + int num_harts) { char *aplic_name; unsigned long aplic_addr; @@ -681,7 +688,7 @@ static void create_fdt_socket_aplic(RISCVVirtState *s, create_fdt_one_aplic(s, socket, aplic_addr, memmap[VIRT_APLIC_M].s= ize, msi_m_phandle, intc_phandles, aplic_m_phandle, aplic_s_phandle, - true); + true, num_harts); } =20 /* S-level APLIC node */ @@ -690,7 +697,7 @@ static void create_fdt_socket_aplic(RISCVVirtState *s, create_fdt_one_aplic(s, socket, aplic_addr, memmap[VIRT_APLIC_S].size, msi_s_phandle, intc_phandles, aplic_s_phandle, 0, - false); + false, num_harts); =20 aplic_name =3D g_strdup_printf("/soc/aplic@%lx", aplic_addr); =20 @@ -774,34 +781,51 @@ static void create_fdt_sockets(RISCVVirtState *s, con= st MemMapEntry *memmap, *msi_pcie_phandle =3D msi_s_phandle; } =20 - phandle_pos =3D ms->smp.cpus; - for (socket =3D (socket_count - 1); socket >=3D 0; socket--) { - phandle_pos -=3D s->soc[socket].num_harts; - - if (s->aia_type =3D=3D VIRT_AIA_TYPE_NONE) { - create_fdt_socket_plic(s, memmap, socket, phandle, - &intc_phandles[phandle_pos], xplic_phandles); - } else { - create_fdt_socket_aplic(s, memmap, socket, - msi_m_phandle, msi_s_phandle, phandle, - &intc_phandles[phandle_pos], xplic_phandles); + /* KVM AIA only has one APLIC instance */ + if (virt_use_kvm_aia(s)) { + create_fdt_socket_aplic(s, memmap, 0, + msi_m_phandle, msi_s_phandle, phandle, + &intc_phandles[0], xplic_phandles, + ms->smp.cpus); + } else { + phandle_pos =3D ms->smp.cpus; + for (socket =3D (socket_count - 1); socket >=3D 0; socket--) { + phandle_pos -=3D s->soc[socket].num_harts; + + if (s->aia_type =3D=3D VIRT_AIA_TYPE_NONE) { + create_fdt_socket_plic(s, memmap, socket, phandle, + &intc_phandles[phandle_pos], + xplic_phandles); + } else { + create_fdt_socket_aplic(s, memmap, socket, + msi_m_phandle, msi_s_phandle, phan= dle, + &intc_phandles[phandle_pos], + xplic_phandles, + s->soc[socket].num_harts); + } } } =20 g_free(intc_phandles); =20 - for (socket =3D 0; socket < socket_count; socket++) { - if (socket =3D=3D 0) { - *irq_mmio_phandle =3D xplic_phandles[socket]; - *irq_virtio_phandle =3D xplic_phandles[socket]; - *irq_pcie_phandle =3D xplic_phandles[socket]; - } - if (socket =3D=3D 1) { - *irq_virtio_phandle =3D xplic_phandles[socket]; - *irq_pcie_phandle =3D xplic_phandles[socket]; - } - if (socket =3D=3D 2) { - *irq_pcie_phandle =3D xplic_phandles[socket]; + if (virt_use_kvm_aia(s)) { + *irq_mmio_phandle =3D xplic_phandles[0]; + *irq_virtio_phandle =3D xplic_phandles[0]; + *irq_pcie_phandle =3D xplic_phandles[0]; + } else { + for (socket =3D 0; socket < socket_count; socket++) { + if (socket =3D=3D 0) { + *irq_mmio_phandle =3D xplic_phandles[socket]; + *irq_virtio_phandle =3D xplic_phandles[socket]; + *irq_pcie_phandle =3D xplic_phandles[socket]; + } + if (socket =3D=3D 1) { + *irq_virtio_phandle =3D xplic_phandles[socket]; + *irq_pcie_phandle =3D xplic_phandles[socket]; + } + if (socket =3D=3D 2) { + *irq_pcie_phandle =3D xplic_phandles[socket]; + } } } =20 @@ -1437,6 +1461,14 @@ static void virt_machine_init(MachineState *machine) } } =20 + if (virt_use_kvm_aia(s)) { + kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT, + VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MS= IS, + memmap[VIRT_APLIC_S].base, + memmap[VIRT_IMSIC_S].base, + s->aia_guests); + } + if (riscv_is_32bit(&s->soc[0])) { #if HOST_LONG_BITS =3D=3D 64 /* limit RAM size in a 32-bit system */ --=20 2.41.0