Skip to contentSkip to conversation

iommu/arm-smmu: Split pagetable support for Adreno GPUs

PATCH Superseded Jordan Crouse 4 participants 12 messages Aug 20, 2019 – Sep 17, 2019

Subsystems (7)

v1 of 19 Superseded Latest is v19 →

lore
Share & tools
lore
#0 lore raw

cover iommu/arm-smmu: Split pagetable support for Adreno GPUs

This is another iteration to support split pagetables for Adreno GPUs as part of an incremental process to enable per-context pagetables.

In order to support per-context pagetables the GPU needs to enable split pagetables so that we can store the global buffers in the TTBR1 space leaving the GPU free to program the TTBR0 register with the page address of a context specific pt.

Previous revisions of this series can be found at [1] and [2].

This iteration is built on top of the arm-smmu-impl and arm-smmu-v2 rework code from Robin Murphy [3] and [4].

This code is based on the realization that when split pagetables are enabled the configuration for the T1 address space is identical to that of the T0 space, so we can just take the TCR configuration provided by io-pgtable, duplicate it and shift it by 16 bits.

Since the current split pagetable implementation is specific to the Adreno GPUs we can also take a small shortcut and only allow split pagetables for SMMUs with a 49 bit upstream bus which allows us to use the default configuration for the sign extension bit and we can avoid a lot of extra code to handle different upstream bus sizes that will never get used.

The first patch implements the split pagetable support for arm-smmu-v2.

The second adds a SMMU model for the Adreno GPU SMMU and enables the split pagetables if conditions warrant.

The 3rd and 4th patches add a domain attribute to query the status of split pagetables.

The remaining patches modify drm/msm slightly to allow a6xx targets to recognize if split pagetables are enabled and adjust the address space accordingly.

This series only includes support for split pagetables because I wanted to get this out for discussion and I haven't ported over the aux domain code to this kernel version, but I don't suspect it will end up being much different than previous versions [5].

[1] https://patchwork.freedesktop.org/series/63403/
[2] https://patchwork.freedesktop.org/series/64874/
[3] https://lists.linuxfoundation.org/pipermail/iommu/2019-August/037905.html
[4] https://lists.linuxfoundation.org/pipermail/iommu/2019-August/038244.html
[5] https://patchwork.freedesktop.org/patch/307601/

Jordan Crouse (7):
iommu/arm-smmu: Support split pagetables
dt-bindings: arm-smmu: Add Adreno GPU variant iommu/arm-smmu: Add a SMMU variant for the Adreno GPU
iommu: Add DOMAIN_ATTR_SPLIT_TABLES
iommu/arm-smmu: Support DOMAIN_ATTR_SPLIT_TABLES drm/msm: Create the msm_mmu object independently from the address
space
drm/msm: Use per-target functions to set up address spaces

 .../devicetree/bindings/iommu/arm,smmu.txt         |  7 +++
 drivers/gpu/drm/msm/adreno/a2xx_gpu.c              | 28 +++++++++++
 drivers/gpu/drm/msm/adreno/a3xx_gpu.c              |  1 +
 drivers/gpu/drm/msm/adreno/a4xx_gpu.c              |  1 +
 drivers/gpu/drm/msm/adreno/a5xx_gpu.c              |  1 +
 drivers/gpu/drm/msm/adreno/a6xx_gpu.c              | 56 ++++++++++++++++++++++
 drivers/gpu/drm/msm/adreno/adreno_gpu.c            | 43 ++++++++++++++---
 drivers/gpu/drm/msm/adreno/adreno_gpu.h            |  5 ++
 drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c            | 16 ++++---
 drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c           | 16 ++++---
 drivers/gpu/drm/msm/disp/mdp5/mdp5_cfg.c           |  4 --
 drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c           | 13 ++++-
 drivers/gpu/drm/msm/msm_drv.h                      |  8 +---
 drivers/gpu/drm/msm/msm_gem_vma.c                  | 30 ++----------
 drivers/gpu/drm/msm/msm_gpu.c                      | 51 ++------------------
 drivers/gpu/drm/msm/msm_gpu.h                      |  4 +-
 drivers/iommu/arm-smmu-impl.c                      | 15 ++++++
 drivers/iommu/arm-smmu.c                           | 46 ++++++++++++++++--
 drivers/iommu/arm-smmu.h                           |  2 +
 include/linux/iommu.h                              |  1 +
 20 files changed, 237 insertions(+), 111 deletions(-)
Signature · 6 lines
2.7.4

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
#2 lore raw

PATCH 2/7 dt-bindings: arm-smmu: Add Adreno GPU variant

Add a compatible string to identify SMMUs that are attached to Adreno GPU devices that wish to support split pagetables.

---

 Documentation/devicetree/bindings/iommu/arm,smmu.txt | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/iommu/arm,smmu.txt +7 -0
