From nobody Sat Sep 21 05:25:23 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=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1706101024; cv=none; d=zohomail.com; s=zohoarc; b=LqhVJ1JbvZLngQaFCWqEySgvQ1CH8ZIM2wQqlxXmuMZ7GfaEIGbWs2t5hOs8J3WdszVZHztpESki90kSDFnxe4xsbDPDQMqCuOkizx/GzKPaMKg0fW8XoIvAhnyhuTZ/WplA+BNqbqcBmw1fR3AhK2GowAA5POT250PUD3os3go= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706101024; 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=CuGhWrORTkOihj+rQPuoBm5v7PsVFDye8Q4Ic6lXRNA=; b=n1NkNf02mNAT97q5rF7D65mWPniwftB9c74omtOIMJFyZO+idSRtMgsgaUkkiMbN8JNPK8kNVyYyWVLOCU3Yr7IuuY5BXbDTT4niJ+5qto3Muscc7odVwyXYpojpSpoFKmzxmoeu0ooVUOCmxapkF+7u2boGeq3hDJuevJRdXd0= 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 1706101024919257.42185895552655; Wed, 24 Jan 2024 04:57:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rScnY-000334-3R; Wed, 24 Jan 2024 07:56:08 -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 1rScnV-00032J-UF; Wed, 24 Jan 2024 07:56:05 -0500 Received: from sin.source.kernel.org ([145.40.73.55]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rScnT-00018J-O8; Wed, 24 Jan 2024 07:56:05 -0500 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 5E56ACE30FF; Wed, 24 Jan 2024 12:55:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41E90C43390; Wed, 24 Jan 2024 12:55:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706100957; bh=ry0lR4qMXsSwWVpsn6ghkeTk9xoq40DbZT3PJKglEhE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H9M2V3BYLs1uIEBoVC6fwCFW2ipVCtRwNyfgIM18atHcjq2kJqbpQhqjy8eUX3V3v yEVjYMDidMnXjd5NYFN5g2nkgxxstDNZAn8vQre3tryNUOSQsZKboH8fmN9sCg7qZp CwdA3YVIm/4KVXK4aeWG2uvS9bcENIRD6Y53/ka7lPkHIZAfFAWpuPSHh3NUtjPpSk SnVZS4/ba25kMyToCbeB65epZtUsKTgzDaC3Yhqnoz05i1zvwq41YgQjzMN6U/AE0b 80eHqpIZ2RpeQaT3Xq+bBpGOpYDC6RzCM/asuI5GldWNcyKR3EBkXoeB4A9soWwWdI xx71aPIOr394Q== From: Conor Dooley To: qemu-riscv@nongnu.org Cc: conor@kernel.org, Conor Dooley , Alistair Francis , Bin Meng , Palmer Dabbelt , Weiwei Li , Daniel Henrique Barboza , Andrew Jones , Liu Zhiwei , qemu-devel@nongnu.org Subject: [PATCH v4 1/2] target/riscv: use misa_mxl_max to populate isa string rather than TARGET_LONG_BITS Date: Wed, 24 Jan 2024 12:55:49 +0000 Message-ID: <20240124-swear-monthly-56c281f809a6@spud> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124-squatting-getup-a16a8499ad73@spud> References: <20240124-squatting-getup-a16a8499ad73@spud> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2734; i=conor.dooley@microchip.com; h=from:subject:message-id; bh=QS/0f+ukaw2mCU94HDKZEschftslg3jvKGDRD/+PYLQ=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDKkbOa4kfX97aX2j4dx+47enbhgq7G+cmL1E/KqxoRnPh 1Sus5wbOkpZGMQ4GGTFFFkSb/e1SK3/47LDuectzBxWJpAhDFycAjCRe28YGaYqvXbfYn5i5e7M c4LCSqnmG8rW/D2Umdj9Ys+0uc8Vp0Qx/PcvnRO5QPTKXKaY5j7l1vkiZzbN6nuisaRGr33qnEy PGF4A X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C 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=145.40.73.55; envelope-from=conor@kernel.org; helo=sin.source.kernel.org X-Spam_score_int: -58 X-Spam_score: -5.9 X-Spam_bar: ----- X-Spam_report: (-5.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.5, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1706101026388100003 Content-Type: text/plain; charset="utf-8" From: Conor Dooley A cpu may not have the same xlen as the compile time target, and misa_mxl_max is the source of truth for what the hart supports. The conversion from misa_mxl_max to xlen already has one user, so introduce a helper and use that to populate the isa string. Link: https://lore.kernel.org/qemu-riscv/20240108-efa3f83dcd3997dc0af458d7@= orel/ Signed-off-by: Conor Dooley Reviewed-by: Alistair Francis Reviewed-by: Andrew Jones Reviewed-by: Daniel Henrique Barboza --- I dropped the tags since I added the helper --- target/riscv/cpu.c | 9 ++++++++- target/riscv/cpu.h | 1 + target/riscv/gdbstub.c | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index ad1df2318b..4aa4b2e988 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -307,6 +307,11 @@ void riscv_cpu_set_misa(CPURISCVState *env, RISCVMXL m= xl, uint32_t ext) env->misa_ext_mask =3D env->misa_ext =3D ext; } =20 +int riscv_cpu_max_xlen(CPURISCVState env) +{ + return 16 << env.misa_mxl_max; +} + #ifndef CONFIG_USER_ONLY static uint8_t satp_mode_from_str(const char *satp_mode_str) { @@ -2332,7 +2337,9 @@ char *riscv_isa_string(RISCVCPU *cpu) int i; const size_t maxlen =3D sizeof("rv128") + sizeof(riscv_single_letter_e= xts); char *isa_str =3D g_new(char, maxlen); - char *p =3D isa_str + snprintf(isa_str, maxlen, "rv%d", TARGET_LONG_BI= TS); + int xlen =3D riscv_cpu_max_xlen(cpu->env); + char *p =3D isa_str + snprintf(isa_str, maxlen, "rv%d", xlen); + for (i =3D 0; i < sizeof(riscv_single_letter_exts) - 1; i++) { if (cpu->env.misa_ext & RV(riscv_single_letter_exts[i])) { *p++ =3D qemu_tolower(riscv_single_letter_exts[i]); diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 05e83c4ac9..aacc031397 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -511,6 +511,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, in= t size, MMUAccessType access_type, int mmu_idx, bool probe, uintptr_t retaddr); char *riscv_isa_string(RISCVCPU *cpu); +int riscv_cpu_max_xlen(CPURISCVState env); bool riscv_cpu_option_set(const char *optname); =20 #define cpu_mmu_index riscv_cpu_mmu_index diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c index 58b3ace0fe..f15980fdcf 100644 --- a/target/riscv/gdbstub.c +++ b/target/riscv/gdbstub.c @@ -218,7 +218,7 @@ static int riscv_gen_dynamic_csr_xml(CPUState *cs, int = base_reg) CPURISCVState *env =3D &cpu->env; GString *s =3D g_string_new(NULL); riscv_csr_predicate_fn predicate; - int bitsize =3D 16 << env->misa_mxl_max; + int bitsize =3D riscv_cpu_max_xlen(*env); int i; =20 #if !defined(CONFIG_USER_ONLY) --=20 2.43.0 From nobody Sat Sep 21 05:25:23 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=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1706101040; cv=none; d=zohomail.com; s=zohoarc; b=L4mSAqTPvzWJmMm6xNiQ+Wp3WoBQv6hTMJuKEcmhJ9+J2ygVKgHR3D+GfXNxr7lvgzi/5ydeASEKcyUmmo3UgHH+oZcWceXHI2q415wy195acAyOEWhNXDjh1e/jKBNBIFXmvXRe+6oxlAnBdtGncSeB02S77k31PuyveOph6nY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706101040; 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=iWXNM8u28L1d002RCaZAORb3CrXnSIFvaA0wdmG+xtM=; b=eywrhCcAOjOfSWGzaKi7aqL8SAweH77O9Ls8XEs4qy/6K0SwrEeMxgMOUcZiIauaIgLo/eAf8eixwqu715AZ1COE5z24aUSQBS+IEBKXLwrOrWfGkBniNvSBiEj+fDMy4CzfkV6UkBG7NclnAnhuw7kkLlw783DhGtHykUaKHfk= 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 1706101040209716.184843479405; Wed, 24 Jan 2024 04:57:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rScnV-00031l-7t; Wed, 24 Jan 2024 07:56:05 -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 1rScnU-00031Y-6f; Wed, 24 Jan 2024 07:56:04 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rScnS-00018H-3p; Wed, 24 Jan 2024 07:56:03 -0500 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B59F861D28; Wed, 24 Jan 2024 12:56:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE49AC433F1; Wed, 24 Jan 2024 12:55:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706100960; bh=ttMJTg52w31+TKSuA7xlLZ6RooEnip2m74J+J3WqgjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eFdzTHQB7B0NoL6MAQw1OMbvbrrzMYgATHTVUpRoxlWuTYK+EPWsZTZExlM7FhWjN 08WRSu9HYJ2jBamk3GeXRxXP+QhD3N4tO3g1fbsX0NpL4SdLh4RgTeDriB2fIQjFx+ QtWLEajF5m2Vo1W6Panqe1PAzPMqC1KiR4LI+N3u4hIbORGW9y8BAw5B7waDSDCPS8 WuDnhwF02HGCM5PVs1vnjy+/BLCWvd/yOymbG7ZsY+z4PPQA/d4gWbvE1EwD6aojk8 SzLPeQXqdYVozgyD7rSH2XRkFdY4nvQYYo9KzQH0fWJyQdkwfyTx432+q1lZr/Uoo0 2wnjHDKX95DEw== From: Conor Dooley To: qemu-riscv@nongnu.org Cc: conor@kernel.org, Conor Dooley , Alistair Francis , Bin Meng , Palmer Dabbelt , Weiwei Li , Daniel Henrique Barboza , Andrew Jones , Liu Zhiwei , qemu-devel@nongnu.org, Alistair Francis Subject: [PATCH v4 2/2] target/riscv: support new isa extension detection devicetree properties Date: Wed, 24 Jan 2024 12:55:50 +0000 Message-ID: <20240124-unvarying-foothold-9dde2aaf95d4@spud> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124-squatting-getup-a16a8499ad73@spud> References: <20240124-squatting-getup-a16a8499ad73@spud> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=9360; i=conor.dooley@microchip.com; h=from:subject:message-id; bh=GneOb0H2BmKPZJ+pLmWpUgQNrOct96Mumc0k9l/7Q2M=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDKkbOa62fv6+p261r5+z1dL1ouu7Vj9t3aFVbD/lZ7+b5 tQV/vHdHaUsDGIcDLJiiiyJt/tapNb/cdnh3PMWZg4rE8gQBi5OAZjIuzkMv5j7PizJbOatXeB0 SsbGqDz40YyIjBtMjR151Z77o65NNWX4Z/Otb55EyG3m2Zw2oUXxiq/k2T6Hv/+Y3d2z1XrbC4e XHAA= X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C 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=139.178.84.217; envelope-from=conor@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -85 X-Spam_score: -8.6 X-Spam_bar: -------- X-Spam_report: (-8.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.5, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1706101040516100005 Content-Type: text/plain; charset="utf-8" From: Conor Dooley A few months ago I submitted a patch to various lists, deprecating "riscv,isa" with a lengthy commit message [0] that is now commit aeb71e42caae ("dt-bindings: riscv: deprecate riscv,isa") in the Linux kernel tree. Primarily, the goal was to replace "riscv,isa" with a new set of properties that allowed for strictly defining the meaning of various extensions, where "riscv,isa" was tied to whatever definitions inflicted upon us by the ISA manual, which have seen some variance over time. Two new properties were introduced: "riscv,isa-base" and "riscv,isa-extensions". The former is a simple string to communicate the base ISA implemented by a hart and the latter an array of strings used to communicate the set of ISA extensions supported, per the definitions of each substring in extensions.yaml [1]. A beneficial side effect was also the ability to define vendor extensions in a more "official" way, as the ISA manual and other RVI specifications only covered the format for vendor extensions in the ISA string, but not the meaning of vendor extensions, for obvious reasons. Add support for setting these two new properties in the devicetrees for the various devicetree platforms supported by QEMU for RISC-V. The Linux kernel already supports parsing ISA extensions from these new properties, and documenting them in the dt-binding is a requirement for new extension detection being added to the kernel. A side effect of the implementation is that the meaning for elements in "riscv,isa" and in "riscv,isa-extensions" are now tied together as they are constructed from the same source. The same applies to the ISA string provided in ACPI tables, but there does not appear to be any strict definitions of meanings in ACPI land either. Link: https://lore.kernel.org/qemu-riscv/20230702-eats-scorebook-c951f170d2= 9f@spud/ [0] Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tr= ee/Documentation/devicetree/bindings/riscv/extensions.yaml [1] Reviewed-by: Alistair Francis Reviewed-by: Andrew Jones Signed-off-by: Conor Dooley Reviewed-by: Daniel Henrique Barboza --- hw/riscv/sifive_u.c | 7 ++---- hw/riscv/spike.c | 6 ++--- hw/riscv/virt.c | 6 ++--- target/riscv/cpu.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ target/riscv/cpu.h | 1 + 5 files changed, 60 insertions(+), 13 deletions(-) diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index ec76dce6c9..2f227f15bc 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -171,7 +171,6 @@ static void create_fdt(SiFiveUState *s, const MemMapEnt= ry *memmap, int cpu_phandle =3D phandle++; nodename =3D g_strdup_printf("/cpus/cpu@%d", cpu); char *intc =3D g_strdup_printf("/cpus/cpu@%d/interrupt-controller"= , cpu); - char *isa; qemu_fdt_add_subnode(fdt, nodename); /* cpu 0 is the management hart that does not have mmu */ if (cpu !=3D 0) { @@ -180,11 +179,10 @@ static void create_fdt(SiFiveUState *s, const MemMapE= ntry *memmap, } else { qemu_fdt_setprop_string(fdt, nodename, "mmu-type", "riscv,= sv48"); } - isa =3D riscv_isa_string(&s->soc.u_cpus.harts[cpu - 1]); + riscv_isa_write_fdt(&s->soc.u_cpus.harts[cpu - 1], fdt, nodena= me); } else { - isa =3D riscv_isa_string(&s->soc.e_cpus.harts[0]); + riscv_isa_write_fdt(&s->soc.e_cpus.harts[0], fdt, nodename); } - qemu_fdt_setprop_string(fdt, nodename, "riscv,isa", isa); qemu_fdt_setprop_string(fdt, nodename, "compatible", "riscv"); qemu_fdt_setprop_string(fdt, nodename, "status", "okay"); qemu_fdt_setprop_cell(fdt, nodename, "reg", cpu); @@ -194,7 +192,6 @@ static void create_fdt(SiFiveUState *s, const MemMapEnt= ry *memmap, qemu_fdt_setprop_string(fdt, intc, "compatible", "riscv,cpu-intc"); qemu_fdt_setprop(fdt, intc, "interrupt-controller", NULL, 0); qemu_fdt_setprop_cell(fdt, intc, "#interrupt-cells", 1); - g_free(isa); g_free(intc); g_free(nodename); } diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c index 81f7e53aed..64074395bc 100644 --- a/hw/riscv/spike.c +++ b/hw/riscv/spike.c @@ -59,7 +59,7 @@ static void create_fdt(SpikeState *s, const MemMapEntry *= memmap, MachineState *ms =3D MACHINE(s); uint32_t *clint_cells; uint32_t cpu_phandle, intc_phandle, phandle =3D 1; - char *name, *mem_name, *clint_name, *clust_name; + char *mem_name, *clint_name, *clust_name; char *core_name, *cpu_name, *intc_name; static const char * const clint_compat[2] =3D { "sifive,clint0", "riscv,clint0" @@ -113,9 +113,7 @@ static void create_fdt(SpikeState *s, const MemMapEntry= *memmap, } else { qemu_fdt_setprop_string(fdt, cpu_name, "mmu-type", "riscv,= sv48"); } - name =3D riscv_isa_string(&s->soc[socket].harts[cpu]); - qemu_fdt_setprop_string(fdt, cpu_name, "riscv,isa", name); - g_free(name); + riscv_isa_write_fdt(&s->soc[socket].harts[cpu], fdt, cpu_name); qemu_fdt_setprop_string(fdt, cpu_name, "compatible", "riscv"); qemu_fdt_setprop_string(fdt, cpu_name, "status", "okay"); qemu_fdt_setprop_cell(fdt, cpu_name, "reg", diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index f9fd1341fc..c47b2d397a 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -215,7 +215,7 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, i= nt socket, int cpu; uint32_t cpu_phandle; MachineState *ms =3D MACHINE(s); - char *name, *cpu_name, *core_name, *intc_name, *sv_name; + char *cpu_name, *core_name, *intc_name, *sv_name; bool is_32_bit =3D riscv_is_32bit(&s->soc[0]); uint8_t satp_mode_max; =20 @@ -236,9 +236,7 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, i= nt socket, g_free(sv_name); } =20 - name =3D riscv_isa_string(cpu_ptr); - qemu_fdt_setprop_string(ms->fdt, cpu_name, "riscv,isa", name); - g_free(name); + riscv_isa_write_fdt(cpu_ptr, ms->fdt, cpu_name); =20 if (cpu_ptr->cfg.ext_zicbom) { qemu_fdt_setprop_cell(ms->fdt, cpu_name, "riscv,cbom-block-siz= e", diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 4aa4b2e988..0d6000f2a8 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -32,6 +32,7 @@ #include "hw/core/qdev-prop-internal.h" #include "migration/vmstate.h" #include "fpu/softfloat-helpers.h" +#include "sysemu/device_tree.h" #include "sysemu/kvm.h" #include "sysemu/tcg.h" #include "kvm/kvm_riscv.h" @@ -2352,6 +2353,58 @@ char *riscv_isa_string(RISCVCPU *cpu) return isa_str; } =20 +#ifndef CONFIG_USER_ONLY +static char **riscv_isa_extensions_list(RISCVCPU *cpu, int *count) +{ + int maxlen =3D ARRAY_SIZE(riscv_single_letter_exts) + ARRAY_SIZE(isa_e= data_arr); + char **extensions =3D g_new(char *, maxlen); + + for (int i =3D 0; i < sizeof(riscv_single_letter_exts) - 1; i++) { + if (cpu->env.misa_ext & RV(riscv_single_letter_exts[i])) { + extensions[*count] =3D g_new(char, 2); + snprintf(extensions[*count], 2, "%c", + qemu_tolower(riscv_single_letter_exts[i])); + (*count)++; + } + } + + for (const RISCVIsaExtData *edata =3D isa_edata_arr; edata->name; edat= a++) { + if (isa_ext_is_enabled(cpu, edata->ext_enable_offset)) { + extensions[*count] =3D g_strdup(edata->name); + (*count)++; + } + } + + return extensions; +} + +void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, char *nodename) +{ + const size_t maxlen =3D sizeof("rv128i"); + g_autofree char *isa_base =3D g_new(char, maxlen); + g_autofree char *riscv_isa; + char **isa_extensions; + int count =3D 0; + int xlen =3D riscv_cpu_max_xlen(cpu->env); + + riscv_isa =3D riscv_isa_string(cpu); + qemu_fdt_setprop_string(fdt, nodename, "riscv,isa", riscv_isa); + + snprintf(isa_base, maxlen, "rv%di", xlen); + qemu_fdt_setprop_string(fdt, nodename, "riscv,isa-base", isa_base); + + isa_extensions =3D riscv_isa_extensions_list(cpu, &count); + qemu_fdt_setprop_string_array(fdt, nodename, "riscv,isa-extensions", + isa_extensions, count); + + for (int i =3D 0; i < count; i++) { + g_free(isa_extensions[i]); + } + + g_free(isa_extensions); +} +#endif + #define DEFINE_CPU(type_name, initfn) \ { \ .name =3D type_name, \ diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index aacc031397..ce03d91b01 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -517,6 +517,7 @@ bool riscv_cpu_option_set(const char *optname); #define cpu_mmu_index riscv_cpu_mmu_index =20 #ifndef CONFIG_USER_ONLY +void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, char *nodename); void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr, unsigned size, MMUAccessType access_type, --=20 2.43.0