Re: [PATCH v2 04/10] xen/arm: smmuv3: Move definitions to a header

2022-09-05 Thread Rahul Singh
Hi Stefano,

> On 3 Sep 2022, at 12:29 am, Stefano Stabellini  wrote:
> 
> On Fri, 2 Sep 2022, Rahul Singh wrote:
>> From: Jean-Philippe Brucker 
>> 
>> Backport Linux commit e881e7839fba. This is the clean backport without
>> any changes.
> 
> I don't think we can say that this is a clean backport because there are
> differences between the two patches.
> 
> That said, it is just code movement, it is similar to the original
> patch, and it still compiles. So I think we should change the commit
> message not to say that it is a clean backport, but other than that is
> fine.
> 

Ok. I will remove the clean backport msg from commit msg in next version.

Regards,
Rahul


Re: [PATCH v2 04/10] xen/arm: smmuv3: Move definitions to a header

2022-09-02 Thread Stefano Stabellini
On Fri, 2 Sep 2022, Rahul Singh wrote:
> From: Jean-Philippe Brucker 
> 
> Backport Linux commit e881e7839fba. This is the clean backport without
> any changes.

I don't think we can say that this is a clean backport because there are
differences between the two patches.

That said, it is just code movement, it is similar to the original
patch, and it still compiles. So I think we should change the commit
message not to say that it is a clean backport, but other than that is
fine.


> Allow sharing structure definitions with the upcoming SVA support for
> Arm SMMUv3, by moving them to a separate header. We could surgically
> extract only what is needed but keeping all definitions in one place
> looks nicer.
> 
> Signed-off-by: Jean-Philippe Brucker 
> Reviewed-by: Eric Auger 
> Reviewed-by: Jonathan Cameron 
> Link: 
> https://lore.kernel.org/r/20200918101852.582559-8-jean-phili...@linaro.org
> Signed-off-by: Will Deacon 
> Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
> e881e7839fba
> Signed-off-by: Rahul Singh 
> ---
> Changes in v2:
>  - fix commit msg
>  - also move struct definition to header file to sync with Linux patch
> ---
>  xen/drivers/passthrough/arm/smmu-v3.c | 666 +
>  xen/drivers/passthrough/arm/smmu-v3.h | 674 ++
>  2 files changed, 675 insertions(+), 665 deletions(-)
>  create mode 100644 xen/drivers/passthrough/arm/smmu-v3.h
> 
> diff --git a/xen/drivers/passthrough/arm/smmu-v3.c 
> b/xen/drivers/passthrough/arm/smmu-v3.c
> index cee13d1fc7..85ad066266 100644
> --- a/xen/drivers/passthrough/arm/smmu-v3.c
> +++ b/xen/drivers/passthrough/arm/smmu-v3.c
> @@ -90,6 +90,7 @@
>  #include 
>  #include 
>  
> +#include "smmu-v3.h"
>  
>  #define ARM_SMMU_VTCR_SH_IS  3
>  #define ARM_SMMU_VTCR_RGN_WBWA   1
> @@ -102,21 +103,10 @@
>  #define ARM_SMMU_VTCR_PS_48_BIT  0x5ULL
>  #define ARM_SMMU_VTCR_PS_52_BIT  0x6ULL
>  
> -/* Linux compatibility functions. */
> -typedef paddr_t  dma_addr_t;
> -typedef paddr_t  phys_addr_t;
> -typedef unsigned int gfp_t;
> -
>  #define platform_device  device
>  
>  #define GFP_KERNEL   0
>  
> -/* Alias to Xen lock functions */
> -#define mutex spinlock
> -#define mutex_init spin_lock_init
> -#define mutex_lock spin_lock
> -#define mutex_unlock spin_unlock
> -
>  /* Device logger functions */
>  #define dev_name(dev)dt_node_full_name(dev->of_node)
>  #define dev_dbg(dev, fmt, ...)   \
> @@ -157,12 +147,6 @@ typedef unsigned int gfp_t;
>  #define readl_relaxed_poll_timeout(addr, val, cond, delay_us, timeout_us)
> \
>   readx_poll_timeout(readl_relaxed, addr, val, cond, delay_us, timeout_us)
>  
> -#define FIELD_PREP(_mask, _val)  \
> - (((typeof(_mask))(_val) << (ffs64(_mask) - 1)) & (_mask))
> -
> -#define FIELD_GET(_mask, _reg)   \
> - ((typeof(_mask))(((_reg) & (_mask)) >> (ffs64(_mask) - 1)))
> -
>  /*
>   * Helpers for DMA allocation. Just the function name is reused for
>   * porting code, these allocation are not managed allocations
> @@ -195,27 +179,6 @@ static void *dmam_alloc_coherent(struct device *dev, 
> size_t size,
>   return vaddr;
>  }
>  
> -
> -/* Xen specific code. */
> -struct iommu_domain {
> - /* Runtime SMMU configuration for this iommu_domain */
> - atomic_tref;
> - /*
> -  * Used to link iommu_domain contexts for a same domain.
> -  * There is at least one per-SMMU to used by the domain.
> -  */
> - struct list_headlist;
> -};
> -
> -/* Describes information required for a Xen domain */
> -struct arm_smmu_xen_domain {
> - spinlock_t  lock;
> -
> - /* List of iommu domains associated to this domain */
> - struct list_headcontexts;
> -};
> -
> -
>  /* Keep a list of devices associated with this driver */
>  static DEFINE_SPINLOCK(arm_smmu_devices_lock);
>  static LIST_HEAD(arm_smmu_devices);
> @@ -259,635 +222,8 @@ static int platform_get_irq_byname_optional(struct 
> device *dev,
>  }
>  
>  /* Start of Linux SMMUv3 code */
> -/* MMIO registers */
> -#define ARM_SMMU_IDR00x0
> -#define IDR0_ST_LVL  GENMASK(28, 27)
> -#define IDR0_ST_LVL_2LVL 1
> -#define IDR0_STALL_MODEL GENMASK(25, 24)
> -#define IDR0_STALL_MODEL_STALL   0
> -#define IDR0_STALL_MODEL_FORCE   2
> -#define IDR0_TTENDIANGENMASK(22, 21)
> -#define IDR0_TTENDIAN_MIXED  0
> -#define IDR0_TTENDIAN_LE 2
> -#define IDR0_TTENDIAN_BE 3
> -#define IDR0_CD2L(1 << 19)
> -#define IDR0_VMID16  (1 << 18)
> -#define IDR0_PRI (1 << 16)
> -#define IDR0_SEV (1 << 14)
> -#define IDR0_MSI (1 << 13)
> 

