18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/* Copyright (c) 2018 The Linux Foundation. All rights reserved. */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include "a2xx_gpu.h"
58c2ecf20Sopenharmony_ci#include "msm_gem.h"
68c2ecf20Sopenharmony_ci#include "msm_mmu.h"
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciextern bool hang_debug;
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_cistatic void a2xx_dump(struct msm_gpu *gpu);
118c2ecf20Sopenharmony_cistatic bool a2xx_idle(struct msm_gpu *gpu);
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_cistatic void a2xx_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit)
148c2ecf20Sopenharmony_ci{
158c2ecf20Sopenharmony_ci	struct msm_drm_private *priv = gpu->dev->dev_private;
168c2ecf20Sopenharmony_ci	struct msm_ringbuffer *ring = submit->ring;
178c2ecf20Sopenharmony_ci	unsigned int i;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci	for (i = 0; i < submit->nr_cmds; i++) {
208c2ecf20Sopenharmony_ci		switch (submit->cmd[i].type) {
218c2ecf20Sopenharmony_ci		case MSM_SUBMIT_CMD_IB_TARGET_BUF:
228c2ecf20Sopenharmony_ci			/* ignore IB-targets */
238c2ecf20Sopenharmony_ci			break;
248c2ecf20Sopenharmony_ci		case MSM_SUBMIT_CMD_CTX_RESTORE_BUF:
258c2ecf20Sopenharmony_ci			/* ignore if there has not been a ctx switch: */
268c2ecf20Sopenharmony_ci			if (priv->lastctx == submit->queue->ctx)
278c2ecf20Sopenharmony_ci				break;
288c2ecf20Sopenharmony_ci			fallthrough;
298c2ecf20Sopenharmony_ci		case MSM_SUBMIT_CMD_BUF:
308c2ecf20Sopenharmony_ci			OUT_PKT3(ring, CP_INDIRECT_BUFFER_PFD, 2);
318c2ecf20Sopenharmony_ci			OUT_RING(ring, lower_32_bits(submit->cmd[i].iova));
328c2ecf20Sopenharmony_ci			OUT_RING(ring, submit->cmd[i].size);
338c2ecf20Sopenharmony_ci			OUT_PKT2(ring);
348c2ecf20Sopenharmony_ci			break;
358c2ecf20Sopenharmony_ci		}
368c2ecf20Sopenharmony_ci	}
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	OUT_PKT0(ring, REG_AXXX_CP_SCRATCH_REG2, 1);
398c2ecf20Sopenharmony_ci	OUT_RING(ring, submit->seqno);
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	/* wait for idle before cache flush/interrupt */
428c2ecf20Sopenharmony_ci	OUT_PKT3(ring, CP_WAIT_FOR_IDLE, 1);
438c2ecf20Sopenharmony_ci	OUT_RING(ring, 0x00000000);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	OUT_PKT3(ring, CP_EVENT_WRITE, 3);
468c2ecf20Sopenharmony_ci	OUT_RING(ring, CACHE_FLUSH_TS);
478c2ecf20Sopenharmony_ci	OUT_RING(ring, rbmemptr(ring, fence));
488c2ecf20Sopenharmony_ci	OUT_RING(ring, submit->seqno);
498c2ecf20Sopenharmony_ci	OUT_PKT3(ring, CP_INTERRUPT, 1);
508c2ecf20Sopenharmony_ci	OUT_RING(ring, 0x80000000);
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	adreno_flush(gpu, ring, REG_AXXX_CP_RB_WPTR);
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistatic bool a2xx_me_init(struct msm_gpu *gpu)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	struct msm_ringbuffer *ring = gpu->rb[0];
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	OUT_PKT3(ring, CP_ME_INIT, 18);
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	/* All fields present (bits 9:0) */
628c2ecf20Sopenharmony_ci	OUT_RING(ring, 0x000003ff);
638c2ecf20Sopenharmony_ci	/* Disable/Enable Real-Time Stream processing (present but ignored) */
648c2ecf20Sopenharmony_ci	OUT_RING(ring, 0x00000000);
658c2ecf20Sopenharmony_ci	/* Enable (2D <-> 3D) implicit synchronization (present but ignored) */
668c2ecf20Sopenharmony_ci	OUT_RING(ring, 0x00000000);
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	OUT_RING(ring, REG_A2XX_RB_SURFACE_INFO - 0x2000);
698c2ecf20Sopenharmony_ci	OUT_RING(ring, REG_A2XX_PA_SC_WINDOW_OFFSET - 0x2000);
708c2ecf20Sopenharmony_ci	OUT_RING(ring, REG_A2XX_VGT_MAX_VTX_INDX - 0x2000);
718c2ecf20Sopenharmony_ci	OUT_RING(ring, REG_A2XX_SQ_PROGRAM_CNTL - 0x2000);
728c2ecf20Sopenharmony_ci	OUT_RING(ring, REG_A2XX_RB_DEPTHCONTROL - 0x2000);
738c2ecf20Sopenharmony_ci	OUT_RING(ring, REG_A2XX_PA_SU_POINT_SIZE - 0x2000);
748c2ecf20Sopenharmony_ci	OUT_RING(ring, REG_A2XX_PA_SC_LINE_CNTL - 0x2000);
758c2ecf20Sopenharmony_ci	OUT_RING(ring, REG_A2XX_PA_SU_POLY_OFFSET_FRONT_SCALE - 0x2000);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	/* Vertex and Pixel Shader Start Addresses in instructions
788c2ecf20Sopenharmony_ci	 * (3 DWORDS per instruction) */
798c2ecf20Sopenharmony_ci	OUT_RING(ring, 0x80000180);
808c2ecf20Sopenharmony_ci	/* Maximum Contexts */
818c2ecf20Sopenharmony_ci	OUT_RING(ring, 0x00000001);
828c2ecf20Sopenharmony_ci	/* Write Confirm Interval and The CP will wait the
838c2ecf20Sopenharmony_ci	 * wait_interval * 16 clocks between polling  */
848c2ecf20Sopenharmony_ci	OUT_RING(ring, 0x00000000);
858c2ecf20Sopenharmony_ci	/* NQ and External Memory Swap */
868c2ecf20Sopenharmony_ci	OUT_RING(ring, 0x00000000);
878c2ecf20Sopenharmony_ci	/* protected mode error checking (0x1f2 is REG_AXXX_CP_INT_CNTL) */
888c2ecf20Sopenharmony_ci	OUT_RING(ring, 0x200001f2);
898c2ecf20Sopenharmony_ci	/* Disable header dumping and Header dump address */
908c2ecf20Sopenharmony_ci	OUT_RING(ring, 0x00000000);
918c2ecf20Sopenharmony_ci	/* Header dump size */
928c2ecf20Sopenharmony_ci	OUT_RING(ring, 0x00000000);
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	/* enable protected mode */
958c2ecf20Sopenharmony_ci	OUT_PKT3(ring, CP_SET_PROTECTED_MODE, 1);
968c2ecf20Sopenharmony_ci	OUT_RING(ring, 1);
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	adreno_flush(gpu, ring, REG_AXXX_CP_RB_WPTR);
998c2ecf20Sopenharmony_ci	return a2xx_idle(gpu);
1008c2ecf20Sopenharmony_ci}
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistatic int a2xx_hw_init(struct msm_gpu *gpu)
1038c2ecf20Sopenharmony_ci{
1048c2ecf20Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
1058c2ecf20Sopenharmony_ci	dma_addr_t pt_base, tran_error;
1068c2ecf20Sopenharmony_ci	uint32_t *ptr, len;
1078c2ecf20Sopenharmony_ci	int i, ret;
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci	msm_gpummu_params(gpu->aspace->mmu, &pt_base, &tran_error);
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	DBG("%s", gpu->name);
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	/* halt ME to avoid ucode upload issues on a20x */
1148c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_AXXX_CP_ME_CNTL, AXXX_CP_ME_CNTL_HALT);
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_RBBM_PM_OVERRIDE1, 0xfffffffe);
1178c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_RBBM_PM_OVERRIDE2, 0xffffffff);
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	/* note: kgsl uses 0x00000001 after first reset on a22x */
1208c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_RBBM_SOFT_RESET, 0xffffffff);
1218c2ecf20Sopenharmony_ci	msleep(30);
1228c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_RBBM_SOFT_RESET, 0x00000000);
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	if (adreno_is_a225(adreno_gpu))
1258c2ecf20Sopenharmony_ci		gpu_write(gpu, REG_A2XX_SQ_FLOW_CONTROL, 0x18000000);
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	/* note: kgsl uses 0x0000ffff for a20x */
1288c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_RBBM_CNTL, 0x00004442);
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci	/* MPU: physical range */
1318c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_MH_MMU_MPU_BASE, 0x00000000);
1328c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_MH_MMU_MPU_END, 0xfffff000);
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_MH_MMU_CONFIG, A2XX_MH_MMU_CONFIG_MMU_ENABLE |
1358c2ecf20Sopenharmony_ci		A2XX_MH_MMU_CONFIG_RB_W_CLNT_BEHAVIOR(BEH_TRAN_RNG) |
1368c2ecf20Sopenharmony_ci		A2XX_MH_MMU_CONFIG_CP_W_CLNT_BEHAVIOR(BEH_TRAN_RNG) |
1378c2ecf20Sopenharmony_ci		A2XX_MH_MMU_CONFIG_CP_R0_CLNT_BEHAVIOR(BEH_TRAN_RNG) |
1388c2ecf20Sopenharmony_ci		A2XX_MH_MMU_CONFIG_CP_R1_CLNT_BEHAVIOR(BEH_TRAN_RNG) |
1398c2ecf20Sopenharmony_ci		A2XX_MH_MMU_CONFIG_CP_R2_CLNT_BEHAVIOR(BEH_TRAN_RNG) |
1408c2ecf20Sopenharmony_ci		A2XX_MH_MMU_CONFIG_CP_R3_CLNT_BEHAVIOR(BEH_TRAN_RNG) |
1418c2ecf20Sopenharmony_ci		A2XX_MH_MMU_CONFIG_CP_R4_CLNT_BEHAVIOR(BEH_TRAN_RNG) |
1428c2ecf20Sopenharmony_ci		A2XX_MH_MMU_CONFIG_VGT_R0_CLNT_BEHAVIOR(BEH_TRAN_RNG) |
1438c2ecf20Sopenharmony_ci		A2XX_MH_MMU_CONFIG_VGT_R1_CLNT_BEHAVIOR(BEH_TRAN_RNG) |
1448c2ecf20Sopenharmony_ci		A2XX_MH_MMU_CONFIG_TC_R_CLNT_BEHAVIOR(BEH_TRAN_RNG) |
1458c2ecf20Sopenharmony_ci		A2XX_MH_MMU_CONFIG_PA_W_CLNT_BEHAVIOR(BEH_TRAN_RNG));
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	/* same as parameters in adreno_gpu */
1488c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_MH_MMU_VA_RANGE, SZ_16M |
1498c2ecf20Sopenharmony_ci		A2XX_MH_MMU_VA_RANGE_NUM_64KB_REGIONS(0xfff));
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_MH_MMU_PT_BASE, pt_base);
1528c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_MH_MMU_TRAN_ERROR, tran_error);
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_MH_MMU_INVALIDATE,
1558c2ecf20Sopenharmony_ci		A2XX_MH_MMU_INVALIDATE_INVALIDATE_ALL |
1568c2ecf20Sopenharmony_ci		A2XX_MH_MMU_INVALIDATE_INVALIDATE_TC);
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_MH_ARBITER_CONFIG,
1598c2ecf20Sopenharmony_ci		A2XX_MH_ARBITER_CONFIG_SAME_PAGE_LIMIT(16) |
1608c2ecf20Sopenharmony_ci		A2XX_MH_ARBITER_CONFIG_L1_ARB_ENABLE |
1618c2ecf20Sopenharmony_ci		A2XX_MH_ARBITER_CONFIG_L1_ARB_HOLD_ENABLE |
1628c2ecf20Sopenharmony_ci		A2XX_MH_ARBITER_CONFIG_PAGE_SIZE(1) |
1638c2ecf20Sopenharmony_ci		A2XX_MH_ARBITER_CONFIG_TC_REORDER_ENABLE |
1648c2ecf20Sopenharmony_ci		A2XX_MH_ARBITER_CONFIG_TC_ARB_HOLD_ENABLE |
1658c2ecf20Sopenharmony_ci		A2XX_MH_ARBITER_CONFIG_IN_FLIGHT_LIMIT_ENABLE |
1668c2ecf20Sopenharmony_ci		A2XX_MH_ARBITER_CONFIG_IN_FLIGHT_LIMIT(8) |
1678c2ecf20Sopenharmony_ci		A2XX_MH_ARBITER_CONFIG_CP_CLNT_ENABLE |
1688c2ecf20Sopenharmony_ci		A2XX_MH_ARBITER_CONFIG_VGT_CLNT_ENABLE |
1698c2ecf20Sopenharmony_ci		A2XX_MH_ARBITER_CONFIG_TC_CLNT_ENABLE |
1708c2ecf20Sopenharmony_ci		A2XX_MH_ARBITER_CONFIG_RB_CLNT_ENABLE |
1718c2ecf20Sopenharmony_ci		A2XX_MH_ARBITER_CONFIG_PA_CLNT_ENABLE);
1728c2ecf20Sopenharmony_ci	if (!adreno_is_a20x(adreno_gpu))
1738c2ecf20Sopenharmony_ci		gpu_write(gpu, REG_A2XX_MH_CLNT_INTF_CTRL_CONFIG1, 0x00032f07);
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_SQ_VS_PROGRAM, 0x00000000);
1768c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_SQ_PS_PROGRAM, 0x00000000);
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_RBBM_PM_OVERRIDE1, 0); /* 0x200 for msm8960? */
1798c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_RBBM_PM_OVERRIDE2, 0); /* 0x80/0x1a0 for a22x? */
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci	/* note: gsl doesn't set this */
1828c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_RBBM_DEBUG, 0x00080000);
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_RBBM_INT_CNTL,
1858c2ecf20Sopenharmony_ci		A2XX_RBBM_INT_CNTL_RDERR_INT_MASK);
1868c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_AXXX_CP_INT_CNTL,
1878c2ecf20Sopenharmony_ci		AXXX_CP_INT_CNTL_T0_PACKET_IN_IB_MASK |
1888c2ecf20Sopenharmony_ci		AXXX_CP_INT_CNTL_OPCODE_ERROR_MASK |
1898c2ecf20Sopenharmony_ci		AXXX_CP_INT_CNTL_PROTECTED_MODE_ERROR_MASK |
1908c2ecf20Sopenharmony_ci		AXXX_CP_INT_CNTL_RESERVED_BIT_ERROR_MASK |
1918c2ecf20Sopenharmony_ci		AXXX_CP_INT_CNTL_IB_ERROR_MASK |
1928c2ecf20Sopenharmony_ci		AXXX_CP_INT_CNTL_IB1_INT_MASK |
1938c2ecf20Sopenharmony_ci		AXXX_CP_INT_CNTL_RB_INT_MASK);
1948c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_SQ_INT_CNTL, 0);
1958c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_MH_INTERRUPT_MASK,
1968c2ecf20Sopenharmony_ci		A2XX_MH_INTERRUPT_MASK_AXI_READ_ERROR |
1978c2ecf20Sopenharmony_ci		A2XX_MH_INTERRUPT_MASK_AXI_WRITE_ERROR |
1988c2ecf20Sopenharmony_ci		A2XX_MH_INTERRUPT_MASK_MMU_PAGE_FAULT);
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	for (i = 3; i <= 5; i++)
2018c2ecf20Sopenharmony_ci		if ((SZ_16K << i) == adreno_gpu->gmem)
2028c2ecf20Sopenharmony_ci			break;
2038c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_RB_EDRAM_INFO, i);
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	ret = adreno_hw_init(gpu);
2068c2ecf20Sopenharmony_ci	if (ret)
2078c2ecf20Sopenharmony_ci		return ret;
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_AXXX_CP_RB_CNTL,
2108c2ecf20Sopenharmony_ci		MSM_GPU_RB_CNTL_DEFAULT | AXXX_CP_RB_CNTL_NO_UPDATE);
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_AXXX_CP_RB_BASE, lower_32_bits(gpu->rb[0]->iova));
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci	/* NOTE: PM4/micro-engine firmware registers look to be the same
2158c2ecf20Sopenharmony_ci	 * for a2xx and a3xx.. we could possibly push that part down to
2168c2ecf20Sopenharmony_ci	 * adreno_gpu base class.  Or push both PM4 and PFP but
2178c2ecf20Sopenharmony_ci	 * parameterize the pfp ucode addr/data registers..
2188c2ecf20Sopenharmony_ci	 */
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	/* Load PM4: */
2218c2ecf20Sopenharmony_ci	ptr = (uint32_t *)(adreno_gpu->fw[ADRENO_FW_PM4]->data);
2228c2ecf20Sopenharmony_ci	len = adreno_gpu->fw[ADRENO_FW_PM4]->size / 4;
2238c2ecf20Sopenharmony_ci	DBG("loading PM4 ucode version: %x", ptr[1]);
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_AXXX_CP_DEBUG,
2268c2ecf20Sopenharmony_ci			AXXX_CP_DEBUG_MIU_128BIT_WRITE_ENABLE);
2278c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_AXXX_CP_ME_RAM_WADDR, 0);
2288c2ecf20Sopenharmony_ci	for (i = 1; i < len; i++)
2298c2ecf20Sopenharmony_ci		gpu_write(gpu, REG_AXXX_CP_ME_RAM_DATA, ptr[i]);
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci	/* Load PFP: */
2328c2ecf20Sopenharmony_ci	ptr = (uint32_t *)(adreno_gpu->fw[ADRENO_FW_PFP]->data);
2338c2ecf20Sopenharmony_ci	len = adreno_gpu->fw[ADRENO_FW_PFP]->size / 4;
2348c2ecf20Sopenharmony_ci	DBG("loading PFP ucode version: %x", ptr[5]);
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_CP_PFP_UCODE_ADDR, 0);
2378c2ecf20Sopenharmony_ci	for (i = 1; i < len; i++)
2388c2ecf20Sopenharmony_ci		gpu_write(gpu, REG_A2XX_CP_PFP_UCODE_DATA, ptr[i]);
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_AXXX_CP_QUEUE_THRESHOLDS, 0x000C0804);
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci	/* clear ME_HALT to start micro engine */
2438c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_AXXX_CP_ME_CNTL, 0);
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci	return a2xx_me_init(gpu) ? 0 : -EINVAL;
2468c2ecf20Sopenharmony_ci}
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_cistatic void a2xx_recover(struct msm_gpu *gpu)
2498c2ecf20Sopenharmony_ci{
2508c2ecf20Sopenharmony_ci	int i;
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	adreno_dump_info(gpu);
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci	for (i = 0; i < 8; i++) {
2558c2ecf20Sopenharmony_ci		printk("CP_SCRATCH_REG%d: %u\n", i,
2568c2ecf20Sopenharmony_ci			gpu_read(gpu, REG_AXXX_CP_SCRATCH_REG0 + i));
2578c2ecf20Sopenharmony_ci	}
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci	/* dump registers before resetting gpu, if enabled: */
2608c2ecf20Sopenharmony_ci	if (hang_debug)
2618c2ecf20Sopenharmony_ci		a2xx_dump(gpu);
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_RBBM_SOFT_RESET, 1);
2648c2ecf20Sopenharmony_ci	gpu_read(gpu, REG_A2XX_RBBM_SOFT_RESET);
2658c2ecf20Sopenharmony_ci	gpu_write(gpu, REG_A2XX_RBBM_SOFT_RESET, 0);
2668c2ecf20Sopenharmony_ci	adreno_recover(gpu);
2678c2ecf20Sopenharmony_ci}
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_cistatic void a2xx_destroy(struct msm_gpu *gpu)
2708c2ecf20Sopenharmony_ci{
2718c2ecf20Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
2728c2ecf20Sopenharmony_ci	struct a2xx_gpu *a2xx_gpu = to_a2xx_gpu(adreno_gpu);
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	DBG("%s", gpu->name);
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	adreno_gpu_cleanup(adreno_gpu);
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	kfree(a2xx_gpu);
2798c2ecf20Sopenharmony_ci}
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_cistatic bool a2xx_idle(struct msm_gpu *gpu)
2828c2ecf20Sopenharmony_ci{
2838c2ecf20Sopenharmony_ci	/* wait for ringbuffer to drain: */
2848c2ecf20Sopenharmony_ci	if (!adreno_idle(gpu, gpu->rb[0]))
2858c2ecf20Sopenharmony_ci		return false;
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci	/* then wait for GPU to finish: */
2888c2ecf20Sopenharmony_ci	if (spin_until(!(gpu_read(gpu, REG_A2XX_RBBM_STATUS) &
2898c2ecf20Sopenharmony_ci			A2XX_RBBM_STATUS_GUI_ACTIVE))) {
2908c2ecf20Sopenharmony_ci		DRM_ERROR("%s: timeout waiting for GPU to idle!\n", gpu->name);
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci		/* TODO maybe we need to reset GPU here to recover from hang? */
2938c2ecf20Sopenharmony_ci		return false;
2948c2ecf20Sopenharmony_ci	}
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	return true;
2978c2ecf20Sopenharmony_ci}
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_cistatic irqreturn_t a2xx_irq(struct msm_gpu *gpu)
3008c2ecf20Sopenharmony_ci{
3018c2ecf20Sopenharmony_ci	uint32_t mstatus, status;
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci	mstatus = gpu_read(gpu, REG_A2XX_MASTER_INT_SIGNAL);
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	if (mstatus & A2XX_MASTER_INT_SIGNAL_MH_INT_STAT) {
3068c2ecf20Sopenharmony_ci		status = gpu_read(gpu, REG_A2XX_MH_INTERRUPT_STATUS);
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci		dev_warn(gpu->dev->dev, "MH_INT: %08X\n", status);
3098c2ecf20Sopenharmony_ci		dev_warn(gpu->dev->dev, "MMU_PAGE_FAULT: %08X\n",
3108c2ecf20Sopenharmony_ci			gpu_read(gpu, REG_A2XX_MH_MMU_PAGE_FAULT));
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci		gpu_write(gpu, REG_A2XX_MH_INTERRUPT_CLEAR, status);
3138c2ecf20Sopenharmony_ci	}
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	if (mstatus & A2XX_MASTER_INT_SIGNAL_CP_INT_STAT) {
3168c2ecf20Sopenharmony_ci		status = gpu_read(gpu, REG_AXXX_CP_INT_STATUS);
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ci		/* only RB_INT is expected */
3198c2ecf20Sopenharmony_ci		if (status & ~AXXX_CP_INT_CNTL_RB_INT_MASK)
3208c2ecf20Sopenharmony_ci			dev_warn(gpu->dev->dev, "CP_INT: %08X\n", status);
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci		gpu_write(gpu, REG_AXXX_CP_INT_ACK, status);
3238c2ecf20Sopenharmony_ci	}
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	if (mstatus & A2XX_MASTER_INT_SIGNAL_RBBM_INT_STAT) {
3268c2ecf20Sopenharmony_ci		status = gpu_read(gpu, REG_A2XX_RBBM_INT_STATUS);
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci		dev_warn(gpu->dev->dev, "RBBM_INT: %08X\n", status);
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci		gpu_write(gpu, REG_A2XX_RBBM_INT_ACK, status);
3318c2ecf20Sopenharmony_ci	}
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	msm_gpu_retire(gpu);
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	return IRQ_HANDLED;
3368c2ecf20Sopenharmony_ci}
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_cistatic const unsigned int a200_registers[] = {
3398c2ecf20Sopenharmony_ci	0x0000, 0x0002, 0x0004, 0x000B, 0x003B, 0x003D, 0x0040, 0x0044,
3408c2ecf20Sopenharmony_ci	0x0046, 0x0047, 0x01C0, 0x01C1, 0x01C3, 0x01C8, 0x01D5, 0x01D9,
3418c2ecf20Sopenharmony_ci	0x01DC, 0x01DD, 0x01EA, 0x01EA, 0x01EE, 0x01F3, 0x01F6, 0x01F7,
3428c2ecf20Sopenharmony_ci	0x01FC, 0x01FF, 0x0391, 0x0392, 0x039B, 0x039E, 0x03B2, 0x03B5,
3438c2ecf20Sopenharmony_ci	0x03B7, 0x03B7, 0x03F8, 0x03FB, 0x0440, 0x0440, 0x0443, 0x0444,
3448c2ecf20Sopenharmony_ci	0x044B, 0x044B, 0x044D, 0x044F, 0x0452, 0x0452, 0x0454, 0x045B,
3458c2ecf20Sopenharmony_ci	0x047F, 0x047F, 0x0578, 0x0587, 0x05C9, 0x05C9, 0x05D0, 0x05D0,
3468c2ecf20Sopenharmony_ci	0x0601, 0x0604, 0x0606, 0x0609, 0x060B, 0x060E, 0x0613, 0x0614,
3478c2ecf20Sopenharmony_ci	0x0A29, 0x0A2B, 0x0A2F, 0x0A31, 0x0A40, 0x0A43, 0x0A45, 0x0A45,
3488c2ecf20Sopenharmony_ci	0x0A4E, 0x0A4F, 0x0C2C, 0x0C2C, 0x0C30, 0x0C30, 0x0C38, 0x0C3C,
3498c2ecf20Sopenharmony_ci	0x0C40, 0x0C40, 0x0C44, 0x0C44, 0x0C80, 0x0C86, 0x0C88, 0x0C94,
3508c2ecf20Sopenharmony_ci	0x0C99, 0x0C9A, 0x0CA4, 0x0CA5, 0x0D00, 0x0D03, 0x0D06, 0x0D06,
3518c2ecf20Sopenharmony_ci	0x0D08, 0x0D0B, 0x0D34, 0x0D35, 0x0DAE, 0x0DC1, 0x0DC8, 0x0DD4,
3528c2ecf20Sopenharmony_ci	0x0DD8, 0x0DD9, 0x0E00, 0x0E00, 0x0E02, 0x0E04, 0x0E17, 0x0E1E,
3538c2ecf20Sopenharmony_ci	0x0EC0, 0x0EC9, 0x0ECB, 0x0ECC, 0x0ED0, 0x0ED0, 0x0ED4, 0x0ED7,
3548c2ecf20Sopenharmony_ci	0x0EE0, 0x0EE2, 0x0F01, 0x0F02, 0x0F0C, 0x0F0C, 0x0F0E, 0x0F12,
3558c2ecf20Sopenharmony_ci	0x0F26, 0x0F2A, 0x0F2C, 0x0F2C, 0x2000, 0x2002, 0x2006, 0x200F,
3568c2ecf20Sopenharmony_ci	0x2080, 0x2082, 0x2100, 0x2109, 0x210C, 0x2114, 0x2180, 0x2184,
3578c2ecf20Sopenharmony_ci	0x21F5, 0x21F7, 0x2200, 0x2208, 0x2280, 0x2283, 0x2293, 0x2294,
3588c2ecf20Sopenharmony_ci	0x2300, 0x2308, 0x2312, 0x2312, 0x2316, 0x231D, 0x2324, 0x2326,
3598c2ecf20Sopenharmony_ci	0x2380, 0x2383, 0x2400, 0x2402, 0x2406, 0x240F, 0x2480, 0x2482,
3608c2ecf20Sopenharmony_ci	0x2500, 0x2509, 0x250C, 0x2514, 0x2580, 0x2584, 0x25F5, 0x25F7,
3618c2ecf20Sopenharmony_ci	0x2600, 0x2608, 0x2680, 0x2683, 0x2693, 0x2694, 0x2700, 0x2708,
3628c2ecf20Sopenharmony_ci	0x2712, 0x2712, 0x2716, 0x271D, 0x2724, 0x2726, 0x2780, 0x2783,
3638c2ecf20Sopenharmony_ci	0x4000, 0x4003, 0x4800, 0x4805, 0x4900, 0x4900, 0x4908, 0x4908,
3648c2ecf20Sopenharmony_ci	~0   /* sentinel */
3658c2ecf20Sopenharmony_ci};
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_cistatic const unsigned int a220_registers[] = {
3688c2ecf20Sopenharmony_ci	0x0000, 0x0002, 0x0004, 0x000B, 0x003B, 0x003D, 0x0040, 0x0044,
3698c2ecf20Sopenharmony_ci	0x0046, 0x0047, 0x01C0, 0x01C1, 0x01C3, 0x01C8, 0x01D5, 0x01D9,
3708c2ecf20Sopenharmony_ci	0x01DC, 0x01DD, 0x01EA, 0x01EA, 0x01EE, 0x01F3, 0x01F6, 0x01F7,
3718c2ecf20Sopenharmony_ci	0x01FC, 0x01FF, 0x0391, 0x0392, 0x039B, 0x039E, 0x03B2, 0x03B5,
3728c2ecf20Sopenharmony_ci	0x03B7, 0x03B7, 0x03F8, 0x03FB, 0x0440, 0x0440, 0x0443, 0x0444,
3738c2ecf20Sopenharmony_ci	0x044B, 0x044B, 0x044D, 0x044F, 0x0452, 0x0452, 0x0454, 0x045B,
3748c2ecf20Sopenharmony_ci	0x047F, 0x047F, 0x0578, 0x0587, 0x05C9, 0x05C9, 0x05D0, 0x05D0,
3758c2ecf20Sopenharmony_ci	0x0601, 0x0604, 0x0606, 0x0609, 0x060B, 0x060E, 0x0613, 0x0614,
3768c2ecf20Sopenharmony_ci	0x0A29, 0x0A2B, 0x0A2F, 0x0A31, 0x0A40, 0x0A40, 0x0A42, 0x0A43,
3778c2ecf20Sopenharmony_ci	0x0A45, 0x0A45, 0x0A4E, 0x0A4F, 0x0C30, 0x0C30, 0x0C38, 0x0C39,
3788c2ecf20Sopenharmony_ci	0x0C3C, 0x0C3C, 0x0C80, 0x0C81, 0x0C88, 0x0C93, 0x0D00, 0x0D03,
3798c2ecf20Sopenharmony_ci	0x0D05, 0x0D06, 0x0D08, 0x0D0B, 0x0D34, 0x0D35, 0x0DAE, 0x0DC1,
3808c2ecf20Sopenharmony_ci	0x0DC8, 0x0DD4, 0x0DD8, 0x0DD9, 0x0E00, 0x0E00, 0x0E02, 0x0E04,
3818c2ecf20Sopenharmony_ci	0x0E17, 0x0E1E, 0x0EC0, 0x0EC9, 0x0ECB, 0x0ECC, 0x0ED0, 0x0ED0,
3828c2ecf20Sopenharmony_ci	0x0ED4, 0x0ED7, 0x0EE0, 0x0EE2, 0x0F01, 0x0F02, 0x2000, 0x2002,
3838c2ecf20Sopenharmony_ci	0x2006, 0x200F, 0x2080, 0x2082, 0x2100, 0x2102, 0x2104, 0x2109,
3848c2ecf20Sopenharmony_ci	0x210C, 0x2114, 0x2180, 0x2184, 0x21F5, 0x21F7, 0x2200, 0x2202,
3858c2ecf20Sopenharmony_ci	0x2204, 0x2204, 0x2208, 0x2208, 0x2280, 0x2282, 0x2294, 0x2294,
3868c2ecf20Sopenharmony_ci	0x2300, 0x2308, 0x2309, 0x230A, 0x2312, 0x2312, 0x2316, 0x2316,
3878c2ecf20Sopenharmony_ci	0x2318, 0x231D, 0x2324, 0x2326, 0x2380, 0x2383, 0x2400, 0x2402,
3888c2ecf20Sopenharmony_ci	0x2406, 0x240F, 0x2480, 0x2482, 0x2500, 0x2502, 0x2504, 0x2509,
3898c2ecf20Sopenharmony_ci	0x250C, 0x2514, 0x2580, 0x2584, 0x25F5, 0x25F7, 0x2600, 0x2602,
3908c2ecf20Sopenharmony_ci	0x2604, 0x2606, 0x2608, 0x2608, 0x2680, 0x2682, 0x2694, 0x2694,
3918c2ecf20Sopenharmony_ci	0x2700, 0x2708, 0x2712, 0x2712, 0x2716, 0x2716, 0x2718, 0x271D,
3928c2ecf20Sopenharmony_ci	0x2724, 0x2726, 0x2780, 0x2783, 0x4000, 0x4003, 0x4800, 0x4805,
3938c2ecf20Sopenharmony_ci	0x4900, 0x4900, 0x4908, 0x4908,
3948c2ecf20Sopenharmony_ci	~0   /* sentinel */
3958c2ecf20Sopenharmony_ci};
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_cistatic const unsigned int a225_registers[] = {
3988c2ecf20Sopenharmony_ci	0x0000, 0x0002, 0x0004, 0x000B, 0x003B, 0x003D, 0x0040, 0x0044,
3998c2ecf20Sopenharmony_ci	0x0046, 0x0047, 0x013C, 0x013C, 0x0140, 0x014F, 0x01C0, 0x01C1,
4008c2ecf20Sopenharmony_ci	0x01C3, 0x01C8, 0x01D5, 0x01D9, 0x01DC, 0x01DD, 0x01EA, 0x01EA,
4018c2ecf20Sopenharmony_ci	0x01EE, 0x01F3, 0x01F6, 0x01F7, 0x01FC, 0x01FF, 0x0391, 0x0392,
4028c2ecf20Sopenharmony_ci	0x039B, 0x039E, 0x03B2, 0x03B5, 0x03B7, 0x03B7, 0x03F8, 0x03FB,
4038c2ecf20Sopenharmony_ci	0x0440, 0x0440, 0x0443, 0x0444, 0x044B, 0x044B, 0x044D, 0x044F,
4048c2ecf20Sopenharmony_ci	0x0452, 0x0452, 0x0454, 0x045B, 0x047F, 0x047F, 0x0578, 0x0587,
4058c2ecf20Sopenharmony_ci	0x05C9, 0x05C9, 0x05D0, 0x05D0, 0x0601, 0x0604, 0x0606, 0x0609,
4068c2ecf20Sopenharmony_ci	0x060B, 0x060E, 0x0613, 0x0614, 0x0A29, 0x0A2B, 0x0A2F, 0x0A31,
4078c2ecf20Sopenharmony_ci	0x0A40, 0x0A40, 0x0A42, 0x0A43, 0x0A45, 0x0A45, 0x0A4E, 0x0A4F,
4088c2ecf20Sopenharmony_ci	0x0C01, 0x0C1D, 0x0C30, 0x0C30, 0x0C38, 0x0C39, 0x0C3C, 0x0C3C,
4098c2ecf20Sopenharmony_ci	0x0C80, 0x0C81, 0x0C88, 0x0C93, 0x0D00, 0x0D03, 0x0D05, 0x0D06,
4108c2ecf20Sopenharmony_ci	0x0D08, 0x0D0B, 0x0D34, 0x0D35, 0x0DAE, 0x0DC1, 0x0DC8, 0x0DD4,
4118c2ecf20Sopenharmony_ci	0x0DD8, 0x0DD9, 0x0E00, 0x0E00, 0x0E02, 0x0E04, 0x0E17, 0x0E1E,
4128c2ecf20Sopenharmony_ci	0x0EC0, 0x0EC9, 0x0ECB, 0x0ECC, 0x0ED0, 0x0ED0, 0x0ED4, 0x0ED7,
4138c2ecf20Sopenharmony_ci	0x0EE0, 0x0EE2, 0x0F01, 0x0F02, 0x2000, 0x200F, 0x2080, 0x2082,
4148c2ecf20Sopenharmony_ci	0x2100, 0x2109, 0x210C, 0x2114, 0x2180, 0x2184, 0x21F5, 0x21F7,
4158c2ecf20Sopenharmony_ci	0x2200, 0x2202, 0x2204, 0x2206, 0x2208, 0x2210, 0x2220, 0x2222,
4168c2ecf20Sopenharmony_ci	0x2280, 0x2282, 0x2294, 0x2294, 0x2297, 0x2297, 0x2300, 0x230A,
4178c2ecf20Sopenharmony_ci	0x2312, 0x2312, 0x2315, 0x2316, 0x2318, 0x231D, 0x2324, 0x2326,
4188c2ecf20Sopenharmony_ci	0x2340, 0x2357, 0x2360, 0x2360, 0x2380, 0x2383, 0x2400, 0x240F,
4198c2ecf20Sopenharmony_ci	0x2480, 0x2482, 0x2500, 0x2509, 0x250C, 0x2514, 0x2580, 0x2584,
4208c2ecf20Sopenharmony_ci	0x25F5, 0x25F7, 0x2600, 0x2602, 0x2604, 0x2606, 0x2608, 0x2610,
4218c2ecf20Sopenharmony_ci	0x2620, 0x2622, 0x2680, 0x2682, 0x2694, 0x2694, 0x2697, 0x2697,
4228c2ecf20Sopenharmony_ci	0x2700, 0x270A, 0x2712, 0x2712, 0x2715, 0x2716, 0x2718, 0x271D,
4238c2ecf20Sopenharmony_ci	0x2724, 0x2726, 0x2740, 0x2757, 0x2760, 0x2760, 0x2780, 0x2783,
4248c2ecf20Sopenharmony_ci	0x4000, 0x4003, 0x4800, 0x4806, 0x4808, 0x4808, 0x4900, 0x4900,
4258c2ecf20Sopenharmony_ci	0x4908, 0x4908,
4268c2ecf20Sopenharmony_ci	~0   /* sentinel */
4278c2ecf20Sopenharmony_ci};
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci/* would be nice to not have to duplicate the _show() stuff with printk(): */
4308c2ecf20Sopenharmony_cistatic void a2xx_dump(struct msm_gpu *gpu)
4318c2ecf20Sopenharmony_ci{
4328c2ecf20Sopenharmony_ci	printk("status:   %08x\n",
4338c2ecf20Sopenharmony_ci			gpu_read(gpu, REG_A2XX_RBBM_STATUS));
4348c2ecf20Sopenharmony_ci	adreno_dump(gpu);
4358c2ecf20Sopenharmony_ci}
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_cistatic struct msm_gpu_state *a2xx_gpu_state_get(struct msm_gpu *gpu)
4388c2ecf20Sopenharmony_ci{
4398c2ecf20Sopenharmony_ci	struct msm_gpu_state *state = kzalloc(sizeof(*state), GFP_KERNEL);
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ci	if (!state)
4428c2ecf20Sopenharmony_ci		return ERR_PTR(-ENOMEM);
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci	adreno_gpu_state_get(gpu, state);
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci	state->rbbm_status = gpu_read(gpu, REG_A2XX_RBBM_STATUS);
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci	return state;
4498c2ecf20Sopenharmony_ci}
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_cistatic struct msm_gem_address_space *
4528c2ecf20Sopenharmony_cia2xx_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev)
4538c2ecf20Sopenharmony_ci{
4548c2ecf20Sopenharmony_ci	struct msm_mmu *mmu = msm_gpummu_new(&pdev->dev, gpu);
4558c2ecf20Sopenharmony_ci	struct msm_gem_address_space *aspace;
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci	aspace = msm_gem_address_space_create(mmu, "gpu", SZ_16M,
4588c2ecf20Sopenharmony_ci		0xfff * SZ_64K);
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci	if (IS_ERR(aspace) && !IS_ERR(mmu))
4618c2ecf20Sopenharmony_ci		mmu->funcs->destroy(mmu);
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci	return aspace;
4648c2ecf20Sopenharmony_ci}
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_cistatic u32 a2xx_get_rptr(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
4678c2ecf20Sopenharmony_ci{
4688c2ecf20Sopenharmony_ci	ring->memptrs->rptr = gpu_read(gpu, REG_AXXX_CP_RB_RPTR);
4698c2ecf20Sopenharmony_ci	return ring->memptrs->rptr;
4708c2ecf20Sopenharmony_ci}
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_cistatic const struct adreno_gpu_funcs funcs = {
4738c2ecf20Sopenharmony_ci	.base = {
4748c2ecf20Sopenharmony_ci		.get_param = adreno_get_param,
4758c2ecf20Sopenharmony_ci		.hw_init = a2xx_hw_init,
4768c2ecf20Sopenharmony_ci		.pm_suspend = msm_gpu_pm_suspend,
4778c2ecf20Sopenharmony_ci		.pm_resume = msm_gpu_pm_resume,
4788c2ecf20Sopenharmony_ci		.recover = a2xx_recover,
4798c2ecf20Sopenharmony_ci		.submit = a2xx_submit,
4808c2ecf20Sopenharmony_ci		.active_ring = adreno_active_ring,
4818c2ecf20Sopenharmony_ci		.irq = a2xx_irq,
4828c2ecf20Sopenharmony_ci		.destroy = a2xx_destroy,
4838c2ecf20Sopenharmony_ci#if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
4848c2ecf20Sopenharmony_ci		.show = adreno_show,
4858c2ecf20Sopenharmony_ci#endif
4868c2ecf20Sopenharmony_ci		.gpu_state_get = a2xx_gpu_state_get,
4878c2ecf20Sopenharmony_ci		.gpu_state_put = adreno_gpu_state_put,
4888c2ecf20Sopenharmony_ci		.create_address_space = a2xx_create_address_space,
4898c2ecf20Sopenharmony_ci		.get_rptr = a2xx_get_rptr,
4908c2ecf20Sopenharmony_ci	},
4918c2ecf20Sopenharmony_ci};
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_cistatic const struct msm_gpu_perfcntr perfcntrs[] = {
4948c2ecf20Sopenharmony_ci/* TODO */
4958c2ecf20Sopenharmony_ci};
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_cistruct msm_gpu *a2xx_gpu_init(struct drm_device *dev)
4988c2ecf20Sopenharmony_ci{
4998c2ecf20Sopenharmony_ci	struct a2xx_gpu *a2xx_gpu = NULL;
5008c2ecf20Sopenharmony_ci	struct adreno_gpu *adreno_gpu;
5018c2ecf20Sopenharmony_ci	struct msm_gpu *gpu;
5028c2ecf20Sopenharmony_ci	struct msm_drm_private *priv = dev->dev_private;
5038c2ecf20Sopenharmony_ci	struct platform_device *pdev = priv->gpu_pdev;
5048c2ecf20Sopenharmony_ci	int ret;
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ci	if (!pdev) {
5078c2ecf20Sopenharmony_ci		dev_err(dev->dev, "no a2xx device\n");
5088c2ecf20Sopenharmony_ci		ret = -ENXIO;
5098c2ecf20Sopenharmony_ci		goto fail;
5108c2ecf20Sopenharmony_ci	}
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci	a2xx_gpu = kzalloc(sizeof(*a2xx_gpu), GFP_KERNEL);
5138c2ecf20Sopenharmony_ci	if (!a2xx_gpu) {
5148c2ecf20Sopenharmony_ci		ret = -ENOMEM;
5158c2ecf20Sopenharmony_ci		goto fail;
5168c2ecf20Sopenharmony_ci	}
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci	adreno_gpu = &a2xx_gpu->base;
5198c2ecf20Sopenharmony_ci	gpu = &adreno_gpu->base;
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci	gpu->perfcntrs = perfcntrs;
5228c2ecf20Sopenharmony_ci	gpu->num_perfcntrs = ARRAY_SIZE(perfcntrs);
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci	ret = adreno_gpu_init(dev, pdev, adreno_gpu, &funcs, 1);
5258c2ecf20Sopenharmony_ci	if (ret)
5268c2ecf20Sopenharmony_ci		goto fail;
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ci	if (adreno_is_a20x(adreno_gpu))
5298c2ecf20Sopenharmony_ci		adreno_gpu->registers = a200_registers;
5308c2ecf20Sopenharmony_ci	else if (adreno_is_a225(adreno_gpu))
5318c2ecf20Sopenharmony_ci		adreno_gpu->registers = a225_registers;
5328c2ecf20Sopenharmony_ci	else
5338c2ecf20Sopenharmony_ci		adreno_gpu->registers = a220_registers;
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ci	if (!gpu->aspace) {
5368c2ecf20Sopenharmony_ci		dev_err(dev->dev, "No memory protection without MMU\n");
5378c2ecf20Sopenharmony_ci		ret = -ENXIO;
5388c2ecf20Sopenharmony_ci		goto fail;
5398c2ecf20Sopenharmony_ci	}
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci	return gpu;
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_cifail:
5448c2ecf20Sopenharmony_ci	if (a2xx_gpu)
5458c2ecf20Sopenharmony_ci		a2xx_destroy(&a2xx_gpu->base.base);
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci	return ERR_PTR(ret);
5488c2ecf20Sopenharmony_ci}
549