Skip to contentSkip to conversation

xen/arm: Add SMMU drivers

PATCH In review Julien Grall 1 participant 4 messages May 28, 2014

lore
Share & tools
lore
#0 lore raw

v9 cover xen/arm: Add SMMU drivers

This series was formerly called "IOMMU support for ARM". It adds support for the ARM SMMU driver which is used for instance by Midway.

Major changes in v8:
- Update comments and commit message in patch #2

For all changes see in each patch.

A working tree can be found here:
git://xenbits.xen.org/people/julieng/xen-unstable.git branch smmu-v9

Sincerely yours,

Julien Grall (2):
drivers/passthrough: arm: Add support for SMMU drivers xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m

 xen/arch/arm/p2m.c                   |    2 +
 xen/common/grant_table.c             |    4 +-
 xen/drivers/passthrough/arm/Makefile |    1 +
 xen/drivers/passthrough/arm/smmu.c   | 1784 ++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/grant_table.h    |    3 +
 xen/include/asm-arm/p2m.h            |    3 +
 xen/include/asm-x86/grant_table.h    |    3 +
 7 files changed, 1798 insertions(+), 2 deletions(-)
 create mode 100644 xen/drivers/passthrough/arm/smmu.c
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v9 1/2 drivers/passthrough: arm: Add support for SMMU drivers

This patch add support for ARM architected SMMU driver. It's based on the linux drivers (drivers/iommu/arm-smmu) commit 89ac23cd.

The major differences with the Linux driver are:
- Fault by default if the SMMU is enabled to translate an address (Linux is bypassing the SMMU)
- Using P2M page table instead of creating new one
- Dropped stage-1 support
- Dropped chained SMMUs support for now
- Reworking device assignment and the different structures

Xen is programming each IOMMU by:
- Using stage-2 mode translation
- Sharing the page table with the processor
- Injecting a fault if the device has made a wrong translation

---
Changes in v6:
- Move the definition page PAGE_*_64K in another patch. This patch only contains ARM specific code now.
- Use the new way to set feature
Changes in v5:
- Fix arm_smmu_domain_remove_master by using num_s2crs instead of num_streamids
- IOMMU_FEATURE_COHERENT_WALK is became a bit position
Changes in v4:
- Use the new IRQ API e.g function without _dt_ in the name
- Use IRQF_SHARED to notify that the IRQ can be shared (i.e handle multiple actions)
- Update comment in smmu_init
- Update comment for upgrade barrier in smmu_device_reset
- Update CB_TCR to reflect change in VTCR by commit 8200dae
- Drop gr0_base which is not unused in arm_smmu_init_context_bank
- Rebase on the latest Xen (hwdom series was pushed)
- On 32 bit IPA is encoded on 40-bits. Read CB_FAR_HI on all arch
- Add verbosity in CB fault handler
- Handle 40 bits address space on ARM{32,64}.
- Implement new callback features
- platform_get_irq now returns -1 if an error occured
Changes in v3:
- Missing some static
Changes in v2:
- Update commit message
- Update some comments in the code
- Add new callbacks to assign/reassign DT device
- Rework init_dom0 and domain_teardown. The assignment/deassignement is now made in the generic code
- Set protected field in dt_device_node when the device is under an IOMMU
- Use SZ_64K and SZ_4K by the global PAGE_SIZE_{64,4}K in xen/iommu.h. The first one was not defined.

---
 xen/drivers/passthrough/arm/Makefile |    1 +
 xen/drivers/passthrough/arm/smmu.c   | 1742 ++++++++++++++++++++++++++++++++++
 2 files changed, 1743 insertions(+)
 create mode 100644 xen/drivers/passthrough/arm/smmu.c
xen/drivers/passthrough/arm/Makefile +1 -0
index 0484b79..f4cd26e 100644
@@ -1 +1,2 @@
 obj-y += iommu.o
+obj-y += smmu.o
xen/drivers/passthrough/arm/smmu.c new file +1742 -0

1,742 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

PATCH v9 2/2 xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m

In reply to Julien Grall

Grant mappings can be used for DMA requests. Currently the dev_bus_addr returned by the hypercall is the MFN (not the IPA). Guest expects to be able the returned address for DMA. When the device is protected by IOMMU the request will fail. Therefore, we have to add 1:1 mapping in the domain p2m to allow DMA request to work.

This is valid because DOM0 has its memory mapped 1:1 and therefore we know that RAM and devices cannot clash.

If the guest only owns protected device, the return dev_bus_addr should be an IPA. This will allow us to remove safely the 1:1 mapping and make grant mapping works correctly in the guest. For now, this is not addressed by this patch.

The grant mapping code does the reference counting on every MFN and will call iommu_{map,unmap}_page when necessary. This was already handle for x86 PV guests, so we can reuse the same code path for ARM guest.

---
The patch has been heavily rework to use iommu_{,un}map_page. I dropped all the acks.

Changes in v9:
- Move need_iommu in each gnttab_need_iommu
- Add missing parentheses in the macros
- Update comment and commit message
- Add BUG_ON as we should never reach this path

