162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/* Copyright (c) 2017-2019 The Linux Foundation. All rights reserved. */
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include "msm_gem.h"
662306a36Sopenharmony_ci#include "msm_mmu.h"
762306a36Sopenharmony_ci#include "msm_gpu_trace.h"
862306a36Sopenharmony_ci#include "a6xx_gpu.h"
962306a36Sopenharmony_ci#include "a6xx_gmu.xml.h"
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <linux/bitfield.h>
1262306a36Sopenharmony_ci#include <linux/devfreq.h>
1362306a36Sopenharmony_ci#include <linux/pm_domain.h>
1462306a36Sopenharmony_ci#include <linux/soc/qcom/llcc-qcom.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define GPU_PAS_ID 13
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistatic inline bool _a6xx_check_idle(struct msm_gpu *gpu)
1962306a36Sopenharmony_ci{
2062306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
2162306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci	/* Check that the GMU is idle */
2462306a36Sopenharmony_ci	if (!adreno_has_gmu_wrapper(adreno_gpu) && !a6xx_gmu_isidle(&a6xx_gpu->gmu))
2562306a36Sopenharmony_ci		return false;
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci	/* Check tha the CX master is idle */
2862306a36Sopenharmony_ci	if (gpu_read(gpu, REG_A6XX_RBBM_STATUS) &
2962306a36Sopenharmony_ci			~A6XX_RBBM_STATUS_CP_AHB_BUSY_CX_MASTER)
3062306a36Sopenharmony_ci		return false;
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci	return !(gpu_read(gpu, REG_A6XX_RBBM_INT_0_STATUS) &
3362306a36Sopenharmony_ci		A6XX_RBBM_INT_0_MASK_RBBM_HANG_DETECT);
3462306a36Sopenharmony_ci}
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_cistatic bool a6xx_idle(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
3762306a36Sopenharmony_ci{
3862306a36Sopenharmony_ci	/* wait for CP to drain ringbuffer: */
3962306a36Sopenharmony_ci	if (!adreno_idle(gpu, ring))
4062306a36Sopenharmony_ci		return false;
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci	if (spin_until(_a6xx_check_idle(gpu))) {
4362306a36Sopenharmony_ci		DRM_ERROR("%s: %ps: timeout waiting for GPU to idle: status %8.8X irq %8.8X rptr/wptr %d/%d\n",
4462306a36Sopenharmony_ci			gpu->name, __builtin_return_address(0),
4562306a36Sopenharmony_ci			gpu_read(gpu, REG_A6XX_RBBM_STATUS),
4662306a36Sopenharmony_ci			gpu_read(gpu, REG_A6XX_RBBM_INT_0_STATUS),
4762306a36Sopenharmony_ci			gpu_read(gpu, REG_A6XX_CP_RB_RPTR),
4862306a36Sopenharmony_ci			gpu_read(gpu, REG_A6XX_CP_RB_WPTR));
4962306a36Sopenharmony_ci		return false;
5062306a36Sopenharmony_ci	}
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci	return true;
5362306a36Sopenharmony_ci}
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_cistatic void update_shadow_rptr(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
5662306a36Sopenharmony_ci{
5762306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
5862306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci	/* Expanded APRIV doesn't need to issue the WHERE_AM_I opcode */
6162306a36Sopenharmony_ci	if (a6xx_gpu->has_whereami && !adreno_gpu->base.hw_apriv) {
6262306a36Sopenharmony_ci		OUT_PKT7(ring, CP_WHERE_AM_I, 2);
6362306a36Sopenharmony_ci		OUT_RING(ring, lower_32_bits(shadowptr(a6xx_gpu, ring)));
6462306a36Sopenharmony_ci		OUT_RING(ring, upper_32_bits(shadowptr(a6xx_gpu, ring)));
6562306a36Sopenharmony_ci	}
6662306a36Sopenharmony_ci}
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_cistatic void a6xx_flush(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
6962306a36Sopenharmony_ci{
7062306a36Sopenharmony_ci	uint32_t wptr;
7162306a36Sopenharmony_ci	unsigned long flags;
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci	update_shadow_rptr(gpu, ring);
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci	spin_lock_irqsave(&ring->preempt_lock, flags);
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci	/* Copy the shadow to the actual register */
7862306a36Sopenharmony_ci	ring->cur = ring->next;
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci	/* Make sure to wrap wptr if we need to */
8162306a36Sopenharmony_ci	wptr = get_wptr(ring);
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci	spin_unlock_irqrestore(&ring->preempt_lock, flags);
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci	/* Make sure everything is posted before making a decision */
8662306a36Sopenharmony_ci	mb();
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_CP_RB_WPTR, wptr);
8962306a36Sopenharmony_ci}
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_cistatic void get_stats_counter(struct msm_ringbuffer *ring, u32 counter,
9262306a36Sopenharmony_ci		u64 iova)
9362306a36Sopenharmony_ci{
9462306a36Sopenharmony_ci	OUT_PKT7(ring, CP_REG_TO_MEM, 3);
9562306a36Sopenharmony_ci	OUT_RING(ring, CP_REG_TO_MEM_0_REG(counter) |
9662306a36Sopenharmony_ci		CP_REG_TO_MEM_0_CNT(2) |
9762306a36Sopenharmony_ci		CP_REG_TO_MEM_0_64B);
9862306a36Sopenharmony_ci	OUT_RING(ring, lower_32_bits(iova));
9962306a36Sopenharmony_ci	OUT_RING(ring, upper_32_bits(iova));
10062306a36Sopenharmony_ci}
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_cistatic void a6xx_set_pagetable(struct a6xx_gpu *a6xx_gpu,
10362306a36Sopenharmony_ci		struct msm_ringbuffer *ring, struct msm_file_private *ctx)
10462306a36Sopenharmony_ci{
10562306a36Sopenharmony_ci	bool sysprof = refcount_read(&a6xx_gpu->base.base.sysprof_active) > 1;
10662306a36Sopenharmony_ci	phys_addr_t ttbr;
10762306a36Sopenharmony_ci	u32 asid;
10862306a36Sopenharmony_ci	u64 memptr = rbmemptr(ring, ttbr0);
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci	if (ctx->seqno == a6xx_gpu->base.base.cur_ctx_seqno)
11162306a36Sopenharmony_ci		return;
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci	if (msm_iommu_pagetable_params(ctx->aspace->mmu, &ttbr, &asid))
11462306a36Sopenharmony_ci		return;
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci	if (!sysprof) {
11762306a36Sopenharmony_ci		/* Turn off protected mode to write to special registers */
11862306a36Sopenharmony_ci		OUT_PKT7(ring, CP_SET_PROTECTED_MODE, 1);
11962306a36Sopenharmony_ci		OUT_RING(ring, 0);
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci		OUT_PKT4(ring, REG_A6XX_RBBM_PERFCTR_SRAM_INIT_CMD, 1);
12262306a36Sopenharmony_ci		OUT_RING(ring, 1);
12362306a36Sopenharmony_ci	}
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci	/* Execute the table update */
12662306a36Sopenharmony_ci	OUT_PKT7(ring, CP_SMMU_TABLE_UPDATE, 4);
12762306a36Sopenharmony_ci	OUT_RING(ring, CP_SMMU_TABLE_UPDATE_0_TTBR0_LO(lower_32_bits(ttbr)));
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci	OUT_RING(ring,
13062306a36Sopenharmony_ci		CP_SMMU_TABLE_UPDATE_1_TTBR0_HI(upper_32_bits(ttbr)) |
13162306a36Sopenharmony_ci		CP_SMMU_TABLE_UPDATE_1_ASID(asid));
13262306a36Sopenharmony_ci	OUT_RING(ring, CP_SMMU_TABLE_UPDATE_2_CONTEXTIDR(0));
13362306a36Sopenharmony_ci	OUT_RING(ring, CP_SMMU_TABLE_UPDATE_3_CONTEXTBANK(0));
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci	/*
13662306a36Sopenharmony_ci	 * Write the new TTBR0 to the memstore. This is good for debugging.
13762306a36Sopenharmony_ci	 */
13862306a36Sopenharmony_ci	OUT_PKT7(ring, CP_MEM_WRITE, 4);
13962306a36Sopenharmony_ci	OUT_RING(ring, CP_MEM_WRITE_0_ADDR_LO(lower_32_bits(memptr)));
14062306a36Sopenharmony_ci	OUT_RING(ring, CP_MEM_WRITE_1_ADDR_HI(upper_32_bits(memptr)));
14162306a36Sopenharmony_ci	OUT_RING(ring, lower_32_bits(ttbr));
14262306a36Sopenharmony_ci	OUT_RING(ring, (asid << 16) | upper_32_bits(ttbr));
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci	/*
14562306a36Sopenharmony_ci	 * And finally, trigger a uche flush to be sure there isn't anything
14662306a36Sopenharmony_ci	 * lingering in that part of the GPU
14762306a36Sopenharmony_ci	 */
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci	OUT_PKT7(ring, CP_EVENT_WRITE, 1);
15062306a36Sopenharmony_ci	OUT_RING(ring, CACHE_INVALIDATE);
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci	if (!sysprof) {
15362306a36Sopenharmony_ci		/*
15462306a36Sopenharmony_ci		 * Wait for SRAM clear after the pgtable update, so the
15562306a36Sopenharmony_ci		 * two can happen in parallel:
15662306a36Sopenharmony_ci		 */
15762306a36Sopenharmony_ci		OUT_PKT7(ring, CP_WAIT_REG_MEM, 6);
15862306a36Sopenharmony_ci		OUT_RING(ring, CP_WAIT_REG_MEM_0_FUNCTION(WRITE_EQ));
15962306a36Sopenharmony_ci		OUT_RING(ring, CP_WAIT_REG_MEM_1_POLL_ADDR_LO(
16062306a36Sopenharmony_ci				REG_A6XX_RBBM_PERFCTR_SRAM_INIT_STATUS));
16162306a36Sopenharmony_ci		OUT_RING(ring, CP_WAIT_REG_MEM_2_POLL_ADDR_HI(0));
16262306a36Sopenharmony_ci		OUT_RING(ring, CP_WAIT_REG_MEM_3_REF(0x1));
16362306a36Sopenharmony_ci		OUT_RING(ring, CP_WAIT_REG_MEM_4_MASK(0x1));
16462306a36Sopenharmony_ci		OUT_RING(ring, CP_WAIT_REG_MEM_5_DELAY_LOOP_CYCLES(0));
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci		/* Re-enable protected mode: */
16762306a36Sopenharmony_ci		OUT_PKT7(ring, CP_SET_PROTECTED_MODE, 1);
16862306a36Sopenharmony_ci		OUT_RING(ring, 1);
16962306a36Sopenharmony_ci	}
17062306a36Sopenharmony_ci}
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_cistatic void a6xx_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit)
17362306a36Sopenharmony_ci{
17462306a36Sopenharmony_ci	unsigned int index = submit->seqno % MSM_GPU_SUBMIT_STATS_COUNT;
17562306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
17662306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
17762306a36Sopenharmony_ci	struct msm_ringbuffer *ring = submit->ring;
17862306a36Sopenharmony_ci	unsigned int i, ibs = 0;
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_ci	a6xx_set_pagetable(a6xx_gpu, ring, submit->queue->ctx);
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ci	get_stats_counter(ring, REG_A6XX_RBBM_PERFCTR_CP(0),
18362306a36Sopenharmony_ci		rbmemptr_stats(ring, index, cpcycles_start));
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci	/*
18662306a36Sopenharmony_ci	 * For PM4 the GMU register offsets are calculated from the base of the
18762306a36Sopenharmony_ci	 * GPU registers so we need to add 0x1a800 to the register value on A630
18862306a36Sopenharmony_ci	 * to get the right value from PM4.
18962306a36Sopenharmony_ci	 */
19062306a36Sopenharmony_ci	get_stats_counter(ring, REG_A6XX_CP_ALWAYS_ON_COUNTER,
19162306a36Sopenharmony_ci		rbmemptr_stats(ring, index, alwayson_start));
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci	/* Invalidate CCU depth and color */
19462306a36Sopenharmony_ci	OUT_PKT7(ring, CP_EVENT_WRITE, 1);
19562306a36Sopenharmony_ci	OUT_RING(ring, CP_EVENT_WRITE_0_EVENT(PC_CCU_INVALIDATE_DEPTH));
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci	OUT_PKT7(ring, CP_EVENT_WRITE, 1);
19862306a36Sopenharmony_ci	OUT_RING(ring, CP_EVENT_WRITE_0_EVENT(PC_CCU_INVALIDATE_COLOR));
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ci	/* Submit the commands */
20162306a36Sopenharmony_ci	for (i = 0; i < submit->nr_cmds; i++) {
20262306a36Sopenharmony_ci		switch (submit->cmd[i].type) {
20362306a36Sopenharmony_ci		case MSM_SUBMIT_CMD_IB_TARGET_BUF:
20462306a36Sopenharmony_ci			break;
20562306a36Sopenharmony_ci		case MSM_SUBMIT_CMD_CTX_RESTORE_BUF:
20662306a36Sopenharmony_ci			if (gpu->cur_ctx_seqno == submit->queue->ctx->seqno)
20762306a36Sopenharmony_ci				break;
20862306a36Sopenharmony_ci			fallthrough;
20962306a36Sopenharmony_ci		case MSM_SUBMIT_CMD_BUF:
21062306a36Sopenharmony_ci			OUT_PKT7(ring, CP_INDIRECT_BUFFER_PFE, 3);
21162306a36Sopenharmony_ci			OUT_RING(ring, lower_32_bits(submit->cmd[i].iova));
21262306a36Sopenharmony_ci			OUT_RING(ring, upper_32_bits(submit->cmd[i].iova));
21362306a36Sopenharmony_ci			OUT_RING(ring, submit->cmd[i].size);
21462306a36Sopenharmony_ci			ibs++;
21562306a36Sopenharmony_ci			break;
21662306a36Sopenharmony_ci		}
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ci		/*
21962306a36Sopenharmony_ci		 * Periodically update shadow-wptr if needed, so that we
22062306a36Sopenharmony_ci		 * can see partial progress of submits with large # of
22162306a36Sopenharmony_ci		 * cmds.. otherwise we could needlessly stall waiting for
22262306a36Sopenharmony_ci		 * ringbuffer state, simply due to looking at a shadow
22362306a36Sopenharmony_ci		 * rptr value that has not been updated
22462306a36Sopenharmony_ci		 */
22562306a36Sopenharmony_ci		if ((ibs % 32) == 0)
22662306a36Sopenharmony_ci			update_shadow_rptr(gpu, ring);
22762306a36Sopenharmony_ci	}
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci	get_stats_counter(ring, REG_A6XX_RBBM_PERFCTR_CP(0),
23062306a36Sopenharmony_ci		rbmemptr_stats(ring, index, cpcycles_end));
23162306a36Sopenharmony_ci	get_stats_counter(ring, REG_A6XX_CP_ALWAYS_ON_COUNTER,
23262306a36Sopenharmony_ci		rbmemptr_stats(ring, index, alwayson_end));
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ci	/* Write the fence to the scratch register */
23562306a36Sopenharmony_ci	OUT_PKT4(ring, REG_A6XX_CP_SCRATCH_REG(2), 1);
23662306a36Sopenharmony_ci	OUT_RING(ring, submit->seqno);
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci	/*
23962306a36Sopenharmony_ci	 * Execute a CACHE_FLUSH_TS event. This will ensure that the
24062306a36Sopenharmony_ci	 * timestamp is written to the memory and then triggers the interrupt
24162306a36Sopenharmony_ci	 */
24262306a36Sopenharmony_ci	OUT_PKT7(ring, CP_EVENT_WRITE, 4);
24362306a36Sopenharmony_ci	OUT_RING(ring, CP_EVENT_WRITE_0_EVENT(CACHE_FLUSH_TS) |
24462306a36Sopenharmony_ci		CP_EVENT_WRITE_0_IRQ);
24562306a36Sopenharmony_ci	OUT_RING(ring, lower_32_bits(rbmemptr(ring, fence)));
24662306a36Sopenharmony_ci	OUT_RING(ring, upper_32_bits(rbmemptr(ring, fence)));
24762306a36Sopenharmony_ci	OUT_RING(ring, submit->seqno);
24862306a36Sopenharmony_ci
24962306a36Sopenharmony_ci	trace_msm_gpu_submit_flush(submit,
25062306a36Sopenharmony_ci		gpu_read64(gpu, REG_A6XX_CP_ALWAYS_ON_COUNTER));
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci	a6xx_flush(gpu, ring);
25362306a36Sopenharmony_ci}
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ciconst struct adreno_reglist a612_hwcg[] = {
25662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_SP0, 0x22222222},
25762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_SP0, 0x02222220},
25862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_SP0, 0x00000081},
25962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_SP0, 0x0000f3cf},
26062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TP0, 0x22222222},
26162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_TP0, 0x22222222},
26262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL3_TP0, 0x22222222},
26362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL4_TP0, 0x00022222},
26462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TP0, 0x11111111},
26562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY2_TP0, 0x11111111},
26662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY3_TP0, 0x11111111},
26762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY4_TP0, 0x00011111},
26862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TP0, 0x77777777},
26962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST2_TP0, 0x77777777},
27062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST3_TP0, 0x77777777},
27162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST4_TP0, 0x00077777},
27262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RB0, 0x22222222},
27362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RB0, 0x01202222},
27462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_CCU0, 0x00002220},
27562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RB_CCU0, 0x00040f00},
27662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RAC, 0x05522022},
27762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RAC, 0x00005555},
27862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_RAC, 0x00000011},
27962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RAC, 0x00445044},
28062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TSE_RAS_RBBM, 0x04222222},
28162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_VFD, 0x00002222},
28262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_GPC, 0x02222222},
28362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ_2, 0x00000002},
28462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_HLSQ, 0x00002222},
28562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000},
28662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_VFD, 0x00002222},
28762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GPC, 0x00000200},
28862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000},
28962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TSE_RAS_RBBM, 0x00000000},
29062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_VFD, 0x00000000},
29162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GPC, 0x04104004},
29262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_HLSQ, 0x00000000},
29362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_UCHE, 0x22222222},
29462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_UCHE, 0x00000004},
29562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_UCHE, 0x00000002},
29662306a36Sopenharmony_ci	{REG_A6XX_RBBM_ISDB_CNT, 0x00000182},
29762306a36Sopenharmony_ci	{REG_A6XX_RBBM_RAC_THRESHOLD_CNT, 0x00000000},
29862306a36Sopenharmony_ci	{REG_A6XX_RBBM_SP_HYST_CNT, 0x00000000},
29962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_GMU_GX, 0x00000222},
30062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GMU_GX, 0x00000111},
30162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555},
30262306a36Sopenharmony_ci	{},
30362306a36Sopenharmony_ci};
30462306a36Sopenharmony_ci
30562306a36Sopenharmony_ci/* For a615 family (a615, a616, a618 and a619) */
30662306a36Sopenharmony_ciconst struct adreno_reglist a615_hwcg[] = {
30762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_SP0,  0x02222222},
30862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_SP0, 0x02222220},
30962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_SP0, 0x00000080},
31062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_SP0,  0x0000F3CF},
31162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TP0,  0x02222222},
31262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TP1,  0x02222222},
31362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_TP0, 0x22222222},
31462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_TP1, 0x22222222},
31562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL3_TP0, 0x22222222},
31662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL3_TP1, 0x22222222},
31762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL4_TP0, 0x00022222},
31862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL4_TP1, 0x00022222},
31962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TP0,  0x77777777},
32062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TP1,  0x77777777},
32162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST2_TP0, 0x77777777},
32262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST2_TP1, 0x77777777},
32362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST3_TP0, 0x77777777},
32462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST3_TP1, 0x77777777},
32562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST4_TP0, 0x00077777},
32662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST4_TP1, 0x00077777},
32762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TP0, 0x11111111},
32862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TP1, 0x11111111},
32962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY2_TP0, 0x11111111},
33062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY2_TP1, 0x11111111},
33162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY3_TP0, 0x11111111},
33262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY3_TP1, 0x11111111},
33362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY4_TP0, 0x00011111},
33462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY4_TP1, 0x00011111},
33562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_UCHE,  0x22222222},
33662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_UCHE, 0x22222222},
33762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL3_UCHE, 0x22222222},
33862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL4_UCHE, 0x00222222},
33962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_UCHE,  0x00000004},
34062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_UCHE, 0x00000002},
34162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RB0, 0x22222222},
34262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RB0, 0x00002222},
34362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_CCU0, 0x00002020},
34462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_CCU1, 0x00002220},
34562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_CCU2, 0x00002220},
34662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_CCU3, 0x00002220},
34762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RB_CCU0, 0x00040F00},
34862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RB_CCU1, 0x00040F00},
34962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RB_CCU2, 0x00040F00},
35062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RB_CCU3, 0x00040F00},
35162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RAC, 0x05022022},
35262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RAC, 0x00005555},
35362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_RAC, 0x00000011},
35462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RAC, 0x00445044},
35562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TSE_RAS_RBBM, 0x04222222},
35662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_GPC, 0x00222222},
35762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_VFD, 0x00002222},
35862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TSE_RAS_RBBM, 0x00000000},
35962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GPC, 0x04104004},
36062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_VFD, 0x00000000},
36162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000},
36262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000},
36362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GPC, 0x00000200},
36462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_VFD, 0x00002222},
36562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ_2, 0x00000002},
36662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_HLSQ, 0x00002222},
36762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_GMU_GX, 0x00000222},
36862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GMU_GX, 0x00000111},
36962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555},
37062306a36Sopenharmony_ci	{},
37162306a36Sopenharmony_ci};
37262306a36Sopenharmony_ci
37362306a36Sopenharmony_ciconst struct adreno_reglist a630_hwcg[] = {
37462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_SP0, 0x22222222},
37562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_SP1, 0x22222222},
37662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_SP2, 0x22222222},
37762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_SP3, 0x22222222},
37862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_SP0, 0x02022220},
37962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_SP1, 0x02022220},
38062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_SP2, 0x02022220},
38162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_SP3, 0x02022220},
38262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_SP0, 0x00000080},
38362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_SP1, 0x00000080},
38462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_SP2, 0x00000080},
38562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_SP3, 0x00000080},
38662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_SP0, 0x0000f3cf},
38762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_SP1, 0x0000f3cf},
38862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_SP2, 0x0000f3cf},
38962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_SP3, 0x0000f3cf},
39062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TP0, 0x02222222},
39162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TP1, 0x02222222},
39262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TP2, 0x02222222},
39362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TP3, 0x02222222},
39462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_TP0, 0x22222222},
39562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_TP1, 0x22222222},
39662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_TP2, 0x22222222},
39762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_TP3, 0x22222222},
39862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL3_TP0, 0x22222222},
39962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL3_TP1, 0x22222222},
40062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL3_TP2, 0x22222222},
40162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL3_TP3, 0x22222222},
40262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL4_TP0, 0x00022222},
40362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL4_TP1, 0x00022222},
40462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL4_TP2, 0x00022222},
40562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL4_TP3, 0x00022222},
40662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TP0, 0x77777777},
40762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TP1, 0x77777777},
40862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TP2, 0x77777777},
40962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TP3, 0x77777777},
41062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST2_TP0, 0x77777777},
41162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST2_TP1, 0x77777777},
41262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST2_TP2, 0x77777777},
41362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST2_TP3, 0x77777777},
41462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST3_TP0, 0x77777777},
41562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST3_TP1, 0x77777777},
41662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST3_TP2, 0x77777777},
41762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST3_TP3, 0x77777777},
41862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST4_TP0, 0x00077777},
41962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST4_TP1, 0x00077777},
42062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST4_TP2, 0x00077777},
42162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST4_TP3, 0x00077777},
42262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TP0, 0x11111111},
42362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TP1, 0x11111111},
42462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TP2, 0x11111111},
42562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TP3, 0x11111111},
42662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY2_TP0, 0x11111111},
42762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY2_TP1, 0x11111111},
42862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY2_TP2, 0x11111111},
42962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY2_TP3, 0x11111111},
43062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY3_TP0, 0x11111111},
43162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY3_TP1, 0x11111111},
43262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY3_TP2, 0x11111111},
43362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY3_TP3, 0x11111111},
43462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY4_TP0, 0x00011111},
43562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY4_TP1, 0x00011111},
43662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY4_TP2, 0x00011111},
43762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY4_TP3, 0x00011111},
43862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_UCHE, 0x22222222},
43962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_UCHE, 0x22222222},
44062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL3_UCHE, 0x22222222},
44162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL4_UCHE, 0x00222222},
44262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_UCHE, 0x00000004},
44362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_UCHE, 0x00000002},
44462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RB0, 0x22222222},
44562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RB1, 0x22222222},
44662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RB2, 0x22222222},
44762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RB3, 0x22222222},
44862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RB0, 0x00002222},
44962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RB1, 0x00002222},
45062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RB2, 0x00002222},
45162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RB3, 0x00002222},
45262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_CCU0, 0x00002220},
45362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_CCU1, 0x00002220},
45462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_CCU2, 0x00002220},
45562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_CCU3, 0x00002220},
45662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RB_CCU0, 0x00040f00},
45762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RB_CCU1, 0x00040f00},
45862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RB_CCU2, 0x00040f00},
45962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RB_CCU3, 0x00040f00},
46062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RAC, 0x05022022},
46162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RAC, 0x00005555},
46262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_RAC, 0x00000011},
46362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RAC, 0x00445044},
46462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TSE_RAS_RBBM, 0x04222222},
46562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_GPC, 0x00222222},
46662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_VFD, 0x00002222},
46762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TSE_RAS_RBBM, 0x00000000},
46862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GPC, 0x04104004},
46962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_VFD, 0x00000000},
47062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000},
47162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000},
47262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GPC, 0x00000200},
47362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_VFD, 0x00002222},
47462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ_2, 0x00000002},
47562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_HLSQ, 0x00002222},
47662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_GMU_GX, 0x00000222},
47762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GMU_GX, 0x00000111},
47862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555},
47962306a36Sopenharmony_ci	{},
48062306a36Sopenharmony_ci};
48162306a36Sopenharmony_ci
48262306a36Sopenharmony_ciconst struct adreno_reglist a640_hwcg[] = {
48362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_SP0, 0x02222222},
48462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_SP0, 0x02222220},
48562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_SP0, 0x00000080},
48662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_SP0, 0x0000F3CF},
48762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TP0, 0x02222222},
48862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_TP0, 0x22222222},
48962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL3_TP0, 0x22222222},
49062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL4_TP0, 0x00022222},
49162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TP0, 0x11111111},
49262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY2_TP0, 0x11111111},
49362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY3_TP0, 0x11111111},
49462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY4_TP0, 0x00011111},
49562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TP0, 0x77777777},
49662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST2_TP0, 0x77777777},
49762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST3_TP0, 0x77777777},
49862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST4_TP0, 0x00077777},
49962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RB0, 0x22222222},
50062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RB0, 0x01002222},
50162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_CCU0, 0x00002220},
50262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RB_CCU0, 0x00040F00},
50362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RAC, 0x05222022},
50462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RAC, 0x00005555},
50562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_RAC, 0x00000011},
50662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RAC, 0x00445044},
50762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TSE_RAS_RBBM, 0x04222222},
50862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_VFD, 0x00002222},
50962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_GPC, 0x00222222},
51062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ_2, 0x00000002},
51162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_HLSQ, 0x00002222},
51262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000},
51362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_VFD, 0x00002222},
51462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GPC, 0x00000200},
51562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000},
51662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TSE_RAS_RBBM, 0x00000000},
51762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_VFD, 0x00000000},
51862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GPC, 0x04104004},
51962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_HLSQ, 0x00000000},
52062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TEX_FCHE, 0x00000222},
52162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TEX_FCHE, 0x00000111},
52262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TEX_FCHE, 0x00000000},
52362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_UCHE, 0x22222222},
52462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_UCHE, 0x00000004},
52562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_UCHE, 0x00000002},
52662306a36Sopenharmony_ci	{REG_A6XX_RBBM_ISDB_CNT, 0x00000182},
52762306a36Sopenharmony_ci	{REG_A6XX_RBBM_RAC_THRESHOLD_CNT, 0x00000000},
52862306a36Sopenharmony_ci	{REG_A6XX_RBBM_SP_HYST_CNT, 0x00000000},
52962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_GMU_GX, 0x00000222},
53062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GMU_GX, 0x00000111},
53162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555},
53262306a36Sopenharmony_ci	{},
53362306a36Sopenharmony_ci};
53462306a36Sopenharmony_ci
53562306a36Sopenharmony_ciconst struct adreno_reglist a650_hwcg[] = {
53662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_SP0, 0x02222222},
53762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_SP0, 0x02222220},
53862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_SP0, 0x00000080},
53962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_SP0, 0x0000F3CF},
54062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TP0, 0x02222222},
54162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_TP0, 0x22222222},
54262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL3_TP0, 0x22222222},
54362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL4_TP0, 0x00022222},
54462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TP0, 0x11111111},
54562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY2_TP0, 0x11111111},
54662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY3_TP0, 0x11111111},
54762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY4_TP0, 0x00011111},
54862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TP0, 0x77777777},
54962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST2_TP0, 0x77777777},
55062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST3_TP0, 0x77777777},
55162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST4_TP0, 0x00077777},
55262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RB0, 0x22222222},
55362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RB0, 0x01002222},
55462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_CCU0, 0x00002220},
55562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RB_CCU0, 0x00040F00},
55662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RAC, 0x25222022},
55762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RAC, 0x00005555},
55862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_RAC, 0x00000011},
55962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RAC, 0x00445044},
56062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TSE_RAS_RBBM, 0x04222222},
56162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_VFD, 0x00002222},
56262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_GPC, 0x00222222},
56362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ_2, 0x00000002},
56462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_HLSQ, 0x00002222},
56562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000},
56662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_VFD, 0x00002222},
56762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GPC, 0x00000200},
56862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000},
56962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TSE_RAS_RBBM, 0x00000000},
57062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_VFD, 0x00000000},
57162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GPC, 0x04104004},
57262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_HLSQ, 0x00000000},
57362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TEX_FCHE, 0x00000222},
57462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TEX_FCHE, 0x00000111},
57562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TEX_FCHE, 0x00000777},
57662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_UCHE, 0x22222222},
57762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_UCHE, 0x00000004},
57862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_UCHE, 0x00000002},
57962306a36Sopenharmony_ci	{REG_A6XX_RBBM_ISDB_CNT, 0x00000182},
58062306a36Sopenharmony_ci	{REG_A6XX_RBBM_RAC_THRESHOLD_CNT, 0x00000000},
58162306a36Sopenharmony_ci	{REG_A6XX_RBBM_SP_HYST_CNT, 0x00000000},
58262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_GMU_GX, 0x00000222},
58362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GMU_GX, 0x00000111},
58462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555},
58562306a36Sopenharmony_ci	{},
58662306a36Sopenharmony_ci};
58762306a36Sopenharmony_ci
58862306a36Sopenharmony_ciconst struct adreno_reglist a660_hwcg[] = {
58962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_SP0, 0x02222222},
59062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_SP0, 0x02222220},
59162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_SP0, 0x00000080},
59262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_SP0, 0x0000F3CF},
59362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TP0, 0x22222222},
59462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_TP0, 0x22222222},
59562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL3_TP0, 0x22222222},
59662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL4_TP0, 0x00022222},
59762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TP0, 0x11111111},
59862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY2_TP0, 0x11111111},
59962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY3_TP0, 0x11111111},
60062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY4_TP0, 0x00011111},
60162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TP0, 0x77777777},
60262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST2_TP0, 0x77777777},
60362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST3_TP0, 0x77777777},
60462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST4_TP0, 0x00077777},
60562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RB0, 0x22222222},
60662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RB0, 0x01002222},
60762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_CCU0, 0x00002220},
60862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RB_CCU0, 0x00040F00},
60962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RAC, 0x25222022},
61062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RAC, 0x00005555},
61162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_RAC, 0x00000011},
61262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RAC, 0x00445044},
61362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TSE_RAS_RBBM, 0x04222222},
61462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_VFD, 0x00002222},
61562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_GPC, 0x00222222},
61662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ_2, 0x00000002},
61762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_HLSQ, 0x00002222},
61862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000},
61962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_VFD, 0x00002222},
62062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GPC, 0x00000200},
62162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000},
62262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TSE_RAS_RBBM, 0x00000000},
62362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_VFD, 0x00000000},
62462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GPC, 0x04104004},
62562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_HLSQ, 0x00000000},
62662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TEX_FCHE, 0x00000222},
62762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TEX_FCHE, 0x00000111},
62862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TEX_FCHE, 0x00000000},
62962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_UCHE, 0x22222222},
63062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_UCHE, 0x00000004},
63162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_UCHE, 0x00000002},
63262306a36Sopenharmony_ci	{REG_A6XX_RBBM_ISDB_CNT, 0x00000182},
63362306a36Sopenharmony_ci	{REG_A6XX_RBBM_RAC_THRESHOLD_CNT, 0x00000000},
63462306a36Sopenharmony_ci	{REG_A6XX_RBBM_SP_HYST_CNT, 0x00000000},
63562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_GMU_GX, 0x00000222},
63662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GMU_GX, 0x00000111},
63762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555},
63862306a36Sopenharmony_ci	{},
63962306a36Sopenharmony_ci};
64062306a36Sopenharmony_ci
64162306a36Sopenharmony_ciconst struct adreno_reglist a690_hwcg[] = {
64262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_SP0, 0x02222222},
64362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_SP0, 0x02222220},
64462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_SP0, 0x00000080},
64562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_SP0, 0x0000F3CF},
64662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TP0, 0x22222222},
64762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_TP0, 0x22222222},
64862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL3_TP0, 0x22222222},
64962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL4_TP0, 0x00022222},
65062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TP0, 0x11111111},
65162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY2_TP0, 0x11111111},
65262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY3_TP0, 0x11111111},
65362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY4_TP0, 0x00011111},
65462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TP0, 0x77777777},
65562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST2_TP0, 0x77777777},
65662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST3_TP0, 0x77777777},
65762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST4_TP0, 0x00077777},
65862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RB0, 0x22222222},
65962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RB0, 0x01002222},
66062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_CCU0, 0x00002220},
66162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RB_CCU0, 0x00040F00},
66262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_RAC, 0x25222022},
66362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL2_RAC, 0x00005555},
66462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_RAC, 0x00000011},
66562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_RAC, 0x00445044},
66662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TSE_RAS_RBBM, 0x04222222},
66762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_VFD, 0x00002222},
66862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_GPC, 0x00222222},
66962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ_2, 0x00000002},
67062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_MODE_HLSQ, 0x00002222},
67162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000},
67262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_VFD, 0x00002222},
67362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GPC, 0x00000200},
67462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000},
67562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TSE_RAS_RBBM, 0x00000000},
67662306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_VFD, 0x00000000},
67762306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GPC, 0x04104004},
67862306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_HLSQ, 0x00000000},
67962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_TEX_FCHE, 0x00000222},
68062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_TEX_FCHE, 0x00000111},
68162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_TEX_FCHE, 0x00000000},
68262306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_UCHE, 0x22222222},
68362306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_UCHE, 0x00000004},
68462306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_UCHE, 0x00000002},
68562306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL, 0x8AA8AA82},
68662306a36Sopenharmony_ci	{REG_A6XX_RBBM_ISDB_CNT, 0x00000182},
68762306a36Sopenharmony_ci	{REG_A6XX_RBBM_RAC_THRESHOLD_CNT, 0x00000000},
68862306a36Sopenharmony_ci	{REG_A6XX_RBBM_SP_HYST_CNT, 0x00000000},
68962306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_CNTL_GMU_GX, 0x00000222},
69062306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_DELAY_GMU_GX, 0x00000111},
69162306a36Sopenharmony_ci	{REG_A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555},
69262306a36Sopenharmony_ci	{REG_A6XX_GPU_GMU_AO_GMU_CGC_MODE_CNTL, 0x20200},
69362306a36Sopenharmony_ci	{REG_A6XX_GPU_GMU_AO_GMU_CGC_DELAY_CNTL, 0x10111},
69462306a36Sopenharmony_ci	{REG_A6XX_GPU_GMU_AO_GMU_CGC_HYST_CNTL, 0x5555},
69562306a36Sopenharmony_ci	{}
69662306a36Sopenharmony_ci};
69762306a36Sopenharmony_ci
69862306a36Sopenharmony_cistatic void a6xx_set_hwcg(struct msm_gpu *gpu, bool state)
69962306a36Sopenharmony_ci{
70062306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
70162306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
70262306a36Sopenharmony_ci	struct a6xx_gmu *gmu = &a6xx_gpu->gmu;
70362306a36Sopenharmony_ci	const struct adreno_reglist *reg;
70462306a36Sopenharmony_ci	unsigned int i;
70562306a36Sopenharmony_ci	u32 val, clock_cntl_on;
70662306a36Sopenharmony_ci
70762306a36Sopenharmony_ci	if (!adreno_gpu->info->hwcg)
70862306a36Sopenharmony_ci		return;
70962306a36Sopenharmony_ci
71062306a36Sopenharmony_ci	if (adreno_is_a630(adreno_gpu))
71162306a36Sopenharmony_ci		clock_cntl_on = 0x8aa8aa02;
71262306a36Sopenharmony_ci	else if (adreno_is_a610(adreno_gpu))
71362306a36Sopenharmony_ci		clock_cntl_on = 0xaaa8aa82;
71462306a36Sopenharmony_ci	else
71562306a36Sopenharmony_ci		clock_cntl_on = 0x8aa8aa82;
71662306a36Sopenharmony_ci
71762306a36Sopenharmony_ci	val = gpu_read(gpu, REG_A6XX_RBBM_CLOCK_CNTL);
71862306a36Sopenharmony_ci
71962306a36Sopenharmony_ci	/* Don't re-program the registers if they are already correct */
72062306a36Sopenharmony_ci	if ((!state && !val) || (state && (val == clock_cntl_on)))
72162306a36Sopenharmony_ci		return;
72262306a36Sopenharmony_ci
72362306a36Sopenharmony_ci	/* Disable SP clock before programming HWCG registers */
72462306a36Sopenharmony_ci	if (!adreno_is_a610(adreno_gpu))
72562306a36Sopenharmony_ci		gmu_rmw(gmu, REG_A6XX_GPU_GMU_GX_SPTPRAC_CLOCK_CONTROL, 1, 0);
72662306a36Sopenharmony_ci
72762306a36Sopenharmony_ci	for (i = 0; (reg = &adreno_gpu->info->hwcg[i], reg->offset); i++)
72862306a36Sopenharmony_ci		gpu_write(gpu, reg->offset, state ? reg->value : 0);
72962306a36Sopenharmony_ci
73062306a36Sopenharmony_ci	/* Enable SP clock */
73162306a36Sopenharmony_ci	if (!adreno_is_a610(adreno_gpu))
73262306a36Sopenharmony_ci		gmu_rmw(gmu, REG_A6XX_GPU_GMU_GX_SPTPRAC_CLOCK_CONTROL, 0, 1);
73362306a36Sopenharmony_ci
73462306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_RBBM_CLOCK_CNTL, state ? clock_cntl_on : 0);
73562306a36Sopenharmony_ci}
73662306a36Sopenharmony_ci
73762306a36Sopenharmony_ci/* For a615, a616, a618, a619, a630, a640 and a680 */
73862306a36Sopenharmony_cistatic const u32 a6xx_protect[] = {
73962306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x00000, 0x04ff),
74062306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x00501, 0x0005),
74162306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x0050b, 0x02f4),
74262306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0050e, 0x0000),
74362306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00510, 0x0000),
74462306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00534, 0x0000),
74562306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00800, 0x0082),
74662306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x008a0, 0x0008),
74762306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x008ab, 0x0024),
74862306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x008de, 0x00ae),
74962306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00900, 0x004d),
75062306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0098d, 0x0272),
75162306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00e00, 0x0001),
75262306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00e03, 0x000c),
75362306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x03c00, 0x00c3),
75462306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x03cc4, 0x1fff),
75562306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08630, 0x01cf),
75662306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e00, 0x0000),
75762306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e08, 0x0000),
75862306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e50, 0x001f),
75962306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x09624, 0x01db),
76062306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x09e70, 0x0001),
76162306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x09e78, 0x0187),
76262306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0a630, 0x01cf),
76362306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0ae02, 0x0000),
76462306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0ae50, 0x032f),
76562306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0b604, 0x0000),
76662306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0be02, 0x0001),
76762306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0be20, 0x17df),
76862306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0f000, 0x0bff),
76962306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x0fc00, 0x1fff),
77062306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x11c00, 0x0000), /* note: infinite range */
77162306a36Sopenharmony_ci};
77262306a36Sopenharmony_ci
77362306a36Sopenharmony_ci/* These are for a620 and a650 */
77462306a36Sopenharmony_cistatic const u32 a650_protect[] = {
77562306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x00000, 0x04ff),
77662306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x00501, 0x0005),
77762306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x0050b, 0x02f4),
77862306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0050e, 0x0000),
77962306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00510, 0x0000),
78062306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00534, 0x0000),
78162306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00800, 0x0082),
78262306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x008a0, 0x0008),
78362306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x008ab, 0x0024),
78462306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x008de, 0x00ae),
78562306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00900, 0x004d),
78662306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0098d, 0x0272),
78762306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00e00, 0x0001),
78862306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00e03, 0x000c),
78962306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x03c00, 0x00c3),
79062306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x03cc4, 0x1fff),
79162306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08630, 0x01cf),
79262306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e00, 0x0000),
79362306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e08, 0x0000),
79462306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e50, 0x001f),
79562306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e80, 0x027f),
79662306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x09624, 0x01db),
79762306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x09e60, 0x0011),
79862306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x09e78, 0x0187),
79962306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0a630, 0x01cf),
80062306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0ae02, 0x0000),
80162306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0ae50, 0x032f),
80262306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0b604, 0x0000),
80362306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0b608, 0x0007),
80462306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0be02, 0x0001),
80562306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0be20, 0x17df),
80662306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0f000, 0x0bff),
80762306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x0fc00, 0x1fff),
80862306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x18400, 0x1fff),
80962306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x1a800, 0x1fff),
81062306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x1f400, 0x0443),
81162306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x1f844, 0x007b),
81262306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x1f887, 0x001b),
81362306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x1f8c0, 0x0000), /* note: infinite range */
81462306a36Sopenharmony_ci};
81562306a36Sopenharmony_ci
81662306a36Sopenharmony_ci/* These are for a635 and a660 */
81762306a36Sopenharmony_cistatic const u32 a660_protect[] = {
81862306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x00000, 0x04ff),
81962306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x00501, 0x0005),
82062306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x0050b, 0x02f4),
82162306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0050e, 0x0000),
82262306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00510, 0x0000),
82362306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00534, 0x0000),
82462306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00800, 0x0082),
82562306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x008a0, 0x0008),
82662306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x008ab, 0x0024),
82762306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x008de, 0x00ae),
82862306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00900, 0x004d),
82962306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0098d, 0x0272),
83062306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00e00, 0x0001),
83162306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00e03, 0x000c),
83262306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x03c00, 0x00c3),
83362306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x03cc4, 0x1fff),
83462306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08630, 0x01cf),
83562306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e00, 0x0000),
83662306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e08, 0x0000),
83762306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e50, 0x001f),
83862306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e80, 0x027f),
83962306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x09624, 0x01db),
84062306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x09e60, 0x0011),
84162306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x09e78, 0x0187),
84262306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0a630, 0x01cf),
84362306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0ae02, 0x0000),
84462306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0ae50, 0x012f),
84562306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0b604, 0x0000),
84662306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0b608, 0x0006),
84762306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0be02, 0x0001),
84862306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0be20, 0x015f),
84962306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0d000, 0x05ff),
85062306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0f000, 0x0bff),
85162306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x0fc00, 0x1fff),
85262306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x18400, 0x1fff),
85362306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x1a400, 0x1fff),
85462306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x1f400, 0x0443),
85562306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x1f844, 0x007b),
85662306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x1f860, 0x0000),
85762306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x1f887, 0x001b),
85862306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x1f8c0, 0x0000), /* note: infinite range */
85962306a36Sopenharmony_ci};
86062306a36Sopenharmony_ci
86162306a36Sopenharmony_ci/* These are for a690 */
86262306a36Sopenharmony_cistatic const u32 a690_protect[] = {
86362306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x00000, 0x004ff),
86462306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x00501, 0x00001),
86562306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x0050b, 0x002f4),
86662306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0050e, 0x00000),
86762306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00510, 0x00000),
86862306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00534, 0x00000),
86962306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00800, 0x00082),
87062306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x008a0, 0x00008),
87162306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x008ab, 0x00024),
87262306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x008de, 0x000ae),
87362306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00900, 0x0004d),
87462306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0098d, 0x00272),
87562306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00e00, 0x00001),
87662306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x00e03, 0x0000c),
87762306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x03c00, 0x000c3),
87862306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x03cc4, 0x01fff),
87962306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08630, 0x001cf),
88062306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e00, 0x00000),
88162306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e08, 0x00007),
88262306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e50, 0x0001f),
88362306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x08e80, 0x0027f),
88462306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x09624, 0x001db),
88562306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x09e60, 0x00011),
88662306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x09e78, 0x00187),
88762306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0a630, 0x001cf),
88862306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0ae02, 0x00000),
88962306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0ae50, 0x0012f),
89062306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0b604, 0x00000),
89162306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0b608, 0x00006),
89262306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0be02, 0x00001),
89362306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0be20, 0x0015f),
89462306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0d000, 0x005ff),
89562306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x0f000, 0x00bff),
89662306a36Sopenharmony_ci	A6XX_PROTECT_RDONLY(0x0fc00, 0x01fff),
89762306a36Sopenharmony_ci	A6XX_PROTECT_NORDWR(0x11c00, 0x00000), /*note: infiite range */
89862306a36Sopenharmony_ci};
89962306a36Sopenharmony_ci
90062306a36Sopenharmony_cistatic void a6xx_set_cp_protect(struct msm_gpu *gpu)
90162306a36Sopenharmony_ci{
90262306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
90362306a36Sopenharmony_ci	const u32 *regs = a6xx_protect;
90462306a36Sopenharmony_ci	unsigned i, count, count_max;
90562306a36Sopenharmony_ci
90662306a36Sopenharmony_ci	if (adreno_is_a650(adreno_gpu)) {
90762306a36Sopenharmony_ci		regs = a650_protect;
90862306a36Sopenharmony_ci		count = ARRAY_SIZE(a650_protect);
90962306a36Sopenharmony_ci		count_max = 48;
91062306a36Sopenharmony_ci		BUILD_BUG_ON(ARRAY_SIZE(a650_protect) > 48);
91162306a36Sopenharmony_ci	} else if (adreno_is_a690(adreno_gpu)) {
91262306a36Sopenharmony_ci		regs = a690_protect;
91362306a36Sopenharmony_ci		count = ARRAY_SIZE(a690_protect);
91462306a36Sopenharmony_ci		count_max = 48;
91562306a36Sopenharmony_ci		BUILD_BUG_ON(ARRAY_SIZE(a690_protect) > 48);
91662306a36Sopenharmony_ci	} else if (adreno_is_a660_family(adreno_gpu)) {
91762306a36Sopenharmony_ci		regs = a660_protect;
91862306a36Sopenharmony_ci		count = ARRAY_SIZE(a660_protect);
91962306a36Sopenharmony_ci		count_max = 48;
92062306a36Sopenharmony_ci		BUILD_BUG_ON(ARRAY_SIZE(a660_protect) > 48);
92162306a36Sopenharmony_ci	} else {
92262306a36Sopenharmony_ci		regs = a6xx_protect;
92362306a36Sopenharmony_ci		count = ARRAY_SIZE(a6xx_protect);
92462306a36Sopenharmony_ci		count_max = 32;
92562306a36Sopenharmony_ci		BUILD_BUG_ON(ARRAY_SIZE(a6xx_protect) > 32);
92662306a36Sopenharmony_ci	}
92762306a36Sopenharmony_ci
92862306a36Sopenharmony_ci	/*
92962306a36Sopenharmony_ci	 * Enable access protection to privileged registers, fault on an access
93062306a36Sopenharmony_ci	 * protect violation and select the last span to protect from the start
93162306a36Sopenharmony_ci	 * address all the way to the end of the register address space
93262306a36Sopenharmony_ci	 */
93362306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_CP_PROTECT_CNTL,
93462306a36Sopenharmony_ci		  A6XX_CP_PROTECT_CNTL_ACCESS_PROT_EN |
93562306a36Sopenharmony_ci		  A6XX_CP_PROTECT_CNTL_ACCESS_FAULT_ON_VIOL_EN |
93662306a36Sopenharmony_ci		  A6XX_CP_PROTECT_CNTL_LAST_SPAN_INF_RANGE);
93762306a36Sopenharmony_ci
93862306a36Sopenharmony_ci	for (i = 0; i < count - 1; i++) {
93962306a36Sopenharmony_ci		/* Intentionally skip writing to some registers */
94062306a36Sopenharmony_ci		if (regs[i])
94162306a36Sopenharmony_ci			gpu_write(gpu, REG_A6XX_CP_PROTECT(i), regs[i]);
94262306a36Sopenharmony_ci	}
94362306a36Sopenharmony_ci	/* last CP_PROTECT to have "infinite" length on the last entry */
94462306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_CP_PROTECT(count_max - 1), regs[i]);
94562306a36Sopenharmony_ci}
94662306a36Sopenharmony_ci
94762306a36Sopenharmony_cistatic void a6xx_set_ubwc_config(struct msm_gpu *gpu)
94862306a36Sopenharmony_ci{
94962306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
95062306a36Sopenharmony_ci	/* Unknown, introduced with A650 family, related to UBWC mode/ver 4 */
95162306a36Sopenharmony_ci	u32 rgb565_predicator = 0;
95262306a36Sopenharmony_ci	/* Unknown, introduced with A650 family */
95362306a36Sopenharmony_ci	u32 uavflagprd_inv = 0;
95462306a36Sopenharmony_ci	/* Whether the minimum access length is 64 bits */
95562306a36Sopenharmony_ci	u32 min_acc_len = 0;
95662306a36Sopenharmony_ci	/* Entirely magic, per-GPU-gen value */
95762306a36Sopenharmony_ci	u32 ubwc_mode = 0;
95862306a36Sopenharmony_ci	/*
95962306a36Sopenharmony_ci	 * The Highest Bank Bit value represents the bit of the highest DDR bank.
96062306a36Sopenharmony_ci	 * We then subtract 13 from it (13 is the minimum value allowed by hw) and
96162306a36Sopenharmony_ci	 * write the lowest two bits of the remaining value as hbb_lo and the
96262306a36Sopenharmony_ci	 * one above it as hbb_hi to the hardware. This should ideally use DRAM
96362306a36Sopenharmony_ci	 * type detection.
96462306a36Sopenharmony_ci	 */
96562306a36Sopenharmony_ci	u32 hbb_hi = 0;
96662306a36Sopenharmony_ci	u32 hbb_lo = 2;
96762306a36Sopenharmony_ci	/* Unknown, introduced with A640/680 */
96862306a36Sopenharmony_ci	u32 amsbc = 0;
96962306a36Sopenharmony_ci
97062306a36Sopenharmony_ci	if (adreno_is_a610(adreno_gpu)) {
97162306a36Sopenharmony_ci		/* HBB = 14 */
97262306a36Sopenharmony_ci		hbb_lo = 1;
97362306a36Sopenharmony_ci		min_acc_len = 1;
97462306a36Sopenharmony_ci		ubwc_mode = 1;
97562306a36Sopenharmony_ci	}
97662306a36Sopenharmony_ci
97762306a36Sopenharmony_ci	/* a618 is using the hw default values */
97862306a36Sopenharmony_ci	if (adreno_is_a618(adreno_gpu))
97962306a36Sopenharmony_ci		return;
98062306a36Sopenharmony_ci
98162306a36Sopenharmony_ci	if (adreno_is_a619_holi(adreno_gpu))
98262306a36Sopenharmony_ci		hbb_lo = 0;
98362306a36Sopenharmony_ci
98462306a36Sopenharmony_ci	if (adreno_is_a640_family(adreno_gpu))
98562306a36Sopenharmony_ci		amsbc = 1;
98662306a36Sopenharmony_ci
98762306a36Sopenharmony_ci	if (adreno_is_a650(adreno_gpu) || adreno_is_a660(adreno_gpu)) {
98862306a36Sopenharmony_ci		/* TODO: get ddr type from bootloader and use 2 for LPDDR4 */
98962306a36Sopenharmony_ci		hbb_lo = 3;
99062306a36Sopenharmony_ci		amsbc = 1;
99162306a36Sopenharmony_ci		rgb565_predicator = 1;
99262306a36Sopenharmony_ci		uavflagprd_inv = 2;
99362306a36Sopenharmony_ci	}
99462306a36Sopenharmony_ci
99562306a36Sopenharmony_ci	if (adreno_is_a690(adreno_gpu)) {
99662306a36Sopenharmony_ci		hbb_lo = 2;
99762306a36Sopenharmony_ci		amsbc = 1;
99862306a36Sopenharmony_ci		rgb565_predicator = 1;
99962306a36Sopenharmony_ci		uavflagprd_inv = 2;
100062306a36Sopenharmony_ci	}
100162306a36Sopenharmony_ci
100262306a36Sopenharmony_ci	if (adreno_is_7c3(adreno_gpu)) {
100362306a36Sopenharmony_ci		hbb_lo = 1;
100462306a36Sopenharmony_ci		amsbc = 1;
100562306a36Sopenharmony_ci		rgb565_predicator = 1;
100662306a36Sopenharmony_ci		uavflagprd_inv = 2;
100762306a36Sopenharmony_ci	}
100862306a36Sopenharmony_ci
100962306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_RB_NC_MODE_CNTL,
101062306a36Sopenharmony_ci		  rgb565_predicator << 11 | hbb_hi << 10 | amsbc << 4 |
101162306a36Sopenharmony_ci		  min_acc_len << 3 | hbb_lo << 1 | ubwc_mode);
101262306a36Sopenharmony_ci
101362306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_TPL1_NC_MODE_CNTL, hbb_hi << 4 |
101462306a36Sopenharmony_ci		  min_acc_len << 3 | hbb_lo << 1 | ubwc_mode);
101562306a36Sopenharmony_ci
101662306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_SP_NC_MODE_CNTL, hbb_hi << 10 |
101762306a36Sopenharmony_ci		  uavflagprd_inv << 4 | min_acc_len << 3 |
101862306a36Sopenharmony_ci		  hbb_lo << 1 | ubwc_mode);
101962306a36Sopenharmony_ci
102062306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_UCHE_MODE_CNTL, min_acc_len << 23 | hbb_lo << 21);
102162306a36Sopenharmony_ci}
102262306a36Sopenharmony_ci
102362306a36Sopenharmony_cistatic int a6xx_cp_init(struct msm_gpu *gpu)
102462306a36Sopenharmony_ci{
102562306a36Sopenharmony_ci	struct msm_ringbuffer *ring = gpu->rb[0];
102662306a36Sopenharmony_ci
102762306a36Sopenharmony_ci	OUT_PKT7(ring, CP_ME_INIT, 8);
102862306a36Sopenharmony_ci
102962306a36Sopenharmony_ci	OUT_RING(ring, 0x0000002f);
103062306a36Sopenharmony_ci
103162306a36Sopenharmony_ci	/* Enable multiple hardware contexts */
103262306a36Sopenharmony_ci	OUT_RING(ring, 0x00000003);
103362306a36Sopenharmony_ci
103462306a36Sopenharmony_ci	/* Enable error detection */
103562306a36Sopenharmony_ci	OUT_RING(ring, 0x20000000);
103662306a36Sopenharmony_ci
103762306a36Sopenharmony_ci	/* Don't enable header dump */
103862306a36Sopenharmony_ci	OUT_RING(ring, 0x00000000);
103962306a36Sopenharmony_ci	OUT_RING(ring, 0x00000000);
104062306a36Sopenharmony_ci
104162306a36Sopenharmony_ci	/* No workarounds enabled */
104262306a36Sopenharmony_ci	OUT_RING(ring, 0x00000000);
104362306a36Sopenharmony_ci
104462306a36Sopenharmony_ci	/* Pad rest of the cmds with 0's */
104562306a36Sopenharmony_ci	OUT_RING(ring, 0x00000000);
104662306a36Sopenharmony_ci	OUT_RING(ring, 0x00000000);
104762306a36Sopenharmony_ci
104862306a36Sopenharmony_ci	a6xx_flush(gpu, ring);
104962306a36Sopenharmony_ci	return a6xx_idle(gpu, ring) ? 0 : -EINVAL;
105062306a36Sopenharmony_ci}
105162306a36Sopenharmony_ci
105262306a36Sopenharmony_ci/*
105362306a36Sopenharmony_ci * Check that the microcode version is new enough to include several key
105462306a36Sopenharmony_ci * security fixes. Return true if the ucode is safe.
105562306a36Sopenharmony_ci */
105662306a36Sopenharmony_cistatic bool a6xx_ucode_check_version(struct a6xx_gpu *a6xx_gpu,
105762306a36Sopenharmony_ci		struct drm_gem_object *obj)
105862306a36Sopenharmony_ci{
105962306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = &a6xx_gpu->base;
106062306a36Sopenharmony_ci	struct msm_gpu *gpu = &adreno_gpu->base;
106162306a36Sopenharmony_ci	const char *sqe_name = adreno_gpu->info->fw[ADRENO_FW_SQE];
106262306a36Sopenharmony_ci	u32 *buf = msm_gem_get_vaddr(obj);
106362306a36Sopenharmony_ci	bool ret = false;
106462306a36Sopenharmony_ci
106562306a36Sopenharmony_ci	if (IS_ERR(buf))
106662306a36Sopenharmony_ci		return false;
106762306a36Sopenharmony_ci
106862306a36Sopenharmony_ci	/*
106962306a36Sopenharmony_ci	 * Targets up to a640 (a618, a630 and a640) need to check for a
107062306a36Sopenharmony_ci	 * microcode version that is patched to support the whereami opcode or
107162306a36Sopenharmony_ci	 * one that is new enough to include it by default.
107262306a36Sopenharmony_ci	 *
107362306a36Sopenharmony_ci	 * a650 tier targets don't need whereami but still need to be
107462306a36Sopenharmony_ci	 * equal to or newer than 0.95 for other security fixes
107562306a36Sopenharmony_ci	 *
107662306a36Sopenharmony_ci	 * a660 targets have all the critical security fixes from the start
107762306a36Sopenharmony_ci	 */
107862306a36Sopenharmony_ci	if (!strcmp(sqe_name, "a630_sqe.fw")) {
107962306a36Sopenharmony_ci		/*
108062306a36Sopenharmony_ci		 * If the lowest nibble is 0xa that is an indication that this
108162306a36Sopenharmony_ci		 * microcode has been patched. The actual version is in dword
108262306a36Sopenharmony_ci		 * [3] but we only care about the patchlevel which is the lowest
108362306a36Sopenharmony_ci		 * nibble of dword [3]
108462306a36Sopenharmony_ci		 *
108562306a36Sopenharmony_ci		 * Otherwise check that the firmware is greater than or equal
108662306a36Sopenharmony_ci		 * to 1.90 which was the first version that had this fix built
108762306a36Sopenharmony_ci		 * in
108862306a36Sopenharmony_ci		 */
108962306a36Sopenharmony_ci		if ((((buf[0] & 0xf) == 0xa) && (buf[2] & 0xf) >= 1) ||
109062306a36Sopenharmony_ci			(buf[0] & 0xfff) >= 0x190) {
109162306a36Sopenharmony_ci			a6xx_gpu->has_whereami = true;
109262306a36Sopenharmony_ci			ret = true;
109362306a36Sopenharmony_ci			goto out;
109462306a36Sopenharmony_ci		}
109562306a36Sopenharmony_ci
109662306a36Sopenharmony_ci		DRM_DEV_ERROR(&gpu->pdev->dev,
109762306a36Sopenharmony_ci			"a630 SQE ucode is too old. Have version %x need at least %x\n",
109862306a36Sopenharmony_ci			buf[0] & 0xfff, 0x190);
109962306a36Sopenharmony_ci	} else if (!strcmp(sqe_name, "a650_sqe.fw")) {
110062306a36Sopenharmony_ci		if ((buf[0] & 0xfff) >= 0x095) {
110162306a36Sopenharmony_ci			ret = true;
110262306a36Sopenharmony_ci			goto out;
110362306a36Sopenharmony_ci		}
110462306a36Sopenharmony_ci
110562306a36Sopenharmony_ci		DRM_DEV_ERROR(&gpu->pdev->dev,
110662306a36Sopenharmony_ci			"a650 SQE ucode is too old. Have version %x need at least %x\n",
110762306a36Sopenharmony_ci			buf[0] & 0xfff, 0x095);
110862306a36Sopenharmony_ci	} else if (!strcmp(sqe_name, "a660_sqe.fw")) {
110962306a36Sopenharmony_ci		ret = true;
111062306a36Sopenharmony_ci	} else {
111162306a36Sopenharmony_ci		DRM_DEV_ERROR(&gpu->pdev->dev,
111262306a36Sopenharmony_ci			"unknown GPU, add it to a6xx_ucode_check_version()!!\n");
111362306a36Sopenharmony_ci	}
111462306a36Sopenharmony_ciout:
111562306a36Sopenharmony_ci	msm_gem_put_vaddr(obj);
111662306a36Sopenharmony_ci	return ret;
111762306a36Sopenharmony_ci}
111862306a36Sopenharmony_ci
111962306a36Sopenharmony_cistatic int a6xx_ucode_load(struct msm_gpu *gpu)
112062306a36Sopenharmony_ci{
112162306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
112262306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
112362306a36Sopenharmony_ci
112462306a36Sopenharmony_ci	if (!a6xx_gpu->sqe_bo) {
112562306a36Sopenharmony_ci		a6xx_gpu->sqe_bo = adreno_fw_create_bo(gpu,
112662306a36Sopenharmony_ci			adreno_gpu->fw[ADRENO_FW_SQE], &a6xx_gpu->sqe_iova);
112762306a36Sopenharmony_ci
112862306a36Sopenharmony_ci		if (IS_ERR(a6xx_gpu->sqe_bo)) {
112962306a36Sopenharmony_ci			int ret = PTR_ERR(a6xx_gpu->sqe_bo);
113062306a36Sopenharmony_ci
113162306a36Sopenharmony_ci			a6xx_gpu->sqe_bo = NULL;
113262306a36Sopenharmony_ci			DRM_DEV_ERROR(&gpu->pdev->dev,
113362306a36Sopenharmony_ci				"Could not allocate SQE ucode: %d\n", ret);
113462306a36Sopenharmony_ci
113562306a36Sopenharmony_ci			return ret;
113662306a36Sopenharmony_ci		}
113762306a36Sopenharmony_ci
113862306a36Sopenharmony_ci		msm_gem_object_set_name(a6xx_gpu->sqe_bo, "sqefw");
113962306a36Sopenharmony_ci		if (!a6xx_ucode_check_version(a6xx_gpu, a6xx_gpu->sqe_bo)) {
114062306a36Sopenharmony_ci			msm_gem_unpin_iova(a6xx_gpu->sqe_bo, gpu->aspace);
114162306a36Sopenharmony_ci			drm_gem_object_put(a6xx_gpu->sqe_bo);
114262306a36Sopenharmony_ci
114362306a36Sopenharmony_ci			a6xx_gpu->sqe_bo = NULL;
114462306a36Sopenharmony_ci			return -EPERM;
114562306a36Sopenharmony_ci		}
114662306a36Sopenharmony_ci	}
114762306a36Sopenharmony_ci
114862306a36Sopenharmony_ci	/*
114962306a36Sopenharmony_ci	 * Expanded APRIV and targets that support WHERE_AM_I both need a
115062306a36Sopenharmony_ci	 * privileged buffer to store the RPTR shadow
115162306a36Sopenharmony_ci	 */
115262306a36Sopenharmony_ci	if ((adreno_gpu->base.hw_apriv || a6xx_gpu->has_whereami) &&
115362306a36Sopenharmony_ci	    !a6xx_gpu->shadow_bo) {
115462306a36Sopenharmony_ci		a6xx_gpu->shadow = msm_gem_kernel_new(gpu->dev,
115562306a36Sopenharmony_ci						      sizeof(u32) * gpu->nr_rings,
115662306a36Sopenharmony_ci						      MSM_BO_WC | MSM_BO_MAP_PRIV,
115762306a36Sopenharmony_ci						      gpu->aspace, &a6xx_gpu->shadow_bo,
115862306a36Sopenharmony_ci						      &a6xx_gpu->shadow_iova);
115962306a36Sopenharmony_ci
116062306a36Sopenharmony_ci		if (IS_ERR(a6xx_gpu->shadow))
116162306a36Sopenharmony_ci			return PTR_ERR(a6xx_gpu->shadow);
116262306a36Sopenharmony_ci
116362306a36Sopenharmony_ci		msm_gem_object_set_name(a6xx_gpu->shadow_bo, "shadow");
116462306a36Sopenharmony_ci	}
116562306a36Sopenharmony_ci
116662306a36Sopenharmony_ci	return 0;
116762306a36Sopenharmony_ci}
116862306a36Sopenharmony_ci
116962306a36Sopenharmony_cistatic int a6xx_zap_shader_init(struct msm_gpu *gpu)
117062306a36Sopenharmony_ci{
117162306a36Sopenharmony_ci	static bool loaded;
117262306a36Sopenharmony_ci	int ret;
117362306a36Sopenharmony_ci
117462306a36Sopenharmony_ci	if (loaded)
117562306a36Sopenharmony_ci		return 0;
117662306a36Sopenharmony_ci
117762306a36Sopenharmony_ci	ret = adreno_zap_shader_load(gpu, GPU_PAS_ID);
117862306a36Sopenharmony_ci
117962306a36Sopenharmony_ci	loaded = !ret;
118062306a36Sopenharmony_ci	return ret;
118162306a36Sopenharmony_ci}
118262306a36Sopenharmony_ci
118362306a36Sopenharmony_ci#define A6XX_INT_MASK (A6XX_RBBM_INT_0_MASK_CP_AHB_ERROR | \
118462306a36Sopenharmony_ci	  A6XX_RBBM_INT_0_MASK_RBBM_ATB_ASYNCFIFO_OVERFLOW | \
118562306a36Sopenharmony_ci	  A6XX_RBBM_INT_0_MASK_CP_HW_ERROR | \
118662306a36Sopenharmony_ci	  A6XX_RBBM_INT_0_MASK_CP_IB2 | \
118762306a36Sopenharmony_ci	  A6XX_RBBM_INT_0_MASK_CP_IB1 | \
118862306a36Sopenharmony_ci	  A6XX_RBBM_INT_0_MASK_CP_RB | \
118962306a36Sopenharmony_ci	  A6XX_RBBM_INT_0_MASK_CP_CACHE_FLUSH_TS | \
119062306a36Sopenharmony_ci	  A6XX_RBBM_INT_0_MASK_RBBM_ATB_BUS_OVERFLOW | \
119162306a36Sopenharmony_ci	  A6XX_RBBM_INT_0_MASK_RBBM_HANG_DETECT | \
119262306a36Sopenharmony_ci	  A6XX_RBBM_INT_0_MASK_UCHE_OOB_ACCESS | \
119362306a36Sopenharmony_ci	  A6XX_RBBM_INT_0_MASK_UCHE_TRAP_INTR)
119462306a36Sopenharmony_ci
119562306a36Sopenharmony_cistatic int hw_init(struct msm_gpu *gpu)
119662306a36Sopenharmony_ci{
119762306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
119862306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
119962306a36Sopenharmony_ci	struct a6xx_gmu *gmu = &a6xx_gpu->gmu;
120062306a36Sopenharmony_ci	int ret;
120162306a36Sopenharmony_ci
120262306a36Sopenharmony_ci	if (!adreno_has_gmu_wrapper(adreno_gpu)) {
120362306a36Sopenharmony_ci		/* Make sure the GMU keeps the GPU on while we set it up */
120462306a36Sopenharmony_ci		ret = a6xx_gmu_set_oob(&a6xx_gpu->gmu, GMU_OOB_GPU_SET);
120562306a36Sopenharmony_ci		if (ret)
120662306a36Sopenharmony_ci			return ret;
120762306a36Sopenharmony_ci	}
120862306a36Sopenharmony_ci
120962306a36Sopenharmony_ci	/* Clear GBIF halt in case GX domain was not collapsed */
121062306a36Sopenharmony_ci	if (adreno_is_a619_holi(adreno_gpu)) {
121162306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_GBIF_HALT, 0);
121262306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_RBBM_GPR0_CNTL, 0);
121362306a36Sopenharmony_ci		/* Let's make extra sure that the GPU can access the memory.. */
121462306a36Sopenharmony_ci		mb();
121562306a36Sopenharmony_ci	} else if (a6xx_has_gbif(adreno_gpu)) {
121662306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_GBIF_HALT, 0);
121762306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_RBBM_GBIF_HALT, 0);
121862306a36Sopenharmony_ci		/* Let's make extra sure that the GPU can access the memory.. */
121962306a36Sopenharmony_ci		mb();
122062306a36Sopenharmony_ci	}
122162306a36Sopenharmony_ci
122262306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_RBBM_SECVID_TSB_CNTL, 0);
122362306a36Sopenharmony_ci
122462306a36Sopenharmony_ci	if (adreno_is_a619_holi(adreno_gpu))
122562306a36Sopenharmony_ci		a6xx_sptprac_enable(gmu);
122662306a36Sopenharmony_ci
122762306a36Sopenharmony_ci	/*
122862306a36Sopenharmony_ci	 * Disable the trusted memory range - we don't actually supported secure
122962306a36Sopenharmony_ci	 * memory rendering at this point in time and we don't want to block off
123062306a36Sopenharmony_ci	 * part of the virtual memory space.
123162306a36Sopenharmony_ci	 */
123262306a36Sopenharmony_ci	gpu_write64(gpu, REG_A6XX_RBBM_SECVID_TSB_TRUSTED_BASE, 0x00000000);
123362306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_RBBM_SECVID_TSB_TRUSTED_SIZE, 0x00000000);
123462306a36Sopenharmony_ci
123562306a36Sopenharmony_ci	/* Turn on 64 bit addressing for all blocks */
123662306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_CP_ADDR_MODE_CNTL, 0x1);
123762306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_VSC_ADDR_MODE_CNTL, 0x1);
123862306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_GRAS_ADDR_MODE_CNTL, 0x1);
123962306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_RB_ADDR_MODE_CNTL, 0x1);
124062306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_PC_ADDR_MODE_CNTL, 0x1);
124162306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_HLSQ_ADDR_MODE_CNTL, 0x1);
124262306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_VFD_ADDR_MODE_CNTL, 0x1);
124362306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_VPC_ADDR_MODE_CNTL, 0x1);
124462306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_UCHE_ADDR_MODE_CNTL, 0x1);
124562306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_SP_ADDR_MODE_CNTL, 0x1);
124662306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_TPL1_ADDR_MODE_CNTL, 0x1);
124762306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_RBBM_SECVID_TSB_ADDR_MODE_CNTL, 0x1);
124862306a36Sopenharmony_ci
124962306a36Sopenharmony_ci	/* enable hardware clockgating */
125062306a36Sopenharmony_ci	a6xx_set_hwcg(gpu, true);
125162306a36Sopenharmony_ci
125262306a36Sopenharmony_ci	/* VBIF/GBIF start*/
125362306a36Sopenharmony_ci	if (adreno_is_a610(adreno_gpu) ||
125462306a36Sopenharmony_ci	    adreno_is_a640_family(adreno_gpu) ||
125562306a36Sopenharmony_ci	    adreno_is_a650_family(adreno_gpu)) {
125662306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_GBIF_QSB_SIDE0, 0x00071620);
125762306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_GBIF_QSB_SIDE1, 0x00071620);
125862306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_GBIF_QSB_SIDE2, 0x00071620);
125962306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_GBIF_QSB_SIDE3, 0x00071620);
126062306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_RBBM_GBIF_CLIENT_QOS_CNTL, 0x3);
126162306a36Sopenharmony_ci	} else {
126262306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_RBBM_VBIF_CLIENT_QOS_CNTL, 0x3);
126362306a36Sopenharmony_ci	}
126462306a36Sopenharmony_ci
126562306a36Sopenharmony_ci	if (adreno_is_a630(adreno_gpu))
126662306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_VBIF_GATE_OFF_WRREQ_EN, 0x00000009);
126762306a36Sopenharmony_ci
126862306a36Sopenharmony_ci	/* Make all blocks contribute to the GPU BUSY perf counter */
126962306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_RBBM_PERFCTR_GPU_BUSY_MASKED, 0xffffffff);
127062306a36Sopenharmony_ci
127162306a36Sopenharmony_ci	/* Disable L2 bypass in the UCHE */
127262306a36Sopenharmony_ci	gpu_write64(gpu, REG_A6XX_UCHE_WRITE_RANGE_MAX, 0x0001ffffffffffc0llu);
127362306a36Sopenharmony_ci	gpu_write64(gpu, REG_A6XX_UCHE_TRAP_BASE, 0x0001fffffffff000llu);
127462306a36Sopenharmony_ci	gpu_write64(gpu, REG_A6XX_UCHE_WRITE_THRU_BASE, 0x0001fffffffff000llu);
127562306a36Sopenharmony_ci
127662306a36Sopenharmony_ci	if (!adreno_is_a650_family(adreno_gpu)) {
127762306a36Sopenharmony_ci		/* Set the GMEM VA range [0x100000:0x100000 + gpu->gmem - 1] */
127862306a36Sopenharmony_ci		gpu_write64(gpu, REG_A6XX_UCHE_GMEM_RANGE_MIN, 0x00100000);
127962306a36Sopenharmony_ci
128062306a36Sopenharmony_ci		gpu_write64(gpu, REG_A6XX_UCHE_GMEM_RANGE_MAX,
128162306a36Sopenharmony_ci			0x00100000 + adreno_gpu->info->gmem - 1);
128262306a36Sopenharmony_ci	}
128362306a36Sopenharmony_ci
128462306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_UCHE_FILTER_CNTL, 0x804);
128562306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_UCHE_CACHE_WAYS, 0x4);
128662306a36Sopenharmony_ci
128762306a36Sopenharmony_ci	if (adreno_is_a640_family(adreno_gpu) || adreno_is_a650_family(adreno_gpu)) {
128862306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_ROQ_THRESHOLDS_2, 0x02000140);
128962306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_ROQ_THRESHOLDS_1, 0x8040362c);
129062306a36Sopenharmony_ci	} else if (adreno_is_a610(adreno_gpu)) {
129162306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_ROQ_THRESHOLDS_2, 0x00800060);
129262306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_ROQ_THRESHOLDS_1, 0x40201b16);
129362306a36Sopenharmony_ci	} else {
129462306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_ROQ_THRESHOLDS_2, 0x010000c0);
129562306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_ROQ_THRESHOLDS_1, 0x8040362c);
129662306a36Sopenharmony_ci	}
129762306a36Sopenharmony_ci
129862306a36Sopenharmony_ci	if (adreno_is_a660_family(adreno_gpu))
129962306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_LPAC_PROG_FIFO_SIZE, 0x00000020);
130062306a36Sopenharmony_ci
130162306a36Sopenharmony_ci	/* Setting the mem pool size */
130262306a36Sopenharmony_ci	if (adreno_is_a610(adreno_gpu)) {
130362306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_MEM_POOL_SIZE, 48);
130462306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_MEM_POOL_DBG_ADDR, 47);
130562306a36Sopenharmony_ci	} else
130662306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_MEM_POOL_SIZE, 128);
130762306a36Sopenharmony_ci
130862306a36Sopenharmony_ci	/* Setting the primFifo thresholds default values,
130962306a36Sopenharmony_ci	 * and vccCacheSkipDis=1 bit (0x200) for A640 and newer
131062306a36Sopenharmony_ci	*/
131162306a36Sopenharmony_ci	if (adreno_is_a650(adreno_gpu) || adreno_is_a660(adreno_gpu) || adreno_is_a690(adreno_gpu))
131262306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_PC_DBG_ECO_CNTL, 0x00300200);
131362306a36Sopenharmony_ci	else if (adreno_is_a640_family(adreno_gpu) || adreno_is_7c3(adreno_gpu))
131462306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_PC_DBG_ECO_CNTL, 0x00200200);
131562306a36Sopenharmony_ci	else if (adreno_is_a650(adreno_gpu) || adreno_is_a660(adreno_gpu))
131662306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_PC_DBG_ECO_CNTL, 0x00300200);
131762306a36Sopenharmony_ci	else if (adreno_is_a619(adreno_gpu))
131862306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_PC_DBG_ECO_CNTL, 0x00018000);
131962306a36Sopenharmony_ci	else if (adreno_is_a610(adreno_gpu))
132062306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_PC_DBG_ECO_CNTL, 0x00080000);
132162306a36Sopenharmony_ci	else
132262306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_PC_DBG_ECO_CNTL, 0x00180000);
132362306a36Sopenharmony_ci
132462306a36Sopenharmony_ci	/* Set the AHB default slave response to "ERROR" */
132562306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_CP_AHB_CNTL, 0x1);
132662306a36Sopenharmony_ci
132762306a36Sopenharmony_ci	/* Turn on performance counters */
132862306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_RBBM_PERFCTR_CNTL, 0x1);
132962306a36Sopenharmony_ci
133062306a36Sopenharmony_ci	/* Select CP0 to always count cycles */
133162306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_CP_PERFCTR_CP_SEL(0), PERF_CP_ALWAYS_COUNT);
133262306a36Sopenharmony_ci
133362306a36Sopenharmony_ci	a6xx_set_ubwc_config(gpu);
133462306a36Sopenharmony_ci
133562306a36Sopenharmony_ci	/* Enable fault detection */
133662306a36Sopenharmony_ci	if (adreno_is_a619(adreno_gpu))
133762306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_RBBM_INTERFACE_HANG_INT_CNTL, (1 << 30) | 0x3fffff);
133862306a36Sopenharmony_ci	else if (adreno_is_a610(adreno_gpu))
133962306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_RBBM_INTERFACE_HANG_INT_CNTL, (1 << 30) | 0x3ffff);
134062306a36Sopenharmony_ci	else
134162306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_RBBM_INTERFACE_HANG_INT_CNTL, (1 << 30) | 0x1fffff);
134262306a36Sopenharmony_ci
134362306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_UCHE_CLIENT_PF, 1);
134462306a36Sopenharmony_ci
134562306a36Sopenharmony_ci	/* Set weights for bicubic filtering */
134662306a36Sopenharmony_ci	if (adreno_is_a650_family(adreno_gpu)) {
134762306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_0, 0);
134862306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_1,
134962306a36Sopenharmony_ci			0x3fe05ff4);
135062306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_2,
135162306a36Sopenharmony_ci			0x3fa0ebee);
135262306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_3,
135362306a36Sopenharmony_ci			0x3f5193ed);
135462306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_4,
135562306a36Sopenharmony_ci			0x3f0243f0);
135662306a36Sopenharmony_ci	}
135762306a36Sopenharmony_ci
135862306a36Sopenharmony_ci	/* Set up the CX GMU counter 0 to count busy ticks */
135962306a36Sopenharmony_ci	gmu_write(gmu, REG_A6XX_GPU_GMU_AO_GPU_CX_BUSY_MASK, 0xff000000);
136062306a36Sopenharmony_ci
136162306a36Sopenharmony_ci	/* Enable the power counter */
136262306a36Sopenharmony_ci	gmu_rmw(gmu, REG_A6XX_GMU_CX_GMU_POWER_COUNTER_SELECT_0, 0xff, BIT(5));
136362306a36Sopenharmony_ci	gmu_write(gmu, REG_A6XX_GMU_CX_GMU_POWER_COUNTER_ENABLE, 1);
136462306a36Sopenharmony_ci
136562306a36Sopenharmony_ci	/* Protect registers from the CP */
136662306a36Sopenharmony_ci	a6xx_set_cp_protect(gpu);
136762306a36Sopenharmony_ci
136862306a36Sopenharmony_ci	if (adreno_is_a660_family(adreno_gpu)) {
136962306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_CHICKEN_DBG, 0x1);
137062306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_RBBM_GBIF_CLIENT_QOS_CNTL, 0x0);
137162306a36Sopenharmony_ci	}
137262306a36Sopenharmony_ci
137362306a36Sopenharmony_ci	/* Set dualQ + disable afull for A660 GPU */
137462306a36Sopenharmony_ci	if (adreno_is_a660(adreno_gpu))
137562306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_UCHE_CMDQ_CONFIG, 0x66906);
137662306a36Sopenharmony_ci
137762306a36Sopenharmony_ci	/* Enable expanded apriv for targets that support it */
137862306a36Sopenharmony_ci	if (gpu->hw_apriv) {
137962306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_APRIV_CNTL,
138062306a36Sopenharmony_ci			(1 << 6) | (1 << 5) | (1 << 3) | (1 << 2) | (1 << 1));
138162306a36Sopenharmony_ci	}
138262306a36Sopenharmony_ci
138362306a36Sopenharmony_ci	/* Enable interrupts */
138462306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_RBBM_INT_0_MASK, A6XX_INT_MASK);
138562306a36Sopenharmony_ci
138662306a36Sopenharmony_ci	ret = adreno_hw_init(gpu);
138762306a36Sopenharmony_ci	if (ret)
138862306a36Sopenharmony_ci		goto out;
138962306a36Sopenharmony_ci
139062306a36Sopenharmony_ci	gpu_write64(gpu, REG_A6XX_CP_SQE_INSTR_BASE, a6xx_gpu->sqe_iova);
139162306a36Sopenharmony_ci
139262306a36Sopenharmony_ci	/* Set the ringbuffer address */
139362306a36Sopenharmony_ci	gpu_write64(gpu, REG_A6XX_CP_RB_BASE, gpu->rb[0]->iova);
139462306a36Sopenharmony_ci
139562306a36Sopenharmony_ci	/* Targets that support extended APRIV can use the RPTR shadow from
139662306a36Sopenharmony_ci	 * hardware but all the other ones need to disable the feature. Targets
139762306a36Sopenharmony_ci	 * that support the WHERE_AM_I opcode can use that instead
139862306a36Sopenharmony_ci	 */
139962306a36Sopenharmony_ci	if (adreno_gpu->base.hw_apriv)
140062306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_RB_CNTL, MSM_GPU_RB_CNTL_DEFAULT);
140162306a36Sopenharmony_ci	else
140262306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_RB_CNTL,
140362306a36Sopenharmony_ci			MSM_GPU_RB_CNTL_DEFAULT | AXXX_CP_RB_CNTL_NO_UPDATE);
140462306a36Sopenharmony_ci
140562306a36Sopenharmony_ci	/* Configure the RPTR shadow if needed: */
140662306a36Sopenharmony_ci	if (a6xx_gpu->shadow_bo) {
140762306a36Sopenharmony_ci		gpu_write64(gpu, REG_A6XX_CP_RB_RPTR_ADDR,
140862306a36Sopenharmony_ci			shadowptr(a6xx_gpu, gpu->rb[0]));
140962306a36Sopenharmony_ci	}
141062306a36Sopenharmony_ci
141162306a36Sopenharmony_ci	/* Always come up on rb 0 */
141262306a36Sopenharmony_ci	a6xx_gpu->cur_ring = gpu->rb[0];
141362306a36Sopenharmony_ci
141462306a36Sopenharmony_ci	gpu->cur_ctx_seqno = 0;
141562306a36Sopenharmony_ci
141662306a36Sopenharmony_ci	/* Enable the SQE_to start the CP engine */
141762306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_CP_SQE_CNTL, 1);
141862306a36Sopenharmony_ci
141962306a36Sopenharmony_ci	ret = a6xx_cp_init(gpu);
142062306a36Sopenharmony_ci	if (ret)
142162306a36Sopenharmony_ci		goto out;
142262306a36Sopenharmony_ci
142362306a36Sopenharmony_ci	/*
142462306a36Sopenharmony_ci	 * Try to load a zap shader into the secure world. If successful
142562306a36Sopenharmony_ci	 * we can use the CP to switch out of secure mode. If not then we
142662306a36Sopenharmony_ci	 * have no resource but to try to switch ourselves out manually. If we
142762306a36Sopenharmony_ci	 * guessed wrong then access to the RBBM_SECVID_TRUST_CNTL register will
142862306a36Sopenharmony_ci	 * be blocked and a permissions violation will soon follow.
142962306a36Sopenharmony_ci	 */
143062306a36Sopenharmony_ci	ret = a6xx_zap_shader_init(gpu);
143162306a36Sopenharmony_ci	if (!ret) {
143262306a36Sopenharmony_ci		OUT_PKT7(gpu->rb[0], CP_SET_SECURE_MODE, 1);
143362306a36Sopenharmony_ci		OUT_RING(gpu->rb[0], 0x00000000);
143462306a36Sopenharmony_ci
143562306a36Sopenharmony_ci		a6xx_flush(gpu, gpu->rb[0]);
143662306a36Sopenharmony_ci		if (!a6xx_idle(gpu, gpu->rb[0]))
143762306a36Sopenharmony_ci			return -EINVAL;
143862306a36Sopenharmony_ci	} else if (ret == -ENODEV) {
143962306a36Sopenharmony_ci		/*
144062306a36Sopenharmony_ci		 * This device does not use zap shader (but print a warning
144162306a36Sopenharmony_ci		 * just in case someone got their dt wrong.. hopefully they
144262306a36Sopenharmony_ci		 * have a debug UART to realize the error of their ways...
144362306a36Sopenharmony_ci		 * if you mess this up you are about to crash horribly)
144462306a36Sopenharmony_ci		 */
144562306a36Sopenharmony_ci		dev_warn_once(gpu->dev->dev,
144662306a36Sopenharmony_ci			"Zap shader not enabled - using SECVID_TRUST_CNTL instead\n");
144762306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_RBBM_SECVID_TRUST_CNTL, 0x0);
144862306a36Sopenharmony_ci		ret = 0;
144962306a36Sopenharmony_ci	} else {
145062306a36Sopenharmony_ci		return ret;
145162306a36Sopenharmony_ci	}
145262306a36Sopenharmony_ci
145362306a36Sopenharmony_ciout:
145462306a36Sopenharmony_ci	if (adreno_has_gmu_wrapper(adreno_gpu))
145562306a36Sopenharmony_ci		return ret;
145662306a36Sopenharmony_ci	/*
145762306a36Sopenharmony_ci	 * Tell the GMU that we are done touching the GPU and it can start power
145862306a36Sopenharmony_ci	 * management
145962306a36Sopenharmony_ci	 */
146062306a36Sopenharmony_ci	a6xx_gmu_clear_oob(&a6xx_gpu->gmu, GMU_OOB_GPU_SET);
146162306a36Sopenharmony_ci
146262306a36Sopenharmony_ci	if (a6xx_gpu->gmu.legacy) {
146362306a36Sopenharmony_ci		/* Take the GMU out of its special boot mode */
146462306a36Sopenharmony_ci		a6xx_gmu_clear_oob(&a6xx_gpu->gmu, GMU_OOB_BOOT_SLUMBER);
146562306a36Sopenharmony_ci	}
146662306a36Sopenharmony_ci
146762306a36Sopenharmony_ci	return ret;
146862306a36Sopenharmony_ci}
146962306a36Sopenharmony_ci
147062306a36Sopenharmony_cistatic int a6xx_hw_init(struct msm_gpu *gpu)
147162306a36Sopenharmony_ci{
147262306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
147362306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
147462306a36Sopenharmony_ci	int ret;
147562306a36Sopenharmony_ci
147662306a36Sopenharmony_ci	mutex_lock(&a6xx_gpu->gmu.lock);
147762306a36Sopenharmony_ci	ret = hw_init(gpu);
147862306a36Sopenharmony_ci	mutex_unlock(&a6xx_gpu->gmu.lock);
147962306a36Sopenharmony_ci
148062306a36Sopenharmony_ci	return ret;
148162306a36Sopenharmony_ci}
148262306a36Sopenharmony_ci
148362306a36Sopenharmony_cistatic void a6xx_dump(struct msm_gpu *gpu)
148462306a36Sopenharmony_ci{
148562306a36Sopenharmony_ci	DRM_DEV_INFO(&gpu->pdev->dev, "status:   %08x\n",
148662306a36Sopenharmony_ci			gpu_read(gpu, REG_A6XX_RBBM_STATUS));
148762306a36Sopenharmony_ci	adreno_dump(gpu);
148862306a36Sopenharmony_ci}
148962306a36Sopenharmony_ci
149062306a36Sopenharmony_cistatic void a6xx_recover(struct msm_gpu *gpu)
149162306a36Sopenharmony_ci{
149262306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
149362306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
149462306a36Sopenharmony_ci	struct a6xx_gmu *gmu = &a6xx_gpu->gmu;
149562306a36Sopenharmony_ci	int i, active_submits;
149662306a36Sopenharmony_ci
149762306a36Sopenharmony_ci	adreno_dump_info(gpu);
149862306a36Sopenharmony_ci
149962306a36Sopenharmony_ci	for (i = 0; i < 8; i++)
150062306a36Sopenharmony_ci		DRM_DEV_INFO(&gpu->pdev->dev, "CP_SCRATCH_REG%d: %u\n", i,
150162306a36Sopenharmony_ci			gpu_read(gpu, REG_A6XX_CP_SCRATCH_REG(i)));
150262306a36Sopenharmony_ci
150362306a36Sopenharmony_ci	if (hang_debug)
150462306a36Sopenharmony_ci		a6xx_dump(gpu);
150562306a36Sopenharmony_ci
150662306a36Sopenharmony_ci	/*
150762306a36Sopenharmony_ci	 * To handle recovery specific sequences during the rpm suspend we are
150862306a36Sopenharmony_ci	 * about to trigger
150962306a36Sopenharmony_ci	 */
151062306a36Sopenharmony_ci	a6xx_gpu->hung = true;
151162306a36Sopenharmony_ci
151262306a36Sopenharmony_ci	/* Halt SQE first */
151362306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_CP_SQE_CNTL, 3);
151462306a36Sopenharmony_ci
151562306a36Sopenharmony_ci	pm_runtime_dont_use_autosuspend(&gpu->pdev->dev);
151662306a36Sopenharmony_ci
151762306a36Sopenharmony_ci	/* active_submit won't change until we make a submission */
151862306a36Sopenharmony_ci	mutex_lock(&gpu->active_lock);
151962306a36Sopenharmony_ci	active_submits = gpu->active_submits;
152062306a36Sopenharmony_ci
152162306a36Sopenharmony_ci	/*
152262306a36Sopenharmony_ci	 * Temporarily clear active_submits count to silence a WARN() in the
152362306a36Sopenharmony_ci	 * runtime suspend cb
152462306a36Sopenharmony_ci	 */
152562306a36Sopenharmony_ci	gpu->active_submits = 0;
152662306a36Sopenharmony_ci
152762306a36Sopenharmony_ci	if (adreno_has_gmu_wrapper(adreno_gpu)) {
152862306a36Sopenharmony_ci		/* Drain the outstanding traffic on memory buses */
152962306a36Sopenharmony_ci		a6xx_bus_clear_pending_transactions(adreno_gpu, true);
153062306a36Sopenharmony_ci
153162306a36Sopenharmony_ci		/* Reset the GPU to a clean state */
153262306a36Sopenharmony_ci		a6xx_gpu_sw_reset(gpu, true);
153362306a36Sopenharmony_ci		a6xx_gpu_sw_reset(gpu, false);
153462306a36Sopenharmony_ci	}
153562306a36Sopenharmony_ci
153662306a36Sopenharmony_ci	reinit_completion(&gmu->pd_gate);
153762306a36Sopenharmony_ci	dev_pm_genpd_add_notifier(gmu->cxpd, &gmu->pd_nb);
153862306a36Sopenharmony_ci	dev_pm_genpd_synced_poweroff(gmu->cxpd);
153962306a36Sopenharmony_ci
154062306a36Sopenharmony_ci	/* Drop the rpm refcount from active submits */
154162306a36Sopenharmony_ci	if (active_submits)
154262306a36Sopenharmony_ci		pm_runtime_put(&gpu->pdev->dev);
154362306a36Sopenharmony_ci
154462306a36Sopenharmony_ci	/* And the final one from recover worker */
154562306a36Sopenharmony_ci	pm_runtime_put_sync(&gpu->pdev->dev);
154662306a36Sopenharmony_ci
154762306a36Sopenharmony_ci	if (!wait_for_completion_timeout(&gmu->pd_gate, msecs_to_jiffies(1000)))
154862306a36Sopenharmony_ci		DRM_DEV_ERROR(&gpu->pdev->dev, "cx gdsc didn't collapse\n");
154962306a36Sopenharmony_ci
155062306a36Sopenharmony_ci	dev_pm_genpd_remove_notifier(gmu->cxpd);
155162306a36Sopenharmony_ci
155262306a36Sopenharmony_ci	pm_runtime_use_autosuspend(&gpu->pdev->dev);
155362306a36Sopenharmony_ci
155462306a36Sopenharmony_ci	if (active_submits)
155562306a36Sopenharmony_ci		pm_runtime_get(&gpu->pdev->dev);
155662306a36Sopenharmony_ci
155762306a36Sopenharmony_ci	pm_runtime_get_sync(&gpu->pdev->dev);
155862306a36Sopenharmony_ci
155962306a36Sopenharmony_ci	gpu->active_submits = active_submits;
156062306a36Sopenharmony_ci	mutex_unlock(&gpu->active_lock);
156162306a36Sopenharmony_ci
156262306a36Sopenharmony_ci	msm_gpu_hw_init(gpu);
156362306a36Sopenharmony_ci	a6xx_gpu->hung = false;
156462306a36Sopenharmony_ci}
156562306a36Sopenharmony_ci
156662306a36Sopenharmony_cistatic const char *a6xx_uche_fault_block(struct msm_gpu *gpu, u32 mid)
156762306a36Sopenharmony_ci{
156862306a36Sopenharmony_ci	static const char *uche_clients[7] = {
156962306a36Sopenharmony_ci		"VFD", "SP", "VSC", "VPC", "HLSQ", "PC", "LRZ",
157062306a36Sopenharmony_ci	};
157162306a36Sopenharmony_ci	u32 val;
157262306a36Sopenharmony_ci
157362306a36Sopenharmony_ci	if (mid < 1 || mid > 3)
157462306a36Sopenharmony_ci		return "UNKNOWN";
157562306a36Sopenharmony_ci
157662306a36Sopenharmony_ci	/*
157762306a36Sopenharmony_ci	 * The source of the data depends on the mid ID read from FSYNR1.
157862306a36Sopenharmony_ci	 * and the client ID read from the UCHE block
157962306a36Sopenharmony_ci	 */
158062306a36Sopenharmony_ci	val = gpu_read(gpu, REG_A6XX_UCHE_CLIENT_PF);
158162306a36Sopenharmony_ci
158262306a36Sopenharmony_ci	/* mid = 3 is most precise and refers to only one block per client */
158362306a36Sopenharmony_ci	if (mid == 3)
158462306a36Sopenharmony_ci		return uche_clients[val & 7];
158562306a36Sopenharmony_ci
158662306a36Sopenharmony_ci	/* For mid=2 the source is TP or VFD except when the client id is 0 */
158762306a36Sopenharmony_ci	if (mid == 2)
158862306a36Sopenharmony_ci		return ((val & 7) == 0) ? "TP" : "TP|VFD";
158962306a36Sopenharmony_ci
159062306a36Sopenharmony_ci	/* For mid=1 just return "UCHE" as a catchall for everything else */
159162306a36Sopenharmony_ci	return "UCHE";
159262306a36Sopenharmony_ci}
159362306a36Sopenharmony_ci
159462306a36Sopenharmony_cistatic const char *a6xx_fault_block(struct msm_gpu *gpu, u32 id)
159562306a36Sopenharmony_ci{
159662306a36Sopenharmony_ci	if (id == 0)
159762306a36Sopenharmony_ci		return "CP";
159862306a36Sopenharmony_ci	else if (id == 4)
159962306a36Sopenharmony_ci		return "CCU";
160062306a36Sopenharmony_ci	else if (id == 6)
160162306a36Sopenharmony_ci		return "CDP Prefetch";
160262306a36Sopenharmony_ci
160362306a36Sopenharmony_ci	return a6xx_uche_fault_block(gpu, id);
160462306a36Sopenharmony_ci}
160562306a36Sopenharmony_ci
160662306a36Sopenharmony_cistatic int a6xx_fault_handler(void *arg, unsigned long iova, int flags, void *data)
160762306a36Sopenharmony_ci{
160862306a36Sopenharmony_ci	struct msm_gpu *gpu = arg;
160962306a36Sopenharmony_ci	struct adreno_smmu_fault_info *info = data;
161062306a36Sopenharmony_ci	const char *block = "unknown";
161162306a36Sopenharmony_ci
161262306a36Sopenharmony_ci	u32 scratch[] = {
161362306a36Sopenharmony_ci			gpu_read(gpu, REG_A6XX_CP_SCRATCH_REG(4)),
161462306a36Sopenharmony_ci			gpu_read(gpu, REG_A6XX_CP_SCRATCH_REG(5)),
161562306a36Sopenharmony_ci			gpu_read(gpu, REG_A6XX_CP_SCRATCH_REG(6)),
161662306a36Sopenharmony_ci			gpu_read(gpu, REG_A6XX_CP_SCRATCH_REG(7)),
161762306a36Sopenharmony_ci	};
161862306a36Sopenharmony_ci
161962306a36Sopenharmony_ci	if (info)
162062306a36Sopenharmony_ci		block = a6xx_fault_block(gpu, info->fsynr1 & 0xff);
162162306a36Sopenharmony_ci
162262306a36Sopenharmony_ci	return adreno_fault_handler(gpu, iova, flags, info, block, scratch);
162362306a36Sopenharmony_ci}
162462306a36Sopenharmony_ci
162562306a36Sopenharmony_cistatic void a6xx_cp_hw_err_irq(struct msm_gpu *gpu)
162662306a36Sopenharmony_ci{
162762306a36Sopenharmony_ci	u32 status = gpu_read(gpu, REG_A6XX_CP_INTERRUPT_STATUS);
162862306a36Sopenharmony_ci
162962306a36Sopenharmony_ci	if (status & A6XX_CP_INT_CP_OPCODE_ERROR) {
163062306a36Sopenharmony_ci		u32 val;
163162306a36Sopenharmony_ci
163262306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_CP_SQE_STAT_ADDR, 1);
163362306a36Sopenharmony_ci		val = gpu_read(gpu, REG_A6XX_CP_SQE_STAT_DATA);
163462306a36Sopenharmony_ci		dev_err_ratelimited(&gpu->pdev->dev,
163562306a36Sopenharmony_ci			"CP | opcode error | possible opcode=0x%8.8X\n",
163662306a36Sopenharmony_ci			val);
163762306a36Sopenharmony_ci	}
163862306a36Sopenharmony_ci
163962306a36Sopenharmony_ci	if (status & A6XX_CP_INT_CP_UCODE_ERROR)
164062306a36Sopenharmony_ci		dev_err_ratelimited(&gpu->pdev->dev,
164162306a36Sopenharmony_ci			"CP ucode error interrupt\n");
164262306a36Sopenharmony_ci
164362306a36Sopenharmony_ci	if (status & A6XX_CP_INT_CP_HW_FAULT_ERROR)
164462306a36Sopenharmony_ci		dev_err_ratelimited(&gpu->pdev->dev, "CP | HW fault | status=0x%8.8X\n",
164562306a36Sopenharmony_ci			gpu_read(gpu, REG_A6XX_CP_HW_FAULT));
164662306a36Sopenharmony_ci
164762306a36Sopenharmony_ci	if (status & A6XX_CP_INT_CP_REGISTER_PROTECTION_ERROR) {
164862306a36Sopenharmony_ci		u32 val = gpu_read(gpu, REG_A6XX_CP_PROTECT_STATUS);
164962306a36Sopenharmony_ci
165062306a36Sopenharmony_ci		dev_err_ratelimited(&gpu->pdev->dev,
165162306a36Sopenharmony_ci			"CP | protected mode error | %s | addr=0x%8.8X | status=0x%8.8X\n",
165262306a36Sopenharmony_ci			val & (1 << 20) ? "READ" : "WRITE",
165362306a36Sopenharmony_ci			(val & 0x3ffff), val);
165462306a36Sopenharmony_ci	}
165562306a36Sopenharmony_ci
165662306a36Sopenharmony_ci	if (status & A6XX_CP_INT_CP_AHB_ERROR)
165762306a36Sopenharmony_ci		dev_err_ratelimited(&gpu->pdev->dev, "CP AHB error interrupt\n");
165862306a36Sopenharmony_ci
165962306a36Sopenharmony_ci	if (status & A6XX_CP_INT_CP_VSD_PARITY_ERROR)
166062306a36Sopenharmony_ci		dev_err_ratelimited(&gpu->pdev->dev, "CP VSD decoder parity error\n");
166162306a36Sopenharmony_ci
166262306a36Sopenharmony_ci	if (status & A6XX_CP_INT_CP_ILLEGAL_INSTR_ERROR)
166362306a36Sopenharmony_ci		dev_err_ratelimited(&gpu->pdev->dev, "CP illegal instruction error\n");
166462306a36Sopenharmony_ci
166562306a36Sopenharmony_ci}
166662306a36Sopenharmony_ci
166762306a36Sopenharmony_cistatic void a6xx_fault_detect_irq(struct msm_gpu *gpu)
166862306a36Sopenharmony_ci{
166962306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
167062306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
167162306a36Sopenharmony_ci	struct msm_ringbuffer *ring = gpu->funcs->active_ring(gpu);
167262306a36Sopenharmony_ci
167362306a36Sopenharmony_ci	/*
167462306a36Sopenharmony_ci	 * If stalled on SMMU fault, we could trip the GPU's hang detection,
167562306a36Sopenharmony_ci	 * but the fault handler will trigger the devcore dump, and we want
167662306a36Sopenharmony_ci	 * to otherwise resume normally rather than killing the submit, so
167762306a36Sopenharmony_ci	 * just bail.
167862306a36Sopenharmony_ci	 */
167962306a36Sopenharmony_ci	if (gpu_read(gpu, REG_A6XX_RBBM_STATUS3) & A6XX_RBBM_STATUS3_SMMU_STALLED_ON_FAULT)
168062306a36Sopenharmony_ci		return;
168162306a36Sopenharmony_ci
168262306a36Sopenharmony_ci	/*
168362306a36Sopenharmony_ci	 * Force the GPU to stay on until after we finish
168462306a36Sopenharmony_ci	 * collecting information
168562306a36Sopenharmony_ci	 */
168662306a36Sopenharmony_ci	if (!adreno_has_gmu_wrapper(adreno_gpu))
168762306a36Sopenharmony_ci		gmu_write(&a6xx_gpu->gmu, REG_A6XX_GMU_GMU_PWR_COL_KEEPALIVE, 1);
168862306a36Sopenharmony_ci
168962306a36Sopenharmony_ci	DRM_DEV_ERROR(&gpu->pdev->dev,
169062306a36Sopenharmony_ci		"gpu fault ring %d fence %x status %8.8X rb %4.4x/%4.4x ib1 %16.16llX/%4.4x ib2 %16.16llX/%4.4x\n",
169162306a36Sopenharmony_ci		ring ? ring->id : -1, ring ? ring->fctx->last_fence : 0,
169262306a36Sopenharmony_ci		gpu_read(gpu, REG_A6XX_RBBM_STATUS),
169362306a36Sopenharmony_ci		gpu_read(gpu, REG_A6XX_CP_RB_RPTR),
169462306a36Sopenharmony_ci		gpu_read(gpu, REG_A6XX_CP_RB_WPTR),
169562306a36Sopenharmony_ci		gpu_read64(gpu, REG_A6XX_CP_IB1_BASE),
169662306a36Sopenharmony_ci		gpu_read(gpu, REG_A6XX_CP_IB1_REM_SIZE),
169762306a36Sopenharmony_ci		gpu_read64(gpu, REG_A6XX_CP_IB2_BASE),
169862306a36Sopenharmony_ci		gpu_read(gpu, REG_A6XX_CP_IB2_REM_SIZE));
169962306a36Sopenharmony_ci
170062306a36Sopenharmony_ci	/* Turn off the hangcheck timer to keep it from bothering us */
170162306a36Sopenharmony_ci	del_timer(&gpu->hangcheck_timer);
170262306a36Sopenharmony_ci
170362306a36Sopenharmony_ci	kthread_queue_work(gpu->worker, &gpu->recover_work);
170462306a36Sopenharmony_ci}
170562306a36Sopenharmony_ci
170662306a36Sopenharmony_cistatic irqreturn_t a6xx_irq(struct msm_gpu *gpu)
170762306a36Sopenharmony_ci{
170862306a36Sopenharmony_ci	struct msm_drm_private *priv = gpu->dev->dev_private;
170962306a36Sopenharmony_ci	u32 status = gpu_read(gpu, REG_A6XX_RBBM_INT_0_STATUS);
171062306a36Sopenharmony_ci
171162306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_RBBM_INT_CLEAR_CMD, status);
171262306a36Sopenharmony_ci
171362306a36Sopenharmony_ci	if (priv->disable_err_irq)
171462306a36Sopenharmony_ci		status &= A6XX_RBBM_INT_0_MASK_CP_CACHE_FLUSH_TS;
171562306a36Sopenharmony_ci
171662306a36Sopenharmony_ci	if (status & A6XX_RBBM_INT_0_MASK_RBBM_HANG_DETECT)
171762306a36Sopenharmony_ci		a6xx_fault_detect_irq(gpu);
171862306a36Sopenharmony_ci
171962306a36Sopenharmony_ci	if (status & A6XX_RBBM_INT_0_MASK_CP_AHB_ERROR)
172062306a36Sopenharmony_ci		dev_err_ratelimited(&gpu->pdev->dev, "CP | AHB bus error\n");
172162306a36Sopenharmony_ci
172262306a36Sopenharmony_ci	if (status & A6XX_RBBM_INT_0_MASK_CP_HW_ERROR)
172362306a36Sopenharmony_ci		a6xx_cp_hw_err_irq(gpu);
172462306a36Sopenharmony_ci
172562306a36Sopenharmony_ci	if (status & A6XX_RBBM_INT_0_MASK_RBBM_ATB_ASYNCFIFO_OVERFLOW)
172662306a36Sopenharmony_ci		dev_err_ratelimited(&gpu->pdev->dev, "RBBM | ATB ASYNC overflow\n");
172762306a36Sopenharmony_ci
172862306a36Sopenharmony_ci	if (status & A6XX_RBBM_INT_0_MASK_RBBM_ATB_BUS_OVERFLOW)
172962306a36Sopenharmony_ci		dev_err_ratelimited(&gpu->pdev->dev, "RBBM | ATB bus overflow\n");
173062306a36Sopenharmony_ci
173162306a36Sopenharmony_ci	if (status & A6XX_RBBM_INT_0_MASK_UCHE_OOB_ACCESS)
173262306a36Sopenharmony_ci		dev_err_ratelimited(&gpu->pdev->dev, "UCHE | Out of bounds access\n");
173362306a36Sopenharmony_ci
173462306a36Sopenharmony_ci	if (status & A6XX_RBBM_INT_0_MASK_CP_CACHE_FLUSH_TS)
173562306a36Sopenharmony_ci		msm_gpu_retire(gpu);
173662306a36Sopenharmony_ci
173762306a36Sopenharmony_ci	return IRQ_HANDLED;
173862306a36Sopenharmony_ci}
173962306a36Sopenharmony_ci
174062306a36Sopenharmony_cistatic void a6xx_llc_deactivate(struct a6xx_gpu *a6xx_gpu)
174162306a36Sopenharmony_ci{
174262306a36Sopenharmony_ci	llcc_slice_deactivate(a6xx_gpu->llc_slice);
174362306a36Sopenharmony_ci	llcc_slice_deactivate(a6xx_gpu->htw_llc_slice);
174462306a36Sopenharmony_ci}
174562306a36Sopenharmony_ci
174662306a36Sopenharmony_cistatic void a6xx_llc_activate(struct a6xx_gpu *a6xx_gpu)
174762306a36Sopenharmony_ci{
174862306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = &a6xx_gpu->base;
174962306a36Sopenharmony_ci	struct msm_gpu *gpu = &adreno_gpu->base;
175062306a36Sopenharmony_ci	u32 cntl1_regval = 0;
175162306a36Sopenharmony_ci
175262306a36Sopenharmony_ci	if (IS_ERR(a6xx_gpu->llc_mmio))
175362306a36Sopenharmony_ci		return;
175462306a36Sopenharmony_ci
175562306a36Sopenharmony_ci	if (!llcc_slice_activate(a6xx_gpu->llc_slice)) {
175662306a36Sopenharmony_ci		u32 gpu_scid = llcc_get_slice_id(a6xx_gpu->llc_slice);
175762306a36Sopenharmony_ci
175862306a36Sopenharmony_ci		gpu_scid &= 0x1f;
175962306a36Sopenharmony_ci		cntl1_regval = (gpu_scid << 0) | (gpu_scid << 5) | (gpu_scid << 10) |
176062306a36Sopenharmony_ci			       (gpu_scid << 15) | (gpu_scid << 20);
176162306a36Sopenharmony_ci
176262306a36Sopenharmony_ci		/* On A660, the SCID programming for UCHE traffic is done in
176362306a36Sopenharmony_ci		 * A6XX_GBIF_SCACHE_CNTL0[14:10]
176462306a36Sopenharmony_ci		 */
176562306a36Sopenharmony_ci		if (adreno_is_a660_family(adreno_gpu))
176662306a36Sopenharmony_ci			gpu_rmw(gpu, REG_A6XX_GBIF_SCACHE_CNTL0, (0x1f << 10) |
176762306a36Sopenharmony_ci				(1 << 8), (gpu_scid << 10) | (1 << 8));
176862306a36Sopenharmony_ci	}
176962306a36Sopenharmony_ci
177062306a36Sopenharmony_ci	/*
177162306a36Sopenharmony_ci	 * For targets with a MMU500, activate the slice but don't program the
177262306a36Sopenharmony_ci	 * register.  The XBL will take care of that.
177362306a36Sopenharmony_ci	 */
177462306a36Sopenharmony_ci	if (!llcc_slice_activate(a6xx_gpu->htw_llc_slice)) {
177562306a36Sopenharmony_ci		if (!a6xx_gpu->have_mmu500) {
177662306a36Sopenharmony_ci			u32 gpuhtw_scid = llcc_get_slice_id(a6xx_gpu->htw_llc_slice);
177762306a36Sopenharmony_ci
177862306a36Sopenharmony_ci			gpuhtw_scid &= 0x1f;
177962306a36Sopenharmony_ci			cntl1_regval |= FIELD_PREP(GENMASK(29, 25), gpuhtw_scid);
178062306a36Sopenharmony_ci		}
178162306a36Sopenharmony_ci	}
178262306a36Sopenharmony_ci
178362306a36Sopenharmony_ci	if (!cntl1_regval)
178462306a36Sopenharmony_ci		return;
178562306a36Sopenharmony_ci
178662306a36Sopenharmony_ci	/*
178762306a36Sopenharmony_ci	 * Program the slice IDs for the various GPU blocks and GPU MMU
178862306a36Sopenharmony_ci	 * pagetables
178962306a36Sopenharmony_ci	 */
179062306a36Sopenharmony_ci	if (!a6xx_gpu->have_mmu500) {
179162306a36Sopenharmony_ci		a6xx_llc_write(a6xx_gpu,
179262306a36Sopenharmony_ci			REG_A6XX_CX_MISC_SYSTEM_CACHE_CNTL_1, cntl1_regval);
179362306a36Sopenharmony_ci
179462306a36Sopenharmony_ci		/*
179562306a36Sopenharmony_ci		 * Program cacheability overrides to not allocate cache
179662306a36Sopenharmony_ci		 * lines on a write miss
179762306a36Sopenharmony_ci		 */
179862306a36Sopenharmony_ci		a6xx_llc_rmw(a6xx_gpu,
179962306a36Sopenharmony_ci			REG_A6XX_CX_MISC_SYSTEM_CACHE_CNTL_0, 0xF, 0x03);
180062306a36Sopenharmony_ci		return;
180162306a36Sopenharmony_ci	}
180262306a36Sopenharmony_ci
180362306a36Sopenharmony_ci	gpu_rmw(gpu, REG_A6XX_GBIF_SCACHE_CNTL1, GENMASK(24, 0), cntl1_regval);
180462306a36Sopenharmony_ci}
180562306a36Sopenharmony_ci
180662306a36Sopenharmony_cistatic void a6xx_llc_slices_destroy(struct a6xx_gpu *a6xx_gpu)
180762306a36Sopenharmony_ci{
180862306a36Sopenharmony_ci	/* No LLCC on non-RPMh (and by extension, non-GMU) SoCs */
180962306a36Sopenharmony_ci	if (adreno_has_gmu_wrapper(&a6xx_gpu->base))
181062306a36Sopenharmony_ci		return;
181162306a36Sopenharmony_ci
181262306a36Sopenharmony_ci	llcc_slice_putd(a6xx_gpu->llc_slice);
181362306a36Sopenharmony_ci	llcc_slice_putd(a6xx_gpu->htw_llc_slice);
181462306a36Sopenharmony_ci}
181562306a36Sopenharmony_ci
181662306a36Sopenharmony_cistatic void a6xx_llc_slices_init(struct platform_device *pdev,
181762306a36Sopenharmony_ci		struct a6xx_gpu *a6xx_gpu)
181862306a36Sopenharmony_ci{
181962306a36Sopenharmony_ci	struct device_node *phandle;
182062306a36Sopenharmony_ci
182162306a36Sopenharmony_ci	/* No LLCC on non-RPMh (and by extension, non-GMU) SoCs */
182262306a36Sopenharmony_ci	if (adreno_has_gmu_wrapper(&a6xx_gpu->base))
182362306a36Sopenharmony_ci		return;
182462306a36Sopenharmony_ci
182562306a36Sopenharmony_ci	/*
182662306a36Sopenharmony_ci	 * There is a different programming path for targets with an mmu500
182762306a36Sopenharmony_ci	 * attached, so detect if that is the case
182862306a36Sopenharmony_ci	 */
182962306a36Sopenharmony_ci	phandle = of_parse_phandle(pdev->dev.of_node, "iommus", 0);
183062306a36Sopenharmony_ci	a6xx_gpu->have_mmu500 = (phandle &&
183162306a36Sopenharmony_ci		of_device_is_compatible(phandle, "arm,mmu-500"));
183262306a36Sopenharmony_ci	of_node_put(phandle);
183362306a36Sopenharmony_ci
183462306a36Sopenharmony_ci	if (a6xx_gpu->have_mmu500)
183562306a36Sopenharmony_ci		a6xx_gpu->llc_mmio = NULL;
183662306a36Sopenharmony_ci	else
183762306a36Sopenharmony_ci		a6xx_gpu->llc_mmio = msm_ioremap(pdev, "cx_mem");
183862306a36Sopenharmony_ci
183962306a36Sopenharmony_ci	a6xx_gpu->llc_slice = llcc_slice_getd(LLCC_GPU);
184062306a36Sopenharmony_ci	a6xx_gpu->htw_llc_slice = llcc_slice_getd(LLCC_GPUHTW);
184162306a36Sopenharmony_ci
184262306a36Sopenharmony_ci	if (IS_ERR_OR_NULL(a6xx_gpu->llc_slice) && IS_ERR_OR_NULL(a6xx_gpu->htw_llc_slice))
184362306a36Sopenharmony_ci		a6xx_gpu->llc_mmio = ERR_PTR(-EINVAL);
184462306a36Sopenharmony_ci}
184562306a36Sopenharmony_ci
184662306a36Sopenharmony_ci#define GBIF_CLIENT_HALT_MASK		BIT(0)
184762306a36Sopenharmony_ci#define GBIF_ARB_HALT_MASK		BIT(1)
184862306a36Sopenharmony_ci#define VBIF_XIN_HALT_CTRL0_MASK	GENMASK(3, 0)
184962306a36Sopenharmony_ci#define VBIF_RESET_ACK_MASK		0xF0
185062306a36Sopenharmony_ci#define GPR0_GBIF_HALT_REQUEST		0x1E0
185162306a36Sopenharmony_ci
185262306a36Sopenharmony_civoid a6xx_bus_clear_pending_transactions(struct adreno_gpu *adreno_gpu, bool gx_off)
185362306a36Sopenharmony_ci{
185462306a36Sopenharmony_ci	struct msm_gpu *gpu = &adreno_gpu->base;
185562306a36Sopenharmony_ci
185662306a36Sopenharmony_ci	if (adreno_is_a619_holi(adreno_gpu)) {
185762306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_RBBM_GPR0_CNTL, GPR0_GBIF_HALT_REQUEST);
185862306a36Sopenharmony_ci		spin_until((gpu_read(gpu, REG_A6XX_RBBM_VBIF_GX_RESET_STATUS) &
185962306a36Sopenharmony_ci				(VBIF_RESET_ACK_MASK)) == VBIF_RESET_ACK_MASK);
186062306a36Sopenharmony_ci	} else if (!a6xx_has_gbif(adreno_gpu)) {
186162306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_VBIF_XIN_HALT_CTRL0, VBIF_XIN_HALT_CTRL0_MASK);
186262306a36Sopenharmony_ci		spin_until((gpu_read(gpu, REG_A6XX_VBIF_XIN_HALT_CTRL1) &
186362306a36Sopenharmony_ci				(VBIF_XIN_HALT_CTRL0_MASK)) == VBIF_XIN_HALT_CTRL0_MASK);
186462306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_VBIF_XIN_HALT_CTRL0, 0);
186562306a36Sopenharmony_ci
186662306a36Sopenharmony_ci		return;
186762306a36Sopenharmony_ci	}
186862306a36Sopenharmony_ci
186962306a36Sopenharmony_ci	if (gx_off) {
187062306a36Sopenharmony_ci		/* Halt the gx side of GBIF */
187162306a36Sopenharmony_ci		gpu_write(gpu, REG_A6XX_RBBM_GBIF_HALT, 1);
187262306a36Sopenharmony_ci		spin_until(gpu_read(gpu, REG_A6XX_RBBM_GBIF_HALT_ACK) & 1);
187362306a36Sopenharmony_ci	}
187462306a36Sopenharmony_ci
187562306a36Sopenharmony_ci	/* Halt new client requests on GBIF */
187662306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_GBIF_HALT, GBIF_CLIENT_HALT_MASK);
187762306a36Sopenharmony_ci	spin_until((gpu_read(gpu, REG_A6XX_GBIF_HALT_ACK) &
187862306a36Sopenharmony_ci			(GBIF_CLIENT_HALT_MASK)) == GBIF_CLIENT_HALT_MASK);
187962306a36Sopenharmony_ci
188062306a36Sopenharmony_ci	/* Halt all AXI requests on GBIF */
188162306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_GBIF_HALT, GBIF_ARB_HALT_MASK);
188262306a36Sopenharmony_ci	spin_until((gpu_read(gpu,  REG_A6XX_GBIF_HALT_ACK) &
188362306a36Sopenharmony_ci			(GBIF_ARB_HALT_MASK)) == GBIF_ARB_HALT_MASK);
188462306a36Sopenharmony_ci
188562306a36Sopenharmony_ci	/* The GBIF halt needs to be explicitly cleared */
188662306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_GBIF_HALT, 0x0);
188762306a36Sopenharmony_ci}
188862306a36Sopenharmony_ci
188962306a36Sopenharmony_civoid a6xx_gpu_sw_reset(struct msm_gpu *gpu, bool assert)
189062306a36Sopenharmony_ci{
189162306a36Sopenharmony_ci	/* 11nm chips (e.g. ones with A610) have hw issues with the reset line! */
189262306a36Sopenharmony_ci	if (adreno_is_a610(to_adreno_gpu(gpu)))
189362306a36Sopenharmony_ci		return;
189462306a36Sopenharmony_ci
189562306a36Sopenharmony_ci	gpu_write(gpu, REG_A6XX_RBBM_SW_RESET_CMD, assert);
189662306a36Sopenharmony_ci	/* Perform a bogus read and add a brief delay to ensure ordering. */
189762306a36Sopenharmony_ci	gpu_read(gpu, REG_A6XX_RBBM_SW_RESET_CMD);
189862306a36Sopenharmony_ci	udelay(1);
189962306a36Sopenharmony_ci
190062306a36Sopenharmony_ci	/* The reset line needs to be asserted for at least 100 us */
190162306a36Sopenharmony_ci	if (assert)
190262306a36Sopenharmony_ci		udelay(100);
190362306a36Sopenharmony_ci}
190462306a36Sopenharmony_ci
190562306a36Sopenharmony_cistatic int a6xx_gmu_pm_resume(struct msm_gpu *gpu)
190662306a36Sopenharmony_ci{
190762306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
190862306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
190962306a36Sopenharmony_ci	int ret;
191062306a36Sopenharmony_ci
191162306a36Sopenharmony_ci	gpu->needs_hw_init = true;
191262306a36Sopenharmony_ci
191362306a36Sopenharmony_ci	trace_msm_gpu_resume(0);
191462306a36Sopenharmony_ci
191562306a36Sopenharmony_ci	mutex_lock(&a6xx_gpu->gmu.lock);
191662306a36Sopenharmony_ci	ret = a6xx_gmu_resume(a6xx_gpu);
191762306a36Sopenharmony_ci	mutex_unlock(&a6xx_gpu->gmu.lock);
191862306a36Sopenharmony_ci	if (ret)
191962306a36Sopenharmony_ci		return ret;
192062306a36Sopenharmony_ci
192162306a36Sopenharmony_ci	msm_devfreq_resume(gpu);
192262306a36Sopenharmony_ci
192362306a36Sopenharmony_ci	a6xx_llc_activate(a6xx_gpu);
192462306a36Sopenharmony_ci
192562306a36Sopenharmony_ci	return ret;
192662306a36Sopenharmony_ci}
192762306a36Sopenharmony_ci
192862306a36Sopenharmony_cistatic int a6xx_pm_resume(struct msm_gpu *gpu)
192962306a36Sopenharmony_ci{
193062306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
193162306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
193262306a36Sopenharmony_ci	struct a6xx_gmu *gmu = &a6xx_gpu->gmu;
193362306a36Sopenharmony_ci	unsigned long freq = gpu->fast_rate;
193462306a36Sopenharmony_ci	struct dev_pm_opp *opp;
193562306a36Sopenharmony_ci	int ret;
193662306a36Sopenharmony_ci
193762306a36Sopenharmony_ci	gpu->needs_hw_init = true;
193862306a36Sopenharmony_ci
193962306a36Sopenharmony_ci	trace_msm_gpu_resume(0);
194062306a36Sopenharmony_ci
194162306a36Sopenharmony_ci	mutex_lock(&a6xx_gpu->gmu.lock);
194262306a36Sopenharmony_ci
194362306a36Sopenharmony_ci	opp = dev_pm_opp_find_freq_ceil(&gpu->pdev->dev, &freq);
194462306a36Sopenharmony_ci	if (IS_ERR(opp)) {
194562306a36Sopenharmony_ci		ret = PTR_ERR(opp);
194662306a36Sopenharmony_ci		goto err_set_opp;
194762306a36Sopenharmony_ci	}
194862306a36Sopenharmony_ci	dev_pm_opp_put(opp);
194962306a36Sopenharmony_ci
195062306a36Sopenharmony_ci	/* Set the core clock and bus bw, having VDD scaling in mind */
195162306a36Sopenharmony_ci	dev_pm_opp_set_opp(&gpu->pdev->dev, opp);
195262306a36Sopenharmony_ci
195362306a36Sopenharmony_ci	pm_runtime_resume_and_get(gmu->dev);
195462306a36Sopenharmony_ci	pm_runtime_resume_and_get(gmu->gxpd);
195562306a36Sopenharmony_ci
195662306a36Sopenharmony_ci	ret = clk_bulk_prepare_enable(gpu->nr_clocks, gpu->grp_clks);
195762306a36Sopenharmony_ci	if (ret)
195862306a36Sopenharmony_ci		goto err_bulk_clk;
195962306a36Sopenharmony_ci
196062306a36Sopenharmony_ci	if (adreno_is_a619_holi(adreno_gpu))
196162306a36Sopenharmony_ci		a6xx_sptprac_enable(gmu);
196262306a36Sopenharmony_ci
196362306a36Sopenharmony_ci	/* If anything goes south, tear the GPU down piece by piece.. */
196462306a36Sopenharmony_ci	if (ret) {
196562306a36Sopenharmony_cierr_bulk_clk:
196662306a36Sopenharmony_ci		pm_runtime_put(gmu->gxpd);
196762306a36Sopenharmony_ci		pm_runtime_put(gmu->dev);
196862306a36Sopenharmony_ci		dev_pm_opp_set_opp(&gpu->pdev->dev, NULL);
196962306a36Sopenharmony_ci	}
197062306a36Sopenharmony_cierr_set_opp:
197162306a36Sopenharmony_ci	mutex_unlock(&a6xx_gpu->gmu.lock);
197262306a36Sopenharmony_ci
197362306a36Sopenharmony_ci	if (!ret)
197462306a36Sopenharmony_ci		msm_devfreq_resume(gpu);
197562306a36Sopenharmony_ci
197662306a36Sopenharmony_ci	return ret;
197762306a36Sopenharmony_ci}
197862306a36Sopenharmony_ci
197962306a36Sopenharmony_cistatic int a6xx_gmu_pm_suspend(struct msm_gpu *gpu)
198062306a36Sopenharmony_ci{
198162306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
198262306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
198362306a36Sopenharmony_ci	int i, ret;
198462306a36Sopenharmony_ci
198562306a36Sopenharmony_ci	trace_msm_gpu_suspend(0);
198662306a36Sopenharmony_ci
198762306a36Sopenharmony_ci	a6xx_llc_deactivate(a6xx_gpu);
198862306a36Sopenharmony_ci
198962306a36Sopenharmony_ci	msm_devfreq_suspend(gpu);
199062306a36Sopenharmony_ci
199162306a36Sopenharmony_ci	mutex_lock(&a6xx_gpu->gmu.lock);
199262306a36Sopenharmony_ci	ret = a6xx_gmu_stop(a6xx_gpu);
199362306a36Sopenharmony_ci	mutex_unlock(&a6xx_gpu->gmu.lock);
199462306a36Sopenharmony_ci	if (ret)
199562306a36Sopenharmony_ci		return ret;
199662306a36Sopenharmony_ci
199762306a36Sopenharmony_ci	if (a6xx_gpu->shadow_bo)
199862306a36Sopenharmony_ci		for (i = 0; i < gpu->nr_rings; i++)
199962306a36Sopenharmony_ci			a6xx_gpu->shadow[i] = 0;
200062306a36Sopenharmony_ci
200162306a36Sopenharmony_ci	gpu->suspend_count++;
200262306a36Sopenharmony_ci
200362306a36Sopenharmony_ci	return 0;
200462306a36Sopenharmony_ci}
200562306a36Sopenharmony_ci
200662306a36Sopenharmony_cistatic int a6xx_pm_suspend(struct msm_gpu *gpu)
200762306a36Sopenharmony_ci{
200862306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
200962306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
201062306a36Sopenharmony_ci	struct a6xx_gmu *gmu = &a6xx_gpu->gmu;
201162306a36Sopenharmony_ci	int i;
201262306a36Sopenharmony_ci
201362306a36Sopenharmony_ci	trace_msm_gpu_suspend(0);
201462306a36Sopenharmony_ci
201562306a36Sopenharmony_ci	msm_devfreq_suspend(gpu);
201662306a36Sopenharmony_ci
201762306a36Sopenharmony_ci	mutex_lock(&a6xx_gpu->gmu.lock);
201862306a36Sopenharmony_ci
201962306a36Sopenharmony_ci	/* Drain the outstanding traffic on memory buses */
202062306a36Sopenharmony_ci	a6xx_bus_clear_pending_transactions(adreno_gpu, true);
202162306a36Sopenharmony_ci
202262306a36Sopenharmony_ci	if (adreno_is_a619_holi(adreno_gpu))
202362306a36Sopenharmony_ci		a6xx_sptprac_disable(gmu);
202462306a36Sopenharmony_ci
202562306a36Sopenharmony_ci	clk_bulk_disable_unprepare(gpu->nr_clocks, gpu->grp_clks);
202662306a36Sopenharmony_ci
202762306a36Sopenharmony_ci	pm_runtime_put_sync(gmu->gxpd);
202862306a36Sopenharmony_ci	dev_pm_opp_set_opp(&gpu->pdev->dev, NULL);
202962306a36Sopenharmony_ci	pm_runtime_put_sync(gmu->dev);
203062306a36Sopenharmony_ci
203162306a36Sopenharmony_ci	mutex_unlock(&a6xx_gpu->gmu.lock);
203262306a36Sopenharmony_ci
203362306a36Sopenharmony_ci	if (a6xx_gpu->shadow_bo)
203462306a36Sopenharmony_ci		for (i = 0; i < gpu->nr_rings; i++)
203562306a36Sopenharmony_ci			a6xx_gpu->shadow[i] = 0;
203662306a36Sopenharmony_ci
203762306a36Sopenharmony_ci	gpu->suspend_count++;
203862306a36Sopenharmony_ci
203962306a36Sopenharmony_ci	return 0;
204062306a36Sopenharmony_ci}
204162306a36Sopenharmony_ci
204262306a36Sopenharmony_cistatic int a6xx_gmu_get_timestamp(struct msm_gpu *gpu, uint64_t *value)
204362306a36Sopenharmony_ci{
204462306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
204562306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
204662306a36Sopenharmony_ci
204762306a36Sopenharmony_ci	mutex_lock(&a6xx_gpu->gmu.lock);
204862306a36Sopenharmony_ci
204962306a36Sopenharmony_ci	/* Force the GPU power on so we can read this register */
205062306a36Sopenharmony_ci	a6xx_gmu_set_oob(&a6xx_gpu->gmu, GMU_OOB_PERFCOUNTER_SET);
205162306a36Sopenharmony_ci
205262306a36Sopenharmony_ci	*value = gpu_read64(gpu, REG_A6XX_CP_ALWAYS_ON_COUNTER);
205362306a36Sopenharmony_ci
205462306a36Sopenharmony_ci	a6xx_gmu_clear_oob(&a6xx_gpu->gmu, GMU_OOB_PERFCOUNTER_SET);
205562306a36Sopenharmony_ci
205662306a36Sopenharmony_ci	mutex_unlock(&a6xx_gpu->gmu.lock);
205762306a36Sopenharmony_ci
205862306a36Sopenharmony_ci	return 0;
205962306a36Sopenharmony_ci}
206062306a36Sopenharmony_ci
206162306a36Sopenharmony_cistatic int a6xx_get_timestamp(struct msm_gpu *gpu, uint64_t *value)
206262306a36Sopenharmony_ci{
206362306a36Sopenharmony_ci	*value = gpu_read64(gpu, REG_A6XX_CP_ALWAYS_ON_COUNTER);
206462306a36Sopenharmony_ci	return 0;
206562306a36Sopenharmony_ci}
206662306a36Sopenharmony_ci
206762306a36Sopenharmony_cistatic struct msm_ringbuffer *a6xx_active_ring(struct msm_gpu *gpu)
206862306a36Sopenharmony_ci{
206962306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
207062306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
207162306a36Sopenharmony_ci
207262306a36Sopenharmony_ci	return a6xx_gpu->cur_ring;
207362306a36Sopenharmony_ci}
207462306a36Sopenharmony_ci
207562306a36Sopenharmony_cistatic void a6xx_destroy(struct msm_gpu *gpu)
207662306a36Sopenharmony_ci{
207762306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
207862306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
207962306a36Sopenharmony_ci
208062306a36Sopenharmony_ci	if (a6xx_gpu->sqe_bo) {
208162306a36Sopenharmony_ci		msm_gem_unpin_iova(a6xx_gpu->sqe_bo, gpu->aspace);
208262306a36Sopenharmony_ci		drm_gem_object_put(a6xx_gpu->sqe_bo);
208362306a36Sopenharmony_ci	}
208462306a36Sopenharmony_ci
208562306a36Sopenharmony_ci	if (a6xx_gpu->shadow_bo) {
208662306a36Sopenharmony_ci		msm_gem_unpin_iova(a6xx_gpu->shadow_bo, gpu->aspace);
208762306a36Sopenharmony_ci		drm_gem_object_put(a6xx_gpu->shadow_bo);
208862306a36Sopenharmony_ci	}
208962306a36Sopenharmony_ci
209062306a36Sopenharmony_ci	a6xx_llc_slices_destroy(a6xx_gpu);
209162306a36Sopenharmony_ci
209262306a36Sopenharmony_ci	a6xx_gmu_remove(a6xx_gpu);
209362306a36Sopenharmony_ci
209462306a36Sopenharmony_ci	adreno_gpu_cleanup(adreno_gpu);
209562306a36Sopenharmony_ci
209662306a36Sopenharmony_ci	kfree(a6xx_gpu);
209762306a36Sopenharmony_ci}
209862306a36Sopenharmony_ci
209962306a36Sopenharmony_cistatic u64 a6xx_gpu_busy(struct msm_gpu *gpu, unsigned long *out_sample_rate)
210062306a36Sopenharmony_ci{
210162306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
210262306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
210362306a36Sopenharmony_ci	u64 busy_cycles;
210462306a36Sopenharmony_ci
210562306a36Sopenharmony_ci	/* 19.2MHz */
210662306a36Sopenharmony_ci	*out_sample_rate = 19200000;
210762306a36Sopenharmony_ci
210862306a36Sopenharmony_ci	busy_cycles = gmu_read64(&a6xx_gpu->gmu,
210962306a36Sopenharmony_ci			REG_A6XX_GMU_CX_GMU_POWER_COUNTER_XOCLK_0_L,
211062306a36Sopenharmony_ci			REG_A6XX_GMU_CX_GMU_POWER_COUNTER_XOCLK_0_H);
211162306a36Sopenharmony_ci
211262306a36Sopenharmony_ci	return busy_cycles;
211362306a36Sopenharmony_ci}
211462306a36Sopenharmony_ci
211562306a36Sopenharmony_cistatic void a6xx_gpu_set_freq(struct msm_gpu *gpu, struct dev_pm_opp *opp,
211662306a36Sopenharmony_ci			      bool suspended)
211762306a36Sopenharmony_ci{
211862306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
211962306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
212062306a36Sopenharmony_ci
212162306a36Sopenharmony_ci	mutex_lock(&a6xx_gpu->gmu.lock);
212262306a36Sopenharmony_ci	a6xx_gmu_set_freq(gpu, opp, suspended);
212362306a36Sopenharmony_ci	mutex_unlock(&a6xx_gpu->gmu.lock);
212462306a36Sopenharmony_ci}
212562306a36Sopenharmony_ci
212662306a36Sopenharmony_cistatic struct msm_gem_address_space *
212762306a36Sopenharmony_cia6xx_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev)
212862306a36Sopenharmony_ci{
212962306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
213062306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
213162306a36Sopenharmony_ci	unsigned long quirks = 0;
213262306a36Sopenharmony_ci
213362306a36Sopenharmony_ci	/*
213462306a36Sopenharmony_ci	 * This allows GPU to set the bus attributes required to use system
213562306a36Sopenharmony_ci	 * cache on behalf of the iommu page table walker.
213662306a36Sopenharmony_ci	 */
213762306a36Sopenharmony_ci	if (!IS_ERR_OR_NULL(a6xx_gpu->htw_llc_slice) &&
213862306a36Sopenharmony_ci	    !device_iommu_capable(&pdev->dev, IOMMU_CAP_CACHE_COHERENCY))
213962306a36Sopenharmony_ci		quirks |= IO_PGTABLE_QUIRK_ARM_OUTER_WBWA;
214062306a36Sopenharmony_ci
214162306a36Sopenharmony_ci	return adreno_iommu_create_address_space(gpu, pdev, quirks);
214262306a36Sopenharmony_ci}
214362306a36Sopenharmony_ci
214462306a36Sopenharmony_cistatic struct msm_gem_address_space *
214562306a36Sopenharmony_cia6xx_create_private_address_space(struct msm_gpu *gpu)
214662306a36Sopenharmony_ci{
214762306a36Sopenharmony_ci	struct msm_mmu *mmu;
214862306a36Sopenharmony_ci
214962306a36Sopenharmony_ci	mmu = msm_iommu_pagetable_create(gpu->aspace->mmu);
215062306a36Sopenharmony_ci
215162306a36Sopenharmony_ci	if (IS_ERR(mmu))
215262306a36Sopenharmony_ci		return ERR_CAST(mmu);
215362306a36Sopenharmony_ci
215462306a36Sopenharmony_ci	return msm_gem_address_space_create(mmu,
215562306a36Sopenharmony_ci		"gpu", 0x100000000ULL,
215662306a36Sopenharmony_ci		adreno_private_address_space_size(gpu));
215762306a36Sopenharmony_ci}
215862306a36Sopenharmony_ci
215962306a36Sopenharmony_cistatic uint32_t a6xx_get_rptr(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
216062306a36Sopenharmony_ci{
216162306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
216262306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
216362306a36Sopenharmony_ci
216462306a36Sopenharmony_ci	if (adreno_gpu->base.hw_apriv || a6xx_gpu->has_whereami)
216562306a36Sopenharmony_ci		return a6xx_gpu->shadow[ring->id];
216662306a36Sopenharmony_ci
216762306a36Sopenharmony_ci	return ring->memptrs->rptr = gpu_read(gpu, REG_A6XX_CP_RB_RPTR);
216862306a36Sopenharmony_ci}
216962306a36Sopenharmony_ci
217062306a36Sopenharmony_cistatic bool a6xx_progress(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
217162306a36Sopenharmony_ci{
217262306a36Sopenharmony_ci	struct msm_cp_state cp_state = {
217362306a36Sopenharmony_ci		.ib1_base = gpu_read64(gpu, REG_A6XX_CP_IB1_BASE),
217462306a36Sopenharmony_ci		.ib2_base = gpu_read64(gpu, REG_A6XX_CP_IB2_BASE),
217562306a36Sopenharmony_ci		.ib1_rem  = gpu_read(gpu, REG_A6XX_CP_IB1_REM_SIZE),
217662306a36Sopenharmony_ci		.ib2_rem  = gpu_read(gpu, REG_A6XX_CP_IB2_REM_SIZE),
217762306a36Sopenharmony_ci	};
217862306a36Sopenharmony_ci	bool progress;
217962306a36Sopenharmony_ci
218062306a36Sopenharmony_ci	/*
218162306a36Sopenharmony_ci	 * Adjust the remaining data to account for what has already been
218262306a36Sopenharmony_ci	 * fetched from memory, but not yet consumed by the SQE.
218362306a36Sopenharmony_ci	 *
218462306a36Sopenharmony_ci	 * This is not *technically* correct, the amount buffered could
218562306a36Sopenharmony_ci	 * exceed the IB size due to hw prefetching ahead, but:
218662306a36Sopenharmony_ci	 *
218762306a36Sopenharmony_ci	 * (1) We aren't trying to find the exact position, just whether
218862306a36Sopenharmony_ci	 *     progress has been made
218962306a36Sopenharmony_ci	 * (2) The CP_REG_TO_MEM at the end of a submit should be enough
219062306a36Sopenharmony_ci	 *     to prevent prefetching into an unrelated submit.  (And
219162306a36Sopenharmony_ci	 *     either way, at some point the ROQ will be full.)
219262306a36Sopenharmony_ci	 */
219362306a36Sopenharmony_ci	cp_state.ib1_rem += gpu_read(gpu, REG_A6XX_CP_ROQ_AVAIL_IB1) >> 16;
219462306a36Sopenharmony_ci	cp_state.ib2_rem += gpu_read(gpu, REG_A6XX_CP_ROQ_AVAIL_IB2) >> 16;
219562306a36Sopenharmony_ci
219662306a36Sopenharmony_ci	progress = !!memcmp(&cp_state, &ring->last_cp_state, sizeof(cp_state));
219762306a36Sopenharmony_ci
219862306a36Sopenharmony_ci	ring->last_cp_state = cp_state;
219962306a36Sopenharmony_ci
220062306a36Sopenharmony_ci	return progress;
220162306a36Sopenharmony_ci}
220262306a36Sopenharmony_ci
220362306a36Sopenharmony_cistatic u32 fuse_to_supp_hw(const struct adreno_info *info, u32 fuse)
220462306a36Sopenharmony_ci{
220562306a36Sopenharmony_ci	if (!info->speedbins)
220662306a36Sopenharmony_ci		return UINT_MAX;
220762306a36Sopenharmony_ci
220862306a36Sopenharmony_ci	for (int i = 0; info->speedbins[i].fuse != SHRT_MAX; i++)
220962306a36Sopenharmony_ci		if (info->speedbins[i].fuse == fuse)
221062306a36Sopenharmony_ci			return BIT(info->speedbins[i].speedbin);
221162306a36Sopenharmony_ci
221262306a36Sopenharmony_ci	return UINT_MAX;
221362306a36Sopenharmony_ci}
221462306a36Sopenharmony_ci
221562306a36Sopenharmony_cistatic int a6xx_set_supported_hw(struct device *dev, const struct adreno_info *info)
221662306a36Sopenharmony_ci{
221762306a36Sopenharmony_ci	u32 supp_hw;
221862306a36Sopenharmony_ci	u32 speedbin;
221962306a36Sopenharmony_ci	int ret;
222062306a36Sopenharmony_ci
222162306a36Sopenharmony_ci	ret = adreno_read_speedbin(dev, &speedbin);
222262306a36Sopenharmony_ci	/*
222362306a36Sopenharmony_ci	 * -ENOENT means that the platform doesn't support speedbin which is
222462306a36Sopenharmony_ci	 * fine
222562306a36Sopenharmony_ci	 */
222662306a36Sopenharmony_ci	if (ret == -ENOENT) {
222762306a36Sopenharmony_ci		return 0;
222862306a36Sopenharmony_ci	} else if (ret) {
222962306a36Sopenharmony_ci		dev_err_probe(dev, ret,
223062306a36Sopenharmony_ci			      "failed to read speed-bin. Some OPPs may not be supported by hardware\n");
223162306a36Sopenharmony_ci		return ret;
223262306a36Sopenharmony_ci	}
223362306a36Sopenharmony_ci
223462306a36Sopenharmony_ci	supp_hw = fuse_to_supp_hw(info, speedbin);
223562306a36Sopenharmony_ci
223662306a36Sopenharmony_ci	if (supp_hw == UINT_MAX) {
223762306a36Sopenharmony_ci		DRM_DEV_ERROR(dev,
223862306a36Sopenharmony_ci			"missing support for speed-bin: %u. Some OPPs may not be supported by hardware\n",
223962306a36Sopenharmony_ci			speedbin);
224062306a36Sopenharmony_ci		supp_hw = BIT(0); /* Default */
224162306a36Sopenharmony_ci	}
224262306a36Sopenharmony_ci
224362306a36Sopenharmony_ci	ret = devm_pm_opp_set_supported_hw(dev, &supp_hw, 1);
224462306a36Sopenharmony_ci	if (ret)
224562306a36Sopenharmony_ci		return ret;
224662306a36Sopenharmony_ci
224762306a36Sopenharmony_ci	return 0;
224862306a36Sopenharmony_ci}
224962306a36Sopenharmony_ci
225062306a36Sopenharmony_cistatic const struct adreno_gpu_funcs funcs = {
225162306a36Sopenharmony_ci	.base = {
225262306a36Sopenharmony_ci		.get_param = adreno_get_param,
225362306a36Sopenharmony_ci		.set_param = adreno_set_param,
225462306a36Sopenharmony_ci		.hw_init = a6xx_hw_init,
225562306a36Sopenharmony_ci		.ucode_load = a6xx_ucode_load,
225662306a36Sopenharmony_ci		.pm_suspend = a6xx_gmu_pm_suspend,
225762306a36Sopenharmony_ci		.pm_resume = a6xx_gmu_pm_resume,
225862306a36Sopenharmony_ci		.recover = a6xx_recover,
225962306a36Sopenharmony_ci		.submit = a6xx_submit,
226062306a36Sopenharmony_ci		.active_ring = a6xx_active_ring,
226162306a36Sopenharmony_ci		.irq = a6xx_irq,
226262306a36Sopenharmony_ci		.destroy = a6xx_destroy,
226362306a36Sopenharmony_ci#if defined(CONFIG_DRM_MSM_GPU_STATE)
226462306a36Sopenharmony_ci		.show = a6xx_show,
226562306a36Sopenharmony_ci#endif
226662306a36Sopenharmony_ci		.gpu_busy = a6xx_gpu_busy,
226762306a36Sopenharmony_ci		.gpu_get_freq = a6xx_gmu_get_freq,
226862306a36Sopenharmony_ci		.gpu_set_freq = a6xx_gpu_set_freq,
226962306a36Sopenharmony_ci#if defined(CONFIG_DRM_MSM_GPU_STATE)
227062306a36Sopenharmony_ci		.gpu_state_get = a6xx_gpu_state_get,
227162306a36Sopenharmony_ci		.gpu_state_put = a6xx_gpu_state_put,
227262306a36Sopenharmony_ci#endif
227362306a36Sopenharmony_ci		.create_address_space = a6xx_create_address_space,
227462306a36Sopenharmony_ci		.create_private_address_space = a6xx_create_private_address_space,
227562306a36Sopenharmony_ci		.get_rptr = a6xx_get_rptr,
227662306a36Sopenharmony_ci		.progress = a6xx_progress,
227762306a36Sopenharmony_ci	},
227862306a36Sopenharmony_ci	.get_timestamp = a6xx_gmu_get_timestamp,
227962306a36Sopenharmony_ci};
228062306a36Sopenharmony_ci
228162306a36Sopenharmony_cistatic const struct adreno_gpu_funcs funcs_gmuwrapper = {
228262306a36Sopenharmony_ci	.base = {
228362306a36Sopenharmony_ci		.get_param = adreno_get_param,
228462306a36Sopenharmony_ci		.set_param = adreno_set_param,
228562306a36Sopenharmony_ci		.hw_init = a6xx_hw_init,
228662306a36Sopenharmony_ci		.ucode_load = a6xx_ucode_load,
228762306a36Sopenharmony_ci		.pm_suspend = a6xx_pm_suspend,
228862306a36Sopenharmony_ci		.pm_resume = a6xx_pm_resume,
228962306a36Sopenharmony_ci		.recover = a6xx_recover,
229062306a36Sopenharmony_ci		.submit = a6xx_submit,
229162306a36Sopenharmony_ci		.active_ring = a6xx_active_ring,
229262306a36Sopenharmony_ci		.irq = a6xx_irq,
229362306a36Sopenharmony_ci		.destroy = a6xx_destroy,
229462306a36Sopenharmony_ci#if defined(CONFIG_DRM_MSM_GPU_STATE)
229562306a36Sopenharmony_ci		.show = a6xx_show,
229662306a36Sopenharmony_ci#endif
229762306a36Sopenharmony_ci		.gpu_busy = a6xx_gpu_busy,
229862306a36Sopenharmony_ci#if defined(CONFIG_DRM_MSM_GPU_STATE)
229962306a36Sopenharmony_ci		.gpu_state_get = a6xx_gpu_state_get,
230062306a36Sopenharmony_ci		.gpu_state_put = a6xx_gpu_state_put,
230162306a36Sopenharmony_ci#endif
230262306a36Sopenharmony_ci		.create_address_space = a6xx_create_address_space,
230362306a36Sopenharmony_ci		.create_private_address_space = a6xx_create_private_address_space,
230462306a36Sopenharmony_ci		.get_rptr = a6xx_get_rptr,
230562306a36Sopenharmony_ci		.progress = a6xx_progress,
230662306a36Sopenharmony_ci	},
230762306a36Sopenharmony_ci	.get_timestamp = a6xx_get_timestamp,
230862306a36Sopenharmony_ci};
230962306a36Sopenharmony_ci
231062306a36Sopenharmony_cistruct msm_gpu *a6xx_gpu_init(struct drm_device *dev)
231162306a36Sopenharmony_ci{
231262306a36Sopenharmony_ci	struct msm_drm_private *priv = dev->dev_private;
231362306a36Sopenharmony_ci	struct platform_device *pdev = priv->gpu_pdev;
231462306a36Sopenharmony_ci	struct adreno_platform_config *config = pdev->dev.platform_data;
231562306a36Sopenharmony_ci	struct device_node *node;
231662306a36Sopenharmony_ci	struct a6xx_gpu *a6xx_gpu;
231762306a36Sopenharmony_ci	struct adreno_gpu *adreno_gpu;
231862306a36Sopenharmony_ci	struct msm_gpu *gpu;
231962306a36Sopenharmony_ci	int ret;
232062306a36Sopenharmony_ci
232162306a36Sopenharmony_ci	a6xx_gpu = kzalloc(sizeof(*a6xx_gpu), GFP_KERNEL);
232262306a36Sopenharmony_ci	if (!a6xx_gpu)
232362306a36Sopenharmony_ci		return ERR_PTR(-ENOMEM);
232462306a36Sopenharmony_ci
232562306a36Sopenharmony_ci	adreno_gpu = &a6xx_gpu->base;
232662306a36Sopenharmony_ci	gpu = &adreno_gpu->base;
232762306a36Sopenharmony_ci
232862306a36Sopenharmony_ci	mutex_init(&a6xx_gpu->gmu.lock);
232962306a36Sopenharmony_ci
233062306a36Sopenharmony_ci	adreno_gpu->registers = NULL;
233162306a36Sopenharmony_ci
233262306a36Sopenharmony_ci	/* Check if there is a GMU phandle and set it up */
233362306a36Sopenharmony_ci	node = of_parse_phandle(pdev->dev.of_node, "qcom,gmu", 0);
233462306a36Sopenharmony_ci	/* FIXME: How do we gracefully handle this? */
233562306a36Sopenharmony_ci	BUG_ON(!node);
233662306a36Sopenharmony_ci
233762306a36Sopenharmony_ci	adreno_gpu->gmu_is_wrapper = of_device_is_compatible(node, "qcom,adreno-gmu-wrapper");
233862306a36Sopenharmony_ci
233962306a36Sopenharmony_ci	adreno_gpu->base.hw_apriv =
234062306a36Sopenharmony_ci		!!(config->info->quirks & ADRENO_QUIRK_HAS_HW_APRIV);
234162306a36Sopenharmony_ci
234262306a36Sopenharmony_ci	a6xx_llc_slices_init(pdev, a6xx_gpu);
234362306a36Sopenharmony_ci
234462306a36Sopenharmony_ci	ret = a6xx_set_supported_hw(&pdev->dev, config->info);
234562306a36Sopenharmony_ci	if (ret) {
234662306a36Sopenharmony_ci		a6xx_destroy(&(a6xx_gpu->base.base));
234762306a36Sopenharmony_ci		return ERR_PTR(ret);
234862306a36Sopenharmony_ci	}
234962306a36Sopenharmony_ci
235062306a36Sopenharmony_ci	if (adreno_has_gmu_wrapper(adreno_gpu))
235162306a36Sopenharmony_ci		ret = adreno_gpu_init(dev, pdev, adreno_gpu, &funcs_gmuwrapper, 1);
235262306a36Sopenharmony_ci	else
235362306a36Sopenharmony_ci		ret = adreno_gpu_init(dev, pdev, adreno_gpu, &funcs, 1);
235462306a36Sopenharmony_ci	if (ret) {
235562306a36Sopenharmony_ci		a6xx_destroy(&(a6xx_gpu->base.base));
235662306a36Sopenharmony_ci		return ERR_PTR(ret);
235762306a36Sopenharmony_ci	}
235862306a36Sopenharmony_ci
235962306a36Sopenharmony_ci	/*
236062306a36Sopenharmony_ci	 * For now only clamp to idle freq for devices where this is known not
236162306a36Sopenharmony_ci	 * to cause power supply issues:
236262306a36Sopenharmony_ci	 */
236362306a36Sopenharmony_ci	if (adreno_is_a618(adreno_gpu) || adreno_is_7c3(adreno_gpu))
236462306a36Sopenharmony_ci		priv->gpu_clamp_to_idle = true;
236562306a36Sopenharmony_ci
236662306a36Sopenharmony_ci	if (adreno_has_gmu_wrapper(adreno_gpu))
236762306a36Sopenharmony_ci		ret = a6xx_gmu_wrapper_init(a6xx_gpu, node);
236862306a36Sopenharmony_ci	else
236962306a36Sopenharmony_ci		ret = a6xx_gmu_init(a6xx_gpu, node);
237062306a36Sopenharmony_ci	of_node_put(node);
237162306a36Sopenharmony_ci	if (ret) {
237262306a36Sopenharmony_ci		a6xx_destroy(&(a6xx_gpu->base.base));
237362306a36Sopenharmony_ci		return ERR_PTR(ret);
237462306a36Sopenharmony_ci	}
237562306a36Sopenharmony_ci
237662306a36Sopenharmony_ci	if (gpu->aspace)
237762306a36Sopenharmony_ci		msm_mmu_set_fault_handler(gpu->aspace->mmu, gpu,
237862306a36Sopenharmony_ci				a6xx_fault_handler);
237962306a36Sopenharmony_ci
238062306a36Sopenharmony_ci	return gpu;
238162306a36Sopenharmony_ci}
2382