All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-02 17:28 ` Lorenzo Pieralisi
  0 siblings, 0 replies; 21+ messages in thread
From: Lorenzo Pieralisi @ 2017-10-02 17:28 UTC (permalink / raw)
  To: linux-acpi
  Cc: linux-arm-kernel, linux-pci, Lorenzo Pieralisi, Will Deacon,
	Hanjun Guo, Sudeep Holla, Catalin Marinas, Robin Murphy,
	Zhou Wang, Alex Williamson

commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
workarounds") removed kernel code that was allowing to initialize
and probe the SMMU devices early (ie earlier than PCI devices, through
linker script callback entries) in the boot process because it was not
needed any longer in that the SMMU devices/drivers now support deferred
probing.

Since the SMMUs probe routines are also in charge of requesting global
PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
up early-probing workarounds") also postponed PCI ACS enablement to
SMMUs devices probe time, which is too late given that PCI devices needs
to detect if PCI ACS is enabled to init the respective capability
through the following call path:

pci_device_add()
 -> pci_init_capabilities()
  -> pci_enable_acs()

Add code in the ACPI IORT SMMU platform devices initialization path
(that is called before ACPI PCI enumeration) to detect if there
exists firmware mappings to map root complexes ids to SMMU ids
and if so enable ACS for the system.

Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
Signed-workarounds")
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Hanjun Guo <hanjun.guo@linaro.org>
Cc: Sudeep Holla <sudeep.holla@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Zhou Wang <wangzhou1@hisilicon.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
---
v1 -> v2:

- Reworked ACS enablement logic and based on root complex to SMMU
  ids firmware mapping detection
- Rebased against v4.14-rc3

v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2

 drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index 9565d57..de56394 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
 	return ret;
 }
 
+static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
+{
+	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
+		struct acpi_iort_node *parent;
+		struct acpi_iort_id_mapping *map;
+		int i;
+
+		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
+				   iort_node->mapping_offset);
+
+		for (i = 0; i < iort_node->mapping_count; i++, map++) {
+			if (!map->output_reference)
+				continue;
+
+			parent = ACPI_ADD_PTR(struct acpi_iort_node,
+					iort_table,  map->output_reference);
+			/*
+			 * If we detect a RC->SMMU mapping, make sure
+			 * we enable ACS on the system.
+			 */
+			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
+				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
+				pci_request_acs();
+				return true;
+			}
+		}
+	}
+
+	return false;
+}
+
 static void __init iort_init_platform_devices(void)
 {
 	struct acpi_iort_node *iort_node, *iort_end;
 	struct acpi_table_iort *iort;
 	struct fwnode_handle *fwnode;
 	int i, ret;
+	bool acs_enabled = false;
 
 	/*
 	 * iort_table and iort both point to the start of IORT table, but
@@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
 			return;
 		}
 
+		if (!acs_enabled)
+			acs_enabled = iort_enable_acs(iort_node);
+
 		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
 			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
 
-- 
2.4.12


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-02 17:28 ` Lorenzo Pieralisi
  0 siblings, 0 replies; 21+ messages in thread
From: Lorenzo Pieralisi @ 2017-10-02 17:28 UTC (permalink / raw)
  To: linux-arm-kernel

commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
workarounds") removed kernel code that was allowing to initialize
and probe the SMMU devices early (ie earlier than PCI devices, through
linker script callback entries) in the boot process because it was not
needed any longer in that the SMMU devices/drivers now support deferred
probing.

Since the SMMUs probe routines are also in charge of requesting global
PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
up early-probing workarounds") also postponed PCI ACS enablement to
SMMUs devices probe time, which is too late given that PCI devices needs
to detect if PCI ACS is enabled to init the respective capability
through the following call path:

pci_device_add()
 -> pci_init_capabilities()
  -> pci_enable_acs()

Add code in the ACPI IORT SMMU platform devices initialization path
(that is called before ACPI PCI enumeration) to detect if there
exists firmware mappings to map root complexes ids to SMMU ids
and if so enable ACS for the system.

Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
Signed-workarounds")
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Hanjun Guo <hanjun.guo@linaro.org>
Cc: Sudeep Holla <sudeep.holla@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Zhou Wang <wangzhou1@hisilicon.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
---
v1 -> v2:

- Reworked ACS enablement logic and based on root complex to SMMU
  ids firmware mapping detection
- Rebased against v4.14-rc3

v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2

 drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index 9565d57..de56394 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
 	return ret;
 }
 
