From nobody Sat Nov 15 22:32:02 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=1747739417; cv=none; d=zohomail.com; s=zohoarc; b=E/Qam/1znlnLgpcOINWw48wegFz7RLttjPkI7bHq0zFLUFuEzaDqrPD5d32oNWwCwz4A//ieuspWPbKAVFqxMDi1M+88NRbJqc0pl4poHCs2/3lKqz9aJl3SbH+V72YMEpuOFNnVxHEcjPFtx6/nUd9hB7eg2uBmIF7KfRvEnQw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747739417; 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=IlP2lhS81+uvghTLlJlc3pWMGTZTvlZCWSW9BG7siWs=; b=cpECVQyQjEDG/k9sZnzlFhj8xDrzocWfxLstk8zI2hO0Ph+pRzFgTYqtk4WgMaaH7bj3WV4W+8SWqBNtLPy/hh18BJYr5USaWU5xt4KZ2zD8Ci+HPqjw3H8imsF/eDm8S0OCX72tuOHCZVPZiHdz28OooUh0XVaIAT6goQHbvFc= 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 1747739417342583.696348414229; Tue, 20 May 2025 04:10:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uHKno-0000Rt-7x; 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 1uHKni-0008Sd-HL for qemu-devel@nongnu.org; Tue, 20 May 2025 07:06:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uHKng-0003F0-Kp for qemu-devel@nongnu.org; Tue, 20 May 2025 07:06:26 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-150-4RnYBLuKNsC4T6460vmM2g-1; Tue, 20 May 2025 07:06:22 -0400 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ad56c38dbeaso237090066b.0 for ; Tue, 20 May 2025 04:06:22 -0700 (PDT) Received: from [192.168.122.1] ([151.95.46.79]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ad52d271916sm721976166b.69.2025.05.20.04.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 May 2025 04:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747739184; 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=IlP2lhS81+uvghTLlJlc3pWMGTZTvlZCWSW9BG7siWs=; b=hwtW9tmjHpoyJ5A8VTLYv3YS1506NJcuwjAhwo/0SGIXAz4f8qI9dTU9h+UNurg7LLJ9Pf 1URIvmYMY4JA94F6RwfbGtLBLI5Vlo66vIZNetGtp5PEVUk5J92ZMJpE6ziKg4MXEUuj9d 9/wgUZq+dcJcHpVY03ioGyo5dKTqngk= X-MC-Unique: 4RnYBLuKNsC4T6460vmM2g-1 X-Mimecast-MFC-AGG-ID: 4RnYBLuKNsC4T6460vmM2g_1747739181 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747739180; x=1748343980; 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=IlP2lhS81+uvghTLlJlc3pWMGTZTvlZCWSW9BG7siWs=; b=PRpyRBxKJ/0IdMgFLHWrmJZQeOGKJUHj18lnKEPLRDKXeTrGarX0gDG40SUqIkwnbs GRrH3Mqy4XEMU4+x3dNfzI6W82SstVtlaTSkx+NXIiLVV3eZHObtULVV7G9n7IuRk3/D xGgS8QS871azUQnYV4DBh3Hbgp58hHdL4l2I3FmVYW5K7m/KOpfbO8VaNobAEAJjOK8p zoa6eqimM9UcgD0Wia1v3FXFNmq1IAQEW9FNH0IROLsk2BcmRoYzDJ3+Do4ecRuOTewy LF2VQqVJfNLSIoGHNYc31rqoAzXzju0s8HtYHNfVahVmSZZwAp93xfhQdnHRVjGUg5ac K/fQ== X-Gm-Message-State: AOJu0Yyb4BsBz/RM+PW5HTshPFPKuKd2xzIIagYJOIjTcP+RgZfNRplE heZWzjvwjpbW9B//SOGpKNWK4L0XLicV0cj8pPZeKFa3I3aiMPnTcabyzjBQvqnrKa9C4n9Dkxg ljPQa8rgI/ooNYmVT/09P59aRUUCs6IAiIjw0mPZkVRwul9JfjRvGdEkc1yvFvjIN8aaTj7MIUT 3Oikdml2s5J98I5HJNRlC6IRMGuWDPa6NILhKwLiBO X-Gm-Gg: ASbGncuT8tQXcEk58wjvwDaEhzXfohf13y2e2bt+BaWF6ZyqtmyddXS8LRYYoNqdxUv Kh/5GvynamKmlfYXqDEooHjqWWc0GKFOeE3ned1cop8EA44QpYrggAlWG3vEWGEko8F+OamyoOe pXltA9UTut7dFOozVN6GFB+Q+FELLDRoOf5RK0vq2dFGYJ7BPGMY5ATfovKgW6yU2ZVd7FWS44c R8isLCt0msOQ92IzQpraBcAv+t8tAbU/jxuwSebU4nen6hagZyOncqpWvslm53JP+ZtiDHvdAOt TNJko08AquWx2g== X-Received: by 2002:a17:907:97ca:b0:ace:cc7f:8abe with SMTP id a640c23a62f3a-ad536c22d77mr1336393066b.31.1747739179855; Tue, 20 May 2025 04:06:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjNeQQAM/zF/aDpbVwh+PLHjjWyJ9Pdk2e64I2dTGCjPWeMQIRNr8SK6hMyJ+kH93nVbQSPA== X-Received: by 2002:a17:907:97ca:b0:ace:cc7f:8abe with SMTP id a640c23a62f3a-ad536c22d77mr1336389766b.31.1747739179350; Tue, 20 May 2025 04:06:19 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Alistair Francis Subject: [PULL 21/35] target/riscv: convert abstract CPU classes to RISCVCPUDef Date: Tue, 20 May 2025 13:05:16 +0200 Message-ID: <20250520110530.366202-22-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.133.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: 1747739419839116600 Content-Type: text/plain; charset="utf-8" Start from the top of the hierarchy: dynamic and vendor CPUs are just markers, whereas bare CPUs can have their instance_init function replaced by RISCVCPUDef. The only difference is that the maximum supported SATP mode has to be specified separately for 32-bit and 64-bit modes. Reviewed-by: Alistair Francis Signed-off-by: Paolo Bonzini --- target/riscv/cpu.h | 1 + target/riscv/cpu.c | 93 ++++++++++++++++++++++------------------------ 2 files changed, 46 insertions(+), 48 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 29b01e9aa86..f3d70afb866 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -544,6 +544,7 @@ typedef struct RISCVCPUDef { int priv_spec; int32_t vext_spec; RISCVCPUConfig cfg; + bool bare; } RISCVCPUDef; =20 /** diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 634216870ed..7dcaf72fc14 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1474,8 +1474,8 @@ static void riscv_cpu_init(Object *obj) * for all CPUs. Each accelerator will decide what to do when * users disable them. */ - RISCV_CPU(obj)->cfg.ext_zicntr =3D true; - RISCV_CPU(obj)->cfg.ext_zihpm =3D true; + RISCV_CPU(obj)->cfg.ext_zicntr =3D !mcc->def->bare; + RISCV_CPU(obj)->cfg.ext_zihpm =3D !mcc->def->bare; =20 /* Default values for non-bool cpu properties */ cpu->cfg.pmu_mask =3D MAKE_64BIT_MASK(3, 16); @@ -1498,36 +1498,6 @@ static void riscv_cpu_init(Object *obj) } } =20 -static void riscv_bare_cpu_init(Object *obj) -{ - RISCVCPU *cpu =3D RISCV_CPU(obj); - - /* - * Bare CPUs do not inherit the timer and performance - * counters from the parent class (see riscv_cpu_init() - * for info on why the parent enables them). - * - * Users have to explicitly enable these counters for - * bare CPUs. - */ - cpu->cfg.ext_zicntr =3D false; - cpu->cfg.ext_zihpm =3D false; - - /* Set to QEMU's first supported priv version */ - cpu->env.priv_ver =3D PRIV_VERSION_1_10_0; - - /* - * Support all available satp_mode settings. The default - * value will be set to MBARE if the user doesn't set - * satp_mode manually (see set_satp_mode_default()). - */ -#ifndef CONFIG_USER_ONLY - set_satp_mode_max_supported(RISCV_CPU(obj), - riscv_cpu_mxl(&RISCV_CPU(obj)->env) =3D=3D MXL_RV32 ? - VM_1_10_SV32 : VM_1_10_SV57); -#endif -} - typedef struct misa_ext_info { const char *name; const char *description; @@ -3100,6 +3070,7 @@ static void riscv_cpu_class_base_init(ObjectClass *c,= const void *data) =20 if (data) { const RISCVCPUDef *def =3D data; + mcc->def->bare |=3D def->bare; if (def->misa_mxl_max) { assert(def->misa_mxl_max <=3D MXL_RV128); mcc->def->misa_mxl_max =3D def->misa_mxl_max; @@ -3253,6 +3224,19 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, c= har *nodename) }, \ } =20 +#define DEFINE_ABSTRACT_RISCV_CPU(type_name, parent_type_name, ...) \ + { \ + .name =3D (type_name), \ + .parent =3D (parent_type_name), \ + .abstract =3D true, \ + .class_data =3D &(const RISCVCPUDef) { \ + .priv_spec =3D RISCV_PROFILE_ATTR_UNUSED, \ + .vext_spec =3D RISCV_PROFILE_ATTR_UNUSED, \ + .cfg.max_satp_mode =3D -1, \ + __VA_ARGS__ \ + }, \ + } + #define DEFINE_PROFILE_CPU(type_name, misa_mxl_max_, initfn) \ { \ .name =3D (type_name), \ @@ -3279,22 +3263,35 @@ static const TypeInfo riscv_cpu_type_infos[] =3D { .class_init =3D riscv_cpu_common_class_init, .class_base_init =3D riscv_cpu_class_base_init, }, - { - .name =3D TYPE_RISCV_DYNAMIC_CPU, - .parent =3D TYPE_RISCV_CPU, - .abstract =3D true, - }, - { - .name =3D TYPE_RISCV_VENDOR_CPU, - .parent =3D TYPE_RISCV_CPU, - .abstract =3D true, - }, - { - .name =3D TYPE_RISCV_BARE_CPU, - .parent =3D TYPE_RISCV_CPU, - .instance_init =3D riscv_bare_cpu_init, - .abstract =3D true, - }, + + DEFINE_ABSTRACT_RISCV_CPU(TYPE_RISCV_DYNAMIC_CPU, TYPE_RISCV_CPU), + DEFINE_ABSTRACT_RISCV_CPU(TYPE_RISCV_VENDOR_CPU, TYPE_RISCV_CPU), + DEFINE_ABSTRACT_RISCV_CPU(TYPE_RISCV_BARE_CPU, TYPE_RISCV_CPU, + /* + * Bare CPUs do not inherit the timer and performance + * counters from the parent class (see riscv_cpu_init() + * for info on why the parent enables them). + * + * Users have to explicitly enable these counters for + * bare CPUs. + */ + .bare =3D true, + + /* Set to QEMU's first supported priv version */ + .priv_spec =3D PRIV_VERSION_1_10_0, + + /* + * Support all available satp_mode settings. By default + * only MBARE will be available if the user doesn't enable + * a mode manually (see riscv_cpu_satp_mode_finalize()). + */ +#ifdef TARGET_RISCV32 + .cfg.max_satp_mode =3D VM_1_10_SV32, +#else + .cfg.max_satp_mode =3D VM_1_10_SV57, +#endif + ), + #if defined(TARGET_RISCV32) DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_MAX, MXL_RV32, riscv_max_cpu_= init), #elif defined(TARGET_RISCV64) --=20 2.49.0