[PATCH v2 04/10] xen/arm: smmuv3: Move definitions to a header

2022-09-02 Thread Rahul Singh
From: Jean-Philippe Brucker 

Backport Linux commit e881e7839fba. This is the clean backport without
any changes.

Allow sharing structure definitions with the upcoming SVA support for
Arm SMMUv3, by moving them to a separate header. We could surgically
extract only what is needed but keeping all definitions in one place
looks nicer.

Signed-off-by: Jean-Philippe Brucker 
Reviewed-by: Eric Auger 
Reviewed-by: Jonathan Cameron 
Link: https://lore.kernel.org/r/20200918101852.582559-8-jean-phili...@linaro.org
Signed-off-by: Will Deacon 
Origin: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
e881e7839fba
Signed-off-by: Rahul Singh 
---
Changes in v2:
 - fix commit msg
 - also move struct definition to header file to sync with Linux patch
---
 xen/drivers/passthrough/arm/smmu-v3.c | 666 +
 xen/drivers/passthrough/arm/smmu-v3.h | 674 ++
 2 files changed, 675 insertions(+), 665 deletions(-)
 create mode 100644 xen/drivers/passthrough/arm/smmu-v3.h

diff --git a/xen/drivers/passthrough/arm/smmu-v3.c 
b/xen/drivers/passthrough/arm/smmu-v3.c
index cee13d1fc7..85ad066266 100644
--- a/xen/drivers/passthrough/arm/smmu-v3.c
+++ b/xen/drivers/passthrough/arm/smmu-v3.c
@@ -90,6 +90,7 @@
 #include 
 #include 
 
+#include "smmu-v3.h"
 
 #define ARM_SMMU_VTCR_SH_IS3
 #define ARM_SMMU_VTCR_RGN_WBWA 1