index 3133f3b..3b07896 100644
@@ -18,6 +18,7 @@ conditions.
                         "arm,mmu-500"
                         "cavium,smmu-v2"
                         "qcom,smmu-v2"
+			"qcom,adreno-smmu-v2"
 
                   depending on the particular implementation and/or the
                   version of the architecture implemented.
@@ -31,6 +32,12 @@ conditions.
                   as below, SoC-specific compatibles:
                   "qcom,sdm845-smmu-500", "arm,mmu-500"
 
+		  "qcom,adreno-smmu-v2" is a special implementation for
+		  SMMU devices attached to the Adreno GPU on Qcom devices.
+		  If selected, this will enable split pagetable (TTBR1)
+		  support. Only use this if the GPU target is capable of
+		  supporting 64 bit addresses.
+
 - reg           : Base address and size of the SMMU.
 
 - #global-interrupts : The number of global interrupts exposed by the
Signature · 1 line
2.7.4
#10 lore raw

PATCH 6/7 drm/msm: Create the msm_mmu object independently from the address space

In reply to Jordan Crouse

Instead of creating the msm_mmu object along with the address space initialize it separately and pass it into the address space create function. This gives us the flexibility of attaching the IOMMU device and querying it before creating the address space which will come in handy in the next patch that takes advantage of split pagetables if available.

---

 drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c  | 16 ++++++++++------
 drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 16 ++++++++++------
 drivers/gpu/drm/msm/disp/mdp5/mdp5_cfg.c |  4 ----
 drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c | 13 +++++++++++--
 drivers/gpu/drm/msm/msm_drv.h            |  8 ++------
 drivers/gpu/drm/msm/msm_gem_vma.c        | 30 +++---------------------------
 drivers/gpu/drm/msm/msm_gpu.c            | 19 ++++++++++++-------
 7 files changed, 48 insertions(+), 58 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c +10 -6