+static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
+{
+	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
+		struct acpi_iort_node *parent;
+		struct acpi_iort_id_mapping *map;
+		int i;
+
+		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
+				   iort_node->mapping_offset);
+
+		for (i = 0; i < iort_node->mapping_count; i++, map++) {
+			if (!map->output_reference)
+				continue;
+
+			parent = ACPI_ADD_PTR(struct acpi_iort_node,
+					iort_table,  map->output_reference);
+			/*
+			 * If we detect a RC->SMMU mapping, make sure
+			 * we enable ACS on the system.
+			 */
+			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
+				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
+				pci_request_acs();
+				return true;
+			}
+		}
+	}
+
+	return false;
+}
+
 static void __init iort_init_platform_devices(void)
 {
 	struct acpi_iort_node *iort_node, *iort_end;
 	struct acpi_table_iort *iort;
 	struct fwnode_handle *fwnode;
 	int i, ret;
+	bool acs_enabled = false;
 
 	/*
 	 * iort_table and iort both point to the start of IORT table, but
@@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
 			return;
 		}
 
+		if (!acs_enabled)
+			acs_enabled = iort_enable_acs(iort_node);
+
 		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
 			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
 
-- 
2.4.12

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
  2017-10-02 17:28 ` Lorenzo Pieralisi
  (?)
@ 2017-10-03 12:48   ` Lorenzo Pieralisi
  -1 siblings, 0 replies; 21+ messages in thread
From: Lorenzo Pieralisi @ 2017-10-03 12:48 UTC (permalink / raw)
  To: linux-acpi, Zhou Wang, nwatters
  Cc: linux-arm-kernel, linux-pci, Will Deacon, Hanjun Guo,
	Sudeep Holla, Catalin Marinas, Robin Murphy, Alex Williamson

[+Nate]

Zhou, Nate,

On Mon, Oct 02, 2017 at 06:28:44PM +0100, Lorenzo Pieralisi wrote:
> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> workarounds") removed kernel code that was allowing to initialize
> and probe the SMMU devices early (ie earlier than PCI devices, through
> linker script callback entries) in the boot process because it was not
> needed any longer in that the SMMU devices/drivers now support deferred
> probing.
> 
> Since the SMMUs probe routines are also in charge of requesting global
> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> up early-probing workarounds") also postponed PCI ACS enablement to
> SMMUs devices probe time, which is too late given that PCI devices needs
> to detect if PCI ACS is enabled to init the respective capability
> through the following call path:
> 
> pci_device_add()
>  -> pci_init_capabilities()
>   -> pci_enable_acs()
> 
> Add code in the ACPI IORT SMMU platform devices initialization path
> (that is called before ACPI PCI enumeration) to detect if there
> exists firmware mappings to map root complexes ids to SMMU ids
> and if so enable ACS for the system.
> 
> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> Signed-workarounds")
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Hanjun Guo <hanjun.guo@linaro.org>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Alex Williamson <alex.williamson@redhat.com>
> ---
> v1 -> v2:
> 
> - Reworked ACS enablement logic and based on root complex to SMMU
>   ids firmware mapping detection
> - Rebased against v4.14-rc3
> 
> v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
> 
>  drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)

I have reworked the enablement logic wrt v1, dou you mind testing it
please, I would like to get it merged since I have 4.15 patches depending
on it.

Thanks,
Lorenzo

> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> index 9565d57..de56394 100644
> --- a/drivers/acpi/arm64/iort.c
> +++ b/drivers/acpi/arm64/iort.c
> @@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
>  	return ret;
>  }
>  
> +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
> +{
> +	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
> +		struct acpi_iort_node *parent;
> +		struct acpi_iort_id_mapping *map;
> +		int i;
> +
> +		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
> +				   iort_node->mapping_offset);
> +
> +		for (i = 0; i < iort_node->mapping_count; i++, map++) {
> +			if (!map->output_reference)
> +				continue;
> +
> +			parent = ACPI_ADD_PTR(struct acpi_iort_node,
> +					iort_table,  map->output_reference);
> +			/*
> +			 * If we detect a RC->SMMU mapping, make sure
> +			 * we enable ACS on the system.
> +			 */
> +			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
> +				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
> +				pci_request_acs();
> +				return true;
> +			}
> +		}
> +	}
> +
> +	return false;
> +}
> +
>  static void __init iort_init_platform_devices(void)
>  {
>  	struct acpi_iort_node *iort_node, *iort_end;
>  	struct acpi_table_iort *iort;
>  	struct fwnode_handle *fwnode;
>  	int i, ret;
> +	bool acs_enabled = false;
>  
>  	/*
>  	 * iort_table and iort both point to the start of IORT table, but
> @@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
>  			return;
>  		}
>  
> +		if (!acs_enabled)
> +			acs_enabled = iort_enable_acs(iort_node);
> +
>  		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
>  			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
>  
> -- 
> 2.4.12
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-03 12:48   ` Lorenzo Pieralisi
  0 siblings, 0 replies; 21+ messages in thread
From: Lorenzo Pieralisi @ 2017-10-03 12:48 UTC (permalink / raw)
  To: linux-acpi, Zhou Wang, nwatters
  Cc: Catalin Marinas, Sudeep Holla, Will Deacon, Alex Williamson,
	Hanjun Guo, linux-pci, Robin Murphy, linux-arm-kernel

[+Nate]

Zhou, Nate,

On Mon, Oct 02, 2017 at 06:28:44PM +0100, Lorenzo Pieralisi wrote:
> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> workarounds") removed kernel code that was allowing to initialize
> and probe the SMMU devices early (ie earlier than PCI devices, through
> linker script callback entries) in the boot process because it was not
> needed any longer in that the SMMU devices/drivers now support deferred
> probing.
> 
> Since the SMMUs probe routines are also in charge of requesting global
> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> up early-probing workarounds") also postponed PCI ACS enablement to
> SMMUs devices probe time, which is too late given that PCI devices needs
> to detect if PCI ACS is enabled to init the respective capability
> through the following call path:
> 
> pci_device_add()
>  -> pci_init_capabilities()
>   -> pci_enable_acs()
> 
> Add code in the ACPI IORT SMMU platform devices initialization path
> (that is called before ACPI PCI enumeration) to detect if there
> exists firmware mappings to map root complexes ids to SMMU ids
> and if so enable ACS for the system.
> 
> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> Signed-workarounds")
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Hanjun Guo <hanjun.guo@linaro.org>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Alex Williamson <alex.williamson@redhat.com>
> ---
> v1 -> v2:
> 
> - Reworked ACS enablement logic and based on root complex to SMMU
>   ids firmware mapping detection
> - Rebased against v4.14-rc3
> 
> v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
> 
>  drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)

I have reworked the enablement logic wrt v1, dou you mind testing it
please, I would like to get it merged since I have 4.15 patches depending
on it.

Thanks,
Lorenzo

> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> index 9565d57..de56394 100644
> --- a/drivers/acpi/arm64/iort.c
> +++ b/drivers/acpi/arm64/iort.c
> @@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
>  	return ret;
>  }
>  
> +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
> +{
> +	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
> +		struct acpi_iort_node *parent;
> +		struct acpi_iort_id_mapping *map;
> +		int i;
> +
> +		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
> +				   iort_node->mapping_offset);
> +
> +		for (i = 0; i < iort_node->mapping_count; i++, map++) {
> +			if (!map->output_reference)
> +				continue;
> +
> +			parent = ACPI_ADD_PTR(struct acpi_iort_node,
> +					iort_table,  map->output_reference);
> +			/*
> +			 * If we detect a RC->SMMU mapping, make sure
> +			 * we enable ACS on the system.
> +			 */
> +			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
> +				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
> +				pci_request_acs();
> +				return true;
> +			}
> +		}
> +	}
> +
> +	return false;
> +}
> +
>  static void __init iort_init_platform_devices(void)
>  {
>  	struct acpi_iort_node *iort_node, *iort_end;
>  	struct acpi_table_iort *iort;
>  	struct fwnode_handle *fwnode;
>  	int i, ret;
> +	bool acs_enabled = false;
>  
>  	/*
>  	 * iort_table and iort both point to the start of IORT table, but
> @@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
>  			return;
>  		}
>  
> +		if (!acs_enabled)
> +			acs_enabled = iort_enable_acs(iort_node);
> +
>  		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
>  			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
>  
> -- 
> 2.4.12
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-03 12:48   ` Lorenzo Pieralisi
  0 siblings, 0 replies; 21+ messages in thread
From: Lorenzo Pieralisi @ 2017-10-03 12:48 UTC (permalink / raw)
  To: linux-arm-kernel

[+Nate]

Zhou, Nate,

On Mon, Oct 02, 2017 at 06:28:44PM +0100, Lorenzo Pieralisi wrote:
> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> workarounds") removed kernel code that was allowing to initialize
> and probe the SMMU devices early (ie earlier than PCI devices, through
> linker script callback entries) in the boot process because it was not
> needed any longer in that the SMMU devices/drivers now support deferred
> probing.
> 
> Since the SMMUs probe routines are also in charge of requesting global
> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> up early-probing workarounds") also postponed PCI ACS enablement to
> SMMUs devices probe time, which is too late given that PCI devices needs
> to detect if PCI ACS is enabled to init the respective capability
> through the following call path:
> 
> pci_device_add()
>  -> pci_init_capabilities()
>   -> pci_enable_acs()
> 
> Add code in the ACPI IORT SMMU platform devices initialization path
> (that is called before ACPI PCI enumeration) to detect if there
> exists firmware mappings to map root complexes ids to SMMU ids
> and if so enable ACS for the system.
> 
> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> Signed-workarounds")
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Hanjun Guo <hanjun.guo@linaro.org>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Alex Williamson <alex.williamson@redhat.com>
> ---
> v1 -> v2:
> 
> - Reworked ACS enablement logic and based on root complex to SMMU
>   ids firmware mapping detection
> - Rebased against v4.14-rc3
> 
> v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
> 
>  drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)

I have reworked the enablement logic wrt v1, dou you mind testing it
please, I would like to get it merged since I have 4.15 patches depending
on it.

Thanks,
Lorenzo

> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> index 9565d57..de56394 100644
> --- a/drivers/acpi/arm64/iort.c
> +++ b/drivers/acpi/arm64/iort.c
> @@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
>  	return ret;
>  }
>  
> +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
> +{
> +	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
> +		struct acpi_iort_node *parent;
> +		struct acpi_iort_id_mapping *map;
> +		int i;
> +
> +		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
> +				   iort_node->mapping_offset);
> +
> +		for (i = 0; i < iort_node->mapping_count; i++, map++) {
> +			if (!map->output_reference)
> +				continue;
> +
> +			parent = ACPI_ADD_PTR(struct acpi_iort_node,
> +					iort_table,  map->output_reference);
> +			/*
> +			 * If we detect a RC->SMMU mapping, make sure
> +			 * we enable ACS on the system.
> +			 */
> +			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
> +				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
> +				pci_request_acs();
> +				return true;
> +			}
> +		}
> +	}
> +
> +	return false;
> +}
> +
>  static void __init iort_init_platform_devices(void)
>  {
>  	struct acpi_iort_node *iort_node, *iort_end;
>  	struct acpi_table_iort *iort;
>  	struct fwnode_handle *fwnode;
>  	int i, ret;
> +	bool acs_enabled = false;
>  
>  	/*
>  	 * iort_table and iort both point to the start of IORT table, but
> @@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
>  			return;
>  		}
>  
> +		if (!acs_enabled)
> +			acs_enabled = iort_enable_acs(iort_node);
> +
>  		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
>  			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
>  
> -- 
> 2.4.12
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
  2017-10-02 17:28 ` Lorenzo Pieralisi
@ 2017-10-03 13:47   ` Robin Murphy
  -1 siblings, 0 replies; 21+ messages in thread
From: Robin Murphy @ 2017-10-03 13:47 UTC (permalink / raw)
  To: Lorenzo Pieralisi, linux-acpi, Alex Williamson, Bjorn Helgaas
  Cc: linux-arm-kernel, linux-pci, Will Deacon, Hanjun Guo,
	Sudeep Holla, Catalin Marinas, Zhou Wang

On 02/10/17 18:28, Lorenzo Pieralisi wrote:
> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> workarounds") removed kernel code that was allowing to initialize
> and probe the SMMU devices early (ie earlier than PCI devices, through
> linker script callback entries) in the boot process because it was not
> needed any longer in that the SMMU devices/drivers now support deferred
> probing.
> 
> Since the SMMUs probe routines are also in charge of requesting global
> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> up early-probing workarounds") also postponed PCI ACS enablement to
> SMMUs devices probe time, which is too late given that PCI devices needs
> to detect if PCI ACS is enabled to init the respective capability
> through the following call path:
> 
> pci_device_add()
>  -> pci_init_capabilities()
>   -> pci_enable_acs()
> 
> Add code in the ACPI IORT SMMU platform devices initialization path
> (that is called before ACPI PCI enumeration) to detect if there
> exists firmware mappings to map root complexes ids to SMMU ids
> and if so enable ACS for the system.

As a self-contained fix I think this looks reasonable and sufficiently
unintrusive if it wants backporting:

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

More generally, though, I do wonder why this pci_request_acs() mechanism
is like it is - Alex, Bjorn, is there any particular reason that IOMMU
drivers couldn't call pci_enable_acs() directly from their .add_device
callback? In the cases we care about, we can still rely on the IOMMU
probing before any bridge or endpoint drivers, so AFAICS at that point
nothing should have changed much since pci_device_add() time.

Robin.

> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> Signed-workarounds")
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Hanjun Guo <hanjun.guo@linaro.org>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Alex Williamson <alex.williamson@redhat.com>
> ---
> v1 -> v2:
> 
> - Reworked ACS enablement logic and based on root complex to SMMU
>   ids firmware mapping detection
> - Rebased against v4.14-rc3
> 
> v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
> 
>  drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> index 9565d57..de56394 100644
> --- a/drivers/acpi/arm64/iort.c
> +++ b/drivers/acpi/arm64/iort.c
> @@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
>  	return ret;
>  }
>  
> +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
> +{
> +	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
> +		struct acpi_iort_node *parent;
> +		struct acpi_iort_id_mapping *map;
> +		int i;
> +
> +		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
> +				   iort_node->mapping_offset);
> +
> +		for (i = 0; i < iort_node->mapping_count; i++, map++) {
> +			if (!map->output_reference)
> +				continue;
> +
> +			parent = ACPI_ADD_PTR(struct acpi_iort_node,
> +					iort_table,  map->output_reference);
> +			/*
> +			 * If we detect a RC->SMMU mapping, make sure
> +			 * we enable ACS on the system.
> +			 */
> +			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
> +				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
> +				pci_request_acs();
> +				return true;
> +			}
> +		}
> +	}
> +
> +	return false;
> +}
> +
>  static void __init iort_init_platform_devices(void)
>  {
>  	struct acpi_iort_node *iort_node, *iort_end;
>  	struct acpi_table_iort *iort;
>  	struct fwnode_handle *fwnode;
>  	int i, ret;
> +	bool acs_enabled = false;
>  
>  	/*
>  	 * iort_table and iort both point to the start of IORT table, but
> @@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
>  			return;
>  		}
>  
> +		if (!acs_enabled)
> +			acs_enabled = iort_enable_acs(iort_node);
> +
>  		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
>  			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
>  
> 


^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-03 13:47   ` Robin Murphy
  0 siblings, 0 replies; 21+ messages in thread
From: Robin Murphy @ 2017-10-03 13:47 UTC (permalink / raw)
  To: linux-arm-kernel

On 02/10/17 18:28, Lorenzo Pieralisi wrote:
> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> workarounds") removed kernel code that was allowing to initialize
> and probe the SMMU devices early (ie earlier than PCI devices, through
> linker script callback entries) in the boot process because it was not
> needed any longer in that the SMMU devices/drivers now support deferred
> probing.
> 
> Since the SMMUs probe routines are also in charge of requesting global
> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> up early-probing workarounds") also postponed PCI ACS enablement to
> SMMUs devices probe time, which is too late given that PCI devices needs
> to detect if PCI ACS is enabled to init the respective capability
> through the following call path:
> 
> pci_device_add()
>  -> pci_init_capabilities()
>   -> pci_enable_acs()
> 
> Add code in the ACPI IORT SMMU platform devices initialization path
> (that is called before ACPI PCI enumeration) to detect if there
> exists firmware mappings to map root complexes ids to SMMU ids
> and if so enable ACS for the system.

As a self-contained fix I think this looks reasonable and sufficiently
unintrusive if it wants backporting:

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

More generally, though, I do wonder why this pci_request_acs() mechanism
is like it is - Alex, Bjorn, is there any particular reason that IOMMU
drivers couldn't call pci_enable_acs() directly from their .add_device
callback? In the cases we care about, we can still rely on the IOMMU
probing before any bridge or endpoint drivers, so AFAICS at that point
nothing should have changed much since pci_device_add() time.

Robin.

> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> Signed-workarounds")
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Hanjun Guo <hanjun.guo@linaro.org>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Alex Williamson <alex.williamson@redhat.com>
> ---
> v1 -> v2:
> 
> - Reworked ACS enablement logic and based on root complex to SMMU
>   ids firmware mapping detection
> - Rebased against v4.14-rc3
> 
> v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
> 
>  drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> index 9565d57..de56394 100644
> --- a/drivers/acpi/arm64/iort.c
> +++ b/drivers/acpi/arm64/iort.c
> @@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
>  	return ret;
>  }
>  
> +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
> +{
> +	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
> +		struct acpi_iort_node *parent;
> +		struct acpi_iort_id_mapping *map;
> +		int i;
> +
> +		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
> +				   iort_node->mapping_offset);
> +
> +		for (i = 0; i < iort_node->mapping_count; i++, map++) {
> +			if (!map->output_reference)
> +				continue;
> +
> +			parent = ACPI_ADD_PTR(struct acpi_iort_node,
> +					iort_table,  map->output_reference);
> +			/*
> +			 * If we detect a RC->SMMU mapping, make sure
> +			 * we enable ACS on the system.
> +			 */
> +			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
> +				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
> +				pci_request_acs();
> +				return true;
> +			}
> +		}
> +	}
> +
> +	return false;
> +}
> +
>  static void __init iort_init_platform_devices(void)
>  {
>  	struct acpi_iort_node *iort_node, *iort_end;
>  	struct acpi_table_iort *iort;
>  	struct fwnode_handle *fwnode;
>  	int i, ret;
> +	bool acs_enabled = false;
>  
>  	/*
>  	 * iort_table and iort both point to the start of IORT table, but
> @@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
>  			return;
>  		}
>  
> +		if (!acs_enabled)
> +			acs_enabled = iort_enable_acs(iort_node);
> +
>  		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
>  			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
>  
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
  2017-10-02 17:28 ` Lorenzo Pieralisi
  (?)
@ 2017-10-03 14:45   ` John Garry
  -1 siblings, 0 replies; 21+ messages in thread
From: John Garry @ 2017-10-03 14:45 UTC (permalink / raw)
  To: Lorenzo Pieralisi, linux-acpi
  Cc: linux-arm-kernel, linux-pci, Will Deacon, Hanjun Guo,
	Sudeep Holla, Catalin Marinas, Robin Murphy, Zhou Wang,
	Alex Williamson, Linuxarm

On 02/10/2017 18:28, Lorenzo Pieralisi wrote:
> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> workarounds") removed kernel code that was allowing to initialize
> and probe the SMMU devices early (ie earlier than PCI devices, through
> linker script callback entries) in the boot process because it was not
> needed any longer in that the SMMU devices/drivers now support deferred
> probing.
>
> Since the SMMUs probe routines are also in charge of requesting global
> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> up early-probing workarounds") also postponed PCI ACS enablement to
> SMMUs devices probe time, which is too late given that PCI devices needs
> to detect if PCI ACS is enabled to init the respective capability
> through the following call path:
>
> pci_device_add()
>  -> pci_init_capabilities()
>   -> pci_enable_acs()
>
> Add code in the ACPI IORT SMMU platform devices initialization path
> (that is called before ACPI PCI enumeration) to detect if there
> exists firmware mappings to map root complexes ids to SMMU ids
> and if so enable ACS for the system.
>
> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> Signed-workarounds")
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Hanjun Guo <hanjun.guo@linaro.org>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Alex Williamson <alex.williamson@redhat.com>
> ---
> v1 -> v2:
>
> - Reworked ACS enablement logic and based on root complex to SMMU
>   ids firmware mapping detection
> - Rebased against v4.14-rc3
>
> v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
>
>  drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>
> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> index 9565d57..de56394 100644
> --- a/drivers/acpi/arm64/iort.c
> +++ b/drivers/acpi/arm64/iort.c
> @@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
>  	return ret;
>  }
>
> +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
> +{
> +	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
> +		struct acpi_iort_node *parent;
> +		struct acpi_iort_id_mapping *map;
> +		int i;
> +
> +		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
> +				   iort_node->mapping_offset);
> +
> +		for (i = 0; i < iort_node->mapping_count; i++, map++) {
> +			if (!map->output_reference)
> +				continue;
> +
> +			parent = ACPI_ADD_PTR(struct acpi_iort_node,
> +					iort_table,  map->output_reference);
> +			/*
> +			 * If we detect a RC->SMMU mapping, make sure
> +			 * we enable ACS on the system.
> +			 */
> +			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
> +				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {

Hi Lorenzo,

There are a couple of places now which check for any SMMU type. Should 
we have a helper function/macro to condense, like this:
IORT_TYPE_MASK(type) & IORT_IOMMU_TYPE

Personal taste, I guess.

BTW, unfortunately we can't re-test this week due to Chinese holiday.

Cheers,
John

> +				pci_request_acs();
> +				return true;
> +			}
> +		}
> +	}
> +
> +	return false;
> +}
> +
>  static void __init iort_init_platform_devices(void)
>  {
>  	struct acpi_iort_node *iort_node, *iort_end;
>  	struct acpi_table_iort *iort;
>  	struct fwnode_handle *fwnode;
>  	int i, ret;
> +	bool acs_enabled = false;
>
>  	/*
>  	 * iort_table and iort both point to the start of IORT table, but
> @@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
>  			return;
>  		}
>
> +		if (!acs_enabled)
> +			acs_enabled = iort_enable_acs(iort_node);
> +
>  		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
>  			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
>
>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-03 14:45   ` John Garry
  0 siblings, 0 replies; 21+ messages in thread
From: John Garry @ 2017-10-03 14:45 UTC (permalink / raw)
  To: Lorenzo Pieralisi, linux-acpi
  Cc: Catalin Marinas, Sudeep Holla, Will Deacon, Alex Williamson,
	Linuxarm, Zhou Wang, Hanjun Guo, linux-pci, Robin Murphy,
	linux-arm-kernel

On 02/10/2017 18:28, Lorenzo Pieralisi wrote:
> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> workarounds") removed kernel code that was allowing to initialize
> and probe the SMMU devices early (ie earlier than PCI devices, through
> linker script callback entries) in the boot process because it was not
> needed any longer in that the SMMU devices/drivers now support deferred
> probing.
>
> Since the SMMUs probe routines are also in charge of requesting global
> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> up early-probing workarounds") also postponed PCI ACS enablement to
> SMMUs devices probe time, which is too late given that PCI devices needs
> to detect if PCI ACS is enabled to init the respective capability
> through the following call path:
>
> pci_device_add()
>  -> pci_init_capabilities()
>   -> pci_enable_acs()
>
> Add code in the ACPI IORT SMMU platform devices initialization path
> (that is called before ACPI PCI enumeration) to detect if there
> exists firmware mappings to map root complexes ids to SMMU ids
> and if so enable ACS for the system.
>
> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> Signed-workarounds")
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Hanjun Guo <hanjun.guo@linaro.org>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Alex Williamson <alex.williamson@redhat.com>
> ---
> v1 -> v2:
>
> - Reworked ACS enablement logic and based on root complex to SMMU
>   ids firmware mapping detection
> - Rebased against v4.14-rc3
>
> v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
>
>  drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>
> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> index 9565d57..de56394 100644
> --- a/drivers/acpi/arm64/iort.c
> +++ b/drivers/acpi/arm64/iort.c
> @@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
>  	return ret;
>  }
>
> +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
> +{
> +	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
> +		struct acpi_iort_node *parent;
> +		struct acpi_iort_id_mapping *map;
> +		int i;
> +
> +		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
> +				   iort_node->mapping_offset);
> +
> +		for (i = 0; i < iort_node->mapping_count; i++, map++) {
> +			if (!map->output_reference)
> +				continue;
> +
> +			parent = ACPI_ADD_PTR(struct acpi_iort_node,
> +					iort_table,  map->output_reference);
> +			/*
> +			 * If we detect a RC->SMMU mapping, make sure
> +			 * we enable ACS on the system.
> +			 */
> +			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
> +				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {

Hi Lorenzo,

There are a couple of places now which check for any SMMU type. Should 
we have a helper function/macro to condense, like this:
IORT_TYPE_MASK(type) & IORT_IOMMU_TYPE

Personal taste, I guess.

BTW, unfortunately we can't re-test this week due to Chinese holiday.

Cheers,
John

> +				pci_request_acs();
> +				return true;
> +			}
> +		}
> +	}
> +
> +	return false;
> +}
> +
>  static void __init iort_init_platform_devices(void)
>  {
>  	struct acpi_iort_node *iort_node, *iort_end;
>  	struct acpi_table_iort *iort;
>  	struct fwnode_handle *fwnode;
>  	int i, ret;
> +	bool acs_enabled = false;
>
>  	/*
>  	 * iort_table and iort both point to the start of IORT table, but
> @@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
>  			return;
>  		}
>
> +		if (!acs_enabled)
> +			acs_enabled = iort_enable_acs(iort_node);
> +
>  		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
>  			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
>
>



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-03 14:45   ` John Garry
  0 siblings, 0 replies; 21+ messages in thread
From: John Garry @ 2017-10-03 14:45 UTC (permalink / raw)
  To: linux-arm-kernel

On 02/10/2017 18:28, Lorenzo Pieralisi wrote:
> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> workarounds") removed kernel code that was allowing to initialize
> and probe the SMMU devices early (ie earlier than PCI devices, through
> linker script callback entries) in the boot process because it was not
> needed any longer in that the SMMU devices/drivers now support deferred
> probing.
>
> Since the SMMUs probe routines are also in charge of requesting global
> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> up early-probing workarounds") also postponed PCI ACS enablement to
> SMMUs devices probe time, which is too late given that PCI devices needs
> to detect if PCI ACS is enabled to init the respective capability
> through the following call path:
>
> pci_device_add()
>  -> pci_init_capabilities()
>   -> pci_enable_acs()
>
> Add code in the ACPI IORT SMMU platform devices initialization path
> (that is called before ACPI PCI enumeration) to detect if there
> exists firmware mappings to map root complexes ids to SMMU ids
> and if so enable ACS for the system.
>
> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> Signed-workarounds")
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Hanjun Guo <hanjun.guo@linaro.org>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Alex Williamson <alex.williamson@redhat.com>
> ---
> v1 -> v2:
>
> - Reworked ACS enablement logic and based on root complex to SMMU
>   ids firmware mapping detection
> - Rebased against v4.14-rc3
>
> v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
>
>  drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>
> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> index 9565d57..de56394 100644
> --- a/drivers/acpi/arm64/iort.c
> +++ b/drivers/acpi/arm64/iort.c
> @@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
>  	return ret;
>  }
>
> +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
> +{
> +	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
> +		struct acpi_iort_node *parent;
> +		struct acpi_iort_id_mapping *map;
> +		int i;
> +
> +		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
> +				   iort_node->mapping_offset);
> +
> +		for (i = 0; i < iort_node->mapping_count; i++, map++) {
> +			if (!map->output_reference)
> +				continue;
> +
> +			parent = ACPI_ADD_PTR(struct acpi_iort_node,
> +					iort_table,  map->output_reference);
> +			/*
> +			 * If we detect a RC->SMMU mapping, make sure
> +			 * we enable ACS on the system.
> +			 */
> +			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
> +				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {

Hi Lorenzo,

There are a couple of places now which check for any SMMU type. Should 
we have a helper function/macro to condense, like this:
IORT_TYPE_MASK(type) & IORT_IOMMU_TYPE

Personal taste, I guess.

BTW, unfortunately we can't re-test this week due to Chinese holiday.

Cheers,
John

> +				pci_request_acs();
> +				return true;
> +			}
> +		}
> +	}
> +
> +	return false;
> +}
> +
>  static void __init iort_init_platform_devices(void)
>  {
>  	struct acpi_iort_node *iort_node, *iort_end;
>  	struct acpi_table_iort *iort;
>  	struct fwnode_handle *fwnode;
>  	int i, ret;
> +	bool acs_enabled = false;
>
>  	/*
>  	 * iort_table and iort both point to the start of IORT table, but
> @@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
>  			return;
>  		}
>
> +		if (!acs_enabled)
> +			acs_enabled = iort_enable_acs(iort_node);
> +
>  		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
>  			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
>
>

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
  2017-10-03 14:45   ` John Garry
  (?)
@ 2017-10-03 16:53     ` Lorenzo Pieralisi
  -1 siblings, 0 replies; 21+ messages in thread
From: Lorenzo Pieralisi @ 2017-10-03 16:53 UTC (permalink / raw)
  To: John Garry
  Cc: linux-acpi, linux-arm-kernel, linux-pci, Will Deacon, Hanjun Guo,
	Sudeep Holla, Catalin Marinas, Robin Murphy, Zhou Wang,
	Alex Williamson, Linuxarm

On Tue, Oct 03, 2017 at 03:45:38PM +0100, John Garry wrote:
> On 02/10/2017 18:28, Lorenzo Pieralisi wrote:
> >commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> >workarounds") removed kernel code that was allowing to initialize
> >and probe the SMMU devices early (ie earlier than PCI devices, through
> >linker script callback entries) in the boot process because it was not
> >needed any longer in that the SMMU devices/drivers now support deferred
> >probing.
> >
> >Since the SMMUs probe routines are also in charge of requesting global
> >PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> >up early-probing workarounds") also postponed PCI ACS enablement to
> >SMMUs devices probe time, which is too late given that PCI devices needs
> >to detect if PCI ACS is enabled to init the respective capability
> >through the following call path:
> >
> >pci_device_add()
> > -> pci_init_capabilities()
> >  -> pci_enable_acs()
> >
> >Add code in the ACPI IORT SMMU platform devices initialization path
> >(that is called before ACPI PCI enumeration) to detect if there
> >exists firmware mappings to map root complexes ids to SMMU ids
> >and if so enable ACS for the system.
> >
> >Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> >Signed-workarounds")
> >Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> >Cc: Will Deacon <will.deacon@arm.com>
> >Cc: Hanjun Guo <hanjun.guo@linaro.org>
> >Cc: Sudeep Holla <sudeep.holla@arm.com>
> >Cc: Catalin Marinas <catalin.marinas@arm.com>
> >Cc: Robin Murphy <robin.murphy@arm.com>
> >Cc: Zhou Wang <wangzhou1@hisilicon.com>
> >Cc: Alex Williamson <alex.williamson@redhat.com>
> >---
> >v1 -> v2:
> >
> >- Reworked ACS enablement logic and based on root complex to SMMU
> >  ids firmware mapping detection
> >- Rebased against v4.14-rc3
> >
> >v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
> >
> > drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
> > 1 file changed, 35 insertions(+)
> >
> >diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> >index 9565d57..de56394 100644
> >--- a/drivers/acpi/arm64/iort.c
> >+++ b/drivers/acpi/arm64/iort.c
> >@@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
> > 	return ret;
> > }
> >
> >+static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
> >+{
> >+	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
> >+		struct acpi_iort_node *parent;
> >+		struct acpi_iort_id_mapping *map;
> >+		int i;
> >+
> >+		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
> >+				   iort_node->mapping_offset);
> >+
> >+		for (i = 0; i < iort_node->mapping_count; i++, map++) {
> >+			if (!map->output_reference)
> >+				continue;
> >+
> >+			parent = ACPI_ADD_PTR(struct acpi_iort_node,
> >+					iort_table,  map->output_reference);
> >+			/*
> >+			 * If we detect a RC->SMMU mapping, make sure
> >+			 * we enable ACS on the system.
> >+			 */
> >+			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
> >+				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
> 
> Hi Lorenzo,
> 
> There are a couple of places now which check for any SMMU type.
> Should we have a helper function/macro to condense, like this:
> IORT_TYPE_MASK(type) & IORT_IOMMU_TYPE
> 
> Personal taste, I guess.

I agree, I will add that macro for 4.15, I would like to merge this
as a fix now.

> BTW, unfortunately we can't re-test this week due to Chinese holiday.

Understood, I just would like to get some coverage before asking Will
and Catalin to queue it as a fix.

Cheers,
Lorenzo

> Cheers,
> John
> 
> >+				pci_request_acs();
> >+				return true;
> >+			}
> >+		}
> >+	}
> >+
> >+	return false;
> >+}
> >+
> > static void __init iort_init_platform_devices(void)
> > {
> > 	struct acpi_iort_node *iort_node, *iort_end;
> > 	struct acpi_table_iort *iort;
> > 	struct fwnode_handle *fwnode;
> > 	int i, ret;
> >+	bool acs_enabled = false;
> >
> > 	/*
> > 	 * iort_table and iort both point to the start of IORT table, but
> >@@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
> > 			return;
> > 		}
> >
> >+		if (!acs_enabled)
> >+			acs_enabled = iort_enable_acs(iort_node);
> >+
> > 		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
> > 			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
> >
> >
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-03 16:53     ` Lorenzo Pieralisi
  0 siblings, 0 replies; 21+ messages in thread
From: Lorenzo Pieralisi @ 2017-10-03 16:53 UTC (permalink / raw)
  To: John Garry
  Cc: Catalin Marinas, linux-pci, Will Deacon, Alex Williamson,
	Linuxarm, linux-acpi, Zhou Wang, Hanjun Guo, Sudeep Holla,
	Robin Murphy, linux-arm-kernel

On Tue, Oct 03, 2017 at 03:45:38PM +0100, John Garry wrote:
> On 02/10/2017 18:28, Lorenzo Pieralisi wrote:
> >commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> >workarounds") removed kernel code that was allowing to initialize
> >and probe the SMMU devices early (ie earlier than PCI devices, through
> >linker script callback entries) in the boot process because it was not
> >needed any longer in that the SMMU devices/drivers now support deferred
> >probing.
> >
> >Since the SMMUs probe routines are also in charge of requesting global
> >PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> >up early-probing workarounds") also postponed PCI ACS enablement to
> >SMMUs devices probe time, which is too late given that PCI devices needs
> >to detect if PCI ACS is enabled to init the respective capability
> >through the following call path:
> >
> >pci_device_add()
> > -> pci_init_capabilities()
> >  -> pci_enable_acs()
> >
> >Add code in the ACPI IORT SMMU platform devices initialization path
> >(that is called before ACPI PCI enumeration) to detect if there
> >exists firmware mappings to map root complexes ids to SMMU ids
> >and if so enable ACS for the system.
> >
> >Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> >Signed-workarounds")
> >Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> >Cc: Will Deacon <will.deacon@arm.com>
> >Cc: Hanjun Guo <hanjun.guo@linaro.org>
> >Cc: Sudeep Holla <sudeep.holla@arm.com>
> >Cc: Catalin Marinas <catalin.marinas@arm.com>
> >Cc: Robin Murphy <robin.murphy@arm.com>
> >Cc: Zhou Wang <wangzhou1@hisilicon.com>
> >Cc: Alex Williamson <alex.williamson@redhat.com>
> >---
> >v1 -> v2:
> >
> >- Reworked ACS enablement logic and based on root complex to SMMU
> >  ids firmware mapping detection
> >- Rebased against v4.14-rc3
> >
> >v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
> >
> > drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
> > 1 file changed, 35 insertions(+)
> >
> >diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> >index 9565d57..de56394 100644
> >--- a/drivers/acpi/arm64/iort.c
> >+++ b/drivers/acpi/arm64/iort.c
> >@@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
> > 	return ret;
> > }
> >
> >+static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
> >+{
> >+	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
> >+		struct acpi_iort_node *parent;
> >+		struct acpi_iort_id_mapping *map;
> >+		int i;
> >+
> >+		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
> >+				   iort_node->mapping_offset);
> >+
> >+		for (i = 0; i < iort_node->mapping_count; i++, map++) {
> >+			if (!map->output_reference)
> >+				continue;
> >+
> >+			parent = ACPI_ADD_PTR(struct acpi_iort_node,
> >+					iort_table,  map->output_reference);
> >+			/*
> >+			 * If we detect a RC->SMMU mapping, make sure
> >+			 * we enable ACS on the system.
> >+			 */
> >+			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
> >+				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
> 
> Hi Lorenzo,
> 
> There are a couple of places now which check for any SMMU type.
> Should we have a helper function/macro to condense, like this:
> IORT_TYPE_MASK(type) & IORT_IOMMU_TYPE
> 
> Personal taste, I guess.

I agree, I will add that macro for 4.15, I would like to merge this
as a fix now.

> BTW, unfortunately we can't re-test this week due to Chinese holiday.

Understood, I just would like to get some coverage before asking Will
and Catalin to queue it as a fix.

Cheers,
Lorenzo

> Cheers,
> John
> 
> >+				pci_request_acs();
> >+				return true;
> >+			}
> >+		}
> >+	}
> >+
> >+	return false;
> >+}
> >+
> > static void __init iort_init_platform_devices(void)
> > {
> > 	struct acpi_iort_node *iort_node, *iort_end;
> > 	struct acpi_table_iort *iort;
> > 	struct fwnode_handle *fwnode;
> > 	int i, ret;
> >+	bool acs_enabled = false;
> >
> > 	/*
> > 	 * iort_table and iort both point to the start of IORT table, but
> >@@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
> > 			return;
> > 		}
> >
> >+		if (!acs_enabled)
> >+			acs_enabled = iort_enable_acs(iort_node);
> >+
> > 		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
> > 			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
> >
> >
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-03 16:53     ` Lorenzo Pieralisi
  0 siblings, 0 replies; 21+ messages in thread
From: Lorenzo Pieralisi @ 2017-10-03 16:53 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Oct 03, 2017 at 03:45:38PM +0100, John Garry wrote:
> On 02/10/2017 18:28, Lorenzo Pieralisi wrote:
> >commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> >workarounds") removed kernel code that was allowing to initialize
> >and probe the SMMU devices early (ie earlier than PCI devices, through
> >linker script callback entries) in the boot process because it was not
> >needed any longer in that the SMMU devices/drivers now support deferred
> >probing.
> >
> >Since the SMMUs probe routines are also in charge of requesting global
> >PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> >up early-probing workarounds") also postponed PCI ACS enablement to
> >SMMUs devices probe time, which is too late given that PCI devices needs
> >to detect if PCI ACS is enabled to init the respective capability
> >through the following call path:
> >
> >pci_device_add()
> > -> pci_init_capabilities()
> >  -> pci_enable_acs()
> >
> >Add code in the ACPI IORT SMMU platform devices initialization path
> >(that is called before ACPI PCI enumeration) to detect if there
> >exists firmware mappings to map root complexes ids to SMMU ids
> >and if so enable ACS for the system.
> >
> >Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> >Signed-workarounds")
> >Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> >Cc: Will Deacon <will.deacon@arm.com>
> >Cc: Hanjun Guo <hanjun.guo@linaro.org>
> >Cc: Sudeep Holla <sudeep.holla@arm.com>
> >Cc: Catalin Marinas <catalin.marinas@arm.com>
> >Cc: Robin Murphy <robin.murphy@arm.com>
> >Cc: Zhou Wang <wangzhou1@hisilicon.com>
> >Cc: Alex Williamson <alex.williamson@redhat.com>
> >---
> >v1 -> v2:
> >
> >- Reworked ACS enablement logic and based on root complex to SMMU
> >  ids firmware mapping detection
> >- Rebased against v4.14-rc3
> >
> >v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
> >
> > drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
> > 1 file changed, 35 insertions(+)
> >
> >diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> >index 9565d57..de56394 100644
> >--- a/drivers/acpi/arm64/iort.c
> >+++ b/drivers/acpi/arm64/iort.c
> >@@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
> > 	return ret;
> > }
> >
> >+static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
> >+{
> >+	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
> >+		struct acpi_iort_node *parent;
> >+		struct acpi_iort_id_mapping *map;
> >+		int i;
> >+
> >+		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
> >+				   iort_node->mapping_offset);
> >+
> >+		for (i = 0; i < iort_node->mapping_count; i++, map++) {
> >+			if (!map->output_reference)
> >+				continue;
> >+
> >+			parent = ACPI_ADD_PTR(struct acpi_iort_node,
> >+					iort_table,  map->output_reference);
> >+			/*
> >+			 * If we detect a RC->SMMU mapping, make sure
> >+			 * we enable ACS on the system.
> >+			 */
> >+			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
> >+				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
> 
> Hi Lorenzo,
> 
> There are a couple of places now which check for any SMMU type.
> Should we have a helper function/macro to condense, like this:
> IORT_TYPE_MASK(type) & IORT_IOMMU_TYPE
> 
> Personal taste, I guess.

I agree, I will add that macro for 4.15, I would like to merge this
as a fix now.

> BTW, unfortunately we can't re-test this week due to Chinese holiday.

Understood, I just would like to get some coverage before asking Will
and Catalin to queue it as a fix.

Cheers,
Lorenzo

> Cheers,
> John
> 
> >+				pci_request_acs();
> >+				return true;
> >+			}
> >+		}
> >+	}
> >+
> >+	return false;
> >+}
> >+
> > static void __init iort_init_platform_devices(void)
> > {
> > 	struct acpi_iort_node *iort_node, *iort_end;
> > 	struct acpi_table_iort *iort;
> > 	struct fwnode_handle *fwnode;
> > 	int i, ret;
> >+	bool acs_enabled = false;
> >
> > 	/*
> > 	 * iort_table and iort both point to the start of IORT table, but
> >@@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
> > 			return;
> > 		}
> >
> >+		if (!acs_enabled)
> >+			acs_enabled = iort_enable_acs(iort_node);
> >+
> > 		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
> > 			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
> >
> >
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
  2017-10-03 12:48   ` Lorenzo Pieralisi
@ 2017-10-03 19:08     ` Nate Watterson
  -1 siblings, 0 replies; 21+ messages in thread
From: Nate Watterson @ 2017-10-03 19:08 UTC (permalink / raw)
  To: Lorenzo Pieralisi, linux-acpi, Zhou Wang
  Cc: linux-arm-kernel, linux-pci, Will Deacon, Hanjun Guo,
	Sudeep Holla, Catalin Marinas, Robin Murphy, Alex Williamson

Hi Lorenzo,

On 10/3/2017 8:48 AM, Lorenzo Pieralisi wrote:
> [+Nate]
> 
> Zhou, Nate,
> 
> On Mon, Oct 02, 2017 at 06:28:44PM +0100, Lorenzo Pieralisi wrote:
>> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
>> workarounds") removed kernel code that was allowing to initialize
>> and probe the SMMU devices early (ie earlier than PCI devices, through
>> linker script callback entries) in the boot process because it was not
>> needed any longer in that the SMMU devices/drivers now support deferred
>> probing.
>>
>> Since the SMMUs probe routines are also in charge of requesting global
>> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
>> up early-probing workarounds") also postponed PCI ACS enablement to
>> SMMUs devices probe time, which is too late given that PCI devices needs
>> to detect if PCI ACS is enabled to init the respective capability
>> through the following call path:
>>
>> pci_device_add()
>>   -> pci_init_capabilities()
>>    -> pci_enable_acs()
>>
>> Add code in the ACPI IORT SMMU platform devices initialization path
>> (that is called before ACPI PCI enumeration) to detect if there
>> exists firmware mappings to map root complexes ids to SMMU ids
>> and if so enable ACS for the system.
>>
>> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
>> Signed-workarounds")
>> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>> Cc: Will Deacon <will.deacon@arm.com>
>> Cc: Hanjun Guo <hanjun.guo@linaro.org>
>> Cc: Sudeep Holla <sudeep.holla@arm.com>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Robin Murphy <robin.murphy@arm.com>
>> Cc: Zhou Wang <wangzhou1@hisilicon.com>
>> Cc: Alex Williamson <alex.williamson@redhat.com>
>> ---
>> v1 -> v2:
>>
>> - Reworked ACS enablement logic and based on root complex to SMMU
>>    ids firmware mapping detection
>> - Rebased against v4.14-rc3
>>
>> v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
>>
>>   drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
>>   1 file changed, 35 insertions(+)
> 
> I have reworked the enablement logic wrt v1, dou you mind testing it
> please, I would like to get it merged since I have 4.15 patches depending
> on it.

I tested with and without RC->SMMU mappings defined in the IORT and
observed the expected value for pci_acs_enable in both cases.

Tested-by: Nate Watterson <nwatters@codeaurora.org>

Thanks,
Nate

> 
> Thanks,
> Lorenzo
> 
>> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
>> index 9565d57..de56394 100644
>> --- a/drivers/acpi/arm64/iort.c
>> +++ b/drivers/acpi/arm64/iort.c
>> @@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
>>   	return ret;
>>   }
>>   
>> +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
>> +{
>> +	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
>> +		struct acpi_iort_node *parent;
>> +		struct acpi_iort_id_mapping *map;
>> +		int i;
>> +
>> +		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
>> +				   iort_node->mapping_offset);
>> +
>> +		for (i = 0; i < iort_node->mapping_count; i++, map++) {
>> +			if (!map->output_reference)
>> +				continue;
>> +
>> +			parent = ACPI_ADD_PTR(struct acpi_iort_node,
>> +					iort_table,  map->output_reference);
>> +			/*
>> +			 * If we detect a RC->SMMU mapping, make sure
>> +			 * we enable ACS on the system.
>> +			 */
>> +			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
>> +				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
>> +				pci_request_acs();
>> +				return true;
>> +			}
>> +		}
>> +	}
>> +
>> +	return false;
>> +}
>> +
>>   static void __init iort_init_platform_devices(void)
>>   {
>>   	struct acpi_iort_node *iort_node, *iort_end;
>>   	struct acpi_table_iort *iort;
>>   	struct fwnode_handle *fwnode;
>>   	int i, ret;
>> +	bool acs_enabled = false;
>>   
>>   	/*
>>   	 * iort_table and iort both point to the start of IORT table, but
>> @@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
>>   			return;
>>   		}
>>   
>> +		if (!acs_enabled)
>> +			acs_enabled = iort_enable_acs(iort_node);
>> +
>>   		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
>>   			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
>>   
>> -- 
>> 2.4.12
>>

-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-03 19:08     ` Nate Watterson
  0 siblings, 0 replies; 21+ messages in thread
From: Nate Watterson @ 2017-10-03 19:08 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Lorenzo,

On 10/3/2017 8:48 AM, Lorenzo Pieralisi wrote:
> [+Nate]
> 
> Zhou, Nate,
> 
> On Mon, Oct 02, 2017 at 06:28:44PM +0100, Lorenzo Pieralisi wrote:
>> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
>> workarounds") removed kernel code that was allowing to initialize
>> and probe the SMMU devices early (ie earlier than PCI devices, through
>> linker script callback entries) in the boot process because it was not
>> needed any longer in that the SMMU devices/drivers now support deferred
>> probing.
>>
>> Since the SMMUs probe routines are also in charge of requesting global
>> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
>> up early-probing workarounds") also postponed PCI ACS enablement to
>> SMMUs devices probe time, which is too late given that PCI devices needs
>> to detect if PCI ACS is enabled to init the respective capability
>> through the following call path:
>>
>> pci_device_add()
>>   -> pci_init_capabilities()
>>    -> pci_enable_acs()
>>
>> Add code in the ACPI IORT SMMU platform devices initialization path
>> (that is called before ACPI PCI enumeration) to detect if there
>> exists firmware mappings to map root complexes ids to SMMU ids
>> and if so enable ACS for the system.
>>
>> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
>> Signed-workarounds")
>> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>> Cc: Will Deacon <will.deacon@arm.com>
>> Cc: Hanjun Guo <hanjun.guo@linaro.org>
>> Cc: Sudeep Holla <sudeep.holla@arm.com>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Robin Murphy <robin.murphy@arm.com>
>> Cc: Zhou Wang <wangzhou1@hisilicon.com>
>> Cc: Alex Williamson <alex.williamson@redhat.com>
>> ---
>> v1 -> v2:
>>
>> - Reworked ACS enablement logic and based on root complex to SMMU
>>    ids firmware mapping detection
>> - Rebased against v4.14-rc3
>>
>> v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
>>
>>   drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
>>   1 file changed, 35 insertions(+)
> 
> I have reworked the enablement logic wrt v1, dou you mind testing it
> please, I would like to get it merged since I have 4.15 patches depending
> on it.

I tested with and without RC->SMMU mappings defined in the IORT and
observed the expected value for pci_acs_enable in both cases.

Tested-by: Nate Watterson <nwatters@codeaurora.org>

Thanks,
Nate

> 
> Thanks,
> Lorenzo
> 
>> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
>> index 9565d57..de56394 100644
>> --- a/drivers/acpi/arm64/iort.c
>> +++ b/drivers/acpi/arm64/iort.c
>> @@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
>>   	return ret;
>>   }
>>   
>> +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
>> +{
>> +	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
>> +		struct acpi_iort_node *parent;
>> +		struct acpi_iort_id_mapping *map;
>> +		int i;
>> +
>> +		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
>> +				   iort_node->mapping_offset);
>> +
>> +		for (i = 0; i < iort_node->mapping_count; i++, map++) {
>> +			if (!map->output_reference)
>> +				continue;
>> +
>> +			parent = ACPI_ADD_PTR(struct acpi_iort_node,
>> +					iort_table,  map->output_reference);
>> +			/*
>> +			 * If we detect a RC->SMMU mapping, make sure
>> +			 * we enable ACS on the system.
>> +			 */
>> +			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
>> +				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
>> +				pci_request_acs();
>> +				return true;
>> +			}
>> +		}
>> +	}
>> +
>> +	return false;
>> +}
>> +
>>   static void __init iort_init_platform_devices(void)
>>   {
>>   	struct acpi_iort_node *iort_node, *iort_end;
>>   	struct acpi_table_iort *iort;
>>   	struct fwnode_handle *fwnode;
>>   	int i, ret;
>> +	bool acs_enabled = false;
>>   
>>   	/*
>>   	 * iort_table and iort both point to the start of IORT table, but
>> @@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
>>   			return;
>>   		}
>>   
>> +		if (!acs_enabled)
>> +			acs_enabled = iort_enable_acs(iort_node);
>> +
>>   		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
>>   			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
>>   
>> -- 
>> 2.4.12
>>

-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
  2017-10-02 17:28 ` Lorenzo Pieralisi
  (?)
@ 2017-10-04 16:36   ` Catalin Marinas
  -1 siblings, 0 replies; 21+ messages in thread
From: Catalin Marinas @ 2017-10-04 16:36 UTC (permalink / raw)
  To: Lorenzo Pieralisi
  Cc: linux-acpi, linux-pci, Will Deacon, Alex Williamson, Zhou Wang,
	Hanjun Guo, Sudeep Holla, Robin Murphy, linux-arm-kernel

On Mon, Oct 02, 2017 at 06:28:44PM +0100, Lorenzo Pieralisi wrote:
> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> workarounds") removed kernel code that was allowing to initialize
> and probe the SMMU devices early (ie earlier than PCI devices, through
> linker script callback entries) in the boot process because it was not
> needed any longer in that the SMMU devices/drivers now support deferred
> probing.
> 
> Since the SMMUs probe routines are also in charge of requesting global
> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> up early-probing workarounds") also postponed PCI ACS enablement to
> SMMUs devices probe time, which is too late given that PCI devices needs
> to detect if PCI ACS is enabled to init the respective capability
> through the following call path:
> 
> pci_device_add()
>  -> pci_init_capabilities()
>   -> pci_enable_acs()
> 
> Add code in the ACPI IORT SMMU platform devices initialization path
> (that is called before ACPI PCI enumeration) to detect if there
> exists firmware mappings to map root complexes ids to SMMU ids
> and if so enable ACS for the system.
> 
> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> Signed-workarounds")
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Hanjun Guo <hanjun.guo@linaro.org>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Alex Williamson <alex.williamson@redhat.com>

Queued for 4.14-rc4. Thanks.

-- 
Catalin

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-04 16:36   ` Catalin Marinas
  0 siblings, 0 replies; 21+ messages in thread
From: Catalin Marinas @ 2017-10-04 16:36 UTC (permalink / raw)
  To: Lorenzo Pieralisi
  Cc: linux-pci, Will Deacon, Zhou Wang, linux-acpi, Alex Williamson,
	Hanjun Guo, Sudeep Holla, Robin Murphy, linux-arm-kernel

On Mon, Oct 02, 2017 at 06:28:44PM +0100, Lorenzo Pieralisi wrote:
> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> workarounds") removed kernel code that was allowing to initialize
> and probe the SMMU devices early (ie earlier than PCI devices, through
> linker script callback entries) in the boot process because it was not
> needed any longer in that the SMMU devices/drivers now support deferred
> probing.
> 
> Since the SMMUs probe routines are also in charge of requesting global
> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> up early-probing workarounds") also postponed PCI ACS enablement to
> SMMUs devices probe time, which is too late given that PCI devices needs
> to detect if PCI ACS is enabled to init the respective capability
> through the following call path:
> 
> pci_device_add()
>  -> pci_init_capabilities()
>   -> pci_enable_acs()
> 
> Add code in the ACPI IORT SMMU platform devices initialization path
> (that is called before ACPI PCI enumeration) to detect if there
> exists firmware mappings to map root complexes ids to SMMU ids
> and if so enable ACS for the system.
> 
> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> Signed-workarounds")
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Hanjun Guo <hanjun.guo@linaro.org>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Alex Williamson <alex.williamson@redhat.com>

Queued for 4.14-rc4. Thanks.

-- 
Catalin

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-04 16:36   ` Catalin Marinas
  0 siblings, 0 replies; 21+ messages in thread
From: Catalin Marinas @ 2017-10-04 16:36 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Oct 02, 2017 at 06:28:44PM +0100, Lorenzo Pieralisi wrote:
> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> workarounds") removed kernel code that was allowing to initialize
> and probe the SMMU devices early (ie earlier than PCI devices, through
> linker script callback entries) in the boot process because it was not
> needed any longer in that the SMMU devices/drivers now support deferred
> probing.
> 
> Since the SMMUs probe routines are also in charge of requesting global
> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
> up early-probing workarounds") also postponed PCI ACS enablement to
> SMMUs devices probe time, which is too late given that PCI devices needs
> to detect if PCI ACS is enabled to init the respective capability
> through the following call path:
> 
> pci_device_add()
>  -> pci_init_capabilities()
>   -> pci_enable_acs()
> 
> Add code in the ACPI IORT SMMU platform devices initialization path
> (that is called before ACPI PCI enumeration) to detect if there
> exists firmware mappings to map root complexes ids to SMMU ids
> and if so enable ACS for the system.
> 
> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
> Signed-workarounds")
> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Hanjun Guo <hanjun.guo@linaro.org>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Zhou Wang <wangzhou1@hisilicon.com>
> Cc: Alex Williamson <alex.williamson@redhat.com>

Queued for 4.14-rc4. Thanks.

-- 
Catalin

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
  2017-10-03 12:48   ` Lorenzo Pieralisi
  (?)
@ 2017-10-09  8:40     ` Zhou Wang
  -1 siblings, 0 replies; 21+ messages in thread
From: Zhou Wang @ 2017-10-09  8:40 UTC (permalink / raw)
  To: Lorenzo Pieralisi, linux-acpi, nwatters
  Cc: Catalin Marinas, Sudeep Holla, Will Deacon, Alex Williamson,
	Hanjun Guo, linux-pci, Robin Murphy, linux-arm-kernel

On 2017/10/3 20:48, Lorenzo Pieralisi wrote:
> [+Nate]
> 
> Zhou, Nate,
> 
> On Mon, Oct 02, 2017 at 06:28:44PM +0100, Lorenzo Pieralisi wrote:
>> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
>> workarounds") removed kernel code that was allowing to initialize
>> and probe the SMMU devices early (ie earlier than PCI devices, through
>> linker script callback entries) in the boot process because it was not
>> needed any longer in that the SMMU devices/drivers now support deferred
>> probing.
>>
>> Since the SMMUs probe routines are also in charge of requesting global
>> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
>> up early-probing workarounds") also postponed PCI ACS enablement to
>> SMMUs devices probe time, which is too late given that PCI devices needs
>> to detect if PCI ACS is enabled to init the respective capability
>> through the following call path:
>>
>> pci_device_add()
>>  -> pci_init_capabilities()
>>   -> pci_enable_acs()
>>
>> Add code in the ACPI IORT SMMU platform devices initialization path
>> (that is called before ACPI PCI enumeration) to detect if there
>> exists firmware mappings to map root complexes ids to SMMU ids
>> and if so enable ACS for the system.
>>
>> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
>> Signed-workarounds")
>> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>> Cc: Will Deacon <will.deacon@arm.com>
>> Cc: Hanjun Guo <hanjun.guo@linaro.org>
>> Cc: Sudeep Holla <sudeep.holla@arm.com>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Robin Murphy <robin.murphy@arm.com>
>> Cc: Zhou Wang <wangzhou1@hisilicon.com>
>> Cc: Alex Williamson <alex.williamson@redhat.com>
>> ---
>> v1 -> v2:
>>
>> - Reworked ACS enablement logic and based on root complex to SMMU
>>   ids firmware mapping detection
>> - Rebased against v4.14-rc3
>>
>> v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
>>
>>  drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
>>  1 file changed, 35 insertions(+)
> 
> I have reworked the enablement logic wrt v1, dou you mind testing it
> please, I would like to get it merged since I have 4.15 patches depending
> on it.

Hi Lorenzo,

Sorry for late, I was in my National Day holiday.

I tested this patch in HiSilicon Hip08 based board, it works well in RC->SMMU->ITS and
RC->ITS maps.

Tested-by: Zhou Wang <wangzhou1@hisilicon.com>

Thanks,
Zhou

> 
> Thanks,
> Lorenzo
> 
>> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
>> index 9565d57..de56394 100644
>> --- a/drivers/acpi/arm64/iort.c
>> +++ b/drivers/acpi/arm64/iort.c
>> @@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
>>  	return ret;
>>  }
>>  
>> +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
>> +{
>> +	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
>> +		struct acpi_iort_node *parent;
>> +		struct acpi_iort_id_mapping *map;
>> +		int i;
>> +
>> +		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
>> +				   iort_node->mapping_offset);
>> +
>> +		for (i = 0; i < iort_node->mapping_count; i++, map++) {
>> +			if (!map->output_reference)
>> +				continue;
>> +
>> +			parent = ACPI_ADD_PTR(struct acpi_iort_node,
>> +					iort_table,  map->output_reference);
>> +			/*
>> +			 * If we detect a RC->SMMU mapping, make sure
>> +			 * we enable ACS on the system.
>> +			 */
>> +			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
>> +				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
>> +				pci_request_acs();
>> +				return true;
>> +			}
>> +		}
>> +	}
>> +
>> +	return false;
>> +}
>> +
>>  static void __init iort_init_platform_devices(void)
>>  {
>>  	struct acpi_iort_node *iort_node, *iort_end;
>>  	struct acpi_table_iort *iort;
>>  	struct fwnode_handle *fwnode;
>>  	int i, ret;
>> +	bool acs_enabled = false;
>>  
>>  	/*
>>  	 * iort_table and iort both point to the start of IORT table, but
>> @@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
>>  			return;
>>  		}
>>  
>> +		if (!acs_enabled)
>> +			acs_enabled = iort_enable_acs(iort_node);
>> +
>>  		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
>>  			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
>>  
>> -- 
>> 2.4.12
>>
> 
> .
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-09  8:40     ` Zhou Wang
  0 siblings, 0 replies; 21+ messages in thread
From: Zhou Wang @ 2017-10-09  8:40 UTC (permalink / raw)
  To: Lorenzo Pieralisi, linux-acpi, nwatters
  Cc: Catalin Marinas, Sudeep Holla, Will Deacon, Alex Williamson,
	Hanjun Guo, linux-pci, Robin Murphy, linux-arm-kernel

On 2017/10/3 20:48, Lorenzo Pieralisi wrote:
> [+Nate]
> 
> Zhou, Nate,
> 
> On Mon, Oct 02, 2017 at 06:28:44PM +0100, Lorenzo Pieralisi wrote:
>> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
>> workarounds") removed kernel code that was allowing to initialize
>> and probe the SMMU devices early (ie earlier than PCI devices, through
>> linker script callback entries) in the boot process because it was not
>> needed any longer in that the SMMU devices/drivers now support deferred
>> probing.
>>
>> Since the SMMUs probe routines are also in charge of requesting global
>> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
>> up early-probing workarounds") also postponed PCI ACS enablement to
>> SMMUs devices probe time, which is too late given that PCI devices needs
>> to detect if PCI ACS is enabled to init the respective capability
>> through the following call path:
>>
>> pci_device_add()
>>  -> pci_init_capabilities()
>>   -> pci_enable_acs()
>>
>> Add code in the ACPI IORT SMMU platform devices initialization path
>> (that is called before ACPI PCI enumeration) to detect if there
>> exists firmware mappings to map root complexes ids to SMMU ids
>> and if so enable ACS for the system.
>>
>> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
>> Signed-workarounds")
>> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>> Cc: Will Deacon <will.deacon@arm.com>
>> Cc: Hanjun Guo <hanjun.guo@linaro.org>
>> Cc: Sudeep Holla <sudeep.holla@arm.com>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Robin Murphy <robin.murphy@arm.com>
>> Cc: Zhou Wang <wangzhou1@hisilicon.com>
>> Cc: Alex Williamson <alex.williamson@redhat.com>
>> ---
>> v1 -> v2:
>>
>> - Reworked ACS enablement logic and based on root complex to SMMU
>>   ids firmware mapping detection
>> - Rebased against v4.14-rc3
>>
>> v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
>>
>>  drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
>>  1 file changed, 35 insertions(+)
> 
> I have reworked the enablement logic wrt v1, dou you mind testing it
> please, I would like to get it merged since I have 4.15 patches depending
> on it.

Hi Lorenzo,

Sorry for late, I was in my National Day holiday.

I tested this patch in HiSilicon Hip08 based board, it works well in RC->SMMU->ITS and
RC->ITS maps.

Tested-by: Zhou Wang <wangzhou1@hisilicon.com>

Thanks,
Zhou

> 
> Thanks,
> Lorenzo
> 
>> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
>> index 9565d57..de56394 100644
>> --- a/drivers/acpi/arm64/iort.c
>> +++ b/drivers/acpi/arm64/iort.c
>> @@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
>>  	return ret;
>>  }
>>  
>> +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
>> +{
>> +	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
>> +		struct acpi_iort_node *parent;
>> +		struct acpi_iort_id_mapping *map;
>> +		int i;
>> +
>> +		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
>> +				   iort_node->mapping_offset);
>> +
>> +		for (i = 0; i < iort_node->mapping_count; i++, map++) {
>> +			if (!map->output_reference)
>> +				continue;
>> +
>> +			parent = ACPI_ADD_PTR(struct acpi_iort_node,
>> +					iort_table,  map->output_reference);
>> +			/*
>> +			 * If we detect a RC->SMMU mapping, make sure
>> +			 * we enable ACS on the system.
>> +			 */
>> +			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
>> +				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
>> +				pci_request_acs();
>> +				return true;
>> +			}
>> +		}
>> +	}
>> +
>> +	return false;
>> +}
>> +
>>  static void __init iort_init_platform_devices(void)
>>  {
>>  	struct acpi_iort_node *iort_node, *iort_end;
>>  	struct acpi_table_iort *iort;
>>  	struct fwnode_handle *fwnode;
>>  	int i, ret;
>> +	bool acs_enabled = false;
>>  
>>  	/*
>>  	 * iort_table and iort both point to the start of IORT table, but
>> @@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
>>  			return;
>>  		}
>>  
>> +		if (!acs_enabled)
>> +			acs_enabled = iort_enable_acs(iort_node);
>> +
>>  		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
>>  			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
>>  
>> -- 
>> 2.4.12
>>
> 
> .
> 


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2] ACPI/IORT: Fix PCI ACS enablement
@ 2017-10-09  8:40     ` Zhou Wang
  0 siblings, 0 replies; 21+ messages in thread
From: Zhou Wang @ 2017-10-09  8:40 UTC (permalink / raw)
  To: linux-arm-kernel

On 2017/10/3 20:48, Lorenzo Pieralisi wrote:
> [+Nate]
> 
> Zhou, Nate,
> 
> On Mon, Oct 02, 2017 at 06:28:44PM +0100, Lorenzo Pieralisi wrote:
>> commit f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
>> workarounds") removed kernel code that was allowing to initialize
>> and probe the SMMU devices early (ie earlier than PCI devices, through
>> linker script callback entries) in the boot process because it was not
>> needed any longer in that the SMMU devices/drivers now support deferred
>> probing.
>>
>> Since the SMMUs probe routines are also in charge of requesting global
>> PCI ACS kernel enablement, commit f6810c15cf97 ("iommu/arm-smmu: Clean
>> up early-probing workarounds") also postponed PCI ACS enablement to
>> SMMUs devices probe time, which is too late given that PCI devices needs
>> to detect if PCI ACS is enabled to init the respective capability
>> through the following call path:
>>
>> pci_device_add()
>>  -> pci_init_capabilities()
>>   -> pci_enable_acs()
>>
>> Add code in the ACPI IORT SMMU platform devices initialization path
>> (that is called before ACPI PCI enumeration) to detect if there
>> exists firmware mappings to map root complexes ids to SMMU ids
>> and if so enable ACS for the system.
>>
>> Fixes: f6810c15cf97 ("iommu/arm-smmu: Clean up early-probing
>> Signed-workarounds")
>> Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
>> Cc: Will Deacon <will.deacon@arm.com>
>> Cc: Hanjun Guo <hanjun.guo@linaro.org>
>> Cc: Sudeep Holla <sudeep.holla@arm.com>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Robin Murphy <robin.murphy@arm.com>
>> Cc: Zhou Wang <wangzhou1@hisilicon.com>
>> Cc: Alex Williamson <alex.williamson@redhat.com>
>> ---
>> v1 -> v2:
>>
>> - Reworked ACS enablement logic and based on root complex to SMMU
>>   ids firmware mapping detection
>> - Rebased against v4.14-rc3
>>
>> v1: https://marc.info/?l=linux-acpi&m=150584059818925&w=2
>>
>>  drivers/acpi/arm64/iort.c | 35 +++++++++++++++++++++++++++++++++++
>>  1 file changed, 35 insertions(+)
> 
> I have reworked the enablement logic wrt v1, dou you mind testing it
> please, I would like to get it merged since I have 4.15 patches depending
> on it.

Hi Lorenzo,

Sorry for late, I was in my National Day holiday.

I tested this patch in HiSilicon Hip08 based board, it works well in RC->SMMU->ITS and
RC->ITS maps.

Tested-by: Zhou Wang <wangzhou1@hisilicon.com>

Thanks,
Zhou

> 
> Thanks,
> Lorenzo
> 
>> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
>> index 9565d57..de56394 100644
>> --- a/drivers/acpi/arm64/iort.c
>> +++ b/drivers/acpi/arm64/iort.c
>> @@ -1178,12 +1178,44 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node)
>>  	return ret;
>>  }
>>  
>> +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node)
>> +{
>> +	if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
>> +		struct acpi_iort_node *parent;
>> +		struct acpi_iort_id_mapping *map;
>> +		int i;
>> +
>> +		map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node,
>> +				   iort_node->mapping_offset);
>> +
>> +		for (i = 0; i < iort_node->mapping_count; i++, map++) {
>> +			if (!map->output_reference)
>> +				continue;
>> +
>> +			parent = ACPI_ADD_PTR(struct acpi_iort_node,
>> +					iort_table,  map->output_reference);
>> +			/*
>> +			 * If we detect a RC->SMMU mapping, make sure
>> +			 * we enable ACS on the system.
>> +			 */
>> +			if ((parent->type == ACPI_IORT_NODE_SMMU) ||
>> +				(parent->type == ACPI_IORT_NODE_SMMU_V3)) {
>> +				pci_request_acs();
>> +				return true;
>> +			}
>> +		}
>> +	}
>> +
>> +	return false;
>> +}
>> +
>>  static void __init iort_init_platform_devices(void)
>>  {
>>  	struct acpi_iort_node *iort_node, *iort_end;
>>  	struct acpi_table_iort *iort;
>>  	struct fwnode_handle *fwnode;
>>  	int i, ret;
>> +	bool acs_enabled = false;
>>  
>>  	/*
>>  	 * iort_table and iort both point to the start of IORT table, but
>> @@ -1203,6 +1235,9 @@ static void __init iort_init_platform_devices(void)
>>  			return;
>>  		}
>>  
>> +		if (!acs_enabled)
>> +			acs_enabled = iort_enable_acs(iort_node);
>> +
>>  		if ((iort_node->type == ACPI_IORT_NODE_SMMU) ||
>>  			(iort_node->type == ACPI_IORT_NODE_SMMU_V3)) {
>>  
>> -- 
>> 2.4.12
>>
> 
> .
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2017-10-09  8:40 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-02 17:28 [PATCH v2] ACPI/IORT: Fix PCI ACS enablement Lorenzo Pieralisi
2017-10-02 17:28 ` Lorenzo Pieralisi
2017-10-03 12:48 ` Lorenzo Pieralisi
2017-10-03 12:48   ` Lorenzo Pieralisi
2017-10-03 12:48   ` Lorenzo Pieralisi
2017-10-03 19:08   ` Nate Watterson
2017-10-03 19:08     ` Nate Watterson
2017-10-09  8:40   ` Zhou Wang
2017-10-09  8:40     ` Zhou Wang
2017-10-09  8:40     ` Zhou Wang
2017-10-03 13:47 ` Robin Murphy
2017-10-03 13:47   ` Robin Murphy
2017-10-03 14:45 ` John Garry
2017-10-03 14:45   ` John Garry
2017-10-03 14:45   ` John Garry
2017-10-03 16:53   ` Lorenzo Pieralisi
2017-10-03 16:53     ` Lorenzo Pieralisi
2017-10-03 16:53     ` Lorenzo Pieralisi
2017-10-04 16:36 ` Catalin Marinas
2017-10-04 16:36   ` Catalin Marinas
2017-10-04 16:36   ` Catalin Marinas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.