Skip to contentSkip to conversation

drm/msm/adreno: Handle unavailable GPU SCM calls

PATCH In review Puranam V G Tejaswi 5 participants 17 messages Nov 18 – Dec 4

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover drm/msm/adreno: Handle unavailable GPU SCM calls

Some Qualcomm platforms run secure-world firmware that does not implement all GPU-related SCM calls. Two missing calls can leave the GPU unusable, in different ways.

On A750, A753 and A8xx GPUs, a6xx_gmu_secure_init() asks the secure world to program GPU initialization registers. If qcom_scm_gpu_init_regs() is not implemented, the call fails and GMU resume aborts, so the GPU never comes up. Separately, adreno_hw_init() relies on qcom_scm_set_gpu_smmu_aperture() to configure the CX SMMU aperture. When that call is unavailable, the aperture is left unconfigured and the GPU command processor cannot switch pagetables.

The first two patches add an availability query for the GPU init-regs call and skip it, with a one-time message, when the secure world does not provide it. GMU resume can then continue. The kernel cannot program the protected fuse register itself, but it still reads the register back, so fuse-dependent features such as ray tracing are reported correctly if an earlier boot stage programmed it, and stay disabled otherwise.

The remaining patches provide a software fallback for the SMMU aperture. They describe an optional aperture region in DT and add per-GPU register lists for programming it when the SCM call is unavailable. The fallback points the GC aperture at context bank 0, points the LPAC aperture at context bank 1 on A753, and disables the other apertures. When the secure world supports the SCM call, the existing SCM path is still used, and platforms whose DT does not describe the aperture region are unaffected. DT entries are added for Nord and Shikra.

Patch 1 is for Bjorn. Patches 2-4 are for Rob Clark; patch 2 uses the new SCM helper from patch 1. Patches 5 and 6 are for Bjorn.

This series is based on next-20261116 and the Nord GPU v2 series [1]. Patch 4 needs the A753 catalog entry from that series, and patch 5 needs its Nord GPU node.

[1] https://lore.kernel.org/r/[email protected]

---
Puranam V G Tejaswi (6):
firmware: qcom: scm: Add qcom_scm_gpu_init_regs_is_available() drm/msm/a6xx: Don't fail GMU resume if the GPU init regs SCM call is absent
dt-bindings: display/msm: gpu: Document the CX SMMU aperture region drm/msm/adreno: Program the SMMU aperture when the secure world can't
arm64: dts: qcom: nord: Describe the GPU CX SMMU aperture
arm64: dts: qcom: shikra: Describe the GPU CX SMMU aperture

 .../devicetree/bindings/display/msm/gpu.yaml       |  3 +-
 arch/arm64/boot/dts/qcom/nord.dtsi                 |  6 ++--
 arch/arm64/boot/dts/qcom/shikra.dtsi               |  6 ++--
 drivers/firmware/qcom/qcom_scm.c                   |  7 ++++
 drivers/gpu/drm/msm/adreno/a6xx_catalog.c          |  9 ++++++
 drivers/gpu/drm/msm/adreno/a6xx_gmu.c              | 27 ++++++++++------
 drivers/gpu/drm/msm/adreno/a7xx_catalog.c          | 10 ++++++
 drivers/gpu/drm/msm/adreno/adreno_gpu.c            | 37 ++++++++++++++++++++++
 drivers/gpu/drm/msm/adreno/adreno_gpu.h            | 21 ++++++++++++
 include/linux/firmware/qcom/qcom_scm.h             |  1 +
 10 files changed, 113 insertions(+), 14 deletions(-)

---
base-commit: 749a4de370409464cf8501ec5b2451df45c84eb4
change-id: 20261118-adreno-scm-fallback-8cb94180f48a
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: c05f94606aaf87c23ee9f615c2c003fc6a76ee58
prerequisite-patch-id: af5ae392810d6e5e6faea17f4de1f2d067894d37
prerequisite-patch-id: 9b506be1f9a910d8da57d14d42d45ab2a2a52fde
prerequisite-patch-id: 5c8cbb1bd55d50d3f816c0ddf9c2edf7c7ec4195
prerequisite-patch-id: 01f6f94a2887d2217b5e27b84638f8ee375070ee

Best regards,

Signature · 1 line
Puranam V G Tejaswi <[email protected]>
#1 lore raw

PATCH 1/6 firmware: qcom: scm: Add qcom_scm_gpu_init_regs_is_available()

The Adreno driver asks the secure world to initialize some GPU registers through qcom_scm_gpu_init_regs(), and fails to power up the GPU if this call fails.

Not every secure world implements this call. When it is missing, the call fails in the same way as a real error, so the driver cannot tell the two cases apart.

Add qcom_scm_gpu_init_regs_is_available(), similar to qcom_scm_set_gpu_smmu_aperture_is_available(), so that the driver can check whether the secure world supports the call before making it.

---
 drivers/firmware/qcom/qcom_scm.c       | 7 +++++++
 include/linux/firmware/qcom/qcom_scm.h | 1 +
 2 files changed, 8 insertions(+)