index bb9d44e..8bf2639 100644
@@ -722,23 +722,27 @@ static int _dpu_kms_mmu_init(struct dpu_kms *dpu_kms)
 {
 	struct iommu_domain *domain;
 	struct msm_gem_address_space *aspace;
+	struct msm_mmu *mmu;
 	int ret;
 
 	domain = iommu_domain_alloc(&platform_bus_type);
 	if (!domain)
 		return 0;
 
-	domain->geometry.aperture_start = 0x1000;
-	domain->geometry.aperture_end = 0xffffffff;
+	mmu = msm_iommu_new(dpu_kms->dev->dev, domain);
+	if (IS_ERR(mmu)) {
+		iommu_domain_free(domain);
+		return PTR_ERR(mmu);
+	}
 
-	aspace = msm_gem_address_space_create(dpu_kms->dev->dev,
-			domain, "dpu1");
+	aspace = msm_gem_address_space_create(mmu, "dpu1",
+		0x1000, 0xffffffff);
 	if (IS_ERR(aspace)) {
-		iommu_domain_free(domain);
+		mmu->funcs->destroy(mmu);
 		return PTR_ERR(aspace);
 	}
 
-	ret = aspace->mmu->funcs->attach(aspace->mmu, iommu_ports,
+	ret = mmu->funcs->attach(mmu, iommu_ports,
 			ARRAY_SIZE(iommu_ports));
 	if (ret) {
 		DPU_ERROR("failed to attach iommu %d\n", ret);
drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c +10 -6
index 7a9ab55..af5a7a4 100644
@@ -498,9 +498,17 @@ struct msm_kms *mdp4_kms_init(struct drm_device *dev)
 	mdelay(16);
 
 	if (config->iommu) {
-		aspace = msm_gem_address_space_create(&pdev->dev,
-				config->iommu, "mdp4");
+		struct msm_mmu *mmu = msm_iommu_new(&pdev->dev, config->iommu);
+
+		if (IS_ERR(mmu)) {
+			ret = PTR_ERR(mmu);
+			goto fail;
+		}
+
+		aspace = msm_gem_address_space_create(mmu, "mdp4",
+			0x1000, 0xfffffffff);
 		if (IS_ERR(aspace)) {
+			mmu->funcs->destroy(mmu);
 			ret = PTR_ERR(aspace);
 			goto fail;
 		}
@@ -558,10 +566,6 @@ static struct mdp4_platform_config *mdp4_get_config(struct platform_device *dev)
 	/* TODO: Chips that aren't apq8064 have a 200 Mhz max_clk */
 	config.max_clk = 266667000;
 	config.iommu = iommu_domain_alloc(&platform_bus_type);
-	if (config.iommu) {
-		config.iommu->geometry.aperture_start = 0x1000;
-		config.iommu->geometry.aperture_end = 0xffffffff;
-	}
 
 	return &config;
 }
drivers/gpu/drm/msm/disp/mdp5/mdp5_cfg.c +0 -4
index dd1daf0..23265f7 100644
@@ -721,10 +721,6 @@ static struct mdp5_cfg_platform *mdp5_get_config(struct platform_device *dev)
 	static struct mdp5_cfg_platform config = {};
 
 	config.iommu = iommu_domain_alloc(&platform_bus_type);
-	if (config.iommu) {
-		config.iommu->geometry.aperture_start = 0x1000;
-		config.iommu->geometry.aperture_end = 0xffffffff;
-	}
 
 	return &config;
 }
drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c +11 -2
index 4a60f5f..36115fd 100644
@@ -702,9 +702,18 @@ struct msm_kms *mdp5_kms_init(struct drm_device *dev)
 	mdelay(16);
 
 	if (config->platform.iommu) {
-		aspace = msm_gem_address_space_create(&pdev->dev,
-				config->platform.iommu, "mdp5");
+		struct msm_mmu *mmu = msm_iommu_new(&pdev->dev,
+			config->platform.iommu);
+
+		if (IS_ERR(mmu)) {
+			ret = PTR_ERR(mmu);
+			goto fail;
+		}
+
+		aspace = msm_gem_address_space_create(mmu, "mdp5",
+			0x1000, 0xffffffff);
 		if (IS_ERR(aspace)) {
+			mmu->funcs->destroy(mmu);
 			ret = PTR_ERR(aspace);
 			goto fail;
 		}
drivers/gpu/drm/msm/msm_drv.h +2 -6
index ee7b512..c2502b2 100644
@@ -244,12 +244,8 @@ void msm_gem_close_vma(struct msm_gem_address_space *aspace,
 void msm_gem_address_space_put(struct msm_gem_address_space *aspace);
 
 struct msm_gem_address_space *
-msm_gem_address_space_create(struct device *dev, struct iommu_domain *domain,
-		const char *name);
-
-struct msm_gem_address_space *
-msm_gem_address_space_create_a2xx(struct device *dev, struct msm_gpu *gpu,
-		const char *name, uint64_t va_start, uint64_t va_end);
+msm_gem_address_space_create(struct msm_mmu *mmu, const char *name,
+		u64 va_start, u64 va_end);
 
 int msm_register_mmu(struct drm_device *dev, struct msm_mmu *mmu);
 void msm_unregister_mmu(struct drm_device *dev, struct msm_mmu *mmu);
drivers/gpu/drm/msm/msm_gem_vma.c +3 -27
index 1af5354..45d4a63 100644
@@ -127,32 +127,8 @@ int msm_gem_init_vma(struct msm_gem_address_space *aspace,
 
 
 struct msm_gem_address_space *
-msm_gem_address_space_create(struct device *dev, struct iommu_domain *domain,
-		const char *name)
-{
-	struct msm_gem_address_space *aspace;
-	u64 size = domain->geometry.aperture_end -
-		domain->geometry.aperture_start;
-
-	aspace = kzalloc(sizeof(*aspace), GFP_KERNEL);
-	if (!aspace)
-		return ERR_PTR(-ENOMEM);
-
-	spin_lock_init(&aspace->lock);
-	aspace->name = name;
-	aspace->mmu = msm_iommu_new(dev, domain);
-
-	drm_mm_init(&aspace->mm, (domain->geometry.aperture_start >> PAGE_SHIFT),
-		size >> PAGE_SHIFT);
-
-	kref_init(&aspace->kref);
-
-	return aspace;
-}
-
-struct msm_gem_address_space *
-msm_gem_address_space_create_a2xx(struct device *dev, struct msm_gpu *gpu,
-		const char *name, uint64_t va_start, uint64_t va_end)
+msm_gem_address_space_create(struct msm_mmu *mmu, const char *name,
+		u64 va_start, u64 va_end)
 {
 	struct msm_gem_address_space *aspace;
 	u64 size = va_end - va_start;
@@ -163,7 +139,7 @@ msm_gem_address_space_create_a2xx(struct device *dev, struct msm_gpu *gpu,
 
 	spin_lock_init(&aspace->lock);
 	aspace->name = name;
-	aspace->mmu = msm_gpummu_new(dev, gpu);
+	aspace->mmu = mmu;
 
 	drm_mm_init(&aspace->mm, (va_start >> PAGE_SHIFT),
 		size >> PAGE_SHIFT);
drivers/gpu/drm/msm/msm_gpu.c +12 -7
index 4edb874..9271f39 100644
@@ -806,6 +806,7 @@ msm_gpu_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev,
 		uint64_t va_start, uint64_t va_end)
 {
 	struct msm_gem_address_space *aspace;
+	struct msm_mmu *mmu;
 	int ret;
 
 	/*
@@ -818,20 +819,24 @@ msm_gpu_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev,
 		if (!iommu)
 			return NULL;
 
-		iommu->geometry.aperture_start = va_start;
-		iommu->geometry.aperture_end = va_end;
+		mmu = msm_iommu_new(&pdev->dev, iommu);
+		if (IS_ERR(mmu)) {
+			iommu_domain_free(iommu);
+			return ERR_CAST(mmu);
+		}
 
 		DRM_DEV_INFO(gpu->dev->dev, "%s: using IOMMU\n", gpu->name);
 
-		aspace = msm_gem_address_space_create(&pdev->dev, iommu, "gpu");
-		if (IS_ERR(aspace))
-			iommu_domain_free(iommu);
 	} else {
-		aspace = msm_gem_address_space_create_a2xx(&pdev->dev, gpu, "gpu",
-			va_start, va_end);
+		mmu = msm_gpummu_new(&pdev->dev, gpu);
+		if (IS_ERR(mmu))
+			return ERR_CAST(mmu);
 	}
 
+	aspace = msm_gem_address_space_create(mmu, "gpu", va_start, va_end);
 	if (IS_ERR(aspace)) {
+		mmu->funcs->destroy(mmu);
+
 		DRM_DEV_ERROR(gpu->dev->dev, "failed to init mmu: %ld\n",
 			PTR_ERR(aspace));
 		return ERR_CAST(aspace);
Signature · 6 lines
2.7.4

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
#11 lore raw

PATCH 7/7 drm/msm: Use per-target functions to set up address spaces

In reply to Jordan Crouse

Use a per-target function to set up the default address space for each GPU. This allows a6xx targets to set up the correct address range if split pagetables are enabled by the IOMMU device. This also gets rid of a misplaced bit of a2xx code in msm_gpu and returns it to where it belongs.

---

 drivers/gpu/drm/msm/adreno/a2xx_gpu.c   | 28 +++++++++++++++++
 drivers/gpu/drm/msm/adreno/a3xx_gpu.c   |  1 +
 drivers/gpu/drm/msm/adreno/a4xx_gpu.c   |  1 +
 drivers/gpu/drm/msm/adreno/a5xx_gpu.c   |  1 +
 drivers/gpu/drm/msm/adreno/a6xx_gpu.c   | 56 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/msm/adreno/adreno_gpu.c | 43 +++++++++++++++++++++----
 drivers/gpu/drm/msm/adreno/adreno_gpu.h |  5 +++
 drivers/gpu/drm/msm/msm_gpu.c           | 56 ++-------------------------------
 drivers/gpu/drm/msm/msm_gpu.h           |  4 +--
 9 files changed, 134 insertions(+), 61 deletions(-)
drivers/gpu/drm/msm/adreno/a2xx_gpu.c +28 -0
index 1f83bc1..c9c032e 100644
@@ -401,6 +401,33 @@ static struct msm_gpu_state *a2xx_gpu_state_get(struct msm_gpu *gpu)
 	return state;
 }
 
+static struct msm_gem_address_space *
+a2xx_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev)
+{
+	struct msm_gem_address_space *aspace;
+	struct msm_mmu *mmu = msm_gpummu_new(&pdev->dev, gpu);
+	int ret;
+
+	if (IS_ERR(mmu))
+		return ERR_CAST(mmu);
+
+	ret = mmu->funcs->attach(mmu, NULL, 0);
+	if (ret) {
+		mmu->funcs->destroy(mmu);
+		return ERR_PTR(ret);
+	}
+
+	aspace = msm_gem_address_space_create(mmu, "gpu",
+		SZ_16M, SZ_16M + 0xfff * SZ_64K);
+
+	if (IS_ERR(aspace)) {
+		mmu->funcs->detach(mmu, NULL, 0);
+		mmu->funcs->destroy(mmu);
+	}
+
+	return aspace;
+}
+
 /* Register offset defines for A2XX - copy of A3XX */
 static const unsigned int a2xx_register_offsets[REG_ADRENO_REGISTER_MAX] = {
 	REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_BASE, REG_AXXX_CP_RB_BASE),
@@ -429,6 +456,7 @@ static const struct adreno_gpu_funcs funcs = {
 #endif
 		.gpu_state_get = a2xx_gpu_state_get,
 		.gpu_state_put = adreno_gpu_state_put,
+		.create_address_space = a2xx_create_address_space,
 	},
 };
 
drivers/gpu/drm/msm/adreno/a3xx_gpu.c +1 -0
index 5f7e980..f24dc21 100644
@@ -448,6 +448,7 @@ static const struct adreno_gpu_funcs funcs = {
 #endif
 		.gpu_state_get = a3xx_gpu_state_get,
 		.gpu_state_put = adreno_gpu_state_put,
+		.create_address_space = adreno_gpu_create_address_space,
 	},
 };
 
drivers/gpu/drm/msm/adreno/a4xx_gpu.c +1 -0
index ab2b752..08f4292 100644
@@ -538,6 +538,7 @@ static const struct adreno_gpu_funcs funcs = {
 #endif
 		.gpu_state_get = a4xx_gpu_state_get,
 		.gpu_state_put = adreno_gpu_state_put,
+		.create_address_space = adreno_gpu_create_address_space,
 	},
 	.get_timestamp = a4xx_get_timestamp,
 };
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +1 -0
index 1671db4..e29fea5 100644
@@ -1385,6 +1385,7 @@ static const struct adreno_gpu_funcs funcs = {
 		.gpu_busy = a5xx_gpu_busy,
 		.gpu_state_get = a5xx_gpu_state_get,
 		.gpu_state_put = a5xx_gpu_state_put,
+		.create_address_space = adreno_gpu_create_address_space,
 	},
 	.get_timestamp = a5xx_get_timestamp,
 };
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +56 -0

68 lines not on this page · raw message

drivers/gpu/drm/msm/adreno/adreno_gpu.c +37 -6

55 lines not on this page · raw message

drivers/gpu/drm/msm/adreno/adreno_gpu.h +5 -0
index c7441fb..141ff3a 100644
@@ -247,6 +247,11 @@ void adreno_gpu_state_destroy(struct msm_gpu_state *state);
 int adreno_gpu_state_get(struct msm_gpu *gpu, struct msm_gpu_state *state);
 int adreno_gpu_state_put(struct msm_gpu_state *state);
 
+
+struct msm_gem_address_space *
+adreno_gpu_create_address_space(struct msm_gpu *gpu,
+		struct platform_device *pdev);
+
 /*
  * For a5xx and a6xx targets load the zap shader that is used to pull the GPU
  * out of secure mode
drivers/gpu/drm/msm/msm_gpu.c +3 -53

78 lines not on this page · raw message

drivers/gpu/drm/msm/msm_gpu.h +2 -2
index ab8f0f9c..41d86c2 100644
@@ -21,8 +21,6 @@ struct msm_gpu_state;
 
 struct msm_gpu_config {
 	const char *ioname;
-	uint64_t va_start;
-	uint64_t va_end;
 	unsigned int nr_rings;
 };
 
@@ -64,6 +62,8 @@ struct msm_gpu_funcs {
 	int (*gpu_state_put)(struct msm_gpu_state *state);
 	unsigned long (*gpu_get_freq)(struct msm_gpu *gpu);
 	void (*gpu_set_freq)(struct msm_gpu *gpu, unsigned long freq);
+	struct msm_gem_address_space *(*create_address_space)
+		(struct msm_gpu *gpu, struct platform_device *pdev);
 };
 
 struct msm_gpu {
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/7 iommu/arm-smmu: Support split pagetables

In reply to Jordan Crouse

Support a split pagetable format for SMMU models that support it. If enabled, mirror the TTBR0 setup for TTBR1 and program the pagetable address in TTBR1 instead of TTBR0.

For now only allow split pagetables for ARM64 stage 1 IOMMUs with 49 bit upstream buses. This is the only real-life use case for split pagetables on arm-smmu-v2 to date and it is the easiest configuration to support without a bunch of extra logic.

---

 drivers/iommu/arm-smmu.c | 41 +++++++++++++++++++++++++++++++++++++----
 drivers/iommu/arm-smmu.h |  1 +
 2 files changed, 38 insertions(+), 4 deletions(-)
drivers/iommu/arm-smmu.c +37 -4
index 49c734a..39e81ef 100644
@@ -461,7 +461,17 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain,
 			cb->tcr[0] = pgtbl_cfg->arm_v7s_cfg.tcr;
 		} else {
 			cb->tcr[0] = pgtbl_cfg->arm_lpae_s1_cfg.tcr;
-			cb->tcr[0] |= TCR_EPD1;
+
+			/*
+			 * For split pagetables, duplicate the T0 configuration
+			 * for T1. Otherwise, disable walks through TTBR1
+			 */
+			if (smmu_domain->split_pagetables)
+				cb->tcr[0] |= (pgtbl_cfg->arm_lpae_s1_cfg.tcr &
+					0xffff) << 16;
+			else
+				cb->tcr[0] |= TCR_EPD1;
+
 			cb->tcr[1] = pgtbl_cfg->arm_lpae_s1_cfg.tcr >> 32;
 			cb->tcr[1] |= FIELD_PREP(TCR2_SEP, TCR2_SEP_UPSTREAM);
 			if (cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64)
@@ -477,9 +487,16 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain,
 			cb->ttbr[0] = pgtbl_cfg->arm_v7s_cfg.ttbr;
 			cb->ttbr[1] = 0;
 		} else {
-			cb->ttbr[0] = pgtbl_cfg->arm_lpae_s1_cfg.ttbr;
+			if (smmu_domain->split_pagetables) {
+				cb->ttbr[0] = 0;
+				cb->ttbr[1] = pgtbl_cfg->arm_lpae_s1_cfg.ttbr;
+			} else {
+				cb->ttbr[0] = pgtbl_cfg->arm_lpae_s1_cfg.ttbr;
+				cb->ttbr[1] = 0;
+			}
+
 			cb->ttbr[0] |= FIELD_PREP(TTBRn_ASID, cfg->asid);
-			cb->ttbr[1] = FIELD_PREP(TTBRn_ASID, cfg->asid);
+			cb->ttbr[1] |= FIELD_PREP(TTBRn_ASID, cfg->asid);
 		}
 	} else {
 		cb->ttbr[0] = pgtbl_cfg->arm_lpae_s2_cfg.vttbr;
@@ -720,6 +737,14 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
 			goto out_unlock;
 	}
 
+	/*
+	 * For now, only support a ias of 48 and SEP_UPSTREAM for split
+	 * pagetables. This doesn't preclude using other sign extension bits but
+	 * since the group of split-pagetable users is very small we don't want
+	 * to add a lot of extra code that won't be useful
+	 */
+	WARN_ON(smmu_domain->split_pagetables && ias != 48);
+
 	pgtbl_cfg = (struct io_pgtable_cfg) {
 		.pgsize_bitmap	= smmu->pgsize_bitmap,
 		.ias		= ias,
@@ -740,7 +765,15 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
 
 	/* Update the domain's page sizes to reflect the page table format */
 	domain->pgsize_bitmap = pgtbl_cfg.pgsize_bitmap;
-	domain->geometry.aperture_end = (1UL << ias) - 1;
+
+	if (smmu_domain->split_pagetables) {
+		domain->geometry.aperture_start = ~(1UL << ias);
+		domain->geometry.aperture_end = ~0UL;
+	} else {
+		domain->geometry.aperture_start = 0;
+		domain->geometry.aperture_end = (1UL << ias) - 1;
+	}
+
 	domain->geometry.force_aperture = true;
 
 	/* Initialise the context bank with our page table cfg */
drivers/iommu/arm-smmu.h +1 -0
index 7b0e4d2..91a4eb8 100644
@@ -316,6 +316,7 @@ struct arm_smmu_domain {
 	struct mutex			init_mutex; /* Protects smmu pointer */
 	spinlock_t			cb_lock; /* Serialises ATS1* ops and TLB syncs */
 	struct iommu_domain		domain;
+	bool				split_pagetables;
 };
 
 
Signature · 1 line
2.7.4
#5 lore raw

PATCH 3/7 iommu/arm-smmu: Add a SMMU variant for the Adreno GPU

In reply to Jordan Crouse

Add a SMMU model for the Adreno GPU and use it to enable split pagetable support if the conditions are right.

---

 drivers/iommu/arm-smmu-impl.c | 15 +++++++++++++++
 drivers/iommu/arm-smmu.c      |  2 ++
 drivers/iommu/arm-smmu.h      |  1 +
 3 files changed, 18 insertions(+)
drivers/iommu/arm-smmu-impl.c +15 -0
index 3f88cd0..5d197dd 100644
@@ -147,6 +147,18 @@ static const struct arm_smmu_impl arm_mmu500_impl = {
 	.reset = arm_mmu500_reset,
 };
 
+static int qcom_adreno_init_context(struct arm_smmu_domain *smmu_domain)
+{
+	if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 &&
+		smmu_domain->cfg.fmt == ARM_SMMU_CTX_FMT_AARCH64)
+		smmu_domain->split_pagetables = true;
+
+	return 0;
+}
+
+static const struct arm_smmu_impl qcom_adreno_impl = {
+	.init_context = qcom_adreno_init_context,
+};
 
 struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu)
 {
@@ -162,6 +174,9 @@ struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu)
 		break;
 	case CAVIUM_SMMUV2:
 		return cavium_smmu_impl_init(smmu);
