Received: by 2002:a17:906:5a52:b0:9d0:bf65:29fa with SMTP id my18csp2412335ejc; Tue, 14 Nov 2023 16:04:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEBXFCS9zsvD2LPkDWeDJdMCEYX8TmIK0XEWQSghbTG/cJRqDOv8Fr2dykohdzPyptQwLu X-Received: by 2002:a05:622a:296:b0:41c:b787:7bb with SMTP id z22-20020a05622a029600b0041cb78707bbmr4026202qtw.21.1700006661459; Tue, 14 Nov 2023 16:04:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700006661; cv=none; d=google.com; s=arc-20160816; b=KFl4S6sD1wuRUdhevDCRDV9mAh2vbZyE6QPNyzh1Tn8pN5iEC/V7HcfVrZyhAup1Xp JrufAPRQbgAXVOQ/XSfk82cBtAw8df+7gTEiQI3VAR7eXb3YNtBtbl+9sU5ZGsIScsLE 2Wp3V1rYw6m1HugXeek7Q7Afc3Uoi7Eyr3GFt16YPIEIuWK6MLh0DJzLadDTc0O0Ve4L TdB3qpFlwafCU1gerd4QsU9NM452KQxOqBVtmiI4DcGUNW6t9I0vRa0q04bQcVJfsRuX h2lIZvtGtrTr0LRK68calAtBtA8p253o+c94YZQx7x0I/87ECAujhE1rWukg9RSbrYN9 6vPQ== 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=mQSpWBUC1kwJ34qh0zAux7Kt73lQzg9r7Q8/AIyMDL4=; fh=/T6xqUCWHJxCL2odTXkl490KMICJmjWwCPOs7M5ODd4=; b=Eo4igB9zA60kZFiVdj26FJ4RJdOlg04ksyDL9K6XtV8xm8hCCZnq0NuIkll+j9E5Hh Gj2jxOXAPbH8v1eRFHZiQs7xs8CMtalgHYoMcg9LMLVrCpwoJjZ+yQFyKiXLiRil+9y6 ic6ymm/Zy8Z2V7t43L33dfUgD8p33wASUV5L2CcfmR3ERaZmDdlVi29jHYA5jsUmNivC YXBBnyeU0oRSZaHiLDlmjS398+7st6enngFder6Wc6DVhj/s/1vGb9jJx908c+Yidfno By7/ZIYsL107956RfGdZogPxIaBjOryKvVhWdDUX66HkTRt0P84hiVei38tPvMZ9UG8O MqyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Hxbt97AK; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d7-20020a05622a05c700b0041814a70625si7371368qtb.798.2023.11.14.16.04.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 Nov 2023 16:04:21 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+alex.bennee=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=@redhat.com header.s=mimecast20190719 header.b=Hxbt97AK; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r33N6-0000Gu-DD; Tue, 14 Nov 2023 19:03: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 1r33Mo-0008Tk-6n for qemu-devel@nongnu.org; Tue, 14 Nov 2023 19:02:54 -0500 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 1r33Mm-0008Ms-LX for qemu-devel@nongnu.org; Tue, 14 Nov 2023 19:02:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700006568; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mQSpWBUC1kwJ34qh0zAux7Kt73lQzg9r7Q8/AIyMDL4=; b=Hxbt97AK+hob/vnSJ/SiI0jRsBx07sxaNgn8+SrAAXs2yTmeCslGhu6ekN9I8p3CB+RITL biQj+kgM0J9qAsQafD1i6lcwpymAIQsz6u4S5IGQa3uWPEcKUVIT/VwwNxKwf1FZskbItL wKarJwhuTKHsto2juEpFDpIkhWrayF4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-25-Tkyawx-9PNCtB1x1EM0Ygg-1; Tue, 14 Nov 2023 19:02:41 -0500 X-MC-Unique: Tkyawx-9PNCtB1x1EM0Ygg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1F11B29ABA02; Wed, 15 Nov 2023 00:02:37 +0000 (UTC) Received: from gshan.redhat.com (unknown [10.64.136.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 05F09C15885; Wed, 15 Nov 2023 00:02:23 +0000 (UTC) From: Gavin Shan To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org, qemu-ppc@nongnu.org, imp@bsdimp.com, kevans@freebsd.org, richard.henderson@linaro.org, pbonzini@redhat.com, peter.maydell@linaro.org, imammedo@redhat.com, philmd@linaro.org, b.galvani@gmail.com, strahinja.p.jankovic@gmail.com, sundeep.lkml@gmail.com, kfting@nuvoton.com, wuhaotsh@google.com, nieklinnenbank@gmail.com, rad@semihalf.com, quic_llindhol@quicinc.com, marcin.juszkiewicz@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, wangyanan55@huawei.com, laurent@vivier.eu, vijai@behindbytes.com, palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, mrolnik@gmail.com, edgar.iglesias@gmail.com, bcain@quicinc.com, gaosong@loongson.cn, aurelien@aurel32.net, jiaxun.yang@flygoat.com, aleksandar.rikalo@syrmia.com, chenhuacai@kernel.org, shorne@gmail.com, npiggin@gmail.com, clg@kaod.org, ysato@users.sourceforge.jp, kbastian@mail.uni-paderborn.de, jcmvbkbc@gmail.com, shan.gavin@gmail.com Subject: [PATCH v5 25/31] machine: Introduce helper is_cpu_type_supported() Date: Wed, 15 Nov 2023 09:56:22 +1000 Message-ID: <20231114235628.534334-26-gshan@redhat.com> In-Reply-To: <20231114235628.534334-1-gshan@redhat.com> References: <20231114235628.534334-1-gshan@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 Received-SPF: pass client-ip=170.10.129.124; envelope-from=gshan@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+alex.bennee=linaro.org@nongnu.org Sender: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: +E0c40L5tpYK The logic, to check if the specified CPU type is supported in machine_run_board_init(), is independent enough. Factor it out into helper is_cpu_type_supported(). machine_run_board_init() looks a bit clean with this. Since we're here, @machine_class is renamed to @mc to avoid multiple line spanning of code. The comments are tweaked a bit either. No functional change intended. Signed-off-by: Gavin Shan --- hw/core/machine.c | 82 +++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index 5b45dbbbd5..49e0bc874d 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1387,13 +1387,51 @@ out: return r; } +static void is_cpu_type_supported(MachineState *machine, Error **errp) +{ + MachineClass *mc = MACHINE_GET_CLASS(machine); + ObjectClass *oc = object_class_by_name(machine->cpu_type); + CPUClass *cc; + int i; + + /* + * Check if the user specified CPU type is supported when the valid + * CPU types have been determined. Note that the user specified CPU + * type is provided through '-cpu' option. + */ + if (mc->valid_cpu_types && machine->cpu_type) { + for (i = 0; mc->valid_cpu_types[i]; i++) { + if (object_class_dynamic_cast(oc, mc->valid_cpu_types[i])) { + break; + } + } + + /* The user specified CPU type isn't valid */ + if (!mc->valid_cpu_types[i]) { + error_setg(errp, "Invalid CPU type: %s", machine->cpu_type); + error_append_hint(errp, "The valid types are: %s", + mc->valid_cpu_types[0]); + for (i = 1; mc->valid_cpu_types[i]; i++) { + error_append_hint(errp, ", %s", mc->valid_cpu_types[i]); + } + + error_append_hint(errp, "\n"); + return; + } + } + + /* Check if CPU type is deprecated and warn if so */ + cc = CPU_CLASS(oc); + if (cc && cc->deprecation_note) { + warn_report("CPU model %s is deprecated -- %s", + machine->cpu_type, cc->deprecation_note); + } +} void machine_run_board_init(MachineState *machine, const char *mem_path, Error **errp) { ERRP_GUARD(); MachineClass *machine_class = MACHINE_GET_CLASS(machine); - ObjectClass *oc = object_class_by_name(machine->cpu_type); - CPUClass *cc; Error *local_err = NULL; /* This checkpoint is required by replay to separate prior clock @@ -1449,42 +1487,10 @@ void machine_run_board_init(MachineState *machine, const char *mem_path, Error * machine->ram = machine_consume_memdev(machine, machine->memdev); } - /* If the machine supports the valid_cpu_types check and the user - * specified a CPU with -cpu check here that the user CPU is supported. - */ - if (machine_class->valid_cpu_types && machine->cpu_type) { - int i; - - for (i = 0; machine_class->valid_cpu_types[i]; i++) { - if (object_class_dynamic_cast(oc, - machine_class->valid_cpu_types[i])) { - /* The user specified CPU is in the valid field, we are - * good to go. - */ - break; - } - } - - if (!machine_class->valid_cpu_types[i]) { - /* The user specified CPU is not valid */ - error_setg(&local_err, "Invalid CPU type: %s", machine->cpu_type); - error_append_hint(&local_err, "The valid types are: %s", - machine_class->valid_cpu_types[0]); - for (i = 1; machine_class->valid_cpu_types[i]; i++) { - error_append_hint(&local_err, ", %s", - machine_class->valid_cpu_types[i]); - } - error_append_hint(&local_err, "\n"); - - error_propagate(errp, local_err); - } - } - - /* Check if CPU type is deprecated and warn if so */ - cc = CPU_CLASS(oc); - if (cc && cc->deprecation_note) { - warn_report("CPU model %s is deprecated -- %s", machine->cpu_type, - cc->deprecation_note); + /* Check if the CPU type is supported */ + is_cpu_type_supported(machine, &local_err); + if (local_err) { + error_propagate(errp, local_err); } if (machine->cgs) { -- 2.41.0