From nobody Thu Apr 25 00:51:05 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1653400833; cv=none; d=zohomail.com; s=zohoarc; b=A/TUqxlnh5v88LYdzuwJWNoeRXgZVIpRyYt7dHybwf8i59xX6DLG7GqFvi8BOeDUFAhVncgoN43u1eOOFiLcZXF/m2fYUSj5gLCu4D5mzlD6W6ElfcKmFuXTXwSHTUBkUCHN/4p5+iYpcdBS5GrJKrim4p6TiEZ8CgbiUSocaAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653400833; h=Content-Type: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=kGbmojpONS/3zhVqPidkTxkp029lvf47gykf1NPvoaE=; b=jg8OT8vBZ0kae5E6rAShezkPcgVY/ASzMfmeXed+1QEbI/BVMirbQlsINfYe083N7ViOzuYUxIR1ZfwrXrx/0RRudIz8RRtjoDiqmNc9XjVA/dFo/I7CQTSd4QVrGE9YPEu8zwQ4A/pwEAJli7idbFSmBoGZys0RqHhxxdwFuZo= 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+importer2=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 1653400833311936.7576040788998; Tue, 24 May 2022 07:00:33 -0700 (PDT) Received: from localhost ([::1]:44360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntV5M-0003il-7G for importer2@patchew.org; Tue, 24 May 2022 10:00:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntUtW-0002gS-6D for qemu-devel@nongnu.org; Tue, 24 May 2022 09:48:18 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:53556) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntUtT-0001e4-Hs for qemu-devel@nongnu.org; Tue, 24 May 2022 09:48:17 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.10]) by beetle.greensocs.com (Postfix) with ESMTPS id 0571321A87; Tue, 24 May 2022 13:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1653400091; 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=kGbmojpONS/3zhVqPidkTxkp029lvf47gykf1NPvoaE=; b=S1jsl5zvPCr08CbX9qKvwqQ8VsK+UGYwLq7N8LT5z+t02SRGAs1e8i+XvTG3I47SDeA84a egXSIYasQDrInVBZ4xm/bnWPC9s9ehj+CcbwiWAS2iGqIPL3V9u6wnCrJmXnaDbih+flub BA52uqXzn7VPKXkUfSzE1ocnQRxSjfw= From: Damien Hedde To: qemu-devel@nongnu.org Cc: Damien Hedde , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , Alistair Francis , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Eric Blake , Markus Armbruster , Peter Maydell Subject: [RFC PATCH v5 1/3] none-machine: allow cold plugging sysbus devices Date: Tue, 24 May 2022 15:48:07 +0200 Message-Id: <20220524134809.40732-2-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220524134809.40732-1-damien.hedde@greensocs.com> References: <20220524134809.40732-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+importer2=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: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1653400835429100001 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 can not be hot-plugged because the sysbus bus does not support it. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- v5: + fix commit message (Philippe) --- 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 f586a4bef5..21bc2aca23 100644 --- a/hw/core/null-machine.c +++ b/hw/core/null-machine.c @@ -16,6 +16,7 @@ #include "hw/boards.h" #include "exec/address-spaces.h" #include "hw/core/cpu.h" +#include "hw/sysbus.h" =20 static void machine_none_init(MachineState *mch) { @@ -54,6 +55,9 @@ static void machine_none_machine_init(MachineClass *mc) mc->no_floppy =3D 1; mc->no_cdrom =3D 1; mc->no_sdcard =3D 1; + + /* allow cold plugging any any "user-creatable" sysbus device */ + machine_class_allow_dynamic_sysbus_dev(mc, TYPE_SYS_BUS_DEVICE); } =20 DEFINE_MACHINE("none", machine_none_machine_init) --=20 2.36.1 From nobody Thu Apr 25 00:51:05 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1653400436; cv=none; d=zohomail.com; s=zohoarc; b=nc2jGFyVL4Qj/y8XH5jgjge0LzODjgZRI/ihd9cQvGsLn++RTiBe3gW5gt3SADwIFCg/MEkp8EG5NZKw7H7o3ggy7+MnFZnviuy6Nx2y4aW3mdJweh5Z6oegJW4gnnGgELJsEnq1jJx5DEdQ3SSthn6Mpw6hNa4iuoddim6j0s4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653400436; h=Content-Type: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=1ho6E4EofZqGPbs7w9w8YeE2RX5pQNJmeaNyyWDoGcM=; b=I5v3Z+ctSDbx/ER6NrsEcCMNZKtGI7bcQemWGFLIBxn24BESAUbraT5wkHMauomhbqAaNRDe/gGoERpjTx7nPGfecvaoJyEh4rVXQT2Vn+4VYtp0OH3iKjG9S7ICEbd0qRhEDA9vjEy1k6UR2ob8FO4uZQRLiWiiMhuBSui2eas= 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+importer2=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 1653400436276167.6519430354823; Tue, 24 May 2022 06:53:56 -0700 (PDT) Received: from localhost ([::1]:35126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntUyx-0005Pt-7E for importer2@patchew.org; Tue, 24 May 2022 09:53:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntUtV-0002gI-LG for qemu-devel@nongnu.org; Tue, 24 May 2022 09:48:17 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:53578) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntUtT-0001e8-Ku for qemu-devel@nongnu.org; Tue, 24 May 2022 09:48:17 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.10]) by beetle.greensocs.com (Postfix) with ESMTPS id A8EB421C39; Tue, 24 May 2022 13:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1653400093; 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=1ho6E4EofZqGPbs7w9w8YeE2RX5pQNJmeaNyyWDoGcM=; b=F/u3kW3FxaICP7++Ypz8As8Gcu8+UFJw+XGNyzaTne/ZlzC//ymZfhp5miKu89j30Vyj/m r0W0+bq7hVGdW/EBnap0tDtPWk7HlIFDuVSfP3Nnwhe/UfMgLSsiv/XBdAvpMGXeO56jNl 3RLhUCU7Q4bz4H61/kq/5f4toipGo7s= From: Damien Hedde To: qemu-devel@nongnu.org Cc: Damien Hedde , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , Alistair Francis , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Eric Blake , Markus Armbruster , Peter Maydell Subject: [RFC PATCH v5 2/3] softmmu/memory: add memory_region_try_add_subregion function Date: Tue, 24 May 2022 15:48:08 +0200 Message-Id: <20220524134809.40732-3-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220524134809.40732-1-damien.hedde@greensocs.com> References: <20220524134809.40732-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+importer2=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: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1653400437702100005 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 --- v5: + rebase, new callsite --- include/exec/memory.h | 22 ++++++++++++++++++++++ softmmu/memory.c | 26 +++++++++++++++++--------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index f1c19451bc..36f2e86be5 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 7ba2048836..5ea4000830 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, @@ -2626,7 +2633,8 @@ static void memory_region_readd_subregion(MemoryRegio= n *mr) memory_region_transaction_begin(); memory_region_ref(mr); memory_region_del_subregion(container, mr); - memory_region_add_subregion_common(container, mr->addr, mr); + memory_region_try_add_subregion(container, mr->addr, mr, mr->prior= ity, + &error_abort); memory_region_unref(mr); memory_region_transaction_commit(); } --=20 2.36.1 From nobody Thu Apr 25 00:51:05 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1653400434; cv=none; d=zohomail.com; s=zohoarc; b=dW5EmNamPnOOvRTifb5uwfiGmG4pbGOIL4syilg6vnksmmyEI7Apyrk9OxotwIoDW0MV0gm6M6V2oNymI6wuSey4a4Fq65C882pZ1gK2GNXGn92Fk+QweOay1d/uBY/akM9V92Ap0ly7LZauM36shPCumqIOaiTTBSpAhGwZp20= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653400434; 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=qwvj9JZ6xhN2gp/Fqgqp4B7n4FW5WKzEC1OxRHo9QmI=; b=A9A5ygXyGjcq1uMc/rrSPClSWbBV4tzgwArYW+SCwJz6tvil1/bzgc1Aut2q7OFbXCJ+2JExxq/EOjC0BKHK1aH75yDs+15M1aD4Wsn4XgexnbjBtr54hXTTKWOcVvid++wnFCdHvHEwra/IzFgsYu0jw0c5qEtzIYBe9JFsnpU= 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+importer2=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 1653400434377628.1598709785244; Tue, 24 May 2022 06:53:54 -0700 (PDT) Received: from localhost ([::1]:35064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntUyv-0005MD-5l for importer2@patchew.org; Tue, 24 May 2022 09:53:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41720) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntUtW-0002gZ-JD for qemu-devel@nongnu.org; Tue, 24 May 2022 09:48:18 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:53604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntUtU-0001eG-93 for qemu-devel@nongnu.org; Tue, 24 May 2022 09:48:18 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.10]) by beetle.greensocs.com (Postfix) with ESMTPS id AE85A21C47; Tue, 24 May 2022 13:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1653400095; 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=qwvj9JZ6xhN2gp/Fqgqp4B7n4FW5WKzEC1OxRHo9QmI=; b=ajNrNVCiwdV8PjkZguhAcnh8LQwCJV8aCyHvH6o88F351AvhQVaD6W2JY4mIljOOKtQxWI G8YDjK6ZZ0rImXbF2O1Omapy/aqp0rplVPQqZ/RI40wh/v7o2IQb9YmIZgjIMG3g44DsF0 fcArarwTVXoS87gZr4WPnYVyqFgFNpA= From: Damien Hedde To: qemu-devel@nongnu.org Cc: Damien Hedde , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Hildenbrand , Alistair Francis , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Eric Blake , Markus Armbruster , Peter Maydell Subject: [RFC PATCH v5 3/3] add sysbus-mmio-map qapi command Date: Tue, 24 May 2022 15:48:09 +0200 Message-Id: <20220524134809.40732-4-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220524134809.40732-1-damien.hedde@greensocs.com> References: <20220524134809.40732-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+importer2=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: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1653400435954100002 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-mmio-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 --- Cc: Alistair Francis v5: + bump version to 7.1 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..787d1ebf81 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.1 +# +# 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.36.1