+	case QCOM_ADRENO_SMMUV2:
+		smmu->impl = &qcom_adreno_impl;
+		break;
 	default:
 		break;
 	}
drivers/iommu/arm-smmu.c +2 -0
index 39e81ef..3f41cf7 100644
@@ -1858,6 +1858,7 @@ ARM_SMMU_MATCH_DATA(arm_mmu401, ARM_SMMU_V1_64K, GENERIC_SMMU);
 ARM_SMMU_MATCH_DATA(arm_mmu500, ARM_SMMU_V2, ARM_MMU500);
 ARM_SMMU_MATCH_DATA(cavium_smmuv2, ARM_SMMU_V2, CAVIUM_SMMUV2);
 ARM_SMMU_MATCH_DATA(qcom_smmuv2, ARM_SMMU_V2, QCOM_SMMUV2);
+ARM_SMMU_MATCH_DATA(qcom_adreno_smmuv2, ARM_SMMU_V2, QCOM_ADRENO_SMMUV2);
 
 static const struct of_device_id arm_smmu_of_match[] = {
 	{ .compatible = "arm,smmu-v1", .data = &smmu_generic_v1 },
@@ -1867,6 +1868,7 @@ static const struct of_device_id arm_smmu_of_match[] = {
 	{ .compatible = "arm,mmu-500", .data = &arm_mmu500 },
 	{ .compatible = "cavium,smmu-v2", .data = &cavium_smmuv2 },
 	{ .compatible = "qcom,smmu-v2", .data = &qcom_smmuv2 },
+	{ .compatible = "qcom,adreno-smmu-v2", .data = &qcom_adreno_smmuv2 },
 	{ },
 };
 
drivers/iommu/arm-smmu.h +1 -0
index 91a4eb8..e5a2cc8 100644
@@ -222,6 +222,7 @@ enum arm_smmu_implementation {
 	ARM_MMU500,
 	CAVIUM_SMMUV2,
 	QCOM_SMMUV2,
+	QCOM_ADRENO_SMMUV2,
 };
 
 struct arm_smmu_device {
Signature · 1 line
2.7.4
#7 lore raw

PATCH 4/7 iommu: Add DOMAIN_ATTR_SPLIT_TABLES

In reply to Jordan Crouse

Add a new attribute to query the state of split pagetables for the domain.

---

 include/linux/iommu.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/iommu.h +1 -0
index fdc355c..b06db6c 100644
@@ -125,6 +125,7 @@ enum iommu_attr {
 	DOMAIN_ATTR_FSL_PAMUV1,
 	DOMAIN_ATTR_NESTING,	/* two stages of translation */
 	DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE,
+	DOMAIN_ATTR_SPLIT_TABLES,
 	DOMAIN_ATTR_MAX,
 };
 
Signature · 6 lines
2.7.4

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
#8 lore raw

PATCH 5/7 iommu/arm-smmu: Support DOMAIN_ATTR_SPLIT_TABLES

In reply to Jordan Crouse

Support the DOMAIN_ATTR_SPLIT_TABLES attribute to let the leaf driver know if split pagetables are enabled for the domain.

---

 drivers/iommu/arm-smmu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iommu/arm-smmu.c +3 -0
index 3f41cf7..6a512ff 100644
@@ -1442,6 +1442,9 @@ static int arm_smmu_domain_get_attr(struct iommu_domain *domain,
 		case DOMAIN_ATTR_NESTING:
 			*(int *)data = (smmu_domain->stage == ARM_SMMU_DOMAIN_NESTED);
 			return 0;
+		case DOMAIN_ATTR_SPLIT_TABLES:
+			*(int *)data = !!(smmu_domain->split_pagetables);
+			return 0;
 		default:
 			return -ENODEV;
 		}
Signature · 1 line
2.7.4
maintainer Reviewed-by on v1 2/7
#3 lore raw

Re: [PATCH 2/7] dt-bindings: arm-smmu: Add Adreno GPU variant

In reply to Jordan Crouse
Quoted 9 lines · Jordan Crouse

Add a compatible string to identify SMMUs that are attached to Adreno GPU devices that wish to support split pagetables.

---

 Documentation/devicetree/bindings/iommu/arm,smmu.txt | 7 +++++++
 1 file changed, 7 insertions(+)
maintainer
#9 lore raw

Re: [PATCH 5/7] iommu/arm-smmu: Support DOMAIN_ATTR_SPLIT_TABLES

In reply to Jordan Crouse
Quoted 14 lines · Jordan Crouse

Support the DOMAIN_ATTR_SPLIT_TABLES attribute to let the leaf driver know if split pagetables are enabled for the domain.

---

 drivers/iommu/arm-smmu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iommu/arm-smmu.c +0 -0
index 3f41cf7..6a512ff 100644

drivers/iommu/arm-smmu.c static int arm_smmu_domain_get_attr(struct iommu_domain *domain, · line 1447

Quoted 6 lines
drivers/iommu/arm-smmu.c +3 -0
@@ -1442,6 +1442,9 @@ static int arm_smmu_domain_get_attr(struct iommu_domain *domain,
 		case DOMAIN_ATTR_NESTING:
 			*(int *)data = (smmu_domain->stage == ARM_SMMU_DOMAIN_NESTED);
 			return 0;
+		case DOMAIN_ATTR_SPLIT_TABLES:
+			*(int *)data = !!(smmu_domain->split_pagetables);
+			return 0;

Hmm. Could you move the setting of this attribute into arm_smmu_domain_set_attr() and reject it if the ias != 48 in there? That way the user of the domain can request this feature, rather than us enforcing it based on the compatible string.

I'd also prefer to call it DOMAIN_ATTR_USE_TTBR1 instead, since it's pretty ARM specific at this point.

Will
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#6 lore raw

Re: [PATCH 3/7] iommu/arm-smmu: Add a SMMU variant for the Adreno GPU

In reply to Jordan Crouse

Quoting Jordan Crouse (2019-08-20 12:06:28)

Quoted 13 lines
drivers/iommu/arm-smmu.c +1 -0
index 39e81ef..3f41cf7 100644
@@ -1858,6 +1858,7 @@ ARM_SMMU_MATCH_DATA(arm_mmu401, ARM_SMMU_V1_64K, GENERIC_SMMU);
 ARM_SMMU_MATCH_DATA(arm_mmu500, ARM_SMMU_V2, ARM_MMU500);
 ARM_SMMU_MATCH_DATA(cavium_smmuv2, ARM_SMMU_V2, CAVIUM_SMMUV2);
 ARM_SMMU_MATCH_DATA(qcom_smmuv2, ARM_SMMU_V2, QCOM_SMMUV2);
+ARM_SMMU_MATCH_DATA(qcom_adreno_smmuv2, ARM_SMMU_V2, QCOM_ADRENO_SMMUV2);
 
 static const struct of_device_id arm_smmu_of_match[] = {
        { .compatible = "arm,smmu-v1", .data = &smmu_generic_v1 },

drivers/iommu/arm-smmu.c static const struct of_device_id arm_smmu_of_match[] = { · line 1871

Quoted 4 lines
drivers/iommu/arm-smmu.c +1 -0
@@ -1867,6 +1868,7 @@ static const struct of_device_id arm_smmu_of_match[] = {
        { .compatible = "arm,mmu-500", .data = &arm_mmu500 },
        { .compatible = "cavium,smmu-v2", .data = &cavium_smmuv2 },
        { .compatible = "qcom,smmu-v2", .data = &qcom_smmuv2 },
+       { .compatible = "qcom,adreno-smmu-v2", .data = &qcom_adreno_smmuv2 },

Can this be sorted on compat?

drivers/iommu/arm-smmu.h enum arm_smmu_implementation { · line 225

Quoted 12 lines
drivers/iommu/arm-smmu.c +0 -0
        { },
 };
 
drivers/iommu/arm-smmu.h +1 -0
index 91a4eb8..e5a2cc8 100644
@@ -222,6 +222,7 @@ enum arm_smmu_implementation {
        ARM_MMU500,
        CAVIUM_SMMUV2,
        QCOM_SMMUV2,
+       QCOM_ADRENO_SMMUV2,

Can this be sorted alphabetically?

#4 lore raw

Re: [PATCH 2/7] dt-bindings: arm-smmu: Add Adreno GPU variant

In reply to Jordan Crouse

Quoting Jordan Crouse (2019-08-20 12:06:27)

Quoted 14 lines

Add a compatible string to identify SMMUs that are attached to Adreno GPU devices that wish to support split pagetables.

---

 Documentation/devicetree/bindings/iommu/arm,smmu.txt | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/iommu/arm,smmu.txt +0 -0
index 3133f3b..3b07896 100644

Documentation/devicetree/bindings/iommu/arm,smmu.txt conditions. · line 21

Quoted 4 lines
Documentation/devicetree/bindings/iommu/arm,smmu.txt +1 -0
@@ -18,6 +18,7 @@ conditions.
                         "arm,mmu-500"
                         "cavium,smmu-v2"
                         "qcom,smmu-v2"
+                       "qcom,adreno-smmu-v2"

Is the tabbing weird here or just my MUA is failing?

Documentation/devicetree/bindings/iommu/arm,smmu.txt conditions. · line 35

Quoted 8 lines
Documentation/devicetree/bindings/iommu/arm,smmu.txt +1 -0
                   depending on the particular implementation and/or the
                   version of the architecture implemented.
@@ -31,6 +32,12 @@ conditions.
                   as below, SoC-specific compatibles:
                   "qcom,sdm845-smmu-500", "arm,mmu-500"
 
+                 "qcom,adreno-smmu-v2" is a special implementation for

Heh, special.

Documentation/devicetree/bindings/iommu/arm,smmu.txt conditions. · line 37

Quoted 2 lines
Documentation/devicetree/bindings/iommu/arm,smmu.txt +2 -0
+                 SMMU devices attached to the Adreno GPU on Qcom devices.
+                 If selected, this will enable split pagetable (TTBR1)

Is this selected? Sounds like Kconfig here.

Quoted 5 lines
Documentation/devicetree/bindings/iommu/arm,smmu.txt +3 -0
+                 support. Only use this if the GPU target is capable of
+                 supporting 64 bit addresses.
+
 - reg           : Base address and size of the SMMU.