drm/msm: gpu: Add A5XX target support
Add support for the A5XX family of Adreno GPUs. Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org> Signed-off-by: Rob Clark <robdclark@gmail.com>
This commit is contained in:
		
							parent
							
								
									4ac277cd9d
								
							
						
					
					
						commit
						b5f103ab98
					
				| @ -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 \
 | ||||
|  | ||||
							
								
								
									
										830
									
								
								drivers/gpu/drm/msm/adreno/a5xx_gpu.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										830
									
								
								drivers/gpu/drm/msm/adreno/a5xx_gpu.c
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,830 @@ | ||||
| /* 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. | ||||
|  * | ||||
|  */ | ||||
| 
 | ||||
| #include "msm_gem.h" | ||||
| #include "a5xx_gpu.h" | ||||
| 
 | ||||
| extern bool hang_debug; | ||||
| static void a5xx_dump(struct msm_gpu *gpu); | ||||
| 
 | ||||
| static void a5xx_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit, | ||||
| 	struct msm_file_private *ctx) | ||||
| { | ||||
| 	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu); | ||||
| 	struct msm_drm_private *priv = gpu->dev->dev_private; | ||||
| 	struct msm_ringbuffer *ring = gpu->rb; | ||||
| 	unsigned int i, ibs = 0; | ||||
| 
 | ||||
| 	for (i = 0; i < submit->nr_cmds; i++) { | ||||
| 		switch (submit->cmd[i].type) { | ||||
| 		case MSM_SUBMIT_CMD_IB_TARGET_BUF: | ||||
| 			break; | ||||
| 		case MSM_SUBMIT_CMD_CTX_RESTORE_BUF: | ||||
| 			if (priv->lastctx == ctx) | ||||
| 				break; | ||||
| 		case MSM_SUBMIT_CMD_BUF: | ||||
| 			OUT_PKT7(ring, CP_INDIRECT_BUFFER_PFE, 3); | ||||
| 			OUT_RING(ring, lower_32_bits(submit->cmd[i].iova)); | ||||
| 			OUT_RING(ring, upper_32_bits(submit->cmd[i].iova)); | ||||
| 			OUT_RING(ring, submit->cmd[i].size); | ||||
| 			ibs++; | ||||
| 			break; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	OUT_PKT4(ring, REG_A5XX_CP_SCRATCH_REG(2), 1); | ||||
| 	OUT_RING(ring, submit->fence->seqno); | ||||
| 
 | ||||
| 	OUT_PKT7(ring, CP_EVENT_WRITE, 4); | ||||
| 	OUT_RING(ring, CACHE_FLUSH_TS | (1 << 31)); | ||||
| 	OUT_RING(ring, lower_32_bits(rbmemptr(adreno_gpu, fence))); | ||||
| 	OUT_RING(ring, upper_32_bits(rbmemptr(adreno_gpu, fence))); | ||||
| 	OUT_RING(ring, submit->fence->seqno); | ||||
| 
 | ||||
| 	gpu->funcs->flush(gpu); | ||||
| } | ||||
| 
 | ||||
| struct a5xx_hwcg { | ||||
| 	u32 offset; | ||||
| 	u32 value; | ||||
| }; | ||||
| 
 | ||||
| static const struct a5xx_hwcg a530_hwcg[] = { | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_SP0, 0x02222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_SP1, 0x02222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_SP2, 0x02222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_SP3, 0x02222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_SP0, 0x02222220}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_SP1, 0x02222220}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_SP2, 0x02222220}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_SP3, 0x02222220}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_SP0, 0x0000F3CF}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_SP1, 0x0000F3CF}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_SP2, 0x0000F3CF}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_SP3, 0x0000F3CF}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_SP0, 0x00000080}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_SP1, 0x00000080}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_SP2, 0x00000080}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_SP3, 0x00000080}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_TP0, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_TP1, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_TP2, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_TP3, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_TP0, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_TP1, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_TP2, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_TP3, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL3_TP0, 0x00002222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL3_TP1, 0x00002222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL3_TP2, 0x00002222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL3_TP3, 0x00002222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_TP0, 0x77777777}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_TP1, 0x77777777}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_TP2, 0x77777777}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_TP3, 0x77777777}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST2_TP0, 0x77777777}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST2_TP1, 0x77777777}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST2_TP2, 0x77777777}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST2_TP3, 0x77777777}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST3_TP0, 0x00007777}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST3_TP1, 0x00007777}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST3_TP2, 0x00007777}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST3_TP3, 0x00007777}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_TP0, 0x11111111}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_TP1, 0x11111111}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_TP2, 0x11111111}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_TP3, 0x11111111}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY2_TP0, 0x11111111}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY2_TP1, 0x11111111}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY2_TP2, 0x11111111}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY2_TP3, 0x11111111}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY3_TP0, 0x00001111}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY3_TP1, 0x00001111}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY3_TP2, 0x00001111}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY3_TP3, 0x00001111}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_UCHE, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_UCHE, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL3_UCHE, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL4_UCHE, 0x00222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_UCHE, 0x00444444}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_UCHE, 0x00000002}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_RB0, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_RB1, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_RB2, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_RB3, 0x22222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_RB0, 0x00222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_RB1, 0x00222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_RB2, 0x00222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_RB3, 0x00222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_CCU0, 0x00022220}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_CCU1, 0x00022220}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_CCU2, 0x00022220}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_CCU3, 0x00022220}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_RAC, 0x05522222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL2_RAC, 0x00505555}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_RB_CCU0, 0x04040404}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_RB_CCU1, 0x04040404}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_RB_CCU2, 0x04040404}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_RB_CCU3, 0x04040404}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_RAC, 0x07444044}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_RB_CCU_L1_0, 0x00000002}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_RB_CCU_L1_1, 0x00000002}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_RB_CCU_L1_2, 0x00000002}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_RB_CCU_L1_3, 0x00000002}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_RAC, 0x00010011}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_CNTL_TSE_RAS_RBBM, 0x04222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_MODE_GPC, 0x02222222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_MODE_VFD, 0x00002222}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_TSE_RAS_RBBM, 0x00000000}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_GPC, 0x04104004}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_HYST_VFD, 0x00000000}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_GPC, 0x00000200}, | ||||
| 	{REG_A5XX_RBBM_CLOCK_DELAY_VFD, 0x00002222} | ||||
| }; | ||||
| 
 | ||||
