[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v2 8/9] vpci/msi: add MSI handlers



(Adding maintainers to the Cc...)

On Thu, Apr 20, 2017 at 04:17:42PM +0100, Roger Pau Monne wrote:
[...]
> diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h
> index 75564b9d93..277e860d25 100644
> --- a/xen/include/xen/vpci.h
> +++ b/xen/include/xen/vpci.h
> @@ -88,9 +88,35 @@ struct vpci {
>  
>      /* List of capabilities supported by the device. */
>      struct list_head cap_list;
> +
> +    /* MSI data. */
> +    struct vpci_msi {
> +        /* Maximum number of vectors supported by the device. */
> +        unsigned int max_vectors;
> +        /* Current guest-written number of vectors. */
> +        unsigned int guest_vectors;
> +        /* Number of vectors configured. */
> +        unsigned int vectors;
> +        /* Address and data fields. */
> +        uint64_t address;
> +        uint16_t data;
> +        /* PIRQ */
> +        int pirq;
> +        /* Mask bitfield. */
> +        uint32_t mask;
> +        /* MSI enabled? */
> +        bool enabled;

I've realized that the enabled field is not needed, just checking if pirq != -1
is enough to know if MSIs are enabled or not, so I've folded the following diff
into this patch which removes the enabled field, no functional change.

---8<---
diff --git a/xen/drivers/vpci/msi.c b/xen/drivers/vpci/msi.c
index aea6c68907..329945b30f 100644
--- a/xen/drivers/vpci/msi.c
+++ b/xen/drivers/vpci/msi.c
@@ -46,7 +46,7 @@ static int vpci_msi_control_read(struct pci_dev *pdev, 
unsigned int reg,
 {
     struct vpci_msi *msi = data;
 
-    if ( msi->enabled )
+    if ( msi->pirq != -1 )
         val->word |= PCI_MSI_FLAGS_ENABLE;
     if ( msi->masking )
         val->word |= PCI_MSI_FLAGS_MASKBIT;
@@ -74,7 +74,7 @@ static int vpci_msi_control_write(struct pci_dev *pdev, 
unsigned int reg,
 
     msi->guest_vectors = vectors;
 
-    if ( !((val.word ^ msi->enabled) & PCI_MSI_FLAGS_ENABLE) )
+    if ( !!(val.word & PCI_MSI_FLAGS_ENABLE) == (msi->pirq != -1) )
         return 0;
 
     if ( val.word & PCI_MSI_FLAGS_ENABLE )
@@ -87,7 +87,7 @@ static int vpci_msi_control_write(struct pci_dev *pdev, 
unsigned int reg,
             .entry_nr = vectors,
         };
 
-        ASSERT(!msi->enabled);
+        ASSERT(msi->pirq == -1);
 
         /* Get a PIRQ. */
         rc = allocate_and_map_msi_pirq(pdev->domain, &index, &msi->pirq,
@@ -149,11 +149,10 @@ static int vpci_msi_control_write(struct pci_dev *pdev, 
unsigned int reg,
 
         __msi_set_enable(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
                          PCI_FUNC(pdev->devfn), reg - PCI_MSI_FLAGS, 1);
-        msi->enabled = true;
     }
     else
     {
-        ASSERT(msi->enabled);
+        ASSERT(msi->pirq != -1);
         __msi_set_enable(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),
                          PCI_FUNC(pdev->devfn), reg - PCI_MSI_FLAGS, 0);
 
@@ -178,7 +177,6 @@ static int vpci_msi_control_write(struct pci_dev *pdev, 
unsigned int reg,
 
         msi->pirq = -1;
         msi->vectors = 0;
-        msi->enabled = false;
     }
 
     return 0;
@@ -426,7 +424,7 @@ static void vpci_dump_msi(unsigned char key)
             printk("Device %04x:%02x:%02x.%u\n", seg, bus, slot, func);
 
             printk("Enabled: %u Supports masking: %u 64-bit addresses: %u\n",
-                   msi->enabled, msi->masking, msi->address64);
+                   msi->pirq != -1, msi->masking, msi->address64);
             printk("Max vectors: %u guest vectors: %u enabled vectors: %u\n",
                    msi->max_vectors, msi->guest_vectors, msi->vectors);
 
diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h
index 277e860d25..ad5347b118 100644
--- a/xen/include/xen/vpci.h
+++ b/xen/include/xen/vpci.h
@@ -100,12 +100,10 @@ struct vpci {
         /* Address and data fields. */
         uint64_t address;
         uint16_t data;
-        /* PIRQ */
+        /* PIRQ (if this field is different than -1, MSIs are enabled) */
         int pirq;
         /* Mask bitfield. */
         uint32_t mask;
-        /* MSI enabled? */
-        bool enabled;
         /* Supports per-vector masking? */
         bool masking;
         /* 64-bit address capable? */


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.