Skip to contentSkip to conversation

drm/msm: gpu: Enable zap shader for A5XX

PATCH In review Jordan Crouse 2 participants 2 messages May 17, 2017

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

PATCH v5 1/1 drm/msm: gpu: Enable zap shader for A5XX

The A5XX GPU powers on in "secure" mode. In secure mode the GPU can only render to buffers that are marked as secure and inaccessible to the kernel and user through a series of hardware protections. In practice secure mode is used to draw things like a UI on a secure video frame.

In order to switch out of secure mode the GPU executes a special shader that clears out the GMEM and other sensitve registers and then writes a register. Because the kernel can't be trusted the shader binary is signed and verified and programmed by the secure world. To do this we need to read the MDT header and the segments from the firmware location and put them in memory and present them for approval.

For targets without secure support there is an out: if the secure world doesn't support secure then there are no hardware protections and we can freely write the SECVID_TRUST register from the CPU. We don't have 100% confidence that we can query the secure capabilities at run time but we have enough calls that need to go right to give us some confidence that we're at least doing something useful.

Of course if we guess wrong you trigger a permissions violation which usually ends up in a system crash but thats a problem that shows up immediately.

[v2: use child device per Bjorn]
[v3: use generic MDT loader per Bjorn]
[v4: use managed dma functions and ifdefs for the MDT loader] [v5: Add depends for QCOM_MDT_LOADER]

---
 drivers/gpu/drm/msm/Kconfig                |   1 +
 drivers/gpu/drm/msm/adreno/a5xx_gpu.c      | 180 ++++++++++++++++++++++++++++-
 drivers/gpu/drm/msm/adreno/a5xx_gpu.h      |   2 +
 drivers/gpu/drm/msm/adreno/adreno_device.c |   1 +
 drivers/gpu/drm/msm/adreno/adreno_gpu.h    |   1 +
 5 files changed, 183 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/Kconfig +1 -0
index 5b8e23d..b29bd30 100644
@@ -5,6 +5,7 @@ config DRM_MSM
 	depends on ARCH_QCOM || (ARM && COMPILE_TEST)
 	depends on OF && COMMON_CLK
 	depends on MMU
+	depends on QCOM_MDT_LOADER || QCOM_MDT_LOADER=n
 	select REGULATOR
 	select DRM_KMS_HELPER
 	select DRM_PANEL
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +178 -2

210 lines not on this page · raw message

drivers/gpu/drm/msm/adreno/a5xx_gpu.h +2 -0
index 1590f84..78408f5 100644
@@ -36,6 +36,8 @@ struct a5xx_gpu {
 	uint32_t gpmu_dwords;
 
 	uint32_t lm_leakage;
+
+	struct device zap_dev;
 };
 
 #define to_a5xx_gpu(x) container_of(x, struct a5xx_gpu, base)
drivers/gpu/drm/msm/adreno/adreno_device.c +1 -0
index c0fa5d1..b7bd6d3 100644
@@ -86,6 +86,7 @@
 			ADRENO_QUIRK_FAULT_DETECT_MASK,
 		.init = a5xx_gpu_init,
 		.gpmufw = "a530v3_gpmu.fw2",
+		.zapfw = "a530_zap.mdt",
 	},
 };
 
drivers/gpu/drm/msm/adreno/adreno_gpu.h +1 -0
index fb4831f..12b1483 100644
@@ -77,6 +77,7 @@ struct adreno_info {
 	uint32_t gmem;
 	enum adreno_quirks quirks;
 	struct msm_gpu *(*init)(struct drm_device *dev);
+	const char *zapfw;
 };
 
 const struct adreno_info *adreno_info(struct adreno_rev rev);
Signature · 1 line
1.9.1
Acked-by on v5 1/1
#1 lore raw
Quoted 70 lines · Jordan Crouse

The A5XX GPU powers on in "secure" mode. In secure mode the GPU can only render to buffers that are marked as secure and inaccessible to the kernel and user through a series of hardware protections. In practice secure mode is used to draw things like a UI on a secure video frame.

In order to switch out of secure mode the GPU executes a special shader that clears out the GMEM and other sensitve registers and then writes a register. Because the kernel can't be trusted the shader binary is signed and verified and programmed by the secure world. To do this we need to read the MDT header and the segments from the firmware location and put them in memory and present them for approval.

For targets without secure support there is an out: if the secure world doesn't support secure then there are no hardware protections and we can freely write the SECVID_TRUST register from the CPU. We don't have 100% confidence that we can query the secure capabilities at run time but we have enough calls that need to go right to give us some confidence that we're at least doing something useful.

Of course if we guess wrong you trigger a permissions violation which usually ends up in a system crash but thats a problem that shows up immediately.

[v2: use child device per Bjorn]
[v3: use generic MDT loader per Bjorn]
[v4: use managed dma functions and ifdefs for the MDT loader] [v5: Add depends for QCOM_MDT_LOADER]

---
 drivers/gpu/drm/msm/Kconfig                |   1 +
 drivers/gpu/drm/msm/adreno/a5xx_gpu.c      | 180 ++++++++++++++++++++++++++++-
 drivers/gpu/drm/msm/adreno/a5xx_gpu.h      |   2 +
 drivers/gpu/drm/msm/adreno/adreno_device.c |   1 +
 drivers/gpu/drm/msm/adreno/adreno_gpu.h    |   1 +
 5 files changed, 183 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/Kconfig +1 -0
index 5b8e23d..b29bd30 100644
@@ -5,6 +5,7 @@ config DRM_MSM
 	depends on ARCH_QCOM || (ARM && COMPILE_TEST)
 	depends on OF && COMMON_CLK
 	depends on MMU
+	depends on QCOM_MDT_LOADER || QCOM_MDT_LOADER=n
 	select REGULATOR
 	select DRM_KMS_HELPER
 	select DRM_PANEL
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +6 -0
index 31a9bce..058cb80 100644
@@ -11,6 +11,12 @@
  *
  */
 
+#include <linux/types.h>
+#include <linux/cpumask.h>
+#include <linux/qcom_scm.h>
+#include <linux/dma-mapping.h>
+#include <linux/of_reserved_mem.h>
+#include <linux/soc/qcom/mdt_loader.h>
 #include "msm_gem.h"
 #include "msm_mmu.h"
 #include "a5xx_gpu.h"

drivers/gpu/drm/msm/adreno/a5xx_gpu.c line 29

Quoted 6 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +3 -0
@@ -18,6 +24,62 @@
 extern bool hang_debug;
 static void a5xx_dump(struct msm_gpu *gpu);
 
+#define GPU_PAS_ID 13
+
+#ifdef CONFIG_QCOM_MDT_LOADER

#if IS_ENABLED(CONFIG_QCOM_MDT_LOADER)

Apart from that

Regards,
Bjorn