| static const struct { | ||||
| 	int (*test)(struct adreno_gpu *gpu); | ||||
| 	const struct a5xx_hwcg *regs; | ||||
| 	unsigned int count; | ||||
| } a5xx_hwcg_regs[] = { | ||||
| 	{ adreno_is_a530, a530_hwcg, ARRAY_SIZE(a530_hwcg), }, | ||||
| }; | ||||
| 
 | ||||
| static void _a5xx_enable_hwcg(struct msm_gpu *gpu, | ||||
| 		const struct a5xx_hwcg *regs, unsigned int count) | ||||
| { | ||||
| 	unsigned int i; | ||||
| 
 | ||||
| 	for (i = 0; i < count; i++) | ||||
| 		gpu_write(gpu, regs[i].offset, regs[i].value); | ||||
| 
 | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_CLOCK_CNTL, 0xAAA8AA00); | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_ISDB_CNT, 0x182); | ||||
| } | ||||
| 
 | ||||
| static void a5xx_enable_hwcg(struct msm_gpu *gpu) | ||||
| { | ||||
| 	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu); | ||||
| 	unsigned int i; | ||||
| 
 | ||||
| 	for (i = 0; i < ARRAY_SIZE(a5xx_hwcg_regs); i++) { | ||||
| 		if (a5xx_hwcg_regs[i].test(adreno_gpu)) { | ||||
| 			_a5xx_enable_hwcg(gpu, a5xx_hwcg_regs[i].regs, | ||||
| 				a5xx_hwcg_regs[i].count); | ||||
| 			return; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| static int a5xx_me_init(struct msm_gpu *gpu) | ||||
| { | ||||
| 	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu); | ||||
| 	struct msm_ringbuffer *ring = gpu->rb; | ||||
| 
 | ||||
| 	OUT_PKT7(ring, CP_ME_INIT, 8); | ||||
| 
 | ||||
| 	OUT_RING(ring, 0x0000002F); | ||||
| 
 | ||||
| 	/* Enable multiple hardware contexts */ | ||||
| 	OUT_RING(ring, 0x00000003); | ||||
| 
 | ||||
| 	/* Enable error detection */ | ||||
| 	OUT_RING(ring, 0x20000000); | ||||
| 
 | ||||
| 	/* Don't enable header dump */ | ||||
| 	OUT_RING(ring, 0x00000000); | ||||
| 	OUT_RING(ring, 0x00000000); | ||||
| 
 | ||||
| 	/* Specify workarounds for various microcode issues */ | ||||
| 	if (adreno_is_a530(adreno_gpu)) { | ||||
| 		/* Workaround for token end syncs
 | ||||
| 		 * Force a WFI after every direct-render 3D mode draw and every | ||||
| 		 * 2D mode 3 draw | ||||
| 		 */ | ||||
| 		OUT_RING(ring, 0x0000000B); | ||||
| 	} else { | ||||
| 		/* No workarounds enabled */ | ||||
| 		OUT_RING(ring, 0x00000000); | ||||
| 	} | ||||
| 
 | ||||
| 	OUT_RING(ring, 0x00000000); | ||||
| 	OUT_RING(ring, 0x00000000); | ||||
| 
 | ||||
| 	gpu->funcs->flush(gpu); | ||||
| 
 | ||||
| 	return gpu->funcs->idle(gpu) ? 0 : -EINVAL; | ||||
| } | ||||
| 
 | ||||
| static struct drm_gem_object *a5xx_ucode_load_bo(struct msm_gpu *gpu, | ||||
| 		const struct firmware *fw, u64 *iova) | ||||
| { | ||||
| 	struct drm_device *drm = gpu->dev; | ||||
| 	struct drm_gem_object *bo; | ||||
| 	void *ptr; | ||||
| 
 | ||||
| 	mutex_lock(&drm->struct_mutex); | ||||
| 	bo = msm_gem_new(drm, fw->size - 4, MSM_BO_UNCACHED); | ||||
| 	mutex_unlock(&drm->struct_mutex); | ||||
| 
 | ||||
| 	if (IS_ERR(bo)) | ||||
| 		return bo; | ||||
| 
 | ||||
| 	ptr = msm_gem_get_vaddr(bo); | ||||
| 	if (!ptr) { | ||||
| 		drm_gem_object_unreference_unlocked(bo); | ||||
| 		return ERR_PTR(-ENOMEM); | ||||
| 	} | ||||
| 
 | ||||
| 	if (iova) { | ||||
| 		int ret = msm_gem_get_iova(bo, gpu->id, iova); | ||||
| 
 | ||||
| 		if (ret) { | ||||
| 			drm_gem_object_unreference_unlocked(bo); | ||||
| 			return ERR_PTR(ret); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	memcpy(ptr, &fw->data[4], fw->size - 4); | ||||
| 
 | ||||
| 	msm_gem_put_vaddr(bo); | ||||
| 	return bo; | ||||
| } | ||||
| 
 | ||||
| static int a5xx_ucode_init(struct msm_gpu *gpu) | ||||
| { | ||||
| 	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu); | ||||
| 	struct a5xx_gpu *a5xx_gpu = to_a5xx_gpu(adreno_gpu); | ||||
| 	int ret; | ||||
| 
 | ||||
| 	if (!a5xx_gpu->pm4_bo) { | ||||
| 		a5xx_gpu->pm4_bo = a5xx_ucode_load_bo(gpu, adreno_gpu->pm4, | ||||
| 			&a5xx_gpu->pm4_iova); | ||||
| 
 | ||||
| 		if (IS_ERR(a5xx_gpu->pm4_bo)) { | ||||
| 			ret = PTR_ERR(a5xx_gpu->pm4_bo); | ||||
| 			a5xx_gpu->pm4_bo = NULL; | ||||
| 			dev_err(gpu->dev->dev, "could not allocate PM4: %d\n", | ||||
| 				ret); | ||||
| 			return ret; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	if (!a5xx_gpu->pfp_bo) { | ||||
| 		a5xx_gpu->pfp_bo = a5xx_ucode_load_bo(gpu, adreno_gpu->pfp, | ||||
| 			&a5xx_gpu->pfp_iova); | ||||
| 
 | ||||
| 		if (IS_ERR(a5xx_gpu->pfp_bo)) { | ||||
| 			ret = PTR_ERR(a5xx_gpu->pfp_bo); | ||||
| 			a5xx_gpu->pfp_bo = NULL; | ||||
| 			dev_err(gpu->dev->dev, "could not allocate PFP: %d\n", | ||||
| 				ret); | ||||
| 			return ret; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	gpu_write64(gpu, REG_A5XX_CP_ME_INSTR_BASE_LO, | ||||
| 		REG_A5XX_CP_ME_INSTR_BASE_HI, a5xx_gpu->pm4_iova); | ||||
| 
 | ||||
| 	gpu_write64(gpu, REG_A5XX_CP_PFP_INSTR_BASE_LO, | ||||
| 		REG_A5XX_CP_PFP_INSTR_BASE_HI, a5xx_gpu->pfp_iova); | ||||
| 
 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| #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 | \ | ||||
| 	  A5XX_RBBM_INT_0_MASK_RBBM_PFP_MS_TIMEOUT | \ | ||||
| 	  A5XX_RBBM_INT_0_MASK_RBBM_ETS_MS_TIMEOUT | \ | ||||
| 	  A5XX_RBBM_INT_0_MASK_RBBM_ATB_ASYNC_OVERFLOW | \ | ||||
| 	  A5XX_RBBM_INT_0_MASK_CP_HW_ERROR | \ | ||||
| 	  A5XX_RBBM_INT_0_MASK_CP_CACHE_FLUSH_TS | \ | ||||
| 	  A5XX_RBBM_INT_0_MASK_UCHE_OOB_ACCESS | \ | ||||
| 	  A5XX_RBBM_INT_0_MASK_GPMU_VOLTAGE_DROOP) | ||||
| 
 | ||||
| static int a5xx_hw_init(struct msm_gpu *gpu) | ||||
| { | ||||
| 	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu); | ||||
| 	int ret; | ||||
| 
 | ||||
| 	gpu_write(gpu, REG_A5XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x00000003); | ||||
| 
 | ||||
| 	/* Make all blocks contribute to the GPU BUSY perf counter */ | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_PERFCTR_GPU_BUSY_MASKED, 0xFFFFFFFF); | ||||
| 
 | ||||
| 	/* Enable RBBM error reporting bits */ | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_AHB_CNTL0, 0x00000001); | ||||
| 
 | ||||
| 	if (adreno_gpu->quirks & ADRENO_QUIRK_FAULT_DETECT_MASK) { | ||||
| 		/*
 | ||||
| 		 * Mask out the activity signals from RB1-3 to avoid false | ||||
| 		 * positives | ||||
| 		 */ | ||||
| 
 | ||||
| 		gpu_write(gpu, REG_A5XX_RBBM_INTERFACE_HANG_MASK_CNTL11, | ||||
| 			0xF0000000); | ||||
| 		gpu_write(gpu, REG_A5XX_RBBM_INTERFACE_HANG_MASK_CNTL12, | ||||
| 			0xFFFFFFFF); | ||||
| 		gpu_write(gpu, REG_A5XX_RBBM_INTERFACE_HANG_MASK_CNTL13, | ||||
| 			0xFFFFFFFF); | ||||
| 		gpu_write(gpu, REG_A5XX_RBBM_INTERFACE_HANG_MASK_CNTL14, | ||||
| 			0xFFFFFFFF); | ||||
| 		gpu_write(gpu, REG_A5XX_RBBM_INTERFACE_HANG_MASK_CNTL15, | ||||
| 			0xFFFFFFFF); | ||||
| 		gpu_write(gpu, REG_A5XX_RBBM_INTERFACE_HANG_MASK_CNTL16, | ||||
| 			0xFFFFFFFF); | ||||
| 		gpu_write(gpu, REG_A5XX_RBBM_INTERFACE_HANG_MASK_CNTL17, | ||||
| 			0xFFFFFFFF); | ||||
| 		gpu_write(gpu, REG_A5XX_RBBM_INTERFACE_HANG_MASK_CNTL18, | ||||
| 			0xFFFFFFFF); | ||||
| 	} | ||||
| 
 | ||||
| 	/* Enable fault detection */ | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_INTERFACE_HANG_INT_CNTL, | ||||
| 		(1 << 30) | 0xFFFF); | ||||
| 
 | ||||
| 	/* Turn on performance counters */ | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_PERFCTR_CNTL, 0x01); | ||||
| 
 | ||||
| 	/* Increase VFD cache access so LRZ and other data gets evicted less */ | ||||
| 	gpu_write(gpu, REG_A5XX_UCHE_CACHE_WAYS, 0x02); | ||||
| 
 | ||||
| 	/* Disable L2 bypass in the UCHE */ | ||||
| 	gpu_write(gpu, REG_A5XX_UCHE_TRAP_BASE_LO, 0xFFFF0000); | ||||
| 	gpu_write(gpu, REG_A5XX_UCHE_TRAP_BASE_HI, 0x0001FFFF); | ||||
| 	gpu_write(gpu, REG_A5XX_UCHE_WRITE_THRU_BASE_LO, 0xFFFF0000); | ||||
| 	gpu_write(gpu, REG_A5XX_UCHE_WRITE_THRU_BASE_HI, 0x0001FFFF); | ||||
| 
 | ||||
| 	/* Set the GMEM VA range (0 to gpu->gmem) */ | ||||
| 	gpu_write(gpu, REG_A5XX_UCHE_GMEM_RANGE_MIN_LO, 0x00100000); | ||||
| 	gpu_write(gpu, REG_A5XX_UCHE_GMEM_RANGE_MIN_HI, 0x00000000); | ||||
| 	gpu_write(gpu, REG_A5XX_UCHE_GMEM_RANGE_MAX_LO, | ||||
| 		0x00100000 + adreno_gpu->gmem - 1); | ||||
| 	gpu_write(gpu, REG_A5XX_UCHE_GMEM_RANGE_MAX_HI, 0x00000000); | ||||
| 
 | ||||
| 	gpu_write(gpu, REG_A5XX_CP_MEQ_THRESHOLDS, 0x40); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_MERCIU_SIZE, 0x40); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_ROQ_THRESHOLDS_2, 0x80000060); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_ROQ_THRESHOLDS_1, 0x40201B16); | ||||
| 
 | ||||
