Re: [PATCH v6 13/16] drivers: iommu: arm-smmu: add IORT configuration

2016-11-09 Thread Tomasz Nowicki

Hi Lorenzo,

On 18.10.2016 18:04, Lorenzo Pieralisi wrote:

In ACPI bases systems, in order to be able to create platform
devices and initialize them for ARM SMMU components, the IORT
kernel implementation requires a set of static functions to be
used by the IORT kernel layer to configure platform devices for
ARM SMMU components.

Add static configuration functions to the IORT kernel layer for
the ARM SMMU components, so that the ARM SMMU driver can
initialize its respective platform device by relying on the IORT
kernel infrastructure and by adding a corresponding ACPI device
early probe section entry.

Signed-off-by: Lorenzo Pieralisi 
Cc: Will Deacon 
Cc: Robin Murphy 
Cc: Joerg Roedel 
---
 drivers/acpi/arm64/iort.c | 81 +
 drivers/iommu/arm-smmu.c  | 84 ++-
 include/linux/acpi_iort.h |  3 ++
 3 files changed, 167 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index ea90bc8..04cc5f7 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -548,6 +548,78 @@ static bool __init arm_smmu_v3_is_coherent(struct 
acpi_iort_node *node)
return smmu->flags & ACPI_IORT_SMMU_V3_COHACC_OVERRIDE;
 }


[...]

+
+static int arm_smmu_device_acpi_probe(struct platform_device *pdev,
+ struct arm_smmu_device *smmu)
+{
+   struct device *dev = smmu->dev;
+   struct acpi_iort_node *node =
+   *(struct acpi_iort_node **)dev_get_platdata(dev);
+   struct acpi_iort_smmu *iort_smmu;
+   u64 *glb_irq;
+   int ret;
+
+   /* Retrieve SMMU1/2 specific data */
+   iort_smmu = (struct acpi_iort_smmu *)node->node_data;
+
+   ret = acpi_smmu_get_data(iort_smmu->model, >version,
+  >model);
+   if (ret < 0)
+   return ret;
+
+   glb_irq = ACPI_ADD_PTR(u64, iort_smmu,
+   iort_smmu->global_interrupt_offset);


One bug that I found:

-   glb_irq = ACPI_ADD_PTR(u64, iort_smmu,
-   iort_smmu->global_interrupt_offset);
+   glb_irq = ACPI_ADD_PTR(u64, node,
+   iort_smmu->global_interrupt_offset);

With this fix, I run VM with several PCI devices (NIC, SATA) in 
passthrough mode successfully on ACPI host using ThunderX 1-socket board.


Also, for my tests I used Eric's patches:
https://github.com/eauger/linux/commits/v4.9-rc3-reserved-rfc-v2

Including bug fix above:
Tested-by: Tomasz Nowicki  for all series.


+
+   if (!IORT_IRQ_MASK(glb_irq[1])) /* 0 means not implemented */
+   smmu->num_global_irqs = 1;
+   else
+   smmu->num_global_irqs = 2;
+
+   if (iort_smmu->flags & ACPI_IORT_SMMU_COHERENT_WALK)
+   smmu->features |= ARM_SMMU_FEAT_COHERENT_WALK;
+
+   return 0;
+}
+#else
+static inline int arm_smmu_device_acpi_probe(struct platform_device *pdev,
+struct arm_smmu_device *smmu)
+{
+   return -ENODEV;
+}
+#endif
+


Thanks,
Tomasz


Re: [PATCH v6 13/16] drivers: iommu: arm-smmu: add IORT configuration

2016-11-09 Thread Tomasz Nowicki

Hi Lorenzo,

On 18.10.2016 18:04, Lorenzo Pieralisi wrote:

In ACPI bases systems, in order to be able to create platform
devices and initialize them for ARM SMMU components, the IORT
kernel implementation requires a set of static functions to be
used by the IORT kernel layer to configure platform devices for
ARM SMMU components.

Add static configuration functions to the IORT kernel layer for
the ARM SMMU components, so that the ARM SMMU driver can
initialize its respective platform device by relying on the IORT
kernel infrastructure and by adding a corresponding ACPI device
early probe section entry.

Signed-off-by: Lorenzo Pieralisi 
Cc: Will Deacon 
Cc: Robin Murphy 
Cc: Joerg Roedel 
---
 drivers/acpi/arm64/iort.c | 81 +
 drivers/iommu/arm-smmu.c  | 84 ++-
 include/linux/acpi_iort.h |  3 ++
 3 files changed, 167 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index ea90bc8..04cc5f7 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -548,6 +548,78 @@ static bool __init arm_smmu_v3_is_coherent(struct 
acpi_iort_node *node)
return smmu->flags & ACPI_IORT_SMMU_V3_COHACC_OVERRIDE;
 }


