diff mbox

[V3,14/29] x86/vvtd: Enable Interrupt Remapping through GCMD

Message ID 1506049330-11196-15-git-send-email-tianyu.lan@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

lan,Tianyu Sept. 22, 2017, 3:01 a.m. UTC
From: Chao Gao <chao.gao@intel.com>

Software writes this field to enable/disable interrupt reampping. This patch
emulate IRES field of GCMD.

Signed-off-by: Chao Gao <chao.gao@intel.com>
Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
---
 xen/drivers/passthrough/vtd/iommu.h |  3 ++-
 xen/drivers/passthrough/vtd/vvtd.c  | 30 +++++++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 2 deletions(-)

Comments

Roger Pau Monné Oct. 19, 2017, 1:42 p.m. UTC | #1
On Thu, Sep 21, 2017 at 11:01:55PM -0400, Lan Tianyu wrote:
> From: Chao Gao <chao.gao@intel.com>
> 
> Software writes this field to enable/disable interrupt reampping. This patch
> emulate IRES field of GCMD.
> 
> Signed-off-by: Chao Gao <chao.gao@intel.com>
> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
> ---
>  xen/drivers/passthrough/vtd/iommu.h |  3 ++-
>  xen/drivers/passthrough/vtd/vvtd.c  | 30 +++++++++++++++++++++++++++++-
>  2 files changed, 31 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/drivers/passthrough/vtd/iommu.h b/xen/drivers/passthrough/vtd/iommu.h
> index a0d5ec8..703726f 100644
> --- a/xen/drivers/passthrough/vtd/iommu.h
> +++ b/xen/drivers/passthrough/vtd/iommu.h
> @@ -163,7 +163,8 @@
>  #define DMA_GSTS_AFLS   (((u64)1) << 28)
>  #define DMA_GSTS_WBFS   (((u64)1) << 27)
>  #define DMA_GSTS_QIES   (((u64)1) <<26)
> -#define DMA_GSTS_IRES   (((u64)1) <<25)
> +#define DMA_GSTS_IRES_SHIFT     25
> +#define DMA_GSTS_IRES   (((u64)1) << DMA_GSTS_IRES_SHIFT)
>  #define DMA_GSTS_SIRTPS_SHIFT   24
>  #define DMA_GSTS_SIRTPS (((u64)1) << DMA_GSTS_SIRTPS_SHIFT)
>  #define DMA_GSTS_CFIS   (((u64)1) <<23)
> diff --git a/xen/drivers/passthrough/vtd/vvtd.c b/xen/drivers/passthrough/vtd/vvtd.c
> index 6736956..a0f63e9 100644
> --- a/xen/drivers/passthrough/vtd/vvtd.c
> +++ b/xen/drivers/passthrough/vtd/vvtd.c
> @@ -33,7 +33,8 @@
>  unsigned int vvtd_caps = VIOMMU_CAP_IRQ_REMAPPING;
>  
>  struct hvm_hw_vvtd_status {
> -    uint32_t eim_enabled : 1;
> +    uint32_t eim_enabled : 1,
> +             intremap_enabled : 1;

Again please use bool.

>      uint32_t irt_max_entry;
>      /* Interrupt remapping table base gfn */
>      uint64_t irt;
> @@ -84,6 +85,11 @@ static inline void vvtd_set_bit(struct vvtd *vvtd, uint32_t reg, int nr)
>      __set_bit(nr, &vvtd->regs->data32[reg/sizeof(uint32_t)]);
>  }
>  
> +static inline void vvtd_clear_bit(struct vvtd *vvtd, uint32_t reg, int nr)
> +{
> +    __clear_bit(nr, &vvtd->regs->data32[reg/sizeof(uint32_t)]);
> +}

I'm not sure this functions are helpful, maybe it would be better to
just have a macro to get vvtd->regs->data32[reg/sizeof(uint32_t)]
instead, which seems to be the cumbersome part of the expression above
(and in vvtd_set_bit).