| 	gpu_write(gpu, REG_A5XX_PC_DBG_ECO_CNTL, (0x400 << 11 | 0x300 << 22)); | ||||
| 
 | ||||
| 	if (adreno_gpu->quirks & ADRENO_QUIRK_TWO_PASS_USE_WFI) | ||||
| 		gpu_rmw(gpu, REG_A5XX_PC_DBG_ECO_CNTL, 0, (1 << 8)); | ||||
| 
 | ||||
| 	gpu_write(gpu, REG_A5XX_PC_DBG_ECO_CNTL, 0xc0200100); | ||||
| 
 | ||||
| 	/* Enable USE_RETENTION_FLOPS */ | ||||
| 	gpu_write(gpu, REG_A5XX_CP_CHICKEN_DBG, 0x02000000); | ||||
| 
 | ||||
| 	/* Enable ME/PFP split notification */ | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_AHB_CNTL1, 0xA6FFFFFF); | ||||
| 
 | ||||
| 	/* Enable HWCG */ | ||||
| 	a5xx_enable_hwcg(gpu); | ||||
| 
 | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_AHB_CNTL2, 0x0000003F); | ||||
| 
 | ||||
| 	/* Set the highest bank bit */ | ||||
| 	gpu_write(gpu, REG_A5XX_TPL1_MODE_CNTL, 2 << 7); | ||||
| 	gpu_write(gpu, REG_A5XX_RB_MODE_CNTL, 2 << 1); | ||||
| 
 | ||||