Changes in v8:
- Rework differently the 1:1 mapping by using iommu_{,un}map_page helpers.

Changes in v5:
- Update commit message

Changes in v4:
- Patch added

---
 xen/arch/arm/p2m.c                 |    2 ++
 xen/common/grant_table.c           |    4 ++--
 xen/drivers/passthrough/arm/smmu.c |   42 ++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/grant_table.h  |    3 +++
 xen/include/asm-arm/p2m.h          |    3 +++
 xen/include/asm-x86/grant_table.h  |    3 +++
 6 files changed, 55 insertions(+), 2 deletions(-)
xen/arch/arm/p2m.c +2 -0
index 96bc0ef..810459a 100644
@@ -227,6 +227,7 @@ static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr,
         e.p2m.write = 0;
         break;
 
+    case p2m_iommu_map_rw:
     case p2m_map_foreign:
     case p2m_grant_map_rw:
     case p2m_mmio_direct:
@@ -234,6 +235,7 @@ static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr,
         e.p2m.write = 1;
         break;
 
+    case p2m_iommu_map_ro:
     case p2m_grant_map_ro:
     case p2m_invalid:
         e.p2m.xn = 1;
xen/common/grant_table.c +2 -2
index 2c93d9c..c08e957 100644
@@ -727,7 +727,7 @@ __gnttab_map_grant_ref(
 
     double_gt_lock(lgt, rgt);
 
-    if ( !paging_mode_translate(ld) && need_iommu(ld) )
+    if ( gnttab_need_iommu_mapping(ld) )
     {
         unsigned int wrc, rdc;
         int err = 0;
@@ -935,7 +935,7 @@ __gnttab_unmap_common(
             act->pin -= GNTPIN_hstw_inc;
     }
 
-    if ( !paging_mode_translate(ld) && need_iommu(ld) )
+    if ( gnttab_need_iommu_mapping(ld) )
     {
         unsigned int wrc, rdc;
         int err = 0;
xen/drivers/passthrough/arm/smmu.c +42 -0

54 lines not on this page · raw message

xen/include/asm-arm/grant_table.h +3 -0
index 6e0cc59..cd344ae 100644
@@ -33,6 +33,9 @@ static inline int replace_grant_supported(void)
     ( ((i >= nr_grant_frames(d->grant_table)) &&                         \
      (i < max_nr_grant_frames)) ? 0 : (d->arch.grant_table_gpfn[i]))
 
+#define gnttab_need_iommu_mapping(d)                    \
+    (is_domain_direct_mapped(d) && need_iommu(ld))
+
 #endif /* __ASM_GRANT_TABLE_H__ */
 /*
  * Local variables:
xen/include/asm-arm/p2m.h +3 -0
index bd71abe..911d32d 100644
@@ -45,6 +45,9 @@ typedef enum {
     p2m_map_foreign,    /* Ram pages from foreign domain */
     p2m_grant_map_rw,   /* Read/write grant mapping */
     p2m_grant_map_ro,   /* Read-only grant mapping */
+    /* The types below are only used to decide the page attribute in the P2M */
+    p2m_iommu_map_rw,   /* Read/write iommu mapping */
+    p2m_iommu_map_ro,   /* Read-only iommu mapping */
     p2m_max_real_type,  /* Types after this won't be store in the p2m */
 } p2m_type_t;
 
xen/include/asm-x86/grant_table.h +3 -0
index 3013869..93b81f7 100644
@@ -65,6 +65,9 @@ static inline void gnttab_clear_flag(unsigned int nr, uint16_t *st)
 /* Done implicitly when page tables are destroyed. */
 #define gnttab_release_host_mappings(domain) ( paging_mode_external(domain) )
 
+#define gnttab_need_iommu_mapping(d)                \
+    (!paging_mode_translate(d) && need_iommu(ld))
+
 static inline int replace_grant_supported(void)
 {
     return 1;
Signature · 1 line
1.7.10.4
#3 lore raw
In reply to Julien Grall
Quoted 17 lines · Julien Grall

This series was formerly called "IOMMU support for ARM". It adds support for the ARM SMMU driver which is used for instance by Midway.

Major changes in v8:
- Update comments and commit message in patch #2

For all changes see in each patch.

A working tree can be found here:
git://xenbits.xen.org/people/julieng/xen-unstable.git branch smmu-v9

Sincerely yours,

Julien Grall (2):
drivers/passthrough: arm: Add support for SMMU drivers xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m

Quoted 9 lines
 xen/arch/arm/p2m.c                   |    2 +
 xen/common/grant_table.c             |    4 +-
 xen/drivers/passthrough/arm/Makefile |    1 +
 xen/drivers/passthrough/arm/smmu.c   | 1784 ++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/grant_table.h    |    3 +
 xen/include/asm-arm/p2m.h            |    3 +
 xen/include/asm-x86/grant_table.h    |    3 +
 7 files changed, 1798 insertions(+), 2 deletions(-)
 create mode 100644 xen/drivers/passthrough/arm/smmu.c

Oops, sorry I hit enter on the wrong patch series.

Regards,

Signature · 1 line
Julien Grall