> +
>  static inline void vvtd_set_reg(struct vvtd *vtd, uint32_t reg, uint32_t value)
>  {
>      vtd->regs->data32[reg/sizeof(uint32_t)] = value;
> @@ -105,6 +111,23 @@ static inline uint64_t vvtd_get_reg_quad(struct vvtd *vtd, uint32_t reg)
>      return vtd->regs->data64[reg/sizeof(uint64_t)];
>  }
>  
> +static void vvtd_handle_gcmd_ire(struct vvtd *vvtd, uint32_t val)
> +{
> +    vvtd_info("%sable Interrupt Remapping",
> +              (val & DMA_GCMD_IRE) ? "En" : "Dis");
> +
> +    if ( val & DMA_GCMD_IRE )
> +    {
> +        vvtd->status.intremap_enabled = true;
> +        vvtd_set_bit(vvtd, DMAR_GSTS_REG, DMA_GSTS_IRES_SHIFT);
> +    }
> +    else
> +    {
> +        vvtd->status.intremap_enabled = false;
> +        vvtd_clear_bit(vvtd, DMAR_GSTS_REG, DMA_GSTS_IRES_SHIFT);
> +    }


You cna write the above like:

vvtd->status.intremap_enabled = val & DMA_GCMD_IRE;
(val & DMA_GCMD_IRE) ? vvtd_set_bit : vvtd_clear_bit
    (vvtd, DMAR_GSTS_REG, DMA_GSTS_IRES_SHIFT);

Or similar (certainly setting vvtd->status.intremap_enabled doesn't
need to be branched).

Thanks, Roger.
diff mbox

Patch

diff --git a/xen/drivers/passthrough/vtd/iommu.h b/xen/drivers/passthrough/vtd/iommu.h
index a0d5ec8..703726f 100644
--- a/xen/drivers/passthrough/vtd/iommu.h
+++ b/xen/drivers/passthrough/vtd/iommu.h
@@ -163,7 +163,8 @@ 
 #define DMA_GSTS_AFLS   (((u64)1) << 28)
 #define DMA_GSTS_WBFS   (((u64)1) << 27)
 #define DMA_GSTS_QIES   (((u64)1) <<26)
-#define DMA_GSTS_IRES   (((u64)1) <<25)
+#define DMA_GSTS_IRES_SHIFT     25
+#define DMA_GSTS_IRES   (((u64)1) << DMA_GSTS_IRES_SHIFT)
 #define DMA_GSTS_SIRTPS_SHIFT   24
 #define DMA_GSTS_SIRTPS (((u64)1) << DMA_GSTS_SIRTPS_SHIFT)
 #define DMA_GSTS_CFIS   (((u64)1) <<23)
diff --git a/xen/drivers/passthrough/vtd/vvtd.c b/xen/drivers/passthrough/vtd/vvtd.c
index 6736956..a0f63e9 100644
--- a/xen/drivers/passthrough/vtd/vvtd.c
+++ b/xen/drivers/passthrough/vtd/vvtd.c
@@ -33,7 +33,8 @@ 
 unsigned int vvtd_caps = VIOMMU_CAP_IRQ_REMAPPING;
 
 struct hvm_hw_vvtd_status {
-    uint32_t eim_enabled : 1;
+    uint32_t eim_enabled : 1,
+             intremap_enabled : 1;
     uint32_t irt_max_entry;
     /* Interrupt remapping table base gfn */
     uint64_t irt;
@@ -84,6 +85,11 @@  static inline void vvtd_set_bit(struct vvtd *vvtd, uint32_t reg, int nr)
     __set_bit(nr, &vvtd->regs->data32[reg/sizeof(uint32_t)]);
 }
 
+static inline void vvtd_clear_bit(struct vvtd *vvtd, uint32_t reg, int nr)
+{
+    __clear_bit(nr, &vvtd->regs->data32[reg/sizeof(uint32_t)]);
+}
+
 static inline void vvtd_set_reg(struct vvtd *vtd, uint32_t reg, uint32_t value)
 {
     vtd->regs->data32[reg/sizeof(uint32_t)] = value;
@@ -105,6 +111,23 @@  static inline uint64_t vvtd_get_reg_quad(struct vvtd *vtd, uint32_t reg)
     return vtd->regs->data64[reg/sizeof(uint64_t)];
 }
 
+static void vvtd_handle_gcmd_ire(struct vvtd *vvtd, uint32_t val)
+{
+    vvtd_info("%sable Interrupt Remapping",
+              (val & DMA_GCMD_IRE) ? "En" : "Dis");
+
+    if ( val & DMA_GCMD_IRE )
+    {
+        vvtd->status.intremap_enabled = true;
+        vvtd_set_bit(vvtd, DMAR_GSTS_REG, DMA_GSTS_IRES_SHIFT);
+    }
+    else
+    {
+        vvtd->status.intremap_enabled = false;
+        vvtd_clear_bit(vvtd, DMAR_GSTS_REG, DMA_GSTS_IRES_SHIFT);
+    }
+}
+
 static void vvtd_handle_gcmd_sirtp(struct vvtd *vvtd, uint32_t val)
 {
     uint64_t irta = vvtd_get_reg_quad(vvtd, DMAR_IRTA_REG);
@@ -112,6 +135,9 @@  static void vvtd_handle_gcmd_sirtp(struct vvtd *vvtd, uint32_t val)
     if ( !(val & DMA_GCMD_SIRTP) )
         return;
 
+    if ( vvtd->status.intremap_enabled )
+        vvtd_info("Update Interrupt Remapping Table when active\n");
+
     vvtd->status.irt = DMA_IRTA_ADDR(irta) >> PAGE_SHIFT;
     vvtd->status.irt_max_entry = DMA_IRTA_SIZE(irta);
     vvtd->status.eim_enabled = !!(irta & IRTA_EIME);
@@ -139,6 +165,8 @@  static int vvtd_write_gcmd(struct vvtd *vvtd, uint32_t val)
 
     if ( changed & DMA_GCMD_SIRTP )
         vvtd_handle_gcmd_sirtp(vvtd, val);
+    if ( changed & DMA_GCMD_IRE )
+        vvtd_handle_gcmd_ire(vvtd, val);
 
     return X86EMUL_OKAY;
 }