| 	/* Protect registers from the CP */ | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT_CNTL, 0x00000007); | ||||
| 
 | ||||
| 	/* RBBM */ | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(0), ADRENO_PROTECT_RW(0x04, 4)); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(1), ADRENO_PROTECT_RW(0x08, 8)); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(2), ADRENO_PROTECT_RW(0x10, 16)); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(3), ADRENO_PROTECT_RW(0x20, 32)); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(4), ADRENO_PROTECT_RW(0x40, 64)); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(5), ADRENO_PROTECT_RW(0x80, 64)); | ||||
| 
 | ||||
| 	/* Content protect */ | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(6), | ||||
| 		ADRENO_PROTECT_RW(REG_A5XX_RBBM_SECVID_TSB_TRUSTED_BASE_LO, | ||||
| 			16)); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(7), | ||||
| 		ADRENO_PROTECT_RW(REG_A5XX_RBBM_SECVID_TRUST_CNTL, 2)); | ||||
| 
 | ||||
| 	/* CP */ | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(8), ADRENO_PROTECT_RW(0x800, 64)); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(9), ADRENO_PROTECT_RW(0x840, 8)); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(10), ADRENO_PROTECT_RW(0x880, 32)); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(11), ADRENO_PROTECT_RW(0xAA0, 1)); | ||||
| 
 | ||||
| 	/* RB */ | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(12), ADRENO_PROTECT_RW(0xCC0, 1)); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(13), ADRENO_PROTECT_RW(0xCF0, 2)); | ||||
| 
 | ||||
| 	/* VPC */ | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(14), ADRENO_PROTECT_RW(0xE68, 8)); | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(15), ADRENO_PROTECT_RW(0xE70, 4)); | ||||
| 
 | ||||
| 	/* UCHE */ | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PROTECT(16), ADRENO_PROTECT_RW(0xE80, 16)); | ||||
| 
 | ||||
| 	if (adreno_is_a530(adreno_gpu)) | ||||
| 		gpu_write(gpu, REG_A5XX_CP_PROTECT(17), | ||||
| 			ADRENO_PROTECT_RW(0x10000, 0x8000)); | ||||
| 
 | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_SECVID_TSB_CNTL, 0); | ||||
| 	/*
 | ||||
| 	 * Disable the trusted memory range - we don't actually supported secure | ||||
| 	 * memory rendering at this point in time and we don't want to block off | ||||
| 	 * part of the virtual memory space. | ||||
| 	 */ | ||||
| 	gpu_write64(gpu, REG_A5XX_RBBM_SECVID_TSB_TRUSTED_BASE_LO, | ||||
| 		REG_A5XX_RBBM_SECVID_TSB_TRUSTED_BASE_HI, 0x00000000); | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_SECVID_TSB_TRUSTED_SIZE, 0x00000000); | ||||
| 
 | ||||
| 	ret = adreno_hw_init(gpu); | ||||
| 	if (ret) | ||||
| 		return ret; | ||||
| 
 | ||||
| 	ret = a5xx_ucode_init(gpu); | ||||
| 	if (ret) | ||||
| 		return ret; | ||||
| 
 | ||||
| 	/* Disable the interrupts through the initial bringup stage */ | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_INT_0_MASK, A5XX_INT_MASK); | ||||
| 
 | ||||
| 	/* Clear ME_HALT to start the micro engine */ | ||||
| 	gpu_write(gpu, REG_A5XX_CP_PFP_ME_CNTL, 0); | ||||
| 	ret = a5xx_me_init(gpu); | ||||
| 	if (ret) | ||||
| 		return ret; | ||||
| 
 | ||||
| 	/* Put the GPU into insecure mode */ | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_SECVID_TRUST_CNTL, 0x0); | ||||
| 
 | ||||
