Patchwork [1/3] msi: Allow pre-existing MSI capabilities

login
register
mail settings
Submitter Alex Williamson
Date Nov. 2, 2010, 5:37 a.m.
Message ID <20101102053727.10424.32902.stgit@s20.home>
Download mbox | patch
Permalink /patch/69862/
State New
Headers show

Comments

Alex Williamson - Nov. 2, 2010, 5:37 a.m.
For use with device assignment, allow calling msi_init() on devices
with MSI capability already configured.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

 hw/msi.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
Michael S. Tsirkin - Nov. 2, 2010, 12:02 p.m.
On Mon, Nov 01, 2010 at 11:37:32PM -0600, Alex Williamson wrote:
> For use with device assignment, allow calling msi_init() on devices
> with MSI capability already configured.
> 
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Looks like the same find/add trick is repeated all over:
you put it in msix and now in msi. How about
we teach pci_add_capability about this functionality?
Then if offset is != 0 and capability is found, we can assert.

> ---
>  
>  hw/msi.c |   12 +++++++++---
>  1 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/msi.c b/hw/msi.c
> index f03f519..0ad4e38 100644
> --- a/hw/msi.c
> +++ b/hw/msi.c
> @@ -135,10 +135,16 @@ int msi_init(struct PCIDevice *dev, uint8_t offset,
>          flags |= PCI_MSI_FLAGS_MASKBIT;
>      }
>  
> +    config_offset = pci_find_capability(dev, PCI_CAP_ID_MSI);
> +
>      cap_size = msi_cap_sizeof(flags);
> -    config_offset = pci_add_capability(dev, PCI_CAP_ID_MSI, offset, cap_size);
> -    if (config_offset < 0) {
> -        return config_offset;
> +
> +    if (!config_offset) {
> +        config_offset = pci_add_capability(dev, PCI_CAP_ID_MSI,
> +                                           offset, cap_size);
> +        if (config_offset < 0) {
> +            return config_offset;
> +        }
>      }
>  
>      dev->msi_cap = config_offset;

Patch

diff --git a/hw/msi.c b/hw/msi.c
index f03f519..0ad4e38 100644
--- a/hw/msi.c
+++ b/hw/msi.c
@@ -135,10 +135,16 @@  int msi_init(struct PCIDevice *dev, uint8_t offset,
         flags |= PCI_MSI_FLAGS_MASKBIT;
     }
 
+    config_offset = pci_find_capability(dev, PCI_CAP_ID_MSI);
+
     cap_size = msi_cap_sizeof(flags);
-    config_offset = pci_add_capability(dev, PCI_CAP_ID_MSI, offset, cap_size);
-    if (config_offset < 0) {
-        return config_offset;
+
+    if (!config_offset) {
+        config_offset = pci_add_capability(dev, PCI_CAP_ID_MSI,
+                                           offset, cap_size);
+        if (config_offset < 0) {
+            return config_offset;
+        }
     }
 
     dev->msi_cap = config_offset;