Adreno A5XX support
Subsystems (4)
cover Adreno A5XX support
All, here is initial kernel support for the Adreno A5XX family of GPUs found on the QTI Snapdragon 820 and 821 among others.
This stack turns on the A5XX hardware and initializes the GPMU (Graphics Power Management Unit) which is a microcontroller to assist with more independent power management. This initial stack is mainly concerned with getting the GPU/GPMU operational. Hopefully future improvements will actually tune it for better power.
The last three patches in the stack take the GPU out of "secure" mode. When the GPU is in secure mode it can only read/write from memory that is locked by the secure components of the SoC. By default the GPU comes up in secure mode - to get out of it we need to use SCM to load a special shader that "zaps" the persistent memory and registers and then we can execute a GPU command to take us out of secure. This code should compile cleanly against upstream but there are some changes coming in on other trees to make it functional for the Snapdragon 820/821.
And since the GPU isn't very interesting unless it can draw a triangle or two, Rob Clark has been hard at work on the user side of things and has a great chunk of functionality ready for Mesa:
https://lists.freedesktop.org/archives/freedreno/2016-November/000852.html
So I think this should be everything we need to make the A5XX useful for the community. Please enjoy.
Best regards,
Jordan
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/12 drm/msm: gpu: Cut down the list of "generic" registers to the ones we use
There are very few register accesses in the common code. Cut down the list of common registers to just those that are used. This saves const space and saves us the effort of maintaining registers for A3XX and A4XX that don't exist or are unused.
--- drivers/gpu/drm/msm/adreno/a3xx_gpu.c | 80 --------------------------------- drivers/gpu/drm/msm/adreno/a4xx_gpu.c | 76 ------------------------------- drivers/gpu/drm/msm/adreno/adreno_gpu.h | 59 ------------------------ 3 files changed, 215 deletions(-)
drivers/gpu/drm/msm/adreno/a3xx_gpu.c +0 -80
@@ -419,91 +419,11 @@ static void a3xx_dump(struct msm_gpu *gpu) }/* Register offset defines for A3XX */ static const unsigned int a3xx_register_offsets[REG_ADRENO_REGISTER_MAX ] = { -REG_ADRENO_DEFINE (REG_ADRENO_CP_DEBUG ,REG_AXXX_CP_DEBUG ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_ME_RAM_WADDR ,REG_AXXX_CP_ME_RAM_WADDR ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_ME_RAM_DATA ,REG_AXXX_CP_ME_RAM_DATA ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_PFP_UCODE_DATA , -REG_A3XX_CP_PFP_UCODE_DATA ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_PFP_UCODE_ADDR , -REG_A3XX_CP_PFP_UCODE_ADDR ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_WFI_PEND_CTR ,REG_A3XX_CP_WFI_PEND_CTR ),REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_BASE ,REG_AXXX_CP_RB_BASE ),REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR_ADDR ,REG_AXXX_CP_RB_RPTR_ADDR ),REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR ,REG_AXXX_CP_RB_RPTR ),REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_WPTR ,REG_AXXX_CP_RB_WPTR ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_PROTECT_CTRL ,REG_A3XX_CP_PROTECT_CTRL ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_ME_CNTL ,REG_AXXX_CP_ME_CNTL ),REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_CNTL ,REG_AXXX_CP_RB_CNTL ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_IB1_BASE ,REG_AXXX_CP_IB1_BASE ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_IB1_BUFSZ ,REG_AXXX_CP_IB1_BUFSZ ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_IB2_BASE ,REG_AXXX_CP_IB2_BASE ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_IB2_BUFSZ ,REG_AXXX_CP_IB2_BUFSZ ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_TIMESTAMP ,REG_AXXX_CP_SCRATCH_REG0 ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_ME_RAM_RADDR ,REG_AXXX_CP_ME_RAM_RADDR ), -REG_ADRENO_DEFINE (REG_ADRENO_SCRATCH_ADDR ,REG_AXXX_SCRATCH_ADDR ), -REG_ADRENO_DEFINE (REG_ADRENO_SCRATCH_UMSK ,REG_AXXX_SCRATCH_UMSK ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_ROQ_ADDR ,REG_A3XX_CP_ROQ_ADDR ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_ROQ_DATA ,REG_A3XX_CP_ROQ_DATA ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_MERCIU_ADDR ,REG_A3XX_CP_MERCIU_ADDR ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_MERCIU_DATA ,REG_A3XX_CP_MERCIU_DATA ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_MERCIU_DATA2 ,REG_A3XX_CP_MERCIU_DATA2 ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_MEQ_ADDR ,REG_A3XX_CP_MEQ_ADDR ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_MEQ_DATA ,REG_A3XX_CP_MEQ_DATA ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_HW_FAULT ,REG_A3XX_CP_HW_FAULT ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_PROTECT_STATUS , -REG_A3XX_CP_PROTECT_STATUS ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_STATUS ,REG_A3XX_RBBM_STATUS ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_PERFCTR_CTL , -REG_A3XX_RBBM_PERFCTR_CTL ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_PERFCTR_LOAD_CMD0 , -REG_A3XX_RBBM_PERFCTR_LOAD_CMD0 ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_PERFCTR_LOAD_CMD1 , -REG_A3XX_RBBM_PERFCTR_LOAD_CMD1 ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_PERFCTR_PWR_1_LO , -REG_A3XX_RBBM_PERFCTR_PWR_1_LO ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_INT_0_MASK ,REG_A3XX_RBBM_INT_0_MASK ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_INT_0_STATUS , -REG_A3XX_RBBM_INT_0_STATUS ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_AHB_ERROR_STATUS , -REG_A3XX_RBBM_AHB_ERROR_STATUS ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_AHB_CMD ,REG_A3XX_RBBM_AHB_CMD ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_INT_CLEAR_CMD , -REG_A3XX_RBBM_INT_CLEAR_CMD ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_CLOCK_CTL ,REG_A3XX_RBBM_CLOCK_CTL ), -REG_ADRENO_DEFINE (REG_ADRENO_VPC_DEBUG_RAM_SEL , -REG_A3XX_VPC_VPC_DEBUG_RAM_SEL ), -REG_ADRENO_DEFINE (REG_ADRENO_VPC_DEBUG_RAM_READ , -REG_A3XX_VPC_VPC_DEBUG_RAM_READ ), -REG_ADRENO_DEFINE (REG_ADRENO_VSC_SIZE_ADDRESS , -REG_A3XX_VSC_SIZE_ADDRESS ), -REG_ADRENO_DEFINE (REG_ADRENO_VFD_CONTROL_0 ,REG_A3XX_VFD_CONTROL_0 ), -REG_ADRENO_DEFINE (REG_ADRENO_VFD_INDEX_MAX ,REG_A3XX_VFD_INDEX_MAX ), -REG_ADRENO_DEFINE (REG_ADRENO_SP_VS_PVT_MEM_ADDR_REG , -REG_A3XX_SP_VS_PVT_MEM_ADDR_REG ), -REG_ADRENO_DEFINE (REG_ADRENO_SP_FS_PVT_MEM_ADDR_REG , -REG_A3XX_SP_FS_PVT_MEM_ADDR_REG ), -REG_ADRENO_DEFINE (REG_ADRENO_SP_VS_OBJ_START_REG , -REG_A3XX_SP_VS_OBJ_START_REG ), -REG_ADRENO_DEFINE (REG_ADRENO_SP_FS_OBJ_START_REG , -REG_A3XX_SP_FS_OBJ_START_REG ), -REG_ADRENO_DEFINE (REG_ADRENO_PA_SC_AA_CONFIG ,REG_A3XX_PA_SC_AA_CONFIG ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_PM_OVERRIDE2 , -REG_A3XX_RBBM_PM_OVERRIDE2 ), -REG_ADRENO_DEFINE (REG_ADRENO_SCRATCH_REG2 ,REG_AXXX_CP_SCRATCH_REG2 ), -REG_ADRENO_DEFINE (REG_ADRENO_SQ_GPR_MANAGEMENT , -REG_A3XX_SQ_GPR_MANAGEMENT ), -REG_ADRENO_DEFINE (REG_ADRENO_SQ_INST_STORE_MANAGMENT , -REG_A3XX_SQ_INST_STORE_MANAGMENT ), -REG_ADRENO_DEFINE (REG_ADRENO_TP0_CHICKEN ,REG_A3XX_TP0_CHICKEN ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_RBBM_CTL ,REG_A3XX_RBBM_RBBM_CTL ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_SW_RESET_CMD , -REG_A3XX_RBBM_SW_RESET_CMD ), -REG_ADRENO_DEFINE (REG_ADRENO_UCHE_INVALIDATE0 , -REG_A3XX_UCHE_CACHE_INVALIDATE0_REG ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_PERFCTR_LOAD_VALUE_LO , -REG_A3XX_RBBM_PERFCTR_LOAD_VALUE_LO ), -REG_ADRENO_DEFINE (REG_ADRENO_RBBM_PERFCTR_LOAD_VALUE_HI , -REG_A3XX_RBBM_PERFCTR_LOAD_VALUE_HI ), };static const struct adreno_gpu_funcs funcs = {
drivers/gpu/drm/msm/adreno/a4xx_gpu.c +0 -76
87 lines not on this page · raw message
drivers/gpu/drm/msm/adreno/adreno_gpu.h +0 -59
70 lines not on this page · raw message
Signature · 1 line
1.9.1
A message that is not in the archive (sent off-list or not yet received): 1480361317-9937-1-git-send-email-jcrouse-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org
PATCH 2/12 drm/msm: gpu: Return error on hw_init failure
When the GPU hardware init function fails (like say, ME_INIT timed out) return error instead of blindly continuing on. This gives us a small chance of saving the system before it goes boom.
--- drivers/gpu/drm/msm/adreno/a3xx_gpu.c | 21 ++++++++++++--------- drivers/gpu/drm/msm/adreno/a4xx_gpu.c | 20 +++++++++++--------- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 11 +++++------ drivers/gpu/drm/msm/adreno/adreno_gpu.h | 2 +- drivers/gpu/drm/msm/msm_gpu.h | 2 +- 5 files changed, 30 insertions(+), 26 deletions(-)
drivers/gpu/drm/msm/adreno/a3xx_gpu.c +12 -9
@@ -41,7 +41,7 @@ extern bool hang_debug;static void a3xx_dump (struct msm_gpu *gpu); -static void a3xx_me_init (struct msm_gpu *gpu) +static bool a3xx_me_init (struct msm_gpu *gpu) {struct msm_ringbuffer *ring = gpu->rb;
@@ -65,7 +65,7 @@ static void a3xx_me_init(struct msm_gpu *gpu)OUT_RING (ring,0x00000000 ); gpu->funcs->flush (gpu); - gpu->funcs->idle (gpu); +return gpu->funcs->idle (gpu); }static int a3xx_hw_init (struct msm_gpu *gpu)
@@ -294,9 +294,7 @@ static int a3xx_hw_init(struct msm_gpu *gpu)/* clear ME_HALT to start micro engine */ gpu_write (gpu,REG_AXXX_CP_ME_CNTL ,0 ); -a3xx_me_init (gpu); - -return 0 ; +return a3xx_me_init (gpu) ?0 : -EINVAL ; }static void a3xx_recover (struct msm_gpu *gpu)
@@ -330,17 +328,22 @@ static void a3xx_destroy(struct msm_gpu *gpu)kfree (a3xx_gpu); } -static void a3xx_idle (struct msm_gpu *gpu) +static bool a3xx_idle (struct msm_gpu *gpu) {/* wait for ringbuffer to drain: */ -adreno_idle (gpu); +if (!adreno_idle (gpu)) +return false;/* then wait for GPU to finish: */ if (spin_until (!(gpu_read (gpu,REG_A3XX_RBBM_STATUS ) & -A3XX_RBBM_STATUS_GPU_BUSY ))) +A3XX_RBBM_STATUS_GPU_BUSY ))) {DRM_ERROR ("%s: timeout waiting for GPU to idle!\n" , gpu->name); -/* TODO maybe we need to reset GPU here to recover from hang? */ +/* TODO maybe we need to reset GPU here to recover from hang? */ +return false; + } + +return true; }static irqreturn_t a3xx_irq (struct msm_gpu *gpu)
drivers/gpu/drm/msm/adreno/a4xx_gpu.c +11 -9
@@ -113,7 +113,7 @@ static void a4xx_enable_hwcg(struct msm_gpu *gpu) } -static void a4xx_me_init (struct msm_gpu *gpu) +static bool a4xx_me_init (struct msm_gpu *gpu) {struct msm_ringbuffer *ring = gpu->rb;
@@ -137,7 +137,7 @@ static void a4xx_me_init(struct msm_gpu *gpu)OUT_RING (ring,0x00000000 ); gpu->funcs->flush (gpu); - gpu->funcs->idle (gpu); +return gpu->funcs->idle (gpu); }static int a4xx_hw_init (struct msm_gpu *gpu)
@@ -292,9 +292,7 @@ static int a4xx_hw_init(struct msm_gpu *gpu)/* clear ME_HALT to start micro engine */ gpu_write (gpu,REG_A4XX_CP_ME_CNTL ,0 ); -a4xx_me_init (gpu); - -return 0 ; +return a4xx_me_init (gpu) ?0 : -EINVAL ; }static void a4xx_recover (struct msm_gpu *gpu)
@@ -328,17 +326,21 @@ static void a4xx_destroy(struct msm_gpu *gpu)kfree (a4xx_gpu); } -static void a4xx_idle (struct msm_gpu *gpu) +static bool a4xx_idle (struct msm_gpu *gpu) {/* wait for ringbuffer to drain: */ -adreno_idle (gpu); +if (!adreno_idle (gpu)) +return false;/* then wait for GPU to finish: */ if (spin_until (!(gpu_read (gpu,REG_A4XX_RBBM_STATUS ) & -A4XX_RBBM_STATUS_GPU_BUSY ))) +A4XX_RBBM_STATUS_GPU_BUSY ))) {DRM_ERROR ("%s: timeout waiting for GPU to idle!\n" , gpu->name); +/* TODO maybe we need to reset GPU here to recover from hang? */ +return false; + } -/* TODO maybe we need to reset GPU here to recover from hang? */ +return true; }static irqreturn_t a4xx_irq (struct msm_gpu *gpu)
drivers/gpu/drm/msm/adreno/adreno_gpu.c +5 -6
@@ -218,19 +218,18 @@ void adreno_flush(struct msm_gpu *gpu)adreno_gpu_write (adreno_gpu,REG_ADRENO_CP_RB_WPTR , wptr); } -void adreno_idle (struct msm_gpu *gpu) +bool adreno_idle (struct msm_gpu *gpu) {struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu);uint32_t wptr =get_wptr (gpu->rb); -int ret;/* wait for CP to drain ringbuffer: */ - ret =spin_until (get_rptr (adreno_gpu) == wptr); - -if (ret) -DRM_ERROR ("%s: timeout waiting to drain ringbuffer!\n" , gpu->name); +if (!spin_until (get_rptr (adreno_gpu) == wptr)) +return true;/* TODO maybe we need to reset GPU here to recover from hang? */ +DRM_ERROR ("%s: timeout waiting to drain ringbuffer!\n" , gpu->name); +return false; }#ifdef CONFIG_DEBUG_FS
drivers/gpu/drm/msm/adreno/adreno_gpu.h +1 -1
@@ -182,7 +182,7 @@ void adreno_recover(struct msm_gpu *gpu);void adreno_submit (struct msm_gpu *gpu,struct msm_gem_submit *submit,struct msm_file_private *ctx);void adreno_flush (struct msm_gpu *gpu); -void adreno_idle (struct msm_gpu *gpu); +bool adreno_idle (struct msm_gpu *gpu);#ifdef CONFIG_DEBUG_FS void adreno_show (struct msm_gpu *gpu,struct seq_file *m);#endif
drivers/gpu/drm/msm/msm_gpu.h +1 -1
@@ -50,7 +50,7 @@ struct msm_gpu_funcs {void (*submit)(struct msm_gpu *gpu,struct msm_gem_submit *submit,struct msm_file_private *ctx);void (*flush)(struct msm_gpu *gpu); -void (*idle)(struct msm_gpu *gpu); +bool (*idle)(struct msm_gpu *gpu);irqreturn_t (*irq)(struct msm_gpu *irq);uint32_t (*last_fence)(struct msm_gpu *gpu);void (*recover)(struct msm_gpu *gpu);
Signature · 6 lines
1.9.1 _______________________________________________ Freedreno mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/freedreno
PATCH 5/12 drm/msm: gpu: Add OUT_TYPE4 and OUT_TYPE7
In reply to a message not in the archiveAdd helper functions for TYPE4 and TYPE7 ME opcodes that replace TYPE0 and TYPE3 starting with the A5XX targets.
--- drivers/gpu/drm/msm/adreno/adreno_gpu.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/gpu/drm/msm/adreno/adreno_gpu.h +30 -0
@@ -224,6 +224,36 @@ OUT_PKT3(struct msm_ringbuffer *ring, uint8_t opcode, uint16_t cnt)OUT_RING (ring,CP_TYPE3_PKT | ((cnt-1 ) <<16 ) | ((opcode &0xFF ) <<8 )); } +static inline u32 PM4_PARITY (u32 val) +{ +return (0x9669 >> (0xF & (val ^ + (val >>4 ) ^ (val >>8 ) ^ (val >>12 ) ^ + (val >>16 ) ^ ((val) >>20 ) ^ (val >>24 ) ^ + (val >>28 )))) &1 ; +} + +/* Maximum number of values that can be executed for one opcode */ +#define TYPE4_MAX_PAYLOAD 127 + +#define PKT4 (_reg, _cnt) \ + (CP_TYPE4_PKT | ((_cnt) << 0) | (PM4_PARITY((_cnt)) << 7) | \ + (((_reg) & 0x3FFFF) << 8) | (PM4_PARITY((_reg)) << 27)) + +static inline void +OUT_PKT4 (struct msm_ringbuffer *ring,uint16_t regindx,uint16_t cnt) +{ +adreno_wait_ring (ring->gpu, cnt +1 ); +OUT_RING (ring,PKT4 (regindx, cnt)); +} + +static inline void +OUT_PKT7 (struct msm_ringbuffer *ring,uint8_t opcode,uint16_t cnt) +{ +adreno_wait_ring (ring->gpu, cnt +1 ); +OUT_RING (ring,CP_TYPE7_PKT | (cnt <<0 ) | (PM4_PARITY (cnt) <<15 ) | + ((opcode &0x7F ) <<16 ) | (PM4_PARITY (opcode) <<23 )); +} +/* * adreno_reg_check() - Checks the validity of a register enum * @gpu: Pointer to struct adreno_gpu
Signature · 6 lines
1.9.1 _______________________________________________ Freedreno mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/freedreno
PATCH 6/12 drm/msm: Remove 'src_clk' from adreno configuration
In reply to a message not in the archiveThe adreno code inherited a silly workaround from downstream from the bad old days before decent clock control. grp_clk[0] (named 'src_clk') doesn't actually exist - it was used as a proxy for whatever the core clock actually was (usually 'core_clk').
All targets should be able to correctly request 'core_clk' and get the right thing back so zap the anachronism and directly use grp_clk[0] to control the clock rate.
--- drivers/gpu/drm/msm/msm_gpu.c | 36 +++++++++++++----------------------- drivers/gpu/drm/msm/msm_gpu.h | 2 +- 2 files changed, 14 insertions(+), 24 deletions(-)
drivers/gpu/drm/msm/msm_gpu.c +13 -23
@@ -91,21 +91,16 @@ static int disable_pwrrail(struct msm_gpu *gpu)static int enable_clk (struct msm_gpu *gpu) { -struct clk *rate_clk =NULL ;int i; -/* NOTE: kgsl_pwrctrl_clk() ignores grp_clks[0].. */ -for (i =ARRAY_SIZE (gpu->grp_clks) -1 ; i >0 ; i--) { -if (gpu->grp_clks[i]) { -clk_prepare (gpu->grp_clks[i]); - rate_clk = gpu->grp_clks[i]; - } - } +if (gpu->grp_clks[0 ] && gpu->fast_rate) +clk_set_rate (gpu->grp_clks[0 ], gpu->fast_rate); -if (rate_clk && gpu->fast_rate) -clk_set_rate (rate_clk, gpu->fast_rate); +for (i =ARRAY_SIZE (gpu->grp_clks) -1 ; i >=0 ; i--) +if (gpu->grp_clks[i]) +clk_prepare (gpu->grp_clks[i]); -for (i =ARRAY_SIZE (gpu->grp_clks) -1 ; i >0 ; i--) +for (i =ARRAY_SIZE (gpu->grp_clks) -1 ; i >=0 ; i--)if (gpu->grp_clks[i])clk_enable (gpu->grp_clks[i]);
@@ -114,24 +109,19 @@ static int enable_clk(struct msm_gpu *gpu)static int disable_clk (struct msm_gpu *gpu) { -struct clk *rate_clk =NULL ;int i; -/* NOTE: kgsl_pwrctrl_clk() ignores grp_clks[0].. */ -for (i =ARRAY_SIZE (gpu->grp_clks) -1 ; i >0 ; i--) { -if (gpu->grp_clks[i]) { +for (i =ARRAY_SIZE (gpu->grp_clks) -1 ; i >=0 ; i--) +if (gpu->grp_clks[i])clk_disable (gpu->grp_clks[i]); - rate_clk = gpu->grp_clks[i]; - } - } -if (rate_clk && gpu->slow_rate) -clk_set_rate (rate_clk, gpu->slow_rate); - -for (i =ARRAY_SIZE (gpu->grp_clks) -1 ; i >0 ; i--) +for (i =ARRAY_SIZE (gpu->grp_clks) -1 ; i >=0 ; i--)if (gpu->grp_clks[i])clk_unprepare (gpu->grp_clks[i]); +if (gpu->grp_clks[0 ] && gpu->slow_rate) +clk_set_rate (gpu->grp_clks[0 ], gpu->slow_rate); +return 0 ; }
@@ -572,7 +562,7 @@ static irqreturn_t irq_handler(int irq, void *data) }static const char *clk_names[] = { -"src_clk" ,"core_clk" ,"iface_clk" ,"mem_clk" ,"mem_iface_clk" , +"core_clk" ,"iface_clk" ,"mem_clk" ,"mem_iface_clk" ,"alt_mem_iface_clk" , };
drivers/gpu/drm/msm/msm_gpu.h +1 -1
@@ -103,7 +103,7 @@ struct msm_gpu {/* Power Control: */ struct regulator *gpu_reg, *gpu_cx; -struct clk *ebi1_clk, *grp_clks[6 ]; +struct clk *ebi1_clk, *grp_clks[5 ];uint32_t fast_rate, slow_rate, bus_freq;#ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
Signature · 6 lines
1.9.1 _______________________________________________ Freedreno mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/freedreno
PATCH 3/12 drm/msm: gpu Add new gpu register read/write functions
In reply to Jordan CrouseAdd some new functions to manipulate GPU registers. gpu_read64 and gpu_write64 can read/write a 64 bit value to two 32 bit registers. For 4XX and older these are normally perfcounter registers, but future targets will use 64 bit addressing so there will be many more spots where a 64 bit read and write are needed.
gpu_rmw() does a read/modify/write on a 32 bit register given a mask and bits to OR in.
--- drivers/gpu/drm/msm/adreno/a4xx_gpu.c | 12 ++--------- drivers/gpu/drm/msm/msm_gpu.h | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-)
drivers/gpu/drm/msm/adreno/a4xx_gpu.c +2 -10
@@ -513,16 +513,8 @@ static int a4xx_pm_suspend(struct msm_gpu *gpu) {static int a4xx_get_timestamp (struct msm_gpu *gpu,uint64_t *value) { -uint32_t hi, lo, tmp; - - tmp =gpu_read (gpu,REG_A4XX_RBBM_PERFCTR_CP_0_HI ); -do { - hi = tmp; - lo =gpu_read (gpu,REG_A4XX_RBBM_PERFCTR_CP_0_LO ); - tmp =gpu_read (gpu,REG_A4XX_RBBM_PERFCTR_CP_0_HI ); - }while (tmp != hi); - - *value = (((uint64_t )hi) <<32 ) | lo; + *value =gpu_read64 (gpu,REG_A4XX_RBBM_PERFCTR_CP_0_LO , +REG_A4XX_RBBM_PERFCTR_CP_0_HI );return 0 ; }
drivers/gpu/drm/msm/msm_gpu.h +39 -0
@@ -154,6 +154,45 @@ static inline u32 gpu_read(struct msm_gpu *gpu, u32 reg)return msm_readl (gpu->mmio + (reg <<2 )); } +static inline void gpu_rmw (struct msm_gpu *gpu,u32 reg,u32 mask,u32 or) +{ +uint32_t val =gpu_read (gpu, reg); + + val &= ~mask; +gpu_write (gpu, reg, val | or); +} + +static inline u64 gpu_read64 (struct msm_gpu *gpu,u32 lo,u32 hi) +{ +u64 val; + +/* +* Why not a readq here? Two reasons: 1) many of the LO registers are +* not quad word aligned and 2) the GPU hardware designers have a bit +* of a history of putting registers where they fit, especially in +* spins. The longer a GPU family goes the higher the chance that +* we'll get burned. We could do a series of validity checks if we +* wanted to, but really is a readq() that much better? Nah. +*/ + +/* +* For some lo/hi registers (like perfcounters), the hi value is latched +* when the lo is read, so make sure to read the lo first to trigger +* that +*/ + val = (u64 )msm_readl (gpu->mmio + (lo <<2 )); + val |= ((u64 )msm_readl (gpu->mmio + (hi <<2 )) <<32 ); + +return val; +} + +static inline void gpu_write64 (struct msm_gpu *gpu,u32 lo,u32 hi,u64 val) +{ +/* Why not a writeq here? Read the screed above */ +msm_writel (lower_32_bits (val), gpu->mmio + (lo <<2 )); +msm_writel (upper_32_bits (val), gpu->mmio + (hi <<2 )); +} +int msm_gpu_pm_suspend (struct msm_gpu *gpu);int msm_gpu_pm_resume (struct msm_gpu *gpu);
Signature · 1 line
1.9.1
PATCH 4/12 drm/msm: Add adreno_gpu_write64()
In reply to Jordan CrouseAdd a new generic function to write a "64" bit value. This isn't actually a 64 bit operation, it just writes the upper and lower 32 bit of a 64 bit value to a specified LO and HI register. If a particular target doesn't support one of the registers it can mark that register as SKIP and writes/reads from that register will be quietly dropped.
This can be immediately put in place for the ringbuffer base and the RPTR address. Both writes are converted to use adreno_gpu_write64() with their respective high and low registers and the high register appropriately marked as SKIP for both 32 bit targets (a3xx and a4xx). When a5xx comes it will define valid target registers for the 'hi' option and everything else will just work.
--- drivers/gpu/drm/msm/adreno/a3xx_gpu.c | 2 ++ drivers/gpu/drm/msm/adreno/a4xx_gpu.c | 2 ++ drivers/gpu/drm/msm/adreno/adreno_gpu.c | 11 +++++++---- drivers/gpu/drm/msm/adreno/adreno_gpu.h | 24 +++++++++++++++++++++++- 4 files changed, 34 insertions(+), 5 deletions(-)
drivers/gpu/drm/msm/adreno/a3xx_gpu.c +2 -0
@@ -423,7 +423,9 @@ static void a3xx_dump(struct msm_gpu *gpu)/* Register offset defines for A3XX */ static const unsigned int a3xx_register_offsets[REG_ADRENO_REGISTER_MAX ] = {REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_BASE ,REG_AXXX_CP_RB_BASE ), +REG_ADRENO_SKIP (REG_ADRENO_CP_RB_BASE_HI ),REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR_ADDR ,REG_AXXX_CP_RB_RPTR_ADDR ), +REG_ADRENO_SKIP (REG_ADRENO_CP_RB_RPTR_ADDR_HI ),REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR ,REG_AXXX_CP_RB_RPTR ),REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_WPTR ,REG_AXXX_CP_RB_WPTR ),REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_CNTL ,REG_AXXX_CP_RB_CNTL ),
drivers/gpu/drm/msm/adreno/a4xx_gpu.c +2 -0
@@ -463,7 +463,9 @@ static void a4xx_show(struct msm_gpu *gpu, struct seq_file *m)/* Register offset defines for A4XX, in order of enum adreno_regs */ static const unsigned int a4xx_register_offsets[REG_ADRENO_REGISTER_MAX ] = {REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_BASE ,REG_A4XX_CP_RB_BASE ), +REG_ADRENO_SKIP (REG_ADRENO_CP_RB_BASE_HI ),REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR_ADDR ,REG_A4XX_CP_RB_RPTR_ADDR ), +REG_ADRENO_SKIP (REG_ADRENO_CP_RB_RPTR_ADDR_HI ),REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR ,REG_A4XX_CP_RB_RPTR ),REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_WPTR ,REG_A4XX_CP_RB_WPTR ),REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_CNTL ,REG_A4XX_CP_RB_CNTL ),
drivers/gpu/drm/msm/adreno/adreno_gpu.c +7 -4
@@ -79,11 +79,14 @@ int adreno_hw_init(struct msm_gpu *gpu) (adreno_is_a430(adreno_gpu) ? AXXX_CP_RB_CNTL_NO_UPDATE : 0));/* Setup ringbuffer address: */ -adreno_gpu_write (adreno_gpu,REG_ADRENO_CP_RB_BASE , gpu->rb_iova); +adreno_gpu_write64 (adreno_gpu,REG_ADRENO_CP_RB_BASE , +REG_ADRENO_CP_RB_BASE_HI , gpu->rb_iova); -if (!adreno_is_a430 (adreno_gpu)) -adreno_gpu_write (adreno_gpu,REG_ADRENO_CP_RB_RPTR_ADDR , -rbmemptr (adreno_gpu, rptr)); +if (!adreno_is_a430 (adreno_gpu)) { +adreno_gpu_write64 (adreno_gpu,REG_ADRENO_CP_RB_RPTR_ADDR , +REG_ADRENO_CP_RB_RPTR_ADDR_HI , +rbmemptr (adreno_gpu, rptr)); + }return 0 ; }
drivers/gpu/drm/msm/adreno/adreno_gpu.h +23 -1
@@ -28,6 +28,9 @@#include "adreno_pm4.xml.h" #define REG_ADRENO_DEFINE (_offset, _reg) [_offset] = (_reg) + 1 +#define REG_SKIP ~0 +#define REG_ADRENO_SKIP (_offset) [_offset] = REG_SKIP +/** * adreno_regs: List of registers that are used in across all * 3D devices. Each device type has different offset value for the same
@@ -36,7 +39,9 @@*/ enum adreno_regs {REG_ADRENO_CP_RB_BASE , +REG_ADRENO_CP_RB_BASE_HI ,REG_ADRENO_CP_RB_RPTR_ADDR , +REG_ADRENO_CP_RB_RPTR_ADDR_HI ,REG_ADRENO_CP_RB_RPTR ,REG_ADRENO_CP_RB_WPTR ,REG_ADRENO_CP_RB_CNTL ,
@@ -220,7 +225,7 @@ OUT_PKT3(struct msm_ringbuffer *ring, uint8_t opcode, uint16_t cnt) }/* -* adreno_checkreg_off() - Checks the validity of a register enum +* adreno_reg_check() - Checks the validity of a register enum * @gpu: Pointer to struct adreno_gpu * @offset_name: The register enum that is checked */
@@ -231,6 +236,16 @@ static inline bool adreno_reg_check(struct adreno_gpu *gpu, !gpu->reg_offsets[offset_name]) {BUG (); } + +/* +* REG_SKIP is a special value that tell us that the register in +* question isn't implemented on target but don't trigger a BUG(). This +* is used to cleanly implement adreno_gpu_write64() and +* adreno_gpu_read64() in a generic fashion +*/ +if (gpu->reg_offsets[offset_name] ==REG_SKIP ) +return false; +return true; }
@@ -252,4 +267,11 @@ static inline void adreno_gpu_write(struct adreno_gpu *gpu, gpu_write(&gpu->base, reg - 1, data); } +static inline void adreno_gpu_write64 (struct adreno_gpu *gpu, +enum adreno_regs lo,enum adreno_regs hi,u64 data) +{ +adreno_gpu_write (gpu, lo,lower_32_bits (data)); +adreno_gpu_write (gpu, hi,upper_32_bits (data)); +} +#endif /* __ADRENO_GPU_H__ */
Signature · 1 line
1.9.1
PATCH 7/12 drm/msm: Disable interrupts during init
In reply to Jordan CrouseDisable the interrupt during the init sequence to avoid having interrupts fired for errors and other things that we are not ready to handle while initializing.
--- drivers/gpu/drm/msm/adreno/adreno_device.c | 4 ++++ drivers/gpu/drm/msm/adreno/adreno_gpu.c | 3 +++ 2 files changed, 7 insertions(+)
drivers/gpu/drm/msm/adreno/adreno_device.c +4 -0
@@ -148,12 +148,16 @@ struct msm_gpu *adreno_load_gpu(struct drm_device *dev)mutex_lock (&dev->struct_mutex); gpu->funcs->pm_resume (gpu);mutex_unlock (&dev->struct_mutex); + +disable_irq (gpu->irq); + ret = gpu->funcs->hw_init (gpu);if (ret) {dev_err (dev->dev,"gpu hw init failed: %d\n" , ret); gpu->funcs->destroy (gpu); gpu =NULL ; }else { +enable_irq (gpu->irq);/* give inactive pm a chance to kick in: */ msm_gpu_retire (gpu); }
drivers/gpu/drm/msm/adreno/adreno_gpu.c +3 -0
@@ -129,11 +129,14 @@ void adreno_recover(struct msm_gpu *gpu) adreno_gpu->memptrs->wptr =0 ; gpu->funcs->pm_resume (gpu); + +disable_irq (gpu->irq); ret = gpu->funcs->hw_init (gpu);if (ret) {dev_err (dev->dev,"gpu hw init failed: %d\n" , ret);/* hmm, oh well? */ } +enable_irq (gpu->irq); } void adreno_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
Signature · 1 line
1.9.1
PATCH 8/12 drm/msm: gpu: Add A5XX target support
In reply to Jordan CrouseAdd support for the A5XX family of Adreno GPUs.
--- drivers/gpu/drm/msm/Makefile | 1 + drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 823 +++++++++++++++++++++++++++++ drivers/gpu/drm/msm/adreno/a5xx_gpu.h | 37 ++ drivers/gpu/drm/msm/adreno/adreno_device.c | 25 +- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 6 +- drivers/gpu/drm/msm/adreno/adreno_gpu.h | 40 ++ drivers/gpu/drm/msm/msm_gpu.c | 13 +- drivers/gpu/drm/msm/msm_gpu.h | 2 +- 8 files changed, 938 insertions(+), 9 deletions(-) create mode 100644 drivers/gpu/drm/msm/adreno/a5xx_gpu.c create mode 100644 drivers/gpu/drm/msm/adreno/a5xx_gpu.h
drivers/gpu/drm/msm/Makefile +1 -0
@@ -6,6 +6,7 @@ msm-y := \ adreno/adreno_gpu.o \ adreno/a3xx_gpu.o \ adreno/a4xx_gpu.o \ + adreno/a5xx_gpu.o \ hdmi/hdmi.o \ hdmi/hdmi_audio.o \ hdmi/hdmi_bridge.o \
drivers/gpu/drm/msm/adreno/a5xx_gpu.c new file +823 -0
823 lines not on this page · raw message
drivers/gpu/drm/msm/adreno/a5xx_gpu.h new file +37 -0
@@ -0,0 +1,37 @@ +/* Copyright (c) 2016 The Linux Foundation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ +#ifndef __A5XX_GPU_H__ +#define __A5XX_GPU_H__ + +#include "adreno_gpu.h" + +/* Bringing over the hack from the previous targets */ +#undef ROP_COPY +#undef ROP_XOR + +#include "a5xx.xml.h" + +struct a5xx_gpu { +struct adreno_gpu base; +struct platform_device *pdev; + +struct drm_gem_object *pm4_bo; +uint64_t pm4_iova; + +struct drm_gem_object *pfp_bo; +uint64_t pfp_iova; +}; + +#define to_a5xx_gpu (x) container_of(x, struct a5xx_gpu, base) + +#endif /* __A5XX_GPU_H__ */
drivers/gpu/drm/msm/adreno/adreno_device.c +24 -1
@@ -27,6 +27,7 @@ module_param_named(hang_debug, hang_debug, bool, 0600);struct msm_gpu *a3xx_gpu_init (struct drm_device *dev);struct msm_gpu *a4xx_gpu_init (struct drm_device *dev); +struct msm_gpu *a5xx_gpu_init (struct drm_device *dev);static const struct adreno_info gpulist[] = { {
@@ -77,6 +78,14 @@ static const struct adreno_info gpulist[] = { .pfpfw = "a420_pfp.fw", .gmem = (SZ_1M + SZ_512K), .init = a4xx_gpu_init, + }, { + .rev = ADRENO_REV(5, 3, 0, ANY_ID), + .revn = 530, + .name = "A530", + .pm4fw = "a530_pm4.fw", + .pfpfw = "a530_pfp.fw", + .gmem = SZ_1M, + .init = a5xx_gpu_init, }, };
@@ -86,6 +95,8 @@ MODULE_FIRMWARE("a330_pm4.fw");MODULE_FIRMWARE ("a330_pfp.fw" );MODULE_FIRMWARE ("a420_pm4.fw" );MODULE_FIRMWARE ("a420_pfp.fw" ); +MODULE_FIRMWARE ("a530_fm4.fw" ); +MODULE_FIRMWARE ("a530_pfp.fw" );static inline bool _rev_match (uint8_t entry,uint8_t id) {
@@ -173,12 +184,20 @@ static void set_gpu_pdev(struct drm_device *dev, priv->gpu_pdev = pdev; } +static const struct { +const char *str; +uint32_t flag; +} quirks[] = { + {"qcom,gpu-quirk-two-pass-use-wfi" ,ADRENO_QUIRK_TWO_PASS_USE_WFI }, + {"qcom,gpu-quirk-fault-detect-mask" ,ADRENO_QUIRK_FAULT_DETECT_MASK }, +}; +static int adreno_bind (struct device *dev,struct device *master,void *data) {static struct adreno_platform_config config = {};struct device_node *child, *node = dev->of_node;u32 val; -int ret; +int ret, i; ret =of_property_read_u32 (node,"qcom,chipid" , &val);if (ret) {
@@ -212,6 +231,10 @@ static int adreno_bind(struct device *dev, struct device *master, void *data)return -ENXIO ; } +for (i =0 ; i <ARRAY_SIZE (quirks); i++) +if (of_property_read_bool (node, quirks[i].str)) + config.quirks |= quirks[i].flag; + dev->platform_data = &config;set_gpu_pdev (dev_get_drvdata (master),to_platform_device (dev));return 0 ;
drivers/gpu/drm/msm/adreno/adreno_gpu.c +2 -4
@@ -22,7 +22,7 @@#include "msm_mmu.h" #define RB_SIZE SZ_32K -#define RB_BLKSIZE 16 +#define RB_BLKSIZE 32int adreno_get_param (struct msm_gpu *gpu,uint32_t param,uint64_t *value) {
@@ -54,9 +54,6 @@ int adreno_get_param(struct msm_gpu *gpu, uint32_t param, uint64_t *value) } } -#define rbmemptr (adreno_gpu, member) \ - ((adreno_gpu)->memptrs_iova + offsetof(struct adreno_rbmemptrs, member)) -int adreno_hw_init (struct msm_gpu *gpu) {struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu);
@@ -355,6 +352,7 @@ int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev, adreno_gpu->gmem = adreno_gpu->info->gmem; adreno_gpu->revn = adreno_gpu->info->revn; adreno_gpu->rev = config->rev; + adreno_gpu->quirks = config->quirks; gpu->fast_rate = config->fast_rate; gpu->slow_rate = config->slow_rate;
drivers/gpu/drm/msm/adreno/adreno_gpu.h +40 -0
@@ -48,6 +48,11 @@ enum adreno_regs { REG_ADRENO_REGISTER_MAX, }; +enum adreno_quirks { +ADRENO_QUIRK_TWO_PASS_USE_WFI =1 , +ADRENO_QUIRK_FAULT_DETECT_MASK =2 , +}; +struct adreno_rev {uint8_t core;uint8_t major;
@@ -74,6 +79,9 @@ struct adreno_info {const struct adreno_info *adreno_info (struct adreno_rev rev); +#define rbmemptr (adreno_gpu, member) \ + ((adreno_gpu)->memptrs_iova + offsetof(struct adreno_rbmemptrs, member)) +struct adreno_rbmemptrs {volatile uint32_t rptr;volatile uint32_t wptr;
@@ -107,6 +115,8 @@ struct adreno_gpu {* code (a3xx_gpu.c) and stored in this common location. */ const unsigned int *reg_offsets; + +uint32_t quirks; };#define to_adreno_gpu (x) container_of(x, struct adreno_gpu, base)
@@ -117,6 +127,7 @@ struct adreno_platform_config {#ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING struct msm_bus_scale_pdata *bus_scale_table;#endif +uint32_t quirks; };#define ADRENO_IDLE_TIMEOUT msecs_to_jiffies(1000)
@@ -180,6 +191,11 @@ static inline int adreno_is_a430(struct adreno_gpu *gpu)return gpu->revn ==430 ; } +static inline int adreno_is_a530 (struct adreno_gpu *gpu) +{ +return gpu->revn ==530 ; +} +int adreno_get_param (struct msm_gpu *gpu,uint32_t param,uint64_t *value);int adreno_hw_init (struct msm_gpu *gpu);uint32_t adreno_last_fence (struct msm_gpu *gpu);
@@ -304,4 +320,28 @@ static inline void adreno_gpu_write64(struct adreno_gpu *gpu, adreno_gpu_write(gpu, hi, upper_32_bits(data)); } +/* +* Given a register and a count, return a value to program into +* REG_CP_PROTECT_REG(n) - this will block both reads and writes for _len +* registers starting at _reg. +* +* The register base needs to be a multiple of the length. If it is not, the +* hardware will quietly mask off the bits for you and shift the size. For +* example, if you intend the protection to start at 0x07 for a length of 4 +* (0x07-0x0A) the hardware will actually protect (0x04-0x07) which might +* expose registers you intended to protect! +*/ +#define ADRENO_PROTECT_RW (_reg, _len) \ + ((1 << 30) | (1 << 29) | \ + ((ilog2((_len)) & 0x1F) << 24) | (((_reg) << 2) & 0xFFFFF)) + +/* +* Same as above, but allow reads over the range. For areas of mixed use (such +* as performance counters) this allows us to protect a much larger range with a +* single register +*/ +#define ADRENO_PROTECT_RDONLY (_reg, _len) \ + ((1 << 29) \ + ((ilog2((_len)) & 0x1F) << 24) | (((_reg) << 2) & 0xFFFFF)) +#endif /* __ADRENO_GPU_H__ */
drivers/gpu/drm/msm/msm_gpu.c +10 -3
@@ -96,6 +96,10 @@ static int enable_clk(struct msm_gpu *gpu)if (gpu->grp_clks[0 ] && gpu->fast_rate)clk_set_rate (gpu->grp_clks[0 ], gpu->fast_rate); +/* Set the RBBM timer rate to 19.2Mhz */ +if (gpu->grp_clks[2 ]) +clk_set_rate (gpu->grp_clks[2 ],19200000 ); +for (i =ARRAY_SIZE (gpu->grp_clks) -1 ; i >=0 ; i--)if (gpu->grp_clks[i])clk_prepare (gpu->grp_clks[i]);
@@ -122,6 +126,9 @@ static int disable_clk(struct msm_gpu *gpu)if (gpu->grp_clks[0 ] && gpu->slow_rate)clk_set_rate (gpu->grp_clks[0 ], gpu->slow_rate); +if (gpu->grp_clks[2 ]) +clk_set_rate (gpu->grp_clks[2 ],0 ); +return 0 ; }
@@ -562,8 +569,8 @@ static irqreturn_t irq_handler(int irq, void *data) }static const char *clk_names[] = { -"core_clk" ,"iface_clk" ,"mem_clk" ,"mem_iface_clk" , -"alt_mem_iface_clk" , +"core_clk" ,"iface_clk" ,"rbbmtimer_clk" ,"mem_clk" , +"mem_iface_clk" ,"alt_mem_iface_clk" , }; int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
@@ -656,7 +663,7 @@ int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev, iommu =iommu_domain_alloc (&platform_bus_type);if (iommu) {/* TODO 32b vs 64b address space.. */ - iommu->geometry.aperture_start =0x1000 ; + iommu->geometry.aperture_start =SZ_16M ; iommu->geometry.aperture_end =0xffffffff ;dev_info (drm->dev,"%s: using IOMMU\n" , name);
drivers/gpu/drm/msm/msm_gpu.h +1 -1
@@ -103,7 +103,7 @@ struct msm_gpu {/* Power Control: */ struct regulator *gpu_reg, *gpu_cx; -struct clk *ebi1_clk, *grp_clks[5 ]; +struct clk *ebi1_clk, *grp_clks[6 ];uint32_t fast_rate, slow_rate, bus_freq;#ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
Signature · 1 line
1.9.1
PATCH 9/12 drm/msm: gpu: Add support for the GPMU
In reply to Jordan CrouseMost 5XX targets have GPMU (Graphics Power Management Unit) that handles a lot of the heavy lifting for power management including thermal and limits management and dynamic power collapse. While the GPMU itself is optional, it is usually nessesary to hit aggressive power targets.
The GPMU firmware needs to be loaded into the GPMU at init time via a shared hardware block of registers. Using the GPU to write the microcode is more efficient than using the CPU so at first load create an indirect buffer that can be executed during subsequent initalization sequences.
After loading the GPMU gets initalized through a shared register interface and then we mostly get out of its way and let it do its thing.
--- drivers/gpu/drm/msm/Makefile | 1 + drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 64 +++++- drivers/gpu/drm/msm/adreno/a5xx_gpu.h | 23 ++ drivers/gpu/drm/msm/adreno/a5xx_power.c | 344 +++++++++++++++++++++++++++++ drivers/gpu/drm/msm/adreno/adreno_device.c | 1 + drivers/gpu/drm/msm/adreno/adreno_gpu.h | 1 + 6 files changed, 431 insertions(+), 3 deletions(-) create mode 100644 drivers/gpu/drm/msm/adreno/a5xx_power.c
drivers/gpu/drm/msm/Makefile +1 -0
@@ -7,6 +7,7 @@ msm-y := \ adreno/a3xx_gpu.o \ adreno/a4xx_gpu.o \ adreno/a5xx_gpu.o \ + adreno/a5xx_power.o \ hdmi/hdmi.o \ hdmi/hdmi_audio.o \ hdmi/hdmi_bridge.o \
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +61 -3
104 lines not on this page · raw message
drivers/gpu/drm/msm/adreno/a5xx_gpu.h +23 -0
@@ -30,8 +30,31 @@ struct a5xx_gpu {struct drm_gem_object *pfp_bo;uint64_t pfp_iova; + +struct drm_gem_object *gpmu_bo; +uint64_t gpmu_iova; +uint32_t gpmu_dwords; + + uint32_t lm_leakage; };#define to_a5xx_gpu (x) container_of(x, struct a5xx_gpu, base) +int a5xx_power_init (struct msm_gpu *gpu); +void a5xx_gpmu_ucode_init (struct msm_gpu *gpu); + +static inline int spin_usecs (struct msm_gpu *gpu,uint32_t usecs, +uint32_t reg,uint32_t mask,uint32_t value) +{ +while (usecs--) { +udelay (1 ); +if ((gpu_read (gpu, reg) & mask) == value) +return 0 ; +cpu_relax (); + } + +return -ETIMEDOUT ; +} + +#endif /* __A5XX_GPU_H__ */
drivers/gpu/drm/msm/adreno/a5xx_power.c new file +344 -0
344 lines not on this page · raw message
drivers/gpu/drm/msm/adreno/adreno_device.c +1 -0
@@ -86,6 +86,7 @@ static const struct adreno_info gpulist[] = { .pfpfw = "a530_pfp.fw", .gmem = SZ_1M, .init = a5xx_gpu_init, + .gpmufw = "a530v3_gpmu.fw2", }, };
drivers/gpu/drm/msm/adreno/adreno_gpu.h +1 -0
@@ -73,6 +73,7 @@ struct adreno_info {uint32_t revn;const char *name;const char *pm4fw, *pfpfw; +const char *gpmufw;uint32_t gmem;struct msm_gpu *(*init)(struct drm_device *dev); };
Signature · 1 line
1.9.1
PATCH 10/12 firmware: qcom_scm: Add qcom_scm_gpu_zap_resume()
In reply to Jordan CrouseAdd an interface to trigger the remote processor to reinitialize the GPU zap shader on power-up.
--- drivers/firmware/qcom_scm-32.c | 5 +++++ drivers/firmware/qcom_scm-64.c | 15 +++++++++++++++ drivers/firmware/qcom_scm.c | 6 ++++++ drivers/firmware/qcom_scm.h | 2 ++ include/linux/qcom_scm.h | 2 ++ 5 files changed, 30 insertions(+)
drivers/firmware/qcom_scm-32.c +5 -0
@@ -560,3 +560,8 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)return ret ? :le32_to_cpu (out); } + +int __qcom_scm_gpu_zap_resume (struct device *dev) +{ +return -ENOTSUPP ; +}
drivers/firmware/qcom_scm-64.c +15 -0
@@ -363,3 +363,18 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)return ret ? : res.a1; } + +int __qcom_scm_gpu_zap_resume (struct device *dev) +{ +struct qcom_scm_desc desc = {0 }; +struct arm_smccc_res res; +int ret; + + desc.args[0 ] =0 ; + desc.args[1 ] =13 ; + desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,0x0A , &desc, &res); + +return ret ? : res.a1; +}
drivers/firmware/qcom_scm.c +6 -0
@@ -312,6 +312,12 @@ static const struct reset_control_ops qcom_scm_pas_reset_ops = { .deassert = qcom_scm_pas_reset_deassert, }; +int qcom_scm_gpu_zap_resume (void ) +{ +return __qcom_scm_gpu_zap_resume (__scm->dev); +} +EXPORT_SYMBOL (qcom_scm_gpu_zap_resume); +/** * qcom_scm_is_available() - Checks if SCM is available */
drivers/firmware/qcom_scm.h +2 -0
@@ -56,6 +56,8 @@ extern int __qcom_scm_pas_auth_and_reset(struct device *dev, u32 peripheral);extern int __qcom_scm_pas_shutdown (struct device *dev,u32 peripheral);extern int __qcom_scm_pas_mss_reset (struct device *dev,bool reset); +extern int __qcom_scm_gpu_zap_resume (struct device *dev); +/* common error codes */ #define QCOM_SCM_V2_EBUSY -12#define QCOM_SCM_ENOMEM -5
include/linux/qcom_scm.h +2 -0
@@ -37,6 +37,8 @@ extern int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr,extern int qcom_scm_pas_auth_and_reset (u32 peripheral);extern int qcom_scm_pas_shutdown (u32 peripheral); +extern int qcom_scm_gpu_zap_resume (void ); +#define QCOM_SCM_CPU_PWR_DOWN_L2_ON 0x0#define QCOM_SCM_CPU_PWR_DOWN_L2_OFF 0x1
Signature · 1 line
1.9.1
Re: [PATCH 10/12] firmware: qcom_scm: Add qcom_scm_gpu_zap_resume()
Quoted 5 lines · Jordan Crouse
Add an interface to trigger the remote processor to reinitialize the GPU zap shader on power-up.
Signed-off-by Jordan Crouse <[email protected]>---
<snip>
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 374
Quoted 8 lines
drivers/firmware/qcom_scm-64.c +8
-0+int __qcom_scm_gpu_zap_resume (struct device *dev) +{ +struct qcom_scm_desc desc = {0 }; +struct arm_smccc_res res; +int ret; + + desc.args[0 ] =0 ; + desc.args[1 ] =13 ;
Can I get a define here for these two? Or maybe a comment on what these values are?
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 377
Quoted 3 lines
drivers/firmware/qcom_scm-64.c +3
-0+ desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,0x0A , &desc, &res);
Same with the 0xA. We usually throw a #define in for the command definitions.
Otherwise this all looks fine. If you can get back to me with either the values or a new patch I can include this in the next pull.
Thanks.
Andy
A message that is not in the archive (sent off-list or not yet received): 20170113171241.GH5710-3KkwrOJo9xYlRp7syxWybdHuzzzSOjJt@public.gmane.org
Re: [PATCH 10/12] firmware: qcom_scm: Add qcom_scm_gpu_zap_resume()
Quoted 21 lines · Andy Gross
Quoted 5 lines · Jordan Crouse
Add an interface to trigger the remote processor to reinitialize the GPU zap shader on power-up.
Signed-off-by Jordan Crouse <[email protected]>---
<snip>
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 374
Quoted 8 lines
drivers/firmware/qcom_scm-64.c +8
-0+int __qcom_scm_gpu_zap_resume (struct device *dev) +{ +struct qcom_scm_desc desc = {0 }; +struct arm_smccc_res res; +int ret; + + desc.args[0 ] =0 ; + desc.args[1 ] =13 ;Can I get a define here for these two? Or maybe a comment on what these values are?
Quoted 8 lines
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 377
Quoted 3 lines
drivers/firmware/qcom_scm-64.c +3
-0+ desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,0x0A , &desc, &res);Same with the
0xA. We usually throw a #define in for the command definitions.Otherwise this all looks fine. If you can get back to me with either the values or a new patch I can include this in the next pull.
Thanks for reaching out. Since this isn't my usual area I'll need to work out some terminology with the SCM folks to make sure I don't accidentally do anything that will get me in trouble.
Jordan
Signature · 6 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ Freedreno mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/freedreno
A message that is not in the archive (sent off-list or not yet received): 20170113172244.GA28592-9PYrDHPZ2Orvke4nUoYGnHL1okKdlPRT@public.gmane.org
Re: [PATCH 10/12] firmware: qcom_scm: Add qcom_scm_gpu_zap_resume()
Quoted 28 lines · Jordan Crouse
Quoted 27 lines · Andy Gross
Quoted 5 lines · Jordan Crouse
Add an interface to trigger the remote processor to reinitialize the GPU zap shader on power-up.
Signed-off-by Jordan Crouse <[email protected]>---
<snip>
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 374
Quoted 8 lines
drivers/firmware/qcom_scm-64.c +8
-0+int __qcom_scm_gpu_zap_resume (struct device *dev) +{ +struct qcom_scm_desc desc = {0 }; +struct arm_smccc_res res; +int ret; + + desc.args[0 ] =0 ; + desc.args[1 ] =13 ;Can I get a define here for these two? Or maybe a comment on what these values are?
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 377
Quoted 3 lines
drivers/firmware/qcom_scm-64.c +3
-0+ desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,0x0A , &desc, &res);Same with the
0xA. We usually throw a #define in for the command definitions.
Quoted 6 lines
Quoted 2 lines
Otherwise this all looks fine. If you can get back to me with either the values or a new patch I can include this in the next pull.
Thanks for reaching out. Since this isn't my usual area I'll need to work out some terminology with the SCM folks to make sure I don't accidentally do anything that will get me in trouble.
Yeah I did a brief look through CAF. I saw basically the same information. If
you can't get an answer, let me know and I'll just take it and put in a comment.
Andy
_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
Re: [Freedreno] [PATCH 10/12] firmware: qcom_scm: Add qcom_scm_gpu_zap_resume()
In reply to Andy GrossQuoted 9 lines · Andy Gross
Quoted 5 lines · Jordan Crouse
Add an interface to trigger the remote processor to reinitialize the GPU zap shader on power-up.
Signed-off-by Jordan Crouse <[email protected]>---
<snip>
Quoted 7 lines
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 373
Quoted 7 lines
drivers/firmware/qcom_scm-64.c +7
-0+int __qcom_scm_gpu_zap_resume (struct device *dev) +{ +struct qcom_scm_desc desc = {0 }; +struct arm_smccc_res res; +int ret; + + desc.args[0 ] =0 ;
This is an opcode to force the state to resume.
QCOM_SCM_BOOT_SET_STATE_RESUME perhaps? Or something similar but shorter.
Quoted 1 line
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 374
Quoted 1 line
drivers/firmware/qcom_scm-64.c +1
-0+ desc.args[1 ] =13 ;
This is the same as the SCM id of the GPU but I think that is a coincidence. We've always used it to identify the GPU in this call.
QCOM_SCM_BOOT_SET_STATE_GPU would be fine here - or something similar.
Quoted 8 lines
Can I get a define here for these two? Or maybe a comment on what these values are?
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 377
Quoted 3 lines
drivers/firmware/qcom_scm-64.c +3
-0+ desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,0x0A , &desc, &res);Same with the
0xA. We usually throw a #define in for the command definitions.
0x0A sets the state of the device - for us it is always 0 (resume) and always the GPU.
#define QCOM_SCM_BOOT_SET_STATE 0x0A
Quoted 2 lines
Otherwise this all looks fine. If you can get back to me with either the values or a new patch I can include this in the next pull.
I'll make the changes and start the song and dance, but you'll no doubt be faster than I.
Jordan
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
A message that is not in the archive (sent off-list or not yet received): 20170113232438.GA24139-9PYrDHPZ2Orvke4nUoYGnHL1okKdlPRT@public.gmane.org
Re: [PATCH 10/12] firmware: qcom_scm: Add qcom_scm_gpu_zap_resume()
Quoted 41 lines · Jordan Crouse
Quoted 9 lines · Andy Gross
Quoted 5 lines · Jordan Crouse
Add an interface to trigger the remote processor to reinitialize the GPU zap shader on power-up.
Signed-off-by Jordan Crouse <[email protected]>---
<snip>
Quoted 7 lines
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 373
Quoted 7 lines
drivers/firmware/qcom_scm-64.c +7
-0+int __qcom_scm_gpu_zap_resume (struct device *dev) +{ +struct qcom_scm_desc desc = {0 }; +struct arm_smccc_res res; +int ret; + + desc.args[0 ] =0 ;This is an opcode to force the state to resume.
QCOM_SCM_BOOT_SET_STATE_RESUMEperhaps? Or something similar but shorter.Quoted 1 line
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 374
Quoted 1 line
drivers/firmware/qcom_scm-64.c +1
-0+ desc.args[1 ] =13 ;This is the same as the SCM id of the GPU but I think that is a coincidence. We've always used it to identify the GPU in this call.
QCOM_SCM_BOOT_SET_STATE_GPUwould be fine here - or something similar.Quoted 8 lines
Can I get a define here for these two? Or maybe a comment on what these values are?
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 377
Quoted 3 lines
drivers/firmware/qcom_scm-64.c +3
-0+ desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,0x0A , &desc, &res);Same with the
0xA. We usually throw a #define in for the command definitions.
0x0Asets the state of the device - for us it is always 0 (resume) and always the GPU.
Quoted 7 lines
#define
QCOM_SCM_BOOT_SET_STATE0x0AQuoted 2 lines
Otherwise this all looks fine. If you can get back to me with either the values or a new patch I can include this in the next pull.
I'll make the changes and start the song and dance, but you'll no doubt be faster than I.
I can just fix up the patch with the above. Thanks for the additional details.
Andy
_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
Re: [Freedreno] [PATCH 10/12] firmware: qcom_scm: Add qcom_scm_gpu_zap_resume()
+ Stanimir
Quoted 44 lines · Andy Gross
Quoted 43 lines · Jordan Crouse
Quoted 9 lines · Andy Gross
Quoted 5 lines · Jordan Crouse
Add an interface to trigger the remote processor to reinitialize the GPU zap shader on power-up.
Signed-off-by Jordan Crouse <[email protected]>---
<snip>
Quoted 7 lines
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 373
Quoted 7 lines
drivers/firmware/qcom_scm-64.c +7
-0+int __qcom_scm_gpu_zap_resume (struct device *dev) +{ +struct qcom_scm_desc desc = {0 }; +struct arm_smccc_res res; +int ret; + + desc.args[0 ] =0 ;This is an opcode to force the state to resume.
QCOM_SCM_BOOT_SET_STATE_RESUMEperhaps? Or something similar but shorter.Quoted 1 line
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 374
Quoted 1 line
drivers/firmware/qcom_scm-64.c +1
-0+ desc.args[1 ] =13 ;This is the same as the SCM id of the GPU but I think that is a coincidence. We've always used it to identify the GPU in this call.
QCOM_SCM_BOOT_SET_STATE_GPUwould be fine here - or something similar.Quoted 8 lines
Can I get a define here for these two? Or maybe a comment on what these values are?
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 377
Quoted 3 lines
drivers/firmware/qcom_scm-64.c +3
-0+ desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,0x0A , &desc, &res);Same with the
0xA. We usually throw a #define in for the command definitions.
0x0Asets the state of the device - for us it is always 0 (resume) and always the GPU.#define
QCOM_SCM_BOOT_SET_STATE0x0A
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Otherwise this all looks fine. If you can get back to me with either the values or a new patch I can include this in the next pull.
I'll make the changes and start the song and dance, but you'll no doubt be faster than I.
I can just fix up the patch with the above. Thanks for the additional details.
The plot thickens. So I have a patch from Stanimir concerning another SCM call that is using the same command and number of arguments. And it also concerns setting state. I think that we need to roll a common API for setting the state and then both of you can call it. That way we can kill two birds with one stone.
Something along the lines of a function prototype:
int qcom_scm_set_remote_state(u32 state, u32 id)
{
return __qcom_scm_set_remote_state(__scm->dev, state, id);
}EXPORT_SYMBOL(qcom_scm_set_remote_state);
where state is the state you want set, and id is the identifier of the remote proc.
Does this make sense for both of your use cases?
Andy
Re: [Freedreno] [PATCH 10/12] firmware: qcom_scm: Add qcom_scm_gpu_zap_resume()
Hi Andy,
Quoted 66 lines · Andy Gross
+ Stanimir
Quoted 44 lines · Andy Gross
Quoted 43 lines · Jordan Crouse
Quoted 9 lines · Andy Gross
Quoted 5 lines · Jordan Crouse
Add an interface to trigger the remote processor to reinitialize the GPU zap shader on power-up.
Signed-off-by Jordan Crouse <[email protected]>---
<snip>
Quoted 7 lines
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 373
Quoted 7 lines
drivers/firmware/qcom_scm-64.c +7
-0+int __qcom_scm_gpu_zap_resume (struct device *dev) +{ +struct qcom_scm_desc desc = {0 }; +struct arm_smccc_res res; +int ret; + + desc.args[0 ] =0 ;This is an opcode to force the state to resume.
QCOM_SCM_BOOT_SET_STATE_RESUMEperhaps? Or something similar but shorter.Quoted 1 line
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 374
Quoted 1 line
drivers/firmware/qcom_scm-64.c +1
-0+ desc.args[1 ] =13 ;This is the same as the SCM id of the GPU but I think that is a coincidence. We've always used it to identify the GPU in this call.
QCOM_SCM_BOOT_SET_STATE_GPUwould be fine here - or something similar.Quoted 8 lines
Can I get a define here for these two? Or maybe a comment on what these values are?
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 377
Quoted 3 lines
drivers/firmware/qcom_scm-64.c +3
-0+ desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,0x0A , &desc, &res);Same with the
0xA. We usually throw a #define in for the command definitions.
0x0Asets the state of the device - for us it is always 0 (resume) and always the GPU.#define
QCOM_SCM_BOOT_SET_STATE0x0AQuoted 7 lines
Quoted 5 lines
Quoted 2 lines
Otherwise this all looks fine. If you can get back to me with either the values or a new patch I can include this in the next pull.
I'll make the changes and start the song and dance, but you'll no doubt be faster than I.
I can just fix up the patch with the above. Thanks for the additional details.
The plot thickens. So I have a patch from Stanimir concerning another SCM call that is using the same command and number of arguments. And it also concerns setting state. I think that we need to roll a common API for setting the state and then both of you can call it. That way we can kill two birds with one stone.
Something along the lines of a function prototype:
intqcom_scm_set_remote_state(u32 state, u32 id){ return __qcom_scm_set_remote_state(__scm->dev, state, id); }
Quoted 6 lines
EXPORT_SYMBOL(qcom_scm_set_remote_state);where state is the state you want set, and id is the identifier of the remote proc.
Does this make sense for both of your use cases?
I'm fine with that.
Signature · 6 lines
regards, Stan _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Freedreno] [PATCH 10/12] firmware: qcom_scm: Add qcom_scm_gpu_zap_resume()
In reply to Andy GrossQuoted 53 lines · Andy Gross
+ Stanimir
Quoted 50 lines · Andy Gross
Quoted 48 lines · Jordan Crouse
Quoted 9 lines · Andy Gross
Quoted 5 lines · Jordan Crouse
Add an interface to trigger the remote processor to reinitialize the GPU zap shader on power-up.
Signed-off-by Jordan Crouse <[email protected]>---
<snip>
Quoted 7 lines
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 373
Quoted 7 lines
drivers/firmware/qcom_scm-64.c +7
-0+int __qcom_scm_gpu_zap_resume (struct device *dev) +{ +struct qcom_scm_desc desc = {0 }; +struct arm_smccc_res res; +int ret; + + desc.args[0 ] =0 ;This is an opcode to force the state to resume.
QCOM_SCM_BOOT_SET_STATE_RESUMEperhaps? Or something similar but shorter.Quoted 1 line
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 374
Quoted 1 line
drivers/firmware/qcom_scm-64.c +1
-0+ desc.args[1 ] =13 ;This is the same as the SCM id of the GPU but I think that is a coincidence. We've always used it to identify the GPU in this call.
QCOM_SCM_BOOT_SET_STATE_GPUwould be fine here - or something similar.Quoted 8 lines
Can I get a define here for these two? Or maybe a comment on what these values are?
drivers/firmware/qcom_scm-64.c int __qcom_scm_pas_mss_reset(struct device *dev, bool reset) · line 377
Quoted 3 lines
drivers/firmware/qcom_scm-64.c +3
-0+ desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,0x0A , &desc, &res);Same with the
0xA. We usually throw a #define in for the command definitions.
0x0Asets the state of the device - for us it is always 0 (resume) and always the GPU.#define
QCOM_SCM_BOOT_SET_STATE0x0AQuoted 2 lines
Otherwise this all looks fine. If you can get back to me with either the values or a new patch I can include this in the next pull.
I'll make the changes and start the song and dance, but you'll no doubt be faster than I.
Quoted 7 lines
Quoted 1 line
I can just fix up the patch with the above. Thanks for the additional details.
The plot thickens. So I have a patch from Stanimir concerning another SCM call that is using the same command and number of arguments. And it also concerns setting state. I think that we need to roll a common API for setting the state and then both of you can call it. That way we can kill two birds with one stone.
I was worried about this, but not this quickly - glad to see that the other drivers are coming along too.
If you look carefully, you'll note that the values are inverted - the video state uses 0 to suspend and 1 to resume, and GPU uses 0 to resume and no suspend. I asked why and got a bunch of shrugging back. Its not a big deal because your API accounts for this but expect GPU to have a RESUME #define that is a different value.
Quoted 11 lines
Something along the lines of a function prototype:
intqcom_scm_set_remote_state(u32 state, u32 id){ return __qcom_scm_set_remote_state(__scm->dev, state, id); }
EXPORT_SYMBOL(qcom_scm_set_remote_state);where state is the state you want set, and id is the identifier of the remote proc.
Does this make sense for both of your use cases?
Yep - this is fine.
Jordan
Signature · 6 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): 20170117170459.GA29647-9PYrDHPZ2Orvke4nUoYGnHL1okKdlPRT@public.gmane.org
Re: [PATCH 10/12] firmware: qcom_scm: Add qcom_scm_gpu_zap_resume()
Quoted 78 lines · Jordan Crouse
Quoted 53 lines · Andy Gross
+ Stanimir
Quoted 50 lines · Andy Gross
Quoted 48 lines · Jordan Crouse
Quoted 9 lines · Andy Gross
Quoted 5 lines · Jordan Crouse
Add an interface to trigger the remote processor to reinitialize the GPU zap shader on power-up.
Signed-off-by Jordan Crouse <[email protected]>---
<snip>
Quoted 7 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+int __qcom_scm_gpu_zap_resume(struct device *dev) +{ + struct qcom_scm_desc desc = {0}; + struct arm_smccc_res res; + int ret; + + desc.args[0] = 0;This is an opcode to force the state to resume.
QCOM_SCM_BOOT_SET_STATE_RESUMEperhaps? Or something similar but shorter.Quoted 1 line
Review
Quoted 1 line
(quoted diff) +1
-0+ desc.args[1] = 13;This is the same as the SCM id of the GPU but I think that is a coincidence. We've always used it to identify the GPU in this call.
QCOM_SCM_BOOT_SET_STATE_GPUwould be fine here - or something similar.Quoted 8 lines
Can I get a define here for these two? Or maybe a comment on what these values are?
Review
Quoted 3 lines
(quoted diff) +3
-0+ desc.arginfo = QCOM_SCM_ARGS(2); + + ret = qcom_scm_call(dev, QCOM_SCM_SVC_BOOT, 0x0A, &desc, &res);Same with the
0xA. We usually throw a #define in for the command definitions.
0x0Asets the state of the device - for us it is always 0 (resume) and always the GPU.#define
QCOM_SCM_BOOT_SET_STATE0x0AQuoted 2 lines
Otherwise this all looks fine. If you can get back to me with either the values or a new patch I can include this in the next pull.
I'll make the changes and start the song and dance, but you'll no doubt be faster than I.
Quoted 7 lines
Quoted 1 line
I can just fix up the patch with the above. Thanks for the additional details.
The plot thickens. So I have a patch from Stanimir concerning another SCM call that is using the same command and number of arguments. And it also concerns setting state. I think that we need to roll a common API for setting the state and then both of you can call it. That way we can kill two birds with one stone.
I was worried about this, but not this quickly - glad to see that the other drivers are coming along too.
If you look carefully, you'll note that the values are inverted - the video state uses 0 to suspend and 1 to resume, and GPU uses 0 to resume and no suspend. I asked why and got a bunch of shrugging back. Its not a big deal because your API accounts for this but expect GPU to have a RESUME #define that is a different value.
Quoted 7 lines
Something along the lines of a function prototype:
intqcom_scm_set_remote_state(u32 state, u32 id){ return __qcom_scm_set_remote_state(__scm->dev, state, id); }
EXPORT_SYMBOL(qcom_scm_set_remote_state);
Quoted 6 lines
Quoted 4 lines
where state is the state you want set, and id is the identifier of the remote proc.
Does this make sense for both of your use cases?
Yep - this is fine.
If you guys can ack/sob that patch I'd appreciate it.
As for the #defines, you guys can define whatever you like in your drivers. This API just pushes all that into your client drivers.
Andy
_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
A message that is not in the archive (sent off-list or not yet received): 1480361317-9937-11-git-send-email-jcrouse-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org
PATCH 1/1 firmware: qcom_scm: Add set remote state API
This patch adds a set remote state SCM API. This will be used by the Venus and GPU subsystems to set state on the remote processors.
This work was based on two patch sets by Jordan Crouse and Stanimir Varbanov.
--- drivers/firmware/qcom_scm-32.c | 18 ++++++++++++++++++ drivers/firmware/qcom_scm-64.c | 16 ++++++++++++++++ drivers/firmware/qcom_scm.c | 6 ++++++ drivers/firmware/qcom_scm.h | 2 ++ include/linux/qcom_scm.h | 4 +++- 5 files changed, 45 insertions(+), 1 deletion(-)
drivers/firmware/qcom_scm-32.c +18 -0
@@ -560,3 +560,21 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)return ret ? :le32_to_cpu (out); } + +int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id) +{ +struct { +__le32 state; +__le32 id; + } req; +__le32 scm_ret =0 ; +int ret; + + req.state =cpu_to_le32 (state); + req.id =cpu_to_le32 (id); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_SET_REMOTE_STATE , + &req,sizeof (req), &scm_ret,sizeof (scm_ret)); + +return ret ? :le32_to_cpu (scm_ret); +}
drivers/firmware/qcom_scm-64.c +16 -0
@@ -358,3 +358,19 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)return ret ? : res.a1; } + +int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id) +{ +struct qcom_scm_desc desc = {0 }; +struct arm_smccc_res res; +int ret; + + desc.args[0 ] = state; + desc.args[1 ] = id; + desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_SET_REMOTE_STATE , + &desc, &res); + +return ret ? : res.a1; +}
drivers/firmware/qcom_scm.c +6 -0
@@ -324,6 +324,12 @@ bool qcom_scm_is_available(void) }EXPORT_SYMBOL (qcom_scm_is_available); +int qcom_scm_set_remote_state (u32 state,u32 id) +{ +return __qcom_scm_set_remote_state (__scm->dev, state, id); +} +EXPORT_SYMBOL (qcom_scm_set_remote_state); +static int qcom_scm_probe (struct platform_device *pdev) {struct qcom_scm *scm;
drivers/firmware/qcom_scm.h +2 -0
@@ -15,6 +15,8 @@#define QCOM_SCM_SVC_BOOT 0x1#define QCOM_SCM_BOOT_ADDR 0x1#define QCOM_SCM_BOOT_ADDR_MC 0x11 +#define QCOM_SCM_SET_REMOTE_STATE 0xa +extern int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id);#define QCOM_SCM_FLAG_HLOS 0x01#define QCOM_SCM_FLAG_COLDBOOT_MC 0x02
include/linux/qcom_scm.h +3 -1
@@ -39,6 +39,7 @@ extern int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr,extern int qcom_scm_pas_shutdown (u32 peripheral);extern void qcom_scm_cpu_power_down (u32 flags);extern u32 qcom_scm_get_version (void ); +extern int qcom_scm_set_remote_state (u32 state,u32 id);#else static inline int qcom_scm_set_cold_boot_addr (void *entry,const cpumask_t *cpus)
@@ -64,6 +65,7 @@ static inline int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr,static inline int qcom_scm_pas_shutdown (u32 peripheral) {return -ENODEV ; }static inline void qcom_scm_cpu_power_down (u32 flags) {}static inline u32 qcom_scm_get_version (void ) {return 0 ; } +static inline u32 +qcom_scm_set_remote_state (u32 state,u32 id) {return -ENODEV ; }#endif -#endif
Signature · 6 lines
1.9.1 _______________________________________________ Freedreno mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/freedreno
A message that is not in the archive (sent off-list or not yet received): 1484632578-4539-1-git-send-email-andy.gross-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org
Jordan Crouse
Acked-byRe: [PATCH] firmware: qcom_scm: Add set remote state API
Quoted 7 lines · Andy Gross
This patch adds a set remote state SCM API. This will be used by the Venus and GPU subsystems to set state on the remote processors.
This work was based on two patch sets by Jordan Crouse and Stanimir Varbanov.
Signed-off-by Andy Gross <[email protected]>
Quoted 111 lines
--- drivers/firmware/qcom_scm-32.c | 18 ++++++++++++++++++ drivers/firmware/qcom_scm-64.c | 16 ++++++++++++++++ drivers/firmware/qcom_scm.c | 6 ++++++ drivers/firmware/qcom_scm.h | 2 ++ include/linux/qcom_scm.h | 4 +++- 5 files changed, 45 insertions(+), 1 deletion(-)drivers/firmware/qcom_scm-32.c +18
-0@@ -560,3 +560,21 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)return ret ? :le32_to_cpu (out); } + +int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id) +{ +struct { +__le32 state; +__le32 id; + } req; +__le32 scm_ret =0 ; +int ret; + + req.state =cpu_to_le32 (state); + req.id =cpu_to_le32 (id); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_SET_REMOTE_STATE , + &req,sizeof (req), &scm_ret,sizeof (scm_ret)); + +return ret ? :le32_to_cpu (scm_ret); +}drivers/firmware/qcom_scm-64.c +16
-0@@ -358,3 +358,19 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)return ret ? : res.a1; } + +int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id) +{ +struct qcom_scm_desc desc = {0 }; +struct arm_smccc_res res; +int ret; + + desc.args[0 ] = state; + desc.args[1 ] = id; + desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_SET_REMOTE_STATE , + &desc, &res); + +return ret ? : res.a1; +}drivers/firmware/qcom_scm.c +6
-0@@ -324,6 +324,12 @@ bool qcom_scm_is_available(void) }EXPORT_SYMBOL (qcom_scm_is_available); +int qcom_scm_set_remote_state (u32 state,u32 id) +{ +return __qcom_scm_set_remote_state (__scm->dev, state, id); +} +EXPORT_SYMBOL (qcom_scm_set_remote_state); +static int qcom_scm_probe (struct platform_device *pdev) {struct qcom_scm *scm;drivers/firmware/qcom_scm.h +2
-0@@ -15,6 +15,8 @@#define QCOM_SCM_SVC_BOOT 0x1#define QCOM_SCM_BOOT_ADDR 0x1#define QCOM_SCM_BOOT_ADDR_MC 0x11 +#define QCOM_SCM_SET_REMOTE_STATE 0xa +extern int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id);#define QCOM_SCM_FLAG_HLOS 0x01#define QCOM_SCM_FLAG_COLDBOOT_MC 0x02include/linux/qcom_scm.h +3
-1@@ -39,6 +39,7 @@ extern int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr,extern int qcom_scm_pas_shutdown (u32 peripheral);extern void qcom_scm_cpu_power_down (u32 flags);extern u32 qcom_scm_get_version (void ); +extern int qcom_scm_set_remote_state (u32 state,u32 id);#else static inline int qcom_scm_set_cold_boot_addr (void *entry,const cpumask_t *cpus)@@ -64,6 +65,7 @@ static inline int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr,static inline int qcom_scm_pas_shutdown (u32 peripheral) {return -ENODEV ; }static inline void qcom_scm_cpu_power_down (u32 flags) {}static inline u32 qcom_scm_get_version (void ) {return 0 ; } +static inline u32 +qcom_scm_set_remote_state (u32 state,u32 id) {return -ENODEV ; }#endif -#endif Signature · 1 line
1.9.1
_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
Re: [PATCH] firmware: qcom_scm: Add set remote state API
In reply to Andy GrossThanks Andy,
Quoted 6 lines · Andy Gross
This patch adds a set remote state SCM API. This will be used by the Venus and GPU subsystems to set state on the remote processors.
This work was based on two patch sets by Jordan Crouse and Stanimir Varbanov.
Quoted 8 lines
Signed-off-by Andy Gross <[email protected]>--- drivers/firmware/qcom_scm-32.c | 18 ++++++++++++++++++ drivers/firmware/qcom_scm-64.c | 16 ++++++++++++++++ drivers/firmware/qcom_scm.c | 6 ++++++ drivers/firmware/qcom_scm.h | 2 ++ include/linux/qcom_scm.h | 4 +++- 5 files changed, 45 insertions(+), 1 deletion(-)
Signature · 6 lines
regards, Stan _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH] firmware: qcom_scm: Add set remote state API
In reply to Andy GrossAndy,
Could you queue this patch for 4.11?
Quoted 117 lines · Andy Gross
This patch adds a set remote state SCM API. This will be used by the Venus and GPU subsystems to set state on the remote processors.
This work was based on two patch sets by Jordan Crouse and Stanimir Varbanov.
Signed-off-by Andy Gross <[email protected]>--- drivers/firmware/qcom_scm-32.c | 18 ++++++++++++++++++ drivers/firmware/qcom_scm-64.c | 16 ++++++++++++++++ drivers/firmware/qcom_scm.c | 6 ++++++ drivers/firmware/qcom_scm.h | 2 ++ include/linux/qcom_scm.h | 4 +++- 5 files changed, 45 insertions(+), 1 deletion(-)drivers/firmware/qcom_scm-32.c +18
-0@@ -560,3 +560,21 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)return ret ? :le32_to_cpu (out); } + +int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id) +{ +struct { +__le32 state; +__le32 id; + } req; +__le32 scm_ret =0 ; +int ret; + + req.state =cpu_to_le32 (state); + req.id =cpu_to_le32 (id); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_SET_REMOTE_STATE , + &req,sizeof (req), &scm_ret,sizeof (scm_ret)); + +return ret ? :le32_to_cpu (scm_ret); +}drivers/firmware/qcom_scm-64.c +16
-0@@ -358,3 +358,19 @@ int __qcom_scm_pas_mss_reset(struct device *dev, bool reset)return ret ? : res.a1; } + +int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id) +{ +struct qcom_scm_desc desc = {0 }; +struct arm_smccc_res res; +int ret; + + desc.args[0 ] = state; + desc.args[1 ] = id; + desc.arginfo =QCOM_SCM_ARGS (2 ); + + ret =qcom_scm_call (dev,QCOM_SCM_SVC_BOOT ,QCOM_SCM_SET_REMOTE_STATE , + &desc, &res); + +return ret ? : res.a1; +}drivers/firmware/qcom_scm.c +6
-0@@ -324,6 +324,12 @@ bool qcom_scm_is_available(void) }EXPORT_SYMBOL (qcom_scm_is_available); +int qcom_scm_set_remote_state (u32 state,u32 id) +{ +return __qcom_scm_set_remote_state (__scm->dev, state, id); +} +EXPORT_SYMBOL (qcom_scm_set_remote_state); +static int qcom_scm_probe (struct platform_device *pdev) {struct qcom_scm *scm;drivers/firmware/qcom_scm.h +2
-0@@ -15,6 +15,8 @@#define QCOM_SCM_SVC_BOOT 0x1#define QCOM_SCM_BOOT_ADDR 0x1#define QCOM_SCM_BOOT_ADDR_MC 0x11 +#define QCOM_SCM_SET_REMOTE_STATE 0xa +extern int __qcom_scm_set_remote_state (struct device *dev,u32 state,u32 id);#define QCOM_SCM_FLAG_HLOS 0x01#define QCOM_SCM_FLAG_COLDBOOT_MC 0x02include/linux/qcom_scm.h +3
-1@@ -39,6 +39,7 @@ extern int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr,extern int qcom_scm_pas_shutdown (u32 peripheral);extern void qcom_scm_cpu_power_down (u32 flags);extern u32 qcom_scm_get_version (void ); +extern int qcom_scm_set_remote_state (u32 state,u32 id);#else static inline int qcom_scm_set_cold_boot_addr (void *entry,const cpumask_t *cpus)@@ -64,6 +65,7 @@ static inline int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr,static inline int qcom_scm_pas_shutdown (u32 peripheral) {return -ENODEV ; }static inline void qcom_scm_cpu_power_down (u32 flags) {}static inline u32 qcom_scm_get_version (void ) {return 0 ; } +static inline u32 +qcom_scm_set_remote_state (u32 state,u32 id) {return -ENODEV ; }#endif -#endif
Re: [PATCH] firmware: qcom_scm: Add set remote state API
Quoted 3 lines · Stanimir Varbanov
Andy,
Could you queue this patch for 4.11?
This patch is in the qcom-drivers-for-4.11 pull request I sent 9 hours ago. So you should be good.
PATCH 11/12 drm/msm: Add a quick and dirty PIL loader
In reply to Jordan CrouseIn order to switch the GPU out of secure mode on most systems we need to load a zap shader into memory and get it authenticated and into the secure world. All the bits and pieces to do the load are scattered throughout the kernel, but we need to bring everything together.
Add a semi-custom loader that will read a MDT file and get it loaded and authenticated through SCM.
--- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 166 ++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+)
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +166 -0
@@ -11,12 +11,178 @@* */ +#include <linux/elf.h> +#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 "msm_gem.h" #include "a5xx_gpu.h" extern bool hang_debug;static void a5xx_dump (struct msm_gpu *gpu); +static inline bool _check_segment (const struct elf32_phdr *phdr) +{ +return ((phdr->p_type ==PT_LOAD ) && + ((phdr->p_flags & (7 <<24 )) != (2 <<24 )) && + phdr->p_memsz); +} + +static int __pil_tz_load_image (struct platform_device *pdev, +const struct firmware *mdt,const char *fwname, +void *fwptr,size_t fw_size,unsigned long fw_min_addr) +{ +char str[64 ] = {0 }; +const struct elf32_hdr *ehdr = (struct elf32_hdr *) mdt->data; +const struct elf32_phdr *phdrs = (struct elf32_phdr *) (ehdr +1 ); +const struct firmware *fw; +int i, ret =0 ; + +for (i =0 ; i < ehdr->e_phnum; i++) { +const struct elf32_phdr *phdr = &phdrs[i]; +size_t offset; + +/* Make sure the segment is loadable */ +if (!_check_segment (phdr)) +continue ; + +/* Get the offset of the segment within the region */ + offset = (phdr->p_paddr - fw_min_addr); + +/* Request the file containing the segment */ +snprintf (str,sizeof (str) -1 ,"%s.b%02d" , fwname, i); + + ret =request_firmware (&fw, str, &pdev->dev); +if (ret) { +dev_err (&pdev->dev,"Failed to load segment %s\n" , str); +break ; + } + +if (offset + fw->size > fw_size) { +dev_err (&pdev->dev,"Segment %s is too big\n" , str); + ret = -EINVAL ; +release_firmware (fw); +break ; + } + +/* Copy the segment into place */ +memcpy (fwptr + offset, fw->data, fw->size); +release_firmware (fw); + } + +return ret; +} + +static int _pil_tz_load_image (struct platform_device *pdev) +{ +char str[64 ] = {0 }; +const char *fwname; +const struct elf32_hdr *ehdr; +const struct elf32_phdr *phdrs; +const struct firmware *mdt; +phys_addr_t fw_min_addr, fw_max_addr; +dma_addr_t fw_phys; +size_t fw_size; +u32 pas_id; +void *ptr; +int i, ret; + +if (pdev ==NULL ) +return -ENODEV ; + +if (!qcom_scm_is_available ()) { +dev_err (&pdev->dev,"SCM is not available\n" ); +return -EINVAL ; + } + + ret =of_reserved_mem_device_init (&pdev->dev); + +if (ret) { +dev_err (&pdev->dev,"Unable to set up the reserved memory\n" ); +return ret; + } + +/* Get the firmware and PAS id from the device node */ +if (of_property_read_string (pdev->dev.of_node,"qcom,firmware" , + &fwname)) { +dev_err (&pdev->dev,"Could not read a firmware name\n" ); +return -EINVAL ; + } + +if (of_property_read_u32 (pdev->dev.of_node,"qcom,pas-id" , &pas_id)) { +dev_err (&pdev->dev,"Could not read the pas ID\n" ); +return -EINVAL ; + } + +snprintf (str,sizeof (str) -1 ,"%s.mdt" , fwname); + +/* Request the MDT file for the firmware */ + ret =request_firmware (&mdt, str, &pdev->dev); +if (ret) { +dev_err (&pdev->dev,"Unable to load %s\n" , str); +return ret; + } + + ehdr = (struct elf32_hdr *) mdt->data; + phdrs = (struct elf32_phdr *) (ehdr +1 ); + +/* Get the extents of the firmware image */ + + fw_min_addr = (phys_addr_t )ULLONG_MAX ; + fw_max_addr =0 ; + +for (i =0 ; i < ehdr->e_phnum; i++) { +const struct elf32_phdr *phdr = &phdrs[i]; + +if (!_check_segment (phdr)) +continue ; + + fw_min_addr =min_t (phys_addr_t, fw_min_addr, phdr->p_paddr); + fw_max_addr =max_t (phys_addr_t, fw_max_addr, +PAGE_ALIGN (phdr->p_paddr + phdr->p_memsz)); + } + +if (fw_min_addr == (phys_addr_t )ULLONG_MAX && fw_max_addr ==0 ) + goto out; + + fw_size = (size_t ) (fw_max_addr - fw_min_addr); + +/* Verify the MDT header */ + ret =qcom_scm_pas_init_image (pas_id, mdt->data, mdt->size); +if (ret) { +dev_err (&pdev->dev,"Invalid firmware metadata\n" ); + goto out; + } + +/* allocate some memory */ + ptr =dma_alloc_coherent (&pdev->dev, fw_size, &fw_phys,GFP_KERNEL ); +if (ptr ==NULL ) + goto out; + +/* Set up the newly allocated memory region */ + ret =qcom_scm_pas_mem_setup (pas_id, fw_phys, fw_size); +if (ret) { +dev_err (&pdev->dev,"Unable to set up firmware memory\n" ); + goto out; + } + + ret =__pil_tz_load_image (pdev, mdt, fwname, ptr, fw_size, fw_min_addr); +if (!ret) { + ret =qcom_scm_pas_auth_and_reset (pas_id); +if (ret) +dev_err (&pdev->dev,"Unable to authorize the image\n" ); + } + +out: +if (ret && ptr) +dma_free_coherent (&pdev->dev, fw_size, ptr, fw_phys); + +release_firmware (mdt); +return ret; +} +static void a5xx_submit (struct msm_gpu *gpu,struct msm_gem_submit *submit,struct msm_file_private *ctx) {
Signature · 1 line
1.9.1
Re: [PATCH 11/12] drm/msm: Add a quick and dirty PIL loader
Quoted 9 lines · Jordan Crouse
In order to switch the GPU out of secure mode on most systems we need to load a zap shader into memory and get it authenticated and into the secure world. All the bits and pieces to do the load are scattered throughout the kernel, but we need to bring everything together.
Add a semi-custom loader that will read a MDT file and get it loaded and authenticated through SCM.
I've been trying to figure out a reasonable way to provide a scm/pas/mdt-loader, but haven't come up with anything sane yet. Perhaps it's better to provide helpers for the scm case and open code the MDT loading in the non-scm driver. I think this is an okay approach for now.
But it's not a "PIL loader", that's just a side effect of reusing parts of the existing PIL load in the Qualcomm tree. I would suggest just making the subject "Add ZAP MDT loader".
Some minor comments below.
Quoted 23 lines
Signed-off-by Jordan Crouse <[email protected]>--- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 166 ++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+)drivers/gpu/drm/msm/adreno/a5xx_gpu.c +6
-0@@ -11,12 +11,178 @@* */ +#include <linux/elf.h> +#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 "msm_gem.h" #include "a5xx_gpu.h" extern bool hang_debug;
drivers/gpu/drm/msm/adreno/a5xx_gpu.c line 33
Quoted 10 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +8
-0static void a5xx_dump (struct msm_gpu *gpu); +static inline bool _check_segment (const struct elf32_phdr *phdr) +{ +return ((phdr->p_type ==PT_LOAD ) && + ((phdr->p_flags & (7 <<24 )) != (2 <<24 )) && + phdr->p_memsz); +} + +static int __pil_tz_load_image(struct platform_device *pdev,
Rather than throwing more underscores at it I would have named this "zap_load_segments".
drivers/gpu/drm/msm/adreno/a5xx_gpu.c line 37
Quoted 4 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +4
-0+ const struct firmware *mdt, const char *fwname, + void *fwptr, size_t fw_size, unsigned long fw_min_addr) +{ + char str[64] = { 0 };
Name this filename or similar and no need to initialize it.
Quoted 7 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +7
-0+const struct elf32_hdr *ehdr = (struct elf32_hdr *) mdt->data; +const struct elf32_phdr *phdrs = (struct elf32_phdr *) (ehdr +1 ); +const struct firmware *fw; +int i, ret =0 ; + +for (i =0 ; i < ehdr->e_phnum; i++) { +const struct elf32_phdr *phdr = &phdrs[i];
drivers/gpu/drm/msm/adreno/a5xx_gpu.c line 55
Quoted 10 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +10
-0+size_t offset; + +/* Make sure the segment is loadable */ +if (!_check_segment (phdr)) + continue; > + +/* Get the offset of the segment within the region */ + offset = (phdr->p_paddr - fw_min_addr); + +/* Request the file containing the segment */ +snprintf (str,sizeof (str) -1 ,"%s.b%02d" , fwname, i);
snprintf(, size, ) writes at most size bytes and includes null termination, so drop the "- 1".
Quoted 6 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +6
-0+ + ret =request_firmware (&fw, str, &pdev->dev); +if (ret) { +dev_err (&pdev->dev,"Failed to load segment %s\n" , str); +break ; + }
drivers/gpu/drm/msm/adreno/a5xx_gpu.c line 71
Quoted 10 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +10
-0+ +if (offset + fw->size > fw_size) { +dev_err (&pdev->dev,"Segment %s is too big\n" , str); + ret = -EINVAL ; +release_firmware (fw); +break ; + } + +/* Copy the segment into place */ +memcpy (fwptr + offset, fw->data, fw->size);
Just to be on the safe side, please add:
if (phdr->p_memsz > phdr->p_filesz)memset(fwptr + fw->size, 0, phdr->p_memsz - phdr->p_filesz);
drivers/gpu/drm/msm/adreno/a5xx_gpu.c line 78
Quoted 7 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +7
-0+release_firmware (fw); + } + +return ret; +} + +static int _pil_tz_load_image (struct platform_device *pdev)
zap_load_mdt() ?
Quoted 5 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +5
-0+{ +char str[64 ] = {0 }; +const char *fwname; +const struct elf32_hdr *ehdr; +const struct elf32_phdr *phdrs;
drivers/gpu/drm/msm/adreno/a5xx_gpu.c line 93
Quoted 10 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +10
-0+const struct firmware *mdt; +phys_addr_t fw_min_addr, fw_max_addr; +dma_addr_t fw_phys; +size_t fw_size; +u32 pas_id; +void *ptr; +int i, ret; + +if (pdev ==NULL ) +return -ENODEV ;
This should not happen.
drivers/gpu/drm/msm/adreno/a5xx_gpu.c line 97
Quoted 4 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +4
-0+ +if (!qcom_scm_is_available ()) { +dev_err (&pdev->dev,"SCM is not available\n" ); +return -EINVAL ;
We generally return -EPROBE_DEFER here.
drivers/gpu/drm/msm/adreno/a5xx_gpu.c line 101
Quoted 4 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +4
-0+ } + + ret =of_reserved_mem_device_init (&pdev->dev); +
Please drop the extra newline.
drivers/gpu/drm/msm/adreno/a5xx_gpu.c line 114
Quoted 13 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +13
-0+if (ret) { +dev_err (&pdev->dev,"Unable to set up the reserved memory\n" ); +return ret; + } + +/* Get the firmware and PAS id from the device node */ +if (of_property_read_string (pdev->dev.of_node,"qcom,firmware" , + &fwname)) { +dev_err (&pdev->dev,"Could not read a firmware name\n" ); +return -EINVAL ; + } + +if (of_property_read_u32 (pdev->dev.of_node,"qcom,pas-id" , &pas_id)) {
This is constant, so define it in the driver.
drivers/gpu/drm/msm/adreno/a5xx_gpu.c line 119
Quoted 5 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +5
-0+dev_err (&pdev->dev,"Could not read the pas ID\n" ); +return -EINVAL ; + } + +snprintf (str,sizeof (str) -1 ,"%s.mdt" , fwname);
As above, re "- 1", name of str and initialization.
Quoted 43 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +43
-0+ +/* Request the MDT file for the firmware */ + ret =request_firmware (&mdt, str, &pdev->dev); +if (ret) { +dev_err (&pdev->dev,"Unable to load %s\n" , str); +return ret; + } + + ehdr = (struct elf32_hdr *) mdt->data; + phdrs = (struct elf32_phdr *) (ehdr +1 ); + +/* Get the extents of the firmware image */ + + fw_min_addr = (phys_addr_t )ULLONG_MAX ; + fw_max_addr =0 ; + +for (i =0 ; i < ehdr->e_phnum; i++) { +const struct elf32_phdr *phdr = &phdrs[i]; + +if (!_check_segment (phdr)) +continue ; + + fw_min_addr =min_t (phys_addr_t, fw_min_addr, phdr->p_paddr); + fw_max_addr =max_t (phys_addr_t, fw_max_addr, +PAGE_ALIGN (phdr->p_paddr + phdr->p_memsz)); + } + +if (fw_min_addr == (phys_addr_t )ULLONG_MAX && fw_max_addr ==0 ) + goto out; + + fw_size = (size_t ) (fw_max_addr - fw_min_addr); + +/* Verify the MDT header */ + ret =qcom_scm_pas_init_image (pas_id, mdt->data, mdt->size); +if (ret) { +dev_err (&pdev->dev,"Invalid firmware metadata\n" ); + goto out; + } + +/* allocate some memory */ + ptr =dma_alloc_coherent (&pdev->dev, fw_size, &fw_phys,GFP_KERNEL ); +if (ptr ==NULL ) + goto out;
drivers/gpu/drm/msm/adreno/a5xx_gpu.c line 172
Quoted 10 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +10
-0+ +/* Set up the newly allocated memory region */ + ret =qcom_scm_pas_mem_setup (pas_id, fw_phys, fw_size); +if (ret) { +dev_err (&pdev->dev,"Unable to set up firmware memory\n" ); + goto out; + } + + ret =__pil_tz_load_image (pdev, mdt, fwname, ptr, fw_size, fw_min_addr); +if (!ret) {
Please don't mix style like this, goto out on error.
drivers/gpu/drm/msm/adreno/a5xx_gpu.c line 185
Quoted 13 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +13
-0+ ret =qcom_scm_pas_auth_and_reset (pas_id); +if (ret) +dev_err (&pdev->dev,"Unable to authorize the image\n" ); + } + +out: +if (ret && ptr) +dma_free_coherent (&pdev->dev, fw_size, ptr, fw_phys); + +release_firmware (mdt); +return ret; +} +
Regards,
Bjorn
Re: [PATCH 11/12] drm/msm: Add a quick and dirty PIL loader
Quoted 3 lines · Bjorn Andersson
Quoted 1 line
+ if (
of_property_read_u32(pdev->dev.of_node, "qcom,pas-id", &pas_id)) {This is constant, so define it in the driver.
Little bit concerned it might not always be constant but I suppose we can cross that bridge when we get to it.
Quoted 2 lines
Regards,
Bjorn
Jordan
Signature · 6 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ Freedreno mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/freedreno
PATCH 12/12 drm/msm: gpu: Use the zap shader on 5XX if we can
In reply to Jordan CrouseThe 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.
--- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 72 ++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +70 -2
@@ -469,6 +469,55 @@ static int a5xx_ucode_init(struct msm_gpu *gpu)return 0 ; } +static int a5xx_zap_shader_resume (struct msm_gpu *gpu) +{ +int ret; + + ret =qcom_scm_gpu_zap_resume (); +if (ret) +DRM_ERROR ("%s: zap-shader resume failed: %d\n" , + gpu->name, ret); + +return ret; +} + +static int a5xx_zap_shader_init (struct msm_gpu *gpu) +{ +static bool loaded; +struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu); +struct a5xx_gpu *a5xx_gpu =to_a5xx_gpu (adreno_gpu); +struct platform_device *pdev = a5xx_gpu->pdev; +struct device_node *node; +int ret; + +/* +* If the zap shader is already loaded into memory we just need to kick +* the remote processor to reinitialize it +*/ +if (loaded) +return a5xx_zap_shader_resume (gpu); + +/* Populate the sub-nodes if they haven't already been done */ +of_platform_populate (pdev->dev.of_node,NULL ,NULL , &pdev->dev); + +/* Find the sub-node for the zap shader */ + node =of_find_node_by_name (pdev->dev.of_node,"qcom,zap-shader" ); +if (!node) { +DRM_ERROR ("%s: qcom,zap-shader not found in device tree\n" , + gpu->name); +return -ENODEV ; + } + + ret =_pil_tz_load_image (of_find_device_by_node (node)); +if (ret) +DRM_ERROR ("%s: Unable to load the zap shader\n" , + gpu->name); + + loaded = !ret; + +return ret; +} +#define A5XX_INT_MASK (A5XX_RBBM_INT_0_MASK_RBBM_AHB_ERROR | \ A5XX_RBBM_INT_0_MASK_RBBM_TRANSFER_TIMEOUT | \ A5XX_RBBM_INT_0_MASK_RBBM_ME_MS_TIMEOUT | \
@@ -653,8 +702,27 @@ static int a5xx_hw_init(struct msm_gpu *gpu)return -EINVAL ; } -/* Put the GPU into unsecure mode */ -gpu_write (gpu,REG_A5XX_RBBM_SECVID_TRUST_CNTL ,0x0 ); +/* +* Try to load a zap shader into the secure world. If successful +* we can use the CP to switch out of secure mode. If not then we +* have no resource but to try to switch ourselves out manually. If we +* guessed wrong then access to the RBBM_SECVID_TRUST_CNTL register will +* be blocked and a permissions violation will soon follow. +*/ + ret =a5xx_zap_shader_init (gpu); +if (!ret) { +OUT_PKT7 (gpu->rb,CP_SET_SECURE_MODE ,1 ); +OUT_RING (gpu->rb,0x00000000 ); + + gpu->funcs->flush (gpu); +if (!gpu->funcs->idle (gpu)) +return -EINVAL ; + }else { +/* Print a warning so if we die, we know why */ +dev_warn_once (gpu->dev->dev, +"Zap shader not enabled - using SECVID_TRUST_CNTL instead\n" ); +gpu_write (gpu,REG_A5XX_RBBM_SECVID_TRUST_CNTL ,0x0 ); + }return 0 ; }
Signature · 1 line
1.9.1
Re: [PATCH 12/12] drm/msm: gpu: Use the zap shader on 5XX if we can
Quoted 55 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_TRUSTregister 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.
Signed-off-by Jordan Crouse <[email protected]>--- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 72 ++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-)drivers/gpu/drm/msm/adreno/a5xx_gpu.c +16
-0@@ -469,6 +469,55 @@ static int a5xx_ucode_init(struct msm_gpu *gpu)return 0 ; } +static int a5xx_zap_shader_resume (struct msm_gpu *gpu) +{ +int ret; + + ret =qcom_scm_gpu_zap_resume (); +if (ret) +DRM_ERROR ("%s: zap-shader resume failed: %d\n" , + gpu->name, ret); + +return ret; +} + +static int a5xx_zap_shader_init (struct msm_gpu *gpu) +{ +static bool loaded; +struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu);
drivers/gpu/drm/msm/adreno/a5xx_gpu.c static int a5xx_ucode_init(struct msm_gpu *gpu) · line 497
Quoted 10 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +10
-0+struct a5xx_gpu *a5xx_gpu =to_a5xx_gpu (adreno_gpu); +struct platform_device *pdev = a5xx_gpu->pdev; +struct device_node *node; +int ret; + +/* +* If the zap shader is already loaded into memory we just need to kick +* the remote processor to reinitialize it +*/ +if (loaded)
Why is this handling needed? Why can init be called multiple times?
drivers/gpu/drm/msm/adreno/a5xx_gpu.c static int a5xx_ucode_init(struct msm_gpu *gpu) · line 501
Quoted 4 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +4
-0+return a5xx_zap_shader_resume (gpu); + +/* Populate the sub-nodes if they haven't already been done */ +of_platform_populate (pdev->dev.of_node,NULL ,NULL , &pdev->dev);
I haven't been able to find the qcom,zap-shader platform driver, but I presume you have something like:
adreno {
qcom,zap-shader {
compatible = "qcom,zap-shader";
firmware = "zapfw";
memory-region = <&zap_region>;
};
};I presume this is done to not "taint" the adreno device's with the zap memory region, but I don't think you should (ab)use a platform driver for this.
You should rather add a struct device zap_dev to your adreno context, do minimal initialization (name and a parent I think is enough), call device_register(&zap_dev);, of_reserved_mem_device_init() and then use that for your dma allocation.
This saves you from creating a platform_driver, instantiating a platform_device and the worry of the race between the creation of that device and the of_find_device_by_node() below.
drivers/gpu/drm/msm/adreno/a5xx_gpu.c static int a5xx_ucode_init(struct msm_gpu *gpu) · line 504
Quoted 3 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +3
-0+ +/* Find the sub-node for the zap shader */ + node =of_find_node_by_name (pdev->dev.of_node,"qcom,zap-shader" );
If you're looking for immediate children use of_get_child_by_name()
And no "qcom," in node names please.
Quoted 5 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +5
-0+if (!node) { +DRM_ERROR ("%s: qcom,zap-shader not found in device tree\n" , + gpu->name); +return -ENODEV ; + }
drivers/gpu/drm/msm/adreno/a5xx_gpu.c static int a5xx_ucode_init(struct msm_gpu *gpu) · line 519
Quoted 10 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +10
-0+ + ret =_pil_tz_load_image (of_find_device_by_node (node)); +if (ret) +DRM_ERROR ("%s: Unable to load the zap shader\n" , + gpu->name); + + loaded = !ret; + +return ret; +}
Regards,
Bjorn
Re: [PATCH 12/12] drm/msm: gpu: Use the zap shader on 5XX if we can
On Mon 05 Dec 11:57 PST 2016, Bjorn Andersson wrote:
[..]
Quoted 4 lines
You should rather add a struct device
zap_devto your adreno context, do minimal initialization (name and a parent I think is enough), calldevice_register(&zap_dev);,of_reserved_mem_device_init()and then use that for your dma allocation.
You would of course need to set the of_node on the zap_dev for of_reserved_mem_device_init() to work. Sorry for missing that.
Regards,
Bjorn
Re: [PATCH 12/12] drm/msm: gpu: Use the zap shader on 5XX if we can
In reply to Bjorn AnderssonQuoted 61 lines · Bjorn Andersson
Quoted 59 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_TRUSTregister 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.
Signed-off-by Jordan Crouse <[email protected]>--- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 72 ++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-)drivers/gpu/drm/msm/adreno/a5xx_gpu.c +20
-0@@ -469,6 +469,55 @@ static int a5xx_ucode_init(struct msm_gpu *gpu)return 0 ; } +static int a5xx_zap_shader_resume (struct msm_gpu *gpu) +{ +int ret; + + ret =qcom_scm_gpu_zap_resume (); +if (ret) +DRM_ERROR ("%s: zap-shader resume failed: %d\n" , + gpu->name, ret); + +return ret; +} + +static int a5xx_zap_shader_init (struct msm_gpu *gpu) +{ +static bool loaded; +struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu); +struct a5xx_gpu *a5xx_gpu =to_a5xx_gpu (adreno_gpu); +struct platform_device *pdev = a5xx_gpu->pdev; +struct device_node *node; +int ret;
Quoted 8 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c static int a5xx_ucode_init(struct msm_gpu *gpu) · line 497
Quoted 6 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +6
-0+ +/* +* If the zap shader is already loaded into memory we just need to kick +* the remote processor to reinitialize it +*/ +if (loaded)Why is this handling needed? Why can init be called multiple times?
This is for resume - if we suspend and resume the device without losing state the secure zone we can't load it again, so we have to call a different operation to "resume" it. This will be much more heavily used when we have more aggressive power management.
Quoted 21 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c static int a5xx_ucode_init(struct msm_gpu *gpu) · line 501
Quoted 4 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +4
-0+return a5xx_zap_shader_resume (gpu); + +/* Populate the sub-nodes if they haven't already been done */ +of_platform_populate (pdev->dev.of_node,NULL ,NULL , &pdev->dev);I haven't been able to find the qcom,zap-shader platform driver, but I presume you have something like:
adreno { qcom,zap-shader { compatible = "qcom,zap-shader"; firmware = "zapfw"; memory-region = <&zap_region>; }; };I presume this is done to not "taint" the adreno device's with the zap memory region, but I don't think you should (ab)use a platform driver for this.
Quoted 8 lines
You should rather add a struct device
zap_devto your adreno context, do minimal initialization (name and a parent I think is enough), calldevice_register(&zap_dev);,of_reserved_mem_device_init()and then use that for your dma allocation.This saves you from creating a
platform_driver, instantiating aplatform_deviceand the worry of the race between the creation of that device and theof_find_device_by_node()below.
As far as I know, of_platform_populate() just fleshed out the platform devices for the sub-nodes. We are not creating a new platform driver or doing any sort of probe code, we're just setting up the useful memory to attach the memory-region to. As far as I can tell, using of_platform_populate() + of_find_device_by_node() does a lot of the heavy lifting of what you describe.
Quoted 7 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c static int a5xx_ucode_init(struct msm_gpu *gpu) · line 504
Quoted 3 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +3
-0+ +/* Find the sub-node for the zap shader */ + node =of_find_node_by_name (pdev->dev.of_node,"qcom,zap-shader" );If you're looking for immediate children use
of_get_child_by_name()And no "qcom," in node names please.
Okay, can do.
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +10
-0+if (!node) { +DRM_ERROR ("%s: qcom,zap-shader not found in device tree\n" , + gpu->name); +return -ENODEV ; + } + + ret =_pil_tz_load_image (of_find_device_by_node (node)); +if (ret) +DRM_ERROR ("%s: Unable to load the zap shader\n" , + gpu->name);
Quoted 8 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c static int a5xx_ucode_init(struct msm_gpu *gpu) · line 519
Quoted 5 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +5
-0+ + loaded = !ret; + +return ret; +}Regards,
Bjorn
Jordan
Signature · 6 lines
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project _______________________________________________ Freedreno mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/freedreno
Re: [Freedreno] [PATCH 12/12] drm/msm: gpu: Use the zap shader on 5XX if we can
Quoted 71 lines · Jordan Crouse
Quoted 61 lines · Bjorn Andersson
Quoted 59 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_TRUSTregister 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.
Signed-off-by Jordan Crouse <[email protected]>--- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 72 ++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-)drivers/gpu/drm/msm/adreno/a5xx_gpu.c +20
-0@@ -469,6 +469,55 @@ static int a5xx_ucode_init(struct msm_gpu *gpu)return 0 ; } +static int a5xx_zap_shader_resume (struct msm_gpu *gpu) +{ +int ret; + + ret =qcom_scm_gpu_zap_resume (); +if (ret) +DRM_ERROR ("%s: zap-shader resume failed: %d\n" , + gpu->name, ret); + +return ret; +} + +static int a5xx_zap_shader_init (struct msm_gpu *gpu) +{ +static bool loaded; +struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu); +struct a5xx_gpu *a5xx_gpu =to_a5xx_gpu (adreno_gpu); +struct platform_device *pdev = a5xx_gpu->pdev; +struct device_node *node; +int ret;Quoted 8 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c static int a5xx_ucode_init(struct msm_gpu *gpu) · line 497
Quoted 6 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +6
-0+ +/* +* If the zap shader is already loaded into memory we just need to kick +* the remote processor to reinitialize it +*/ +if (loaded)Why is this handling needed? Why can init be called multiple times?
Quoted 4 lines
This is for resume - if we suspend and resume the device without losing state the secure zone we can't load it again, so we have to call a different operation to "resume" it. This will be much more heavily used when we have more aggressive power management.
also for recovery when I crash the gpu ;-)
BR,
-R
A message that is not in the archive (sent off-list or not yet received): 20161206153501.GA25541-9PYrDHPZ2Orvke4nUoYGnHL1okKdlPRT@public.gmane.org
Re: [PATCH 12/12] drm/msm: gpu: Use the zap shader on 5XX if we can
Quoted 71 lines · Jordan Crouse
Quoted 61 lines · Bjorn Andersson
Quoted 59 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_TRUSTregister 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.
Signed-off-by Jordan Crouse <[email protected]>--- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 72 ++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-)drivers/gpu/drm/msm/adreno/a5xx_gpu.c +20
-0@@ -469,6 +469,55 @@ static int a5xx_ucode_init(struct msm_gpu *gpu)return 0 ; } +static int a5xx_zap_shader_resume (struct msm_gpu *gpu) +{ +int ret; + + ret =qcom_scm_gpu_zap_resume (); +if (ret) +DRM_ERROR ("%s: zap-shader resume failed: %d\n" , + gpu->name, ret); + +return ret; +} + +static int a5xx_zap_shader_init (struct msm_gpu *gpu) +{ +static bool loaded; +struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu); +struct a5xx_gpu *a5xx_gpu =to_a5xx_gpu (adreno_gpu); +struct platform_device *pdev = a5xx_gpu->pdev; +struct device_node *node; +int ret;Quoted 8 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c static int a5xx_ucode_init(struct msm_gpu *gpu) · line 497
Quoted 6 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +6
-0+ +/* +* If the zap shader is already loaded into memory we just need to kick +* the remote processor to reinitialize it +*/ +if (loaded)Why is this handling needed? Why can init be called multiple times?
Quoted 5 lines
This is for resume - if we suspend and resume the device without losing state the secure zone we can't load it again, so we have to call a different operation to "resume" it. This will be much more heavily used when we have more aggressive power management.
I presume then that the rest of the resume path is the same as the initialization.
Quoted 26 lines
Quoted 26 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c static int a5xx_ucode_init(struct msm_gpu *gpu) · line 501
Quoted 4 lines
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +4
-0+return a5xx_zap_shader_resume (gpu); + +/* Populate the sub-nodes if they haven't already been done */ +of_platform_populate (pdev->dev.of_node,NULL ,NULL , &pdev->dev);I haven't been able to find the qcom,zap-shader platform driver, but I presume you have something like:
adreno { qcom,zap-shader { compatible = "qcom,zap-shader"; firmware = "zapfw"; memory-region = <&zap_region>; }; };I presume this is done to not "taint" the adreno device's with the zap memory region, but I don't think you should (ab)use a platform driver for this.
You should rather add a struct device
zap_devto your adreno context, do minimal initialization (name and a parent I think is enough), calldevice_register(&zap_dev);,of_reserved_mem_device_init()and then use that for your dma allocation.
Quoted 6 lines
Quoted 3 lines
This saves you from creating a
platform_driver, instantiating aplatform_deviceand the worry of the race between the creation of that device and theof_find_device_by_node()below.As far as I know,
of_platform_populate()just fleshed out the platform devices for the sub-nodes.
Correct, it will scan all subnodes and try to match their compatible with platform_drivers. For each match it finds it probes that driver.
Quoted 5 lines
We are not creating a new platform driver
or doing any sort of probe code, we're just setting up the useful memory to attach the memory-region to. As far as I can tell, usingof_platform_populate()+of_find_device_by_node()does a lot of the heavy lifting of what you describe.
But as far as I know the compatible of node that you name "qcom,zap-shader" must actually match a platform_driver for there to be a device that of_find_device_by_node() will be able to match against.
The heavy lifting I'm talking about is (untested):
struct device zap_dev;
zap_dev.of_node = of_get_child_by_name("zap-shader");
zap_dev.parent = &pdev->dev;
dev_set_name(&zap_dev, "zap-shader");
ret = device_register(&zap_dev);
if (ret < 0) {
dev_err();
return ret;
}
of_reserved_mem_device_init(&zap_dev);And then you need a device_put(&zap_dev) when you're done with the device and if you set zap_dev.release you can have that clean things up...
Regards,
Bjorn
_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno