xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Feng Wu <feng.wu@intel.com>
To: xen-devel@lists.xen.org
Cc: Yang Zhang <yang.z.zhang@intel.com>,
	Kevin Tian <kevin.tian@intel.com>, Feng Wu <feng.wu@intel.com>
Subject: [PATCH v6 10/18] vt-d: Extend struct iremap_entry to support VT-d Posted-Interrupts
Date: Tue, 25 Aug 2015 09:57:49 +0800	[thread overview]
Message-ID: <1440467877-5116-11-git-send-email-feng.wu@intel.com> (raw)
In-Reply-To: <1440467877-5116-1-git-send-email-feng.wu@intel.com>

Extend struct iremap_entry according to VT-d Posted-Interrupts Spec.

CC: Yang Zhang <yang.z.zhang@intel.com>
CC: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Feng Wu <feng.wu@intel.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
---
v4:
- res_4 is not a bitfiled, correct it.
- Expose 'im' to remapped irte as well.

v3:
- Use u32 instead of u64 to define the bitfields in 'struct iremap_entry'
- Limit using bitfield if possible

 xen/drivers/passthrough/vtd/intremap.c | 92 +++++++++++++++++-----------------
 xen/drivers/passthrough/vtd/iommu.h    | 43 ++++++++++------
 xen/drivers/passthrough/vtd/utils.c    |  8 +--
 3 files changed, 80 insertions(+), 63 deletions(-)

diff --git a/xen/drivers/passthrough/vtd/intremap.c b/xen/drivers/passthrough/vtd/intremap.c
index 987bbe9..e9fffa6 100644
--- a/xen/drivers/passthrough/vtd/intremap.c
+++ b/xen/drivers/passthrough/vtd/intremap.c
@@ -122,9 +122,9 @@ static u16 hpetid_to_bdf(unsigned int hpet_id)
 static void set_ire_sid(struct iremap_entry *ire,
                         unsigned int svt, unsigned int sq, unsigned int sid)
 {
-    ire->hi.svt = svt;
-    ire->hi.sq = sq;
-    ire->hi.sid = sid;
+    ire->remap.svt = svt;
+    ire->remap.sq = sq;
+    ire->remap.sid = sid;
 }
 
 static void set_ioapic_source_id(int apic_id, struct iremap_entry *ire)
@@ -219,7 +219,7 @@ static unsigned int alloc_remap_entry(struct iommu *iommu, unsigned int nr)
         else
             p = &iremap_entries[i % (1 << IREMAP_ENTRY_ORDER)];
 
-        if ( p->lo_val || p->hi_val ) /* not a free entry */
+        if ( p->lo || p->hi ) /* not a free entry */
             found = 0;
         else if ( ++found == nr )
             break;
