diff mbox

[12/12] spapr_pci: emit hotplug add/remove events during hotplug

Message ID 1408407718-10835-13-git-send-email-mdroth@linux.vnet.ibm.com
State New
Headers show

Commit Message

Michael Roth Aug. 19, 2014, 12:21 a.m. UTC
From: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>

This uses extension of existing EPOW interrupt/event mechanism
to notify userspace tools like librtas/drmgr to handle
in-guest configuration/cleanup operations in response to
device_add/device_del.

Userspace tools that don't implement this extension will need
to be run manually in response/advance of device_add/device_del,
respectively.

Signed-off-by: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 hw/ppc/spapr_pci.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Alexey Kardashevskiy Aug. 26, 2014, 9:35 a.m. UTC | #1
On 08/19/2014 10:21 AM, Michael Roth wrote:
> From: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
> 
> This uses extension of existing EPOW interrupt/event mechanism
> to notify userspace tools like librtas/drmgr to handle
> in-guest configuration/cleanup operations in response to
> device_add/device_del.
> 
> Userspace tools that don't implement this extension will need
> to be run manually in response/advance of device_add/device_del,
> respectively.
> 
> Signed-off-by: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
> ---
>  hw/ppc/spapr_pci.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index 23864ab..17d37c0 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -944,6 +944,18 @@ static int spapr_device_hotplug_add(DeviceState *qdev, PCIDevice *dev)
>      drc_entry_slot->state &= ~(uint32_t)INDICATOR_ENTITY_SENSE_MASK;
>      drc_entry_slot->state |= encoded; /* and the slot */
>  
> +    /* reliable unplug requires we wait for a transition from
> +     * UNISOLATED->ISOLATED prior to device removal/deletion.
> +     * However, slots populated by devices at boot-time will not
> +     * have ever been set by guest tools to an UNISOLATED/populated
> +     * state, so set this manually in the case of coldplug devices
> +     */
> +    if (!DEVICE(dev)->hotplugged) {
> +        drc_entry_slot->state |= ENCODE_DRC_STATE(1,
> +                                                  INDICATOR_ISOLATION_MASK,
> +                                                  INDICATOR_ISOLATION_SHIFT);
> +    }
> +
>      /* add OF node for pci device and required OF DT properties */
>      fdt_orig = g_malloc0(FDT_MAX_SIZE);
>      offset = fdt_create(fdt_orig, FDT_MAX_SIZE);
> @@ -1026,13 +1038,21 @@ static void spapr_device_hotplug_remove(DeviceState *qdev, PCIDevice *dev)
>  static void spapr_phb_hot_plug(HotplugHandler *plug_handler,
>                                 DeviceState *plugged_dev, Error **errp)
>  {
> +    int slot = PCI_SLOT(PCI_DEVICE(plugged_dev)->devfn);
> +
>      spapr_device_hotplug_add(DEVICE(plug_handler), PCI_DEVICE(plugged_dev));
> +    if (plugged_dev->hotplugged) {
> +        spapr_pci_hotplug_add_event(DEVICE(plug_handler), slot);
> +    }


Minor comment here :)
@slot is a temporary variable and it used once. Ok, may be it increases
readability, then it makes sense to have local variables for
PCI_DEVICE(plugged_dev) and DEVICE(plug_handler) too as they both are
calculated twice. But I do not insist :)


>  }
>  
>  static void spapr_phb_hot_unplug(HotplugHandler *plug_handler,
>                                   DeviceState *plugged_dev, Error **errp)
>  {
> +    int slot = PCI_SLOT(PCI_DEVICE(plugged_dev)->devfn);
> +
>      spapr_device_hotplug_remove(DEVICE(plug_handler), PCI_DEVICE(plugged_dev));
> +    spapr_pci_hotplug_remove_event(DEVICE(plug_handler), slot);
>  }

Same here.

