Patchwork [1/4] Introduce a new hotplug state: Force eject.

login
register
mail settings
Submitter Anthony PERARD
Date May 15, 2012, 3:26 p.m.
Message ID <1337095599-28836-2-git-send-email-anthony.perard@citrix.com>
Download mbox | patch
Permalink /patch/159368/
State New
Headers show

Comments

Anthony PERARD - May 15, 2012, 3:26 p.m.
This hotplug state will be used to remove a device without the guest
cooperation.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 hw/acpi_piix4.c |    5 +++++
 hw/pci.h        |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)
Stefano Stabellini - May 15, 2012, 6:19 p.m.
On Tue, 15 May 2012, Anthony PERARD wrote:
> This hotplug state will be used to remove a device without the guest
> cooperation.
> 
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> ---
>  hw/acpi_piix4.c |    5 +++++
>  hw/pci.h        |    1 +
>  2 files changed, 6 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
> index 585da4e..dfd5a9d 100644
> --- a/hw/acpi_piix4.c
> +++ b/hw/acpi_piix4.c
> @@ -587,6 +587,11 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
>          return 0;
>      }
>  
> +    if (state == PCI_FORCE_EJECT) {
> +        acpi_piix_eject_slot(s, 1 << slot);
> +        return 0;
> +    }
> +
>      if (state == PCI_HOTPLUG_ENABLED) {
>          enable_device(s, slot);
>      } else {
> diff --git a/hw/pci.h b/hw/pci.h
> index 8d0aa49..3b61e43 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -273,6 +273,7 @@ typedef enum {
>      PCI_HOTPLUG_DISABLED,
>      PCI_HOTPLUG_ENABLED,
>      PCI_COLDPLUG_ENABLED,
> +    PCI_FORCE_EJECT,
>  } PCIHotplugState;

Given that it is supposed to be a state rather than an action, it should
be called PCI_FORCE_DISABLED or something like that.
Anthony PERARD - May 15, 2012, 6:25 p.m.
On Tue, May 15, 2012 at 7:19 PM, Stefano Stabellini
<stefano.stabellini@eu.citrix.com> wrote:
>
> Given that it is supposed to be a state rather than an action, it should
> be called PCI_FORCE_DISABLED or something like that.

Ok, I will change to that.

Thanks,
Michael S. Tsirkin - May 15, 2012, 8:52 p.m.
On Tue, May 15, 2012 at 04:26:36PM +0100, Anthony PERARD wrote:
> This hotplug state will be used to remove a device without the guest
> cooperation.
> 
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>

This can crash guest, can't it? If you are fine with crashing guest,
we already let you do this:
- delete device
- reset guest
no need for new flags.

> ---
>  hw/acpi_piix4.c |    5 +++++
>  hw/pci.h        |    1 +
>  2 files changed, 6 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
> index 585da4e..dfd5a9d 100644
> --- a/hw/acpi_piix4.c
> +++ b/hw/acpi_piix4.c
> @@ -587,6 +587,11 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
>          return 0;
>      }
>  
> +    if (state == PCI_FORCE_EJECT) {
> +        acpi_piix_eject_slot(s, 1 << slot);
> +        return 0;
> +    }
> +
>      if (state == PCI_HOTPLUG_ENABLED) {
>          enable_device(s, slot);
>      } else {
> diff --git a/hw/pci.h b/hw/pci.h
> index 8d0aa49..3b61e43 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -273,6 +273,7 @@ typedef enum {
>      PCI_HOTPLUG_DISABLED,
>      PCI_HOTPLUG_ENABLED,
>      PCI_COLDPLUG_ENABLED,
> +    PCI_FORCE_EJECT,
>  } PCIHotplugState;
>  
>  typedef int (*pci_hotplug_fn)(DeviceState *qdev, PCIDevice *pci_dev,
> -- 
> Anthony PERARD

Patch

diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index 585da4e..dfd5a9d 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -587,6 +587,11 @@  static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
         return 0;
     }
 
+    if (state == PCI_FORCE_EJECT) {
+        acpi_piix_eject_slot(s, 1 << slot);
+        return 0;
+    }
+
     if (state == PCI_HOTPLUG_ENABLED) {
         enable_device(s, slot);
     } else {
diff --git a/hw/pci.h b/hw/pci.h
index 8d0aa49..3b61e43 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -273,6 +273,7 @@  typedef enum {
     PCI_HOTPLUG_DISABLED,
     PCI_HOTPLUG_ENABLED,
     PCI_COLDPLUG_ENABLED,
+    PCI_FORCE_EJECT,
 } PCIHotplugState;
 
 typedef int (*pci_hotplug_fn)(DeviceState *qdev, PCIDevice *pci_dev,