[...]

+
+static int arm_smmu_device_acpi_probe(struct platform_device *pdev,
+ struct arm_smmu_device *smmu)
+{
+   struct device *dev = smmu->dev;
+   struct acpi_iort_node *node =
+   *(struct acpi_iort_node **)dev_get_platdata(dev);
+   struct acpi_iort_smmu *iort_smmu;
+   u64 *glb_irq;
+   int ret;
+
+   /* Retrieve SMMU1/2 specific data */
+   iort_smmu = (struct acpi_iort_smmu *)node->node_data;
+
+   ret = acpi_smmu_get_data(iort_smmu->model, >version,
+  >model);
+   if (ret < 0)
+   return ret;
+
+   glb_irq = ACPI_ADD_PTR(u64, iort_smmu,
+   iort_smmu->global_interrupt_offset);


One bug that I found:

-   glb_irq = ACPI_ADD_PTR(u64, iort_smmu,
-   iort_smmu->global_interrupt_offset);
+   glb_irq = ACPI_ADD_PTR(u64, node,
+   iort_smmu->global_interrupt_offset);

With this fix, I run VM with several PCI devices (NIC, SATA) in 
passthrough mode successfully on ACPI host using ThunderX 1-socket board.


Also, for my tests I used Eric's patches:
https://github.com/eauger/linux/commits/v4.9-rc3-reserved-rfc-v2

Including bug fix above:
Tested-by: Tomasz Nowicki  for all series.


+
+   if (!IORT_IRQ_MASK(glb_irq[1])) /* 0 means not implemented */
+   smmu->num_global_irqs = 1;
+   else
+   smmu->num_global_irqs = 2;
+
+   if (iort_smmu->flags & ACPI_IORT_SMMU_COHERENT_WALK)
+   smmu->features |= ARM_SMMU_FEAT_COHERENT_WALK;
+
+   return 0;
+}
+#else
+static inline int arm_smmu_device_acpi_probe(struct platform_device *pdev,
+struct arm_smmu_device *smmu)
+{
+   return -ENODEV;
+}
+#endif
+


Thanks,
Tomasz


[PATCH v6 13/16] drivers: iommu: arm-smmu: add IORT configuration

2016-10-18 Thread Lorenzo Pieralisi
In ACPI bases systems, in order to be able to create platform
devices and initialize them for ARM SMMU components, the IORT
kernel implementation requires a set of static functions to be
used by the IORT kernel layer to configure platform devices for
ARM SMMU components.

Add static configuration functions to the IORT kernel layer for
the ARM SMMU components, so that the ARM SMMU driver can
initialize its respective platform device by relying on the IORT
kernel infrastructure and by adding a corresponding ACPI device
early probe section entry.

Signed-off-by: Lorenzo Pieralisi 
Cc: Will Deacon 
Cc: Robin Murphy 
Cc: Joerg Roedel 
---
 drivers/acpi/arm64/iort.c | 81 +
 drivers/iommu/arm-smmu.c  | 84 ++-
 include/linux/acpi_iort.h |  3 ++
 3 files changed, 167 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index ea90bc8..04cc5f7 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -548,6 +548,78 @@ static bool __init arm_smmu_v3_is_coherent(struct 
acpi_iort_node *node)
return smmu->flags & ACPI_IORT_SMMU_V3_COHACC_OVERRIDE;
 }
 
