From nobody Tue May 14 23:14:33 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 ARC-Seal: i=1; a=rsa-sha256; t=1645610013; cv=none; d=zohomail.com; s=zohoarc; b=XtvxuPdbCft7s32bm5cm0kuauQX82lO7RYurz0TdjmdItOKpiZpfrsDbMxnQf2G+JnOVPIVQY1KoLgsyPJkq8pvukKuGBH1UTqRPMEIZElmsSSHEBeCWRO1nRPcfLpZ2ETeK/e+O29NvP8LRBq/x8eMi17zOglG6PqfSO9J5GYY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645610013; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FZWF8zdWv3oxTpKzce+G0IL5UnOX2sfeDOvbB9FkH8s=; b=TboENfi8WB/XUUu3cnOQfzwuo2ouTMnQSfGu4U2JNta1OpSJ4shs1U3mEUVoFyN78OiIIVj2BPxEUKE5L9DYCnDG4l1/lcmc7Mnb0Id8Bz16zLXGPnQbG5OAb+JXM/2+110p3CcvCPhz74CfC5NruHgbv2yoDi94wU1LbUvFg/M= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645610013786117.9771966046128; Wed, 23 Feb 2022 01:53:33 -0800 (PST) Received: from localhost ([::1]:60406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMoKy-0001nA-FG for importer@patchew.org; Wed, 23 Feb 2022 04:53:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMncc-0001Tw-EL for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:48 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50176) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMncP-0001zO-Qc for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:36 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 1043221C36; Wed, 23 Feb 2022 09:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607237; 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=FZWF8zdWv3oxTpKzce+G0IL5UnOX2sfeDOvbB9FkH8s=; b=srEBmfvUH4+v0bT36pQ8mXdeNYKa4Hqlk06CMeqnwPz0OlOlWtBA9lr9kyydCWoKwyRgg0 W5rUEunRvV2q2ndEn2szLo/8f43bwzAZt4Koe2LnAHDWBVK26rF/aihggJ7XAH9ppJPxTl QZ55sPXcUZQfl7500gOw/TA/AqjjE8U= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 01/14] machine: add phase_get() and document phase_check()/advance() Date: Wed, 23 Feb 2022 10:06:53 +0100 Message-Id: <20220223090706.4888-2-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1645610016385100001 Content-Type: text/plain; charset="utf-8" phase_get() returns the current phase, we'll use it in next commit. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/qdev-core.h | 19 +++++++++++++++++++ hw/core/qdev.c | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 92c3d65208..e29c705b74 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -887,7 +887,26 @@ typedef enum MachineInitPhase { PHASE_MACHINE_READY, } MachineInitPhase; =20 +/* + * phase_get: + * Returns the current phase + */ +MachineInitPhase phase_get(void); + +/** + * phase_check: + * Test if current phase is at least @phase. + * + * Returns true if this is the case. + */ extern bool phase_check(MachineInitPhase phase); + +/** + * @phase_advance: + * Update the current phase to @phase. + * + * Must only be used to make a single phase step. + */ extern void phase_advance(MachineInitPhase phase); =20 #endif diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 84f3019440..632dc0a4be 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -910,6 +910,11 @@ Object *qdev_get_machine(void) =20 static MachineInitPhase machine_phase; =20 +MachineInitPhase phase_get(void) +{ + return machine_phase; +} + bool phase_check(MachineInitPhase phase) { return machine_phase >=3D phase; --=20 2.35.1 From nobody Tue May 14 23:14:33 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 ARC-Seal: i=1; a=rsa-sha256; t=1645607896; cv=none; d=zohomail.com; s=zohoarc; b=FPXu3sKA8Q5WyUBn8yKV7xlZIqat9qGq5RF6I8plWO8B8LkxgAFqCp3kMrBBPSStYWSrmowoiML7msUINnapTND30kx6e/8/s8yF9Izjn6kapTeQnTAnunTYSCWunIsbXqQtt7ZUX0GCHxVPV6xkV1IaNGbz1lPjhXVvIt4soqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645607896; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+m1uLGIgItw9aGthsOYxemQYeg02WFewRFIsl1QPD3o=; b=TIj8LvfYFWA0ntYSc2Yopk5jmUGhnTk6sOxyPHTEwclFxGkAmupK72lg6GRVRFAMUYSZdwHWDbeYvKdQYvj4IdRwmPxmwXnWdOAB7AZxzUHUVsElFWsJvQ8/vIG8rm3IHccPpP2qK8oI//KFTJgemnkzbzJXD35dBOZZWvhPepY= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645607896735377.34998306318096; Wed, 23 Feb 2022 01:18:16 -0800 (PST) Received: from localhost ([::1]:59856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMnmp-0005A5-AV for importer@patchew.org; Wed, 23 Feb 2022 04:18:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMncc-0001Tz-EI for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:48 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50186) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMncP-0001zQ-Qd for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:36 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 996BB21C38; Wed, 23 Feb 2022 09:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607237; 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=+m1uLGIgItw9aGthsOYxemQYeg02WFewRFIsl1QPD3o=; b=mxrDsNA+uZNHClQjMbaUgXzMbe+zqM7XPLnp3xA+9uGZalO5wa5GfwRUpRBzGhTIUTUYYD uGwH4w2/awJPKbBjDTpjvyU6smDges59ybfAnRZaHosaWttXr3C9R+WW2bh45SeECR5p2H EuBLKoFmM9mjxZfXKZlhQkE7sICM96Q= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 02/14] machine&vl: introduce phase_until() to handle phase transitions Date: Wed, 23 Feb 2022 10:06:54 +0100 Message-Id: <20220223090706.4888-3-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1645607898972100003 Content-Type: text/plain; charset="utf-8" phase_until() is implemented in vl.c and is meant to be used to make startup progress up to a specified phase being reached(). At this point, no behavior change is introduced: phase_until() only supports a single double transition corresponding to the functionality of qmp_exit_preconfig(): + accel-created -> machine-initialized -> machine-ready As a result qmp_exit_preconfig() now uses phase_until(). This commit is a preparation to support cold plugging a device using qapi command (which will be introduced in a following commit). For this we need fine grain control of the phase. Signed-off-by: Damien Hedde --- include/hw/qdev-core.h | 14 ++++++++ softmmu/vl.c | 78 ++++++++++++++++++++++++++++++++---------- 2 files changed, 74 insertions(+), 18 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index e29c705b74..5f73d06408 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -909,4 +909,18 @@ extern bool phase_check(MachineInitPhase phase); */ extern void phase_advance(MachineInitPhase phase); =20 +/** + * @phase_until: + * @phase: the target phase + * @errp: error report + * + * Make the machine init progress until the target phase is reached. + * + * Its is a no-op is the target phase is the current or an earlier + * phase. + * + * Returns true in case of success. + */ +extern bool phase_until(MachineInitPhase phase, Error **errp); + #endif diff --git a/softmmu/vl.c b/softmmu/vl.c index 5e1b35ba48..5689d0be88 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2741,30 +2741,72 @@ void qmp_x_exit_preconfig(Error **errp) error_setg(errp, "The command is permitted only before machine ini= tialization"); return; } + phase_until(PHASE_MACHINE_READY, errp); +} =20 - qemu_init_board(); - qemu_create_cli_devices(); - qemu_machine_creation_done(); - - if (loadvm) { - load_snapshot(loadvm, NULL, false, NULL, &error_fatal); - } - if (replay_mode !=3D REPLAY_MODE_NONE) { - replay_vmstate_init(); +bool phase_until(MachineInitPhase phase, Error **errp) +{ + if (!phase_check(PHASE_ACCEL_CREATED)) { + error_setg(errp, "Phase transition is not supported until accelera= tor" + " is created"); + return false; } =20 - if (incoming) { - Error *local_err =3D NULL; - if (strcmp(incoming, "defer") !=3D 0) { - qmp_migrate_incoming(incoming, &local_err); - if (local_err) { - error_reportf_err(local_err, "-incoming %s: ", incoming); - exit(1); + while (!phase_check(phase)) { + MachineInitPhase cur_phase =3D phase_get(); + + switch (cur_phase) { + case PHASE_ACCEL_CREATED: + qemu_init_board(); + /* We are now in PHASE_MACHINE_INITIALIZED. */ + qemu_create_cli_devices(); + /* + * At this point all CLI options are handled apart: + * + -S (autostart) + * + -incoming + */ + qemu_machine_creation_done(); + /* We are now in PHASE_MACHINE_READY. */ + + if (loadvm) { + load_snapshot(loadvm, NULL, false, NULL, &error_fatal); } + if (replay_mode !=3D REPLAY_MODE_NONE) { + replay_vmstate_init(); + } + + if (incoming) { + Error *local_err =3D NULL; + if (strcmp(incoming, "defer") !=3D 0) { + qmp_migrate_incoming(incoming, &local_err); + if (local_err) { + error_reportf_err(local_err, "-incoming %s: ", + incoming); + exit(1); + } + } + } else if (autostart) { + qmp_cont(NULL); + } + break; + + default: + /* + * If we end up here, it is because we miss a case above. + */ + error_setg(&error_abort, "Requested phase transition is not" + " implemented"); + return false; } - } else if (autostart) { - qmp_cont(NULL); + + /* + * Ensure we made some progress. + * With the default case above, it should be enough to prevent + * any infinite loop. + */ + assert(cur_phase < phase_get()); } + return true; } =20 void qemu_init(int argc, char **argv, char **envp) --=20 2.35.1 From nobody Tue May 14 23:14:33 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 ARC-Seal: i=1; a=rsa-sha256; t=1645609790; cv=none; d=zohomail.com; s=zohoarc; b=e9YwEXrlgxaUhESkiXvsXoawAmIYsnEqruzlLoahAeRgB0XapAyEweqIDhDEJsZL5vvEabmyxOCdJ+DzFydaYJtZJ9Q1JV8r6VvEDwaFM1NtT77AlQPRpu8d5xiI91Af9r+6yZiyfilKD/peON3Ncecb8OrV65AH3D2qiwauTJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645609790; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fK//uTVRDEVguoVlIYMceoQvqPjIUKZhtPzueFDLdN8=; b=PY3df6aM3rD2zKTYPgwYDKG6BaJeXxXL/dFBkDEGWIvnTfcublcOQjzQ9eNAhKnKsumcRmmsNZj01eh6BArLu92k+B+RbhrblCefLOIBRi0/q1iifv3WeNyIaapwhTb4WmX82byEBpZCv2CQzfzUPB6Ah3MkOqBJE9sGxbbPAHw= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645609789952438.669885592636; Wed, 23 Feb 2022 01:49:49 -0800 (PST) Received: from localhost ([::1]:58048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMoHK-0008OY-Or for importer@patchew.org; Wed, 23 Feb 2022 04:49:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMncc-0001Tx-FH for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:48 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50198) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMncP-0001zS-Qc for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:36 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 1EE4921C6C; Wed, 23 Feb 2022 09:07:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607238; 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=fK//uTVRDEVguoVlIYMceoQvqPjIUKZhtPzueFDLdN8=; b=RyF1Y2XrrYTdeCE6ex2l5r4njs1SWF+Ew2G0Pk4uiLXvDtQYoMZ4TXkNgR6aPWvqZkDZ/Y 1Nb615lGzed7PoPOv5wBiX9WrNMr3aZwlkcIg/Mj+aDUCoxhgDUrN8lcMM+II34SRqtICy P/ApJZpEDoLkrxc84N3SZxPi8VwRyZA= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 03/14] vl: support machine-initialized target in phase_until() Date: Wed, 23 Feb 2022 10:06:55 +0100 Message-Id: <20220223090706.4888-4-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1645609819347100001 Content-Type: text/plain; charset="utf-8" phase_until() now supports the following transitions: + accel-created -> machine-initialized + machine-initialized -> machine-ready As a consequence we can now support the use of qmp_exit_preconfig() from phases _accel-created_ and _machine-initialized_. This commit is a preparation to support cold plugging a device using qapi (which will be introduced in a following commit). For this we need fine grain control of the phase. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- softmmu/vl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index 5689d0be88..50337d68b9 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2737,8 +2737,8 @@ static void qemu_machine_creation_done(void) =20 void qmp_x_exit_preconfig(Error **errp) { - if (phase_check(PHASE_MACHINE_INITIALIZED)) { - error_setg(errp, "The command is permitted only before machine ini= tialization"); + if (phase_check(PHASE_MACHINE_READY)) { + error_setg(errp, "The command is permitted only before machine is = ready"); return; } phase_until(PHASE_MACHINE_READY, errp); @@ -2759,7 +2759,17 @@ bool phase_until(MachineInitPhase phase, Error **err= p) case PHASE_ACCEL_CREATED: qemu_init_board(); /* We are now in PHASE_MACHINE_INITIALIZED. */ + /* + * Handle CLI devices now in order leave the function in a sta= te + * where we can cold plug devices with QMP. The following call + * handles the CLI options: + * + -fw_cfg (has side effects on device cold plug) + * + -device + */ qemu_create_cli_devices(); + break; + + case PHASE_MACHINE_INITIALIZED: /* * At this point all CLI options are handled apart: * + -S (autostart) --=20 2.35.1 From nobody Tue May 14 23:14:33 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 ARC-Seal: i=1; a=rsa-sha256; t=1645609106; cv=none; d=zohomail.com; s=zohoarc; b=BUotF+pTaUNZwOLKaGO2f/uK2hiPDTsY4f4ZiMTSMFYJWmlkqkQYKyviq4wIBrksev3rNVjHVgv978+e2YAdfotkfXdTlf1bFn31o7zkwAuwHGCtPxFNie7PhyjEwpuPhJGD8mYXq5huJN8WbOqAisfxULpwefMOH4DSQs4V+5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645609106; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=leheYCudOea9CxkF8jZtbqwtNcoRlV8wZddLLXZ7QCE=; b=I3eviYOsXYfLjzo7oVTpwxBTYXFjyL95UHnQEFbefCZe5eX/cRjl9DcMpA69S0402nL4NqqijavnmgNoVjSuf1n13SozgmeAkcoH0W7QlDQIxte2LflTL+JHrxkjsiINN7aBwaA7UehyctceaL9rAfTXO6BFq8aLeM83Sii4ch4= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645609106247306.92463961079295; Wed, 23 Feb 2022 01:38:26 -0800 (PST) Received: from localhost ([::1]:48738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMo6K-0001Zo-Hj for importer@patchew.org; Wed, 23 Feb 2022 04:38:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMncc-0001U1-V3 for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:48 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50210) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMncR-0001za-DF for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:42 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 83DFF21EB7; Wed, 23 Feb 2022 09:07:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607238; 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=leheYCudOea9CxkF8jZtbqwtNcoRlV8wZddLLXZ7QCE=; b=fDF4R8kwR7lmcowzSBEv0RjHLt78+/fpaGJx+GavXlVpGWRt3o/nPKG0UWR4o9MvAAjObZ HdB290gvrrAJqkVkmWjfzXb5cukes4oVBWs9bRnVKT0/9qiGHtPmsT4gs35HIDobhiEU9u 9YAoLs9X7vlykKRnZJZIDoWmG3ZwpTo= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 04/14] qapi/device_add: compute is_hotplug flag Date: Wed, 23 Feb 2022 10:06:56 +0100 Message-Id: <20220223090706.4888-5-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1645609107698100001 Content-Type: text/plain; charset="utf-8" Instead of checking the phase everytime, just store the result in a flag. We will use more of it in the following commit. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- softmmu/qdev-monitor.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 01f3834db5..47a89aee20 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -617,6 +617,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *op= ts, char *id; DeviceState *dev =3D NULL; BusState *bus =3D NULL; + bool is_hotplug =3D phase_check(PHASE_MACHINE_READY); =20 driver =3D qdict_get_try_str(opts, "driver"); if (!driver) { @@ -660,7 +661,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *op= ts, return NULL; } =20 - if (phase_check(PHASE_MACHINE_READY) && bus && !qbus_is_hotpluggable(b= us)) { + if (is_hotplug && bus && !qbus_is_hotpluggable(bus)) { error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name); return NULL; } @@ -674,7 +675,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *op= ts, dev =3D qdev_new(driver); =20 /* Check whether the hotplug is allowed by the machine */ - if (phase_check(PHASE_MACHINE_READY)) { + if (is_hotplug) { if (!qdev_hotplug_allowed(dev, errp)) { goto err_del_dev; } --=20 2.35.1 From nobody Tue May 14 23:14:33 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 ARC-Seal: i=1; a=rsa-sha256; t=1645608033; cv=none; d=zohomail.com; s=zohoarc; b=ces47VwBvUyRfgu2hvoY32FHuY3Xy13SXOerq6UlGOWQux7n0UcNoqx0XOe7IkDkgI8ti2p4OZQL89ZPB/6D+uSRfmP0OOqXFxA2T5qFkwisO33wMdAKRRfXv2AMSCM/y7+WVaK1PgeKk5LpX+VkHx4PTl/DBFAtEcMYUkTu928= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645608033; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Tsth2S0QxzZ6akvNQ6dnRjZtK+bdfneUMgsqCFymbWM=; b=nf+U/Ma7pnkqSuO8zz9yZdjwt+/jtCa4333J8kTSx7bTKzefcNE4d1Wij9bOqHdV5FmdDIMj3canPMuyg4WWzmG/2D9qFUXR2UpCASHXqno+i/6mAn0xGWmdHJQsDwGGfr0wh+MzFcJ/Gv6NfYjyii4cCCLnbdvbN0IW40GAw/U= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164560803303213.212817575377244; Wed, 23 Feb 2022 01:20:33 -0800 (PST) Received: from localhost ([::1]:33570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMnp0-0006jw-DV for importer@patchew.org; Wed, 23 Feb 2022 04:20:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnci-0001UG-0J for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:48 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50374) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnce-00022s-PE for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:47 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 11D3D21EB9; Wed, 23 Feb 2022 09:07:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607239; 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=Tsth2S0QxzZ6akvNQ6dnRjZtK+bdfneUMgsqCFymbWM=; b=VR8E/ErgXlnmVgJPPX+fpDo6kUaM03AckYQoA7y9n4Mz8tZL0QdR8p3Uj4RLVDPuv+V071 VF5y9cdGODSgPa2axybOSt1J+A84ksFQaOwnwIzT9c1zVWRQlgg2n/v2ThEph+pXQBncjs /s7fCBRWayKK/0ovgbPBbTFqPUyL6/M= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 05/14] qapi/device_add: handle the rom_order_override when cold-plugging Date: Wed, 23 Feb 2022 10:06:57 +0100 Message-Id: <20220223090706.4888-6-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1645608034220100001 Content-Type: text/plain; charset="utf-8" rom_set_order_override() and rom_reset_order_override() were called in qemu_create_cli_devices() to set the rom_order_override value once and for all when creating the devices added on CLI. Unfortunately this won't work with qapi commands. Move the calls inside device_add so that it will be done in every case: + CLI option: -device + QAPI command: device_add rom_[set|reset]_order_override() are implemented in hw/core/loader.c They either do nothing or call fw_cfg_[set|reset]_order_override(). The later functions are implemented in hw/nvram/fw_cfg.c and only change an integer value of a "global" variable. In consequence, there are no complex side effects involved and we can safely move them from outside the -device option loop to the inner function. Signed-off-by: Damien Hedde Tested-by: Jim Shu --- softmmu/qdev-monitor.c | 11 +++++++++++ softmmu/vl.c | 2 -- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 47a89aee20..9ec3e0ebff 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -43,6 +43,7 @@ #include "hw/qdev-properties.h" #include "hw/clock.h" #include "hw/boards.h" +#include "hw/loader.h" =20 /* * Aliases were a bad idea from the start. Let's keep them @@ -671,6 +672,10 @@ DeviceState *qdev_device_add_from_qdict(const QDict *o= pts, return NULL; } =20 + if (!is_hotplug) { + rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); + } + /* create device */ dev =3D qdev_new(driver); =20 @@ -712,6 +717,9 @@ DeviceState *qdev_device_add_from_qdict(const QDict *op= ts, if (!qdev_realize(DEVICE(dev), bus, errp)) { goto err_del_dev; } + if (!is_hotplug) { + rom_reset_order_override(); + } return dev; =20 err_del_dev: @@ -719,6 +727,9 @@ err_del_dev: object_unparent(OBJECT(dev)); object_unref(OBJECT(dev)); } + if (!is_hotplug) { + rom_reset_order_override(); + } return NULL; } =20 diff --git a/softmmu/vl.c b/softmmu/vl.c index 50337d68b9..b91ae1b8ae 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2680,7 +2680,6 @@ static void qemu_create_cli_devices(void) } =20 /* init generic devices */ - rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, &error_fatal); QTAILQ_FOREACH(opt, &device_opts, next) { @@ -2697,7 +2696,6 @@ static void qemu_create_cli_devices(void) object_unref(OBJECT(dev)); loc_pop(&opt->loc); } - rom_reset_order_override(); } =20 static void qemu_machine_creation_done(void) --=20 2.35.1 From nobody Tue May 14 23:14:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645609293894827.0734259873899; Wed, 23 Feb 2022 01:41:33 -0800 (PST) Received: from localhost ([::1]:50746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMo9M-0002zc-Js for importer@patchew.org; Wed, 23 Feb 2022 04:41:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48344) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnch-0001UD-Me for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:48 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50376) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnce-00022r-Oy for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:47 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 7B97B21EBA; Wed, 23 Feb 2022 09:07:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607239; 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=saHwrJRZtMfgZkanr0jmyHUux2j0Im+vXN3vMdIgf10=; b=rruXzPzRg2p5VTQK7T0MwHeKrfTraehCcD2PdtKZ5zthw0+k7i55/wZ8LFtOwG9+WaxF4e 4xkOZdBWQyRWKUumeSlUov87GSIw8poSJ+elh516AwKJeY+fqQ29opdsHGzQCbw0af7W2Z 2U0MUIqSawsKWEBVzyTzurc8vTbaMSg= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 06/14] qapi/device_add: Allow execution in machine initialized phase Date: Wed, 23 Feb 2022 10:06:58 +0100 Message-Id: <20220223090706.4888-7-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , Eduardo Habkost , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , "Dr. David Alan Gilbert" , Markus Armbruster , Mirela Grujic , Paolo Bonzini , Eric Blake Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1645609294429100001 Content-Type: text/plain; charset="utf-8" From: Mirela Grujic This commit allows to use the QMP command to add a cold-plugged device like we can do with the CLI option -device. Note: for device_add command in qdev.json adding the 'allow-preconfig' option has no effect because the command appears to bypass QAPI (see TODO at qapi/qdev.json:61). The option is added there solely to document the intent. For the same reason, the flags have to be explicitly set in monitor_init_qmp_commands() when the device_add command is registered. Signed-off-by: Mirela Grujic Signed-off-by: Damien Hedde --- v4: + use phase_until() + add missing flag in hmp-commands.hx --- qapi/qdev.json | 3 ++- monitor/misc.c | 2 +- softmmu/qdev-monitor.c | 4 ++++ hmp-commands.hx | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/qapi/qdev.json b/qapi/qdev.json index 26cd10106b..2e2de41499 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -77,7 +77,8 @@ { 'command': 'device_add', 'data': {'driver': 'str', '*bus': 'str', '*id': 'str'}, 'gen': false, # so we can get the additional arguments - 'features': ['json-cli', 'json-cli-hotplug'] } + 'features': ['json-cli', 'json-cli-hotplug'], + 'allow-preconfig': true } =20 ## # @device_del: diff --git a/monitor/misc.c b/monitor/misc.c index a3a6e47844..fd56dd8f08 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -233,7 +233,7 @@ static void monitor_init_qmp_commands(void) qmp_init_marshal(&qmp_commands); =20 qmp_register_command(&qmp_commands, "device_add", - qmp_device_add, 0, 0); + qmp_device_add, QCO_ALLOW_PRECONFIG, 0); =20 QTAILQ_INIT(&qmp_cap_negotiation_commands); qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities", diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 9ec3e0ebff..ec0eddaf72 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -853,6 +853,10 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, = Error **errp) QemuOpts *opts; DeviceState *dev; =20 + if (!phase_until(PHASE_MACHINE_INITIALIZED, errp)) { + return; + } + opts =3D qemu_opts_from_qdict(qemu_find_opts("device"), qdict, errp); if (!opts) { return; diff --git a/hmp-commands.hx b/hmp-commands.hx index 70a9136ac2..3237085e22 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -668,6 +668,7 @@ ERST .help =3D "add device, like -device on the command line", .cmd =3D hmp_device_add, .command_completion =3D device_add_completion, + .flags =3D "p", }, =20 SRST --=20 2.35.1 From nobody Tue May 14 23:14:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645610434732535.4559868680097; Wed, 23 Feb 2022 02:00:34 -0800 (PST) Received: from localhost ([::1]:44068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMoRk-0001ea-IQ for importer@patchew.org; Wed, 23 Feb 2022 05:00:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnch-0001UB-JF for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:48 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50378) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnce-00022u-Pg for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:47 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 12D8721EBD; Wed, 23 Feb 2022 09:07:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607240; 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=gaNB2TsWb8LnUxC0b8QE1vl0YRpFNbVBSRKKXrGk7SU=; b=a4eWfCz8NYAq91dTRS2o3vC21NfN3SZEYjYKIkCrrgGpEfuqympcdcTWgQFCDkjYHn+3NL TywpLsJxK8f/57GIthmSdLOFcfaEQcIOglYO6czm97TXbw8TAuz0gW0I4Szxyce95LkUgx 6mJbQazOk7OwQMhdl5UOs+kyArWaIRo= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 07/14] none-machine: add the NoneMachineState structure Date: Wed, 23 Feb 2022 10:06:59 +0100 Message-Id: <20220223090706.4888-8-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes 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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , Eduardo Habkost , Yanan Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1645610435586100001 Content-Type: text/plain; charset="utf-8" The none machine was using the parent state structure. We'll need a custom state to add a field in the following commit. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Jim Shu --- hw/core/null-machine.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/hw/core/null-machine.c b/hw/core/null-machine.c index f586a4bef5..7eb258af07 100644 --- a/hw/core/null-machine.c +++ b/hw/core/null-machine.c @@ -17,6 +17,13 @@ #include "exec/address-spaces.h" #include "hw/core/cpu.h" =20 +struct NoneMachineState { + MachineState parent; +}; + +#define TYPE_NONE_MACHINE MACHINE_TYPE_NAME("none") +OBJECT_DECLARE_SIMPLE_TYPE(NoneMachineState, NONE_MACHINE) + static void machine_none_init(MachineState *mch) { CPUState *cpu =3D NULL; @@ -42,8 +49,10 @@ static void machine_none_init(MachineState *mch) } } =20 -static void machine_none_machine_init(MachineClass *mc) +static void machine_none_class_init(ObjectClass *oc, void *data) { + MachineClass *mc =3D MACHINE_CLASS(oc); + mc->desc =3D "empty machine"; mc->init =3D machine_none_init; mc->max_cpus =3D 1; @@ -56,4 +65,15 @@ static void machine_none_machine_init(MachineClass *mc) mc->no_sdcard =3D 1; } =20 -DEFINE_MACHINE("none", machine_none_machine_init) +static const TypeInfo none_machine_info =3D { + .name =3D TYPE_NONE_MACHINE, + .parent =3D TYPE_MACHINE, + .instance_size =3D sizeof(NoneMachineState), + .class_init =3D machine_none_class_init, +}; + +static void none_machine_register_types(void) +{ + type_register_static(&none_machine_info); +} +type_init(none_machine_register_types); --=20 2.35.1 From nobody Tue May 14 23:14:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645607895254653.6160534794143; Wed, 23 Feb 2022 01:18:15 -0800 (PST) Received: from localhost ([::1]:59804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMnmj-000582-E5 for importer@patchew.org; Wed, 23 Feb 2022 04:18:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnch-0001UC-Js for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:48 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50380) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnce-00022t-PP for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:47 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 7D48821EC0; Wed, 23 Feb 2022 09:07:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607240; 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=Zxn5NdwFOT4UPyXGAHs+RBbnTzq323hI5ry9yIbKUDI=; b=RmXUjX6Vlv7TqKVDF6kpFtjlTzJnwmS6kFLFMSLLP0g3k1vZLzzznJYwBEm6rPs1xsg+Br 3XAe3ir26+8yd6bTkWjSfsu2cIVSQ1tH4dVYelFnpXykk5CSdS5W1wDhis5rnpdgHWoE3a 0YngfEZ/7O48Yf+sc/+bMiTEzqu0mx4= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 08/14] none-machine: add 'ram-addr' property Date: Wed, 23 Feb 2022 10:07:00 +0100 Message-Id: <20220223090706.4888-9-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes 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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , Eduardo Habkost , Yanan Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1645607898295100001 Content-Type: text/plain; charset="utf-8" Add the property to configure a the base address of the ram. The default value remains zero. This commit is needed to use the 'none' machine as a base, and subsequently to dynamically populate it using qapi commands. Having a non null 'ram' is really hard to workaround because of the actual constraints on the generic loader: it prevents loading binaries bigger than ram_size (with a null ram, we cannot load anything). For now we need to be able to use the existing ram creation feature of the none machine with a configurable base address. Signed-off-by: Damien Hedde Tested-by: Jim Shu --- hw/core/null-machine.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/hw/core/null-machine.c b/hw/core/null-machine.c index 7eb258af07..5fd1cc0218 100644 --- a/hw/core/null-machine.c +++ b/hw/core/null-machine.c @@ -16,9 +16,11 @@ #include "hw/boards.h" #include "exec/address-spaces.h" #include "hw/core/cpu.h" +#include "qapi/visitor.h" =20 struct NoneMachineState { MachineState parent; + uint64_t ram_addr; }; =20 #define TYPE_NONE_MACHINE MACHINE_TYPE_NAME("none") @@ -26,6 +28,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(NoneMachineState, NONE_MACHINE) =20 static void machine_none_init(MachineState *mch) { + NoneMachineState *nms =3D NONE_MACHINE(mch); CPUState *cpu =3D NULL; =20 /* Initialize CPU (if user asked for it) */ @@ -37,9 +40,13 @@ static void machine_none_init(MachineState *mch) } } =20 - /* RAM at address zero */ + /* RAM at configured address (default: 0) */ if (mch->ram) { - memory_region_add_subregion(get_system_memory(), 0, mch->ram); + memory_region_add_subregion(get_system_memory(), nms->ram_addr, + mch->ram); + } else if (nms->ram_addr) { + error_report("'ram-addr' has been specified but the size is zero"); + exit(1); } =20 if (mch->kernel_filename) { @@ -49,6 +56,22 @@ static void machine_none_init(MachineState *mch) } } =20 +static void machine_none_get_ram_addr(Object *obj, Visitor *v, const char = *name, + void *opaque, Error **errp) +{ + NoneMachineState *nms =3D NONE_MACHINE(obj); + + visit_type_uint64(v, name, &nms->ram_addr, errp); +} + +static void machine_none_set_ram_addr(Object *obj, Visitor *v, const char = *name, + void *opaque, Error **errp) +{ + NoneMachineState *nms =3D NONE_MACHINE(obj); + + visit_type_uint64(v, name, &nms->ram_addr, errp); +} + static void machine_none_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); @@ -63,6 +86,13 @@ static void machine_none_class_init(ObjectClass *oc, voi= d *data) mc->no_floppy =3D 1; mc->no_cdrom =3D 1; mc->no_sdcard =3D 1; + + object_class_property_add(oc, "ram-addr", "int", + machine_none_get_ram_addr, + machine_none_set_ram_addr, + NULL, NULL); + object_class_property_set_description(oc, "ram-addr", + "Base address of the RAM (default is 0)"); } =20 static const TypeInfo none_machine_info =3D { --=20 2.35.1 From nobody Tue May 14 23:14:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645608526171141.96621454156116; Wed, 23 Feb 2022 01:28:46 -0800 (PST) Received: from localhost ([::1]:40410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMnwr-0003fX-9c for importer@patchew.org; Wed, 23 Feb 2022 04:28:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMncg-0001U6-9o for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:48 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50382) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnce-00022x-Pu for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:46 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 0087A21EC1; Wed, 23 Feb 2022 09:07:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607241; 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=qt+ol21qgIv6OQQUWDXZLUHokTiPWEUZfPCAlGQbiHQ=; b=CAnnmbHtIMpukq/EvDYei3hLMi+AEAu604k3MyOjhFdjMxZ2JS2a41FjDQt+EAxY3QFMWh a7Pptsj1qaDsOKNjPZ7MQqKg4W2KIAT//C9KLXyoqLHRz7nhZiaKtHKQKT/LxGTOmYH3o7 3u0A1Tw4g5RmLgOyqPaKoJFQ4MQ0oH4= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 09/14] none-machine: allow cold plugging sysbus devices Date: Wed, 23 Feb 2022 10:07:01 +0100 Message-Id: <20220223090706.4888-10-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes 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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , Eduardo Habkost , Yanan Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1645608526852100001 Content-Type: text/plain; charset="utf-8" Allow plugging any sysbus device on this machine (the sysbus devices still need to be 'user-creatable'). This commit is needed to use the 'none' machine as a base, and subsequently to dynamically populate it with sysbus devices using qapi commands. Note that this only concern cold-plug: sysbus devices cann't be hot plugged because the sysbus bus does not support it. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Jim Shu --- hw/core/null-machine.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/core/null-machine.c b/hw/core/null-machine.c index 5fd1cc0218..702b56232d 100644 --- a/hw/core/null-machine.c +++ b/hw/core/null-machine.c @@ -17,6 +17,7 @@ #include "exec/address-spaces.h" #include "hw/core/cpu.h" #include "qapi/visitor.h" +#include "hw/sysbus.h" =20 struct NoneMachineState { MachineState parent; @@ -93,6 +94,9 @@ static void machine_none_class_init(ObjectClass *oc, void= *data) NULL, NULL); object_class_property_set_description(oc, "ram-addr", "Base address of the RAM (default is 0)"); + + /* allow cold plugging any any "user-creatable" sysbus device */ + machine_class_allow_dynamic_sysbus_dev(mc, TYPE_SYS_BUS_DEVICE); } =20 static const TypeInfo none_machine_info =3D { --=20 2.35.1 From nobody Tue May 14 23:14:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645608701799765.1698704166331; Wed, 23 Feb 2022 01:31:41 -0800 (PST) Received: from localhost ([::1]:42148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMnzo-0004sp-B9 for importer@patchew.org; Wed, 23 Feb 2022 04:31:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMncg-0001U8-Ew for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:48 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50384) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnce-00022v-Pm for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:46 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 6BB7521EC2; Wed, 23 Feb 2022 09:07:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607241; 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=9yXFjKtsL6//0NeX/WHfSo+Sj8m/tUGliNIvyAG/AQI=; b=OQuss5E7KgBuY8/im2tqJLjnNHKA9Ljz14NQT4sCCNGAx5Q/KaFH8JqyIw9fnz9k/PhSpu Q0pP98wbYGzgs83LSUiJd4H9vQ0AFZA6aLjFGq0nSFaHsq5VzoCjULTwdqKvw6QraO7GNS NXHFpO55MR3He9yu4A70wMb1ZMlkE6s= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 10/14] none-machine: allow several cpus Date: Wed, 23 Feb 2022 10:07:02 +0100 Message-Id: <20220223090706.4888-11-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam: Yes 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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , Eduardo Habkost , Yanan Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1645608702643100001 Content-Type: text/plain; charset="utf-8" In order to dynamically create (cold-plugging) cpus, we need to increase _maxcpus_. This value is indeed used to initialize the accelerator during qemu startup. Allowing 16 seems a good starting point. Add a check to prevent a user to request more than 1 cpu if he specifies the cpu type on the CLI so that the legacy use case of the none machine is preserved. This commit is needed to use the 'none' machine as a base, and subsequently to dynamically populate it wth cpus usign qapi commands. Signed-off-by: Damien Hedde --- hw/core/null-machine.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/core/null-machine.c b/hw/core/null-machine.c index 702b56232d..64f9931857 100644 --- a/hw/core/null-machine.c +++ b/hw/core/null-machine.c @@ -34,6 +34,10 @@ static void machine_none_init(MachineState *mch) =20 /* Initialize CPU (if user asked for it) */ if (mch->cpu_type) { + if (mch->smp.cpus > 1) { + error_report("Cannot initialize more than 1 CPU"); + exit(1); + } cpu =3D cpu_create(mch->cpu_type); if (!cpu) { error_report("Unable to initialize CPU"); @@ -79,7 +83,7 @@ static void machine_none_class_init(ObjectClass *oc, void= *data) =20 mc->desc =3D "empty machine"; mc->init =3D machine_none_init; - mc->max_cpus =3D 1; + mc->max_cpus =3D 16; mc->default_ram_size =3D 0; mc->default_ram_id =3D "ram"; mc->no_serial =3D 1; --=20 2.35.1 From nobody Tue May 14 23:14:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645609854195719.0776508955566; Wed, 23 Feb 2022 01:50:54 -0800 (PST) Received: from localhost ([::1]:58454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMoIO-0000Jc-SI for importer@patchew.org; Wed, 23 Feb 2022 04:50:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnct-0001bi-S3 for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:59 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50388) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnco-00023M-QT for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:59 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id D0F5721EC3; Wed, 23 Feb 2022 09:07:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607242; 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=Rd/aJBw3vxIoVXBM+lhDisHOFbTCT86AFnBFlrW8gvE=; b=FHKQzn308hOQ18zA2RMm2ZXsUr85Q98gGE/vSwV9TzILZJQtM56ySPXkJPprdZRiCzHT0L 5RRmuYwgEtMceCHgzZlV0tgkmqLhZTP8YvdX1lZJuPnKjMutvcQhXmoGUgCnOezZZto6Qn I+C41Pb+8N4vKMNvRF5OIzscm7vuh9s= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 11/14] softmmu/memory: add memory_region_try_add_subregion function Date: Wed, 23 Feb 2022 10:07:03 +0100 Message-Id: <20220223090706.4888-12-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Xu , Alistair Francis , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1645609855416100001 It allows adding a subregion to a memory region with error handling. Like memory_region_add_subregion_overlap(), it handles priority as well. Apart from the error handling, the behavior is the same. It can be used to do the simple memory_region_add_subregion() (with no overlap) by setting the priority parameter to 0. This commit is a preparation to further use of this function in the context of qapi command which needs error handling support. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: David Hildenbrand Reviewed-by: Alistair Francis Tested-by: Jim Shu --- include/exec/memory.h | 22 ++++++++++++++++++++++ softmmu/memory.c | 23 +++++++++++++++-------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 4d5997e6bb..070dcb5255 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2215,6 +2215,28 @@ void memory_region_add_subregion_overlap(MemoryRegio= n *mr, MemoryRegion *subregion, int priority); =20 +/** + * memory_region_try_add_subregion: Add a subregion to a container + * with error handling. + * + * Behaves like memory_region_add_subregion_overlap(), but errors are + * reported if the subregion cannot be added. + * + * @mr: the region to contain the new subregion; must be a container + * initialized with memory_region_init(). + * @offset: the offset relative to @mr where @subregion is added. + * @subregion: the subregion to be added. + * @priority: used for resolving overlaps; highest priority wins. + * @errp: pointer to Error*, to store an error if it happens. + * + * Returns: True in case of success, false otherwise. + */ +bool memory_region_try_add_subregion(MemoryRegion *mr, + hwaddr offset, + MemoryRegion *subregion, + int priority, + Error **errp); + /** * memory_region_get_ram_addr: Get the ram address associated with a memory * region diff --git a/softmmu/memory.c b/softmmu/memory.c index 678dc62f06..6bc76bf6da 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -2541,27 +2541,34 @@ done: memory_region_transaction_commit(); } =20 -static void memory_region_add_subregion_common(MemoryRegion *mr, - hwaddr offset, - MemoryRegion *subregion) +bool memory_region_try_add_subregion(MemoryRegion *mr, + hwaddr offset, + MemoryRegion *subregion, + int priority, + Error **errp) { MemoryRegion *alias; =20 - assert(!subregion->container); + if (subregion->container) { + error_setg(errp, "The memory region is already in another region"); + return false; + } + + subregion->priority =3D priority; subregion->container =3D mr; for (alias =3D subregion->alias; alias; alias =3D alias->alias) { alias->mapped_via_alias++; } subregion->addr =3D offset; memory_region_update_container_subregions(subregion); + return true; } =20 void memory_region_add_subregion(MemoryRegion *mr, hwaddr offset, MemoryRegion *subregion) { - subregion->priority =3D 0; - memory_region_add_subregion_common(mr, offset, subregion); + memory_region_try_add_subregion(mr, offset, subregion, 0, &error_abort= ); } =20 void memory_region_add_subregion_overlap(MemoryRegion *mr, @@ -2569,8 +2576,8 @@ void memory_region_add_subregion_overlap(MemoryRegion= *mr, MemoryRegion *subregion, int priority) { - subregion->priority =3D priority; - memory_region_add_subregion_common(mr, offset, subregion); + memory_region_try_add_subregion(mr, offset, subregion, priority, + &error_abort); } =20 void memory_region_del_subregion(MemoryRegion *mr, --=20 2.35.1 From nobody Tue May 14 23:14:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645609117694996.3696207060768; Wed, 23 Feb 2022 01:38:37 -0800 (PST) Received: from localhost ([::1]:49134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMo6V-0001rZ-QC for importer@patchew.org; Wed, 23 Feb 2022 04:38:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48412) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnct-0001bg-Rw for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:59 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50386) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnco-00023L-QM for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:59 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 9D3EA21EC5; Wed, 23 Feb 2022 09:07:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607242; 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=VsssQ08ielxMrdpKfjAGfaxN0aH2oCRXyf3fM7RTCcM=; b=D0o9NXufAaSroe65FoOzDEGepoT7H9Cp5l+PZtDrhEpa28h1S8nZ0mGOY9aig2JTccAXus v6Uo6ZFaOPJNbAzbmX6vl3spaYJdsbjEKduEyt2Zfi6Wkz9rFtqusp37R/7E72D/U2ofJv ziTzRVZqPIHECCtmLODNoDaBSVaUzAg= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 12/14] add sysbus-mmio-map qapi command Date: Wed, 23 Feb 2022 10:07:04 +0100 Message-Id: <20220223090706.4888-13-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , Eduardo Habkost , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Markus Armbruster , Alistair Francis , Paolo Bonzini , Eric Blake Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1645609119330100001 Content-Type: text/plain; charset="utf-8" This command allows to map an mmio region of sysbus device onto the system memory. Its behavior mimics the sysbus_mmio_map() function apart from the automatic unmap (the C function unmaps the region if it is already mapped). For the qapi function we consider it is an error to try to map an already mapped function. If unmapping is required, it is probably better to add a sysbus-mmip-unmap command. This command is still experimental (hence the 'unstable' feature), as it is related to the sysbus device creation through qapi commands. This command is required to be able to dynamically build a machine from scratch as there is no qapi-way of doing a memory mapping. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Jim Shu --- Cc: Alistair Francis v4: + integrate priority parameter + use 'unstable' feature flag instead of 'x-' prefix + bump version to 7.0 + dropped Alistair's reviewed-by as a consequence --- qapi/qdev.json | 31 ++++++++++++++++++++++++++++++ hw/core/sysbus.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/qapi/qdev.json b/qapi/qdev.json index 2e2de41499..4830e87a90 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -160,3 +160,34 @@ ## { 'event': 'DEVICE_UNPLUG_GUEST_ERROR', 'data': { '*device': 'str', 'path': 'str' } } + +## +# @sysbus-mmio-map: +# +# Map a sysbus device mmio onto the main system bus. +# +# @device: the device's QOM path +# +# @mmio: The mmio number to be mapped (defaults to 0). +# +# @addr: The base address for the mapping. +# +# @priority: The priority of the mapping (defaults to 0). +# +# Features: +# @unstable: Command is meant to map sysbus devices +# while in preconfig mode. +# +# Since: 7.0 +# +# Returns: Nothing on success +# +## + +{ 'command': 'sysbus-mmio-map', + 'data': { 'device': 'str', + '*mmio': 'uint8', + 'addr': 'uint64', + '*priority': 'int32' }, + 'features': ['unstable'], + 'allow-preconfig' : true } diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c index 05c1da3d31..df1f1f43a5 100644 --- a/hw/core/sysbus.c +++ b/hw/core/sysbus.c @@ -23,6 +23,7 @@ #include "hw/sysbus.h" #include "monitor/monitor.h" #include "exec/address-spaces.h" +#include "qapi/qapi-commands-qdev.h" =20 static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent); static char *sysbus_get_fw_dev_path(DeviceState *dev); @@ -154,6 +155,54 @@ static void sysbus_mmio_map_common(SysBusDevice *dev, = int n, hwaddr addr, } } =20 +void qmp_sysbus_mmio_map(const char *device, + bool has_mmio, uint8_t mmio, + uint64_t addr, + bool has_priority, int32_t priority, + Error **errp) +{ + Object *obj =3D object_resolve_path_type(device, TYPE_SYS_BUS_DEVICE, = NULL); + SysBusDevice *dev; + + if (phase_get() !=3D PHASE_MACHINE_INITIALIZED) { + error_setg(errp, "The command is permitted only when " + "the machine is in initialized phase"); + return; + } + + if (obj =3D=3D NULL) { + error_setg(errp, "Device '%s' not found", device); + return; + } + dev =3D SYS_BUS_DEVICE(obj); + + if (!has_mmio) { + mmio =3D 0; + } + if (!has_priority) { + priority =3D 0; + } + + if (mmio >=3D dev->num_mmio) { + error_setg(errp, "MMIO index '%u' does not exist in '%s'", + mmio, device); + return; + } + + if (dev->mmio[mmio].addr !=3D (hwaddr)-1) { + error_setg(errp, "MMIO index '%u' is already mapped", mmio); + return; + } + + if (!memory_region_try_add_subregion(get_system_memory(), addr, + dev->mmio[mmio].memory, priority, + errp)) { + return; + } + + dev->mmio[mmio].addr =3D addr; +} + void sysbus_mmio_unmap(SysBusDevice *dev, int n) { assert(n >=3D 0 && n < dev->num_mmio); --=20 2.35.1 From nobody Tue May 14 23:14:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645607901766451.19101112108183; Wed, 23 Feb 2022 01:18:21 -0800 (PST) Received: from localhost ([::1]:60004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMnmt-0005GD-Cn for importer@patchew.org; Wed, 23 Feb 2022 04:18:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnct-0001bb-QP for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:59 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50390) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnco-00023R-Qe for qemu-devel@nongnu.org; Wed, 23 Feb 2022 04:07:56 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 1D90821EC6; Wed, 23 Feb 2022 09:07:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607243; 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=k2+3Y2v7C83b2PzO7L9N3pbndvBj5nOp+P0TN2m3QKE=; b=yUTLM06+4zb3xiPgyxuFprLcboFIxbSz7MLzvd5qQ93tR0Y687ix+uk7DX7WMjMGWKgrDy RLl61bdIQFOY5tiNtKY8xIaP4+MRPZoZrHHC41YksjtJ39PBpAd6BEn4wiK1dmjmacvehf 2XytH0xCuGBAv+6zveYUXXnFlLlGLcs= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 13/14] hw/mem/system-memory: add a memory sysbus device Date: Wed, 23 Feb 2022 10:07:05 +0100 Message-Id: <20220223090706.4888-14-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , Igor Mammedov , Ani Sinha , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1645607904222100001 Content-Type: text/plain; charset="utf-8" This device can be used to create a memory wrapped into a sysbus device. This device has one property 'readonly' which allows to choose between a ram or a rom. The purpose for this device is to be used with qapi command device_add. Signed-off-by: Damien Hedde Tested-by: Jim Shu --- include/hw/mem/sysbus-memory.h | 28 ++++++++++++ hw/mem/sysbus-memory.c | 80 ++++++++++++++++++++++++++++++++++ hw/mem/meson.build | 2 + 3 files changed, 110 insertions(+) create mode 100644 include/hw/mem/sysbus-memory.h create mode 100644 hw/mem/sysbus-memory.c diff --git a/include/hw/mem/sysbus-memory.h b/include/hw/mem/sysbus-memory.h new file mode 100644 index 0000000000..5c596f8b4f --- /dev/null +++ b/include/hw/mem/sysbus-memory.h @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * SysBusDevice Memory + * + * Copyright (c) 2021 Greensocs + */ + +#ifndef HW_SYSBUS_MEMORY_H +#define HW_SYSBUS_MEMORY_H + +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_SYSBUS_MEMORY "sysbus-memory" +OBJECT_DECLARE_SIMPLE_TYPE(SysBusMemoryState, SYSBUS_MEMORY) + +struct SysBusMemoryState { + /* */ + SysBusDevice parent_obj; + uint64_t size; + bool readonly; + + /* */ + MemoryRegion mem; +}; + +#endif /* HW_SYSBUS_MEMORY_H */ diff --git a/hw/mem/sysbus-memory.c b/hw/mem/sysbus-memory.c new file mode 100644 index 0000000000..f1ad7ba7ec --- /dev/null +++ b/hw/mem/sysbus-memory.c @@ -0,0 +1,80 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * SysBusDevice Memory + * + * Copyright (c) 2021 Greensocs + */ + +#include "qemu/osdep.h" +#include "hw/mem/sysbus-memory.h" +#include "hw/qdev-properties.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" + +static Property sysbus_memory_properties[] =3D { + DEFINE_PROP_UINT64("size", SysBusMemoryState, size, 0), + DEFINE_PROP_BOOL("readonly", SysBusMemoryState, readonly, false), + DEFINE_PROP_END_OF_LIST(), +}; + +static void sysbus_memory_realize(DeviceState *dev, Error **errp) +{ + SysBusMemoryState *s =3D SYSBUS_MEMORY(dev); + gchar *name; + + if (!s->size) { + error_setg(errp, "'size' must be non-zero."); + return; + } + + /* + * We impose having an id (which is unique) because we need to generate + * a unique name for the memory region. + * memory_region_init_ram/rom() will abort() (in qemu_ram_set_idstr() + * function if 2 system-memory devices are created with the same name + * for the memory region). + */ + if (!dev->id) { + error_setg(errp, "system-memory device must have an id."); + return; + } + name =3D g_strdup_printf("%s.region", dev->id); + + if (s->readonly) { + memory_region_init_rom(&s->mem, OBJECT(dev), name, s->size, errp); + } else { + memory_region_init_ram(&s->mem, OBJECT(dev), name, s->size, errp); + } + + g_free(name); + if (*errp) { + return; + } + + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mem); +} + +static void sysbus_memory_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->user_creatable =3D true; + dc->realize =3D sysbus_memory_realize; + device_class_set_props(dc, sysbus_memory_properties); +} + +static const TypeInfo sysbus_memory_info =3D { + .name =3D TYPE_SYSBUS_MEMORY, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(SysBusMemoryState), + .class_init =3D sysbus_memory_class_init, +}; + +static void sysbus_memory_register_types(void) +{ + type_register_static(&sysbus_memory_info); +} + +type_init(sysbus_memory_register_types) diff --git a/hw/mem/meson.build b/hw/mem/meson.build index 82f86d117e..04c74e12f2 100644 --- a/hw/mem/meson.build +++ b/hw/mem/meson.build @@ -7,3 +7,5 @@ mem_ss.add(when: 'CONFIG_NVDIMM', if_true: files('nvdimm.c'= )) softmmu_ss.add_all(when: 'CONFIG_MEM_DEVICE', if_true: mem_ss) =20 softmmu_ss.add(when: 'CONFIG_SPARSE_MEM', if_true: files('sparse-mem.c')) + +softmmu_ss.add(files('sysbus-memory.c')) --=20 2.35.1 From nobody Tue May 14 23:14:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1645608554171624.8168255613168; Wed, 23 Feb 2022 01:29:14 -0800 (PST) Received: from localhost ([::1]:40436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMnxO-0003gZ-UV for importer@patchew.org; Wed, 23 Feb 2022 04:29:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMnd1-0001rL-O3; Wed, 23 Feb 2022 04:08:07 -0500 Received: from beetle.greensocs.com ([5.135.226.135]:50392) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMncz-00023Q-5H; Wed, 23 Feb 2022 04:08:07 -0500 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 89B0021EC7; Wed, 23 Feb 2022 09:07:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1645607243; 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=Qk+gMrnBuDwA4drP9M9tff9or15I+dFur3lZMPXIvp0=; b=NqvYpP9ztjWoFW3/YETDtLGUC3hSVlYVEiMIfX4oESzcUt8ef01tQLp5rrk4SbKFhexk0F QMtjgYMJDoxiqHa7QMJNIQlFudjpyPUmGLsc7v4FfSbaj7LH+RStSH+jcqHWa78C07ZiVs WL3VglpG7Le0+b2FqB9ckbWF9J3XhW8= From: Damien Hedde To: qemu-devel@nongnu.org, mark.burton@greensocs.com, edgari@xilinx.com Subject: [PATCH v4 14/14] hw: set user_creatable on opentitan/sifive_e devices Date: Wed, 23 Feb 2022 10:07:06 +0100 Message-Id: <20220223090706.4888-15-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220223090706.4888-1-damien.hedde@greensocs.com> References: <20220223090706.4888-1-damien.hedde@greensocs.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=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.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, 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: , Cc: Damien Hedde , Peter Maydell , "open list:OpenTitan" , Bin Meng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Palmer Dabbelt Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1645608555573100001 Content-Type: text/plain; charset="utf-8" The devices are: + ibex-timer + ibex-uart + riscv.aclint.swi + riscv.aclint.mtimer + riscv.hart_array + riscv.sifive.e.prci + riscv.sifive.plic + riscv.sifive.uart + sifive_soc.gpio + unimplemented-device These devices are clean regarding error handling in realize. They are all sysbus devices, so setting user-creatable will only enable cold-plugging them on machine having explicitely allowed them (only _none_ machine does that). Note that this commit include the ricv_array which embeds cpus. There are some deep internal constraints about them: you cannot create more cpus than the machine's maxcpus. TCG accelerator's code will for example assert if a user try to create too many cpus. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Jim Shu --- I can also split this patch if you think it's better. But it is mostly a one-line fix per file. This patch requires first some cleanups in order to fix error errors and some more memory leaks that could happend in legit user-related life cycles: a miss-configuration should not be a fatal error anymore. https://lore.kernel.org/qemu-devel/20220218164646.132112-1-damien.hedde@gre= ensocs.com --- hw/char/ibex_uart.c | 1 + hw/char/sifive_uart.c | 1 + hw/gpio/sifive_gpio.c | 1 + hw/intc/riscv_aclint.c | 2 ++ hw/intc/sifive_plic.c | 1 + hw/misc/sifive_e_prci.c | 8 ++++++++ hw/misc/unimp.c | 1 + hw/riscv/riscv_hart.c | 1 + hw/timer/ibex_timer.c | 1 + 9 files changed, 17 insertions(+) diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c index e58181fcf4..0b6d45f2e7 100644 --- a/hw/char/ibex_uart.c +++ b/hw/char/ibex_uart.c @@ -546,6 +546,7 @@ static void ibex_uart_class_init(ObjectClass *klass, vo= id *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); =20 + dc->user_creatable =3D true; dc->reset =3D ibex_uart_reset; dc->realize =3D ibex_uart_realize; dc->vmsd =3D &vmstate_ibex_uart; diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c index 1c75f792b3..6e88778c03 100644 --- a/hw/char/sifive_uart.c +++ b/hw/char/sifive_uart.c @@ -243,6 +243,7 @@ static void sifive_uart_class_init(ObjectClass *oc, voi= d *data) DeviceClass *dc =3D DEVICE_CLASS(oc); ResettableClass *rc =3D RESETTABLE_CLASS(oc); =20 + dc->user_creatable =3D true; dc->realize =3D sifive_uart_realize; dc->vmsd =3D &vmstate_sifive_uart; rc->phases.enter =3D sifive_uart_reset_enter; diff --git a/hw/gpio/sifive_gpio.c b/hw/gpio/sifive_gpio.c index 78bf29e996..8443befa20 100644 --- a/hw/gpio/sifive_gpio.c +++ b/hw/gpio/sifive_gpio.c @@ -380,6 +380,7 @@ static void sifive_gpio_class_init(ObjectClass *klass, = void *data) dc->realize =3D sifive_gpio_realize; dc->reset =3D sifive_gpio_reset; dc->desc =3D "SiFive GPIO"; + dc->user_creatable =3D true; } =20 static const TypeInfo sifive_gpio_info =3D { diff --git a/hw/intc/riscv_aclint.c b/hw/intc/riscv_aclint.c index bef2e1988b..fbf63a52b7 100644 --- a/hw/intc/riscv_aclint.c +++ b/hw/intc/riscv_aclint.c @@ -283,6 +283,7 @@ static void riscv_aclint_mtimer_class_init(ObjectClass = *klass, void *data) DeviceClass *dc =3D DEVICE_CLASS(klass); dc->realize =3D riscv_aclint_mtimer_realize; device_class_set_props(dc, riscv_aclint_mtimer_properties); + dc->user_creatable =3D true; } =20 static const TypeInfo riscv_aclint_mtimer_info =3D { @@ -466,6 +467,7 @@ static void riscv_aclint_swi_class_init(ObjectClass *kl= ass, void *data) DeviceClass *dc =3D DEVICE_CLASS(klass); dc->realize =3D riscv_aclint_swi_realize; device_class_set_props(dc, riscv_aclint_swi_properties); + dc->user_creatable =3D true; } =20 static const TypeInfo riscv_aclint_swi_info =3D { diff --git a/hw/intc/sifive_plic.c b/hw/intc/sifive_plic.c index 8692ea6725..4e5831b487 100644 --- a/hw/intc/sifive_plic.c +++ b/hw/intc/sifive_plic.c @@ -434,6 +434,7 @@ static void sifive_plic_class_init(ObjectClass *klass, = void *data) =20 dc->reset =3D sifive_plic_reset; device_class_set_props(dc, sifive_plic_properties); + dc->user_creatable =3D true; dc->realize =3D sifive_plic_realize; dc->vmsd =3D &vmstate_sifive_plic; } diff --git a/hw/misc/sifive_e_prci.c b/hw/misc/sifive_e_prci.c index a8702c6a5d..7341823e43 100644 --- a/hw/misc/sifive_e_prci.c +++ b/hw/misc/sifive_e_prci.c @@ -97,11 +97,19 @@ static void sifive_e_prci_init(Object *obj) s->plloutdiv =3D SIFIVE_E_PRCI_PLLOUTDIV_DIV1; } =20 +static void sifive_e_prci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->user_creatable =3D true; +} + static const TypeInfo sifive_e_prci_info =3D { .name =3D TYPE_SIFIVE_E_PRCI, .parent =3D TYPE_SYS_BUS_DEVICE, .instance_size =3D sizeof(SiFiveEPRCIState), .instance_init =3D sifive_e_prci_init, + .class_init =3D sifive_e_prci_class_init, }; =20 static void sifive_e_prci_register_types(void) diff --git a/hw/misc/unimp.c b/hw/misc/unimp.c index 6cfc5727f0..fb2a0b23dd 100644 --- a/hw/misc/unimp.c +++ b/hw/misc/unimp.c @@ -80,6 +80,7 @@ static void unimp_class_init(ObjectClass *klass, void *da= ta) { DeviceClass *dc =3D DEVICE_CLASS(klass); =20 + dc->user_creatable =3D true; dc->realize =3D unimp_realize; device_class_set_props(dc, unimp_properties); } diff --git a/hw/riscv/riscv_hart.c b/hw/riscv/riscv_hart.c index 4aed6c2a59..85fae44048 100644 --- a/hw/riscv/riscv_hart.c +++ b/hw/riscv/riscv_hart.c @@ -77,6 +77,7 @@ static void riscv_harts_class_init(ObjectClass *klass, vo= id *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); =20 + dc->user_creatable =3D true; device_class_set_props(dc, riscv_harts_props); dc->realize =3D riscv_harts_realize; } diff --git a/hw/timer/ibex_timer.c b/hw/timer/ibex_timer.c index 8c2ca364da..d1cc337416 100644 --- a/hw/timer/ibex_timer.c +++ b/hw/timer/ibex_timer.c @@ -295,6 +295,7 @@ static void ibex_timer_class_init(ObjectClass *klass, v= oid *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); =20 + dc->user_creatable =3D true; dc->reset =3D ibex_timer_reset; dc->vmsd =3D &vmstate_ibex_timer; dc->realize =3D ibex_timer_realize; --=20 2.35.1