diff mbox

[v2,1/4] pci: allow devices being tagged as not hotpluggable.

Message ID 1294323280-21692-2-git-send-email-kraxel@redhat.com
State New
Headers show

Commit Message

Gerd Hoffmann Jan. 6, 2011, 2:14 p.m. UTC
This patch adds a field to PCIDeviceInfo to tag devices as being
not hotpluggable.  Any attempt to plug-in or -out such a device
will throw an error.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/pci.c |   10 ++++++++++
 hw/pci.h |    3 +++
 qerror.c |    4 ++++
 qerror.h |    3 +++
 4 files changed, 20 insertions(+), 0 deletions(-)

Comments

Michael S. Tsirkin Jan. 6, 2011, 5:52 p.m. UTC | #1
On Thu, Jan 06, 2011 at 03:14:37PM +0100, Gerd Hoffmann wrote:
> This patch adds a field to PCIDeviceInfo to tag devices as being
> not hotpluggable.  Any attempt to plug-in or -out such a device
> will throw an error.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
>  hw/pci.c |   10 ++++++++++
>  hw/pci.h |    3 +++
>  qerror.c |    4 ++++
>  qerror.h |    3 +++
>  4 files changed, 20 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/pci.c b/hw/pci.c
> index ef00d20..a4ae3b2 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -1620,6 +1620,11 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
>                                       info->is_bridge);
>      if (pci_dev == NULL)
>          return -1;
> +    if (qdev->hotplugged && info->no_hotplug) {
> +        qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name);
> +        do_pci_unregister_device(pci_dev);
> +        return -1;
> +    }
>      rc = info->init(pci_dev);
>      if (rc != 0) {
>          do_pci_unregister_device(pci_dev);
> @@ -1652,7 +1657,12 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
>  static int pci_unplug_device(DeviceState *qdev)
>  {
>      PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
> +    PCIDeviceInfo *info = container_of(qdev->info, PCIDeviceInfo, qdev);
>  
> +    if (info->no_hotplug) {
> +        qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name);
> +        return -1;
> +    }
>      return dev->bus->hotplug(dev->bus->hotplug_qdev, dev,
>                               PCI_HOTPLUG_DISABLED);
>  }
> diff --git a/hw/pci.h b/hw/pci.h
> index 17744dc..6b4bd3e 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -434,6 +434,9 @@ typedef struct {
>      /* pcie stuff */
>      int is_express;   /* is this device pci express? */
>  
> +    /* device isn't hot-pluggable */
> +    int no_hotplug;
> +
>      /* rom bar */
>      const char *romfile;
>  } PCIDeviceInfo;
> diff --git a/qerror.c b/qerror.c
> index ac2cdaf..9d0cdeb 100644
> --- a/qerror.c
> +++ b/qerror.c
> @@ -101,6 +101,10 @@ static const QErrorStringTable qerror_table[] = {
>          .desc      = "Device '%(device)' has no child bus",
>      },
>      {
> +        .error_fmt = QERR_DEVICE_NO_HOTPLUG,
> +        .desc      = "Device '%(device)' does not support hotplugging",
> +    },
> +    {
>          .error_fmt = QERR_DUPLICATE_ID,
>          .desc      = "Duplicate ID '%(id)' for %(object)",
>      },
> diff --git a/qerror.h b/qerror.h
> index 943a24b..b0f69da 100644
> --- a/qerror.h
> +++ b/qerror.h
> @@ -90,6 +90,9 @@ QError *qobject_to_qerror(const QObject *obj);
>  #define QERR_DEVICE_NO_BUS \
>      "{ 'class': 'DeviceNoBus', 'data': { 'device': %s } }"
>  
> +#define QERR_DEVICE_NO_HOTPLUG \
> +    "{ 'class': 'DeviceNoHotplug', 'data': { 'device': %s } }"
> +
>  #define QERR_DUPLICATE_ID \
>      "{ 'class': 'DuplicateId', 'data': { 'id': %s, 'object': %s } }"
>  
> -- 
> 1.7.1
>
Markus Armbruster Jan. 12, 2011, 12:19 p.m. UTC | #2
Gerd Hoffmann <kraxel@redhat.com> writes:

> This patch adds a field to PCIDeviceInfo to tag devices as being
> not hotpluggable.  Any attempt to plug-in or -out such a device
> will throw an error.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/pci.c |   10 ++++++++++
>  hw/pci.h |    3 +++
>  qerror.c |    4 ++++
>  qerror.h |    3 +++
>  4 files changed, 20 insertions(+), 0 deletions(-)
>
> diff --git a/hw/pci.c b/hw/pci.c
> index ef00d20..a4ae3b2 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -1620,6 +1620,11 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
>                                       info->is_bridge);
>      if (pci_dev == NULL)
>          return -1;
> +    if (qdev->hotplugged && info->no_hotplug) {
> +        qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name);
> +        do_pci_unregister_device(pci_dev);
> +        return -1;
> +    }

Any particular reason for not check this before
do_pci_register_device()?

