From nobody Sat Nov 15 22:33:41 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1747741069; cv=none; d=zohomail.com; s=zohoarc; b=hMGbyf22zJlA2h/DNmxD6DCTxwnlVjovy4HYPJHFnnNdBkoihAMY43hJtOQxFlT6CWY7pjEt/epiU5eNl1AF03rnf1l5A6IS83NtubL4YFzaMHAnRAaVJcCF6lt4PG3eFvt5xjdFIJoDa8tzpEJIevp1bwYxuXBYl2Gb4OhhUhE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747741069; 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=wAk3VJycK08RmuxbhLOpqsKTeVaRPtp4EDzgHmUZ2g8=; b=Uz0p5gcHS+iQ7XbgRkRvnbxBCGBUoif+CyBjOPhnbo4wUUv7V+ZwowZZ+cp105aV7YRkVVMRQsjf/jl72DvEHX9GrlbbwHym2uIBYdp7FX9Dy9y5BMgptI24rmP2f2tQT949LPqnZKRKqWIHB20Pld3Kjo74+58Um1QUTANgJ9w= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747741069525131.22841751906674; Tue, 20 May 2025 04:37:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uHKnn-0000Od-Pi; Tue, 20 May 2025 07:06:32 -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 1uHKnh-0008Mq-6x for qemu-devel@nongnu.org; Tue, 20 May 2025 07:06:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uHKne-0003EG-TS for qemu-devel@nongnu.org; Tue, 20 May 2025 07:06:24 -0400 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-427-Jm4sCJ7RNQSP_ZPPg1X-Kw-1; Tue, 20 May 2025 07:06:21 -0400 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-ac6ef2d1b7dso429027366b.0 for ; Tue, 20 May 2025 04:06:20 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad52d490794sm718639166b.131.2025.05.20.04.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 May 2025 04:06:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747739182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wAk3VJycK08RmuxbhLOpqsKTeVaRPtp4EDzgHmUZ2g8=; b=ciY3Gev5iDdk2/tIHXbaTIGkszuFGJgL5RXWimVt76AvXJMnpMQHZTbZdk1R5l8t4oi11v r752ApaiBtn8rJvev9AWLF6d0vaCp9x872t70Yqu6RkH/b/kXPQDhMGVl75d0p1eP9xB7y KB4jHX7k6NqCYsnCmYVdi5V9g2jMQPw= X-MC-Unique: Jm4sCJ7RNQSP_ZPPg1X-Kw-1 X-Mimecast-MFC-AGG-ID: Jm4sCJ7RNQSP_ZPPg1X-Kw_1747739180 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747739179; x=1748343979; 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=wAk3VJycK08RmuxbhLOpqsKTeVaRPtp4EDzgHmUZ2g8=; b=PEyB+VCX8wCydd086CxDOiAFcA6+2OAettGHn0O60dZHvOkNhH7+A7oJx94aDeWmbk rEY3r9tTiae1u6tRoE17TDMauhSEdXETJ+/xqIyqNbm6/grKCu4iRTx/Zib68yI3WHgp fQ8v1FIQGkdJVX0HxYv5H7jnCo1CreRTyfbq2fDRUVHy2wrWchtLoibaIYAyzEhwVhg7 06b/ZqST1XWZgVT6wNufXMY2V3PIYQykIxcErj+cZ3k+QTu15kSHlFmRbazQbJwr9YNz 351IMiaDnaQ3sqYjeeDn+lGZPnLuEjVcvmRPSgVMEopKOebS/20DjYjP51mHLPGbJJyc aCyA== X-Gm-Message-State: AOJu0YzfMUu9L9nqJMV0idGOqLQPmqZxOFQVwGttjiHTDtubrdnS6rpw TA1l4nZqj/6fuVLKz5tcQRCMW8IJvIdGRiiwH/hW7bJXT+dAM/UkpDWU/WpwpzvlPOm/bjTo6Kt Vl/QvSVqiFmmM9D3PVHIcHF7ePlB4UhaO+PyD7nZpBJoyf47HmNWl880neL2w7MdJpcYta1rqzU Y+O4x2Zg8uV0wFFk26InkpeR1GN+oL7cRIzS2maLqC X-Gm-Gg: ASbGncu5YstQgBhIYfq8/0zDfnAPZvFKBE0Zdb4nc062pLuO+jmOiOCXQ7UuWV4+YN7 HxK+TYrUqXEJ/2YHu+VyBnOzETTxHA3o8wu41sye/twmR4HzyyslBSSxWG9Ambp02KC5/JGDNxV a0fAOQUN/EhN8+5Ye08nElDl45vkU9ursjtjkEhhQwL8/UD9UXbiOkPYAtu13D6MTQwcJ/yPavE k3IrLP+ruCfuocLIEMXvPm18Wn30FBQPMzXHnc5JGF18sICYqg3Wk1+WA3wNMzndhdGNBve4Oi8 laXQh9OKob90bg== X-Received: by 2002:a17:907:3e20:b0:ad5:6d1a:6fa4 with SMTP id a640c23a62f3a-ad56d1a72c0mr705556766b.44.1747739178648; Tue, 20 May 2025 04:06:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+lsNnPhSldruvQx3pEXqHfvs0QzXpXaF+W6k25TWWTk0YO/Fv75HOdqGG+XhNQU5i4oHx2g== X-Received: by 2002:a17:907:3e20:b0:ad5:6d1a:6fa4 with SMTP id a640c23a62f3a-ad56d1a72c0mr705552966b.44.1747739178159; Tue, 20 May 2025 04:06:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Alistair Francis Subject: [PULL 20/35] target/riscv: add more RISCVCPUDef fields Date: Tue, 20 May 2025 13:05:15 +0200 Message-ID: <20250520110530.366202-21-pbonzini@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250520110530.366202-1-pbonzini@redhat.com> References: <20250520110530.366202-1-pbonzini@redhat.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=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.487, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1747741072010116600 Content-Type: text/plain; charset="utf-8" Allow using RISCVCPUDef to replicate all the logic of custom .instance_init functions. To simulate inheritance, merge the child's RISCVCPUDef with the parent and then finally move it to the CPUState at the end of TYPE_RISCV_CPU's own instance_init function. Reviewed-by: Alistair Francis Signed-off-by: Paolo Bonzini --- target/riscv/cpu.h | 4 ++++ target/riscv/cpu.c | 42 +++++++++++++++++++++++++++++++++++++- target/riscv/kvm/kvm-cpu.c | 6 ++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index d2d4db95c17..29b01e9aa86 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -540,6 +540,10 @@ struct ArchCPU { =20 typedef struct RISCVCPUDef { RISCVMXL misa_mxl_max; /* max mxl for this cpu */ + uint32_t misa_ext; + int priv_spec; + int32_t vext_spec; + RISCVCPUConfig cfg; } RISCVCPUDef; =20 /** diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 334791eebdf..634216870ed 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -73,6 +73,13 @@ bool riscv_cpu_option_set(const char *optname) return g_hash_table_contains(general_user_opts, optname); } =20 +static void riscv_cpu_cfg_merge(RISCVCPUConfig *dest, const RISCVCPUConfig= *src) +{ +#define BOOL_FIELD(x) dest->x |=3D src->x; +#define TYPED_FIELD(type, x, default_) if (src->x !=3D default_) dest->x = =3D src->x; +#include "cpu_cfg_fields.h.inc" +} + #define ISA_EXT_DATA_ENTRY(_name, _min_ver, _prop) \ {#_name, _min_ver, CPU_CFG_OFFSET(_prop)} =20 @@ -434,7 +441,7 @@ const char *satp_mode_str(uint8_t satp_mode, bool is_32= _bit) } =20 static void set_satp_mode_max_supported(RISCVCPU *cpu, - uint8_t satp_mode) + int satp_mode) { bool rv32 =3D riscv_cpu_mxl(&cpu->env) =3D=3D MXL_RV32; const bool *valid_vm =3D rv32 ? valid_vm_1_10_32 : valid_vm_1_10_64; @@ -1479,6 +1486,16 @@ static void riscv_cpu_init(Object *obj) cpu->cfg.cboz_blocksize =3D 64; cpu->env.vext_ver =3D VEXT_VERSION_1_00_0; cpu->cfg.max_satp_mode =3D -1; + + env->misa_ext_mask =3D env->misa_ext =3D mcc->def->misa_ext; + riscv_cpu_cfg_merge(&cpu->cfg, &mcc->def->cfg); + + if (mcc->def->priv_spec !=3D RISCV_PROFILE_ATTR_UNUSED) { + cpu->env.priv_ver =3D mcc->def->priv_spec; + } + if (mcc->def->vext_spec !=3D RISCV_PROFILE_ATTR_UNUSED) { + cpu->env.vext_ver =3D mcc->def->vext_spec; + } } =20 static void riscv_bare_cpu_init(Object *obj) @@ -3087,6 +3104,17 @@ static void riscv_cpu_class_base_init(ObjectClass *c= , const void *data) assert(def->misa_mxl_max <=3D MXL_RV128); mcc->def->misa_mxl_max =3D def->misa_mxl_max; } + if (def->priv_spec !=3D RISCV_PROFILE_ATTR_UNUSED) { + assert(def->priv_spec <=3D PRIV_VERSION_LATEST); + mcc->def->priv_spec =3D def->priv_spec; + } + if (def->vext_spec !=3D RISCV_PROFILE_ATTR_UNUSED) { + assert(def->vext_spec !=3D 0); + mcc->def->vext_spec =3D def->vext_spec; + } + mcc->def->misa_ext |=3D def->misa_ext; + + riscv_cpu_cfg_merge(&mcc->def->cfg, &def->cfg); } =20 if (!object_class_is_abstract(c)) { @@ -3193,6 +3221,9 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, ch= ar *nodename) .instance_init =3D (initfn), \ .class_data =3D &(const RISCVCPUDef) { \ .misa_mxl_max =3D (misa_mxl_max_), \ + .priv_spec =3D RISCV_PROFILE_ATTR_UNUSED, \ + .vext_spec =3D RISCV_PROFILE_ATTR_UNUSED, \ + .cfg.max_satp_mode =3D -1, \ }, \ } =20 @@ -3203,6 +3234,9 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, ch= ar *nodename) .instance_init =3D (initfn), \ .class_data =3D &(const RISCVCPUDef) { \ .misa_mxl_max =3D (misa_mxl_max_), \ + .priv_spec =3D RISCV_PROFILE_ATTR_UNUSED, \ + .vext_spec =3D RISCV_PROFILE_ATTR_UNUSED, \ + .cfg.max_satp_mode =3D -1, \ }, \ } =20 @@ -3213,6 +3247,9 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, ch= ar *nodename) .instance_init =3D (initfn), \ .class_data =3D &(const RISCVCPUDef) { \ .misa_mxl_max =3D (misa_mxl_max_), \ + .priv_spec =3D RISCV_PROFILE_ATTR_UNUSED, \ + .vext_spec =3D RISCV_PROFILE_ATTR_UNUSED, \ + .cfg.max_satp_mode =3D -1, \ }, \ } =20 @@ -3223,6 +3260,9 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, ch= ar *nodename) .instance_init =3D (initfn), \ .class_data =3D &(const RISCVCPUDef) { \ .misa_mxl_max =3D (misa_mxl_max_), \ + .priv_spec =3D RISCV_PROFILE_ATTR_UNUSED, \ + .vext_spec =3D RISCV_PROFILE_ATTR_UNUSED, \ + .cfg.max_satp_mode =3D -1, \ }, \ } =20 diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c index e77f612af35..efb41fac53e 100644 --- a/target/riscv/kvm/kvm-cpu.c +++ b/target/riscv/kvm/kvm-cpu.c @@ -2093,10 +2093,16 @@ static const TypeInfo riscv_kvm_cpu_type_infos[] = =3D { #if defined(TARGET_RISCV32) .class_data =3D &(const RISCVCPUDef) { .misa_mxl_max =3D MXL_RV32, + .priv_spec =3D RISCV_PROFILE_ATTR_UNUSED, + .vext_spec =3D RISCV_PROFILE_ATTR_UNUSED, + .cfg.max_satp_mode =3D -1, }, #elif defined(TARGET_RISCV64) .class_data =3D &(const RISCVCPUDef) { .misa_mxl_max =3D MXL_RV64, + .priv_spec =3D RISCV_PROFILE_ATTR_UNUSED, + .vext_spec =3D RISCV_PROFILE_ATTR_UNUSED, + .cfg.max_satp_mode =3D -1, }, #endif } --=20 2.49.0