From: Nikhil Devshatwar <[email protected]>

When ARM IOMMU drivers are supported, it will setup the IO address
translation tables unique for each DMA context in the system.

A typical DMA context is identified by an integer called stream id.
To setup the correct IOMMU mapping, hypervisor should know
list of all the streamIDs that should be setup in the IOMMU.

Add an array of stream IDs in the cell config, bump up the config revision.
Change the python struct unpacking logic in the tools to reflect
revised config structure.

[[email protected]: Make the stream_ids array resizeable]

Signed-off-by: Nikhil Devshatwar <[email protected]>
Signed-off-by: Lokesh Vutla <[email protected]>
Signed-off-by: Pratyush Yadav <[email protected]>
---
v2:
- Make stream_ids array resizeable.
- Add for_each_stream_id loop generating macro.

 hypervisor/arch/arm-common/include/asm/iommu.h |  5 +++++
 include/jailhouse/cell-config.h                | 15 +++++++++++++--
 tools/jailhouse-cell-linux                     |  5 +++--
 tools/jailhouse-hardware-check                 |  2 +-
 4 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/hypervisor/arch/arm-common/include/asm/iommu.h 
b/hypervisor/arch/arm-common/include/asm/iommu.h
index d33ec17c..f86120ec 100644
--- a/hypervisor/arch/arm-common/include/asm/iommu.h
+++ b/hypervisor/arch/arm-common/include/asm/iommu.h
@@ -18,6 +18,11 @@
 #include <jailhouse/config.h>
 #include <jailhouse/cell-config.h>
 
+#define for_each_stream_id(sid, config, counter)                              \
+       for ((sid) = (jailhouse_cell_stream_ids(config)[0]), (counter) = 0;    \
+            (counter) < (config)->num_stream_ids;                             \
+            (sid) = (jailhouse_cell_stream_ids(config)[++(counter)]))
+
 int iommu_map_memory_region(struct cell *cell,
                            const struct jailhouse_memory *mem);
 int iommu_unmap_memory_region(struct cell *cell,
diff --git a/include/jailhouse/cell-config.h b/include/jailhouse/cell-config.h
index c988f7c5..a559720c 100644
--- a/include/jailhouse/cell-config.h
+++ b/include/jailhouse/cell-config.h
@@ -50,7 +50,7 @@
  * Incremented on any layout or semantic change of system or cell config.
  * Also update HEADER_REVISION in tools.
  */
-#define JAILHOUSE_CONFIG_REVISION      10
+#define JAILHOUSE_CONFIG_REVISION      11
 
 #define JAILHOUSE_CELL_NAME_MAXLEN     31
 
@@ -74,6 +74,8 @@
 
 #define JAILHOUSE_CELL_DESC_SIGNATURE  "JHCELL"
 
+#define JAILHOUSE_INVALID_STREAMID                     (~0)
+
 /**
  * The jailhouse cell configuration.
  *
@@ -95,6 +97,7 @@ struct jailhouse_cell_desc {
        __u32 pio_bitmap_size;
        __u32 num_pci_devices;
        __u32 num_pci_caps;
+       __u32 num_stream_ids;
 
        __u32 vpci_irq_base;
 
@@ -276,7 +279,8 @@ jailhouse_cell_config_size(struct jailhouse_cell_desc *cell)
                cell->num_irqchips * sizeof(struct jailhouse_irqchip) +
                cell->pio_bitmap_size +
                cell->num_pci_devices * sizeof(struct jailhouse_pci_device) +
-               cell->num_pci_caps * sizeof(struct jailhouse_pci_capability);
+               cell->num_pci_caps * sizeof(struct jailhouse_pci_capability) +
+               cell->num_stream_ids * sizeof(__u32);
 }
 
 static inline __u32
@@ -339,4 +343,11 @@ jailhouse_cell_pci_caps(const struct jailhouse_cell_desc 
*cell)
                 cell->num_pci_devices * sizeof(struct jailhouse_pci_device));
 }
 
+static inline __u32 *
+jailhouse_cell_stream_ids(const struct jailhouse_cell_desc *cell)
+{
+       return (__u32 *)((void *)jailhouse_cell_pci_caps(cell) +
+               cell->num_pci_caps * sizeof(struct jailhouse_pci_capability));
+}
+
 #endif /* !_JAILHOUSE_CELL_CONFIG_H */
diff --git a/tools/jailhouse-cell-linux b/tools/jailhouse-cell-linux
index 49babd92..e4e59663 100755
--- a/tools/jailhouse-cell-linux
+++ b/tools/jailhouse-cell-linux
@@ -564,8 +564,8 @@ class Irqchip:
 
 
 class Config:
-    _HEADER_FORMAT = '6sH32s4xIIIIIIIIIQ8x32x'
-    _HEADER_REVISION = 10
+    _HEADER_FORMAT = '6sH32s4xIIIIIIIIIIQ8x32x'
+    _HEADER_REVISION = 11
 
     def __init__(self, config_file):
         self.data = config_file.read()
@@ -581,6 +581,7 @@ class Config:
          self.pio_bitmap_size,
          self.num_pci_devices,
          self.num_pci_caps,
+         self.num_stream_ids,
          self.vpci_irq_base,
          self.cpu_reset_address) = \
             struct.unpack_from(Config._HEADER_FORMAT, self.data)
diff --git a/tools/jailhouse-hardware-check b/tools/jailhouse-hardware-check
index b86756ac..afd1139b 100755
--- a/tools/jailhouse-hardware-check
+++ b/tools/jailhouse-hardware-check
@@ -136,7 +136,7 @@ class Sysconfig:
     X86_MAX_IOMMU_UNITS = 8
     X86_IOMMU_SIZE = 20
 
-    HEADER_REVISION = 10
+    HEADER_REVISION = 11
     HEADER_FORMAT = '6sH'
 
     def __init__(self, path):
-- 
2.17.1

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/20190705144225.7126-4-p-yadav1%40ti.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to