| 	/*
 | ||||
| 	 * Send a pipeline event stat to get misbehaving counters to start | ||||
| 	 * ticking correctly | ||||
| 	 */ | ||||
| 	if (adreno_is_a530(adreno_gpu)) { | ||||
| 		OUT_PKT7(gpu->rb, CP_EVENT_WRITE, 1); | ||||
| 		OUT_RING(gpu->rb, 0x0F); | ||||
| 
 | ||||
| 		gpu->funcs->flush(gpu); | ||||
| 		if (!gpu->funcs->idle(gpu)) | ||||
| 			return -EINVAL; | ||||
| 	} | ||||
| 
 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| static void a5xx_recover(struct msm_gpu *gpu) | ||||
| { | ||||
| 	int i; | ||||
| 
 | ||||
| 	adreno_dump_info(gpu); | ||||
| 
 | ||||
| 	for (i = 0; i < 8; i++) { | ||||
| 		printk("CP_SCRATCH_REG%d: %u\n", i, | ||||
| 			gpu_read(gpu, REG_A5XX_CP_SCRATCH_REG(i))); | ||||
| 	} | ||||
| 
 | ||||
| 	if (hang_debug) | ||||
| 		a5xx_dump(gpu); | ||||
| 
 | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_SW_RESET_CMD, 1); | ||||
| 	gpu_read(gpu, REG_A5XX_RBBM_SW_RESET_CMD); | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_SW_RESET_CMD, 0); | ||||
| 	adreno_recover(gpu); | ||||
| } | ||||
| 
 | ||||
| static void a5xx_destroy(struct msm_gpu *gpu) | ||||
| { | ||||
| 	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu); | ||||
| 	struct a5xx_gpu *a5xx_gpu = to_a5xx_gpu(adreno_gpu); | ||||
| 
 | ||||
| 	DBG("%s", gpu->name); | ||||
| 
 | ||||
| 	if (a5xx_gpu->pm4_bo) { | ||||
| 		if (a5xx_gpu->pm4_iova) | ||||
| 			msm_gem_put_iova(a5xx_gpu->pm4_bo, gpu->id); | ||||
| 		drm_gem_object_unreference_unlocked(a5xx_gpu->pm4_bo); | ||||
| 	} | ||||
| 
 | ||||
| 	if (a5xx_gpu->pfp_bo) { | ||||
| 		if (a5xx_gpu->pfp_iova) | ||||
| 			msm_gem_put_iova(a5xx_gpu->pfp_bo, gpu->id); | ||||
| 		drm_gem_object_unreference_unlocked(a5xx_gpu->pfp_bo); | ||||
| 	} | ||||
| 
 | ||||
| 	adreno_gpu_cleanup(adreno_gpu); | ||||
| 	kfree(a5xx_gpu); | ||||
| } | ||||
| 
 | ||||
| static inline bool _a5xx_check_idle(struct msm_gpu *gpu) | ||||
| { | ||||
| 	if (gpu_read(gpu, REG_A5XX_RBBM_STATUS) & ~A5XX_RBBM_STATUS_HI_BUSY) | ||||
| 		return false; | ||||
| 
 | ||||
| 	/*
 | ||||
| 	 * Nearly every abnormality ends up pausing the GPU and triggering a | ||||
| 	 * fault so we can safely just watch for this one interrupt to fire | ||||
| 	 */ | ||||
| 	return !(gpu_read(gpu, REG_A5XX_RBBM_INT_0_STATUS) & | ||||
| 		A5XX_RBBM_INT_0_MASK_MISC_HANG_DETECT); | ||||
| } | ||||
| 
 | ||||