@@ -253,7 +253,7 @@ static int remap_entry_to_ioapic_rte(
     GET_IREMAP_ENTRY(ir_ctrl->iremap_maddr, index,
                      iremap_entries, iremap_entry);
 
-    if ( iremap_entry->hi_val == 0 && iremap_entry->lo_val == 0 )
+    if ( iremap_entry->hi == 0 && iremap_entry->lo == 0 )
     {
         dprintk(XENLOG_ERR VTDPREFIX,
                 "%s: index (%d) get an empty entry!\n",
@@ -263,13 +263,13 @@ static int remap_entry_to_ioapic_rte(
         return -EFAULT;
     }
 
-    old_rte->vector = iremap_entry->lo.vector;
-    old_rte->delivery_mode = iremap_entry->lo.dlm;
-    old_rte->dest_mode = iremap_entry->lo.dm;
-    old_rte->trigger = iremap_entry->lo.tm;
+    old_rte->vector = iremap_entry->remap.vector;
+    old_rte->delivery_mode = iremap_entry->remap.dlm;
+    old_rte->dest_mode = iremap_entry->remap.dm;
+    old_rte->trigger = iremap_entry->remap.tm;
     old_rte->__reserved_2 = 0;
     old_rte->dest.logical.__reserved_1 = 0;
-    old_rte->dest.logical.logical_dest = iremap_entry->lo.dst >> 8;
+    old_rte->dest.logical.logical_dest = iremap_entry->remap.dst >> 8;
 
     unmap_vtd_domain_page(iremap_entries);
     spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags);
@@ -317,27 +317,28 @@ static int ioapic_rte_to_remap_entry(struct iommu *iommu,
     if ( rte_upper )
     {
         if ( x2apic_enabled )
-            new_ire.lo.dst = value;
+            new_ire.remap.dst = value;
         else
-            new_ire.lo.dst = (value >> 24) << 8;
+            new_ire.remap.dst = (value >> 24) << 8;
     }
     else
     {
         *(((u32 *)&new_rte) + 0) = value;
-        new_ire.lo.fpd = 0;
-        new_ire.lo.dm = new_rte.dest_mode;
-        new_ire.lo.tm = new_rte.trigger;
-        new_ire.lo.dlm = new_rte.delivery_mode;
+        new_ire.remap.fpd = 0;
+        new_ire.remap.dm = new_rte.dest_mode;
+        new_ire.remap.tm = new_rte.trigger;
+        new_ire.remap.dlm = new_rte.delivery_mode;
         /* Hardware require RH = 1 for LPR delivery mode */
-        new_ire.lo.rh = (new_ire.lo.dlm == dest_LowestPrio);
-        new_ire.lo.avail = 0;
-        new_ire.lo.res_1 = 0;
-        new_ire.lo.vector = new_rte.vector;
-        new_ire.lo.res_2 = 0;
+        new_ire.remap.rh = (new_ire.remap.dlm == dest_LowestPrio);
+        new_ire.remap.avail = 0;
+        new_ire.remap.res_1 = 0;
+        new_ire.remap.vector = new_rte.vector;
+        new_ire.remap.res_2 = 0;
 
         set_ioapic_source_id(IO_APIC_ID(apic), &new_ire);
-        new_ire.hi.res_1 = 0;
-        new_ire.lo.p = 1;     /* finally, set present bit */
+        new_ire.remap.res_3 = 0;
+        new_ire.remap.res_4 = 0;
+        new_ire.remap.p = 1;     /* finally, set present bit */
 
         /* now construct new ioapic rte entry */
         remap_rte->vector = new_rte.vector;
@@ -510,7 +511,7 @@ static int remap_entry_to_msi_msg(
     GET_IREMAP_ENTRY(ir_ctrl->iremap_maddr, index,
                      iremap_entries, iremap_entry);
 
-    if ( iremap_entry->hi_val == 0 && iremap_entry->lo_val == 0 )
+    if ( iremap_entry->hi == 0 && iremap_entry->lo == 0 )
     {
         dprintk(XENLOG_ERR VTDPREFIX,
                 "%s: index (%d) get an empty entry!\n",
@@ -523,25 +524,25 @@ static int remap_entry_to_msi_msg(
     msg->address_hi = MSI_ADDR_BASE_HI;
     msg->address_lo =
         MSI_ADDR_BASE_LO |
-        ((iremap_entry->lo.dm == 0) ?
+        ((iremap_entry->remap.dm == 0) ?
             MSI_ADDR_DESTMODE_PHYS:
             MSI_ADDR_DESTMODE_LOGIC) |
-        ((iremap_entry->lo.dlm != dest_LowestPrio) ?
+        ((iremap_entry->remap.dlm != dest_LowestPrio) ?
             MSI_ADDR_REDIRECTION_CPU:
             MSI_ADDR_REDIRECTION_LOWPRI);
     if ( x2apic_enabled )
-        msg->dest32 = iremap_entry->lo.dst;
+        msg->dest32 = iremap_entry->remap.dst;
     else
-        msg->dest32 = (iremap_entry->lo.dst >> 8) & 0xff;
+        msg->dest32 = (iremap_entry->remap.dst >> 8) & 0xff;
     msg->address_lo |= MSI_ADDR_DEST_ID(msg->dest32);
 
     msg->data =
         MSI_DATA_TRIGGER_EDGE |
         MSI_DATA_LEVEL_ASSERT |
-        ((iremap_entry->lo.dlm != dest_LowestPrio) ?
+        ((iremap_entry->remap.dlm != dest_LowestPrio) ?
             MSI_DATA_DELIVERY_FIXED:
             MSI_DATA_DELIVERY_LOWPRI) |
-        iremap_entry->lo.vector;
+        iremap_entry->remap.vector;
 
     unmap_vtd_domain_page(iremap_entries);
     spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags);
@@ -600,29 +601,30 @@ static int msi_msg_to_remap_entry(
     memcpy(&new_ire, iremap_entry, sizeof(struct iremap_entry));
 
     /* Set interrupt remapping table entry */
-    new_ire.lo.fpd = 0;
-    new_ire.lo.dm = (msg->address_lo >> MSI_ADDR_DESTMODE_SHIFT) & 0x1;
-    new_ire.lo.tm = (msg->data >> MSI_DATA_TRIGGER_SHIFT) & 0x1;
-    new_ire.lo.dlm = (msg->data >> MSI_DATA_DELIVERY_MODE_SHIFT) & 0x1;
+    new_ire.remap.fpd = 0;
+    new_ire.remap.dm = (msg->address_lo >> MSI_ADDR_DESTMODE_SHIFT) & 0x1;
+    new_ire.remap.tm = (msg->data >> MSI_DATA_TRIGGER_SHIFT) & 0x1;
+    new_ire.remap.dlm = (msg->data >> MSI_DATA_DELIVERY_MODE_SHIFT) & 0x1;
     /* Hardware require RH = 1 for LPR delivery mode */
-    new_ire.lo.rh = (new_ire.lo.dlm == dest_LowestPrio);
-    new_ire.lo.avail = 0;
-    new_ire.lo.res_1 = 0;
-    new_ire.lo.vector = (msg->data >> MSI_DATA_VECTOR_SHIFT) &
-                        MSI_DATA_VECTOR_MASK;
-    new_ire.lo.res_2 = 0;
+    new_ire.remap.rh = (new_ire.remap.dlm == dest_LowestPrio);
+    new_ire.remap.avail = 0;
+    new_ire.remap.res_1 = 0;
+    new_ire.remap.vector = (msg->data >> MSI_DATA_VECTOR_SHIFT) &
+                            MSI_DATA_VECTOR_MASK;
+    new_ire.remap.res_2 = 0;
     if ( x2apic_enabled )
-        new_ire.lo.dst = msg->dest32;
+        new_ire.remap.dst = msg->dest32;
     else
-        new_ire.lo.dst = ((msg->address_lo >> MSI_ADDR_DEST_ID_SHIFT)
-                          & 0xff) << 8;
+        new_ire.remap.dst = ((msg->address_lo >> MSI_ADDR_DEST_ID_SHIFT)
+                             & 0xff) << 8;
 
     if ( pdev )
         set_msi_source_id(pdev, &new_ire);
     else
         set_hpet_source_id(msi_desc->hpet_id, &new_ire);
-    new_ire.hi.res_1 = 0;
-    new_ire.lo.p = 1;    /* finally, set present bit */
+    new_ire.remap.res_3 = 0;
+    new_ire.remap.res_4 = 0;
+    new_ire.remap.p = 1;    /* finally, set present bit */
 
     /* now construct new MSI/MSI-X rte entry */
     remap_rte = (struct msi_msg_remap_entry *)msg;
diff --git a/xen/drivers/passthrough/vtd/iommu.h b/xen/drivers/passthrough/vtd/iommu.h
index 22abefe..6fca430 100644
--- a/xen/drivers/passthrough/vtd/iommu.h
+++ b/xen/drivers/passthrough/vtd/iommu.h
@@ -281,29 +281,44 @@ struct dma_pte {
 /* interrupt remap entry */
 struct iremap_entry {
   union {
-    u64 lo_val;
+    struct { u64 lo, hi; };
     struct {
-        u64 p       : 1,
+        u16 p       : 1,
             fpd     : 1,
             dm      : 1,
             rh      : 1,
             tm      : 1,
             dlm     : 3,
             avail   : 4,
-            res_1   : 4,
-            vector  : 8,
-            res_2   : 8,
-            dst     : 32;
-    }lo;
-  };
-  union {
-    u64 hi_val;
+            res_1   : 3,
+            im      : 1;
+        u8  vector;
+        u8  res_2;
+        u32 dst;
+        u16 sid;
+        u16 sq      : 2,
+            svt     : 2,
+            res_3   : 12;
+        u32 res_4;
+    } remap;
     struct {
-        u64 sid     : 16,
-            sq      : 2,
+        u16 p       : 1,
+            fpd     : 1,
+            res_1   : 6,
+            avail   : 4,
+            res_2   : 2,
+            urg     : 1,
+            im      : 1;
+        u8  vector;
+        u8  res_3;
+        u32 res_4   : 6,
+            pda_l   : 26;
+        u16 sid;
+        u16 sq      : 2,
             svt     : 2,
-            res_1   : 44;
-    }hi;
+            res_5   : 12;
+        u32 pda_h;
+    } post;
   };
 };
 
diff --git a/xen/drivers/passthrough/vtd/utils.c b/xen/drivers/passthrough/vtd/utils.c
index 162b764..9d556da 100644
--- a/xen/drivers/passthrough/vtd/utils.c
+++ b/xen/drivers/passthrough/vtd/utils.c
@@ -230,13 +230,13 @@ static void dump_iommu_info(unsigned char key)
                 else
                     p = &iremap_entries[i % (1 << IREMAP_ENTRY_ORDER)];
 
-                if ( !p->lo.p )
+                if ( !p->remap.p )
                     continue;
                 printk("  %04x:  %x   %x  %04x %08x %02x    %x   %x  %x  %x  %x"
                     "   %x %x\n", i,
-                    p->hi.svt, p->hi.sq, p->hi.sid, p->lo.dst, p->lo.vector,
-                    p->lo.avail, p->lo.dlm, p->lo.tm, p->lo.rh, p->lo.dm,
-                    p->lo.fpd, p->lo.p);
+                    p->remap.svt, p->remap.sq, p->remap.sid, p->remap.dst,
+                    p->remap.vector, p->remap.avail, p->remap.dlm, p->remap.tm,
+                    p->remap.rh, p->remap.dm, p->remap.fpd, p->remap.p);
                 print_cnt++;
             }
             if ( iremap_entries )
-- 
2.1.0

  parent reply	other threads:[~2015-08-25  1:57 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-25  1:57 [PATCH v6 00/18] Add VT-d Posted-Interrupts support Feng Wu
2015-08-25  1:57 ` [PATCH v6 01/18] VT-d Posted-intterrupt (PI) design Feng Wu
2015-08-25  1:57 ` [PATCH v6 02/18] Add cmpxchg16b support for x86-64 Feng Wu
2015-09-04 14:22   ` Jan Beulich
2015-09-06  6:07     ` Wu, Feng
2015-09-06  6:32       ` Wu, Feng
2015-09-07 10:36         ` Jan Beulich
2015-09-08  7:37           ` Wu, Feng
2015-09-08  8:52             ` Jan Beulich
2015-09-08  8:57               ` Wu, Feng
2015-09-08  9:19                 ` Jan Beulich
2015-09-08  9:30                   ` Wu, Feng
2015-09-07 10:34       ` Jan Beulich
2015-09-07 10:39       ` Jan Beulich
2015-09-04 15:12   ` Jan Beulich
2015-08-25  1:57 ` [PATCH v6 03/18] iommu: Add iommu_intpost to control VT-d Posted-Interrupts feature Feng Wu
2015-09-04 14:26   ` Jan Beulich
2015-08-25  1:57 ` [PATCH v6 04/18] vt-d: VT-d Posted-Interrupts feature detection Feng Wu
2015-09-04 14:31   ` Jan Beulich
2015-09-06  1:49     ` Wu, Feng
2015-09-07 10:43       ` Jan Beulich
2015-09-08  2:35         ` Wu, Feng
2015-09-08  5:18           ` Jan Beulich
2015-08-25  1:57 ` [PATCH v6 05/18] vmx: Extend struct pi_desc to support VT-d Posted-Interrupts Feng Wu
2015-09-04 14:32   ` Jan Beulich
2015-08-25  1:57 ` [PATCH v6 06/18] vmx: Add some helper functions for Posted-Interrupts Feng Wu
2015-09-04 14:40   ` Jan Beulich
2015-09-06  2:05     ` Wu, Feng
2015-09-07 10:46       ` Jan Beulich
2015-09-08  2:39         ` Wu, Feng
2015-09-08  5:22           ` Jan Beulich
2015-08-25  1:57 ` [PATCH v6 07/18] vmx: Initialize VT-d Posted-Interrupts Descriptor Feng Wu
2015-09-04 14:47   ` Jan Beulich
2015-09-06  2:22     ` Wu, Feng
2015-09-07 10:49       ` Jan Beulich
2015-08-25  1:57 ` [PATCH v6 08/18] vmx: Suppress posting interrupts when 'SN' is set Feng Wu
2015-09-04 14:53   ` Jan Beulich
2015-09-06  2:33     ` Wu, Feng
2015-09-07 10:51       ` Jan Beulich
2015-08-25  1:57 ` [PATCH v6 09/18] VT-d: Remove pointless casts Feng Wu
2015-09-04 14:55   ` Jan Beulich
2015-08-25  1:57 ` Feng Wu [this message]
2015-08-25  1:57 ` [PATCH v6 11/18] vt-d: Add API to update IRTE when VT-d PI is used Feng Wu
2015-09-04 15:11   ` Jan Beulich
2015-09-06  5:24     ` Wu, Feng
2015-09-07 10:54       ` Jan Beulich
2015-08-25  1:57 ` [PATCH v6 12/18] x86: move some APIC related macros to apicdef.h Feng Wu
2015-09-04 15:15   ` Jan Beulich
2015-08-25  1:57 ` [PATCH v6 13/18] Update IRTE according to guest interrupt config changes Feng Wu
2015-09-04 15:59   ` Jan Beulich
2015-09-06  4:54     ` Wu, Feng
2015-09-07 11:03       ` Jan Beulich
2015-09-08  4:47         ` Wu, Feng
2015-09-08  9:02           ` Jan Beulich
2015-08-25  1:57 ` [PATCH v6 14/18] vmx: posted-interrupt handling when vCPU is blocked Feng Wu
2015-09-07 11:47   ` Jan Beulich
2015-09-08  8:50     ` Wu, Feng
2015-09-08  9:08       ` Jan Beulich
2015-09-08  9:14         ` Wu, Feng
2015-08-25  1:57 ` [PATCH v6 15/18] vmx: Properly handle notification event when vCPU is running Feng Wu
2015-09-07 12:10   ` Jan Beulich
2015-09-07 13:00     ` Zhang, Yang Z
2015-09-07 13:12       ` Jan Beulich
2015-09-08  1:38         ` Zhang, Yang Z
2015-09-08  8:57           ` Jan Beulich
2015-09-08  5:18     ` Wu, Feng
2015-09-08  9:13       ` Jan Beulich
2015-09-08  9:23         ` Wu, Feng
2015-09-08  9:31           ` Jan Beulich
2015-09-08  9:36             ` Wu, Feng
2015-09-08 10:13               ` Jan Beulich
2015-09-08 10:15                 ` Wu, Feng
2015-08-25  1:57 ` [PATCH v6 16/18] vmx: Add some scheduler hooks for VT-d posted interrupts Feng Wu
2015-09-07 12:54   ` Jan Beulich
2015-09-09  8:56     ` Wu, Feng
2015-09-09 10:26       ` Jan Beulich
2015-09-10  2:07         ` Wu, Feng
2015-09-10  8:27           ` Jan Beulich
2015-09-10  8:59             ` Wu, Feng
2015-09-10  9:26               ` Jan Beulich
2015-09-10  9:41                 ` Wu, Feng
2015-09-10 10:01                   ` Jan Beulich
2015-09-10 12:34                     ` Wu, Feng
2015-09-10 12:44                       ` Jan Beulich
2015-09-10 12:58                         ` Wu, Feng
2015-09-10 13:15                           ` Jan Beulich
2015-09-10 13:27                             ` Wu, Feng
2015-09-10 14:01                               ` Jan Beulich
2015-09-16  8:56                 ` Wu, Feng
2015-09-16 17:08               ` George Dunlap
2015-09-17  6:26                 ` Wu, Feng
2015-09-16 16:56     ` George Dunlap
2015-09-17  6:15       ` Wu, Feng
2015-09-21  8:23       ` Jan Beulich
2015-09-21  9:28         ` George Dunlap
2015-09-21 11:56           ` Jan Beulich
2015-08-25  1:57 ` [PATCH v6 17/18] VT-d: Dump the posted format IRTE Feng Wu
2015-09-07 13:04   ` Jan Beulich
2015-09-08  5:38     ` Wu, Feng
2015-09-08  9:16       ` Jan Beulich
2015-08-25  1:57 ` [PATCH v6 18/18] Add a command line parameter for VT-d posted-interrupts Feng Wu
2015-09-07 13:05   ` Jan Beulich
2015-09-01  5:13 ` [PATCH v6 00/18] Add VT-d Posted-Interrupts support Wu, Feng
2015-09-01  5:20   ` Jan Beulich
2015-09-01  5:32     ` Wu, Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1440467877-5116-11-git-send-email-feng.wu@intel.com \
    --to=feng.wu@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=xen-devel@lists.xen.org \
    --cc=yang.z.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).