+static int __init arm_smmu_count_resources(struct acpi_iort_node *node)
+{
+   struct acpi_iort_smmu *smmu;
+   int num_irqs;
+   u64 *glb_irq;
+
+   /* Retrieve SMMU specific data */
+   smmu = (struct acpi_iort_smmu *)node->node_data;
+
+   glb_irq = ACPI_ADD_PTR(u64, node, smmu->global_interrupt_offset);
+   if (!IORT_IRQ_MASK(glb_irq[1])) /* 0 means not implemented */
+   num_irqs = 1;
+   else
+   num_irqs = 2;
+
+   num_irqs += smmu->context_interrupt_count;
+
+   return num_irqs + 1;
+}
+
+static void __init arm_smmu_init_resources(struct resource *res,
+  struct acpi_iort_node *node)
+{
+   struct acpi_iort_smmu *smmu;
+   int i, hw_irq, trigger, num_res = 0;
+   u64 *ctx_irq, *glb_irq;
+
+   /* Retrieve SMMU specific data */
+   smmu = (struct acpi_iort_smmu *)node->node_data;
+
+   res[num_res].start = smmu->base_address;
+   res[num_res].end = smmu->base_address + smmu->span - 1;
+   res[num_res].flags = IORESOURCE_MEM;
+   num_res++;
+
+   glb_irq = ACPI_ADD_PTR(u64, node, smmu->global_interrupt_offset);
+   /* Global IRQs */
+   hw_irq = IORT_IRQ_MASK(glb_irq[0]);
+   trigger = IORT_IRQ_TRIGGER_MASK(glb_irq[0]);
+
+   acpi_iort_register_irq(hw_irq, "arm-smmu-global", trigger,
+[num_res++]);
+
+   /* Global IRQs */
+   hw_irq = IORT_IRQ_MASK(glb_irq[1]);
+   if (hw_irq) {
+   trigger = IORT_IRQ_TRIGGER_MASK(glb_irq[1]);
+   acpi_iort_register_irq(hw_irq, "arm-smmu-global", trigger,
+[num_res++]);
+   }
+
+   /* Context IRQs */
+   ctx_irq = ACPI_ADD_PTR(u64, node, smmu->context_interrupt_offset);
+   for (i = 0; i < smmu->context_interrupt_count; i++) {
+   hw_irq = IORT_IRQ_MASK(ctx_irq[i]);
+   trigger = IORT_IRQ_TRIGGER_MASK(ctx_irq[i]);
+
+   acpi_iort_register_irq(hw_irq, "arm-smmu-context", trigger,
+  [num_res++]);
+   }
+}
+
+static bool __init arm_smmu_is_coherent(struct acpi_iort_node *node)
+{
+   struct acpi_iort_smmu *smmu;
+
+   /* Retrieve SMMU specific data */
+   smmu = (struct acpi_iort_smmu *)node->node_data;
+
+   return smmu->flags & ACPI_IORT_SMMU_COHERENT_WALK;
+}
+
 struct iort_iommu_config {
const char *name;
int (*iommu_init)(struct acpi_iort_node *node);
@@ -564,12 +636,21 @@ static const struct iort_iommu_config 
iort_arm_smmu_v3_cfg __initconst = {
.iommu_init_resources = arm_smmu_v3_init_resources
 };
 
+static const struct iort_iommu_config iort_arm_smmu_cfg __initconst = {
+   .name = "arm-smmu",
+   .iommu_is_coherent = arm_smmu_is_coherent,
+   .iommu_count_resources = arm_smmu_count_resources,
+   .iommu_init_resources = arm_smmu_init_resources
+};
+
 static __init
 const struct iort_iommu_config *iort_get_iommu_cfg(struct acpi_iort_node *node)
 {
switch (node->type) {
case ACPI_IORT_NODE_SMMU_V3:
return _arm_smmu_v3_cfg;
+   case ACPI_IORT_NODE_SMMU:
+   return _arm_smmu_cfg;
default:
return NULL;
}
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 813dbf2..aa2d944 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -28,6 +28,8 @@
 
 #define pr_fmt(fmt) "arm-smmu: " fmt
 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -1892,6 +1894,71 @@ static const struct of_device_id arm_smmu_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, 

[PATCH v6 13/16] drivers: iommu: arm-smmu: add IORT configuration

2016-10-18 Thread Lorenzo Pieralisi
In ACPI bases systems, in order to be able to create platform
devices and initialize them for ARM SMMU components, the IORT
kernel implementation requires a set of static functions to be
used by the IORT kernel layer to configure platform devices for
ARM SMMU components.

Add static configuration functions to the IORT kernel layer for
the ARM SMMU components, so that the ARM SMMU driver can
initialize its respective platform device by relying on the IORT
kernel infrastructure and by adding a corresponding ACPI device
early probe section entry.

Signed-off-by: Lorenzo Pieralisi 
Cc: Will Deacon 
Cc: Robin Murphy 
Cc: Joerg Roedel 
---
 drivers/acpi/arm64/iort.c | 81 +
 drivers/iommu/arm-smmu.c  | 84 ++-
 include/linux/acpi_iort.h |  3 ++
 3 files changed, 167 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index ea90bc8..04cc5f7 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -548,6 +548,78 @@ static bool __init arm_smmu_v3_is_coherent(struct 
acpi_iort_node *node)
return smmu->flags & ACPI_IORT_SMMU_V3_COHACC_OVERRIDE;
 }
 
+static int __init arm_smmu_count_resources(struct acpi_iort_node *node)
+{
+   struct acpi_iort_smmu *smmu;
+   int num_irqs;
+   u64 *glb_irq;
+
+   /* Retrieve SMMU specific data */
+   smmu = (struct acpi_iort_smmu *)node->node_data;
+
+   glb_irq = ACPI_ADD_PTR(u64, node, smmu->global_interrupt_offset);
+   if (!IORT_IRQ_MASK(glb_irq[1])) /* 0 means not implemented */
+   num_irqs = 1;
+   else
+   num_irqs = 2;
+
+   num_irqs += smmu->context_interrupt_count;
+
+   return num_irqs + 1;
+}
+
+static void __init arm_smmu_init_resources(struct resource *res,
+  struct acpi_iort_node *node)
+{
+   struct acpi_iort_smmu *smmu;
+   int i, hw_irq, trigger, num_res = 0;
+   u64 *ctx_irq, *glb_irq;
+
+   /* Retrieve SMMU specific data */
+   smmu = (struct acpi_iort_smmu *)node->node_data;
+
+   res[num_res].start = smmu->base_address;
+   res[num_res].end = smmu->base_address + smmu->span - 1;
+   res[num_res].flags = IORESOURCE_MEM;
+   num_res++;
+
+   glb_irq = ACPI_ADD_PTR(u64, node, smmu->global_interrupt_offset);
+   /* Global IRQs */
+   hw_irq = IORT_IRQ_MASK(glb_irq[0]);
+   trigger = IORT_IRQ_TRIGGER_MASK(glb_irq[0]);
+
+   acpi_iort_register_irq(hw_irq, "arm-smmu-global", trigger,
+[num_res++]);
+
+   /* Global IRQs */
+   hw_irq = IORT_IRQ_MASK(glb_irq[1]);
+   if (hw_irq) {
+   trigger = IORT_IRQ_TRIGGER_MASK(glb_irq[1]);
+   acpi_iort_register_irq(hw_irq, "arm-smmu-global", trigger,
+[num_res++]);
+   }
+
+   /* Context IRQs */
+   ctx_irq = ACPI_ADD_PTR(u64, node, smmu->context_interrupt_offset);
+   for (i = 0; i < smmu->context_interrupt_count; i++) {
+   hw_irq = IORT_IRQ_MASK(ctx_irq[i]);
+   trigger = IORT_IRQ_TRIGGER_MASK(ctx_irq[i]);
+
+   acpi_iort_register_irq(hw_irq, "arm-smmu-context", trigger,
+  [num_res++]);
+   }
+}
+
+static bool __init arm_smmu_is_coherent(struct acpi_iort_node *node)
+{
+   struct acpi_iort_smmu *smmu;
+
+   /* Retrieve SMMU specific data */
+   smmu = (struct acpi_iort_smmu *)node->node_data;
+
+   return smmu->flags & ACPI_IORT_SMMU_COHERENT_WALK;
+}
+
 struct iort_iommu_config {
const char *name;
int (*iommu_init)(struct acpi_iort_node *node);
@@ -564,12 +636,21 @@ static const struct iort_iommu_config 
iort_arm_smmu_v3_cfg __initconst = {
.iommu_init_resources = arm_smmu_v3_init_resources
 };
 
+static const struct iort_iommu_config iort_arm_smmu_cfg __initconst = {
+   .name = "arm-smmu",
+   .iommu_is_coherent = arm_smmu_is_coherent,
+   .iommu_count_resources = arm_smmu_count_resources,
+   .iommu_init_resources = arm_smmu_init_resources
+};
+
 static __init
 const struct iort_iommu_config *iort_get_iommu_cfg(struct acpi_iort_node *node)
 {
switch (node->type) {
case ACPI_IORT_NODE_SMMU_V3:
return _arm_smmu_v3_cfg;
+   case ACPI_IORT_NODE_SMMU:
+   return _arm_smmu_cfg;
default:
return NULL;
}
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 813dbf2..aa2d944 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -28,6 +28,8 @@
 
 #define pr_fmt(fmt) "arm-smmu: " fmt
 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -1892,6 +1894,71 @@ static const struct of_device_id arm_smmu_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, arm_smmu_of_match);
 
+#ifdef CONFIG_ACPI
+static int acpi_smmu_get_data(u32 model, u32 *version, u32