Patchwork [6/6] pci/aer: factor out common code

login
register
mail settings
Submitter Michael S. Tsirkin
Date Dec. 2, 2010, 10:54 p.m.
Message ID <7ab56779a4dcd09712ff1045ca8dcd312faae435.1291330353.git.mst@redhat.com>
Download mbox | patch
Permalink /patch/74042/
State New
Headers show

Comments

Michael S. Tsirkin - Dec. 2, 2010, 10:54 p.m.
Same logic is used to assert interrupts
and send msix messages, so add a static functin for this.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pcie_aer.c |   27 +++++++++++++--------------
 1 files changed, 13 insertions(+), 14 deletions(-)
Isaku Yamahata - Dec. 7, 2010, 7:24 a.m.
Looks good.
Maybe assert(0) should be replaced by abort().
Anyway this patch removes it, though.

On Fri, Dec 03, 2010 at 12:54:47AM +0200, Michael S. Tsirkin wrote:
> Same logic is used to assert interrupts
> and send msix messages, so add a static functin for this.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  hw/pcie_aer.c |   27 +++++++++++++--------------
>  1 files changed, 13 insertions(+), 14 deletions(-)
> 
> diff --git a/hw/pcie_aer.c b/hw/pcie_aer.c
> index 1c513a7..ca4f517 100644
> --- a/hw/pcie_aer.c
> +++ b/hw/pcie_aer.c
> @@ -273,6 +273,17 @@ static uint32_t pcie_aer_status_to_cmd(uint32_t status)
>      return cmd;
>  }
>  
> +static void pcie_aer_root_notify(PCIDevice *dev)
> +{
> +    if (msix_enabled(dev)) {
> +        msix_notify(dev, pcie_aer_root_get_vector(dev));
> +    } else if (msi_enabled(dev)) {
> +        msi_notify(dev, pcie_aer_root_get_vector(dev));
> +    } else {
> +        qemu_set_irq(dev->irq[dev->exp.aer_intx], 1);
> +    }
> +}
> +
>  /*
>   * 6.2.6 Error Message Control
>   * Figure 6-3
> @@ -352,13 +363,7 @@ static void pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg)
>          return;
>      }
>  
> -    if (msix_enabled(dev)) {
> -        msix_notify(dev, pcie_aer_root_get_vector(dev));
> -    } else if (msi_enabled(dev)) {
> -        msi_notify(dev, pcie_aer_root_get_vector(dev));
> -    } else {
> -        qemu_set_irq(dev->irq[dev->exp.aer_intx], 1);
> -    }
> +    pcie_aer_root_notify(dev);
>  }
>  
>  /*
> @@ -768,13 +773,7 @@ void pcie_aer_root_write_config(PCIDevice *dev,
>          return;
>      }
>  
> -    if (msix_enabled(dev)) {
> -        msix_notify(dev, pcie_aer_root_get_vector(dev));
> -    } else if (msi_enabled(dev)) {
> -        msi_notify(dev, pcie_aer_root_get_vector(dev));
> -    } else {
> -        assert(0);
> -    }
> +    pcie_aer_root_notify(dev);
>  }
>  
>  static const VMStateDescription vmstate_pcie_aer_err = {
> -- 
> 1.7.3.2.91.g446ac
>

Patch

diff --git a/hw/pcie_aer.c b/hw/pcie_aer.c
index 1c513a7..ca4f517 100644
--- a/hw/pcie_aer.c
+++ b/hw/pcie_aer.c
@@ -273,6 +273,17 @@  static uint32_t pcie_aer_status_to_cmd(uint32_t status)
     return cmd;
 }
 
+static void pcie_aer_root_notify(PCIDevice *dev)
+{
+    if (msix_enabled(dev)) {
+        msix_notify(dev, pcie_aer_root_get_vector(dev));
+    } else if (msi_enabled(dev)) {
+        msi_notify(dev, pcie_aer_root_get_vector(dev));
+    } else {
+        qemu_set_irq(dev->irq[dev->exp.aer_intx], 1);
+    }
+}
+
 /*
  * 6.2.6 Error Message Control
  * Figure 6-3
@@ -352,13 +363,7 @@  static void pcie_aer_msg_root_port(PCIDevice *dev, const PCIEAERMsg *msg)
         return;
     }
 
-    if (msix_enabled(dev)) {
-        msix_notify(dev, pcie_aer_root_get_vector(dev));
-    } else if (msi_enabled(dev)) {
-        msi_notify(dev, pcie_aer_root_get_vector(dev));
-    } else {
-        qemu_set_irq(dev->irq[dev->exp.aer_intx], 1);
-    }
+    pcie_aer_root_notify(dev);
 }
 
 /*
@@ -768,13 +773,7 @@  void pcie_aer_root_write_config(PCIDevice *dev,
         return;
     }
 
-    if (msix_enabled(dev)) {
-        msix_notify(dev, pcie_aer_root_get_vector(dev));
-    } else if (msi_enabled(dev)) {
-        msi_notify(dev, pcie_aer_root_get_vector(dev));
-    } else {
-        assert(0);
-    }
+    pcie_aer_root_notify(dev);
 }
 
 static const VMStateDescription vmstate_pcie_aer_err = {