drivers/firmware/qcom/qcom_scm.c +7 -0
index 030e4ba90812..f4f34b7dd0b2 100644
@@ -1941,6 +1941,13 @@ int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val,
 }
 EXPORT_SYMBOL_GPL(qcom_scm_lmh_dcvsh);
 
+bool qcom_scm_gpu_init_regs_is_available(void)
+{
+	return __qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_GPU,
+					    QCOM_SCM_SVC_GPU_INIT_REGS);
+}
+EXPORT_SYMBOL_GPL(qcom_scm_gpu_init_regs_is_available);
+
 int qcom_scm_gpu_init_regs(u32 gpu_req)
 {
 	struct qcom_scm_desc desc = {
include/linux/firmware/qcom/qcom_scm.h +1 -0
index a0a6bc0229c4..c9e88b2904e3 100644
@@ -131,6 +131,7 @@ bool qcom_scm_lmh_dcvsh_available(void);
  */
 #define QCOM_SCM_GPU_TSENSE_EN_REQ BIT(3)
 
+bool qcom_scm_gpu_init_regs_is_available(void);
 int qcom_scm_gpu_init_regs(u32 gpu_req);
 
 int qcom_scm_shm_bridge_create(u64 pfn_and_ns_perm_flags,
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] firmware: qcom: scm: Add qcom_scm_gpu_init_regs_is_available()

Quoted 8 lines · Puranam V G Tejaswi

The Adreno driver asks the secure world to initialize some GPU registers through qcom_scm_gpu_init_regs(), and fails to power up the GPU if this call fails.

Not every secure world implements this call. When it is missing, the call fails in the same way as a real error, so the driver cannot tell the two cases apart.

Quoted 5 lines

Add qcom_scm_gpu_init_regs_is_available(), similar to qcom_scm_set_gpu_smmu_aperture_is_available(), so that the driver can check whether the secure world supports the call before making it.

-Akhil> ---

Quoted 35 lines
 drivers/firmware/qcom/qcom_scm.c       | 7 +++++++
 include/linux/firmware/qcom/qcom_scm.h | 1 +
 2 files changed, 8 insertions(+)
drivers/firmware/qcom/qcom_scm.c +7 -0
index 030e4ba90812..f4f34b7dd0b2 100644
@@ -1941,6 +1941,13 @@ int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val,
 }
 EXPORT_SYMBOL_GPL(qcom_scm_lmh_dcvsh);
 
+bool qcom_scm_gpu_init_regs_is_available(void)
+{
+	return __qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_GPU,
+					    QCOM_SCM_SVC_GPU_INIT_REGS);
+}
+EXPORT_SYMBOL_GPL(qcom_scm_gpu_init_regs_is_available);
+
 int qcom_scm_gpu_init_regs(u32 gpu_req)
 {
 	struct qcom_scm_desc desc = {
include/linux/firmware/qcom/qcom_scm.h +1 -0
index a0a6bc0229c4..c9e88b2904e3 100644
@@ -131,6 +131,7 @@ bool qcom_scm_lmh_dcvsh_available(void);
  */
 #define QCOM_SCM_GPU_TSENSE_EN_REQ BIT(3)
 
+bool qcom_scm_gpu_init_regs_is_available(void);
 int qcom_scm_gpu_init_regs(u32 gpu_req);
 
 int qcom_scm_shm_bridge_create(u64 pfn_and_ns_perm_flags,
maintainer Acked-by on v1 1/6
#3 lore raw

Re: [PATCH 1/6] firmware: qcom: scm: Add qcom_scm_gpu_init_regs_is_available()

In reply to Puranam V G Tejaswi
Quoted 8 lines · Puranam V G Tejaswi

The Adreno driver asks the secure world to initialize some GPU registers through qcom_scm_gpu_init_regs(), and fails to power up the GPU if this call fails.

Not every secure world implements this call. When it is missing, the call fails in the same way as a real error, so the driver cannot tell the two cases apart.

Quoted 5 lines

Add qcom_scm_gpu_init_regs_is_available(), similar to qcom_scm_set_gpu_smmu_aperture_is_available(), so that the driver can check whether the secure world supports the call before making it.

Regards,
Bjorn

Quoted 39 lines
---
 drivers/firmware/qcom/qcom_scm.c       | 7 +++++++
 include/linux/firmware/qcom/qcom_scm.h | 1 +
 2 files changed, 8 insertions(+)
drivers/firmware/qcom/qcom_scm.c +7 -0
index 030e4ba90812..f4f34b7dd0b2 100644
@@ -1941,6 +1941,13 @@ int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val,
 }
 EXPORT_SYMBOL_GPL(qcom_scm_lmh_dcvsh);
 
+bool qcom_scm_gpu_init_regs_is_available(void)
+{
+	return __qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_GPU,
+					    QCOM_SCM_SVC_GPU_INIT_REGS);
+}
+EXPORT_SYMBOL_GPL(qcom_scm_gpu_init_regs_is_available);
+
 int qcom_scm_gpu_init_regs(u32 gpu_req)
 {
 	struct qcom_scm_desc desc = {
include/linux/firmware/qcom/qcom_scm.h +1 -0
index a0a6bc0229c4..c9e88b2904e3 100644
@@ -131,6 +131,7 @@ bool qcom_scm_lmh_dcvsh_available(void);
  */
 #define QCOM_SCM_GPU_TSENSE_EN_REQ BIT(3)
 
+bool qcom_scm_gpu_init_regs_is_available(void);
 int qcom_scm_gpu_init_regs(u32 gpu_req);
 
 int qcom_scm_shm_bridge_create(u64 pfn_and_ns_perm_flags,
Signature · 2 lines
-- 
2.34.1
#4 lore raw

PATCH 2/6 drm/msm/a6xx: Don't fail GMU resume if the GPU init regs SCM call is absent

In reply to Puranam V G Tejaswi

On A750, A753 and A8xx, a6xx_gmu_secure_init() asks the secure world to program CX_MISC_SW_FUSE_VALUE through qcom_scm_gpu_init_regs(), and aborts the GMU resume if that call fails.

Some platforms have a secure world that does not implement this call. The call fails every time and the GPU never powers up. The fuse register is still protected from the kernel, so the driver cannot program it directly either.

If the secure world does not support the call, skip it, but still read the fuse register back. An earlier boot stage may have programmed it, and the features it enables, such as raytracing, are then reported correctly. If nothing programmed it, they stay disabled. Log once when the call is skipped.

---
 drivers/gpu/drm/msm/adreno/a6xx_gmu.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/msm/adreno/a6xx_gmu.c +18 -9
index 0fa2d2091f3e..95636dabee38 100644
@@ -1249,22 +1249,31 @@ static int a6xx_gmu_secure_init(struct a6xx_gpu *a6xx_gpu)
 			goto done;
 		}
 
-		u32 gpu_req = QCOM_SCM_GPU_ALWAYS_EN_REQ | QCOM_SCM_GPU_TSENSE_EN_REQ;
+		/*
+		 * Some secure world implementations do not provide this call.
+		 * Skip it then. An earlier boot stage may still have
+		 * programmed the fuse register, so read it back either way.
+		 */
+		if (qcom_scm_gpu_init_regs_is_available()) {
+			u32 gpu_req = QCOM_SCM_GPU_ALWAYS_EN_REQ |
+				      QCOM_SCM_GPU_TSENSE_EN_REQ;
 
-		if (adreno_gpu->info->a6xx->clx_tbl)
-			gpu_req |= QCOM_SCM_GPU_CLX_EN_REQ;
+			if (adreno_gpu->info->a6xx->clx_tbl)
+				gpu_req |= QCOM_SCM_GPU_CLX_EN_REQ;
 
-		ret = qcom_scm_gpu_init_regs(gpu_req);
-		if (ret) {
-			dev_warn_once(gpu->dev->dev,
-				"SCM call failed\n");
-			return ret;
+			ret = qcom_scm_gpu_init_regs(gpu_req);
+			if (ret) {
+				dev_warn_once(gpu->dev->dev, "SCM call failed\n");
+				return ret;
+			}
+		} else {
+			dev_info_once(gpu->dev->dev, "GPU init regs SCM call not available, skipping\n");
 		}
 
 		/*
 		 * On A7XX_GEN3 and newer, raytracing may be disabled by the
 		 * firmware, find out whether that's the case. The scm call
-		 * above sets the fuse register.
+		 * above, or an earlier boot stage, sets the fuse register.
 		 */
 		fuse_val = a6xx_cx_misc_read(a6xx_gpu,
 					 REG_A7XX_CX_MISC_SW_FUSE_VALUE);
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 2/6
#5 lore raw

Re: [PATCH 2/6] drm/msm/a6xx: Don't fail GMU resume if the GPU init regs SCM call is absent

Quoted 9 lines · Puranam V G Tejaswi

On A750, A753 and A8xx, a6xx_gmu_secure_init() asks the secure world to program CX_MISC_SW_FUSE_VALUE through qcom_scm_gpu_init_regs(), and aborts the GMU resume if that call fails.

Some platforms have a secure world that does not implement this call. The call fails every time and the GPU never powers up. The fuse register is still protected from the kernel, so the driver cannot program it directly either.

Quoted 7 lines

If the secure world does not support the call, skip it, but still read the fuse register back. An earlier boot stage may have programmed it, and the features it enables, such as raytracing, are then reported correctly. If nothing programmed it, they stay disabled. Log once when the call is skipped.

Maybe shorten the subject a bit. Say "Make gpu reg init SCM call optional".

Either way:

-Akhil.

Quoted 50 lines
---
 drivers/gpu/drm/msm/adreno/a6xx_gmu.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/msm/adreno/a6xx_gmu.c +18 -9
index 0fa2d2091f3e..95636dabee38 100644
@@ -1249,22 +1249,31 @@ static int a6xx_gmu_secure_init(struct a6xx_gpu *a6xx_gpu)
 			goto done;
 		}
 
-		u32 gpu_req = QCOM_SCM_GPU_ALWAYS_EN_REQ | QCOM_SCM_GPU_TSENSE_EN_REQ;
+		/*
+		 * Some secure world implementations do not provide this call.
+		 * Skip it then. An earlier boot stage may still have
+		 * programmed the fuse register, so read it back either way.
+		 */
+		if (qcom_scm_gpu_init_regs_is_available()) {
+			u32 gpu_req = QCOM_SCM_GPU_ALWAYS_EN_REQ |
+				      QCOM_SCM_GPU_TSENSE_EN_REQ;
 
-		if (adreno_gpu->info->a6xx->clx_tbl)
-			gpu_req |= QCOM_SCM_GPU_CLX_EN_REQ;
+			if (adreno_gpu->info->a6xx->clx_tbl)
+				gpu_req |= QCOM_SCM_GPU_CLX_EN_REQ;
 
-		ret = qcom_scm_gpu_init_regs(gpu_req);
-		if (ret) {
-			dev_warn_once(gpu->dev->dev,
-				"SCM call failed\n");
-			return ret;
+			ret = qcom_scm_gpu_init_regs(gpu_req);
+			if (ret) {
+				dev_warn_once(gpu->dev->dev, "SCM call failed\n");
+				return ret;
+			}
+		} else {
+			dev_info_once(gpu->dev->dev, "GPU init regs SCM call not available, skipping\n");
 		}
 
 		/*
 		 * On A7XX_GEN3 and newer, raytracing may be disabled by the
 		 * firmware, find out whether that's the case. The scm call
-		 * above sets the fuse register.
+		 * above, or an earlier boot stage, sets the fuse register.
 		 */
 		fuse_val = a6xx_cx_misc_read(a6xx_gpu,
 					 REG_A7XX_CX_MISC_SW_FUSE_VALUE);
#6 lore raw

PATCH 3/6 dt-bindings: display/msm: gpu: Document the CX SMMU aperture region

In reply to Puranam V G Tejaswi

The CX SMMU aperture is a register block in the GPU. It holds the location of the GPU SMMU context banks that the CP uses for pagetable switching.

On some GPUs the block lies outside the existing GPU register regions. Add it as an optional aperture region, so the driver can program it on platforms where the secure world does not.

---
 Documentation/devicetree/bindings/display/msm/gpu.yaml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/display/msm/gpu.yaml +2 -1
index 3c90a09febe7..5e4f3149839e 100644
@@ -54,7 +54,7 @@ properties:
 
   reg:
     minItems: 1
-    maxItems: 3
+    maxItems: 4
 
   reg-names:
     minItems: 1
@@ -62,6 +62,7 @@ properties:
       - const: kgsl_3d0_reg_memory
       - const: cx_mem
       - const: cx_dbgc
+      - const: aperture
 
   interrupts:
     maxItems: 1
Signature · 1 line
2.34.1
reviewer Acked-by on v1 3/6
#7 lore raw

Re: [PATCH 3/6] dt-bindings: display/msm: gpu: Document the CX SMMU aperture region

Quoted 9 lines · Puranam V G Tejaswi

The CX SMMU aperture is a register block in the GPU. It holds the location of the GPU SMMU context banks that the CP uses for pagetable switching.

On some GPUs the block lies outside the existing GPU register regions. Add it as an optional aperture region, so the driver can program it on platforms where the secure world does not.

-Akhil

Quoted 26 lines
---
 Documentation/devicetree/bindings/display/msm/gpu.yaml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/display/msm/gpu.yaml +2 -1
index 3c90a09febe7..5e4f3149839e 100644
@@ -54,7 +54,7 @@ properties:
 
   reg:
     minItems: 1
-    maxItems: 3
+    maxItems: 4
 
   reg-names:
     minItems: 1
@@ -62,6 +62,7 @@ properties:
       - const: kgsl_3d0_reg_memory
       - const: cx_mem
       - const: cx_dbgc
+      - const: aperture
 
   interrupts:
     maxItems: 1
maintainer Acked-by on v1 3/6
#8 lore raw

Re: [PATCH 3/6] dt-bindings: display/msm: gpu: Document the CX SMMU aperture region

In reply to Puranam V G Tejaswi
Quoted 4 lines · Puranam V G Tejaswi

The CX SMMU aperture is a register block in the GPU. It holds the location of the GPU SMMU context banks that the CP uses for pagetable switching.

Quoted 9 lines

On some GPUs the block lies outside the existing GPU register regions. Add it as an optional aperture region, so the driver can program it on platforms where the secure world does not.

---
 Documentation/devicetree/bindings/display/msm/gpu.yaml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
#9 lore raw

PATCH 4/6 drm/msm/adreno: Program the SMMU aperture when the secure world can't

In reply to Puranam V G Tejaswi

The CP switches pagetables by writing the GPU SMMU context bank registers itself. It reaches them through the CX SMMU aperture, a register block in the GPU, which has to point at context bank 0. The secure world normally owns this block and programs it when adreno_hw_init() calls qcom_scm_set_gpu_smmu_aperture().

Some platforms have a secure world that does not implement this. Nothing programs the aperture on these platforms, so the CP cannot switch pagetables.

If the SCM call is not supported, program the aperture from adreno_hw_init() instead. Point the GC aperture at context bank 0 and, on GPUs with LPAC, the LPAC aperture at context bank 1, the same way the secure world does. Disable the other apertures. The SCM call is still used whenever it is supported.

The values depend on where context bank 0 sits in the GPU register space, which differs between GPUs, so they come from a register list in the GPU catalog. The aperture region comes from DT. If DT describes the region but it cannot be mapped, fail probe. Add the lists for A702, whose entry Shikra's GPU also uses, and for A753.

---
 drivers/gpu/drm/msm/adreno/a6xx_catalog.c |  9 ++++++++
 drivers/gpu/drm/msm/adreno/a7xx_catalog.c | 10 +++++++++
 drivers/gpu/drm/msm/adreno/adreno_gpu.c   | 37 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/msm/adreno/adreno_gpu.h   | 21 ++++++++++++++++++
 4 files changed, 77 insertions(+)
drivers/gpu/drm/msm/adreno/a6xx_catalog.c +9 -0
index 4ef2bd6e7ad2..fe1902b8de16 100644
@@ -736,6 +736,14 @@ static const struct adreno_reglist a702_hwcg[] = {
 	{}
 };
 
+/* GPU aperture: GC to CB0, other apertures disabled */
+static const struct adreno_reglist a702_aperture_reglist_regs[] = {
+	{ 0x00, 0x000a8000 }, /* GC: CB0 */
+	{ 0x08, 0x00000000 }, /* CTRL: GC only */
+};
+
+DECLARE_ADRENO_REGPAIR_LIST(a702_aperture_reglist);
+
 static const struct adreno_info a6xx_gpus[] = {
 	{
 		.chip_ids = ADRENO_CHIP_IDS(0x06010000),
@@ -1198,6 +1206,7 @@ static const struct adreno_info a6xx_gpus[] = {
 		.quirks = ADRENO_QUIRK_HAS_HW_APRIV,
 		.funcs = &a6xx_gmuwrapper_funcs,
 		.zapfw = "a702_zap.mbn",
+		.aperture_reglist = &a702_aperture_reglist,
 		.a6xx = &(const struct a6xx_info) {
 			.hwcg = a702_hwcg,
 			.protect = &a650_protect,
drivers/gpu/drm/msm/adreno/a7xx_catalog.c +10 -0
index 9465ffa3dd12..43d681aa3c2e 100644
@@ -279,6 +279,15 @@ static const struct adreno_reglist_pipe a7xx_dyn_pwrup_reglist_regs[] = {
 
 DECLARE_ADRENO_REGLIST_PIPE_LIST(a7xx_dyn_pwrup_reglist);
 
+/* GPU aperture: GC to CB0, LPAC to CB1, other apertures disabled */
+static const struct adreno_reglist a753_aperture_reglist_regs[] = {
+	{ 0x00, 0x000c0000 }, /* GC: CB0 */
+	{ 0x04, 0x000c1000 }, /* LPAC: CB1 */
+	{ 0x08, 0x00000002 }, /* CTRL: GC and LPAC */
+};
+
+DECLARE_ADRENO_REGPAIR_LIST(a753_aperture_reglist);
+
 static const struct adreno_info a7xx_gpus[] = {
 	{
 		.chip_ids = ADRENO_CHIP_IDS(0x07030001),
@@ -465,6 +474,7 @@ static const struct adreno_info a7xx_gpus[] = {
 			  ADRENO_QUIRK_PREEMPTION |
 			  ADRENO_QUIRK_IFPC,
 		.funcs = &a7xx_gpu_funcs,
+		.aperture_reglist = &a753_aperture_reglist,
 		.a6xx = &(const struct a6xx_info) {
 			.protect = &a730_protect,
 			.pwrup_reglist = &a7xx_pwrup_reglist,
drivers/gpu/drm/msm/adreno/adreno_gpu.c +37 -0
index 54f337475231..c3c84629c5f4 100644
@@ -675,6 +675,13 @@ int adreno_hw_init(struct msm_gpu *gpu)
 		ret = qcom_scm_set_gpu_smmu_aperture(0);
 		if (ret)
 			DRM_DEV_ERROR(gpu->dev->dev, "unable to set SMMU aperture: %d\n", ret);
+	} else if (adreno_gpu->aperture) {
+		const struct adreno_regpair_list *list =
+			adreno_gpu->info->aperture_reglist;
+
+		for (int i = 0; i < list->count; i++)
+			writel(list->regs[i].value,
+			       adreno_gpu->aperture + list->regs[i].offset);
 	}
 
 	for (int i = 0; i < gpu->nr_rings; i++) {
@@ -1193,6 +1200,32 @@ int adreno_read_speedbin(struct device *dev, u32 *speedbin)
 	return nvmem_cell_read_variable_le_u32(dev, "speed_bin", speedbin);
 }
 
+/*
+ * Map the GPU aperture, so that adreno_hw_init() can program it when
+ * the secure world does not.
+ */
+static int adreno_gpu_aperture_init(struct platform_device *pdev,
+				    struct adreno_gpu *adreno_gpu)
+{
+	struct resource *res;
+	void __iomem *base;
+
+	if (!adreno_gpu->info->aperture_reglist)
+		return 0;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "aperture");
+	if (!res)
+		return 0;
+
+	base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	adreno_gpu->aperture = base;
+
+	return 0;
+}
+
 int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,
 		struct adreno_gpu *adreno_gpu,
 		const struct adreno_gpu_funcs *funcs, int nr_rings)
@@ -1238,6 +1271,10 @@ int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,
 
 	adreno_gpu_config.ioname = "kgsl_3d0_reg_memory";
 
+	ret = adreno_gpu_aperture_init(pdev, adreno_gpu);
+	if (ret)
+		return ret;
+
 	adreno_gpu_config.nr_rings = nr_rings;
 
 	ret = adreno_get_pwrlevels(dev, gpu);
drivers/gpu/drm/msm/adreno/adreno_gpu.h +21 -0
index 2911d440ab17..021802c6830c 100644
@@ -88,6 +88,19 @@ struct adreno_reglist {
 	u32 value;
 };
 
+struct adreno_regpair_list {
+	/** @regs: List of register offset and value pairs **/
+	const struct adreno_reglist *regs;
+	/** @count: Number of registers in the list **/
+	u32 count;
+};
+
+#define DECLARE_ADRENO_REGPAIR_LIST(name)	\
+static const struct adreno_regpair_list name = {		\
+	.regs = name ## _regs,				\
+	.count = ARRAY_SIZE(name ## _regs),		\
+}
+
 /* Reglist with pipe information */
 struct adreno_reglist_pipe {
 	u32 offset;
@@ -129,6 +142,11 @@ struct adreno_info {
 	 */
 	struct adreno_speedbin *speedbins;
 	u64 preempt_record_size;
+	/**
+	 * @aperture_reglist: Optional GPU aperture register values. Used if
+	 * the secure world does not program the aperture.
+	 */
+	const struct adreno_regpair_list *aperture_reglist;
 };
 
 #define ADRENO_CHIP_IDS(tbl...) (uint32_t[]) { tbl, 0 }
@@ -250,6 +268,9 @@ struct adreno_gpu {
 
 	bool has_ray_tracing;
 
+	/* GPU aperture, if the driver may need to program it */
+	void __iomem *aperture;
+
 	u64 uche_trap_base;
 };
 #define to_adreno_gpu(x) container_of(x, struct adreno_gpu, base)
Signature · 1 line
2.34.1
#10 lore raw

Re: [PATCH 4/6] drm/msm/adreno: Program the SMMU aperture when the secure world can't

Quoted 35 lines · Puranam V G Tejaswi

The CP switches pagetables by writing the GPU SMMU context bank registers itself. It reaches them through the CX SMMU aperture, a register block in the GPU, which has to point at context bank 0. The secure world normally owns this block and programs it when adreno_hw_init() calls qcom_scm_set_gpu_smmu_aperture().

Some platforms have a secure world that does not implement this. Nothing programs the aperture on these platforms, so the CP cannot switch pagetables.

If the SCM call is not supported, program the aperture from adreno_hw_init() instead. Point the GC aperture at context bank 0 and, on GPUs with LPAC, the LPAC aperture at context bank 1, the same way the secure world does. Disable the other apertures. The SCM call is still used whenever it is supported.

The values depend on where context bank 0 sits in the GPU register space, which differs between GPUs, so they come from a register list in the GPU catalog. The aperture region comes from DT. If DT describes the region but it cannot be mapped, fail probe. Add the lists for A702, whose entry Shikra's GPU also uses, and for A753.

---
 drivers/gpu/drm/msm/adreno/a6xx_catalog.c |  9 ++++++++
 drivers/gpu/drm/msm/adreno/a7xx_catalog.c | 10 +++++++++
 drivers/gpu/drm/msm/adreno/adreno_gpu.c   | 37 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/msm/adreno/adreno_gpu.h   | 21 ++++++++++++++++++
 4 files changed, 77 insertions(+)
drivers/gpu/drm/msm/adreno/a6xx_catalog.c +0 -0
index 4ef2bd6e7ad2..fe1902b8de16 100644

drivers/gpu/drm/msm/adreno/a6xx_catalog.c static const struct adreno_reglist a702_hwcg[] = { · line 742

Quoted 7 lines
drivers/gpu/drm/msm/adreno/a6xx_catalog.c +4 -0
@@ -736,6 +736,14 @@ static const struct adreno_reglist a702_hwcg[] = {
 	{}
 };
 
+/* GPU aperture: GC to CB0, other apertures disabled */
+static const struct adreno_reglist a702_aperture_reglist_regs[] = {
+	{ 0x00, 0x000a8000 }, /* GC: CB0 */
+	{ 0x08, 0x00000000 }, /* CTRL: GC only */

These offsets should be documented in the xml file instead of hardcoded values. Otherwise LGTM.

-Akhil.

Quoted 152 lines
drivers/gpu/drm/msm/adreno/a6xx_catalog.c +5 -0
+};
+
+DECLARE_ADRENO_REGPAIR_LIST(a702_aperture_reglist);
+
 static const struct adreno_info a6xx_gpus[] = {
 	{
 		.chip_ids = ADRENO_CHIP_IDS(0x06010000),
@@ -1198,6 +1206,7 @@ static const struct adreno_info a6xx_gpus[] = {
 		.quirks = ADRENO_QUIRK_HAS_HW_APRIV,
 		.funcs = &a6xx_gmuwrapper_funcs,
 		.zapfw = "a702_zap.mbn",
+		.aperture_reglist = &a702_aperture_reglist,
 		.a6xx = &(const struct a6xx_info) {
 			.hwcg = a702_hwcg,
 			.protect = &a650_protect,
drivers/gpu/drm/msm/adreno/a7xx_catalog.c +10 -0
index 9465ffa3dd12..43d681aa3c2e 100644
@@ -279,6 +279,15 @@ static const struct adreno_reglist_pipe a7xx_dyn_pwrup_reglist_regs[] = {
 
 DECLARE_ADRENO_REGLIST_PIPE_LIST(a7xx_dyn_pwrup_reglist);
 
+/* GPU aperture: GC to CB0, LPAC to CB1, other apertures disabled */
+static const struct adreno_reglist a753_aperture_reglist_regs[] = {
+	{ 0x00, 0x000c0000 }, /* GC: CB0 */
+	{ 0x04, 0x000c1000 }, /* LPAC: CB1 */
+	{ 0x08, 0x00000002 }, /* CTRL: GC and LPAC */
+};
+
+DECLARE_ADRENO_REGPAIR_LIST(a753_aperture_reglist);
+
 static const struct adreno_info a7xx_gpus[] = {
 	{
 		.chip_ids = ADRENO_CHIP_IDS(0x07030001),
@@ -465,6 +474,7 @@ static const struct adreno_info a7xx_gpus[] = {
 			  ADRENO_QUIRK_PREEMPTION |
 			  ADRENO_QUIRK_IFPC,
 		.funcs = &a7xx_gpu_funcs,
+		.aperture_reglist = &a753_aperture_reglist,
 		.a6xx = &(const struct a6xx_info) {
 			.protect = &a730_protect,
 			.pwrup_reglist = &a7xx_pwrup_reglist,
drivers/gpu/drm/msm/adreno/adreno_gpu.c +37 -0
index 54f337475231..c3c84629c5f4 100644
@@ -675,6 +675,13 @@ int adreno_hw_init(struct msm_gpu *gpu)
 		ret = qcom_scm_set_gpu_smmu_aperture(0);
 		if (ret)
 			DRM_DEV_ERROR(gpu->dev->dev, "unable to set SMMU aperture: %d\n", ret);
+	} else if (adreno_gpu->aperture) {
+		const struct adreno_regpair_list *list =
+			adreno_gpu->info->aperture_reglist;
+
+		for (int i = 0; i < list->count; i++)
+			writel(list->regs[i].value,
+			       adreno_gpu->aperture + list->regs[i].offset);
 	}
 
 	for (int i = 0; i < gpu->nr_rings; i++) {
@@ -1193,6 +1200,32 @@ int adreno_read_speedbin(struct device *dev, u32 *speedbin)
 	return nvmem_cell_read_variable_le_u32(dev, "speed_bin", speedbin);
 }
 
+/*
+ * Map the GPU aperture, so that adreno_hw_init() can program it when
+ * the secure world does not.
+ */
+static int adreno_gpu_aperture_init(struct platform_device *pdev,
+				    struct adreno_gpu *adreno_gpu)
+{
+	struct resource *res;
+	void __iomem *base;
+
+	if (!adreno_gpu->info->aperture_reglist)
+		return 0;
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "aperture");
+	if (!res)
+		return 0;
+
+	base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	adreno_gpu->aperture = base;
+
+	return 0;
+}
+
 int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,
 		struct adreno_gpu *adreno_gpu,
 		const struct adreno_gpu_funcs *funcs, int nr_rings)
@@ -1238,6 +1271,10 @@ int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,
 
 	adreno_gpu_config.ioname = "kgsl_3d0_reg_memory";
 
+	ret = adreno_gpu_aperture_init(pdev, adreno_gpu);
+	if (ret)
+		return ret;
+
 	adreno_gpu_config.nr_rings = nr_rings;
 
 	ret = adreno_get_pwrlevels(dev, gpu);
drivers/gpu/drm/msm/adreno/adreno_gpu.h +21 -0
index 2911d440ab17..021802c6830c 100644
@@ -88,6 +88,19 @@ struct adreno_reglist {
 	u32 value;
 };
 
+struct adreno_regpair_list {
+	/** @regs: List of register offset and value pairs **/
+	const struct adreno_reglist *regs;
+	/** @count: Number of registers in the list **/
+	u32 count;
+};
+
+#define DECLARE_ADRENO_REGPAIR_LIST(name)	\
+static const struct adreno_regpair_list name = {		\
+	.regs = name ## _regs,				\
+	.count = ARRAY_SIZE(name ## _regs),		\
+}
+
 /* Reglist with pipe information */
 struct adreno_reglist_pipe {
 	u32 offset;
@@ -129,6 +142,11 @@ struct adreno_info {
 	 */
 	struct adreno_speedbin *speedbins;
 	u64 preempt_record_size;
+	/**
+	 * @aperture_reglist: Optional GPU aperture register values. Used if
+	 * the secure world does not program the aperture.
+	 */
+	const struct adreno_regpair_list *aperture_reglist;
 };
 
 #define ADRENO_CHIP_IDS(tbl...) (uint32_t[]) { tbl, 0 }
@@ -250,6 +268,9 @@ struct adreno_gpu {
 
 	bool has_ray_tracing;
 
+	/* GPU aperture, if the driver may need to program it */
+	void __iomem *aperture;
+
 	u64 uche_trap_base;
 };
 #define to_adreno_gpu(x) container_of(x, struct adreno_gpu, base)
#11 lore raw

PATCH 5/6 arm64: dts: qcom: nord: Describe the GPU CX SMMU aperture

In reply to Puranam V G Tejaswi

Add the CX SMMU aperture register region to the A753 GPU node.

---
 arch/arm64/boot/dts/qcom/nord.dtsi | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/nord.dtsi +4 -2
index 3e29c43ca9ad..cb5ee6b68779 100644
@@ -1717,10 +1717,12 @@ gpu_0: gpu@3d00000 {
 			compatible = "qcom,adreno-43051701", "qcom,adreno";
 			reg = <0x0 0x03d00000 0x0 0x40000>,
 			      <0x0 0x03d9e000 0x0 0x2000>,
-			      <0x0 0x03d61000 0x0 0x800>;
+			      <0x0 0x03d61000 0x0 0x800>,
+			      <0x0 0x03d60000 0x0 0x1000>;
 			reg-names = "kgsl_3d0_reg_memory",
 				    "cx_mem",
-				    "cx_dbgc";
+				    "cx_dbgc",
+				    "aperture";
 
 			interrupts = <GIC_SPI 300 IRQ_TYPE_LEVEL_HIGH>;
 
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 5/6
#12 lore raw

Re: [PATCH 5/6] arm64: dts: qcom: nord: Describe the GPU CX SMMU aperture

Quoted 3 lines · Puranam V G Tejaswi

Add the CX SMMU aperture register region to the A753 GPU node.

-Akhil

Quoted 24 lines
---
 arch/arm64/boot/dts/qcom/nord.dtsi | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/nord.dtsi +4 -2
index 3e29c43ca9ad..cb5ee6b68779 100644
@@ -1717,10 +1717,12 @@ gpu_0: gpu@3d00000 {
 			compatible = "qcom,adreno-43051701", "qcom,adreno";
 			reg = <0x0 0x03d00000 0x0 0x40000>,
 			      <0x0 0x03d9e000 0x0 0x2000>,
-			      <0x0 0x03d61000 0x0 0x800>;
+			      <0x0 0x03d61000 0x0 0x800>,
+			      <0x0 0x03d60000 0x0 0x1000>;
 			reg-names = "kgsl_3d0_reg_memory",
 				    "cx_mem",
-				    "cx_dbgc";
+				    "cx_dbgc",
+				    "aperture";
 
 			interrupts = <GIC_SPI 300 IRQ_TYPE_LEVEL_HIGH>;
 
#14 lore raw

PATCH 6/6 arm64: dts: qcom: shikra: Describe the GPU CX SMMU aperture

In reply to Puranam V G Tejaswi

Add the CX SMMU aperture register region to the GPU node.

---
 arch/arm64/boot/dts/qcom/shikra.dtsi | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/shikra.dtsi +4 -2
index 0a95ad5a5582..ebbe5e23d173 100644
@@ -2647,10 +2647,12 @@ gpu: gpu@5900000 {
 			compatible = "qcom,adreno-07000400", "qcom,adreno";
 			reg = <0x0 0x05900000 0x0 0x40000>,
 			      <0x0 0x0599e000 0x0 0x1000>,
-			      <0x0 0x05961000 0x0 0x800>;
+			      <0x0 0x05961000 0x0 0x800>,
+			      <0x0 0x05960000 0x0 0x1000>;
 			reg-names = "kgsl_3d0_reg_memory",
 				    "cx_mem",
-				    "cx_dbgc";
+				    "cx_dbgc",
+				    "aperture";
 
 			interrupts = <GIC_SPI 177 IRQ_TYPE_LEVEL_HIGH 0>;
 
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 6/6
#15 lore raw

Re: [PATCH 6/6] arm64: dts: qcom: shikra: Describe the GPU CX SMMU aperture

Quoted 3 lines · Puranam V G Tejaswi

Add the CX SMMU aperture register region to the GPU node.

-Akhil

Quoted 24 lines
---
 arch/arm64/boot/dts/qcom/shikra.dtsi | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/shikra.dtsi +4 -2
index 0a95ad5a5582..ebbe5e23d173 100644
@@ -2647,10 +2647,12 @@ gpu: gpu@5900000 {
 			compatible = "qcom,adreno-07000400", "qcom,adreno";
 			reg = <0x0 0x05900000 0x0 0x40000>,
 			      <0x0 0x0599e000 0x0 0x1000>,
-			      <0x0 0x05961000 0x0 0x800>;
+			      <0x0 0x05961000 0x0 0x800>,
+			      <0x0 0x05960000 0x0 0x1000>;
 			reg-names = "kgsl_3d0_reg_memory",
 				    "cx_mem",
-				    "cx_dbgc";
+				    "cx_dbgc",
+				    "aperture";
 
 			interrupts = <GIC_SPI 177 IRQ_TYPE_LEVEL_HIGH 0>;