>      rc = info->init(pci_dev);
>      if (rc != 0) {
>          do_pci_unregister_device(pci_dev);
[...]
> @@ -1652,7 +1657,12 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
>  static int pci_unplug_device(DeviceState *qdev)
>  {
>      PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
> +    PCIDeviceInfo *info = container_of(qdev->info, PCIDeviceInfo, qdev);
>  
> +    if (info->no_hotplug) {
> +        qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name);
> +        return -1;
> +    }
>      return dev->bus->hotplug(dev->bus->hotplug_qdev, dev,
>                               PCI_HOTPLUG_DISABLED);
>  }
> diff --git a/hw/pci.h b/hw/pci.h
> index 17744dc..6b4bd3e 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -434,6 +434,9 @@ typedef struct {
>      /* pcie stuff */
>      int is_express;   /* is this device pci express? */
>  
> +    /* device isn't hot-pluggable */
> +    int no_hotplug;
> +
>      /* rom bar */
>      const char *romfile;
>  } PCIDeviceInfo;
> diff --git a/qerror.c b/qerror.c
> index ac2cdaf..9d0cdeb 100644
> --- a/qerror.c
> +++ b/qerror.c
> @@ -101,6 +101,10 @@ static const QErrorStringTable qerror_table[] = {
>          .desc      = "Device '%(device)' has no child bus",
>      },
>      {
> +        .error_fmt = QERR_DEVICE_NO_HOTPLUG,
> +        .desc      = "Device '%(device)' does not support hotplugging",
> +    },
> +    {

I'd prefer "can't be hot-plugged", but I doubt it's worth a respin.

>          .error_fmt = QERR_DUPLICATE_ID,
>          .desc      = "Duplicate ID '%(id)' for %(object)",
>      },
> diff --git a/qerror.h b/qerror.h
> index 943a24b..b0f69da 100644
> --- a/qerror.h
> +++ b/qerror.h
> @@ -90,6 +90,9 @@ QError *qobject_to_qerror(const QObject *obj);
>  #define QERR_DEVICE_NO_BUS \
>      "{ 'class': 'DeviceNoBus', 'data': { 'device': %s } }"
>  
> +#define QERR_DEVICE_NO_HOTPLUG \
> +    "{ 'class': 'DeviceNoHotplug', 'data': { 'device': %s } }"
> +
>  #define QERR_DUPLICATE_ID \
>      "{ 'class': 'DuplicateId', 'data': { 'id': %s, 'object': %s } }"
Gerd Hoffmann Jan. 13, 2011, 12:12 p.m. UTC | #3
>> @@ -1620,6 +1620,11 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
>>                                        info->is_bridge);
>>       if (pci_dev == NULL)
>>           return -1;
>> +    if (qdev->hotplugged&&  info->no_hotplug) {
>> +        qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name);
>> +        do_pci_unregister_device(pci_dev);
>> +        return -1;
>> +    }
>
> Any particular reason for not check this before
> do_pci_register_device()?

Don't remember, probably not.  I think can could be moved up (and loose 
the unregister call) and behavior will not change.

cheers,
   Gerd
diff mbox

Patch

diff --git a/hw/pci.c b/hw/pci.c
index ef00d20..a4ae3b2 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1620,6 +1620,11 @@  static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
                                      info->is_bridge);
     if (pci_dev == NULL)
         return -1;
+    if (qdev->hotplugged && info->no_hotplug) {
+        qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name);
+        do_pci_unregister_device(pci_dev);
+        return -1;
+    }
     rc = info->init(pci_dev);
     if (rc != 0) {
         do_pci_unregister_device(pci_dev);
@@ -1652,7 +1657,12 @@  static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
 static int pci_unplug_device(DeviceState *qdev)
 {
     PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
+    PCIDeviceInfo *info = container_of(qdev->info, PCIDeviceInfo, qdev);
 
+    if (info->no_hotplug) {
+        qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name);
+        return -1;
+    }
     return dev->bus->hotplug(dev->bus->hotplug_qdev, dev,
                              PCI_HOTPLUG_DISABLED);
 }
diff --git a/hw/pci.h b/hw/pci.h
index 17744dc..6b4bd3e 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -434,6 +434,9 @@  typedef struct {
     /* pcie stuff */
     int is_express;   /* is this device pci express? */
 
+    /* device isn't hot-pluggable */
+    int no_hotplug;
+
     /* rom bar */
     const char *romfile;
 } PCIDeviceInfo;
diff --git a/qerror.c b/qerror.c
index ac2cdaf..9d0cdeb 100644
--- a/qerror.c
+++ b/qerror.c
@@ -101,6 +101,10 @@  static const QErrorStringTable qerror_table[] = {
         .desc      = "Device '%(device)' has no child bus",
     },
     {
+        .error_fmt = QERR_DEVICE_NO_HOTPLUG,
+        .desc      = "Device '%(device)' does not support hotplugging",
+    },
+    {
         .error_fmt = QERR_DUPLICATE_ID,
         .desc      = "Duplicate ID '%(id)' for %(object)",
     },
diff --git a/qerror.h b/qerror.h
index 943a24b..b0f69da 100644
--- a/qerror.h
+++ b/qerror.h
@@ -90,6 +90,9 @@  QError *qobject_to_qerror(const QObject *obj);
 #define QERR_DEVICE_NO_BUS \
     "{ 'class': 'DeviceNoBus', 'data': { 'device': %s } }"
 
+#define QERR_DEVICE_NO_HOTPLUG \
+    "{ 'class': 'DeviceNoHotplug', 'data': { 'device': %s } }"
+
 #define QERR_DUPLICATE_ID \
     "{ 'class': 'DuplicateId', 'data': { 'id': %s, 'object': %s } }"