From nobody Fri Nov 29 20:50:46 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 1632328707193850.880771434173; Wed, 22 Sep 2021 09:38:27 -0700 (PDT) Received: from localhost ([::1]:59030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT5GL-0004ka-P8 for importer@patchew.org; Wed, 22 Sep 2021 12:38:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4ub-0002jo-J8; Wed, 22 Sep 2021 12:15:57 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:39044) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT4uZ-0005Lo-BC; Wed, 22 Sep 2021 12:15:57 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.6]) by beetle.greensocs.com (Postfix) with ESMTPS id 8859E21EC6; Wed, 22 Sep 2021 16:15:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1632327353; 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=AlcBA0wPhQv7JVjfEB3jyBVlLhydcLHLk7mWNQnkSaw=; b=aNbmKAB3upukJdcXcsuRvB4jG/XeAjvN01JCf7FZfNOuG3Ym0/T3VOHAsNgbv3CyONvpfS mid9Yf6nHZMIKJQ8tXxHLaDcTTsVZesJe5TCDt+J3rfnHcViEzutj1BAJythr3C13zB3oI zK53p1V+hpk5h2HvFJykoc2d/cYBPPw= From: Damien Hedde To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 07/16] hw/core/machine: add machine_class_is_dynamic_sysbus_dev_allowed Date: Wed, 22 Sep 2021 18:13:56 +0200 Message-Id: <20210922161405.140018-8-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922161405.140018-1-damien.hedde@greensocs.com> References: <20210922161405.140018-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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Michael S. Tsirkin" , David Hildenbrand , Peter Xu , mirela.grujic@greensocs.com, Alistair Francis , Gerd Hoffmann , Ani Sinha , Eric Blake , Stefano Stabellini , xen-devel@lists.xenproject.org, Paul Durrant , Markus Armbruster , Anthony Perard , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eduardo Habkost , "Dr. David Alan Gilbert" , Eric Auger , Paolo Bonzini , qemu-riscv@nongnu.org, Damien Hedde , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , mark.burton@greensocs.com, edgari@xilinx.com, Igor Mammedov 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: 1632328709580100001 Content-Type: text/plain; charset="utf-8" Right now the allowance check for adding a sysbus device using -device cli option (or device_add qmp command) is done well after the device has been created. It is done during the machine init done notifier: machine_init_notify() in hw/core/machine.c This new function will allow us to check if a sysbus device type is allowed to be dynamically created by the machine during the device creation time. Also make device_is_dynamic_sysbus() use the new function. Signed-off-by: Damien Hedde --- In the context of our series, we need to be able to do the check at device creation time to allow doing it depending on the current MACHINE_INIT phase. --- include/hw/boards.h | 17 +++++++++++++++++ hw/core/machine.c | 15 ++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/hw/boards.h b/include/hw/boards.h index 463a5514f9..934443c1cd 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -51,6 +51,23 @@ void machine_set_cpu_numa_node(MachineState *machine, */ void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *= type); =20 +/** + * machine_class_is_dynamic_sysbus_dev_allowed: Check if type is an allowed + * sysbus device type for the machine class. + * @mc: Machine class + * @type: type to check (should be a subtype of TYPE_SYS_BUS_DEVICE) + * + * Returns: true if @type is a type in the machine's list of + * dynamically pluggable sysbus devices; otherwise false. + * + * Check if the QOM type @type is in the list of allowed sysbus device + * types (see machine_class_allowed_dynamic_sysbus_dev()). + * Note that if @type is a subtype of a type which is in the list, it is + * allowed too. + */ +bool machine_class_is_dynamic_sysbus_dev_allowed(MachineClass *mc, + const char *type); + /** * device_is_dynamic_sysbus: test whether device is a dynamic sysbus device * @mc: Machine class diff --git a/hw/core/machine.c b/hw/core/machine.c index 9125c9aad0..1a18912dc8 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -545,18 +545,27 @@ void machine_class_allow_dynamic_sysbus_dev(MachineCl= ass *mc, const char *type) =20 bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev) { - bool allowed =3D false; - strList *wl; Object *obj =3D OBJECT(dev); =20 if (!object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE)) { return false; } =20 + return machine_class_is_dynamic_sysbus_dev_allowed(mc, + object_get_typename(obj)); +} + +bool machine_class_is_dynamic_sysbus_dev_allowed(MachineClass *mc, + const char *type) +{ + bool allowed =3D false; + strList *wl; + ObjectClass *klass =3D object_class_by_name(type); + for (wl =3D mc->allowed_dynamic_sysbus_devices; !allowed && wl; wl =3D wl->next) { - allowed |=3D !!object_dynamic_cast(obj, wl->value); + allowed |=3D !!object_class_dynamic_cast(klass, wl->value); } =20 return allowed; --=20 2.33.0