| static bool a5xx_idle(struct msm_gpu *gpu) | ||||
| { | ||||
| 	/* wait for CP to drain ringbuffer: */ | ||||
| 	if (!adreno_idle(gpu)) | ||||
| 		return false; | ||||
| 
 | ||||
| 	if (spin_until(_a5xx_check_idle(gpu))) { | ||||
| 		DRM_ERROR("%s: %ps: timeout waiting for GPU to idle: status %8.8X irq %8.8X\n", | ||||
| 			gpu->name, __builtin_return_address(0), | ||||
| 			gpu_read(gpu, REG_A5XX_RBBM_STATUS), | ||||
| 			gpu_read(gpu, REG_A5XX_RBBM_INT_0_STATUS)); | ||||
| 
 | ||||
| 		return false; | ||||
| 	} | ||||
| 
 | ||||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| static void a5xx_cp_err_irq(struct msm_gpu *gpu) | ||||
| { | ||||
| 	u32 status = gpu_read(gpu, REG_A5XX_CP_INTERRUPT_STATUS); | ||||
| 
 | ||||
| 	if (status & A5XX_CP_INT_CP_OPCODE_ERROR) { | ||||
| 		u32 val; | ||||
| 
 | ||||
| 		gpu_write(gpu, REG_A5XX_CP_PFP_STAT_ADDR, 0); | ||||
| 
 | ||||
| 		/*
 | ||||
| 		 * REG_A5XX_CP_PFP_STAT_DATA is indexed, and we want index 1 so | ||||
| 		 * read it twice | ||||
| 		 */ | ||||
| 
 | ||||
| 		gpu_read(gpu, REG_A5XX_CP_PFP_STAT_DATA); | ||||
| 		val = gpu_read(gpu, REG_A5XX_CP_PFP_STAT_DATA); | ||||
| 
 | ||||
| 		dev_err_ratelimited(gpu->dev->dev, "CP | opcode error | possible opcode=0x%8.8X\n", | ||||
| 			val); | ||||
| 	} | ||||
| 
 | ||||
| 	if (status & A5XX_CP_INT_CP_HW_FAULT_ERROR) | ||||
| 		dev_err_ratelimited(gpu->dev->dev, "CP | HW fault | status=0x%8.8X\n", | ||||
| 			gpu_read(gpu, REG_A5XX_CP_HW_FAULT)); | ||||
| 
 | ||||
| 	if (status & A5XX_CP_INT_CP_DMA_ERROR) | ||||
| 		dev_err_ratelimited(gpu->dev->dev, "CP | DMA error\n"); | ||||
| 
 | ||||
| 	if (status & A5XX_CP_INT_CP_REGISTER_PROTECTION_ERROR) { | ||||
| 		u32 val = gpu_read(gpu, REG_A5XX_CP_PROTECT_STATUS); | ||||
| 
 | ||||
| 		dev_err_ratelimited(gpu->dev->dev, | ||||
| 			"CP | protected mode error | %s | addr=0x%8.8X | status=0x%8.8X\n", | ||||
| 			val & (1 << 24) ? "WRITE" : "READ", | ||||
| 			(val & 0xFFFFF) >> 2, val); | ||||
| 	} | ||||
| 
 | ||||
| 	if (status & A5XX_CP_INT_CP_AHB_ERROR) { | ||||
| 		u32 status = gpu_read(gpu, REG_A5XX_CP_AHB_FAULT); | ||||
| 		const char *access[16] = { "reserved", "reserved", | ||||
| 			"timestamp lo", "timestamp hi", "pfp read", "pfp write", | ||||
| 			"", "", "me read", "me write", "", "", "crashdump read", | ||||
| 			"crashdump write" }; | ||||
| 
 | ||||
| 		dev_err_ratelimited(gpu->dev->dev, | ||||
| 			"CP | AHB error | addr=%X access=%s error=%d | status=0x%8.8X\n", | ||||
| 			status & 0xFFFFF, access[(status >> 24) & 0xF], | ||||
| 			(status & (1 << 31)), status); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| static void a5xx_rbbm_err_irq(struct msm_gpu *gpu) | ||||
| { | ||||
| 	u32 status = gpu_read(gpu, REG_A5XX_RBBM_INT_0_STATUS); | ||||
| 
 | ||||
| 	if (status & A5XX_RBBM_INT_0_MASK_RBBM_AHB_ERROR) { | ||||
| 		u32 val = gpu_read(gpu, REG_A5XX_RBBM_AHB_ERROR_STATUS); | ||||
| 
 | ||||
| 		dev_err_ratelimited(gpu->dev->dev, | ||||
| 			"RBBM | AHB bus error | %s | addr=0x%X | ports=0x%X:0x%X\n", | ||||
| 			val & (1 << 28) ? "WRITE" : "READ", | ||||
| 			(val & 0xFFFFF) >> 2, (val >> 20) & 0x3, | ||||
| 			(val >> 24) & 0xF); | ||||
| 
 | ||||
| 		/* Clear the error */ | ||||
| 		gpu_write(gpu, REG_A5XX_RBBM_AHB_CMD, (1 << 4)); | ||||
| 	} | ||||
| 
 | ||||
| 	if (status & A5XX_RBBM_INT_0_MASK_RBBM_TRANSFER_TIMEOUT) | ||||
| 		dev_err_ratelimited(gpu->dev->dev, "RBBM | AHB transfer timeout\n"); | ||||
| 
 | ||||
| 	if (status & A5XX_RBBM_INT_0_MASK_RBBM_ME_MS_TIMEOUT) | ||||
| 		dev_err_ratelimited(gpu->dev->dev, "RBBM | ME master split | status=0x%X\n", | ||||
| 			gpu_read(gpu, REG_A5XX_RBBM_AHB_ME_SPLIT_STATUS)); | ||||
| 
 | ||||
| 	if (status & A5XX_RBBM_INT_0_MASK_RBBM_PFP_MS_TIMEOUT) | ||||
| 		dev_err_ratelimited(gpu->dev->dev, "RBBM | PFP master split | status=0x%X\n", | ||||
| 			gpu_read(gpu, REG_A5XX_RBBM_AHB_PFP_SPLIT_STATUS)); | ||||
| 
 | ||||
| 	if (status & A5XX_RBBM_INT_0_MASK_RBBM_ETS_MS_TIMEOUT) | ||||
| 		dev_err_ratelimited(gpu->dev->dev, "RBBM | ETS master split | status=0x%X\n", | ||||
| 			gpu_read(gpu, REG_A5XX_RBBM_AHB_ETS_SPLIT_STATUS)); | ||||
| 
 | ||||
| 	if (status & A5XX_RBBM_INT_0_MASK_RBBM_ATB_ASYNC_OVERFLOW) | ||||
| 		dev_err_ratelimited(gpu->dev->dev, "RBBM | ATB ASYNC overflow\n"); | ||||
| 
 | ||||
| 	if (status & A5XX_RBBM_INT_0_MASK_RBBM_ATB_BUS_OVERFLOW) | ||||
| 		dev_err_ratelimited(gpu->dev->dev, "RBBM | ATB bus overflow\n"); | ||||
| } | ||||
| 
 | ||||
| static void a5xx_uche_err_irq(struct msm_gpu *gpu) | ||||
| { | ||||
| 	uint64_t addr = (uint64_t) gpu_read(gpu, REG_A5XX_UCHE_TRAP_LOG_HI); | ||||
| 
 | ||||
| 	addr |= gpu_read(gpu, REG_A5XX_UCHE_TRAP_LOG_LO); | ||||
| 
 | ||||
| 	dev_err_ratelimited(gpu->dev->dev, "UCHE | Out of bounds access | addr=0x%llX\n", | ||||
| 		addr); | ||||
| } | ||||
| 
 | ||||
| static void a5xx_gpmu_err_irq(struct msm_gpu *gpu) | ||||
| { | ||||
| 	dev_err_ratelimited(gpu->dev->dev, "GPMU | voltage droop\n"); | ||||
| } | ||||
| 
 | ||||
| #define RBBM_ERROR_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 | \ | ||||
| 	A5XX_RBBM_INT_0_MASK_RBBM_PFP_MS_TIMEOUT | \ | ||||
| 	A5XX_RBBM_INT_0_MASK_RBBM_ETS_MS_TIMEOUT | \ | ||||
| 	A5XX_RBBM_INT_0_MASK_RBBM_ATB_ASYNC_OVERFLOW) | ||||
| 
 | ||||
| static irqreturn_t a5xx_irq(struct msm_gpu *gpu) | ||||
| { | ||||
| 	u32 status = gpu_read(gpu, REG_A5XX_RBBM_INT_0_STATUS); | ||||
| 
 | ||||
| 	gpu_write(gpu, REG_A5XX_RBBM_INT_CLEAR_CMD, status); | ||||
| 
 | ||||
| 	if (status & RBBM_ERROR_MASK) | ||||
| 		a5xx_rbbm_err_irq(gpu); | ||||
| 
 | ||||
| 	if (status & A5XX_RBBM_INT_0_MASK_CP_HW_ERROR) | ||||
| 		a5xx_cp_err_irq(gpu); | ||||
| 
 | ||||
| 	if (status & A5XX_RBBM_INT_0_MASK_UCHE_OOB_ACCESS) | ||||
| 		a5xx_uche_err_irq(gpu); | ||||
| 
 | ||||
| 	if (status & A5XX_RBBM_INT_0_MASK_GPMU_VOLTAGE_DROOP) | ||||
| 		a5xx_gpmu_err_irq(gpu); | ||||
| 
 | ||||
| 	if (status & A5XX_RBBM_INT_0_MASK_CP_CACHE_FLUSH_TS) | ||||
| 		msm_gpu_retire(gpu); | ||||
| 
 | ||||
| 	return IRQ_HANDLED; | ||||
| } | ||||
| 
 | ||||
| static const u32 a5xx_register_offsets[REG_ADRENO_REGISTER_MAX] = { | ||||
| 	REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_BASE, REG_A5XX_CP_RB_BASE), | ||||
| 	REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_BASE_HI, REG_A5XX_CP_RB_BASE_HI), | ||||
| 	REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_RPTR_ADDR, REG_A5XX_CP_RB_RPTR_ADDR), | ||||
| 	REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_RPTR_ADDR_HI, | ||||
| 		REG_A5XX_CP_RB_RPTR_ADDR_HI), | ||||
| 	REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_RPTR, REG_A5XX_CP_RB_RPTR), | ||||
| 	REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_WPTR, REG_A5XX_CP_RB_WPTR), | ||||
| 	REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_CNTL, REG_A5XX_CP_RB_CNTL), | ||||
| }; | ||||
| 
 | ||||
