From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50383) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WX7n9-0003Hc-K3 for qemu-devel@nongnu.org; Mon, 07 Apr 2014 07:32:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WX7n3-0007i8-Ea for qemu-devel@nongnu.org; Mon, 07 Apr 2014 07:32:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43853) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WX7n3-0007i1-62 for qemu-devel@nongnu.org; Mon, 07 Apr 2014 07:32:37 -0400 Date: Mon, 7 Apr 2014 14:32:41 +0300 From: "Michael S. Tsirkin" Message-ID: <20140407113241.GA15315@redhat.com> References: <1396618620-27823-1-git-send-email-imammedo@redhat.com> <1396618620-27823-24-git-send-email-imammedo@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1396618620-27823-24-git-send-email-imammedo@redhat.com> Subject: Re: [Qemu-devel] [PATCH 23/35] acpi:piix4: make plug/unlug callbacks generic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: peter.maydell@linaro.org, aik@ozlabs.ru, hutao@cn.fujitsu.com, mjt@tls.msk.ru, qemu-devel@nongnu.org, lcapitulino@redhat.com, kraxel@redhat.com, akong@redhat.com, quintela@redhat.com, armbru@redhat.com, aliguori@amazon.com, jan.kiszka@siemens.com, lersek@redhat.com, ehabkost@redhat.com, marcel.a@redhat.com, stefanha@redhat.com, chegu_vinod@hp.com, rth@twiddle.net, kwolf@redhat.com, s.priebe@profihost.ag, mreitz@redhat.com, vasilis.liaskovitis@profitbricks.com, pbonzini@redhat.com, afaerber@suse.de On Fri, Apr 04, 2014 at 03:36:48PM +0200, Igor Mammedov wrote: > ... and report error if plugged in device is not supported. > Later generic callbacks will be used by memory hotplug. > > Signed-off-by: Igor Mammedov OK in that case, how about teaching all hotplug callbacks about this? There are two ATM: shpc_device_hotplug_cb pcie_cap_slot_hotplug_cb Teach them both to fail gracefully if they get an object that is not a pci device. Afterwards, simply iterate over all objects of type TYPE_HOTPLUG_HANDLER and look for one that will accept your object. > --- > hw/acpi/piix4.c | 31 ++++++++++++++++++++++--------- > 1 file changed, 22 insertions(+), 9 deletions(-) > > diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c > index 67dc075..4341f82 100644 > --- a/hw/acpi/piix4.c > +++ b/hw/acpi/piix4.c > @@ -310,19 +310,32 @@ static void piix4_pm_powerdown_req(Notifier *n, void *opaque) > acpi_pm1_evt_power_down(&s->ar); > } > > -static void piix4_pci_device_plug_cb(HotplugHandler *hotplug_dev, > - DeviceState *dev, Error **errp) > +static void piix4_device_plug_cb(HotplugHandler *hotplug_dev, > + DeviceState *dev, Error **errp) > { > PIIX4PMState *s = PIIX4_PM(hotplug_dev); > - acpi_pcihp_device_plug_cb(&s->ar, s->irq, &s->acpi_pci_hotplug, dev, errp); > + > + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { > + acpi_pcihp_device_plug_cb(&s->ar, s->irq, &s->acpi_pci_hotplug, dev, > + errp); > + } else { > + error_setg(errp, "acpi: device plug request for not supported device" > + " type: %s", object_get_typename(OBJECT(dev))); > + } > } > > -static void piix4_pci_device_unplug_cb(HotplugHandler *hotplug_dev, > - DeviceState *dev, Error **errp) > +static void piix4_device_unplug_cb(HotplugHandler *hotplug_dev, > + DeviceState *dev, Error **errp) > { > PIIX4PMState *s = PIIX4_PM(hotplug_dev); > - acpi_pcihp_device_unplug_cb(&s->ar, s->irq, &s->acpi_pci_hotplug, dev, > - errp); > + > + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { > + acpi_pcihp_device_unplug_cb(&s->ar, s->irq, &s->acpi_pci_hotplug, dev, > + errp); > + } else { > + error_setg(errp, "acpi: device unplug request for not supported device" > + " type: %s", object_get_typename(OBJECT(dev))); > + } > } > > static void piix4_update_bus_hotplug(PCIBus *pci_bus, void *opaque) > @@ -553,8 +566,8 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) > */ > dc->cannot_instantiate_with_device_add_yet = true; > dc->hotpluggable = false; > - hc->plug = piix4_pci_device_plug_cb; > - hc->unplug = piix4_pci_device_unplug_cb; > + hc->plug = piix4_device_plug_cb; > + hc->unplug = piix4_device_unplug_cb; > } > > static const TypeInfo piix4_pm_info = { > -- > 1.9.0