From patchwork Fri Sep 8 11:22:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 720803 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp706003wrp; Fri, 8 Sep 2023 04:25:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+0xII5nvL6XgOSA1VowOKiQikmQ/Y5k9rElewF2SGhl4cLgqedYWEmOXMA2BTV3gpOWb7 X-Received: by 2002:a05:620a:2486:b0:76f:14a9:56fe with SMTP id i6-20020a05620a248600b0076f14a956femr2499379qkn.58.1694172348170; Fri, 08 Sep 2023 04:25:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694172348; cv=none; d=google.com; s=arc-20160816; b=hSYe6T4CkoU5WslSucqRU6pD3yvJazB6v2A6ZAqsUMhDA36b+fbBDkmuGwrDUz8mur fS09PoDwjWpH4jHA4m+kLelJgTlhEPZjaP/PvPk9Kl+fgQVaLWIIUVNtRN/xhFZWzRHy pSn/hhn9U02hPqjkVQRxKelc08HRtE2OWnAqOw9MFvul5ld+GeHdbdUspgrqn1KzLxaD jWN59DJalUX0JrD36Bz+hSgifcmuPcZXL1ozrhz5/n44EhSmAtxSY1wliRXAM3H5M1xx cbrZaqfUWgOzaKOJUhHv7N3Lbuhq+bQjCugHyleP3OLuvWoqr+DPp9EQE0IqHyLgoGB5 czMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8QJ5w3av5aVa7TobyFf/rUr16JZ3iJ1jLRJ/icTXTIo=; fh=xrkPdSTzLfgAPR/xILKWCY/2YOP2wIq4k78J4mWio7M=; b=O09nX8Lfxe7rG71SIZlko5LTpiZD2Nnf3ozgrTitnaCZKZJ48G5fc3A9SE+mHdlBF2 SbxgqoPl/hK1uXfSdCXIhPxeSzG2rnuIm6CfJa2pGXuV+wBWiln1ewomTA3OQB5CCivd 9Kkn9ZkYxkAur40MJbw0ZRGTZPxGKAV9jZViB5JJN579lpmaM9dmQT5qNhdIWkx0HDZq 0HnDI2lQCbDGVlPLxH7UcR/DMxFrN8WdmlEyL42I1X0B/fB/JyzpyG0xUwJ0TX930HRV E4cNwUM/1OgAA+XL1qQiKyw9VWizE/04sD29yVhTu6HZUa36Cxtdc/tfmcjAdII0Zdq6 oeGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JLrzv4XW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w5-20020a05620a444500b007679d734e15si985825qkp.360.2023.09.08.04.25.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Sep 2023 04:25:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JLrzv4XW; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeZZq-0003oQ-Cb; Fri, 08 Sep 2023 07:23:06 -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 1qeZZo-0003nY-SY for qemu-devel@nongnu.org; Fri, 08 Sep 2023 07:23:04 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeZZk-0003a2-1Y for qemu-devel@nongnu.org; Fri, 08 Sep 2023 07:23:04 -0400 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-31c5c06e8bbso1859721f8f.1 for ; Fri, 08 Sep 2023 04:22:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694172178; x=1694776978; 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=8QJ5w3av5aVa7TobyFf/rUr16JZ3iJ1jLRJ/icTXTIo=; b=JLrzv4XWBYrQlM0vJPUNiDcZR4KROnCR/bmCvvLfx1Zi8xmNfwdJqtT+ZjFZm0np3B TdUU22cXwUVN3QW4jIet8NPOAuhYjSGs/xSJsYfuOjYJKTriEyXsC5OIrY5ti7Ia80Ki SwCz+O9o8P1oevT10d3Od50LuoRPO7o2qGzPK8oZ8GiU/yj2NXnGiKnVJG6zW1xG52c+ BMalRwFvyWxqxgo7TG57GA5Wnj3hYhePKOV0ix0BntHBuLpfPDDHL/D4l+mX93XLTKJP ls1iRu8FB/sicoNI4h/jKabNXcs5gNkGW+oi40ybG46Awwui5/a37LC28Zhu/6oNqZbt SUag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694172178; x=1694776978; 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=8QJ5w3av5aVa7TobyFf/rUr16JZ3iJ1jLRJ/icTXTIo=; b=KCh+UDvaLnC2AQavnyPR6ANgTBGu2DTA+P7720fl+D5WnFzGIOafqv0hcXkxW5kJym 6plcYGI2S4BnaJcSyTSuj71ufAC18Ob3D9MrdSCVKoEKy/qLFlrZ2/w4SGa7y+5s5KfG xrDyTZ5KECWccut5hN0uPlQka0uPYL9Zk2RSGn4/fBYCyNM6O/nqOWeoRCR5rpjD5Eoa lR1XlV70EqStUXJGepPoc4w4V+e14meM3MWUDW/I7hosZljPkruMj1XzgRsJRmW06Tcr lxjTPvxyQn2W49bkTM07VSrm9fQssQw1YA7kBTpskcJkvqlL+CVcUJD924kCCOfFqiAT f9Lg== X-Gm-Message-State: AOJu0Yy+nDmReqRR/4mwMb4gRdaZawbos2wdMw3mnKf/mbJGdsIplgTP rfBEfQe5CY81q5WnM7ORNy63IrpgKWMWGmnWgyQ= X-Received: by 2002:a5d:4e02:0:b0:313:f33c:24c4 with SMTP id p2-20020a5d4e02000000b00313f33c24c4mr1686380wrt.39.1694172178048; Fri, 08 Sep 2023 04:22:58 -0700 (PDT) Received: from m1x-phil.lan (lfb24-h01-176-173-167-175.dsl.sta.abo.bbox.fr. [176.173.167.175]) by smtp.gmail.com with ESMTPSA id c16-20020a5d4150000000b00317a29af4b2sm1850665wrq.68.2023.09.08.04.22.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 08 Sep 2023 04:22:57 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, David Hildenbrand , Gavin Shan Cc: Chris Wulff , David Gibson , qemu-s390x@nongnu.org, Weiwei Li , qemu-arm@nongnu.org, Mark Cave-Ayland , Jiaxun Yang , Yoshinori Sato , Richard Henderson , Marcel Apfelbaum , Max Filippov , Nicholas Piggin , Eduardo Habkost , Ilya Leoshkevich , Bastian Koppelmann , Greg Kurz , "Edgar E. Iglesias" , qemu-ppc@nongnu.org, Daniel Henrique Barboza , Marek Vasut , Palmer Dabbelt , Michael Rolnik , Laurent Vivier , Peter Maydell , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , qemu-riscv@nongnu.org, Aurelien Jarno , Bin Meng , Xiaojuan Yang , Daniel Henrique Barboza , Aleksandar Rikalo , Artyom Tarasenko , Song Gao , Stafford Horne , Yanan Wang , Alistair Francis , Brian Cain , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Thomas Huth , Liu Zhiwei Subject: [PATCH 2/4] hw/cpu: Call object_class_is_abstract() once in cpu_class_by_name() Date: Fri, 8 Sep 2023 13:22:32 +0200 Message-ID: <20230908112235.75914-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230908112235.75914-1-philmd@linaro.org> References: <20230908112235.75914-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=philmd@linaro.org; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Let CPUClass::class_by_name() handlers to return abstract classes, and filter them once in the public cpu_class_by_name() method. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- include/hw/core/cpu.h | 7 ++++--- hw/core/cpu-common.c | 14 +++++++++++--- target/arm/cpu.c | 3 +-- target/avr/cpu.c | 3 +-- target/cris/cpu.c | 3 +-- target/hexagon/cpu.c | 3 +-- target/loongarch/cpu.c | 3 +-- target/m68k/cpu.c | 3 +-- target/openrisc/cpu.c | 3 +-- target/riscv/cpu.c | 3 +-- target/rx/cpu.c | 6 +----- target/sh4/cpu.c | 3 --- target/tricore/cpu.c | 3 +-- target/xtensa/cpu.c | 3 +-- 14 files changed, 26 insertions(+), 34 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 92a4234439..129d179937 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -101,7 +101,7 @@ struct SysemuCPUOps; /** * CPUClass: * @class_by_name: Callback to map -cpu command line model name to an - * instantiatable CPU type. + * instantiatable CPU type. * @parse_features: Callback to parse command line arguments. * @reset_dump_flags: #CPUDumpFlags to use for reset logging. * @has_work: Callback for checking if there is work to do. @@ -630,9 +630,10 @@ void cpu_reset(CPUState *cpu); * @typename: The CPU base type. * @cpu_model: The model string without any parameters. * - * Looks up a CPU #ObjectClass matching name @cpu_model. + * Looks up a concrete CPU #ObjectClass matching name @cpu_model. * - * Returns: A #CPUClass or %NULL if not matching class is found. + * Returns: A concrete #CPUClass or %NULL if no matching class is found + * or if the matching class is abstract. */ ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model); diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index ced66c2b34..c6a0c9390c 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -149,10 +149,18 @@ static bool cpu_common_has_work(CPUState *cs) ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model) { - CPUClass *cc = CPU_CLASS(object_class_by_name(typename)); + ObjectClass *oc; + CPUClass *cc; - assert(cpu_model && cc->class_by_name); - return cc->class_by_name(cpu_model); + assert(cpu_model); + oc = object_class_by_name(typename); + cc = CPU_CLASS(oc); + assert(cc->class_by_name); + oc = cc->class_by_name(cpu_model); + if (oc == NULL || object_class_is_abstract(oc)) { + return NULL; + } + return oc; } static void cpu_common_parse_features(const char *typename, char *features, diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 0bb0585441..42e29816cc 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2300,8 +2300,7 @@ static ObjectClass *arm_cpu_class_by_name(const char *cpu_model) oc = object_class_by_name(typename); g_strfreev(cpuname); g_free(typename); - if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU) || - object_class_is_abstract(oc)) { + if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU)) { return NULL; } return oc; diff --git a/target/avr/cpu.c b/target/avr/cpu.c index 8f741f258c..4b255eade1 100644 --- a/target/avr/cpu.c +++ b/target/avr/cpu.c @@ -159,8 +159,7 @@ static ObjectClass *avr_cpu_class_by_name(const char *cpu_model) ObjectClass *oc; oc = object_class_by_name(cpu_model); - if (object_class_dynamic_cast(oc, TYPE_AVR_CPU) == NULL || - object_class_is_abstract(oc)) { + if (object_class_dynamic_cast(oc, TYPE_AVR_CPU) == NULL) { oc = NULL; } return oc; diff --git a/target/cris/cpu.c b/target/cris/cpu.c index a6a93c2359..115f6e2ea2 100644 --- a/target/cris/cpu.c +++ b/target/cris/cpu.c @@ -95,8 +95,7 @@ static ObjectClass *cris_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(CRIS_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_CRIS_CPU) || - object_class_is_abstract(oc))) { + if (oc != NULL && !object_class_dynamic_cast(oc, TYPE_CRIS_CPU)) { oc = NULL; } return oc; diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index f155936289..5e301327d3 100644 --- a/target/hexagon/cpu.c +++ b/target/hexagon/cpu.c @@ -63,8 +63,7 @@ static ObjectClass *hexagon_cpu_class_by_name(const char *cpu_model) oc = object_class_by_name(typename); g_strfreev(cpuname); g_free(typename); - if (!oc || !object_class_dynamic_cast(oc, TYPE_HEXAGON_CPU) || - object_class_is_abstract(oc)) { + if (!oc || !object_class_dynamic_cast(oc, TYPE_HEXAGON_CPU)) { return NULL; } return oc; diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index 65f9320e34..fe2e5ecc46 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -646,8 +646,7 @@ static ObjectClass *loongarch_cpu_class_by_name(const char *cpu_model) } } - if (object_class_dynamic_cast(oc, TYPE_LOONGARCH_CPU) - && !object_class_is_abstract(oc)) { + if (object_class_dynamic_cast(oc, TYPE_LOONGARCH_CPU)) { return oc; } return NULL; diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c index 70d58471dc..004f3d6265 100644 --- a/target/m68k/cpu.c +++ b/target/m68k/cpu.c @@ -111,8 +111,7 @@ static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(M68K_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (oc != NULL && (object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL || - object_class_is_abstract(oc))) { + if (oc != NULL && object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL) { return NULL; } return oc; diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c index 61d748cfdc..3bbbcc4e63 100644 --- a/target/openrisc/cpu.c +++ b/target/openrisc/cpu.c @@ -168,8 +168,7 @@ static ObjectClass *openrisc_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(OPENRISC_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_OPENRISC_CPU) || - object_class_is_abstract(oc))) { + if (oc != NULL && !object_class_dynamic_cast(oc, TYPE_OPENRISC_CPU)) { return NULL; } return oc; diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 6b93b04453..17b00eb7c0 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -619,8 +619,7 @@ static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model) oc = object_class_by_name(typename); g_strfreev(cpuname); g_free(typename); - if (!oc || !object_class_dynamic_cast(oc, TYPE_RISCV_CPU) || - object_class_is_abstract(oc)) { + if (!oc || !object_class_dynamic_cast(oc, TYPE_RISCV_CPU)) { return NULL; } return oc; diff --git a/target/rx/cpu.c b/target/rx/cpu.c index 157e57da0f..c98034540d 100644 --- a/target/rx/cpu.c +++ b/target/rx/cpu.c @@ -111,16 +111,12 @@ static ObjectClass *rx_cpu_class_by_name(const char *cpu_model) char *typename; oc = object_class_by_name(cpu_model); - if (oc != NULL && object_class_dynamic_cast(oc, TYPE_RX_CPU) != NULL && - !object_class_is_abstract(oc)) { + if (oc != NULL && object_class_dynamic_cast(oc, TYPE_RX_CPU) != NULL) { return oc; } typename = g_strdup_printf(RX_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (oc != NULL && object_class_is_abstract(oc)) { - oc = NULL; - } return oc; } diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c index 61769ffdfa..bc112776fc 100644 --- a/target/sh4/cpu.c +++ b/target/sh4/cpu.c @@ -152,9 +152,6 @@ static ObjectClass *superh_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(SUPERH_CPU_TYPE_NAME("%s"), s); oc = object_class_by_name(typename); - if (oc != NULL && object_class_is_abstract(oc)) { - oc = NULL; - } out: g_free(s); diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c index 133a9ac70e..a2381b0dc1 100644 --- a/target/tricore/cpu.c +++ b/target/tricore/cpu.c @@ -140,8 +140,7 @@ static ObjectClass *tricore_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(TRICORE_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (!oc || !object_class_dynamic_cast(oc, TYPE_TRICORE_CPU) || - object_class_is_abstract(oc)) { + if (!oc || !object_class_dynamic_cast(oc, TYPE_TRICORE_CPU)) { return NULL; } return oc; diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c index acaf8c905f..a31825a2b5 100644 --- a/target/xtensa/cpu.c +++ b/target/xtensa/cpu.c @@ -141,8 +141,7 @@ static ObjectClass *xtensa_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(XTENSA_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (oc == NULL || !object_class_dynamic_cast(oc, TYPE_XTENSA_CPU) || - object_class_is_abstract(oc)) { + if (oc == NULL || !object_class_dynamic_cast(oc, TYPE_XTENSA_CPU)) { return NULL; } return oc;