| static const u32 a5xx_registers[] = { | ||||
| 	0x0000, 0x0002, 0x0004, 0x0020, 0x0022, 0x0026, 0x0029, 0x002B, | ||||
| 	0x002E, 0x0035, 0x0038, 0x0042, 0x0044, 0x0044, 0x0047, 0x0095, | ||||
| 	0x0097, 0x00BB, 0x03A0, 0x0464, 0x0469, 0x046F, 0x04D2, 0x04D3, | ||||
| 	0x04E0, 0x0533, 0x0540, 0x0555, 0xF400, 0xF400, 0xF800, 0xF807, | ||||
| 	0x0800, 0x081A, 0x081F, 0x0841, 0x0860, 0x0860, 0x0880, 0x08A0, | ||||
| 	0x0B00, 0x0B12, 0x0B15, 0x0B28, 0x0B78, 0x0B7F, 0x0BB0, 0x0BBD, | ||||
| 	0x0BC0, 0x0BC6, 0x0BD0, 0x0C53, 0x0C60, 0x0C61, 0x0C80, 0x0C82, | ||||
| 	0x0C84, 0x0C85, 0x0C90, 0x0C98, 0x0CA0, 0x0CA0, 0x0CB0, 0x0CB2, | ||||
| 	0x2180, 0x2185, 0x2580, 0x2585, 0x0CC1, 0x0CC1, 0x0CC4, 0x0CC7, | ||||
| 	0x0CCC, 0x0CCC, 0x0CD0, 0x0CD8, 0x0CE0, 0x0CE5, 0x0CE8, 0x0CE8, | ||||
| 	0x0CEC, 0x0CF1, 0x0CFB, 0x0D0E, 0x2100, 0x211E, 0x2140, 0x2145, | ||||
| 	0x2500, 0x251E, 0x2540, 0x2545, 0x0D10, 0x0D17, 0x0D20, 0x0D23, | ||||
| 	0x0D30, 0x0D30, 0x20C0, 0x20C0, 0x24C0, 0x24C0, 0x0E40, 0x0E43, | ||||
| 	0x0E4A, 0x0E4A, 0x0E50, 0x0E57, 0x0E60, 0x0E7C, 0x0E80, 0x0E8E, | ||||
| 	0x0E90, 0x0E96, 0x0EA0, 0x0EA8, 0x0EB0, 0x0EB2, 0xE140, 0xE147, | ||||
| 	0xE150, 0xE187, 0xE1A0, 0xE1A9, 0xE1B0, 0xE1B6, 0xE1C0, 0xE1C7, | ||||
| 	0xE1D0, 0xE1D1, 0xE200, 0xE201, 0xE210, 0xE21C, 0xE240, 0xE268, | ||||
| 	0xE000, 0xE006, 0xE010, 0xE09A, 0xE0A0, 0xE0A4, 0xE0AA, 0xE0EB, | ||||
| 	0xE100, 0xE105, 0xE380, 0xE38F, 0xE3B0, 0xE3B0, 0xE400, 0xE405, | ||||
| 	0xE408, 0xE4E9, 0xE4F0, 0xE4F0, 0xE280, 0xE280, 0xE282, 0xE2A3, | ||||
| 	0xE2A5, 0xE2C2, 0xE940, 0xE947, 0xE950, 0xE987, 0xE9A0, 0xE9A9, | ||||
| 	0xE9B0, 0xE9B6, 0xE9C0, 0xE9C7, 0xE9D0, 0xE9D1, 0xEA00, 0xEA01, | ||||
| 	0xEA10, 0xEA1C, 0xEA40, 0xEA68, 0xE800, 0xE806, 0xE810, 0xE89A, | ||||
| 	0xE8A0, 0xE8A4, 0xE8AA, 0xE8EB, 0xE900, 0xE905, 0xEB80, 0xEB8F, | ||||
| 	0xEBB0, 0xEBB0, 0xEC00, 0xEC05, 0xEC08, 0xECE9, 0xECF0, 0xECF0, | ||||
| 	0xEA80, 0xEA80, 0xEA82, 0xEAA3, 0xEAA5, 0xEAC2, 0xA800, 0xA8FF, | ||||
| 	0xAC60, 0xAC60, 0xB000, 0xB97F, 0xB9A0, 0xB9BF, | ||||
| 	~0 | ||||
| }; | ||||
| 
 | ||||
