From nobody Mon Feb 9 20:13:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635433541; cv=none; d=zohomail.com; s=zohoarc; b=hPOKruSo/ipVBSj8xjtPEXxAjHm60oq1FXxAYvBwIVAMBFOXGwcBhfZ8VYKKuvtcqE3Y4PyVvR7ekgUQJYp0QTUnlLylfw408LtKus/ulVoDWAzcSUWTxzxpIxQBTyl28fS45rwoZlElw8ZafFTjuFu66+715h1ei6WOUlSKomg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635433541; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=BP2YG+UwU9At2GQjrOrvf7QoxC3M4wZVtXRCu8IsEeY=; b=f1GRgZa6gB1TS2P+fmHydwGyEV+ny3ITEtIh+cDofzNhMBVc6gI5YaDRE9Uj2cdKWdBs4Xwr5OoKiquWwiMPn7icB8s/EAUKOvsdytO2e5yKtBeiQGfa7llDERAkTOAv7OFbc7pmXSfliYBOR1qiwXIoLSGTCHPrIlYDik43Zbs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1635433541925710.955711485754; Thu, 28 Oct 2021 08:05:41 -0700 (PDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-443-gts5K2YIMsKlqwjFtCa5Zw-1; Thu, 28 Oct 2021 11:05:39 -0400 Received: by mail-wr1-f70.google.com with SMTP id c6-20020adfe706000000b00168acf1bcd5so2231540wrm.5 for ; Thu, 28 Oct 2021 08:05:39 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id e9sm3252978wrn.2.2021.10.28.08.05.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 08:05:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635433540; 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=BP2YG+UwU9At2GQjrOrvf7QoxC3M4wZVtXRCu8IsEeY=; b=gUd5LyZpjKMlpqtcPWjcfx40GW6lRlDtzHX+mZmi+7Sbr9J073tYy3CLfMZpjEDu7BlMdh kobzsnRD4Uo5CD2kDBa0OWOSy6PhzlpX7N2ty4GDV7oQr56xZWs4q57Dpih8r9GC4zUTyV qnVaqjco4Y/g12xpu1EPm4xVgskyQmw= X-MC-Unique: gts5K2YIMsKlqwjFtCa5Zw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BP2YG+UwU9At2GQjrOrvf7QoxC3M4wZVtXRCu8IsEeY=; b=OomNW1W7eHy5ecDL1fNUzgEQQ5oVLsjenwlsrH3Nr1DNQnrbcbJrn4pkQqPHGVX43x y701UCHVaGzOxkfyD6cizkyiVzsAZ6mF9XJM2Ueo+JV83FPoioJ1XSfc42aOfRmU05ls tN3YCjBxslXOF7o5lMXr3kvrESsqt7yxKC5dpOk8el9jlsDHJYP6vdjBtKxwyxQ33XON 21DlSgQtsIWhbIgNoyD2v5qAZmkJ7tHf2ZYGIqQQYL/+h8UISqS43yw2MHKDJWQ23Aqv RAIoSAj74Qpy/qxE1KfSJqtxGyHj8L9ISpMLDFwSDQXyWlCwcIppkESvZyHYqNnIj5x8 FePQ== X-Gm-Message-State: AOAM530QXnKe6tdeTaynQKBBSME5PNnPmZBFnVaIJzHdnvK1XoYJhD1Q HEha0z7JyQoBVzMrF1G5783O07l37fJP4yehQvc7+lKE3vm6XsFHqsuhBP8f9T1MSXv1Rj/2vuB KPdqugrukbwpQrg== X-Received: by 2002:adf:959a:: with SMTP id p26mr6332323wrp.342.1635433538230; Thu, 28 Oct 2021 08:05:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfdaIODQY29LG0UaL6aZJ/CT3C9MkLEbsk0ssVIEjXTS5y0fcCVo0BKxF3WM4rkYpS0feH1Q== X-Received: by 2002:adf:959a:: with SMTP id p26mr6332298wrp.342.1635433538083; Thu, 28 Oct 2021 08:05:38 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Yanan Wang , Eduardo Habkost , Igor Mammedov , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 3/4] hw/core: Extract hotplug-related functions to qdev-hotplug.c Date: Thu, 28 Oct 2021 17:05:20 +0200 Message-Id: <20211028150521.1973821-4-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211028150521.1973821-1-philmd@redhat.com> References: <20211028150521.1973821-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635433542463100001 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Yanan Wang --- hw/core/qdev-hotplug.c | 73 ++++++++++++++++++++++++++++++++++++++++++ hw/core/qdev.c | 60 ---------------------------------- hw/core/meson.build | 1 + 3 files changed, 74 insertions(+), 60 deletions(-) create mode 100644 hw/core/qdev-hotplug.c diff --git a/hw/core/qdev-hotplug.c b/hw/core/qdev-hotplug.c new file mode 100644 index 00000000000..d495d0e9c70 --- /dev/null +++ b/hw/core/qdev-hotplug.c @@ -0,0 +1,73 @@ +/* + * QDev Hotplug handlers + * + * Copyright (c) Red Hat + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/qdev-core.h" +#include "hw/boards.h" + +HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev) +{ + MachineState *machine; + MachineClass *mc; + Object *m_obj =3D qdev_get_machine(); + + if (object_dynamic_cast(m_obj, TYPE_MACHINE)) { + machine =3D MACHINE(m_obj); + mc =3D MACHINE_GET_CLASS(machine); + if (mc->get_hotplug_handler) { + return mc->get_hotplug_handler(machine, dev); + } + } + + return NULL; +} + +bool qdev_hotplug_allowed(DeviceState *dev, Error **errp) +{ + MachineState *machine; + MachineClass *mc; + Object *m_obj =3D qdev_get_machine(); + + if (object_dynamic_cast(m_obj, TYPE_MACHINE)) { + machine =3D MACHINE(m_obj); + mc =3D MACHINE_GET_CLASS(machine); + if (mc->hotplug_allowed) { + return mc->hotplug_allowed(machine, dev, errp); + } + } + + return true; +} + +HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev) +{ + if (dev->parent_bus) { + return dev->parent_bus->hotplug_handler; + } + return NULL; +} + +HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev) +{ + HotplugHandler *hotplug_ctrl =3D qdev_get_machine_hotplug_handler(dev); + + if (hotplug_ctrl =3D=3D NULL && dev->parent_bus) { + hotplug_ctrl =3D qdev_get_bus_hotplug_handler(dev); + } + return hotplug_ctrl; +} + +/* can be used as ->unplug() callback for the simple cases */ +void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + qdev_unrealize(dev); +} diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 7f06403752d..cede76fce47 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -33,7 +33,6 @@ #include "qapi/visitor.h" #include "qemu/error-report.h" #include "qemu/option.h" -#include "hw/hotplug.h" #include "hw/irq.h" #include "hw/qdev-properties.h" #include "hw/boards.h" @@ -238,58 +237,6 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int= alias_id, dev->alias_required_for_version =3D required_for_version; } =20 -HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev) -{ - MachineState *machine; - MachineClass *mc; - Object *m_obj =3D qdev_get_machine(); - - if (object_dynamic_cast(m_obj, TYPE_MACHINE)) { - machine =3D MACHINE(m_obj); - mc =3D MACHINE_GET_CLASS(machine); - if (mc->get_hotplug_handler) { - return mc->get_hotplug_handler(machine, dev); - } - } - - return NULL; -} - -bool qdev_hotplug_allowed(DeviceState *dev, Error **errp) -{ - MachineState *machine; - MachineClass *mc; - Object *m_obj =3D qdev_get_machine(); - - if (object_dynamic_cast(m_obj, TYPE_MACHINE)) { - machine =3D MACHINE(m_obj); - mc =3D MACHINE_GET_CLASS(machine); - if (mc->hotplug_allowed) { - return mc->hotplug_allowed(machine, dev, errp); - } - } - - return true; -} - -HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev) -{ - if (dev->parent_bus) { - return dev->parent_bus->hotplug_handler; - } - return NULL; -} - -HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev) -{ - HotplugHandler *hotplug_ctrl =3D qdev_get_machine_hotplug_handler(dev); - - if (hotplug_ctrl =3D=3D NULL && dev->parent_bus) { - hotplug_ctrl =3D qdev_get_bus_hotplug_handler(dev); - } - return hotplug_ctrl; -} - static int qdev_prereset(DeviceState *dev, void *opaque) { trace_qdev_reset_tree(dev, object_get_typename(OBJECT(dev))); @@ -371,13 +318,6 @@ static void device_reset_child_foreach(Object *obj, Re= settableChildCallback cb, } } =20 -/* can be used as ->unplug() callback for the simple cases */ -void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, - DeviceState *dev, Error **errp) -{ - qdev_unrealize(dev); -} - bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp) { assert(!dev->realized && !dev->parent_bus); diff --git a/hw/core/meson.build b/hw/core/meson.build index 4d04069f85f..85f2ad1374b 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -11,6 +11,7 @@ 'irq.c', 'clock.c', 'qdev-clock.c', + 'qdev-hotplug.c', )) =20 common_ss.add(files('cpu-common.c')) --=20 2.31.1