1caab277bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
27198e6b0SRob Clark /*
37198e6b0SRob Clark * Copyright (C) 2013 Red Hat
47198e6b0SRob Clark * Author: Rob Clark <robdclark@gmail.com>
57198e6b0SRob Clark *
691b74e97SAravind Ganesan * Copyright (c) 2014 The Linux Foundation. All rights reserved.
77198e6b0SRob Clark */
87198e6b0SRob Clark
97198e6b0SRob Clark #include "a3xx_gpu.h"
107198e6b0SRob Clark
117198e6b0SRob Clark #define A3XX_INT0_MASK \
127198e6b0SRob Clark (A3XX_INT0_RBBM_AHB_ERROR | \
137198e6b0SRob Clark A3XX_INT0_RBBM_ATB_BUS_OVERFLOW | \
147198e6b0SRob Clark A3XX_INT0_CP_T0_PACKET_IN_IB | \
157198e6b0SRob Clark A3XX_INT0_CP_OPCODE_ERROR | \
167198e6b0SRob Clark A3XX_INT0_CP_RESERVED_BIT_ERROR | \
177198e6b0SRob Clark A3XX_INT0_CP_HW_FAULT | \
187198e6b0SRob Clark A3XX_INT0_CP_IB1_INT | \
197198e6b0SRob Clark A3XX_INT0_CP_IB2_INT | \
207198e6b0SRob Clark A3XX_INT0_CP_RB_INT | \
217198e6b0SRob Clark A3XX_INT0_CP_REG_PROTECT_FAULT | \
227198e6b0SRob Clark A3XX_INT0_CP_AHB_ERROR_HALT | \
2379d57bf6SBjorn Andersson A3XX_INT0_CACHE_FLUSH_TS | \
247198e6b0SRob Clark A3XX_INT0_UCHE_OOB_ACCESS)
257198e6b0SRob Clark
263526e9fbSRob Clark extern bool hang_debug;
275b6ef08eSRob Clark
285b6ef08eSRob Clark static void a3xx_dump(struct msm_gpu *gpu);
29e895c7bdSJordan Crouse static bool a3xx_idle(struct msm_gpu *gpu);
305b6ef08eSRob Clark
a3xx_submit(struct msm_gpu * gpu,struct msm_gem_submit * submit)312fb7487aSJordan Crouse static void a3xx_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit)
322fb7487aSJordan Crouse {
332fb7487aSJordan Crouse struct msm_ringbuffer *ring = submit->ring;
342fb7487aSJordan Crouse unsigned int i;
352fb7487aSJordan Crouse
362fb7487aSJordan Crouse for (i = 0; i < submit->nr_cmds; i++) {
372fb7487aSJordan Crouse switch (submit->cmd[i].type) {
382fb7487aSJordan Crouse case MSM_SUBMIT_CMD_IB_TARGET_BUF:
392fb7487aSJordan Crouse /* ignore IB-targets */
402fb7487aSJordan Crouse break;
412fb7487aSJordan Crouse case MSM_SUBMIT_CMD_CTX_RESTORE_BUF:
422fb7487aSJordan Crouse /* ignore if there has not been a ctx switch: */
431d054c9bSRob Clark if (gpu->cur_ctx_seqno == submit->queue->ctx->seqno)
442fb7487aSJordan Crouse break;
452fb7487aSJordan Crouse fallthrough;
462fb7487aSJordan Crouse case MSM_SUBMIT_CMD_BUF:
472fb7487aSJordan Crouse OUT_PKT3(ring, CP_INDIRECT_BUFFER_PFD, 2);
482fb7487aSJordan Crouse OUT_RING(ring, lower_32_bits(submit->cmd[i].iova));
492fb7487aSJordan Crouse OUT_RING(ring, submit->cmd[i].size);
502fb7487aSJordan Crouse OUT_PKT2(ring);
512fb7487aSJordan Crouse break;
522fb7487aSJordan Crouse }
532fb7487aSJordan Crouse }
542fb7487aSJordan Crouse
552fb7487aSJordan Crouse OUT_PKT0(ring, REG_AXXX_CP_SCRATCH_REG2, 1);
562fb7487aSJordan Crouse OUT_RING(ring, submit->seqno);
572fb7487aSJordan Crouse
582fb7487aSJordan Crouse /* Flush HLSQ lazy updates to make sure there is nothing
592fb7487aSJordan Crouse * pending for indirect loads after the timestamp has
602fb7487aSJordan Crouse * passed:
612fb7487aSJordan Crouse */
622fb7487aSJordan Crouse OUT_PKT3(ring, CP_EVENT_WRITE, 1);
632fb7487aSJordan Crouse OUT_RING(ring, HLSQ_FLUSH);
642fb7487aSJordan Crouse
652fb7487aSJordan Crouse /* wait for idle before cache flush/interrupt */
662fb7487aSJordan Crouse OUT_PKT3(ring, CP_WAIT_FOR_IDLE, 1);
672fb7487aSJordan Crouse OUT_RING(ring, 0x00000000);
682fb7487aSJordan Crouse
692fb7487aSJordan Crouse /* BIT(31) of CACHE_FLUSH_TS triggers CACHE_FLUSH_TS IRQ from GPU */
702fb7487aSJordan Crouse OUT_PKT3(ring, CP_EVENT_WRITE, 3);
7180059b87SRob Clark OUT_RING(ring, CACHE_FLUSH_TS | CP_EVENT_WRITE_0_IRQ);
722fb7487aSJordan Crouse OUT_RING(ring, rbmemptr(ring, fence));
732fb7487aSJordan Crouse OUT_RING(ring, submit->seqno);
742fb7487aSJordan Crouse
752fb7487aSJordan Crouse #if 0
762fb7487aSJordan Crouse /* Dummy set-constant to trigger context rollover */
772fb7487aSJordan Crouse OUT_PKT3(ring, CP_SET_CONSTANT, 2);
782fb7487aSJordan Crouse OUT_RING(ring, CP_REG(REG_A3XX_HLSQ_CL_KERNEL_GROUP_X_REG));
792fb7487aSJordan Crouse OUT_RING(ring, 0x00000000);
802fb7487aSJordan Crouse #endif
812fb7487aSJordan Crouse
822fb7487aSJordan Crouse adreno_flush(gpu, ring, REG_AXXX_CP_RB_WPTR);
832fb7487aSJordan Crouse }
842fb7487aSJordan Crouse
a3xx_me_init(struct msm_gpu * gpu)85c4a8d475SJordan Crouse static bool a3xx_me_init(struct msm_gpu *gpu)
867198e6b0SRob Clark {
87f97decacSJordan Crouse struct msm_ringbuffer *ring = gpu->rb[0];
887198e6b0SRob Clark
897198e6b0SRob Clark OUT_PKT3(ring, CP_ME_INIT, 17);
907198e6b0SRob Clark OUT_RING(ring, 0x000003f7);
917198e6b0SRob Clark OUT_RING(ring, 0x00000000);
927198e6b0SRob Clark OUT_RING(ring, 0x00000000);
937198e6b0SRob Clark OUT_RING(ring, 0x00000000);
947198e6b0SRob Clark OUT_RING(ring, 0x00000080);
957198e6b0SRob Clark OUT_RING(ring, 0x00000100);
967198e6b0SRob Clark OUT_RING(ring, 0x00000180);
977198e6b0SRob Clark OUT_RING(ring, 0x00006600);
987198e6b0SRob Clark OUT_RING(ring, 0x00000150);
997198e6b0SRob Clark OUT_RING(ring, 0x0000014e);
1007198e6b0SRob Clark OUT_RING(ring, 0x00000154);
1017198e6b0SRob Clark OUT_RING(ring, 0x00000001);
1027198e6b0SRob Clark OUT_RING(ring, 0x00000000);
1037198e6b0SRob Clark OUT_RING(ring, 0x00000000);
1047198e6b0SRob Clark OUT_RING(ring, 0x00000000);
1057198e6b0SRob Clark OUT_RING(ring, 0x00000000);
1067198e6b0SRob Clark OUT_RING(ring, 0x00000000);
1077198e6b0SRob Clark
1082fb7487aSJordan Crouse adreno_flush(gpu, ring, REG_AXXX_CP_RB_WPTR);
109e895c7bdSJordan Crouse return a3xx_idle(gpu);
1107198e6b0SRob Clark }
1117198e6b0SRob Clark
a3xx_hw_init(struct msm_gpu * gpu)1127198e6b0SRob Clark static int a3xx_hw_init(struct msm_gpu *gpu)
1137198e6b0SRob Clark {
1147198e6b0SRob Clark struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
11555459968SRob Clark struct a3xx_gpu *a3xx_gpu = to_a3xx_gpu(adreno_gpu);
1167198e6b0SRob Clark uint32_t *ptr, len;
1177198e6b0SRob Clark int i, ret;
1187198e6b0SRob Clark
1197198e6b0SRob Clark DBG("%s", gpu->name);
1207198e6b0SRob Clark
1217198e6b0SRob Clark if (adreno_is_a305(adreno_gpu)) {
1227198e6b0SRob Clark /* Set up 16 deep read/write request queues: */
1237198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_IN_RD_LIM_CONF0, 0x10101010);
1247198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_IN_RD_LIM_CONF1, 0x10101010);
1257198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_RD_LIM_CONF0, 0x10101010);
1267198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_WR_LIM_CONF0, 0x10101010);
1277198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_DDR_OUT_MAX_BURST, 0x0000303);
1287198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_IN_WR_LIM_CONF0, 0x10101010);
1297198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_IN_WR_LIM_CONF1, 0x10101010);
1307198e6b0SRob Clark /* Enable WR-REQ: */
1317198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_GATE_OFF_WRREQ_EN, 0x0000ff);
1327198e6b0SRob Clark /* Set up round robin arbitration between both AXI ports: */
1337198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_ARB_CTL, 0x00000030);
1347198e6b0SRob Clark /* Set up AOOO: */
1357198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_AXI_AOOO_EN, 0x0000003c);
1367198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_AXI_AOOO, 0x003c003c);
1373d6ab124SLuca Weiss } else if (adreno_is_a305b(adreno_gpu)) {
1383d6ab124SLuca Weiss gpu_write(gpu, REG_A3XX_VBIF_IN_RD_LIM_CONF0, 0x00181818);
1393d6ab124SLuca Weiss gpu_write(gpu, REG_A3XX_VBIF_IN_WR_LIM_CONF0, 0x00181818);
1403d6ab124SLuca Weiss gpu_write(gpu, REG_A3XX_VBIF_OUT_RD_LIM_CONF0, 0x00000018);
1413d6ab124SLuca Weiss gpu_write(gpu, REG_A3XX_VBIF_OUT_WR_LIM_CONF0, 0x00000018);
1423d6ab124SLuca Weiss gpu_write(gpu, REG_A3XX_VBIF_DDR_OUT_MAX_BURST, 0x00000303);
1433d6ab124SLuca Weiss gpu_write(gpu, REG_A3XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x0003);
144de558cd2SRob Clark } else if (adreno_is_a306(adreno_gpu)) {
145de558cd2SRob Clark gpu_write(gpu, REG_A3XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x0003);
146de558cd2SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_RD_LIM_CONF0, 0x0000000a);
147de558cd2SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_WR_LIM_CONF0, 0x0000000a);
148*a14b929bSOtto Pflüger } else if (adreno_is_a306a(adreno_gpu)) {
149*a14b929bSOtto Pflüger gpu_write(gpu, REG_A3XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x0003);
150*a14b929bSOtto Pflüger gpu_write(gpu, REG_A3XX_VBIF_OUT_RD_LIM_CONF0, 0x00000010);
151*a14b929bSOtto Pflüger gpu_write(gpu, REG_A3XX_VBIF_OUT_WR_LIM_CONF0, 0x00000010);
1527198e6b0SRob Clark } else if (adreno_is_a320(adreno_gpu)) {
1537198e6b0SRob Clark /* Set up 16 deep read/write request queues: */
1547198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_IN_RD_LIM_CONF0, 0x10101010);
1557198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_IN_RD_LIM_CONF1, 0x10101010);
1567198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_RD_LIM_CONF0, 0x10101010);
1577198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_WR_LIM_CONF0, 0x10101010);
1587198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_DDR_OUT_MAX_BURST, 0x0000303);
1597198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_IN_WR_LIM_CONF0, 0x10101010);
1607198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_IN_WR_LIM_CONF1, 0x10101010);
1617198e6b0SRob Clark /* Enable WR-REQ: */
1627198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_GATE_OFF_WRREQ_EN, 0x0000ff);
1637198e6b0SRob Clark /* Set up round robin arbitration between both AXI ports: */
1647198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_ARB_CTL, 0x00000030);
1657198e6b0SRob Clark /* Set up AOOO: */
1667198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_AXI_AOOO_EN, 0x0000003c);
1677198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_AXI_AOOO, 0x003c003c);
1687198e6b0SRob Clark /* Enable 1K sort: */
1697198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_ABIT_SORT, 0x000000ff);
1707198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_ABIT_SORT_CONF, 0x000000a4);
1717198e6b0SRob Clark
17255459968SRob Clark } else if (adreno_is_a330v2(adreno_gpu)) {
17355459968SRob Clark /*
17455459968SRob Clark * Most of the VBIF registers on 8974v2 have the correct
17555459968SRob Clark * values at power on, so we won't modify those if we don't
17655459968SRob Clark * need to
17755459968SRob Clark */
17855459968SRob Clark /* Enable 1k sort: */
17955459968SRob Clark gpu_write(gpu, REG_A3XX_VBIF_ABIT_SORT, 0x0001003f);
18055459968SRob Clark gpu_write(gpu, REG_A3XX_VBIF_ABIT_SORT_CONF, 0x000000a4);
18155459968SRob Clark /* Enable WR-REQ: */
18255459968SRob Clark gpu_write(gpu, REG_A3XX_VBIF_GATE_OFF_WRREQ_EN, 0x00003f);
18355459968SRob Clark gpu_write(gpu, REG_A3XX_VBIF_DDR_OUT_MAX_BURST, 0x0000303);
18455459968SRob Clark /* Set up VBIF_ROUND_ROBIN_QOS_ARB: */
18555459968SRob Clark gpu_write(gpu, REG_A3XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x0003);
18655459968SRob Clark
1877198e6b0SRob Clark } else if (adreno_is_a330(adreno_gpu)) {
1887198e6b0SRob Clark /* Set up 16 deep read/write request queues: */
1897198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_IN_RD_LIM_CONF0, 0x18181818);
1907198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_IN_RD_LIM_CONF1, 0x18181818);
1917198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_RD_LIM_CONF0, 0x18181818);
1927198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_WR_LIM_CONF0, 0x18181818);
1937198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_DDR_OUT_MAX_BURST, 0x0000303);
1947198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_IN_WR_LIM_CONF0, 0x18181818);
1957198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_IN_WR_LIM_CONF1, 0x18181818);
1967198e6b0SRob Clark /* Enable WR-REQ: */
1977198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_GATE_OFF_WRREQ_EN, 0x00003f);
1987198e6b0SRob Clark /* Set up round robin arbitration between both AXI ports: */
1997198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_ARB_CTL, 0x00000030);
2007198e6b0SRob Clark /* Set up VBIF_ROUND_ROBIN_QOS_ARB: */
2017198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x0001);
2027198e6b0SRob Clark /* Set up AOOO: */
20355459968SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_AXI_AOOO_EN, 0x0000003f);
20455459968SRob Clark gpu_write(gpu, REG_A3XX_VBIF_OUT_AXI_AOOO, 0x003f003f);
2057198e6b0SRob Clark /* Enable 1K sort: */
20655459968SRob Clark gpu_write(gpu, REG_A3XX_VBIF_ABIT_SORT, 0x0001003f);
2077198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_ABIT_SORT_CONF, 0x000000a4);
2087198e6b0SRob Clark /* Disable VBIF clock gating. This is to enable AXI running
2097198e6b0SRob Clark * higher frequency than GPU:
2107198e6b0SRob Clark */
2117198e6b0SRob Clark gpu_write(gpu, REG_A3XX_VBIF_CLKON, 0x00000001);
2127198e6b0SRob Clark
2137198e6b0SRob Clark } else {
2147198e6b0SRob Clark BUG();
2157198e6b0SRob Clark }
2167198e6b0SRob Clark
2177198e6b0SRob Clark /* Make all blocks contribute to the GPU BUSY perf counter: */
2187198e6b0SRob Clark gpu_write(gpu, REG_A3XX_RBBM_GPU_BUSY_MASKED, 0xffffffff);
2197198e6b0SRob Clark
2207198e6b0SRob Clark /* Tune the hystersis counters for SP and CP idle detection: */
2217198e6b0SRob Clark gpu_write(gpu, REG_A3XX_RBBM_SP_HYST_CNT, 0x10);
2227198e6b0SRob Clark gpu_write(gpu, REG_A3XX_RBBM_WAIT_IDLE_CLOCKS_CTL, 0x10);
2237198e6b0SRob Clark
2247198e6b0SRob Clark /* Enable the RBBM error reporting bits. This lets us get
2257198e6b0SRob Clark * useful information on failure:
2267198e6b0SRob Clark */
2277198e6b0SRob Clark gpu_write(gpu, REG_A3XX_RBBM_AHB_CTL0, 0x00000001);
2287198e6b0SRob Clark
2297198e6b0SRob Clark /* Enable AHB error reporting: */
2307198e6b0SRob Clark gpu_write(gpu, REG_A3XX_RBBM_AHB_CTL1, 0xa6ffffff);
2317198e6b0SRob Clark
2327198e6b0SRob Clark /* Turn on the power counters: */
2337198e6b0SRob Clark gpu_write(gpu, REG_A3XX_RBBM_RBBM_CTL, 0x00030000);
2347198e6b0SRob Clark
2357198e6b0SRob Clark /* Turn on hang detection - this spews a lot of useful information
2367198e6b0SRob Clark * into the RBBM registers on a hang:
2377198e6b0SRob Clark */
2387198e6b0SRob Clark gpu_write(gpu, REG_A3XX_RBBM_INTERFACE_HANG_INT_CTL, 0x00010fff);
2397198e6b0SRob Clark
2407198e6b0SRob Clark /* Enable 64-byte cacheline size. HW Default is 32-byte (0x000000E0): */
2417198e6b0SRob Clark gpu_write(gpu, REG_A3XX_UCHE_CACHE_MODE_CONTROL_REG, 0x00000001);
2427198e6b0SRob Clark
2437198e6b0SRob Clark /* Enable Clock gating: */
244*a14b929bSOtto Pflüger if (adreno_is_a305b(adreno_gpu) ||
245*a14b929bSOtto Pflüger adreno_is_a306(adreno_gpu) ||
246*a14b929bSOtto Pflüger adreno_is_a306a(adreno_gpu))
247de558cd2SRob Clark gpu_write(gpu, REG_A3XX_RBBM_CLOCK_CTL, 0xaaaaaaaa);
248de558cd2SRob Clark else if (adreno_is_a320(adreno_gpu))
2497198e6b0SRob Clark gpu_write(gpu, REG_A3XX_RBBM_CLOCK_CTL, 0xbfffffff);
25055459968SRob Clark else if (adreno_is_a330v2(adreno_gpu))
25155459968SRob Clark gpu_write(gpu, REG_A3XX_RBBM_CLOCK_CTL, 0xaaaaaaaa);
25255459968SRob Clark else if (adreno_is_a330(adreno_gpu))
25355459968SRob Clark gpu_write(gpu, REG_A3XX_RBBM_CLOCK_CTL, 0xbffcffff);
2547198e6b0SRob Clark
25555459968SRob Clark if (adreno_is_a330v2(adreno_gpu))
25655459968SRob Clark gpu_write(gpu, REG_A3XX_RBBM_GPR0_CTL, 0x05515455);
25755459968SRob Clark else if (adreno_is_a330(adreno_gpu))
25855459968SRob Clark gpu_write(gpu, REG_A3XX_RBBM_GPR0_CTL, 0x00000000);
25955459968SRob Clark
26055459968SRob Clark /* Set the OCMEM base address for A330, etc */
26126c0b26dSBrian Masney if (a3xx_gpu->ocmem.hdl) {
26255459968SRob Clark gpu_write(gpu, REG_A3XX_RB_GMEM_BASE_ADDR,
26326c0b26dSBrian Masney (unsigned int)(a3xx_gpu->ocmem.base >> 14));
26455459968SRob Clark }
2657198e6b0SRob Clark
2667198e6b0SRob Clark /* Turn on performance counters: */
2677198e6b0SRob Clark gpu_write(gpu, REG_A3XX_RBBM_PERFCTR_CTL, 0x01);
2687198e6b0SRob Clark
26970c70f09SRob Clark /* Enable the perfcntrs that we use.. */
27070c70f09SRob Clark for (i = 0; i < gpu->num_perfcntrs; i++) {
27170c70f09SRob Clark const struct msm_gpu_perfcntr *perfcntr = &gpu->perfcntrs[i];
27270c70f09SRob Clark gpu_write(gpu, perfcntr->select_reg, perfcntr->select_val);
27370c70f09SRob Clark }
2747198e6b0SRob Clark
2757198e6b0SRob Clark gpu_write(gpu, REG_A3XX_RBBM_INT_0_MASK, A3XX_INT0_MASK);
2767198e6b0SRob Clark
2777198e6b0SRob Clark ret = adreno_hw_init(gpu);
2787198e6b0SRob Clark if (ret)
2797198e6b0SRob Clark return ret;
2807198e6b0SRob Clark
281f6828e0cSJordan Crouse /*
282f6828e0cSJordan Crouse * Use the default ringbuffer size and block size but disable the RPTR
283f6828e0cSJordan Crouse * shadow
284f6828e0cSJordan Crouse */
285f6828e0cSJordan Crouse gpu_write(gpu, REG_AXXX_CP_RB_CNTL,
286f6828e0cSJordan Crouse MSM_GPU_RB_CNTL_DEFAULT | AXXX_CP_RB_CNTL_NO_UPDATE);
287f6828e0cSJordan Crouse
288f6828e0cSJordan Crouse /* Set the ringbuffer address */
289f6828e0cSJordan Crouse gpu_write(gpu, REG_AXXX_CP_RB_BASE, lower_32_bits(gpu->rb[0]->iova));
290f6828e0cSJordan Crouse
2917198e6b0SRob Clark /* setup access protection: */
2927198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT_CTRL, 0x00000007);
2937198e6b0SRob Clark
2947198e6b0SRob Clark /* RBBM registers */
2957198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT(0), 0x63000040);
2967198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT(1), 0x62000080);
2977198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT(2), 0x600000cc);
2987198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT(3), 0x60000108);
2997198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT(4), 0x64000140);
3007198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT(5), 0x66000400);
3017198e6b0SRob Clark
3027198e6b0SRob Clark /* CP registers */
3037198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT(6), 0x65000700);
3047198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT(7), 0x610007d8);
3057198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT(8), 0x620007e0);
3067198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT(9), 0x61001178);
3077198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT(10), 0x64001180);
3087198e6b0SRob Clark
3097198e6b0SRob Clark /* RB registers */
3107198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT(11), 0x60003300);
3117198e6b0SRob Clark
3127198e6b0SRob Clark /* VBIF registers */
3137198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PROTECT(12), 0x6b00c000);
3147198e6b0SRob Clark
3157198e6b0SRob Clark /* NOTE: PM4/micro-engine firmware registers look to be the same
3167198e6b0SRob Clark * for a2xx and a3xx.. we could possibly push that part down to
3177198e6b0SRob Clark * adreno_gpu base class. Or push both PM4 and PFP but
3187198e6b0SRob Clark * parameterize the pfp ucode addr/data registers..
3197198e6b0SRob Clark */
3207198e6b0SRob Clark
3217198e6b0SRob Clark /* Load PM4: */
322c5e3548cSJordan Crouse ptr = (uint32_t *)(adreno_gpu->fw[ADRENO_FW_PM4]->data);
323c5e3548cSJordan Crouse len = adreno_gpu->fw[ADRENO_FW_PM4]->size / 4;
324e529c7e6SRob Clark DBG("loading PM4 ucode version: %x", ptr[1]);
3257198e6b0SRob Clark
3267198e6b0SRob Clark gpu_write(gpu, REG_AXXX_CP_DEBUG,
3277198e6b0SRob Clark AXXX_CP_DEBUG_DYNAMIC_CLK_DISABLE |
3287198e6b0SRob Clark AXXX_CP_DEBUG_MIU_128BIT_WRITE_ENABLE);
3297198e6b0SRob Clark gpu_write(gpu, REG_AXXX_CP_ME_RAM_WADDR, 0);
3307198e6b0SRob Clark for (i = 1; i < len; i++)
3317198e6b0SRob Clark gpu_write(gpu, REG_AXXX_CP_ME_RAM_DATA, ptr[i]);
3327198e6b0SRob Clark
3337198e6b0SRob Clark /* Load PFP: */
334c5e3548cSJordan Crouse ptr = (uint32_t *)(adreno_gpu->fw[ADRENO_FW_PFP]->data);
335c5e3548cSJordan Crouse len = adreno_gpu->fw[ADRENO_FW_PFP]->size / 4;
336e529c7e6SRob Clark DBG("loading PFP ucode version: %x", ptr[5]);
3377198e6b0SRob Clark
3387198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PFP_UCODE_ADDR, 0);
3397198e6b0SRob Clark for (i = 1; i < len; i++)
3407198e6b0SRob Clark gpu_write(gpu, REG_A3XX_CP_PFP_UCODE_DATA, ptr[i]);
3417198e6b0SRob Clark
3427198e6b0SRob Clark /* CP ROQ queue sizes (bytes) - RB:16, ST:16, IB1:32, IB2:64 */
343*a14b929bSOtto Pflüger if (adreno_is_a305(adreno_gpu) ||
344*a14b929bSOtto Pflüger adreno_is_a306(adreno_gpu) ||
345*a14b929bSOtto Pflüger adreno_is_a306a(adreno_gpu) ||
346de558cd2SRob Clark adreno_is_a320(adreno_gpu)) {
3477198e6b0SRob Clark gpu_write(gpu, REG_AXXX_CP_QUEUE_THRESHOLDS,
3487198e6b0SRob Clark AXXX_CP_QUEUE_THRESHOLDS_CSQ_IB1_START(2) |
3497198e6b0SRob Clark AXXX_CP_QUEUE_THRESHOLDS_CSQ_IB2_START(6) |
3507198e6b0SRob Clark AXXX_CP_QUEUE_THRESHOLDS_CSQ_ST_START(14));
3513d6ab124SLuca Weiss } else if (adreno_is_a330(adreno_gpu) || adreno_is_a305b(adreno_gpu)) {
35255459968SRob Clark /* NOTE: this (value take from downstream android driver)
35355459968SRob Clark * includes some bits outside of the known bitfields. But
35455459968SRob Clark * A330 has this "MERCIU queue" thing too, which might
35555459968SRob Clark * explain a new bitfield or reshuffling:
35655459968SRob Clark */
35755459968SRob Clark gpu_write(gpu, REG_AXXX_CP_QUEUE_THRESHOLDS, 0x003e2008);
35855459968SRob Clark }
3597198e6b0SRob Clark
3607198e6b0SRob Clark /* clear ME_HALT to start micro engine */
3617198e6b0SRob Clark gpu_write(gpu, REG_AXXX_CP_ME_CNTL, 0);
3627198e6b0SRob Clark
363c4a8d475SJordan Crouse return a3xx_me_init(gpu) ? 0 : -EINVAL;
3647198e6b0SRob Clark }
3657198e6b0SRob Clark
a3xx_recover(struct msm_gpu * gpu)36655459968SRob Clark static void a3xx_recover(struct msm_gpu *gpu)
36755459968SRob Clark {
368398efc46SRob Clark int i;
369398efc46SRob Clark
37026716185SRob Clark adreno_dump_info(gpu);
37126716185SRob Clark
372398efc46SRob Clark for (i = 0; i < 8; i++) {
373398efc46SRob Clark printk("CP_SCRATCH_REG%d: %u\n", i,
374398efc46SRob Clark gpu_read(gpu, REG_AXXX_CP_SCRATCH_REG0 + i));
375398efc46SRob Clark }
376398efc46SRob Clark
3775b6ef08eSRob Clark /* dump registers before resetting gpu, if enabled: */
3785b6ef08eSRob Clark if (hang_debug)
3795b6ef08eSRob Clark a3xx_dump(gpu);
38026716185SRob Clark
38155459968SRob Clark gpu_write(gpu, REG_A3XX_RBBM_SW_RESET_CMD, 1);
38255459968SRob Clark gpu_read(gpu, REG_A3XX_RBBM_SW_RESET_CMD);
38355459968SRob Clark gpu_write(gpu, REG_A3XX_RBBM_SW_RESET_CMD, 0);
38455459968SRob Clark adreno_recover(gpu);
38555459968SRob Clark }
38655459968SRob Clark
a3xx_destroy(struct msm_gpu * gpu)3877198e6b0SRob Clark static void a3xx_destroy(struct msm_gpu *gpu)
3887198e6b0SRob Clark {
3897198e6b0SRob Clark struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
3907198e6b0SRob Clark struct a3xx_gpu *a3xx_gpu = to_a3xx_gpu(adreno_gpu);
3917198e6b0SRob Clark
3927198e6b0SRob Clark DBG("%s", gpu->name);
3937198e6b0SRob Clark
3947198e6b0SRob Clark adreno_gpu_cleanup(adreno_gpu);
39555459968SRob Clark
39626c0b26dSBrian Masney adreno_gpu_ocmem_cleanup(&a3xx_gpu->ocmem);
39755459968SRob Clark
3987198e6b0SRob Clark kfree(a3xx_gpu);
3997198e6b0SRob Clark }
4007198e6b0SRob Clark
a3xx_idle(struct msm_gpu * gpu)401c4a8d475SJordan Crouse static bool a3xx_idle(struct msm_gpu *gpu)
4027198e6b0SRob Clark {
4037198e6b0SRob Clark /* wait for ringbuffer to drain: */
404f97decacSJordan Crouse if (!adreno_idle(gpu, gpu->rb[0]))
405c4a8d475SJordan Crouse return false;
4067198e6b0SRob Clark
4077198e6b0SRob Clark /* then wait for GPU to finish: */
4080963756fSRob Clark if (spin_until(!(gpu_read(gpu, REG_A3XX_RBBM_STATUS) &
409c4a8d475SJordan Crouse A3XX_RBBM_STATUS_GPU_BUSY))) {
4100963756fSRob Clark DRM_ERROR("%s: timeout waiting for GPU to idle!\n", gpu->name);
4117198e6b0SRob Clark
4127198e6b0SRob Clark /* TODO maybe we need to reset GPU here to recover from hang? */
413c4a8d475SJordan Crouse return false;
414c4a8d475SJordan Crouse }
415c4a8d475SJordan Crouse
416c4a8d475SJordan Crouse return true;
4177198e6b0SRob Clark }
4187198e6b0SRob Clark
a3xx_irq(struct msm_gpu * gpu)4197198e6b0SRob Clark static irqreturn_t a3xx_irq(struct msm_gpu *gpu)
4207198e6b0SRob Clark {
4217198e6b0SRob Clark uint32_t status;
4227198e6b0SRob Clark
4237198e6b0SRob Clark status = gpu_read(gpu, REG_A3XX_RBBM_INT_0_STATUS);
4247198e6b0SRob Clark DBG("%s: %08x", gpu->name, status);
4257198e6b0SRob Clark
4267198e6b0SRob Clark // TODO
4277198e6b0SRob Clark
4287198e6b0SRob Clark gpu_write(gpu, REG_A3XX_RBBM_INT_CLEAR_CMD, status);
4297198e6b0SRob Clark
4307198e6b0SRob Clark msm_gpu_retire(gpu);
4317198e6b0SRob Clark
4327198e6b0SRob Clark return IRQ_HANDLED;
4337198e6b0SRob Clark }
4347198e6b0SRob Clark
4357198e6b0SRob Clark static const unsigned int a3xx_registers[] = {
4367198e6b0SRob Clark 0x0000, 0x0002, 0x0010, 0x0012, 0x0018, 0x0018, 0x0020, 0x0027,
4377198e6b0SRob Clark 0x0029, 0x002b, 0x002e, 0x0033, 0x0040, 0x0042, 0x0050, 0x005c,
4387198e6b0SRob Clark 0x0060, 0x006c, 0x0080, 0x0082, 0x0084, 0x0088, 0x0090, 0x00e5,
4397198e6b0SRob Clark 0x00ea, 0x00ed, 0x0100, 0x0100, 0x0110, 0x0123, 0x01c0, 0x01c1,
4407198e6b0SRob Clark 0x01c3, 0x01c5, 0x01c7, 0x01c7, 0x01d5, 0x01d9, 0x01dc, 0x01dd,
4417198e6b0SRob Clark 0x01ea, 0x01ea, 0x01ee, 0x01f1, 0x01f5, 0x01f5, 0x01fc, 0x01ff,
4427198e6b0SRob Clark 0x0440, 0x0440, 0x0443, 0x0443, 0x0445, 0x0445, 0x044d, 0x044f,
4437198e6b0SRob Clark 0x0452, 0x0452, 0x0454, 0x046f, 0x047c, 0x047c, 0x047f, 0x047f,
4447198e6b0SRob Clark 0x0578, 0x057f, 0x0600, 0x0602, 0x0605, 0x0607, 0x060a, 0x060e,
4457198e6b0SRob Clark 0x0612, 0x0614, 0x0c01, 0x0c02, 0x0c06, 0x0c1d, 0x0c3d, 0x0c3f,
4467198e6b0SRob Clark 0x0c48, 0x0c4b, 0x0c80, 0x0c80, 0x0c88, 0x0c8b, 0x0ca0, 0x0cb7,
4477198e6b0SRob Clark 0x0cc0, 0x0cc1, 0x0cc6, 0x0cc7, 0x0ce4, 0x0ce5, 0x0e00, 0x0e05,
4487198e6b0SRob Clark 0x0e0c, 0x0e0c, 0x0e22, 0x0e23, 0x0e41, 0x0e45, 0x0e64, 0x0e65,
4497198e6b0SRob Clark 0x0e80, 0x0e82, 0x0e84, 0x0e89, 0x0ea0, 0x0ea1, 0x0ea4, 0x0ea7,
4507198e6b0SRob Clark 0x0ec4, 0x0ecb, 0x0ee0, 0x0ee0, 0x0f00, 0x0f01, 0x0f03, 0x0f09,
4517198e6b0SRob Clark 0x2040, 0x2040, 0x2044, 0x2044, 0x2048, 0x204d, 0x2068, 0x2069,
4527198e6b0SRob Clark 0x206c, 0x206d, 0x2070, 0x2070, 0x2072, 0x2072, 0x2074, 0x2075,
4537198e6b0SRob Clark 0x2079, 0x207a, 0x20c0, 0x20d3, 0x20e4, 0x20ef, 0x2100, 0x2109,
4547198e6b0SRob Clark 0x210c, 0x210c, 0x210e, 0x210e, 0x2110, 0x2111, 0x2114, 0x2115,
4557198e6b0SRob Clark 0x21e4, 0x21e4, 0x21ea, 0x21ea, 0x21ec, 0x21ed, 0x21f0, 0x21f0,
4567198e6b0SRob Clark 0x2200, 0x2212, 0x2214, 0x2217, 0x221a, 0x221a, 0x2240, 0x227e,
4577198e6b0SRob Clark 0x2280, 0x228b, 0x22c0, 0x22c0, 0x22c4, 0x22ce, 0x22d0, 0x22d8,
4587198e6b0SRob Clark 0x22df, 0x22e6, 0x22e8, 0x22e9, 0x22ec, 0x22ec, 0x22f0, 0x22f7,
459f47bee2bSRob Clark 0x22ff, 0x22ff, 0x2340, 0x2343, 0x2440, 0x2440, 0x2444, 0x2444,
460f47bee2bSRob Clark 0x2448, 0x244d, 0x2468, 0x2469, 0x246c, 0x246d, 0x2470, 0x2470,
461f47bee2bSRob Clark 0x2472, 0x2472, 0x2474, 0x2475, 0x2479, 0x247a, 0x24c0, 0x24d3,
462f47bee2bSRob Clark 0x24e4, 0x24ef, 0x2500, 0x2509, 0x250c, 0x250c, 0x250e, 0x250e,
463f47bee2bSRob Clark 0x2510, 0x2511, 0x2514, 0x2515, 0x25e4, 0x25e4, 0x25ea, 0x25ea,
464f47bee2bSRob Clark 0x25ec, 0x25ed, 0x25f0, 0x25f0, 0x2600, 0x2612, 0x2614, 0x2617,
465f47bee2bSRob Clark 0x261a, 0x261a, 0x2640, 0x267e, 0x2680, 0x268b, 0x26c0, 0x26c0,
466f47bee2bSRob Clark 0x26c4, 0x26ce, 0x26d0, 0x26d8, 0x26df, 0x26e6, 0x26e8, 0x26e9,
467f47bee2bSRob Clark 0x26ec, 0x26ec, 0x26f0, 0x26f7, 0x26ff, 0x26ff, 0x2740, 0x2743,
468f47bee2bSRob Clark 0x300c, 0x300e, 0x301c, 0x301d, 0x302a, 0x302a, 0x302c, 0x302d,
469f47bee2bSRob Clark 0x3030, 0x3031, 0x3034, 0x3036, 0x303c, 0x303c, 0x305e, 0x305f,
4703bcefb04SRob Clark ~0 /* sentinel */
4717198e6b0SRob Clark };
4727198e6b0SRob Clark
4735b6ef08eSRob Clark /* would be nice to not have to duplicate the _show() stuff with printk(): */
a3xx_dump(struct msm_gpu * gpu)4745b6ef08eSRob Clark static void a3xx_dump(struct msm_gpu *gpu)
4755b6ef08eSRob Clark {
4765b6ef08eSRob Clark printk("status: %08x\n",
4775b6ef08eSRob Clark gpu_read(gpu, REG_A3XX_RBBM_STATUS));
4783bcefb04SRob Clark adreno_dump(gpu);
4795b6ef08eSRob Clark }
480e00e473dSJordan Crouse
a3xx_gpu_state_get(struct msm_gpu * gpu)481e00e473dSJordan Crouse static struct msm_gpu_state *a3xx_gpu_state_get(struct msm_gpu *gpu)
482e00e473dSJordan Crouse {
48350f8d218SJordan Crouse struct msm_gpu_state *state = kzalloc(sizeof(*state), GFP_KERNEL);
484e00e473dSJordan Crouse
48550f8d218SJordan Crouse if (!state)
48650f8d218SJordan Crouse return ERR_PTR(-ENOMEM);
48750f8d218SJordan Crouse
48850f8d218SJordan Crouse adreno_gpu_state_get(gpu, state);
489e00e473dSJordan Crouse
490e00e473dSJordan Crouse state->rbbm_status = gpu_read(gpu, REG_A3XX_RBBM_STATUS);
491e00e473dSJordan Crouse
492e00e473dSJordan Crouse return state;
493e00e473dSJordan Crouse }
494e00e473dSJordan Crouse
a3xx_gpu_busy(struct msm_gpu * gpu,unsigned long * out_sample_rate)495a9cf6e7fSKonrad Dybcio static u64 a3xx_gpu_busy(struct msm_gpu *gpu, unsigned long *out_sample_rate)
496a9cf6e7fSKonrad Dybcio {
497a9cf6e7fSKonrad Dybcio u64 busy_cycles;
498a9cf6e7fSKonrad Dybcio
499a9cf6e7fSKonrad Dybcio busy_cycles = gpu_read64(gpu, REG_A3XX_RBBM_PERFCTR_RBBM_1_LO);
500a9cf6e7fSKonrad Dybcio *out_sample_rate = clk_get_rate(gpu->core_clk);
501a9cf6e7fSKonrad Dybcio
502a9cf6e7fSKonrad Dybcio return busy_cycles;
503a9cf6e7fSKonrad Dybcio }
504a9cf6e7fSKonrad Dybcio
a3xx_get_rptr(struct msm_gpu * gpu,struct msm_ringbuffer * ring)5052fb7487aSJordan Crouse static u32 a3xx_get_rptr(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
5062fb7487aSJordan Crouse {
5072fb7487aSJordan Crouse ring->memptrs->rptr = gpu_read(gpu, REG_AXXX_CP_RB_RPTR);
5082fb7487aSJordan Crouse return ring->memptrs->rptr;
5092fb7487aSJordan Crouse }
5105b6ef08eSRob Clark
5117198e6b0SRob Clark static const struct adreno_gpu_funcs funcs = {
5127198e6b0SRob Clark .base = {
5137198e6b0SRob Clark .get_param = adreno_get_param,
514f7ddbf55SRob Clark .set_param = adreno_set_param,
5157198e6b0SRob Clark .hw_init = a3xx_hw_init,
5167198e6b0SRob Clark .pm_suspend = msm_gpu_pm_suspend,
5177198e6b0SRob Clark .pm_resume = msm_gpu_pm_resume,
51855459968SRob Clark .recover = a3xx_recover,
5192fb7487aSJordan Crouse .submit = a3xx_submit,
520f97decacSJordan Crouse .active_ring = adreno_active_ring,
5217198e6b0SRob Clark .irq = a3xx_irq,
5227198e6b0SRob Clark .destroy = a3xx_destroy,
523c0fec7f5SJordan Crouse #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP)
5244f776f45SJordan Crouse .show = adreno_show,
5257198e6b0SRob Clark #endif
526a9cf6e7fSKonrad Dybcio .gpu_busy = a3xx_gpu_busy,
527e00e473dSJordan Crouse .gpu_state_get = a3xx_gpu_state_get,
528e00e473dSJordan Crouse .gpu_state_put = adreno_gpu_state_put,
529822ff993SDmitry Baryshkov .create_address_space = adreno_create_address_space,
5302fb7487aSJordan Crouse .get_rptr = a3xx_get_rptr,
5317198e6b0SRob Clark },
5327198e6b0SRob Clark };
5337198e6b0SRob Clark
53470c70f09SRob Clark static const struct msm_gpu_perfcntr perfcntrs[] = {
53570c70f09SRob Clark { REG_A3XX_SP_PERFCOUNTER6_SELECT, REG_A3XX_RBBM_PERFCTR_SP_6_LO,
53670c70f09SRob Clark SP_ALU_ACTIVE_CYCLES, "ALUACTIVE" },
53770c70f09SRob Clark { REG_A3XX_SP_PERFCOUNTER7_SELECT, REG_A3XX_RBBM_PERFCTR_SP_7_LO,
53870c70f09SRob Clark SP_FS_FULL_ALU_INSTRUCTIONS, "ALUFULL" },
53970c70f09SRob Clark };
54070c70f09SRob Clark
a3xx_gpu_init(struct drm_device * dev)5417198e6b0SRob Clark struct msm_gpu *a3xx_gpu_init(struct drm_device *dev)
5427198e6b0SRob Clark {
5437198e6b0SRob Clark struct a3xx_gpu *a3xx_gpu = NULL;
54455459968SRob Clark struct adreno_gpu *adreno_gpu;
5457198e6b0SRob Clark struct msm_gpu *gpu;
546060530f1SRob Clark struct msm_drm_private *priv = dev->dev_private;
547060530f1SRob Clark struct platform_device *pdev = priv->gpu_pdev;
5485785dd7aSAkhil P Oommen struct icc_path *ocmem_icc_path;
5495785dd7aSAkhil P Oommen struct icc_path *icc_path;
5507198e6b0SRob Clark int ret;
5517198e6b0SRob Clark
5527198e6b0SRob Clark if (!pdev) {
5536a41da17SMamta Shukla DRM_DEV_ERROR(dev->dev, "no a3xx device\n");
5547198e6b0SRob Clark ret = -ENXIO;
5557198e6b0SRob Clark goto fail;
5567198e6b0SRob Clark }
5577198e6b0SRob Clark
5587198e6b0SRob Clark a3xx_gpu = kzalloc(sizeof(*a3xx_gpu), GFP_KERNEL);
5597198e6b0SRob Clark if (!a3xx_gpu) {
5607198e6b0SRob Clark ret = -ENOMEM;
5617198e6b0SRob Clark goto fail;
5627198e6b0SRob Clark }
5637198e6b0SRob Clark
56455459968SRob Clark adreno_gpu = &a3xx_gpu->base;
56555459968SRob Clark gpu = &adreno_gpu->base;
5667198e6b0SRob Clark
56770c70f09SRob Clark gpu->perfcntrs = perfcntrs;
56870c70f09SRob Clark gpu->num_perfcntrs = ARRAY_SIZE(perfcntrs);
56970c70f09SRob Clark
5703bcefb04SRob Clark adreno_gpu->registers = a3xx_registers;
5713bcefb04SRob Clark
572f97decacSJordan Crouse ret = adreno_gpu_init(dev, pdev, adreno_gpu, &funcs, 1);
5737198e6b0SRob Clark if (ret)
5747198e6b0SRob Clark goto fail;
5757198e6b0SRob Clark
57655459968SRob Clark /* if needed, allocate gmem: */
5773d6ab124SLuca Weiss if (adreno_is_a330(adreno_gpu) || adreno_is_a305b(adreno_gpu)) {
57826c0b26dSBrian Masney ret = adreno_gpu_ocmem_init(&adreno_gpu->base.pdev->dev,
57926c0b26dSBrian Masney adreno_gpu, &a3xx_gpu->ocmem);
58026c0b26dSBrian Masney if (ret)
58126c0b26dSBrian Masney goto fail;
58255459968SRob Clark }
58355459968SRob Clark
584667ce33eSRob Clark if (!gpu->aspace) {
585871d812aSRob Clark /* TODO we think it is possible to configure the GPU to
586871d812aSRob Clark * restrict access to VRAM carveout. But the required
587871d812aSRob Clark * registers are unknown. For now just bail out and
588871d812aSRob Clark * limp along with just modesetting. If it turns out
589871d812aSRob Clark * to not be possible to restrict access, then we must
590871d812aSRob Clark * implement a cmdstream validator.
591871d812aSRob Clark */
5926a41da17SMamta Shukla DRM_DEV_ERROR(dev->dev, "No memory protection without IOMMU\n");
5933f7759e7SIskren Chernev if (!allow_vram_carveout) {
594871d812aSRob Clark ret = -ENXIO;
595871d812aSRob Clark goto fail;
596871d812aSRob Clark }
5973f7759e7SIskren Chernev }
598871d812aSRob Clark
5995785dd7aSAkhil P Oommen icc_path = devm_of_icc_get(&pdev->dev, "gfx-mem");
6003eda9019SDan Carpenter if (IS_ERR(icc_path)) {
6013eda9019SDan Carpenter ret = PTR_ERR(icc_path);
6025785dd7aSAkhil P Oommen goto fail;
6033eda9019SDan Carpenter }
6045785dd7aSAkhil P Oommen
6055785dd7aSAkhil P Oommen ocmem_icc_path = devm_of_icc_get(&pdev->dev, "ocmem");
6063eda9019SDan Carpenter if (IS_ERR(ocmem_icc_path)) {
6073eda9019SDan Carpenter ret = PTR_ERR(ocmem_icc_path);
6085785dd7aSAkhil P Oommen /* allow -ENODATA, ocmem icc is optional */
6095785dd7aSAkhil P Oommen if (ret != -ENODATA)
6105785dd7aSAkhil P Oommen goto fail;
6115785dd7aSAkhil P Oommen ocmem_icc_path = NULL;
6125785dd7aSAkhil P Oommen }
6135785dd7aSAkhil P Oommen
6145785dd7aSAkhil P Oommen
615d163ba0bSBrian Masney /*
616d163ba0bSBrian Masney * Set the ICC path to maximum speed for now by multiplying the fastest
617d163ba0bSBrian Masney * frequency by the bus width (8). We'll want to scale this later on to
618d163ba0bSBrian Masney * improve battery life.
619d163ba0bSBrian Masney */
6205785dd7aSAkhil P Oommen icc_set_bw(icc_path, 0, Bps_to_icc(gpu->fast_rate) * 8);
6215785dd7aSAkhil P Oommen icc_set_bw(ocmem_icc_path, 0, Bps_to_icc(gpu->fast_rate) * 8);
622d163ba0bSBrian Masney
623871d812aSRob Clark return gpu;
6247198e6b0SRob Clark
6257198e6b0SRob Clark fail:
6267198e6b0SRob Clark if (a3xx_gpu)
6277198e6b0SRob Clark a3xx_destroy(&a3xx_gpu->base.base);
6287198e6b0SRob Clark
6297198e6b0SRob Clark return ERR_PTR(ret);
6307198e6b0SRob Clark }
631