>  
>  static void spapr_phb_realize(DeviceState *dev, Error **errp)
>
Alexander Graf Aug. 26, 2014, 12:36 p.m. UTC | #2
On 19.08.14 02:21, Michael Roth wrote:
> From: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
> 
> This uses extension of existing EPOW interrupt/event mechanism
> to notify userspace tools like librtas/drmgr to handle
> in-guest configuration/cleanup operations in response to
> device_add/device_del.
> 
> Userspace tools that don't implement this extension will need
> to be run manually in response/advance of device_add/device_del,
> respectively.

Couldn't they use the pull event mechanism you implement in the previous
patch?

> 
> Signed-off-by: Tyrel Datwyler <tyreld@linux.vnet.ibm.com>
> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
> ---
>  hw/ppc/spapr_pci.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index 23864ab..17d37c0 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -944,6 +944,18 @@ static int spapr_device_hotplug_add(DeviceState *qdev, PCIDevice *dev)
>      drc_entry_slot->state &= ~(uint32_t)INDICATOR_ENTITY_SENSE_MASK;
>      drc_entry_slot->state |= encoded; /* and the slot */
>  
> +    /* reliable unplug requires we wait for a transition from
> +     * UNISOLATED->ISOLATED prior to device removal/deletion.
> +     * However, slots populated by devices at boot-time will not
> +     * have ever been set by guest tools to an UNISOLATED/populated
> +     * state, so set this manually in the case of coldplug devices
> +     */
> +    if (!DEVICE(dev)->hotplugged) {
> +        drc_entry_slot->state |= ENCODE_DRC_STATE(1,
> +                                                  INDICATOR_ISOLATION_MASK,
> +                                                  INDICATOR_ISOLATION_SHIFT);

I think as a general scheme we would like to have the PHB call DRC
(which it knows from a qom link) which raises a qemu_irq to notify the
EPOW device that an event happened. If the EPOW interface is too
complex, I guess we can live with a link and function call too.


Alex
diff mbox

Patch

diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 23864ab..17d37c0 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -944,6 +944,18 @@  static int spapr_device_hotplug_add(DeviceState *qdev, PCIDevice *dev)
     drc_entry_slot->state &= ~(uint32_t)INDICATOR_ENTITY_SENSE_MASK;
     drc_entry_slot->state |= encoded; /* and the slot */
 
+    /* reliable unplug requires we wait for a transition from
+     * UNISOLATED->ISOLATED prior to device removal/deletion.
+     * However, slots populated by devices at boot-time will not
+     * have ever been set by guest tools to an UNISOLATED/populated
+     * state, so set this manually in the case of coldplug devices
+     */
+    if (!DEVICE(dev)->hotplugged) {
+        drc_entry_slot->state |= ENCODE_DRC_STATE(1,
+                                                  INDICATOR_ISOLATION_MASK,
+                                                  INDICATOR_ISOLATION_SHIFT);
+    }
+
     /* add OF node for pci device and required OF DT properties */
     fdt_orig = g_malloc0(FDT_MAX_SIZE);
     offset = fdt_create(fdt_orig, FDT_MAX_SIZE);
@@ -1026,13 +1038,21 @@  static void spapr_device_hotplug_remove(DeviceState *qdev, PCIDevice *dev)
 static void spapr_phb_hot_plug(HotplugHandler *plug_handler,
                                DeviceState *plugged_dev, Error **errp)
 {
+    int slot = PCI_SLOT(PCI_DEVICE(plugged_dev)->devfn);
+
     spapr_device_hotplug_add(DEVICE(plug_handler), PCI_DEVICE(plugged_dev));
+    if (plugged_dev->hotplugged) {
+        spapr_pci_hotplug_add_event(DEVICE(plug_handler), slot);
+    }
 }
 
 static void spapr_phb_hot_unplug(HotplugHandler *plug_handler,
                                  DeviceState *plugged_dev, Error **errp)
 {
+    int slot = PCI_SLOT(PCI_DEVICE(plugged_dev)->devfn);
+
     spapr_device_hotplug_remove(DEVICE(plug_handler), PCI_DEVICE(plugged_dev));
+    spapr_pci_hotplug_remove_event(DEVICE(plug_handler), slot);
 }
 
 static void spapr_phb_realize(DeviceState *dev, Error **errp)