@@ -102,21 +103,10 @@
 #define ARM_SMMU_VTCR_PS_48_BIT0x5ULL
 #define ARM_SMMU_VTCR_PS_52_BIT0x6ULL
 
-/* Linux compatibility functions. */
-typedef paddr_tdma_addr_t;
-typedef paddr_tphys_addr_t;
-typedef unsigned int   gfp_t;
-
 #define platform_devicedevice
 
 #define GFP_KERNEL 0
 
-/* Alias to Xen lock functions */
-#define mutex spinlock
-#define mutex_init spin_lock_init
-#define mutex_lock spin_lock
-#define mutex_unlock spin_unlock
-
 /* Device logger functions */
 #define dev_name(dev)  dt_node_full_name(dev->of_node)
 #define dev_dbg(dev, fmt, ...) \
@@ -157,12 +147,6 @@ typedef unsigned int   gfp_t;
 #define readl_relaxed_poll_timeout(addr, val, cond, delay_us, timeout_us)  
\
readx_poll_timeout(readl_relaxed, addr, val, cond, delay_us, timeout_us)
 
-#define FIELD_PREP(_mask, _val)\
-   (((typeof(_mask))(_val) << (ffs64(_mask) - 1)) & (_mask))
-
-#define FIELD_GET(_mask, _reg) \
-   ((typeof(_mask))(((_reg) & (_mask)) >> (ffs64(_mask) - 1)))
-
 /*
  * Helpers for DMA allocation. Just the function name is reused for
  * porting code, these allocation are not managed allocations
@@ -195,27 +179,6 @@ static void *dmam_alloc_coherent(struct device *dev, 
size_t size,
return vaddr;
 }
 
-
-/* Xen specific code. */
-struct iommu_domain {
-   /* Runtime SMMU configuration for this iommu_domain */
-   atomic_tref;
-   /*
-* Used to link iommu_domain contexts for a same domain.
-* There is at least one per-SMMU to used by the domain.
-*/
-   struct list_headlist;
-};
-
-/* Describes information required for a Xen domain */
-struct arm_smmu_xen_domain {
-   spinlock_t  lock;
-
-   /* List of iommu domains associated to this domain */
-   struct list_headcontexts;
-};
-
-
 /* Keep a list of devices associated with this driver */
 static DEFINE_SPINLOCK(arm_smmu_devices_lock);
 static LIST_HEAD(arm_smmu_devices);
@@ -259,635 +222,8 @@ static int platform_get_irq_byname_optional(struct device 
*dev,
 }
 
 /* Start of Linux SMMUv3 code */
-/* MMIO registers */
-#define ARM_SMMU_IDR0  0x0
-#define IDR0_ST_LVLGENMASK(28, 27)
-#define IDR0_ST_LVL_2LVL   1
-#define IDR0_STALL_MODEL   GENMASK(25, 24)
-#define IDR0_STALL_MODEL_STALL 0
-#define IDR0_STALL_MODEL_FORCE 2
-#define IDR0_TTENDIAN  GENMASK(22, 21)
-#define IDR0_TTENDIAN_MIXED0
-#define IDR0_TTENDIAN_LE   2
-#define IDR0_TTENDIAN_BE   3
-#define IDR0_CD2L  (1 << 19)
-#define IDR0_VMID16(1 << 18)
-#define IDR0_PRI   (1 << 16)
-#define IDR0_SEV   (1 << 14)
-#define IDR0_MSI   (1 << 13)
-#define IDR0_ASID16(1 << 12)
-#define IDR0_ATS   (1 << 10)
-#define IDR0_HYP   (1 << 9)
-#define IDR0_COHACC(1 << 4)
-#define IDR0_TTF   GENMASK(3, 2)
-#define IDR0_TTF_AARCH64   2
-#define IDR0_TTF_AARCH32_643
-#define IDR0_S1P   (1 << 1)
-#define IDR0_S2P   (1 << 0)
-
-#define ARM_SMMU_IDR1  0x4
-#define IDR1_TABLES_PRESET (1 << 30)
-#define IDR1_QUEUES_PRESET (1 << 29)
-#define IDR1_REL