Patchwork [v3,8/8] msi: Use msi/msix_present more consistently

login
register
mail settings
Submitter Jan Kiszka
Date May 11, 2012, 2:42 p.m.
Message ID <b036a21005fbd6f21c89940ffd325db3dcb7ae66.1336747349.git.jan.kiszka@siemens.com>
Download mbox | patch
Permalink /patch/158530/
State New
Headers show

Comments

Jan Kiszka - May 11, 2012, 2:42 p.m.
Replace some open-coded msi/msix_present checks.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 hw/msi.c  |    2 +-
 hw/msix.c |   13 ++++++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)
Michael S. Tsirkin - June 4, 2012, 2:48 p.m.
On Fri, May 11, 2012 at 11:42:41AM -0300, Jan Kiszka wrote:
> Replace some open-coded msi/msix_present checks.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>

This last one doesn't apply but I don't expect this blocks
anything. Applied 1-7 for now.

> ---
>  hw/msi.c  |    2 +-
>  hw/msix.c |   13 ++++++++-----
>  2 files changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/msi.c b/hw/msi.c
> index 556c7c4..5233204 100644
> --- a/hw/msi.c
> +++ b/hw/msi.c
> @@ -175,7 +175,7 @@ void msi_uninit(struct PCIDevice *dev)
>      uint16_t flags;
>      uint8_t cap_size;
>  
> -    if (!(dev->cap_present & QEMU_PCI_CAP_MSI)) {
> +    if (!msi_present(dev)) {
>          return;
>      }
>      flags = pci_get_word(dev->config + msi_flags_off(dev));
> diff --git a/hw/msix.c b/hw/msix.c
> index 84915d8..7c314bb 100644
> --- a/hw/msix.c
> +++ b/hw/msix.c
> @@ -285,8 +285,9 @@ static void msix_free_irq_entries(PCIDevice *dev)
>  /* Clean up resources for the device. */
>  int msix_uninit(PCIDevice *dev, MemoryRegion *bar)
>  {
> -    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX))
> +    if (!msix_present(dev)) {
>          return 0;
> +    }
>      pci_del_capability(dev, PCI_CAP_ID_MSIX, MSIX_CAP_LENGTH);
>      dev->msix_cap = 0;
>      msix_free_irq_entries(dev);
> @@ -305,7 +306,7 @@ void msix_save(PCIDevice *dev, QEMUFile *f)
>  {
>      unsigned n = dev->msix_entries_nr;
>  
> -    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX)) {
> +    if (!msix_present(dev)) {
>          return;
>      }
>  
> @@ -318,7 +319,7 @@ void msix_load(PCIDevice *dev, QEMUFile *f)
>  {
>      unsigned n = dev->msix_entries_nr;
>  
> -    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX)) {
> +    if (!msix_present(dev)) {
>          return;
>      }
>  
> @@ -370,8 +371,9 @@ void msix_notify(PCIDevice *dev, unsigned vector)
>  
>  void msix_reset(PCIDevice *dev)
>  {
> -    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX))
> +    if (!msix_present(dev)) {
>          return;
> +    }
>      msix_free_irq_entries(dev);
>      dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] &=
>  	    ~dev->wmask[dev->msix_cap + MSIX_CONTROL_OFFSET];
> @@ -410,7 +412,8 @@ void msix_vector_unuse(PCIDevice *dev, unsigned vector)
>  
>  void msix_unuse_all_vectors(PCIDevice *dev)
>  {
> -    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX))
> +    if (!msix_present(dev)) {
>          return;
> +    }
>      msix_free_irq_entries(dev);
>  }
> -- 
> 1.7.3.4

Patch

diff --git a/hw/msi.c b/hw/msi.c
index 556c7c4..5233204 100644
--- a/hw/msi.c
+++ b/hw/msi.c
@@ -175,7 +175,7 @@  void msi_uninit(struct PCIDevice *dev)
     uint16_t flags;
     uint8_t cap_size;
 
-    if (!(dev->cap_present & QEMU_PCI_CAP_MSI)) {
+    if (!msi_present(dev)) {
         return;
     }
     flags = pci_get_word(dev->config + msi_flags_off(dev));
diff --git a/hw/msix.c b/hw/msix.c
index 84915d8..7c314bb 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -285,8 +285,9 @@  static void msix_free_irq_entries(PCIDevice *dev)
 /* Clean up resources for the device. */
 int msix_uninit(PCIDevice *dev, MemoryRegion *bar)
 {
-    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX))
+    if (!msix_present(dev)) {
         return 0;
+    }
     pci_del_capability(dev, PCI_CAP_ID_MSIX, MSIX_CAP_LENGTH);
     dev->msix_cap = 0;
     msix_free_irq_entries(dev);
@@ -305,7 +306,7 @@  void msix_save(PCIDevice *dev, QEMUFile *f)
 {
     unsigned n = dev->msix_entries_nr;
 
-    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX)) {
+    if (!msix_present(dev)) {
         return;
     }
 
@@ -318,7 +319,7 @@  void msix_load(PCIDevice *dev, QEMUFile *f)
 {
     unsigned n = dev->msix_entries_nr;
 
-    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX)) {
+    if (!msix_present(dev)) {
         return;
     }
 
@@ -370,8 +371,9 @@  void msix_notify(PCIDevice *dev, unsigned vector)
 
 void msix_reset(PCIDevice *dev)
 {
-    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX))
+    if (!msix_present(dev)) {
         return;
+    }
     msix_free_irq_entries(dev);
     dev->config[dev->msix_cap + MSIX_CONTROL_OFFSET] &=
 	    ~dev->wmask[dev->msix_cap + MSIX_CONTROL_OFFSET];
@@ -410,7 +412,8 @@  void msix_vector_unuse(PCIDevice *dev, unsigned vector)
 
 void msix_unuse_all_vectors(PCIDevice *dev)
 {
-    if (!(dev->cap_present & QEMU_PCI_CAP_MSIX))
+    if (!msix_present(dev)) {
         return;
+    }
     msix_free_irq_entries(dev);
 }