| static void a5xx_dump(struct msm_gpu *gpu) | ||||
| { | ||||
| 	dev_info(gpu->dev->dev, "status:   %08x\n", | ||||
| 		gpu_read(gpu, REG_A5XX_RBBM_STATUS)); | ||||
| 	adreno_dump(gpu); | ||||
| } | ||||
| 
 | ||||
| static int a5xx_pm_resume(struct msm_gpu *gpu) | ||||
| { | ||||
| 	return msm_gpu_pm_resume(gpu); | ||||
| } | ||||
| 
 | ||||
| static int a5xx_pm_suspend(struct msm_gpu *gpu) | ||||
| { | ||||
| 	return msm_gpu_pm_suspend(gpu); | ||||
| } | ||||
| 
 | ||||
| static int a5xx_get_timestamp(struct msm_gpu *gpu, uint64_t *value) | ||||
| { | ||||
| 	*value = gpu_read64(gpu, REG_A5XX_RBBM_PERFCTR_CP_0_LO, | ||||
| 		REG_A5XX_RBBM_PERFCTR_CP_0_HI); | ||||
| 
 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| #ifdef CONFIG_DEBUG_FS | ||||
| static void a5xx_show(struct msm_gpu *gpu, struct seq_file *m) | ||||
| { | ||||
| 	gpu->funcs->pm_resume(gpu); | ||||
| 
 | ||||
| 	seq_printf(m, "status:   %08x\n", | ||||
| 			gpu_read(gpu, REG_A5XX_RBBM_STATUS)); | ||||
| 	gpu->funcs->pm_suspend(gpu); | ||||
| 
 | ||||
| 	adreno_show(gpu, m); | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| static const struct adreno_gpu_funcs funcs = { | ||||
| 	.base = { | ||||
| 		.get_param = adreno_get_param, | ||||
| 		.hw_init = a5xx_hw_init, | ||||
| 		.pm_suspend = a5xx_pm_suspend, | ||||
| 		.pm_resume = a5xx_pm_resume, | ||||
| 		.recover = a5xx_recover, | ||||
| 		.last_fence = adreno_last_fence, | ||||
| 		.submit = a5xx_submit, | ||||
| 		.flush = adreno_flush, | ||||
| 		.idle = a5xx_idle, | ||||
| 		.irq = a5xx_irq, | ||||
| 		.destroy = a5xx_destroy, | ||||
| 		.show = a5xx_show, | ||||
| 	}, | ||||
| 	.get_timestamp = a5xx_get_timestamp, | ||||
| }; | ||||
| 
 | ||||
| struct msm_gpu *a5xx_gpu_init(struct drm_device *dev) | ||||
| { | ||||
| 	struct msm_drm_private *priv = dev->dev_private; | ||||
| 	struct platform_device *pdev = priv->gpu_pdev; | ||||
| 	struct a5xx_gpu *a5xx_gpu = NULL; | ||||
| 	struct adreno_gpu *adreno_gpu; | ||||
| 	struct msm_gpu *gpu; | ||||
| 	int ret; | ||||
| 
 | ||||
| 	if (!pdev) { | ||||
| 		dev_err(dev->dev, "No A5XX device is defined\n"); | ||||
| 		return ERR_PTR(-ENXIO); | ||||
| 	} | ||||
| 
 | ||||
| 	a5xx_gpu = kzalloc(sizeof(*a5xx_gpu), GFP_KERNEL); | ||||
| 	if (!a5xx_gpu) | ||||
| 		return ERR_PTR(-ENOMEM); | ||||
| 
 | ||||
| 	adreno_gpu = &a5xx_gpu->base; | ||||
| 	gpu = &adreno_gpu->base; | ||||
| 
 | ||||
| 	a5xx_gpu->pdev = pdev; | ||||
| 	adreno_gpu->registers = a5xx_registers; | ||||
| 	adreno_gpu->reg_offsets = a5xx_register_offsets; | ||||
| 
 | ||||
| 	ret = adreno_gpu_init(dev, pdev, adreno_gpu, &funcs); | ||||
| 	if (ret) { | ||||
| 		a5xx_destroy(&(a5xx_gpu->base.base)); | ||||
| 		return ERR_PTR(ret); | ||||
| 	} | ||||
| 
 | ||||
| 	return gpu; | ||||
| } | ||||
							
								
								
									
										37
									
								
								drivers/gpu/drm/msm/adreno/a5xx_gpu.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								drivers/gpu/drm/msm/adreno/a5xx_gpu.h
									
									
									
									
									
										Normal file
									
								
							| @ -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__ */ | ||||
| @ -74,6 +74,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, | ||||
| 	}, | ||||
| }; | ||||
| 
 | ||||
| @ -83,6 +91,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) | ||||
| { | ||||
| @ -170,12 +180,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) { | ||||
| @ -209,6 +227,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; | ||||
|  | ||||
| @ -22,7 +22,7 @@ | ||||
| #include "msm_mmu.h" | ||||
| 
 | ||||
| #define RB_SIZE    SZ_32K | ||||
| #define RB_BLKSIZE 16 | ||||
| #define RB_BLKSIZE 32 | ||||
| 
 | ||||
| int 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); | ||||
| @ -349,6 +346,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; | ||||
|  | ||||
| @ -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); | ||||
| @ -299,6 +315,7 @@ static inline void adreno_gpu_write(struct adreno_gpu *gpu, | ||||
| 
 | ||||
| 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 inline void adreno_gpu_write64(struct adreno_gpu *gpu, | ||||
| 		enum adreno_regs lo, enum adreno_regs hi, u64 data) | ||||
| @ -307,4 +324,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__ */ | ||||
|  | ||||
| @ -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; | ||||
| } | ||||
| 
 | ||||
| @ -553,8 +560,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, | ||||
| @ -647,7 +654,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); | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user