A618 EXECUTION FLOW DEEP CAPTURE
Generated: 2026-11-26T19:52:23
Repository: C:\Users\qwertyhorik\Desktop\GPU_TRANSFER_2026-11-26\external\qualcomm-kgsl
========== FILE: adreno_a6xx_ringbuffer.c ==========
--- LINES 6-32 ---
6:
7: #include "adreno.h"
8: #include "adreno_a6xx.h"
9: #include "adreno_pm4types.h"
10: #include "adreno_ringbuffer.h"
11: #include "adreno_trace.h"
12: #include "kgsl_trace.h"
13:
14: static int a6xx_rb_pagetable_switch(struct adreno_device *adreno_dev,
15: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt,
16: struct kgsl_pagetable *pagetable, u32 *cmds)
17: {
18: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
19: u64 ttbr0 = kgsl_mmu_pagetable_get_ttbr0(pagetable);
20: int count = 0;
21: u32 id = drawctxt ? drawctxt->base.id : 0;
22:
23: if (pagetable == device->mmu.defaultpagetable)
24: return 0;
25:
26: cmds[count++] = cp_type7_packet(CP_SMMU_TABLE_UPDATE, 3);
27: cmds[count++] = lower_32_bits(ttbr0);
28: cmds[count++] = upper_32_bits(ttbr0);
29: cmds[count++] = id;
30:
31: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) {
32: cmds[count++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0);
--- LINES 48-75 ---
48: cmds[count++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0);
49: cmds[count++] = cp_type7_packet(CP_WAIT_FOR_ME, 0);
50: cmds[count++] = cp_type4_packet(A6XX_CP_MISC_CNTL, 1);
51: cmds[count++] = 0;
52: }
53:
54: return count;
55: }
56:
57: static int a6xx_rb_context_switch(struct adreno_device *adreno_dev,
58: struct adreno_ringbuffer *rb,
59: struct adreno_context *drawctxt)
60: {
61: struct kgsl_pagetable *pagetable =
62: adreno_drawctxt_get_pagetable(drawctxt);
63: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
64: int count = 0;
65: u32 cmds[41];
66:
67: if (adreno_drawctxt_get_pagetable(rb->drawctxt_active) != pagetable) {
68:
69: /* Clear performance counters during context switches */
70: if (!adreno_dev->perfcounter) {
71: cmds[count++] = cp_type4_packet(A6XX_RBBM_PERFCTR_SRAM_INIT_CMD, 1);
72: cmds[count++] = 0x1;
73: }
74:
75: count += a6xx_rb_pagetable_switch(adreno_dev, rb, drawctxt,
--- LINES 81-577 ---
81: cmds[count++] = 0x3;
82: cmds[count++] = A6XX_RBBM_PERFCTR_SRAM_INIT_STATUS;
83: cmds[count++] = 0x0;
84: cmds[count++] = 0x1;
85: cmds[count++] = 0x1;
86: cmds[count++] = 0x0;
87: }
88: }
89:
90: cmds[count++] = cp_type7_packet(CP_NOP, 1);
91: cmds[count++] = CONTEXT_TO_MEM_IDENTIFIER;
92:
93: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3);
94: cmds[count++] = lower_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb,
95: current_context));
96: cmds[count++] = upper_32_bits(MEMSTORE_RB_GPU_ADDR(device, rb,
97: current_context));
98: cmds[count++] = drawctxt->base.id;
99:
100: cmds[count++] = cp_type7_packet(CP_MEM_WRITE, 3);
101: cmds[count++] = lower_32_bits(MEMSTORE_ID_GPU_ADDR(device,
102: KGSL_MEMSTORE_GLOBAL, current_context));
103: cmds[count++] = upper_32_bits(MEMSTORE_ID_GPU_ADDR(device,
104: KGSL_MEMSTORE_GLOBAL, current_context));
105: cmds[count++] = drawctxt->base.id;
106:
107: cmds[count++] = cp_type7_packet(CP_EVENT_WRITE, 1);
108: cmds[count++] = 0x31;
109:
110: return a6xx_ringbuffer_addcmds(adreno_dev, rb, NULL, F_NOTPROTECTED,
111: cmds, count, 0, NULL);
112: }
113:
114: #define RB_SOPTIMESTAMP(device, rb) \
115: MEMSTORE_RB_GPU_ADDR(device, rb, soptimestamp)
116: #define CTXT_SOPTIMESTAMP(device, drawctxt) \
117: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, soptimestamp)
118:
119: #define RB_EOPTIMESTAMP(device, rb) \
120: MEMSTORE_RB_GPU_ADDR(device, rb, eoptimestamp)
121: #define CTXT_EOPTIMESTAMP(device, drawctxt) \
122: MEMSTORE_ID_GPU_ADDR(device, (drawctxt)->base.id, eoptimestamp)
123:
124: int a6xx_ringbuffer_submit(struct adreno_ringbuffer *rb,
125: struct adreno_submit_time *time, bool sync)
126: {
127: struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
128: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
129: int ret = 0;
130: unsigned long flags;
131:
132: adreno_get_submit_time(adreno_dev, rb, time);
133: adreno_profile_submit_time(time);
134:
135: if (sync && !ADRENO_FEATURE(adreno_dev, ADRENO_APRIV)) {
136: u32 *cmds = adreno_ringbuffer_allocspace(rb, 3);
137:
138: if (IS_ERR(cmds))
139: return PTR_ERR(cmds);
140:
141: cmds[0] = cp_type7_packet(CP_WHERE_AM_I, 2);
142: cmds[1] = lower_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id,
143: rptr));
144: cmds[2] = upper_32_bits(SCRATCH_RB_GPU_ADDR(device, rb->id,
145: rptr));
146: }
147:
148: spin_lock_irqsave(&rb->preempt_lock, flags);
149: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE)) {
150: if (adreno_dev->cur_rb == rb) {
151: ret = a6xx_fenced_write(adreno_dev,
152: A6XX_CP_RB_WPTR, rb->_wptr,
153: FENCE_STATUS_WRITEDROPPED0_MASK);
154: rb->skip_inline_wptr = false;
155: }
156: } else {
157: if (adreno_dev->cur_rb == rb)
158: rb->skip_inline_wptr = true;
159: }
160:
161: rb->wptr = rb->_wptr;
162: spin_unlock_irqrestore(&rb->preempt_lock, flags);
163:
164: if (ret) {
165: /*
166: * If WPTR update fails, take inline snapshot and trigger
167: * recovery.
168: */
169: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE);
170: adreno_scheduler_fault(adreno_dev,
171: ADRENO_GMU_FAULT_SKIP_SNAPSHOT);
172: }
173:
174: return ret;
175: }
176:
177: int a6xx_ringbuffer_init(struct adreno_device *adreno_dev)
178: {
179: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
180: int i, ret;
181:
182: ret = adreno_allocate_global(device, &device->scratch, PAGE_SIZE,
183: 0, 0, KGSL_MEMDESC_RANDOM | KGSL_MEMDESC_PRIVILEGED,
184: "scratch");
185: if (ret)
186: return ret;
187:
188: adreno_dev->cur_rb = &(adreno_dev->ringbuffers[0]);
189:
190: if (!adreno_preemption_feature_set(adreno_dev)) {
191: adreno_dev->num_ringbuffers = 1;
192: return adreno_ringbuffer_setup(adreno_dev,
193: &adreno_dev->ringbuffers[0], 0);
194: }
195:
196: adreno_dev->num_ringbuffers = ARRAY_SIZE(adreno_dev->ringbuffers);
197:
198: for (i = 0; i < adreno_dev->num_ringbuffers; i++) {
199: int ret;
200:
201: ret = adreno_ringbuffer_setup(adreno_dev,
202: &adreno_dev->ringbuffers[i], i);
203: if (ret)
204: return ret;
205: }
206:
207: timer_setup(&adreno_dev->preempt.timer, adreno_preemption_timer, 0);
208: a6xx_preemption_init(adreno_dev);
209: return 0;
210: }
211:
212: #define A6XX_SUBMIT_MAX 79
213:
214: int a6xx_ringbuffer_addcmds(struct adreno_device *adreno_dev,
215: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt,
216: u32 flags, u32 *in, u32 dwords, u32 timestamp,
217: struct adreno_submit_time *time)
218: {
219: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
220: u32 size = A6XX_SUBMIT_MAX + dwords;
221: u32 *cmds, index = 0;
222: u64 profile_gpuaddr;
223: u32 profile_dwords;
224:
225: if (adreno_drawctxt_detached(drawctxt))
226: return -ENOENT;
227:
228: if (adreno_gpu_fault(adreno_dev) != 0)
229: return -EPROTO;
230:
231: rb->timestamp++;
232:
233: if (drawctxt)
234: drawctxt->internal_timestamp = rb->timestamp;
235:
236: /*
237: * if APRIV is enabled we assume all submissions are run with protected
238: * mode off
239: */
240: if (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV))
241: flags &= ~F_NOTPROTECTED;
242:
243: cmds = adreno_ringbuffer_allocspace(rb, size);
244: if (IS_ERR(cmds))
245: return PTR_ERR(cmds);
246:
247: /* Identify the start of a command */
248: cmds[index++] = cp_type7_packet(CP_NOP, 1);
249: cmds[index++] = drawctxt ? CMD_IDENTIFIER : CMD_INTERNAL_IDENTIFIER;
250:
251: /* This is 25 dwords when drawctxt is not NULL and perfcounter needs to be zapped */
252: index += a6xx_preemption_pre_ibsubmit(adreno_dev, rb, drawctxt,
253: &cmds[index]);
254:
255: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1);
256: cmds[index++] = 0x101; /* IFPC disable */
257:
258: profile_gpuaddr = adreno_profile_preib_processing(adreno_dev,
259: drawctxt, &profile_dwords);
260:
261: if (profile_gpuaddr) {
262: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3);
263: cmds[index++] = lower_32_bits(profile_gpuaddr);
264: cmds[index++] = upper_32_bits(profile_gpuaddr);
265: cmds[index++] = profile_dwords;
266: }
267:
268: if (drawctxt) {
269: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3);
270: cmds[index++] = lower_32_bits(CTXT_SOPTIMESTAMP(device,
271: drawctxt));
272: cmds[index++] = upper_32_bits(CTXT_SOPTIMESTAMP(device,
273: drawctxt));
274: cmds[index++] = timestamp;
275: }
276:
277: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 3);
278: cmds[index++] = lower_32_bits(RB_SOPTIMESTAMP(device, rb));
279: cmds[index++] = upper_32_bits(RB_SOPTIMESTAMP(device, rb));
280: cmds[index++] = rb->timestamp;
281:
282: if (IS_SECURE(flags)) {
283: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1);
284: cmds[index++] = 1;
285: }
286:
287: if (IS_NOTPROTECTED(flags)) {
288: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1);
289: cmds[index++] = 0;
290: }
291:
292: memcpy(&cmds[index], in, dwords << 2);
293: index += dwords;
294:
295: if (IS_NOTPROTECTED(flags)) {
296: cmds[index++] = cp_type7_packet(CP_SET_PROTECTED_MODE, 1);
297: cmds[index++] = 1;
298: }
299:
300: profile_gpuaddr = adreno_profile_postib_processing(adreno_dev,
301: drawctxt, &dwords);
302:
303: if (profile_gpuaddr) {
304: cmds[index++] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3);
305: cmds[index++] = lower_32_bits(profile_gpuaddr);
306: cmds[index++] = upper_32_bits(profile_gpuaddr);
307: cmds[index++] = profile_dwords;
308: }
309:
310: if (test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &device->mmu.pfpolicy))
311: cmds[index++] = cp_type7_packet(CP_WAIT_MEM_WRITES, 0);
312:
313: /*
314: * If this is an internal command, just write the ringbuffer timestamp,
315: * otherwise, write both
316: */
317: if (!drawctxt) {
318: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4);
319: cmds[index++] = CACHE_FLUSH_TS | (1 << 31);
320: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb));
321: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb));
322: cmds[index++] = rb->timestamp;
323: } else {
324: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4);
325: cmds[index++] = CACHE_FLUSH_TS | (1 << 31);
326: cmds[index++] = lower_32_bits(CTXT_EOPTIMESTAMP(device,
327: drawctxt));
328: cmds[index++] = upper_32_bits(CTXT_EOPTIMESTAMP(device,
329: drawctxt));
330: cmds[index++] = timestamp;
331:
332: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 4);
333: cmds[index++] = CACHE_FLUSH_TS;
334: cmds[index++] = lower_32_bits(RB_EOPTIMESTAMP(device, rb));
335: cmds[index++] = upper_32_bits(RB_EOPTIMESTAMP(device, rb));
336: cmds[index++] = rb->timestamp;
337: }
338:
339: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1);
340: cmds[index++] = 0x100; /* IFPC enable */
341:
342: if (IS_WFI(flags))
343: cmds[index++] = cp_type7_packet(CP_WAIT_FOR_IDLE, 0);
344:
345: if (IS_SECURE(flags)) {
346: cmds[index++] = cp_type7_packet(CP_SET_SECURE_MODE, 1);
347: cmds[index++] = 0;
348: }
349:
350: /* 10 dwords */
351: index += a6xx_preemption_post_ibsubmit(adreno_dev, &cmds[index]);
352:
353: /* Adjust the thing for the number of dwords we actually wrote */
354: rb->_wptr -= (size - index);
355:
356: return a6xx_ringbuffer_submit(rb, time,
357: !adreno_is_preemption_enabled(adreno_dev));
358: }
359:
360: static u32 a6xx_get_alwayson_counter(u32 *cmds, u64 gpuaddr)
361: {
362: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3);
363: cmds[1] = A6XX_CP_ALWAYS_ON_COUNTER_LO | (1 << 30) | (2 << 18);
364: cmds[2] = lower_32_bits(gpuaddr);
365: cmds[3] = upper_32_bits(gpuaddr);
366:
367: return 4;
368: }
369:
370: static u32 a6xx_get_alwayson_context(u32 *cmds, u64 gpuaddr)
371: {
372: cmds[0] = cp_type7_packet(CP_REG_TO_MEM, 3);
373: cmds[1] = A6XX_CP_ALWAYS_ON_CONTEXT_LO | (1 << 30) | (2 << 18);
374: cmds[2] = lower_32_bits(gpuaddr);
375: cmds[3] = upper_32_bits(gpuaddr);
376:
377: return 4;
378: }
379:
380: #define PROFILE_IB_DWORDS 4
381: #define PROFILE_IB_SLOTS (PAGE_SIZE / (PROFILE_IB_DWORDS << 2))
382:
383: static u64 a6xx_get_user_profiling_ib(struct adreno_ringbuffer *rb,
384: struct kgsl_drawobj_cmd *cmdobj, u32 target_offset, u32 *cmds)
385: {
386: u32 offset, *ib, dwords;
387: u64 gpuaddr;
388:
389: if (IS_ERR(rb->profile_desc))
390: return 0;
391:
392: offset = rb->profile_index * (PROFILE_IB_DWORDS << 2);
393: ib = rb->profile_desc->hostptr + offset;
394: gpuaddr = rb->profile_desc->gpuaddr + offset;
395: dwords = a6xx_get_alwayson_counter(ib,
396: cmdobj->profiling_buffer_gpuaddr + target_offset);
397:
398: cmds[0] = cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3);
399: cmds[1] = lower_32_bits(gpuaddr);
400: cmds[2] = upper_32_bits(gpuaddr);
401: cmds[3] = dwords;
402:
403: rb->profile_index = (rb->profile_index + 1) % PROFILE_IB_SLOTS;
404:
405: return 4;
406: }
407:
408: static int a6xx_drawctxt_switch(struct adreno_device *adreno_dev,
409: struct adreno_ringbuffer *rb,
410: struct adreno_context *drawctxt)
411: {
412: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
413: int ret;
414:
415: if (rb->drawctxt_active == drawctxt)
416: return 0;
417:
418: if (kgsl_context_detached(&drawctxt->base))
419: return -ENOENT;
420:
421: if (!_kgsl_context_get(&drawctxt->base))
422: return -ENOENT;
423:
424: ret = a6xx_rb_context_switch(adreno_dev, rb, drawctxt);
425: if (ret) {
426: kgsl_context_put(&drawctxt->base);
427: return ret;
428: }
429:
430: trace_adreno_drawctxt_switch(rb, drawctxt);
431:
432: /* Release the current drawctxt as soon as the new one is switched */
433: adreno_put_drawctxt_on_timestamp(device, rb->drawctxt_active,
434: rb, rb->timestamp);
435:
436: rb->drawctxt_active = drawctxt;
437: return 0;
438: }
439:
440: #define A6XX_USER_PROFILE_IB(rb, cmdobj, cmds, field) \
441: a6xx_get_user_profiling_ib((rb), (cmdobj), \
442: offsetof(struct kgsl_drawobj_profiling_buffer, field), \
443: (cmds))
444:
445: #define A6XX_KERNEL_PROFILE(dev, cmdobj, cmds, field) \
446: a6xx_get_alwayson_counter((cmds), \
447: (dev)->profile_buffer->gpuaddr + \
448: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \
449: field))
450:
451: #define A6XX_KERNEL_PROFILE_CONTEXT(dev, cmdobj, cmds, field) \
452: a6xx_get_alwayson_context((cmds), \
453: (dev)->profile_buffer->gpuaddr + \
454: ADRENO_DRAWOBJ_PROFILE_OFFSET((cmdobj)->profile_index, \
455: field))
456:
457: #define A6XX_COMMAND_DWORDS 40
458:
459: int a6xx_ringbuffer_submitcmd(struct adreno_device *adreno_dev,
460: struct kgsl_drawobj_cmd *cmdobj, u32 flags,
461: struct adreno_submit_time *time)
462: {
463: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
464: struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj);
465: struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context);
466: struct adreno_ringbuffer *rb = drawctxt->rb;
467: int ret = 0, numibs = 0, index = 0;
468: u32 *cmds;
469:
470: /* Count the number of IBs (if we are not skipping) */
471: if (!IS_SKIP(flags)) {
472: struct list_head *tmp;
473:
474: list_for_each(tmp, &cmdobj->cmdlist)
475: numibs++;
476: }
477:
478: cmds = kvmalloc((A6XX_COMMAND_DWORDS + (numibs * 5)) << 2, GFP_KERNEL);
479: if (!cmds) {
480: ret = -ENOMEM;
481: goto done;
482: }
483:
484: cmds[index++] = cp_type7_packet(CP_NOP, 1);
485: cmds[index++] = START_IB_IDENTIFIER;
486:
487: /* Kernel profiling: 8 dwords */
488: if (IS_KERNEL_PROFILE(flags)) {
489: index += A6XX_KERNEL_PROFILE(adreno_dev, cmdobj, &cmds[index],
490: started);
491: index += A6XX_KERNEL_PROFILE_CONTEXT(adreno_dev, cmdobj, &cmds[index],
492: ctx_start);
493: }
494:
495: /* User profiling: 4 dwords */
496: if (IS_USER_PROFILE(flags))
497: index += A6XX_USER_PROFILE_IB(rb, cmdobj, &cmds[index],
498: gpu_ticks_submitted);
499:
500: if (numibs) {
501: struct kgsl_memobj_node *ib;
502:
503: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1);
504: cmds[index++] = 0x00d; /* IB1LIST start */
505:
506: list_for_each_entry(ib, &cmdobj->cmdlist, node) {
507: if (ib->priv & MEMOBJ_SKIP ||
508: (ib->flags & KGSL_CMDLIST_CTXTSWITCH_PREAMBLE
509: && !IS_PREAMBLE(flags)))
510: cmds[index++] = cp_type7_packet(CP_NOP, 4);
511:
512: cmds[index++] =
513: cp_type7_packet(CP_INDIRECT_BUFFER_PFE, 3);
514: cmds[index++] = lower_32_bits(ib->gpuaddr);
515: cmds[index++] = upper_32_bits(ib->gpuaddr);
516:
517: /* Double check that IB_PRIV is never set */
518: cmds[index++] = (ib->size >> 2) & 0xfffff;
519: }
520:
521: cmds[index++] = cp_type7_packet(CP_SET_MARKER, 1);
522: cmds[index++] = 0x00e; /* IB1LIST end */
523: }
524:
525: /* CCU invalidate */
526: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1);
527: cmds[index++] = 24;
528:
529: cmds[index++] = cp_type7_packet(CP_EVENT_WRITE, 1);
530: cmds[index++] = 25;
531:
532: /* 8 dwords */
533: if (IS_KERNEL_PROFILE(flags)) {
534: index += A6XX_KERNEL_PROFILE(adreno_dev, cmdobj, &cmds[index],
535: retired);
536: index += A6XX_KERNEL_PROFILE_CONTEXT(adreno_dev, cmdobj, &cmds[index],
537: ctx_end);
538: }
539:
540: /* 4 dwords */
541: if (IS_USER_PROFILE(flags))
542: index += A6XX_USER_PROFILE_IB(rb, cmdobj, &cmds[index],
543: gpu_ticks_retired);
544:
545: cmds[index++] = cp_type7_packet(CP_NOP, 1);
546: cmds[index++] = END_IB_IDENTIFIER;
547:
548: ret = a6xx_drawctxt_switch(adreno_dev, rb, drawctxt);
549:
550: /*
551: * In the unlikely event of an error in the drawctxt switch,
552: * treat it like a hang
553: */
554: if (ret) {
555: /*
556: * It is "normal" to get a -ENOSPC or a -ENOENT. Don't log it,
557: * the upper layers know how to handle it
558: */
559: if (ret != -ENOSPC && ret != -ENOENT)
560: dev_err(device->dev,
561: "Unable to switch draw context: %d\n",
562: ret);
563: goto done;
564: }
565:
566: adreno_drawobj_set_constraint(device, drawobj);
567:
568: ret = a6xx_ringbuffer_addcmds(adreno_dev, drawctxt->rb, drawctxt,
569: flags, cmds, index, drawobj->timestamp, time);
570:
571: done:
572: trace_kgsl_issueibcmds(device, drawctxt->base.id, numibs,
573: drawobj->timestamp, drawobj->flags, ret, drawctxt->type);
574:
575: kvfree(cmds);
576: return ret;
577: }
========== FILE: adreno_a6xx_preempt.c ==========
--- LINES 4-758 ---
4: * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
5: */
6:
7: #include "adreno.h"
8: #include "adreno_a6xx.h"
9: #include "adreno_pm4types.h"
10: #include "adreno_trace.h"
11: #include "kgsl_util.h"
12:
13: #define PREEMPT_RECORD(_field) \
14: offsetof(struct a6xx_cp_preemption_record, _field)
15:
16: #define PREEMPT_SMMU_RECORD(_field) \
17: offsetof(struct a6xx_cp_smmu_info, _field)
18:
19: static void _update_wptr(struct adreno_device *adreno_dev, bool reset_timer,
20: bool atomic)
21: {
22: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
23: struct adreno_ringbuffer *rb = adreno_dev->cur_rb;
24: unsigned long flags;
25: int ret = 0;
26:
27: spin_lock_irqsave(&rb->preempt_lock, flags);
28:
29: if (!atomic) {
30: /*
31: * We might have skipped updating the wptr in case we are in
32: * dispatcher context. Do it now.
33: */
34: if (rb->skip_inline_wptr) {
35:
36: ret = a6xx_fenced_write(adreno_dev,
37: A6XX_CP_RB_WPTR, rb->wptr,
38: FENCE_STATUS_WRITEDROPPED0_MASK);
39:
40: reset_timer = true;
41: rb->skip_inline_wptr = false;
42: }
43: } else {
44: unsigned int wptr;
45:
46: kgsl_regread(device, A6XX_CP_RB_WPTR, &wptr);
47: if (wptr != rb->wptr) {
48: kgsl_regwrite(device, A6XX_CP_RB_WPTR, rb->wptr);
49: reset_timer = true;
50: }
51: }
52:
53: if (reset_timer)
54: rb->dispatch_q.expires = jiffies +
55: msecs_to_jiffies(adreno_drawobj_timeout);
56:
57: spin_unlock_irqrestore(&rb->preempt_lock, flags);
58:
59: if (!atomic) {
60: /* If WPTR update fails, set the fault and trigger recovery */
61: if (ret) {
62: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE);
63: adreno_scheduler_fault(adreno_dev,
64: ADRENO_GMU_FAULT_SKIP_SNAPSHOT);
65: }
66: }
67: }
68:
69: static void _power_collapse_set(struct adreno_device *adreno_dev, bool val)
70: {
71: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
72:
73: if (!gmu_core_isenabled(device))
74: return;
75:
76: if (val) {
77: if (adreno_is_a660(adreno_dev) ||
78: adreno_is_a663(adreno_dev))
79: gmu_core_regwrite(device,
80: A6XX_GMU_PWR_COL_PREEMPT_KEEPALIVE, 0x1);
81: else
82: gmu_core_regrmw(device,
83: A6XX_GMU_AO_SPARE_CNTL, 0x0, 0x2);
84: } else {
85: if (adreno_is_a660(adreno_dev) ||
86: adreno_is_a663(adreno_dev))
87: gmu_core_regwrite(device,
88: A6XX_GMU_PWR_COL_PREEMPT_KEEPALIVE, 0x0);
89: else
90: gmu_core_regrmw(device,
91: A6XX_GMU_AO_SPARE_CNTL, 0x2, 0x0);
92: }
93: }
94:
95: static void _a6xx_preemption_done(struct adreno_device *adreno_dev)
96: {
97: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
98: unsigned int status;
99:
100: /*
101: * In the very unlikely case that the power is off, do nothing - the
102: * state will be reset on power up and everybody will be happy
103: */
104:
105: if (!kgsl_state_is_awake(device))
106: return;
107:
108: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, &status);
109:
110: if (status & 0x1) {
111: dev_err(device->dev,
112: "Preemption not complete: status=%X cur=%d R/W=%X/%X next=%d R/W=%X/%X\n",
113: status, adreno_dev->cur_rb->id,
114: adreno_get_rptr(adreno_dev->cur_rb),
115: adreno_dev->cur_rb->wptr,
116: adreno_dev->next_rb->id,
117: adreno_get_rptr(adreno_dev->next_rb),
118: adreno_dev->next_rb->wptr);
119:
120: /* Set a fault and restart */
121: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT);
122:
123: return;
124: }
125:
126: adreno_dev->preempt.count++;
127:
128: /*
129: * In normal scenarios, preemption keep alive bit is cleared during
130: * CP interrupt callback. However, if preemption is successful
131: * immediately after preemption timer expires or there is a preemption
132: * interrupt with non-zero status, the state is transitioned to complete
133: * state. Once dispatcher is scheduled, it calls this function.
134: * We can now safely clear the preemption keepalive bit, allowing
135: * power collapse to resume its regular activity.
136: */
137: _power_collapse_set(adreno_dev, false);
138:
139: kgsl_delete_timer_sync(&adreno_dev->preempt.timer);
140:
141: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status);
142:
143: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id,
144: status, 0);
145:
146: /* Clean up all the bits */
147: adreno_dev->prev_rb = adreno_dev->cur_rb;
148: adreno_dev->cur_rb = adreno_dev->next_rb;
149: adreno_dev->next_rb = NULL;
150:
151: /* Update the wptr for the new command queue */
152: _update_wptr(adreno_dev, true, false);
153:
154: /* Update the dispatcher timer for the new command queue */
155: mod_timer(&adreno_dev->dispatcher.timer,
156: adreno_dev->cur_rb->dispatch_q.expires);
157:
158: /* Clear the preempt state */
159: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE);
160: }
161:
162: static void _a6xx_preemption_fault(struct adreno_device *adreno_dev)
163: {
164: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
165: unsigned int status;
166:
167: /*
168: * If the power is on check the preemption status one more time - if it
169: * was successful then just transition to the complete state
170: */
171: if (kgsl_state_is_awake(device)) {
172: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, &status);
173:
174: if (!(status & 0x1)) {
175: adreno_set_preempt_state(adreno_dev,
176: ADRENO_PREEMPT_COMPLETE);
177:
178: adreno_scheduler_queue(adreno_dev);
179: return;
180: }
181: }
182:
183: dev_err(device->dev,
184: "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n",
185: adreno_dev->cur_rb->id,
186: adreno_get_rptr(adreno_dev->cur_rb),
187: adreno_dev->cur_rb->wptr,
188: adreno_dev->next_rb->id,
189: adreno_get_rptr(adreno_dev->next_rb),
190: adreno_dev->next_rb->wptr);
191:
192: adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT);
193: }
194:
195: static void _a6xx_preemption_worker(struct work_struct *work)
196: {
197: struct adreno_preemption *preempt = container_of(work,
198: struct adreno_preemption, work);
199: struct adreno_device *adreno_dev = container_of(preempt,
200: struct adreno_device, preempt);
201: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
202:
203: /* Need to take the mutex to make sure that the power stays on */
204: kgsl_mutex_lock(&device->mutex);
205:
206: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_FAULTED))
207: _a6xx_preemption_fault(adreno_dev);
208:
209: kgsl_mutex_unlock(&device->mutex);
210: }
211:
212: /* Find the highest priority active ringbuffer */
213: static struct adreno_ringbuffer *a6xx_next_ringbuffer(
214: struct adreno_device *adreno_dev)
215: {
216: struct adreno_ringbuffer *rb;
217: unsigned long flags;
218: unsigned int i;
219:
220: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) {
221: bool empty;
222:
223: spin_lock_irqsave(&rb->preempt_lock, flags);
224: empty = adreno_rb_empty(rb);
225: spin_unlock_irqrestore(&rb->preempt_lock, flags);
226:
227: if (!empty)
228: return rb;
229: }
230:
231: return NULL;
232: }
233:
234: void a6xx_preemption_trigger(struct adreno_device *adreno_dev, bool atomic)
235: {
236: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
237: struct kgsl_iommu *iommu = KGSL_IOMMU(device);
238: struct adreno_ringbuffer *next;
239: uint64_t ttbr0, gpuaddr;
240: unsigned int contextidr, cntl;
241: unsigned long flags;
242: struct adreno_preemption *preempt = &adreno_dev->preempt;
243:
244: /* Put ourselves into a possible trigger state */
245: if (!adreno_move_preempt_state(adreno_dev,
246: ADRENO_PREEMPT_NONE, ADRENO_PREEMPT_START))
247: return;
248:
249: /* Get the next ringbuffer to preempt in */
250: next = a6xx_next_ringbuffer(adreno_dev);
251:
252: /*
253: * Nothing to do if every ringbuffer is empty or if the current
254: * ringbuffer is the only active one
255: */
256: if (next == NULL || next == adreno_dev->cur_rb) {
257: /*
258: * Update any critical things that might have been skipped while
259: * we were looking for a new ringbuffer
260: */
261:
262: if (next != NULL) {
263: _update_wptr(adreno_dev, false, atomic);
264:
265: mod_timer(&adreno_dev->dispatcher.timer,
266: adreno_dev->cur_rb->dispatch_q.expires);
267: }
268:
269: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE);
270: return;
271: }
272:
273: /* Turn off the dispatcher timer */
274: kgsl_delete_timer(&adreno_dev->dispatcher.timer);
275:
276: /*
277: * This is the most critical section - we need to take care not to race
278: * until we have programmed the CP for the switch
279: */
280:
281: spin_lock_irqsave(&next->preempt_lock, flags);
282:
283: /* Get the pagetable from the pagetable info. */
284: kgsl_sharedmem_readq(device->scratch, &ttbr0,
285: SCRATCH_RB_OFFSET(next->id, ttbr0));
286: kgsl_sharedmem_readl(device->scratch, &contextidr,
287: SCRATCH_RB_OFFSET(next->id, contextidr));
288:
289: kgsl_sharedmem_writel(next->preemption_desc,
290: PREEMPT_RECORD(wptr), next->wptr);
291:
292: spin_unlock_irqrestore(&next->preempt_lock, flags);
293:
294: /* And write it to the smmu info */
295:
296: if (kgsl_mmu_is_perprocess(&device->mmu)) {
297: kgsl_sharedmem_writeq(iommu->smmu_info,
298: PREEMPT_SMMU_RECORD(ttbr0), ttbr0);
299: kgsl_sharedmem_writel(iommu->smmu_info,
300: PREEMPT_SMMU_RECORD(context_idr), contextidr);
301: }
302:
303: kgsl_sharedmem_readq(preempt->scratch, &gpuaddr,
304: next->id * sizeof(u64));
305:
306: /*
307: * Set a keepalive bit before the first preemption register write.
308: * This is required since while each individual write to the context
309: * switch registers will wake the GPU from collapse, it will not in
310: * itself cause GPU activity. Thus, the GPU could technically be
311: * re-collapsed between subsequent register writes leading to a
312: * prolonged preemption sequence. The keepalive bit prevents any
313: * further power collapse while it is set.
314: * It is more efficient to use a keepalive+wake-on-fence approach here
315: * rather than an OOB. Both keepalive and the fence are effectively
316: * free when the GPU is already powered on, whereas an OOB requires an
317: * unconditional handshake with the GMU.
318: */
319: _power_collapse_set(adreno_dev, true);
320:
321: /*
322: * Fenced writes on this path will make sure the GPU is woken up
323: * in case it was power collapsed by the GMU.
324: */
325: if (a6xx_fenced_write(adreno_dev,
326: A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_LO,
327: lower_32_bits(next->preemption_desc->gpuaddr),
328: FENCE_STATUS_WRITEDROPPED1_MASK))
329: goto err;
330:
331: /*
332: * Above fence writes will make sure GMU comes out of
333: * IFPC state if its was in IFPC state but it doesn't
334: * guarantee that GMU FW actually moved to ACTIVE state
335: * i.e. wake-up from IFPC is complete.
336: * Wait for GMU to move to ACTIVE state before triggering
337: * preemption. This is require to make sure CP doesn't
338: * interrupt GMU during wake-up from IFPC.
339: */
340: if (!atomic && gmu_core_dev_wait_for_active_transition(device))
341: goto err;
342:
343: if (a6xx_fenced_write(adreno_dev,
344: A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR_HI,
345: upper_32_bits(next->preemption_desc->gpuaddr),
346: FENCE_STATUS_WRITEDROPPED1_MASK))
347: goto err;
348:
349: if (kgsl_mmu_is_secured(&device->mmu)) {
350: if (a6xx_fenced_write(adreno_dev,
351: A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_LO,
352: lower_32_bits(next->secure_preemption_desc->gpuaddr),
353: FENCE_STATUS_WRITEDROPPED1_MASK))
354: goto err;
355:
356: if (a6xx_fenced_write(adreno_dev,
357: A6XX_CP_CONTEXT_SWITCH_PRIV_SECURE_RESTORE_ADDR_HI,
358: upper_32_bits(next->secure_preemption_desc->gpuaddr),
359: FENCE_STATUS_WRITEDROPPED1_MASK))
360: goto err;
361: }
362:
363: if (a6xx_fenced_write(adreno_dev,
364: A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_LO,
365: lower_32_bits(gpuaddr),
366: FENCE_STATUS_WRITEDROPPED1_MASK))
367: goto err;
368:
369: if (a6xx_fenced_write(adreno_dev,
370: A6XX_CP_CONTEXT_SWITCH_NON_PRIV_RESTORE_ADDR_HI,
371: upper_32_bits(gpuaddr),
372: FENCE_STATUS_WRITEDROPPED1_MASK))
373: goto err;
374:
375: adreno_dev->next_rb = next;
376:
377: /* Start the timer to detect a stuck preemption */
378: mod_timer(&adreno_dev->preempt.timer,
379: jiffies + msecs_to_jiffies(ADRENO_PREEMPT_TIMEOUT));
380:
381: cntl = (preempt->preempt_level << 6) | 0x01;
382:
383: /* Skip save/restore during L1 preemption */
384: if (preempt->skipsaverestore)
385: cntl |= (1 << 9);
386:
387: /* Enable GMEM save/restore across preemption */
388: if (preempt->usesgmem)
389: cntl |= (1 << 8);
390:
391: trace_adreno_preempt_trigger(adreno_dev->cur_rb->id, adreno_dev->next_rb->id,
392: cntl, 0);
393:
394: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_TRIGGERED);
395:
396: /* Trigger the preemption */
397: if (a6xx_fenced_write(adreno_dev, A6XX_CP_CONTEXT_SWITCH_CNTL, cntl,
398: FENCE_STATUS_WRITEDROPPED1_MASK)) {
399: adreno_dev->next_rb = NULL;
400: kgsl_delete_timer(&adreno_dev->preempt.timer);
401: goto err;
402: }
403:
404: return;
405: err:
406: /* If fenced write fails, take inline snapshot and trigger recovery */
407: if (!atomic) {
408: gmu_core_fault_snapshot(device, GMU_FAULT_PANIC_NONE);
409: adreno_scheduler_fault(adreno_dev,
410: ADRENO_GMU_FAULT_SKIP_SNAPSHOT);
411: } else {
412: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT);
413: }
414: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE);
415: /* Clear the keep alive */
416: _power_collapse_set(adreno_dev, false);
417:
418: }
419:
420: void a6xx_preemption_callback(struct adreno_device *adreno_dev, int bit)
421: {
422: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
423: unsigned int status;
424:
425: if (!adreno_move_preempt_state(adreno_dev,
426: ADRENO_PREEMPT_TRIGGERED, ADRENO_PREEMPT_PENDING))
427: return;
428:
429: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, &status);
430:
431: if (status & 0x1) {
432: dev_err(KGSL_DEVICE(adreno_dev)->dev,
433: "preempt interrupt with non-zero status: %X\n",
434: status);
435:
436: /*
437: * Under the assumption that this is a race between the
438: * interrupt and the register, schedule the worker to clean up.
439: * If the status still hasn't resolved itself by the time we get
440: * there then we have to assume something bad happened
441: */
442: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE);
443: adreno_scheduler_queue(adreno_dev);
444: return;
445: }
446:
447: adreno_dev->preempt.count++;
448:
449: /*
450: * We can now safely clear the preemption keepalive bit, allowing
451: * power collapse to resume its regular activity.
452: */
453: _power_collapse_set(adreno_dev, false);
454:
455: kgsl_delete_timer(&adreno_dev->preempt.timer);
456:
457: kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status);
458:
459: trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id,
460: status, 0);
461:
462: adreno_dev->prev_rb = adreno_dev->cur_rb;
463: adreno_dev->cur_rb = adreno_dev->next_rb;
464: adreno_dev->next_rb = NULL;
465:
466: /* Update the wptr if it changed while preemption was ongoing */
467: _update_wptr(adreno_dev, true, true);
468:
469: /* Update the dispatcher timer for the new command queue */
470: mod_timer(&adreno_dev->dispatcher.timer,
471: adreno_dev->cur_rb->dispatch_q.expires);
472:
473: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE);
474:
475: a6xx_preemption_trigger(adreno_dev, true);
476: }
477:
478: void a6xx_preemption_schedule(struct adreno_device *adreno_dev)
479: {
480: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
481:
482: if (!adreno_is_preemption_enabled(adreno_dev))
483: return;
484:
485: kgsl_mutex_lock(&device->mutex);
486:
487: if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE))
488: _a6xx_preemption_done(adreno_dev);
489:
490: a6xx_preemption_trigger(adreno_dev, false);
491:
492: kgsl_mutex_unlock(&device->mutex);
493: }
494:
495: u32 a6xx_preemption_pre_ibsubmit(struct adreno_device *adreno_dev,
496: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt,
497: u32 *cmds)
498: {
499: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
500: u32 count = kgsl_mmu_is_secured(&device->mmu) ? 12 : 9;
501: unsigned int *cmds_orig = cmds;
502: uint64_t gpuaddr = 0;
503:
504: if (!adreno_is_preemption_enabled(adreno_dev))
505: return 0;
506:
507: if (drawctxt && drawctxt->base.user_ctxt_record)
508: gpuaddr = drawctxt->base.user_ctxt_record->memdesc.gpuaddr;
509:
510: if (gpuaddr)
511: count += 3;
512:
513: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER, count);
514: /* NULL SMMU_INFO buffer - we track in KMD */
515: *cmds++ = SET_PSEUDO_SMMU_INFO;
516: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0);
517:
518: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR;
519: cmds += cp_gpuaddr(adreno_dev, cmds, rb->preemption_desc->gpuaddr);
520:
521: if (kgsl_mmu_is_secured(&device->mmu)) {
522: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR;
523: cmds += cp_gpuaddr(adreno_dev, cmds,
524: rb->secure_preemption_desc->gpuaddr);
525: }
526:
527: if (gpuaddr) {
528: *cmds++ = SET_PSEUDO_NON_PRIV_SAVE_ADDR;
529: cmds += cp_gpuaddr(adreno_dev, cmds, gpuaddr);
530: }
531:
532: /*
533: * There is no need to specify this address when we are about to
534: * trigger preemption. This is because CP internally stores this
535: * address specified here in the CP_SET_PSEUDO_REGISTER payload to
536: * the context record and thus knows from where to restore
537: * the saved perfcounters for the new ringbuffer.
538: */
539: *cmds++ = SET_PSEUDO_COUNTER;
540: cmds += cp_gpuaddr(adreno_dev, cmds,
541: rb->perfcounter_save_restore_desc->gpuaddr);
542:
543: if (!drawctxt)
544: goto done;
545:
546: cmds += adreno_prepare_preib_preempt_scratch(adreno_dev, drawctxt, cmds);
547:
548: /* Add a KMD post amble to clear the perf counters during preemption */
549: if (!adreno_dev->perfcounter)
550: cmds += adreno_prepare_preib_postamble_scratch(adreno_dev, cmds);
551:
552: done:
553: return (u32) (cmds - cmds_orig);
554: }
555:
556: u32 a6xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev,
557: u32 *cmds)
558: {
559: u32 index = 0;
560:
561: if (!adreno_is_preemption_enabled(adreno_dev))
562: return 0;
563:
564: if (adreno_dev->cur_rb) {
565: u64 dest = PREEMPT_SCRATCH_ADDR(adreno_dev, adreno_dev->cur_rb->id);
566:
567: cmds[index++] = cp_type7_packet(CP_MEM_WRITE, 4);
568: cmds[index++] = lower_32_bits(dest);
569: cmds[index++] = upper_32_bits(dest);
570: cmds[index++] = 0;
571: cmds[index++] = 0;
572: }
573:
574: cmds[index++] = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4);
575: cmds[index++] = 0;
576: cmds[index++] = 0;
577: cmds[index++] = 1;
578: cmds[index++] = 0;
579:
580: return index;
581: }
582:
583: void a6xx_preemption_start(struct adreno_device *adreno_dev)
584: {
585: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
586: struct kgsl_iommu *iommu = KGSL_IOMMU(device);
587: struct adreno_ringbuffer *rb;
588: unsigned int i;
589:
590: if (!adreno_is_preemption_enabled(adreno_dev))
591: return;
592:
593: /* Force the state to be clear */
594: adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE);
595:
596: if (kgsl_mmu_is_perprocess(&device->mmu)) {
597: /* smmu_info is allocated and mapped in a6xx_preemption_iommu_init */
598: kgsl_sharedmem_writel(iommu->smmu_info,
599: PREEMPT_SMMU_RECORD(magic), A6XX_CP_SMMU_INFO_MAGIC_REF);
600: kgsl_sharedmem_writeq(iommu->smmu_info,
601: PREEMPT_SMMU_RECORD(ttbr0), MMU_DEFAULT_TTBR0(device));
602:
603: /* The CP doesn't use the asid record, so poison it */
604: kgsl_sharedmem_writel(iommu->smmu_info,
605: PREEMPT_SMMU_RECORD(asid), 0xDECAFBAD);
606: kgsl_sharedmem_writel(iommu->smmu_info,
607: PREEMPT_SMMU_RECORD(context_idr), 0);
608:
609: kgsl_regwrite(device, A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_LO,
610: lower_32_bits(iommu->smmu_info->gpuaddr));
611:
612: kgsl_regwrite(device, A6XX_CP_CONTEXT_SWITCH_SMMU_INFO_HI,
613: upper_32_bits(iommu->smmu_info->gpuaddr));
614: }
615:
616: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) {
617: kgsl_sharedmem_writel(rb->preemption_desc,
618: PREEMPT_RECORD(rptr), 0);
619: kgsl_sharedmem_writel(rb->preemption_desc,
620: PREEMPT_RECORD(wptr), 0);
621:
622: adreno_ringbuffer_set_pagetable(device, rb,
623: device->mmu.defaultpagetable);
624: }
625: }
626:
627: static void reset_rb_preempt_record(struct adreno_device *adreno_dev,
628: struct adreno_ringbuffer *rb)
629: {
630: u32 cp_rb_cntl = A6XX_CP_RB_CNTL_DEFAULT |
631: (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? 0 : (1 << 27));
632:
633: memset(rb->preemption_desc->hostptr, 0x0, rb->preemption_desc->size);
634:
635: kgsl_sharedmem_writel(rb->preemption_desc,
636: PREEMPT_RECORD(magic), A6XX_CP_CTXRECORD_MAGIC_REF);
637: kgsl_sharedmem_writel(rb->preemption_desc,
638: PREEMPT_RECORD(cntl), cp_rb_cntl);
639: kgsl_sharedmem_writeq(rb->preemption_desc,
640: PREEMPT_RECORD(rptr_addr), SCRATCH_RB_GPU_ADDR(
641: KGSL_DEVICE(adreno_dev), rb->id, rptr));
642: kgsl_sharedmem_writeq(rb->preemption_desc,
643: PREEMPT_RECORD(rbase), rb->buffer_desc->gpuaddr);
644: }
645:
646: void a6xx_reset_preempt_records(struct adreno_device *adreno_dev)
647: {
648: int i;
649: struct adreno_ringbuffer *rb;
650:
651: if (!adreno_is_preemption_enabled(adreno_dev))
652: return;
653:
654: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) {
655: reset_rb_preempt_record(adreno_dev, rb);
656: }
657: }
658:
659: static int a6xx_preemption_ringbuffer_init(struct adreno_device *adreno_dev,
660: struct adreno_ringbuffer *rb)
661: {
662: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
663: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev);
664: u64 ctxt_record_size = A6XX_CP_CTXRECORD_SIZE_IN_BYTES;
665: int ret;
666:
667: if (a6xx_core->ctxt_record_size)
668: ctxt_record_size = a6xx_core->ctxt_record_size;
669:
670: ret = adreno_allocate_global(device, &rb->preemption_desc,
671: ctxt_record_size, SZ_16K, 0, KGSL_MEMDESC_PRIVILEGED,
672: "preemption_desc");
673: if (ret)
674: return ret;
675:
676: if (kgsl_mmu_is_secured(&device->mmu)) {
677: ret = adreno_allocate_global(device, &rb->secure_preemption_desc,
678: ctxt_record_size, 0, KGSL_MEMFLAGS_SECURE,
679: KGSL_MEMDESC_PRIVILEGED, "preemption_desc");
680: if (ret)
681: return ret;
682: }
683:
684: ret = adreno_allocate_global(device, &rb->perfcounter_save_restore_desc,
685: A6XX_CP_PERFCOUNTER_SAVE_RESTORE_SIZE, 0, 0,
686: KGSL_MEMDESC_PRIVILEGED,
687: "perfcounter_save_restore_desc");
688: if (ret)
689: return ret;
690:
691: reset_rb_preempt_record(adreno_dev, rb);
692:
693: return 0;
694: }
695:
696: int a6xx_preemption_init(struct adreno_device *adreno_dev)
697: {
698: u32 flags = ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? KGSL_MEMDESC_PRIVILEGED : 0;
699: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
700: struct kgsl_iommu *iommu = KGSL_IOMMU(device);
701: struct adreno_preemption *preempt = &adreno_dev->preempt;
702: struct adreno_ringbuffer *rb;
703: int ret;
704: unsigned int i;
705:
706: /* We are dependent on IOMMU to make preemption go on the CP side */
707: if (kgsl_mmu_get_mmutype(device) != KGSL_MMU_TYPE_IOMMU)
708: return -ENODEV;
709:
710: INIT_WORK(&preempt->work, _a6xx_preemption_worker);
711:
712: /* Allocate mem for storing preemption switch record */
713: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) {
714: ret = a6xx_preemption_ringbuffer_init(adreno_dev, rb);
715: if (ret)
716: return ret;
717: }
718:
719: ret = adreno_allocate_global(device, &preempt->scratch,
720: PAGE_SIZE, 0, 0, flags, "preempt_scratch");
721: if (ret)
722: return ret;
723:
724: /* Allocate mem for storing preemption smmu record */
725: if (kgsl_mmu_is_perprocess(&device->mmu)) {
726: ret = adreno_allocate_global(device, &iommu->smmu_info, PAGE_SIZE, 0,
727: KGSL_MEMFLAGS_GPUREADONLY, KGSL_MEMDESC_PRIVILEGED,
728: "smmu_info");
729: if (ret)
730: return ret;
731: }
732:
733: /*
734: * First 28 dwords of the device scratch buffer are used to store shadow rb data.
735: * Insert PM4 packets in device scratch buffer to clear perfcounters. This should
736: * be in *device->scratch* so that userspace cannot access it.
737: */
738: if (!adreno_dev->perfcounter) {
739: u32 *postamble = device->scratch->hostptr + SCRATCH_POSTAMBLE_OFFSET;
740: u32 count = 0;
741:
742: postamble[count++] = cp_type4_packet(A6XX_RBBM_PERFCTR_SRAM_INIT_CMD, 1);
743: postamble[count++] = 0x1;
744:
745: postamble[count++] = cp_type7_packet(CP_WAIT_REG_MEM, 6);
746: postamble[count++] = 0x3;
747: postamble[count++] = A6XX_RBBM_PERFCTR_SRAM_INIT_STATUS;
748: postamble[count++] = 0x0;
749: postamble[count++] = 0x1;
750: postamble[count++] = 0x1;
751: postamble[count++] = 0x0;
752:
753: preempt->postamble_len = count;
754: }
755:
756: set_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv);
757: return 0;
758: }
========== FILE: adreno_a6xx.c ==========
--- LINES 19-74 ---
19: #include "adreno.h"
20: #include "adreno_a6xx.h"
21: #include "adreno_a6xx_hwsched.h"
22: #include "adreno_pm4types.h"
23: #include "adreno_trace.h"
24: #include "kgsl_gmu_core.h"
25: #include "kgsl_trace.h"
26: #include "kgsl_util.h"
27:
28: /* IFPC & Preemption static powerup restore list */
29: static u32 a6xx_pwrup_reglist[] = {
30: A6XX_VSC_ADDR_MODE_CNTL,
31: A6XX_GRAS_ADDR_MODE_CNTL,
32: A6XX_RB_ADDR_MODE_CNTL,
33: A6XX_PC_ADDR_MODE_CNTL,
34: A6XX_HLSQ_ADDR_MODE_CNTL,
35: A6XX_VFD_ADDR_MODE_CNTL,
36: A6XX_VPC_ADDR_MODE_CNTL,
37: A6XX_UCHE_ADDR_MODE_CNTL,
38: A6XX_SP_ADDR_MODE_CNTL,
39: A6XX_TPL1_ADDR_MODE_CNTL,
40: A6XX_UCHE_WRITE_RANGE_MAX_LO,
41: A6XX_UCHE_WRITE_RANGE_MAX_HI,
42: A6XX_UCHE_TRAP_BASE_LO,
43: A6XX_UCHE_TRAP_BASE_HI,
44: A6XX_UCHE_WRITE_THRU_BASE_LO,
45: A6XX_UCHE_WRITE_THRU_BASE_HI,
46: A6XX_UCHE_GMEM_RANGE_MIN_LO,
47: A6XX_UCHE_GMEM_RANGE_MIN_HI,
48: A6XX_UCHE_GMEM_RANGE_MAX_LO,
49: A6XX_UCHE_GMEM_RANGE_MAX_HI,
50: A6XX_UCHE_FILTER_CNTL,
51: A6XX_UCHE_CACHE_WAYS,
52: A6XX_UCHE_MODE_CNTL,
53: A6XX_RB_NC_MODE_CNTL,
54: A6XX_TPL1_NC_MODE_CNTL,
55: A6XX_SP_NC_MODE_CNTL,
56: A6XX_PC_DBG_ECO_CNTL,
57: A6XX_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE,
58: A6XX_UCHE_GBIF_GX_CONFIG,
59: A6XX_UCHE_CLIENT_PF,
60: };
61:
62: /* IFPC only static powerup restore list */
63: static u32 a6xx_ifpc_pwrup_reglist[] = {
64: A6XX_CP_CHICKEN_DBG,
65: A6XX_CP_DBG_ECO_CNTL,
66: A6XX_CP_PROTECT_CNTL,
67: A6XX_CP_PROTECT_REG,
68: A6XX_CP_PROTECT_REG+1,
69: A6XX_CP_PROTECT_REG+2,
70: A6XX_CP_PROTECT_REG+3,
71: A6XX_CP_PROTECT_REG+4,
72: A6XX_CP_PROTECT_REG+5,
73: A6XX_CP_PROTECT_REG+6,
74: A6XX_CP_PROTECT_REG+7,
--- LINES 128-202 ---
128: A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_4,
129: A6XX_UCHE_CMDQ_CONFIG,
130: A6XX_SP_DBG_ECO_CNTL,
131: };
132:
133: static u32 a615_pwrup_reglist[] = {
134: A6XX_UCHE_GBIF_GX_CONFIG,
135: };
136:
137: int a6xx_fenced_write(struct adreno_device *adreno_dev, u32 offset,
138: u32 value, u32 mask)
139: {
140: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
141: unsigned int status, i;
142: u64 ts1, ts2;
143:
144: kgsl_regwrite(device, offset, value);
145:
146: if (!gmu_core_isenabled(device))
147: return 0;
148:
149: ts1 = a6xx_read_alwayson(adreno_dev);
150: for (i = 0; i < GMU_CORE_LONG_WAKEUP_RETRY_LIMIT; i++) {
151: /*
152: * Make sure the previous register write is posted before
153: * checking the fence status
154: */
155: mb();
156:
157: kgsl_regread(device, A6XX_GMU_AHB_FENCE_STATUS, &status);
158:
159: /*
160: * If !writedropped0/1, then the write to fenced register
161: * was successful
162: */
163: if (!(status & mask))
164: break;
165:
166: /* Wait a small amount of time before trying again */
167: udelay(GMU_CORE_WAKEUP_DELAY_US);
168:
169: /* Try to write the fenced register again */
170: kgsl_regwrite(device, offset, value);
171: }
172:
173: if (i < GMU_CORE_SHORT_WAKEUP_RETRY_LIMIT)
174: return 0;
175:
176: if (i == GMU_CORE_LONG_WAKEUP_RETRY_LIMIT) {
177: ts2 = a6xx_read_alwayson(adreno_dev);
178: dev_err(adreno_dev->dev.dev,
179: "Timed out waiting %d usecs to write fenced register 0x%x, timestamps: %llx %llx\n",
180: i * GMU_CORE_WAKEUP_DELAY_US, offset, ts1, ts2);
181: return -ETIMEDOUT;
182: }
183:
184: dev_err(adreno_dev->dev.dev,
185: "Waited %d usecs to write fenced register 0x%x\n",
186: i * GMU_CORE_WAKEUP_DELAY_US, offset);
187:
188: return 0;
189: }
190:
191: static void a6xx_calc_ubwc_config_legacy(struct adreno_device *adreno_dev)
192: {
193: struct adreno_ubwc_props *ubwc_props = &adreno_dev->ubwc_props;
194:
195: switch (adreno_dev->ubwc_mode) {
196: case KGSL_UBWC_1_0:
197: ubwc_props->mode = 1;
198: break;
199: case KGSL_UBWC_2_0:
200: ubwc_props->mode = 0;
201: break;
202: case KGSL_UBWC_3_0:
--- LINES 266-292 ---
266: PAGE_SIZE, 0, 0, KGSL_MEMDESC_PRIVILEGED,
267: "powerup_register_list");
268: }
269:
270: static int a6xx_nogmu_init(struct adreno_device *adreno_dev)
271: {
272: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
273: int ret;
274:
275: ret = a6xx_ringbuffer_init(adreno_dev);
276: if (ret)
277: return ret;
278:
279: ret = a6xx_microcode_read(adreno_dev);
280: if (ret)
281: return ret;
282:
283: /* Try to map the GMU wrapper region if applicable */
284: ret = kgsl_regmap_add_region(&device->regmap, device->pdev,
285: "gmu_wrapper", -EINVAL, NULL, NULL);
286: if (ret && ret != -ENODEV)
287: dev_err(device->dev, "Couldn't map the GMU wrapper registers\n");
288:
289: adreno_create_profile_buffer(adreno_dev);
290:
291: return a6xx_init(adreno_dev);
292: }
--- LINES 297-336 ---
297: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev);
298: const struct adreno_protected_regs *regs = a6xx_core->protected_regs;
299: int i;
300:
301: /*
302: * Enable access protection to privileged registers, fault on an access
303: * protect violation and select the last span to protect from the start
304: * address all the way to the end of the register address space
305: */
306: kgsl_regwrite(device, A6XX_CP_PROTECT_CNTL,
307: (1 << 0) | (1 << 1) | (1 << 3));
308:
309: /* Program each register defined by the core definition */
310: for (i = 0; regs[i].reg; i++) {
311: u32 count;
312:
313: /*
314: * This is the offset of the end register as counted from the
315: * start, i.e. # of registers in the range - 1
316: */
317: count = regs[i].end - regs[i].start;
318:
319: kgsl_regwrite(device, regs[i].reg,
320: (regs[i].start & 0x3ffff) | ((count & 0x1fff) << 18) |
321: (regs[i].noaccess << 31));
322: }
323: }
324:
325: static inline unsigned int
326: __get_rbbm_clock_cntl_on(struct adreno_device *adreno_dev)
327: {
328: if (adreno_is_a630(adreno_dev))
329: return 0x8AA8AA02;
330: else if (adreno_is_a612_family(adreno_dev) || adreno_is_a610_family(adreno_dev))
331: return 0xAAA8AA82;
332: else if (adreno_is_a702_family(adreno_dev))
333: return 0xAAAAAA82;
334: else
335: return 0x8AA8AA82;
336: }
--- LINES 383-436 ---
383: return 0x00000002;
384:
385: return 0x00000000;
386: }
387:
388: static void set_holi_sptprac_clock(struct kgsl_device *device, bool enable)
389: {
390: u32 val = 0;
391:
392: kgsl_regread(device, A6XX_GPU_GMU_GX_SPTPRAC_CLOCK_CONTROL, &val);
393: val &= ~1;
394: kgsl_regwrite(device, A6XX_GPU_GMU_GX_SPTPRAC_CLOCK_CONTROL,
395: val | (enable ? 1 : 0));
396: }
397:
398: static void a6xx_hwcg_set(struct adreno_device *adreno_dev, bool on)
399: {
400: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
401: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev);
402: unsigned int value;
403: int i;
404:
405: if (!adreno_dev->hwcg_enabled)
406: on = false;
407:
408: if (gmu_core_isenabled(device)) {
409: gmu_core_regwrite(device, A6XX_GPU_GMU_AO_GMU_CGC_MODE_CNTL,
410: on ? __get_gmu_ao_cgc_mode_cntl(adreno_dev) : 0);
411: gmu_core_regwrite(device, A6XX_GPU_GMU_AO_GMU_CGC_DELAY_CNTL,
412: on ? __get_gmu_ao_cgc_delay_cntl(adreno_dev) : 0);
413: gmu_core_regwrite(device, A6XX_GPU_GMU_AO_GMU_CGC_HYST_CNTL,
414: on ? __get_gmu_ao_cgc_hyst_cntl(adreno_dev) : 0);
415: gmu_core_regwrite(device, A6XX_GMU_CX_GMU_WFI_CONFIG,
416: on ? __get_gmu_wfi_config(adreno_dev) : 0);
417: }
418:
419: kgsl_regread(device, A6XX_RBBM_CLOCK_CNTL, &value);
420:
421: /*
422: * GBIF L2 CGC control is not part of the UCHE and is enabled by
423: * default. Hence modify the register when CGC disabled is
424: * requested.
425: * Note: The below programming will need modification in case
426: * of change in the register reset value in future.
427: */
428: kgsl_regrmw(device, A6XX_UCHE_GBIF_GX_CONFIG, GENMASK(18, 16),
429: FIELD_PREP(GENMASK(18, 16), on ? 2 : 0));
430:
431: /* Recommended to always disable GBIF_CX_CONFIG for gen6_3_26_0 */
432: if (!on || adreno_is_gen6_3_26_0(adreno_dev))
433: kgsl_regrmw(device, A6XX_GBIF_CX_CONFIG, GENMASK(18, 16),
434: FIELD_PREP(GENMASK(18, 16), 0));
435:
436: if (value == __get_rbbm_clock_cntl_on(adreno_dev) && on)
--- LINES 447-489 ---
447:
448: if (gmu_core_isenabled(device) && !adreno_is_a612_family(adreno_dev) &&
449: !adreno_is_a610_family(adreno_dev) && !adreno_is_a702_family(adreno_dev))
450: gmu_core_regrmw(device,
451: A6XX_GPU_GMU_GX_SPTPRAC_CLOCK_CONTROL, 1, 0);
452: else if (adreno_is_a619_holi(adreno_dev))
453: set_holi_sptprac_clock(device, false);
454:
455: for (i = 0; i < a6xx_core->hwcg_count; i++)
456: kgsl_regwrite(device, a6xx_core->hwcg[i].offset,
457: on ? a6xx_core->hwcg[i].val : 0);
458:
459: /*
460: * Enable SP clock after programming HWCG registers.
461: * A612, A610 and A702 family GPU is not having the GX power domain.
462: * Hence skip GMU_GX registers for A612, A610 and A702 family.
463: */
464: if (gmu_core_isenabled(device) && !adreno_is_a612_family(adreno_dev) &&
465: !adreno_is_a610_family(adreno_dev) && !adreno_is_a702_family(adreno_dev))
466: gmu_core_regrmw(device,
467: A6XX_GPU_GMU_GX_SPTPRAC_CLOCK_CONTROL, 0, 1);
468: else if (adreno_is_a619_holi(adreno_dev))
469: set_holi_sptprac_clock(device, true);
470:
471: /* enable top level HWCG */
472: kgsl_regwrite(device, A6XX_RBBM_CLOCK_CNTL,
473: on ? __get_rbbm_clock_cntl_on(adreno_dev) : 0);
474: }
475:
476: struct a6xx_reglist_list {
477: u32 *regs;
478: u32 count;
479: };
480:
481: #define REGLIST(_a) \
482: ((struct a6xx_reglist_list) { .regs = _a, .count = ARRAY_SIZE(_a), })
483:
484: static void a6xx_patch_pwrup_reglist(struct adreno_device *adreno_dev)
485: {
486: struct a6xx_reglist_list reglist[4];
487: void *ptr = adreno_dev->pwrup_reglist->hostptr;
488: struct cpu_gpu_lock *lock = ptr;
489: int items = 0, i, j;
--- LINES 493-617 ---
493: /* Static IFPC-only registers */
494: reglist[items] = REGLIST(a6xx_ifpc_pwrup_reglist);
495: list_offset += reglist[items++].count * 2;
496:
497: if (adreno_is_a650_family(adreno_dev)) {
498: reglist[items] = REGLIST(a650_ifpc_pwrup_reglist);
499: list_offset += reglist[items++].count * 2;
500: }
501:
502: /* Static IFPC + preemption registers */
503: reglist[items++] = REGLIST(a6xx_pwrup_reglist);
504:
505: /* Add target specific registers */
506: if (adreno_is_a615_family(adreno_dev))
507: reglist[items++] = REGLIST(a615_pwrup_reglist);
508: else if (adreno_is_a650_family(adreno_dev))
509: reglist[items++] = REGLIST(a650_pwrup_reglist);
510:
511: /*
512: * For each entry in each of the lists, write the offset and the current
513: * register value into the GPU buffer
514: */
515: for (i = 0; i < items; i++) {
516: u32 *r = reglist[i].regs;
517:
518: for (j = 0; j < reglist[i].count; j++) {
519: *dest++ = r[j];
520: kgsl_regread(KGSL_DEVICE(adreno_dev), r[j], dest++);
521: }
522:
523: lock->list_length += reglist[i].count * 2;
524:
525: if ((r == a6xx_ifpc_pwrup_reglist) || (r == a650_ifpc_pwrup_reglist)) {
526: u32 cs_len = adreno_coresight_patch_pwrup_reglist(adreno_dev, dest);
527:
528: cs_len = cs_len * 2;
529: lock->list_length += cs_len;
530: list_offset += cs_len;
531: dest += cs_len;
532: }
533: }
534:
535: if (adreno_is_a630(adreno_dev)) {
536: *dest++ = A6XX_RBBM_VBIF_CLIENT_QOS_CNTL;
537: kgsl_regread(KGSL_DEVICE(adreno_dev),
538: A6XX_RBBM_VBIF_CLIENT_QOS_CNTL, dest++);
539: } else {
540: *dest++ = A6XX_RBBM_GBIF_CLIENT_QOS_CNTL;
541: kgsl_regread(KGSL_DEVICE(adreno_dev),
542: A6XX_RBBM_GBIF_CLIENT_QOS_CNTL, dest++);
543: }
544:
545: lock->list_length += 2;
546:
547: *dest++ = A6XX_RBBM_PERFCTR_CNTL;
548: *dest++ = 1;
549: lock->list_length += 2;
550:
551: /*
552: * The overall register list is composed of
553: * 1. Static IFPC-only registers
554: * 2. Static IFPC + preemption registers
555: * 3. Dynamic IFPC + preemption registers (ex: perfcounter selects)
556: *
557: * The CP views the second and third entries as one dynamic list
558: * starting from list_offset. list_length should be the total dwords in
559: * all the lists and list_offset should be specified as the size in
560: * dwords of the first entry in the list.
561: */
562: lock->list_offset = list_offset;
563: }
564:
565:
566: static void a6xx_llc_configure_gpu_scid(struct adreno_device *adreno_dev);
567: static void a6xx_llc_configure_gpuhtw_scid(struct adreno_device *adreno_dev);
568: static void a6xx_llc_configure_gpumv_scid(struct adreno_device *adreno_dev);
569: static void a6xx_llc_enable_overrides(struct adreno_device *adreno_dev);
570:
571: static void a6xx_set_secvid(struct kgsl_device *device)
572: {
573: static bool set;
574:
575: if (set || !device->mmu.secured)
576: return;
577:
578: kgsl_regwrite(device, A6XX_RBBM_SECVID_TSB_CNTL, 0x0);
579: kgsl_regwrite(device, A6XX_RBBM_SECVID_TSB_TRUSTED_BASE_LO,
580: lower_32_bits(KGSL_IOMMU_SECURE_BASE32));
581: kgsl_regwrite(device, A6XX_RBBM_SECVID_TSB_TRUSTED_BASE_HI,
582: upper_32_bits(KGSL_IOMMU_SECURE_BASE32));
583: kgsl_regwrite(device, A6XX_RBBM_SECVID_TSB_TRUSTED_SIZE,
584: FIELD_PREP(GENMASK(31, 12),
585: (KGSL_IOMMU_SECURE_SIZE(&device->mmu) / SZ_4K)));
586:
587: if (ADRENO_QUIRK(ADRENO_DEVICE(device), ADRENO_QUIRK_SECVID_SET_ONCE))
588: set = true;
589: }
590:
591: static void a6xx_deassert_gbif_halt(struct adreno_device *adreno_dev)
592: {
593: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
594:
595: kgsl_regwrite(device, A6XX_GBIF_HALT, 0x0);
596:
597: if (adreno_is_a619_holi(adreno_dev))
598: kgsl_regwrite(device, A6XX_RBBM_GPR0_CNTL, 0x0);
599: else
600: kgsl_regwrite(device, A6XX_RBBM_GBIF_HALT, 0x0);
601: }
602:
603: bool a6xx_gx_is_on(struct adreno_device *adreno_dev)
604: {
605: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
606: struct kgsl_pwrctrl *pwr = &device->pwrctrl;
607: bool gdsc_on, clk_on;
608:
609: clk_on = __clk_is_enabled(pwr->grp_clks[0]);
610:
611: if (pwr->gx_pd)
612: gdsc_on = kgsl_genpd_is_enabled(pwr->gx_pd);
613: else
614: gdsc_on = regulator_is_enabled(pwr->gx_regulator);
615:
616: return (gdsc_on & clk_on);
617: }
--- LINES 634-900 ---
634: {
635: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
636: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev);
637: unsigned int hbb_hi = 0, hbb_lo = 0;
638: unsigned int uavflagprd_inv;
639: struct adreno_ubwc_props *ubwc_props = &adreno_dev->ubwc_props;
640: u32 mal = adreno_dev->mal;
641:
642: /* Enable 64 bit addressing */
643: kgsl_regwrite(device, A6XX_CP_ADDR_MODE_CNTL, 0x1);
644: kgsl_regwrite(device, A6XX_VSC_ADDR_MODE_CNTL, 0x1);
645: kgsl_regwrite(device, A6XX_GRAS_ADDR_MODE_CNTL, 0x1);
646: kgsl_regwrite(device, A6XX_RB_ADDR_MODE_CNTL, 0x1);
647: kgsl_regwrite(device, A6XX_PC_ADDR_MODE_CNTL, 0x1);
648: kgsl_regwrite(device, A6XX_HLSQ_ADDR_MODE_CNTL, 0x1);
649: kgsl_regwrite(device, A6XX_VFD_ADDR_MODE_CNTL, 0x1);
650: kgsl_regwrite(device, A6XX_VPC_ADDR_MODE_CNTL, 0x1);
651: kgsl_regwrite(device, A6XX_UCHE_ADDR_MODE_CNTL, 0x1);
652: kgsl_regwrite(device, A6XX_SP_ADDR_MODE_CNTL, 0x1);
653: kgsl_regwrite(device, A6XX_TPL1_ADDR_MODE_CNTL, 0x1);
654: kgsl_regwrite(device, A6XX_RBBM_SECVID_TSB_ADDR_MODE_CNTL, 0x1);
655:
656: /* Set up VBIF registers from the GPU core definition */
657: kgsl_regmap_multi_write(&device->regmap, a6xx_core->vbif,
658: a6xx_core->vbif_count);
659:
660: if (ADRENO_QUIRK(adreno_dev, ADRENO_QUIRK_LIMIT_UCHE_GBIF_RW))
661: kgsl_regwrite(device, A6XX_UCHE_GBIF_GX_CONFIG, 0x10200F9);
662:
663: /* Make all blocks contribute to the GPU BUSY perf counter */
664: kgsl_regwrite(device, A6XX_RBBM_PERFCTR_GPU_BUSY_MASKED, 0xFFFFFFFF);
665:
666: /*
667: * Set UCHE_WRITE_THRU_BASE to the UCHE_TRAP_BASE effectively
668: * disabling L2 bypass
669: */
670: kgsl_regwrite(device, A6XX_UCHE_WRITE_RANGE_MAX_LO, 0xffffffc0);
671: kgsl_regwrite(device, A6XX_UCHE_WRITE_RANGE_MAX_HI, 0x0001ffff);
672: kgsl_regwrite(device, A6XX_UCHE_TRAP_BASE_LO, 0xfffff000);
673: kgsl_regwrite(device, A6XX_UCHE_TRAP_BASE_HI, 0x0001ffff);
674: kgsl_regwrite(device, A6XX_UCHE_WRITE_THRU_BASE_LO, 0xfffff000);
675: kgsl_regwrite(device, A6XX_UCHE_WRITE_THRU_BASE_HI, 0x0001ffff);
676:
677: /*
678: * Some A6xx targets no longer use a programmed UCHE GMEM base
679: * address, so only write the registers if this address is
680: * non-zero.
681: */
682: if (adreno_dev->uche_gmem_base) {
683: kgsl_regwrite(device, A6XX_UCHE_GMEM_RANGE_MIN_LO,
684: adreno_dev->uche_gmem_base);
685: kgsl_regwrite(device, A6XX_UCHE_GMEM_RANGE_MIN_HI, 0x0);
686: kgsl_regwrite(device, A6XX_UCHE_GMEM_RANGE_MAX_LO,
687: adreno_dev->uche_gmem_base +
688: adreno_dev->gpucore->gmem_size - 1);
689: kgsl_regwrite(device, A6XX_UCHE_GMEM_RANGE_MAX_HI, 0x0);
690: }
691:
692: kgsl_regwrite(device, A6XX_UCHE_FILTER_CNTL, 0x804);
693: kgsl_regwrite(device, A6XX_UCHE_CACHE_WAYS, 0x4);
694:
695: /* ROQ sizes are twice as big on a640/a680 than on a630 */
696: if (adreno_is_a612_family(adreno_dev) || adreno_is_a610_family(adreno_dev) ||
697: adreno_is_a702_family(adreno_dev)) {
698: kgsl_regwrite(device, A6XX_CP_ROQ_THRESHOLDS_2, 0x00800060);
699: kgsl_regwrite(device, A6XX_CP_ROQ_THRESHOLDS_1, 0x40201b16);
700: } else if (ADRENO_GPUREV(adreno_dev) >= ADRENO_REV_A640) {
701: kgsl_regwrite(device, A6XX_CP_ROQ_THRESHOLDS_2, 0x02000140);
702: kgsl_regwrite(device, A6XX_CP_ROQ_THRESHOLDS_1, 0x8040362C);
703: } else {
704: kgsl_regwrite(device, A6XX_CP_ROQ_THRESHOLDS_2, 0x010000C0);
705: kgsl_regwrite(device, A6XX_CP_ROQ_THRESHOLDS_1, 0x8040362C);
706: }
707:
708: if (adreno_is_a660(adreno_dev))
709: kgsl_regwrite(device, A6XX_CP_LPAC_PROG_FIFO_SIZE, 0x00000020);
710:
711: if (adreno_is_a663(adreno_dev)) {
712: kgsl_regwrite(device, A6XX_RBBM_GBIF_CLIENT_QOS_CNTL, 0x0);
713: kgsl_regwrite(device, A6XX_RBBM_LPAC_GBIF_CLIENT_QOS_CNTL, 0x0);
714: kgsl_regwrite(device, A6XX_CP_LPAC_PROG_FIFO_SIZE, 0x00000020);
715: }
716:
717: if (adreno_is_a612_family(adreno_dev) || adreno_is_a610_family(adreno_dev)) {
718: /* For A612, gen6_3_26_0 and A610 Mem pool size is reduced to 48 */
719: kgsl_regwrite(device, A6XX_CP_MEM_POOL_SIZE, 48);
720: kgsl_regwrite(device, A6XX_CP_MEM_POOL_DBG_ADDR, 47);
721: } else if (adreno_is_a702_family(adreno_dev)) {
722: kgsl_regwrite(device, A6XX_CP_MEM_POOL_SIZE, 64);
723: kgsl_regwrite(device, A6XX_CP_MEM_POOL_DBG_ADDR, 63);
724: } else {
725: kgsl_regwrite(device, A6XX_CP_MEM_POOL_SIZE, 128);
726: }
727:
728: /* Setting the primFifo thresholds values */
729: kgsl_regwrite(device, A6XX_PC_DBG_ECO_CNTL,
730: a6xx_core->prim_fifo_threshold);
731:
732: /* This enables ECO for an issue in SP instruction fetching */
733: if (adreno_is_a642l(adreno_dev) || adreno_is_a643(adreno_dev))
734: kgsl_regrmw(device, A6XX_SP_DBG_ECO_CNTL, 0x6,
735: FIELD_PREP(GENMASK(2, 1), 0x3));
736:
737: /* Set the AHB default slave response to "ERROR" */
738: kgsl_regwrite(device, A6XX_CP_AHB_CNTL, 0x1);
739:
740: /* Turn on performance counters */
741: kgsl_regwrite(device, A6XX_RBBM_PERFCTR_CNTL, 0x1);
742:
743: /* Turn on the IFPC counter (countable 4 on XOCLK4) */
744: if (gmu_core_isenabled(device))
745: gmu_core_regrmw(device, A6XX_GMU_CX_GMU_POWER_COUNTER_SELECT_1,
746: 0xff, 0x4);
747:
748: /* Turn on GX_MEM retention */
749: if (gmu_core_isenabled(device) && adreno_is_a612(adreno_dev)) {
750: kgsl_regwrite(device, A6XX_RBBM_BLOCK_GX_RETENTION_CNTL, 0x7FB);
751: /* For CP IPC interrupt */
752: kgsl_regwrite(device, A6XX_RBBM_INT_2_MASK, 0x00000010);
753: }
754:
755: /* macrotilingmode 0: 4 channels (default)
756: * overwrite to 1: 8 channels for supported gpus
757: */
758: if (adreno_is_a680(adreno_dev) ||
759: adreno_is_a663(adreno_dev) ||
760: adreno_is_a704(adreno_dev))
761: kgsl_regwrite(device, A6XX_RBBM_NC_MODE_CNTL, 1);
762:
763: if (adreno_dev->highest_bank_bit) {
764: hbb_lo = (adreno_dev->highest_bank_bit - 13) & 3;
765: hbb_hi = ((adreno_dev->highest_bank_bit - 13) >> 2) & 1;
766: }
767:
768: mal = (mal == 64) ? 1 : 0;
769:
770: uavflagprd_inv = (adreno_is_a650_family(adreno_dev)) ? 2 : 0;
771:
772: kgsl_regwrite(device, A6XX_RB_NC_MODE_CNTL,
773: (ubwc_props->level2_swizzling_dis << 12) |
774: (ubwc_props->rgb565_predicator << 11) |
775: (hbb_hi << 10) | (ubwc_props->amsbc << 4) | (mal << 3) |
776: (hbb_lo << 1) | ubwc_props->mode);
777:
778:
779: kgsl_regwrite(device, A6XX_TPL1_NC_MODE_CNTL,
780: (ubwc_props->level2_swizzling_dis << 6) | (hbb_hi << 4) |
781: (mal << 3) | (hbb_lo << 1) | ubwc_props->mode);
782:
783: kgsl_regwrite(device, A6XX_SP_NC_MODE_CNTL,
784: (ubwc_props->level2_swizzling_dis << 12) | (hbb_hi << 10) |
785: (mal << 3) | (uavflagprd_inv << 4) |
786: (hbb_lo << 1) | ubwc_props->mode);
787:
788: kgsl_regwrite(device, A6XX_UCHE_MODE_CNTL, (mal << 23) |
789: (hbb_lo << 21));
790:
791: kgsl_regwrite(device, A6XX_RBBM_INTERFACE_HANG_INT_CNTL,
792: (1 << 30) | a6xx_core->hang_detect_cycles);
793:
794: kgsl_regwrite(device, A6XX_UCHE_CLIENT_PF, BIT(7) |
795: FIELD_PREP(GENMASK(3, 0), adreno_dev->uche_client_pf));
796:
797: /* Set weights for bicubic filtering */
798: if (adreno_is_a650_family(adreno_dev)) {
799: kgsl_regwrite(device, A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_0, 0);
800: kgsl_regwrite(device, A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_1,
801: 0x3FE05FF4);
802: kgsl_regwrite(device, A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_2,
803: 0x3FA0EBEE);
804: kgsl_regwrite(device, A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_3,
805: 0x3F5193ED);
806: kgsl_regwrite(device, A6XX_TPL1_BICUBIC_WEIGHTS_TABLE_4,
807: 0x3F0243F0);
808: }
809:
810: /* Set TWOPASSUSEWFI in A6XX_PC_DBG_ECO_CNTL if requested */
811: if (ADRENO_QUIRK(adreno_dev, ADRENO_QUIRK_TWO_PASS_USE_WFI))
812: kgsl_regrmw(device, A6XX_PC_DBG_ECO_CNTL, 0, (1 << 8));
813:
814: /* Set the bit vccCacheSkipDis=1 to get rid of TSEskip logic */
815: if (a6xx_core->disable_tseskip)
816: kgsl_regrmw(device, A6XX_PC_DBG_ECO_CNTL, 0, (1 << 9));
817:
818: /* Set the bit in HLSQ Cluster for A702 family */
819: if (adreno_is_a702_family(adreno_dev))
820: kgsl_regwrite(device, A6XX_CP_CHICKEN_DBG, (1 << 24));
821:
822: /* Enable the GMEM save/restore feature for preemption */
823: if (adreno_is_preemption_enabled(adreno_dev))
824: kgsl_regwrite(device, A6XX_RB_CONTEXT_SWITCH_GMEM_SAVE_RESTORE,
825: 0x1);
826:
827: /*
828: * Enable GMU power counter 0 to count GPU busy. This is applicable to
829: * all a6xx targets
830: */
831: kgsl_regwrite(device, A6XX_GPU_GMU_AO_GPU_CX_BUSY_MASK, 0xff000000);
832: kgsl_regrmw(device, A6XX_GMU_CX_GMU_POWER_COUNTER_SELECT_0, 0xff, 0x20);
833: kgsl_regwrite(device, A6XX_GMU_CX_GMU_POWER_COUNTER_ENABLE, 0x1);
834:
835: a6xx_protect_init(adreno_dev);
836: /*
837: * We start LM here because we want all the following to be up
838: * 1. GX HS
839: * 2. SPTPRAC
840: * 3. HFI
841: * At this point, we are guaranteed all.
842: */
843:
844: /* Configure LLCC */
845: a6xx_llc_configure_gpu_scid(adreno_dev);
846: a6xx_llc_configure_gpuhtw_scid(adreno_dev);
847: a6xx_llc_configure_gpumv_scid(adreno_dev);
848:
849: a6xx_llc_enable_overrides(adreno_dev);
850:
851: if (adreno_is_a662(adreno_dev))
852: kgsl_regrmw(device, A6XX_GBIF_CX_CONFIG, 0x3c0,
853: FIELD_PREP(GENMASK(7, 6), 0x1) |
854: FIELD_PREP(GENMASK(9, 8), 0x1));
855:
856: if (adreno_is_a660(adreno_dev)) {
857: kgsl_regwrite(device, A6XX_CP_CHICKEN_DBG, 0x1);
858: kgsl_regwrite(device, A6XX_RBBM_GBIF_CLIENT_QOS_CNTL, 0x0);
859: }
860:
861: /* Set dualQ + disable afull for A660 and A663 GPU but not for A642l and A643 */
862: if ((adreno_is_a660(adreno_dev) || adreno_is_a663(adreno_dev)) &&
863: !(adreno_is_a642l(adreno_dev) || adreno_is_a643(adreno_dev)))
864: kgsl_regwrite(device, A6XX_UCHE_CMDQ_CONFIG, 0x66906);
865:
866: if (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV))
867: kgsl_regwrite(device, A6XX_CP_APRIV_CNTL, A6XX_APRIV_DEFAULT);
868:
869: a6xx_set_secvid(device);
870:
871: /*
872: * Enable hardware clock gating here to prevent any register access
873: * issue due to internal clock gating.
874: */
875: a6xx_hwcg_set(adreno_dev, true);
876:
877: /*
878: * All registers must be written before this point so that we don't
879: * miss any register programming when we patch the power up register
880: * list.
881: */
882: if (!adreno_dev->patch_reglist &&
883: (adreno_dev->pwrup_reglist->gpuaddr != 0)) {
884: a6xx_patch_pwrup_reglist(adreno_dev);
885: adreno_dev->patch_reglist = true;
886: }
887:
888: /*
889: * During adreno_stop, GBIF halt is asserted to ensure
890: * no further transaction can go through GPU before GPU
891: * headswitch is turned off.
892: *
893: * This halt is deasserted once headswitch goes off but
894: * incase headswitch doesn't goes off clear GBIF halt
895: * here to ensure GPU wake-up doesn't fail because of
896: * halted GPU transactions.
897: */
898: a6xx_deassert_gbif_halt(adreno_dev);
899:
900: }
--- LINES 907-934 ---
907:
908: /*
909: * During adreno_stop() GBIF halt is asserted to ensure that
910: * no further transactions go through the GPU before the
911: * GPU headswitch is turned off.
912: *
913: * The halt is supposed to be deasserted when the headswitch goes off
914: * but clear it again during start to be sure
915: */
916: kgsl_regwrite(device, A6XX_GBIF_HALT, 0x0);
917: kgsl_regwrite(device, A6XX_RBBM_GBIF_HALT, 0x0);
918:
919: ret = kgsl_mmu_start(device);
920: if (ret)
921: return ret;
922:
923: adreno_get_bus_counters(adreno_dev);
924: adreno_perfcounter_restore(adreno_dev);
925:
926: a6xx_start(adreno_dev);
927: return 0;
928: }
929:
930: /*
931: * CP_INIT_MAX_CONTEXT bit tells if the multiple hardware contexts can
932: * be used at once of if they should be serialized
933: */
934: #define CP_INIT_MAX_CONTEXT BIT(0)
--- LINES 946-972 ---
946: #define CP_INIT_DRAWCALL_FILTER_RANGE BIT(4)
947:
948: /* Ucode workaround masks */
949: #define CP_INIT_UCODE_WORKAROUND_MASK BIT(5)
950:
951: /*
952: * Operation mode mask
953: *
954: * This ordinal provides the option to disable the
955: * save/restore of performance counters across preemption.
956: */
957: #define CP_INIT_OPERATION_MODE_MASK BIT(6)
958:
959: /* Register initialization list */
960: #define CP_INIT_REGISTER_INIT_LIST BIT(7)
961:
962: /* Register initialization list with spinlock */
963: #define CP_INIT_REGISTER_INIT_LIST_WITH_SPINLOCK BIT(8)
964:
965: #define CP_INIT_MASK (CP_INIT_MAX_CONTEXT | \
966: CP_INIT_ERROR_DETECTION_CONTROL | \
967: CP_INIT_HEADER_DUMP | \
968: CP_INIT_DEFAULT_RESET_STATE | \
969: CP_INIT_UCODE_WORKAROUND_MASK | \
970: CP_INIT_OPERATION_MODE_MASK | \
971: CP_INIT_REGISTER_INIT_LIST_WITH_SPINLOCK)
972:
--- LINES 993-1235 ---
993: }
994:
995: if (CP_INIT_MASK & CP_INIT_UCODE_WORKAROUND_MASK)
996: cmds[i++] = 0x00000000;
997:
998: if (CP_INIT_MASK & CP_INIT_OPERATION_MODE_MASK)
999: cmds[i++] = 0x00000002;
1000:
1001: if (CP_INIT_MASK & CP_INIT_REGISTER_INIT_LIST_WITH_SPINLOCK) {
1002: uint64_t gpuaddr = adreno_dev->pwrup_reglist->gpuaddr;
1003:
1004: cmds[i++] = lower_32_bits(gpuaddr);
1005: cmds[i++] = upper_32_bits(gpuaddr);
1006: cmds[i++] = 0;
1007: }
1008: }
1009:
1010: void a6xx_spin_idle_debug(struct adreno_device *adreno_dev,
1011: const char *str)
1012: {
1013: struct kgsl_device *device = &adreno_dev->dev;
1014: unsigned int rptr, wptr;
1015: unsigned int status, status3, intstatus;
1016: unsigned int hwfault;
1017:
1018: dev_err(device->dev, str);
1019:
1020: kgsl_regread(device, A6XX_CP_RB_RPTR, &rptr);
1021: kgsl_regread(device, A6XX_CP_RB_WPTR, &wptr);
1022:
1023: kgsl_regread(device, A6XX_RBBM_STATUS, &status);
1024: kgsl_regread(device, A6XX_RBBM_STATUS3, &status3);
1025: kgsl_regread(device, A6XX_RBBM_INT_0_STATUS, &intstatus);
1026: kgsl_regread(device, A6XX_CP_HW_FAULT, &hwfault);
1027:
1028:
1029: dev_err(device->dev,
1030: "rb=%d pos=%X/%X rbbm_status=%8.8X/%8.8X int_0_status=%8.8X\n",
1031: adreno_dev->cur_rb ? adreno_dev->cur_rb->id : -1, rptr, wptr,
1032: status, status3, intstatus);
1033:
1034: dev_err(device->dev, " hwfault=%8.8X\n", hwfault);
1035:
1036: kgsl_device_snapshot(device, NULL, NULL, false);
1037:
1038: }
1039:
1040: /*
1041: * a6xx_send_cp_init() - Initialize ringbuffer
1042: * @adreno_dev: Pointer to adreno device
1043: * @rb: Pointer to the ringbuffer of device
1044: *
1045: * Submit commands for ME initialization,
1046: */
1047: static int a6xx_send_cp_init(struct adreno_device *adreno_dev,
1048: struct adreno_ringbuffer *rb)
1049: {
1050: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1051: unsigned int *cmds;
1052: int ret;
1053:
1054: cmds = adreno_ringbuffer_allocspace(rb, A6XX_CP_INIT_DWORDS);
1055: if (IS_ERR(cmds))
1056: return PTR_ERR(cmds);
1057:
1058: a6xx_cp_init_cmds(adreno_dev, cmds);
1059:
1060: ret = a6xx_ringbuffer_submit(rb, NULL, true);
1061: if (!ret) {
1062: ret = adreno_spin_idle(adreno_dev, 2000);
1063: if (ret) {
1064: a6xx_spin_idle_debug(adreno_dev,
1065: "CP initialization failed to idle\n");
1066:
1067: kgsl_sharedmem_writel(device->scratch,
1068: SCRATCH_RB_OFFSET(rb->id, rptr), 0);
1069: rb->wptr = 0;
1070: rb->_wptr = 0;
1071: }
1072: }
1073:
1074: return ret;
1075: }
1076:
1077: /*
1078: * Follow the ME_INIT sequence with a preemption yield to allow the GPU to move
1079: * to a different ringbuffer, if desired
1080: */
1081: static int _preemption_init(struct adreno_device *adreno_dev,
1082: struct adreno_ringbuffer *rb, unsigned int *cmds,
1083: struct kgsl_context *context)
1084: {
1085: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1086: unsigned int *cmds_orig = cmds;
1087:
1088: /* Turn CP protection OFF on legacy targets */
1089: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV))
1090: cmds += cp_protected_mode(adreno_dev, cmds, 0);
1091:
1092: *cmds++ = cp_type7_packet(CP_SET_PSEUDO_REGISTER,
1093: kgsl_mmu_is_secured(&device->mmu) ? 6 : 3);
1094: *cmds++ = SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR;
1095: cmds += cp_gpuaddr(adreno_dev, cmds,
1096: rb->preemption_desc->gpuaddr);
1097:
1098: if (kgsl_mmu_is_secured(&device->mmu)) {
1099: *cmds++ = SET_PSEUDO_PRIV_SECURE_SAVE_ADDR;
1100: cmds += cp_gpuaddr(adreno_dev, cmds,
1101: rb->secure_preemption_desc->gpuaddr);
1102: }
1103:
1104: /* Turn CP protection back ON */
1105: if (!ADRENO_FEATURE(adreno_dev, ADRENO_APRIV))
1106: cmds += cp_protected_mode(adreno_dev, cmds, 1);
1107:
1108: *cmds++ = cp_type7_packet(CP_CONTEXT_SWITCH_YIELD, 4);
1109: cmds += cp_gpuaddr(adreno_dev, cmds, 0x0);
1110: *cmds++ = 0;
1111: /* generate interrupt on preemption completion */
1112: *cmds++ = 0;
1113:
1114: return cmds - cmds_orig;
1115: }
1116:
1117: static int a6xx_post_start(struct adreno_device *adreno_dev)
1118: {
1119: int ret;
1120: unsigned int *cmds, *start;
1121: struct adreno_ringbuffer *rb = adreno_dev->cur_rb;
1122: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1123:
1124: if (!adreno_is_preemption_enabled(adreno_dev))
1125: return 0;
1126:
1127: cmds = adreno_ringbuffer_allocspace(rb, 42);
1128: if (IS_ERR(cmds)) {
1129: dev_err(device->dev,
1130: "error allocating preemption init cmds\n");
1131: return PTR_ERR(cmds);
1132: }
1133: start = cmds;
1134:
1135: cmds += _preemption_init(adreno_dev, rb, cmds, NULL);
1136:
1137: rb->_wptr = rb->_wptr - (42 - (cmds - start));
1138:
1139: ret = a6xx_ringbuffer_submit(rb, NULL, false);
1140: if (!ret) {
1141: ret = adreno_spin_idle(adreno_dev, 2000);
1142: if (ret)
1143: a6xx_spin_idle_debug(adreno_dev,
1144: "hw preemption initialization failed to idle\n");
1145: }
1146:
1147: return ret;
1148: }
1149:
1150: int a6xx_rb_start(struct adreno_device *adreno_dev)
1151: {
1152: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev);
1153: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1154: u32 cp_rb_cntl = A6XX_CP_RB_CNTL_DEFAULT |
1155: (ADRENO_FEATURE(adreno_dev, ADRENO_APRIV) ? 0 : (1 << 27));
1156: struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE);
1157: struct adreno_ringbuffer *rb;
1158: uint64_t addr;
1159: int ret, i;
1160: unsigned int *cmds;
1161:
1162: /* Clear all the ringbuffers */
1163: FOR_EACH_RINGBUFFER(adreno_dev, rb, i) {
1164: memset(rb->buffer_desc->hostptr, 0xaa, KGSL_RB_SIZE);
1165: kgsl_sharedmem_writel(device->scratch,
1166: SCRATCH_RB_OFFSET(rb->id, rptr), 0);
1167:
1168: rb->wptr = 0;
1169: rb->_wptr = 0;
1170: rb->wptr_preempt_end = ~0;
1171: }
1172:
1173: a6xx_preemption_start(adreno_dev);
1174:
1175: /* Set up the current ringbuffer */
1176: rb = ADRENO_CURRENT_RINGBUFFER(adreno_dev);
1177: addr = SCRATCH_RB_GPU_ADDR(device, rb->id, rptr);
1178:
1179: kgsl_regwrite(device, A6XX_CP_RB_RPTR_ADDR_LO, lower_32_bits(addr));
1180: kgsl_regwrite(device, A6XX_CP_RB_RPTR_ADDR_HI, upper_32_bits(addr));
1181:
1182: /*
1183: * The size of the ringbuffer in the hardware is the log2
1184: * representation of the size in quadwords (sizedwords / 2).
1185: */
1186: kgsl_regwrite(device, A6XX_CP_RB_CNTL, cp_rb_cntl);
1187:
1188: kgsl_regwrite(device, A6XX_CP_RB_BASE,
1189: lower_32_bits(rb->buffer_desc->gpuaddr));
1190:
1191: kgsl_regwrite(device, A6XX_CP_RB_BASE_HI,
1192: upper_32_bits(rb->buffer_desc->gpuaddr));
1193:
1194: /* Program the ucode base for CP */
1195: kgsl_regwrite(device, A6XX_CP_SQE_INSTR_BASE_LO,
1196: lower_32_bits(fw->memdesc->gpuaddr));
1197: kgsl_regwrite(device, A6XX_CP_SQE_INSTR_BASE_HI,
1198: upper_32_bits(fw->memdesc->gpuaddr));
1199:
1200: /* Clear the SQE_HALT to start the CP engine */
1201: kgsl_regwrite(device, A6XX_CP_SQE_CNTL, 1);
1202:
1203: ret = a6xx_send_cp_init(adreno_dev, rb);
1204: if (ret)
1205: return ret;
1206:
1207: ret = adreno_zap_shader_load(adreno_dev, a6xx_core->zap_name);
1208: if (ret)
1209: return ret;
1210:
1211: /*
1212: * Take the GPU out of secure mode. Try the zap shader if it is loaded,
1213: * otherwise just try to write directly to the secure control register
1214: */
1215: if (!adreno_dev->zap_loaded)
1216: kgsl_regwrite(device, A6XX_RBBM_SECVID_TRUST_CNTL, 0);
1217: else {
1218: cmds = adreno_ringbuffer_allocspace(rb, 2);
1219: if (IS_ERR(cmds))
1220: return PTR_ERR(cmds);
1221:
1222: *cmds++ = cp_packet(adreno_dev, CP_SET_SECURE_MODE, 1);
1223: *cmds++ = 0;
1224:
1225: ret = a6xx_ringbuffer_submit(rb, NULL, true);
1226: if (!ret) {
1227: ret = adreno_spin_idle(adreno_dev, 2000);
1228: if (ret) {
1229: a6xx_spin_idle_debug(adreno_dev,
1230: "Switch to unsecure failed to idle\n");
1231: return ret;
1232: }
1233: }
1234: }
1235:
--- LINES 1260-1344 ---
1260: */
1261: static void a6xx_prepare_for_regulator_disable(struct adreno_device *adreno_dev)
1262: {
1263: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1264:
1265: /* This sequence is only required for A611 */
1266: if (!adreno_is_a611(adreno_dev))
1267: return;
1268:
1269: kgsl_regwrite(device, A6XX_RBBM_SW_RESET_CMD, 0x1);
1270: /* Make sure above writes are posted before turning off power resource.*/
1271: wmb();
1272: /*wait for 100usecs, to allow the software reset to complete*/
1273: udelay(100);
1274: }
1275:
1276: /*
1277: * a6xx_gpu_keepalive() - GMU reg write to request GPU stays on
1278: * @adreno_dev: Pointer to the adreno device that has the GMU
1279: * @state: State to set: true is ON, false is OFF
1280: */
1281: static void a6xx_gpu_keepalive(struct adreno_device *adreno_dev,
1282: bool state)
1283: {
1284: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1285:
1286: if (!gmu_core_isenabled(device))
1287: return;
1288:
1289: gmu_core_regwrite(device, A6XX_GMU_GMU_PWR_COL_KEEPALIVE, state);
1290: }
1291:
1292: bool a6xx_irq_pending(struct adreno_device *adreno_dev)
1293: {
1294: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1295: u32 status;
1296:
1297: kgsl_regread(device, A6XX_RBBM_INT_0_STATUS, &status);
1298:
1299: /* Return busy if a interrupt is pending */
1300: return ((status & adreno_dev->irq_mask) ||
1301: atomic_read(&adreno_dev->pending_irq_refcnt));
1302: }
1303:
1304: static bool a619_holi_hw_isidle(struct adreno_device *adreno_dev)
1305: {
1306: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1307: unsigned int reg;
1308:
1309: kgsl_regread(device, A6XX_RBBM_STATUS, ®);
1310: if (reg & 0xfffffffe)
1311: return false;
1312:
1313: return a6xx_irq_pending(adreno_dev) ? false : true;
1314: }
1315:
1316: bool a6xx_hw_isidle(struct adreno_device *adreno_dev)
1317: {
1318: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1319: unsigned int reg;
1320:
1321: /* Non GMU devices monitor the RBBM status */
1322: if (!gmu_core_isenabled(device)) {
1323: kgsl_regread(device, A6XX_RBBM_STATUS, ®);
1324: if (reg & 0xfffffffe)
1325: return false;
1326:
1327: return a6xx_irq_pending(adreno_dev) ? false : true;
1328: }
1329:
1330: gmu_core_regread(device, A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS, ®);
1331:
1332: /* Bit 23 is GPUBUSYIGNAHB */
1333: return (reg & BIT(23)) ? false : true;
1334: }
1335:
1336: int a6xx_microcode_read(struct adreno_device *adreno_dev)
1337: {
1338: struct adreno_firmware *sqe_fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE);
1339: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev);
1340:
1341: return adreno_get_firmware(adreno_dev, a6xx_core->sqefw_name, sqe_fw);
1342: }
1343:
1344: static int64_t a6xx_read_throttling_counters(struct adreno_device *adreno_dev)
--- LINES 1442-1472 ---
1442: }
1443:
1444: /* This is only defined for non-GMU and non-RGMU targets */
1445: static int a6xx_clear_pending_transactions(struct adreno_device *adreno_dev)
1446: {
1447: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1448: int ret;
1449:
1450: if (adreno_is_a619_holi(adreno_dev)) {
1451: kgsl_regwrite(device, A6XX_RBBM_GPR0_CNTL, 0x1e0);
1452: ret = adreno_wait_for_halt_ack(device,
1453: A6XX_RBBM_VBIF_GX_RESET_STATUS, 0xf0);
1454: } else {
1455: kgsl_regwrite(device, A6XX_RBBM_GBIF_HALT,
1456: A6XX_GBIF_GX_HALT_MASK);
1457: ret = adreno_wait_for_halt_ack(device, A6XX_RBBM_GBIF_HALT_ACK,
1458: A6XX_GBIF_GX_HALT_MASK);
1459: }
1460:
1461: if (ret)
1462: return ret;
1463:
1464: return a6xx_halt_gbif(adreno_dev);
1465: }
1466:
1467: /**
1468: * a6xx_reset() - Helper function to reset the GPU
1469: * @adreno_dev: Pointer to the adreno device structure for the GPU
1470: *
1471: * Try to reset the GPU to recover from a fault for targets without
1472: * a GMU.
--- LINES 1483-1555 ---
1483:
1484: /* Clear ctrl_flags to ensure clocks and regulators are turned off */
1485: device->pwrctrl.ctrl_flags = 0;
1486:
1487: kgsl_pwrctrl_change_state(device, KGSL_STATE_INIT);
1488:
1489: /* since device is officially off now clear start bit */
1490: clear_bit(ADRENO_DEVICE_STARTED, &adreno_dev->priv);
1491:
1492: a6xx_reset_preempt_records(adreno_dev);
1493:
1494: ret = adreno_start(device, 0);
1495: if (ret)
1496: return ret;
1497:
1498: kgsl_pwrctrl_change_state(device, KGSL_STATE_ACTIVE);
1499:
1500: device->pwrctrl.ctrl_flags = flags;
1501:
1502: /* Toggle GX CPR on demand */
1503: a6xx_gx_cpr_toggle(device);
1504:
1505: /*
1506: * If active_cnt is zero, there is no need to keep the GPU active. So,
1507: * we should transition to SLUMBER.
1508: */
1509: if (!atomic_read(&device->active_cnt))
1510: kgsl_pwrctrl_change_state(device, KGSL_STATE_SLUMBER);
1511:
1512: return 0;
1513: }
1514:
1515: static void a6xx_cp_hw_err_callback(struct adreno_device *adreno_dev, int bit)
1516: {
1517: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1518: unsigned int status1, status2;
1519:
1520: kgsl_regread(device, A6XX_CP_INTERRUPT_STATUS, &status1);
1521:
1522: if (status1 & BIT(A6XX_CP_OPCODE_ERROR)) {
1523: unsigned int opcode;
1524:
1525: kgsl_regwrite(device, A6XX_CP_SQE_STAT_ADDR, 1);
1526: kgsl_regread(device, A6XX_CP_SQE_STAT_DATA, &opcode);
1527: dev_crit_ratelimited(device->dev,
1528: "CP opcode error interrupt | opcode=0x%8.8x\n", opcode);
1529: }
1530: if (status1 & BIT(A6XX_CP_UCODE_ERROR))
1531: dev_crit_ratelimited(device->dev, "CP ucode error interrupt\n");
1532: if (status1 & BIT(A6XX_CP_HW_FAULT_ERROR)) {
1533: kgsl_regread(device, A6XX_CP_HW_FAULT, &status2);
1534: dev_crit_ratelimited(device->dev,
1535: "CP | Ringbuffer HW fault | status=%x\n", status2);
1536: }
1537: if (status1 & BIT(A6XX_CP_REGISTER_PROTECTION_ERROR)) {
1538: kgsl_regread(device, A6XX_CP_PROTECT_STATUS, &status2);
1539: dev_crit_ratelimited(device->dev,
1540: "CP | Protected mode error | %s | addr=%x | status=%x\n",
1541: status2 & (1 << 20) ? "READ" : "WRITE",
1542: status2 & 0x3FFFF, status2);
1543: }
1544: if (status1 & BIT(A6XX_CP_AHB_ERROR))
1545: dev_crit_ratelimited(device->dev,
1546: "CP AHB error interrupt\n");
1547: if (status1 & BIT(A6XX_CP_VSD_PARITY_ERROR))
1548: dev_crit_ratelimited(device->dev,
1549: "CP VSD decoder parity error\n");
1550: if (status1 & BIT(A6XX_CP_ILLEGAL_INSTR_ERROR))
1551: dev_crit_ratelimited(device->dev,
1552: "CP Illegal instruction error\n");
1553:
1554: }
1555:
--- LINES 1697-1723 ---
1697: if (mmu->subtype == KGSL_IOMMU_SMMU_V500)
1698: return;
1699:
1700: /*
1701: * 0x3: readnoallocoverrideen=0
1702: * read-no-alloc=0 - Allocate lines on read miss
1703: * writenoallocoverrideen=1
1704: * write-no-alloc=1 - Do not allocates lines on write miss
1705: */
1706: kgsl_regwrite(device, A6XX_GPU_CX_MISC_SYSTEM_CACHE_CNTL_0, 0x3);
1707: }
1708:
1709: static const char *uche_client[7][3] = {
1710: {"SP | VSC | VPC | HLSQ | PC | LRZ", "TP", "VFD"},
1711: {"VSC | VPC | HLSQ | PC | LRZ", "TP | VFD", "SP"},
1712: {"SP | VPC | HLSQ | PC | LRZ", "TP | VFD", "VSC"},
1713: {"SP | VSC | HLSQ | PC | LRZ", "TP | VFD", "VPC"},
1714: {"SP | VSC | VPC | PC | LRZ", "TP | VFD", "HLSQ"},
1715: {"SP | VSC | VPC | HLSQ | LRZ", "TP | VFD", "PC"},
1716: {"SP | VSC | VPC | HLSQ | PC", "TP | VFD", "LRZ"},
1717: };
1718:
1719: static const char *const uche_client_a660[] = { "VFD", "SP", "VSC", "VPC",
1720: "HLSQ", "PC", "LRZ", "TP" };
1721:
1722: #define SCOOBYDOO 0x5c00bd00
1723:
--- LINES 1736-1762 ---
1736: */
1737: if (!kgsl_mutex_trylock(&device->mutex))
1738: return "UCHE: unknown";
1739:
1740: if (!kgsl_state_is_awake(device)) {
1741: kgsl_mutex_unlock(&device->mutex);
1742: return "UCHE: unknown";
1743: }
1744:
1745: kgsl_regread(device, A6XX_UCHE_CLIENT_PF, &uche_client_id);
1746: kgsl_mutex_unlock(&device->mutex);
1747:
1748: /* Ignore the value if the gpu is in IFPC */
1749: if (uche_client_id == SCOOBYDOO)
1750: return "UCHE: unknown";
1751:
1752: if (adreno_is_a660(ADRENO_DEVICE(device))) {
1753:
1754: /* Mask is 7 bits for A660 */
1755: uche_client_id &= 0x7F;
1756: if (uche_client_id >= ARRAY_SIZE(uche_client_a660) ||
1757: (mid == 2))
1758: return "UCHE: Unknown";
1759:
1760: if (mid == 1)
1761: snprintf(str, sizeof(str), "UCHE: Not %s",
1762: uche_client_a660[uche_client_id]);
--- LINES 1794-1983 ---
1794: case 7:
1795: return "GPMU";
1796: }
1797:
1798: return "Unknown";
1799: }
1800:
1801: static void a6xx_cp_callback(struct adreno_device *adreno_dev, int bit)
1802: {
1803: if (adreno_is_preemption_enabled(adreno_dev))
1804: a6xx_preemption_trigger(adreno_dev, true);
1805:
1806: adreno_scheduler_queue(adreno_dev);
1807: }
1808:
1809: /*
1810: * a6xx_gpc_err_int_callback() - Isr for GPC error interrupts
1811: * @adreno_dev: Pointer to device
1812: * @bit: Interrupt bit
1813: */
1814: static void a6xx_gpc_err_int_callback(struct adreno_device *adreno_dev, int bit)
1815: {
1816: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1817:
1818: /*
1819: * GPC error is typically the result of mistake SW programming.
1820: * Force GPU fault for this interrupt so that we can debug it
1821: * with help of register dump.
1822: */
1823:
1824: dev_crit(device->dev, "RBBM: GPC error\n");
1825: adreno_irqctrl(adreno_dev, 0);
1826:
1827: /* Trigger a fault in the dispatcher - this will effect a restart */
1828: adreno_scheduler_fault(adreno_dev, ADRENO_SOFT_FAULT);
1829: }
1830:
1831: static const struct adreno_irq_funcs a6xx_irq_funcs[32] = {
1832: ADRENO_IRQ_CALLBACK(NULL), /* 0 - RBBM_GPU_IDLE */
1833: ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 1 - RBBM_AHB_ERROR */
1834: ADRENO_IRQ_CALLBACK(NULL), /* 2 - UNUSED */
1835: ADRENO_IRQ_CALLBACK(NULL), /* 3 - UNUSED */
1836: ADRENO_IRQ_CALLBACK(NULL), /* 4 - UNUSED */
1837: ADRENO_IRQ_CALLBACK(NULL), /* 5 - UNUSED */
1838: /* 6 - RBBM_ATB_ASYNC_OVERFLOW */
1839: ADRENO_IRQ_CALLBACK(a6xx_err_callback),
1840: ADRENO_IRQ_CALLBACK(a6xx_gpc_err_int_callback), /* 7 - GPC_ERR */
1841: ADRENO_IRQ_CALLBACK(a6xx_preemption_callback),/* 8 - CP_SW */
1842: ADRENO_IRQ_CALLBACK(a6xx_cp_hw_err_callback), /* 9 - CP_HW_ERROR */
1843: ADRENO_IRQ_CALLBACK(NULL), /* 10 - CP_CCU_FLUSH_DEPTH_TS */
1844: ADRENO_IRQ_CALLBACK(NULL), /* 11 - CP_CCU_FLUSH_COLOR_TS */
1845: ADRENO_IRQ_CALLBACK(NULL), /* 12 - CP_CCU_RESOLVE_TS */
1846: ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 13 - CP_IB2_INT */
1847: ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 14 - CP_IB1_INT */
1848: ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 15 - CP_RB_INT */
1849: ADRENO_IRQ_CALLBACK(NULL), /* 16 - UNUSED */
1850: ADRENO_IRQ_CALLBACK(NULL), /* 17 - CP_RB_DONE_TS */
1851: ADRENO_IRQ_CALLBACK(NULL), /* 18 - CP_WT_DONE_TS */
1852: ADRENO_IRQ_CALLBACK(NULL), /* 19 - UNUSED */
1853: ADRENO_IRQ_CALLBACK(a6xx_cp_callback), /* 20 - CP_CACHE_FLUSH_TS */
1854: ADRENO_IRQ_CALLBACK(NULL), /* 21 - UNUSED */
1855: ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 22 - RBBM_ATB_BUS_OVERFLOW */
1856: /* 23 - MISC_HANG_DETECT */
1857: ADRENO_IRQ_CALLBACK(adreno_hang_int_callback),
1858: ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 24 - UCHE_OOB_ACCESS */
1859: ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 25 - UCHE_TRAP_INTR */
1860: ADRENO_IRQ_CALLBACK(NULL), /* 26 - DEBBUS_INTR_0 */
1861: ADRENO_IRQ_CALLBACK(NULL), /* 27 - DEBBUS_INTR_1 */
1862: ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 28 - TSBWRITEERROR */
1863: ADRENO_IRQ_CALLBACK(NULL), /* 29 - UNUSED */
1864: ADRENO_IRQ_CALLBACK(NULL), /* 30 - ISDB_CPU_IRQ */
1865: ADRENO_IRQ_CALLBACK(NULL), /* 31 - ISDB_UNDER_DEBUG */
1866: };
1867:
1868: /*
1869: * If the AHB fence is not in ALLOW mode when we receive an RBBM
1870: * interrupt, something went wrong. This means that we cannot proceed
1871: * since the IRQ status and clear registers are not accessible.
1872: * This is usually harmless because the GMU will abort power collapse
1873: * and change the fence back to ALLOW. Poll so that this can happen.
1874: */
1875: static int a6xx_irq_poll_fence(struct adreno_device *adreno_dev)
1876: {
1877: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1878: u32 status, fence, fence_retries = 0;
1879: u64 a, b, c;
1880:
1881: if (!gmu_core_isenabled(device))
1882: return 0;
1883:
1884: a = a6xx_read_alwayson(adreno_dev);
1885:
1886: kgsl_regread(device, A6XX_GMU_AO_AHB_FENCE_CTRL, &fence);
1887:
1888: while (fence != 0) {
1889: b = a6xx_read_alwayson(adreno_dev);
1890:
1891: /* Wait for small time before trying again */
1892: udelay(1);
1893: kgsl_regread(device, A6XX_GMU_AO_AHB_FENCE_CTRL, &fence);
1894:
1895: if (fence_retries == 100 && fence != 0) {
1896: c = a6xx_read_alwayson(adreno_dev);
1897:
1898: kgsl_regread(device, A6XX_GMU_RBBM_INT_UNMASKED_STATUS,
1899: &status);
1900:
1901: dev_crit_ratelimited(device->dev,
1902: "status=0x%x Unmasked status=0x%x Mask=0x%x timestamps: %llx %llx %llx\n",
1903: status & adreno_dev->irq_mask, status,
1904: adreno_dev->irq_mask, a, b, c);
1905: return -ETIMEDOUT;
1906: }
1907:
1908: fence_retries++;
1909: }
1910:
1911: return 0;
1912: }
1913:
1914: static irqreturn_t a6xx_hwsched_irq_handler(struct adreno_device *adreno_dev)
1915: {
1916: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1917: irqreturn_t ret = IRQ_NONE;
1918: u32 status;
1919:
1920: /*
1921: * On A6xx, the GPU can power down once the INT_0_STATUS is read
1922: * below. But there still might be some register reads required
1923: * so force the GMU/GPU into KEEPALIVE mode until done with the ISR.
1924: */
1925: a6xx_gpu_keepalive(adreno_dev, true);
1926:
1927: kgsl_regread(device, A6XX_RBBM_INT_0_STATUS, &status);
1928:
1929: kgsl_regwrite(device, A6XX_RBBM_INT_CLEAR_CMD, status);
1930:
1931: ret = adreno_irq_callbacks(adreno_dev, a6xx_irq_funcs, status);
1932:
1933: trace_kgsl_a5xx_irq_status(adreno_dev, status);
1934:
1935: /* If hard fault, then let snapshot turn off the keepalive */
1936: if (!(adreno_gpu_fault(adreno_dev) & ADRENO_HARD_FAULT))
1937: a6xx_gpu_keepalive(adreno_dev, false);
1938:
1939: return ret;
1940: }
1941:
1942: static irqreturn_t a6xx_irq_handler(struct adreno_device *adreno_dev)
1943: {
1944: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1945: irqreturn_t ret = IRQ_NONE;
1946: u32 status;
1947:
1948: /*
1949: * On A6xx, the GPU can power down once the INT_0_STATUS is read
1950: * below. But there still might be some register reads required
1951: * so force the GMU/GPU into KEEPALIVE mode until done with the ISR.
1952: */
1953: a6xx_gpu_keepalive(adreno_dev, true);
1954:
1955: if (a6xx_irq_poll_fence(adreno_dev)) {
1956: adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT);
1957: goto done;
1958: }
1959:
1960: kgsl_regread(device, A6XX_RBBM_INT_0_STATUS, &status);
1961:
1962: kgsl_regwrite(device, A6XX_RBBM_INT_CLEAR_CMD, status);
1963:
1964: ret = adreno_irq_callbacks(adreno_dev, a6xx_irq_funcs, status);
1965:
1966: trace_kgsl_a5xx_irq_status(adreno_dev, status);
1967:
1968: done:
1969: /* If hard fault, then let snapshot turn off the keepalive */
1970: if (!(adreno_gpu_fault(adreno_dev) & ADRENO_HARD_FAULT))
1971: a6xx_gpu_keepalive(adreno_dev, false);
1972:
1973: return ret;
1974: }
1975:
1976: int a6xx_probe_common(struct platform_device *pdev,
1977: struct adreno_device *adreno_dev, u32 chipid,
1978: const struct adreno_gpu_core *gpucore)
1979: {
1980: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1981: const struct adreno_gpudev *gpudev = gpucore->gpudev;
1982: int ret;
1983:
--- LINES 1993-2052 ---
1993: A662_GPU_CC_CX_CFG_GDSCR : A6XX_GPU_CC_CX_CFG_GDSCR;
1994:
1995: if (adreno_is_a622(adreno_dev))
1996: device->pwrctrl.cx_cfg_gdsc_offset = A622_GPU_CC_CX_CFG_GDSCR;
1997: }
1998:
1999: adreno_dev->hwcg_enabled = true;
2000: adreno_dev->uche_client_pf = 1;
2001:
2002: if (adreno_preemption_feature_set(adreno_dev)) {
2003: const struct adreno_a6xx_core *a6xx_core = to_a6xx_core(adreno_dev);
2004:
2005: adreno_dev->total_ctxt_record_sz = a6xx_core->ctxt_record_size ?
2006: a6xx_core->ctxt_record_size : A6XX_CP_CTXRECORD_SIZE_IN_BYTES;
2007:
2008: adreno_dev->preempt.preempt_level = 1;
2009: adreno_dev->preempt.skipsaverestore = true;
2010: adreno_dev->preempt.usesgmem = true;
2011: }
2012:
2013: ret = adreno_device_probe(pdev, adreno_dev);
2014:
2015: if (ret)
2016: return ret;
2017:
2018: a6xx_coresight_init(adreno_dev);
2019: return 0;
2020: }
2021:
2022: static int a6xx_probe(struct platform_device *pdev,
2023: u32 chipid, const struct adreno_gpu_core *gpucore)
2024: {
2025: struct adreno_device *adreno_dev;
2026: struct kgsl_device *device;
2027: struct platform_device *gmu_wrapper_pdev;
2028: int ret;
2029:
2030: adreno_dev = (struct adreno_device *)
2031: of_device_get_match_data(&pdev->dev);
2032:
2033: memset(adreno_dev, 0, sizeof(*adreno_dev));
2034:
2035: adreno_dev->irq_mask = A6XX_INT_MASK;
2036:
2037: ret = a6xx_probe_common(pdev, adreno_dev, chipid, gpucore);
2038: if (ret)
2039: return ret;
2040:
2041: device = KGSL_DEVICE(adreno_dev);
2042:
2043: /*
2044: * In standard DT bindings, no-GMU targets have a wrapper device
2045: * with a dedicated "gmu" register range. In contrast, non-standard
2046: * DT bindings include these registers within "kgsl_3d0_reg_memory"
2047: * for such targets. To handle the first case, add the "gmu" block to
2048: * the regmap if the wrapper device is present.
2049: */
2050: gmu_wrapper_pdev = get_gmu_wrapper_pdev();
2051:
2052: if (gmu_wrapper_pdev) {
--- LINES 2085-2122 ---
2085:
2086: INIT_WORK(&device->idle_check_ws, kgsl_idle_check);
2087:
2088: return 0;
2089: }
2090:
2091: /* Register offset defines for A6XX, in order of enum adreno_regs */
2092: static unsigned int a6xx_register_offsets[ADRENO_REG_REGISTER_MAX] = {
2093:
2094: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_BASE, A6XX_CP_RB_BASE),
2095: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_BASE_HI, A6XX_CP_RB_BASE_HI),
2096: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_RPTR, A6XX_CP_RB_RPTR),
2097: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_WPTR, A6XX_CP_RB_WPTR),
2098: ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_CNTL, A6XX_CP_RB_CNTL),
2099: ADRENO_REG_DEFINE(ADRENO_REG_CP_ME_CNTL, A6XX_CP_SQE_CNTL),
2100: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BASE, A6XX_CP_IB1_BASE),
2101: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BASE_HI, A6XX_CP_IB1_BASE_HI),
2102: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BUFSZ, A6XX_CP_IB1_REM_SIZE),
2103: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BASE, A6XX_CP_IB2_BASE),
2104: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BASE_HI, A6XX_CP_IB2_BASE_HI),
2105: ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BUFSZ, A6XX_CP_IB2_REM_SIZE),
2106: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_STATUS, A6XX_RBBM_STATUS),
2107: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_STATUS3, A6XX_RBBM_STATUS3),
2108: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_INT_0_MASK, A6XX_RBBM_INT_0_MASK),
2109: ADRENO_REG_DEFINE(ADRENO_REG_RBBM_SW_RESET_CMD, A6XX_RBBM_SW_RESET_CMD),
2110: ADRENO_REG_DEFINE(ADRENO_REG_GMU_AO_HOST_INTERRUPT_MASK,
2111: A6XX_GMU_AO_HOST_INTERRUPT_MASK),
2112: ADRENO_REG_DEFINE(ADRENO_REG_GMU_GMU2HOST_INTR_MASK,
2113: A6XX_GMU_GMU2HOST_INTR_MASK),
2114: };
2115:
2116: int a6xx_perfcounter_update(struct adreno_device *adreno_dev,
2117: struct adreno_perfcount_register *reg, bool update_reg)
2118: {
2119: void *ptr = adreno_dev->pwrup_reglist->hostptr;
2120: struct cpu_gpu_lock *lock = ptr;
2121: u32 *data = ptr + sizeof(*lock);
2122: u64 reglist_size_dwords = adreno_dev->pwrup_reglist->size / sizeof(u32);
--- LINES 2165-2227 ---
2165: data[offset] = reg->select;
2166: data[offset + 1] = reg->countable;
2167: data[offset + 2] = A6XX_RBBM_PERFCTR_CNTL;
2168: data[offset + 3] = 1;
2169:
2170: lock->list_length += 2;
2171:
2172: update:
2173: if (update_reg)
2174: kgsl_regwrite(KGSL_DEVICE(adreno_dev), reg->select,
2175: reg->countable);
2176:
2177: kgsl_hwunlock(lock);
2178: return 0;
2179: }
2180:
2181: u64 a6xx_read_alwayson(struct adreno_device *adreno_dev)
2182: {
2183: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
2184: u32 lo = 0, hi = 0, tmp = 0;
2185:
2186: if (!gmu_core_isenabled(device)) {
2187: kgsl_regread(device, A6XX_CP_ALWAYS_ON_COUNTER_LO, &lo);
2188: kgsl_regread(device, A6XX_CP_ALWAYS_ON_COUNTER_HI, &hi);
2189: } else {
2190: /* Always use the GMU AO counter when doing a AHB read */
2191: gmu_core_regread(device, A6XX_GMU_ALWAYS_ON_COUNTER_H, &hi);
2192: gmu_core_regread(device, A6XX_GMU_ALWAYS_ON_COUNTER_L, &lo);
2193:
2194: /* Check for overflow */
2195: gmu_core_regread(device, A6XX_GMU_ALWAYS_ON_COUNTER_H, &tmp);
2196:
2197: if (hi != tmp) {
2198: gmu_core_regread(device, A6XX_GMU_ALWAYS_ON_COUNTER_L,
2199: &lo);
2200: hi = tmp;
2201: }
2202: }
2203:
2204: return (((u64) hi) << 32) | lo;
2205: }
2206:
2207: static void a6xx_remove(struct adreno_device *adreno_dev)
2208: {
2209: if (adreno_preemption_feature_set(adreno_dev))
2210: kgsl_delete_timer(&adreno_dev->preempt.timer);
2211: }
2212:
2213: static void a6xx_read_bus_stats(struct kgsl_device *device,
2214: struct kgsl_power_stats *stats,
2215: struct adreno_busy_data *busy)
2216: {
2217: struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
2218: u64 ram_cycles, starved_ram;
2219:
2220: ram_cycles = counter_delta(device, adreno_dev->ram_cycles_lo,
2221: &busy->bif_ram_cycles);
2222:
2223: starved_ram = counter_delta(device, adreno_dev->starved_ram_lo,
2224: &busy->bif_starved_ram);
2225:
2226: if (!adreno_is_a630(adreno_dev)) {
2227: ram_cycles += counter_delta(device,
--- LINES 2337-2534 ---
2337: {
2338: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
2339: void __iomem *addr = kgsl_regmap_virt(&device->regmap,
2340: A6XX_GMU_SPTPRAC_PWR_CLK_STATUS);
2341: u32 val;
2342:
2343: if (test_bit(ADRENO_DEVICE_GPU_REGULATOR_ENABLED, &adreno_dev->priv))
2344: return 0;
2345:
2346: kgsl_regwrite(device, A6XX_GMU_GX_SPTPRAC_POWER_CONTROL,
2347: SPTPRAC_POWERON_CTRL_MASK);
2348:
2349: if (readl_poll_timeout(addr, val,
2350: (val & SPTPRAC_POWERON_STATUS_MASK) ==
2351: SPTPRAC_POWERON_STATUS_MASK, 10, 10 * 1000)) {
2352: dev_err(device->dev, "power on SPTPRAC fail\n");
2353: return -EINVAL;
2354: }
2355:
2356: set_bit(ADRENO_DEVICE_GPU_REGULATOR_ENABLED, &adreno_dev->priv);
2357: return 0;
2358: }
2359:
2360: static void a619_holi_sptprac_disable(struct adreno_device *adreno_dev)
2361: {
2362: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
2363: void __iomem *addr = kgsl_regmap_virt(&device->regmap,
2364: A6XX_GMU_SPTPRAC_PWR_CLK_STATUS);
2365: u32 val;
2366:
2367: if (!test_and_clear_bit(ADRENO_DEVICE_GPU_REGULATOR_ENABLED,
2368: &adreno_dev->priv))
2369: return;
2370:
2371: /* Ensure that retention is on */
2372: kgsl_regrmw(device, A6XX_GPU_CC_GX_GDSCR, 0,
2373: A6XX_RETAIN_FF_ENABLE_ENABLE_MASK);
2374:
2375: kgsl_regwrite(device, A6XX_GMU_GX_SPTPRAC_POWER_CONTROL,
2376: SPTPRAC_POWEROFF_CTRL_MASK);
2377: if (readl_poll_timeout(addr, val,
2378: (val & SPTPRAC_POWEROFF_STATUS_MASK) ==
2379: SPTPRAC_POWEROFF_STATUS_MASK, 10, 10 * 1000))
2380: dev_err(device->dev, "power off SPTPRAC fail\n");
2381: }
2382:
2383: /* This is a non GMU/RGMU part */
2384: const struct adreno_gpudev adreno_a6xx_gpudev = {
2385: .reg_offsets = a6xx_register_offsets,
2386: .probe = a6xx_probe,
2387: .start = a6xx_nogmu_start,
2388: .snapshot = a6xx_snapshot,
2389: .init = a6xx_nogmu_init,
2390: .irq_handler = a6xx_irq_handler,
2391: .rb_start = a6xx_rb_start,
2392: .regulator_disable = a6xx_prepare_for_regulator_disable,
2393: .gpu_keepalive = a6xx_gpu_keepalive,
2394: .hw_isidle = a6xx_hw_isidle,
2395: .iommu_fault_block = a6xx_iommu_fault_block,
2396: .reset = a6xx_reset,
2397: .preemption_schedule = a6xx_preemption_schedule,
2398: .read_alwayson = a6xx_read_alwayson,
2399: .power_ops = &adreno_power_operations,
2400: .clear_pending_transactions = a6xx_clear_pending_transactions,
2401: .deassert_gbif_halt = a6xx_deassert_gbif_halt,
2402: .remove = a6xx_remove,
2403: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd,
2404: .is_hw_collapsible = adreno_isidle,
2405: .power_stats = a6xx_power_stats,
2406: .add_to_va_minidump = a6xx_dev_add_to_minidump,
2407: .gx_is_on = a6xx_gx_is_on,
2408: };
2409:
2410: const struct a6xx_gpudev adreno_a6xx_hwsched_gpudev = {
2411: .base = {
2412: .reg_offsets = a6xx_register_offsets,
2413: .probe = a6xx_hwsched_probe,
2414: .snapshot = a6xx_hwsched_snapshot,
2415: .irq_handler = a6xx_hwsched_irq_handler,
2416: .iommu_fault_block = a6xx_iommu_fault_block,
2417: .context_detach = a6xx_hwsched_context_detach,
2418: .read_alwayson = a6xx_read_alwayson,
2419: .reset = a6xx_hwsched_reset_replay,
2420: .power_ops = &a6xx_hwsched_power_ops,
2421: .power_stats = a6xx_power_stats,
2422: .hw_isidle = a6xx_hw_isidle,
2423: .add_to_va_minidump = a6xx_hwsched_add_to_minidump,
2424: .gx_is_on = a6xx_gmu_gx_is_on,
2425: .send_recurring_cmdobj = a6xx_hwsched_send_recurring_cmdobj,
2426: .set_isdb_breakpoint_registers = a6xx_set_isdb_breakpoint_registers,
2427: },
2428: .hfi_probe = a6xx_hwsched_hfi_probe,
2429: .hfi_remove = a6xx_hwsched_hfi_remove,
2430: .handle_watchdog = a6xx_hwsched_handle_watchdog,
2431: };
2432:
2433: const struct a6xx_gpudev adreno_a6xx_gmu_gpudev = {
2434: .base = {
2435: .reg_offsets = a6xx_register_offsets,
2436: .probe = a6xx_gmu_device_probe,
2437: .snapshot = a6xx_gmu_snapshot,
2438: .irq_handler = a6xx_irq_handler,
2439: .rb_start = a6xx_rb_start,
2440: .regulator_enable = a6xx_sptprac_enable,
2441: .regulator_disable = a6xx_sptprac_disable,
2442: .gpu_keepalive = a6xx_gpu_keepalive,
2443: .hw_isidle = a6xx_hw_isidle,
2444: .iommu_fault_block = a6xx_iommu_fault_block,
2445: .reset = a6xx_gmu_reset,
2446: .preemption_schedule = a6xx_preemption_schedule,
2447: .read_alwayson = a6xx_read_alwayson,
2448: .power_ops = &a6xx_gmu_power_ops,
2449: .remove = a6xx_remove,
2450: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd,
2451: .power_stats = a6xx_power_stats,
2452: .add_to_va_minidump = a6xx_gmu_add_to_minidump,
2453: .gx_is_on = a6xx_gmu_gx_is_on,
2454: .set_isdb_breakpoint_registers = a6xx_set_isdb_breakpoint_registers,
2455: },
2456: .hfi_probe = a6xx_gmu_hfi_probe,
2457: .handle_watchdog = a6xx_gmu_handle_watchdog,
2458: };
2459:
2460: const struct adreno_gpudev adreno_a6xx_rgmu_gpudev = {
2461: .reg_offsets = a6xx_register_offsets,
2462: .probe = a6xx_rgmu_device_probe,
2463: .snapshot = a6xx_rgmu_snapshot,
2464: .irq_handler = a6xx_irq_handler,
2465: .rb_start = a6xx_rb_start,
2466: .regulator_enable = a6xx_sptprac_enable,
2467: .regulator_disable = a6xx_sptprac_disable,
2468: .gpu_keepalive = a6xx_gpu_keepalive,
2469: .hw_isidle = a6xx_hw_isidle,
2470: .iommu_fault_block = a6xx_iommu_fault_block,
2471: .reset = a6xx_rgmu_reset,
2472: .preemption_schedule = a6xx_preemption_schedule,
2473: .read_alwayson = a6xx_read_alwayson,
2474: .power_ops = &a6xx_rgmu_power_ops,
2475: .remove = a6xx_remove,
2476: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd,
2477: .power_stats = a6xx_power_stats,
2478: .add_to_va_minidump = a6xx_rgmu_add_to_minidump,
2479: .gx_is_on = a6xx_rgmu_gx_is_on,
2480: };
2481:
2482: /* This is a non GMU/RGMU part */
2483: const struct adreno_gpudev adreno_a619_holi_gpudev = {
2484: .reg_offsets = a6xx_register_offsets,
2485: .probe = a6xx_probe,
2486: .start = a6xx_nogmu_start,
2487: .snapshot = a6xx_snapshot,
2488: .init = a6xx_nogmu_init,
2489: .irq_handler = a6xx_irq_handler,
2490: .rb_start = a6xx_rb_start,
2491: .regulator_enable = a619_holi_sptprac_enable,
2492: .regulator_disable = a619_holi_sptprac_disable,
2493: .gpu_keepalive = a6xx_gpu_keepalive,
2494: .hw_isidle = a619_holi_hw_isidle,
2495: .iommu_fault_block = a6xx_iommu_fault_block,
2496: .reset = a6xx_reset,
2497: .preemption_schedule = a6xx_preemption_schedule,
2498: .read_alwayson = a6xx_read_alwayson,
2499: .power_ops = &adreno_power_operations,
2500: .clear_pending_transactions = a6xx_clear_pending_transactions,
2501: .deassert_gbif_halt = a6xx_deassert_gbif_halt,
2502: .remove = a6xx_remove,
2503: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd,
2504: .is_hw_collapsible = adreno_isidle,
2505: .power_stats = a6xx_power_stats,
2506: .add_to_va_minidump = a6xx_dev_add_to_minidump,
2507: .gx_is_on = a619_holi_gx_is_on,
2508: };
2509:
2510: const struct a6xx_gpudev adreno_a630_gpudev = {
2511: .base = {
2512: .reg_offsets = a6xx_register_offsets,
2513: .probe = a6xx_gmu_device_probe,
2514: .snapshot = a6xx_gmu_snapshot,
2515: .irq_handler = a6xx_irq_handler,
2516: .rb_start = a6xx_rb_start,
2517: .regulator_enable = a6xx_sptprac_enable,
2518: .regulator_disable = a6xx_sptprac_disable,
2519: .gpu_keepalive = a6xx_gpu_keepalive,
2520: .hw_isidle = a6xx_hw_isidle,
2521: .iommu_fault_block = a6xx_iommu_fault_block,
2522: .reset = a6xx_gmu_reset,
2523: .preemption_schedule = a6xx_preemption_schedule,
2524: .read_alwayson = a6xx_read_alwayson,
2525: .power_ops = &a630_gmu_power_ops,
2526: .remove = a6xx_remove,
2527: .ringbuffer_submitcmd = a6xx_ringbuffer_submitcmd,
2528: .power_stats = a6xx_power_stats,
2529: .add_to_va_minidump = a6xx_gmu_add_to_minidump,
2530: .gx_is_on = a6xx_gmu_gx_is_on,
2531: },
2532: .hfi_probe = a6xx_gmu_hfi_probe,
2533: .handle_watchdog = a6xx_gmu_handle_watchdog,
2534: };
========== FILE: adreno_a6xx.h ==========
--- LINES 76-195 ---
76: bool pdc_in_aop;
77: /** @hang_detect_cycles: Hang detect counter timeout value */
78: u32 hang_detect_cycles;
79: /** @protected_regs: Array of protected registers for the target */
80: const struct adreno_protected_regs *protected_regs;
81: /** @disable_tseskip: True if TSESkip logic is disabled */
82: bool disable_tseskip;
83: /** @gx_cpr_toggle: True to toggle GX CPR FSM to avoid CPR stalls */
84: bool gx_cpr_toggle;
85: /** @ctxt_record_size: Size of the preemption record in bytes */
86: u64 ctxt_record_size;
87: /** @gmu_hub_clk_freq: Gmu hub interface clock frequency */
88: u64 gmu_hub_clk_freq;
89: };
90:
91: #define SPTPRAC_POWERON_CTRL_MASK 0x00778000
92: #define SPTPRAC_POWEROFF_CTRL_MASK 0x00778001
93: #define SPTPRAC_POWEROFF_STATUS_MASK BIT(2)
94: #define SPTPRAC_POWERON_STATUS_MASK BIT(3)
95: #define A6XX_RETAIN_FF_ENABLE_ENABLE_MASK BIT(11)
96:
97: #define CP_CLUSTER_FE 0x0
98: #define CP_CLUSTER_SP_VS 0x1
99: #define CP_CLUSTER_PC_VS 0x2
100: #define CP_CLUSTER_GRAS 0x3
101: #define CP_CLUSTER_SP_PS 0x4
102: #define CP_CLUSTER_PS 0x5
103: #define CP_CLUSTER_VPC_PS 0x6
104:
105: /**
106: * struct a6xx_cp_preemption_record - CP context record for
107: * preemption.
108: * @magic: (00) Value at this offset must be equal to
109: * A6XX_CP_CTXRECORD_MAGIC_REF.
110: * @info: (04) Type of record. Written non-zero (usually) by CP.
111: * we must set to zero for all ringbuffers.
112: * @errno: (08) Error code. Initialize this to A6XX_CP_CTXRECORD_ERROR_NONE.
113: * CP will update to another value if a preemption error occurs.
114: * @data: (12) DATA field in YIELD and SET_MARKER packets.
115: * Written by CP when switching out. Not used on switch-in. Initialized to 0.
116: * @cntl: (16) RB_CNTL, saved and restored by CP. We must initialize this.
117: * @rptr: (20) RB_RPTR, saved and restored by CP. We must initialize this.
118: * @wptr: (24) RB_WPTR, saved and restored by CP. We must initialize this.
119: * @_pad28: (28) Reserved/padding.
120: * @rptr_addr: (32) RB_RPTR_ADDR_LO|HI saved and restored. We must initialize.
121: * rbase: (40) RB_BASE_LO|HI saved and restored.
122: * counter: (48) Pointer to preemption counter.
123: */
124: struct a6xx_cp_preemption_record {
125: uint32_t magic;
126: uint32_t info;
127: uint32_t errno;
128: uint32_t data;
129: uint32_t cntl;
130: uint32_t rptr;
131: uint32_t wptr;
132: uint32_t _pad28;
133: uint64_t rptr_addr;
134: uint64_t rbase;
135: uint64_t counter;
136: };
137:
138: /**
139: * struct a6xx_cp_smmu_info - CP preemption SMMU info.
140: * @magic: (00) The value at this offset must be equal to
141: * A6XX_CP_SMMU_INFO_MAGIC_REF.
142: * @_pad4: (04) Reserved/padding
143: * @ttbr0: (08) Base address of the page table for the
144: * incoming context.
145: * @context_idr: (16) Context Identification Register value.
146: */
147: struct a6xx_cp_smmu_info {
148: uint32_t magic;
149: uint32_t _pad4;
150: uint64_t ttbr0;
151: uint32_t asid;
152: uint32_t context_idr;
153: };
154:
155: #define A6XX_CP_SMMU_INFO_MAGIC_REF 0x241350D5UL
156:
157: #define A6XX_CP_CTXRECORD_MAGIC_REF 0xAE399D6EUL
158: /* Size of each CP preemption record */
159: #define A6XX_CP_CTXRECORD_SIZE_IN_BYTES (2112 * 1024)
160: /* Size of the performance counter save/restore block (in bytes) */
161: #define A6XX_CP_PERFCOUNTER_SAVE_RESTORE_SIZE (4 * 1024)
162:
163: #define A6XX_CP_RB_CNTL_DEFAULT (((ilog2(4) << 8) & 0x1F00) | \
164: (ilog2(KGSL_RB_DWORDS >> 1) & 0x3F))
165:
166: /* Size of the CP_INIT pm4 stream in dwords */
167: #define A6XX_CP_INIT_DWORDS 11
168:
169: #define A6XX_INT_MASK \
170: ((1 << A6XX_INT_CP_AHB_ERROR) | \
171: (1 << A6XX_INT_ATB_ASYNCFIFO_OVERFLOW) | \
172: (1 << A6XX_INT_RBBM_GPC_ERROR) | \
173: (1 << A6XX_INT_CP_SW) | \
174: (1 << A6XX_INT_CP_HW_ERROR) | \
175: (1 << A6XX_INT_CP_IB2) | \
176: (1 << A6XX_INT_CP_IB1) | \
177: (1 << A6XX_INT_CP_RB) | \
178: (1 << A6XX_INT_CP_CACHE_FLUSH_TS) | \
179: (1 << A6XX_INT_RBBM_ATB_BUS_OVERFLOW) | \
180: (1 << A6XX_INT_RBBM_HANG_DETECT) | \
181: (1 << A6XX_INT_UCHE_OOB_ACCESS) | \
182: (1 << A6XX_INT_UCHE_TRAP_INTR) | \
183: (1 << A6XX_INT_TSB_WRITE_ERROR))
184:
185: #define A6XX_HWSCHED_INT_MASK \
186: ((1 << A6XX_INT_CP_AHB_ERROR) | \
187: (1 << A6XX_INT_ATB_ASYNCFIFO_OVERFLOW) | \
188: (1 << A6XX_INT_RBBM_ATB_BUS_OVERFLOW) | \
189: (1 << A6XX_INT_UCHE_OOB_ACCESS) | \
190: (1 << A6XX_INT_UCHE_TRAP_INTR) | \
191: (1 << A6XX_INT_TSB_WRITE_ERROR))
192:
193: /**
194: * to_a6xx_core - return the a6xx specific GPU core struct
195: * @adreno_dev: An Adreno GPU device handle
--- LINES 199-255 ---
199: */
200: static inline const struct adreno_a6xx_core *
201: to_a6xx_core(struct adreno_device *adreno_dev)
202: {
203: const struct adreno_gpu_core *core = adreno_dev->gpucore;
204:
205: return container_of(core, struct adreno_a6xx_core, base);
206: }
207:
208: /* Preemption functions */
209: void a6xx_preemption_trigger(struct adreno_device *adreno_dev, bool atomic);
210: void a6xx_preemption_schedule(struct adreno_device *adreno_dev);
211: void a6xx_preemption_start(struct adreno_device *adreno_dev);
212: int a6xx_preemption_init(struct adreno_device *adreno_dev);
213:
214: /**
215: * a6xx_preemption_post_ibsubmit - Insert commands following a submission
216: * @adreno_dev: Adreno GPU handle
217: * @cmds: Pointer to the ringbuffer to insert opcodes
218: *
219: * Return: The number of dwords written to @cmds
220: */
221: u32 a6xx_preemption_post_ibsubmit(struct adreno_device *adreno_dev, u32 *cmds);
222:
223: /**
224: * a6xx_preemption_post_ibsubmit - Insert opcodes before a submission
225: * @adreno_dev: Adreno GPU handle
226: * @rb: The ringbuffer being written
227: * @drawctxt: The draw context being written
228: * @cmds: Pointer to the ringbuffer to insert opcodes
229: *
230: * Return: The number of dwords written to @cmds
231: */
232: u32 a6xx_preemption_pre_ibsubmit(struct adreno_device *adreno_dev,
233: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt,
234: u32 *cmds);
235:
236: void a6xx_preemption_callback(struct adreno_device *adreno_dev, int bit);
237:
238: void a6xx_preemption_context_destroy(struct kgsl_context *context);
239:
240: void a6xx_snapshot(struct adreno_device *adreno_dev,
241: struct kgsl_snapshot *snapshot);
242: void a6xx_crashdump_init(struct adreno_device *adreno_dev);
243: int a6xx_gmu_sptprac_enable(struct adreno_device *adreno_dev);
244: void a6xx_gmu_sptprac_disable(struct adreno_device *adreno_dev);
245: bool a6xx_gmu_sptprac_is_on(struct adreno_device *adreno_dev);
246: bool a619_holi_gx_is_on(struct adreno_device *adreno_dev);
247:
248: /**
249: * a6xx_read_alwayson - Read the current always on clock value
250: * @adreno_dev: An Adreno GPU handle
251: *
252: * Return: The current value of the GMU always on counter
253: */
254: u64 a6xx_read_alwayson(struct adreno_device *adreno_dev);
255:
--- LINES 269-303 ---
269: * This function does a6xx specific one time initialization
270: * and is invoked when the very first client opens a
271: * kgsl instance
272: *
273: * Return: Zero on success and negative error on failure
274: */
275: int a6xx_init(struct adreno_device *adreno_dev);
276:
277: /**
278: * a6xx_rb_start - A6xx specific ringbuffer setup
279: * @adreno_dev: An Adreno GPU handle
280: *
281: * This function does a6xx specific ringbuffer setup and
282: * attempts to submit CP INIT and bring GPU out of secure mode
283: *
284: * Return: Zero on success and negative error on failure
285: */
286: int a6xx_rb_start(struct adreno_device *adreno_dev);
287:
288: /**
289: * a6xx_microcode_read - Get the cp microcode from the filesystem
290: * @adreno_dev: An Adreno GPU handle
291: *
292: * This function gets the firmware from filesystem and sets up
293: * the micorocode global buffer
294: *
295: * Return: Zero on success and negative error on failure
296: */
297: int a6xx_microcode_read(struct adreno_device *adreno_dev);
298:
299: /**
300: * a6xx_probe_common - Probe common a6xx resources
301: * @pdev: Pointer to the platform device
302: * @adreno_dev: Pointer to the adreno device
303: * @chipid: Chipid of the target
--- LINES 325-417 ---
325: * @reg: Perfcounter reg struct to add/remove to the list
326: * @update_reg: true if the perfcounter needs to be programmed by the CPU
327: *
328: * Return: 0 on success or -EBUSY if the lock couldn't be taken
329: */
330: int a6xx_perfcounter_update(struct adreno_device *adreno_dev,
331: struct adreno_perfcount_register *reg, bool update_reg);
332:
333: /*
334: * a6xx_ringbuffer_init - Initialize the ringbuffers
335: * @adreno_dev: An Adreno GPU handle
336: *
337: * Initialize the ringbuffer(s) for a6xx.
338: * Return: 0 on success or negative on failure
339: */
340: int a6xx_ringbuffer_init(struct adreno_device *adreno_dev);
341:
342: extern const struct adreno_perfcounters adreno_a630_perfcounters;
343: extern const struct adreno_perfcounters adreno_a6xx_perfcounters;
344: extern const struct adreno_perfcounters adreno_a6xx_legacy_perfcounters;
345:
346: /**
347: * a6xx_ringbuffer_addcmds - Submit a command to the ringbuffer
348: * @adreno_dev: An Adreno GPU handle
349: * @rb: Pointer to the ringbuffer to submit on
350: * @drawctxt: Pointer to the draw context for the submission, or NULL for
351: * internal submissions
352: * @flags: Flags for the submission
353: * @in: Commands to write to the ringbuffer
354: * @dwords: Size of @in (in dwords)
355: * @timestamp: Timestamp for the submission
356: * @time: Optional pointer to a submit time structure
357: *
358: * Submit a command to the ringbuffer.
359: * Return: 0 on success or negative on failure
360: */
361: int a6xx_ringbuffer_addcmds(struct adreno_device *adreno_dev,
362: struct adreno_ringbuffer *rb, struct adreno_context *drawctxt,
363: u32 flags, u32 *in, u32 dwords, u32 timestamp,
364: struct adreno_submit_time *time);
365: /**
366: * a6xx_ringbuffer_submitcmd - Submit a user command to the ringbuffer
367: * @adreno_dev: An Adreno GPU handle
368: * @cmdobj: Pointer to a user command object
369: * @flags: Internal submit flags
370: * @time: Optional pointer to a adreno_submit_time container
371: *
372: * Return: 0 on success or negative on failure
373: */
374: int a6xx_ringbuffer_submitcmd(struct adreno_device *adreno_dev,
375: struct kgsl_drawobj_cmd *cmdobj, u32 flags,
376: struct adreno_submit_time *time);
377:
378:
379: int a6xx_fenced_write(struct adreno_device *adreno_dev, u32 offset,
380: u32 value, u32 mask);
381:
382: int a6xx_ringbuffer_submit(struct adreno_ringbuffer *rb,
383: struct adreno_submit_time *time, bool sync);
384:
385: void a6xx_cp_init_cmds(struct adreno_device *adreno_dev, u32 *cmds);
386:
387: int a6xx_gmu_hfi_probe(struct adreno_device *adreno_dev);
388:
389: static inline const struct a6xx_gpudev *
390: to_a6xx_gpudev(const struct adreno_gpudev *gpudev)
391: {
392: return container_of(gpudev, struct a6xx_gpudev, base);
393: }
394:
395: /**
396: * a6xx_reset_preempt_records - Reset the preemption buffers
397: * @adreno_dev: Handle to the adreno device
398: *
399: * Reset the preemption records at the time of hard reset
400: */
401: void a6xx_reset_preempt_records(struct adreno_device *adreno_dev);
402:
403: /**
404: * a6xx_irq_pending - Check if there is any gpu irq pending
405: * @adreno_dev: Handle to the adreno device
406: *
407: * Return true if there is any gpu irq pending
408: */
409: bool a6xx_irq_pending(struct adreno_device *adreno_dev);
410:
411: #ifdef CONFIG_QCOM_KGSL_CORESIGHT
412: void a6xx_coresight_init(struct adreno_device *device);
413: #else
414: static inline void a6xx_coresight_init(struct adreno_device *device) { }
415: #endif
416:
417: #endif
========== FILE: adreno.h ==========
--- LINES 13-50 ---
13: #include "adreno_coresight.h"
14: #include "adreno_dispatch.h"
15: #include "adreno_drawctxt.h"
16: #include "adreno_hwsched.h"
17: #include "adreno_perfcounter.h"
18: #include "adreno_profile.h"
19: #include "adreno_ringbuffer.h"
20: #include "kgsl_sharedmem.h"
21:
22: /* Used to point CP to the SMMU record during preemption */
23: #define SET_PSEUDO_SMMU_INFO 0
24: /* Used to inform CP where to save preemption data at the time of switch out */
25: #define SET_PSEUDO_PRIV_NON_SECURE_SAVE_ADDR 1
26: /* Used to inform CP where to save secure preemption data at the time of switch out */
27: #define SET_PSEUDO_PRIV_SECURE_SAVE_ADDR 2
28: /* Used to inform CP where to save per context non-secure data at the time of switch out */
29: #define SET_PSEUDO_NON_PRIV_SAVE_ADDR 3
30: /* Used to inform CP where to save preemption counter data at the time of switch out */
31: #define SET_PSEUDO_COUNTER 4
32:
33: /* Index to preemption scratch buffer to store current QOS value */
34: #define QOS_VALUE_IDX KGSL_PRIORITY_MAX_RB_LEVELS
35:
36: /* Size of the user context record block (in bytes) */
37: #define ADRENO_CP_CTXRECORD_USER_RESTORE_SIZE (192 * SZ_1K)
38:
39: /* ADRENO_DEVICE - Given a kgsl_device return the adreno device struct */
40: #define ADRENO_DEVICE(device) \
41: container_of(device, struct adreno_device, dev)
42:
43: /* KGSL_DEVICE - given an adreno_device, return the KGSL device struct */
44: #define KGSL_DEVICE(_dev) (&((_dev)->dev))
45:
46: /* ADRENO_CONTEXT - Given a context return the adreno context struct */
47: #define ADRENO_CONTEXT(context) \
48: container_of(context, struct adreno_context, base)
49:
50: /* ADRENO_GPU_DEVICE - Given an adreno device return the GPU specific struct */
--- LINES 74-158 ---
74: #define ADRENO_GMU_REV(_rev) \
75: (FIELD_PREP(GENMASK(31, 24), ADRENO_REV_MAJOR(_rev)) | \
76: FIELD_PREP(GENMASK(23, 16), ADRENO_REV_MINOR(_rev)) | \
77: FIELD_PREP(GENMASK(15, 8), ADRENO_REV_PATCH(_rev)))
78:
79: /* ADRENO_GPUREV - Return the GPU ID for the given adreno_device */
80: #define ADRENO_GPUREV(_a) ((_a)->gpucore->gpurev)
81:
82: /*
83: * Disable local interrupts and CPU preemption to avoid interruptions
84: * while holding the CP semaphore; otherwise, it could stall the CP.
85: * Make sure to call ADRENO_RELEASE_CP_SEMAPHORE after calling the
86: * below macro to reenable CPU interrupts.
87: */
88: #define ADRENO_ACQUIRE_CP_SEMAPHORE(_adreno_dev, _flags) \
89: ({ \
90: bool ret = true; \
91: if ((_adreno_dev)->gpucore->gpudev->acquire_cp_semaphore) { \
92: local_irq_save(_flags); \
93: preempt_disable(); \
94: ret = (_adreno_dev)->gpucore->gpudev->acquire_cp_semaphore(_adreno_dev); \
95: if (!ret) { \
96: preempt_enable(); \
97: local_irq_restore(_flags); \
98: dev_err_ratelimited(KGSL_DEVICE(_adreno_dev)->dev, \
99: "Timed out waiting to acquire CP semaphore: status=0x%08x\n", \
100: ret); \
101: } \
102: } \
103: ret; \
104: })
105:
106: #define ADRENO_RELEASE_CP_SEMAPHORE(_adreno_dev, _flags) \
107: ({ \
108: do { \
109: if ((_adreno_dev)->gpucore->gpudev->release_cp_semaphore) { \
110: (_adreno_dev)->gpucore->gpudev->release_cp_semaphore(_adreno_dev); \
111: preempt_enable(); \
112: local_irq_restore(_flags); \
113: } \
114: } while (0);\
115: })
116:
117: /*
118: * ADRENO_FEATURE - return true if the specified feature is supported by the GPU
119: * core
120: */
121: #define ADRENO_FEATURE(_dev, _bit) \
122: (((_dev)->gpucore->features_standard && \
123: of_device_is_compatible((_dev)->dev.pdev->dev.of_node, "qcom,adreno")) \
124: ? ((_dev)->gpucore->features_standard & (_bit)) \
125: : ((_dev)->gpucore->features & (_bit)))
126:
127: /**
128: * ADRENO_QUIRK - return true if the specified quirk is required by the GPU
129: */
130: #define ADRENO_QUIRK(_dev, _bit) \
131: ((_dev)->quirks & (_bit))
132:
133: #define ADRENO_FW(a, f) (&(a->fw[f]))
134:
135: /* Adreno core features */
136: /* The core supports SP/TP hw controlled power collapse */
137: #define ADRENO_SPTP_PC BIT(0)
138: /* The GPU supports content protection */
139: #define ADRENO_CONTENT_PROTECTION BIT(1)
140: /* The GPU supports preemption */
141: #define ADRENO_PREEMPTION BIT(2)
142: /* The GPMU supports Limits Management */
143: #define ADRENO_LM BIT(3)
144: /* The GPU supports retention for cpz registers */
145: #define ADRENO_CPZ_RETENTION BIT(4)
146: /* The core has soft fault detection available */
147: #define ADRENO_SOFT_FAULT_DETECT BIT(5)
148: /* The GMU supports IFPC power management*/
149: #define ADRENO_IFPC BIT(6)
150: /* The core supports IO-coherent memory */
151: #define ADRENO_IOCOHERENT BIT(7)
152: /*
153: * The GMU supports Adaptive Clock Distribution (ACD)
154: * for droop mitigation
155: */
156: #define ADRENO_ACD BIT(8)
157: /* Cooperative reset enabled GMU */
158: #define ADRENO_COOP_RESET BIT(9)
--- LINES 162-229 ---
162: #define ADRENO_APRIV BIT(11)
163: /* The GMU supports Battery Current Limiting */
164: #define ADRENO_BCL BIT(12)
165: /* L3 voting is supported with L3 constraints */
166: #define ADRENO_L3_VOTE BIT(13)
167: /* LPAC is supported */
168: #define ADRENO_LPAC BIT(14)
169: /* Late Stage Reprojection (LSR) enablment for GMU */
170: #define ADRENO_LSR BIT(15)
171: /* GMU and kernel supports hardware fences */
172: #define ADRENO_HW_FENCE BIT(16)
173: /* Dynamic Mode Switching supported on this target */
174: #define ADRENO_DMS BIT(17)
175: /* AQE supported on this target */
176: #define ADRENO_AQE BIT(18)
177: /* Warm Boot supported on this target */
178: #define ADRENO_GMU_WARMBOOT BIT(19)
179: /* The GPU supports CLX */
180: #define ADRENO_CLX BIT(20)
181: /* Enable GMU support for GMU based thermal mitigation */
182: #define ADRENO_GMU_THERMAL_MITIGATION BIT(21)
183: /* GMU Based DCVS */
184: #define ADRENO_GMU_BASED_DCVS BIT(22)
185: /* RT hint feature for RB0 workloads */
186: #define ADRENO_RT_HINT BIT(23)
187: /* Defer allocation of preemption record gmem memory when needed */
188: #define ADRENO_DEFER_GMEM_ALLOC BIT(24)
189: /* The GMU supports MINBW voting */
190: #define ADRENO_GMU_MINBW BIT(25)
191: /* Enable GMU Based DCVS profile */
192: #define ADRENO_DCVS_PROFILE BIT(26)
193: /* Enable TSENSE power savings during sleep */
194: #define ADRENO_TSENSE_DYNAMIC_PERIOD BIT(27)
195: /* Enable GMU Based AB voting */
196: #define ADRENO_GMU_AB BIT(28)
197: /* Enable GMU Fast Context Destroy optimization */
198: #define ADRENO_GMU_FAST_CONTEXT_DESTROY BIT(29)
199: /*
200: * The target uses the GPU_CX_MISC_SW_FUSE_FREQ_LIMIT_STATUS register to
201: * get combined (HW + SW) speedbin when no nvmem speed_bin cell exists.
202: */
203: #define ADRENO_SOFTFUSE BIT_ULL(32)
204: /*
205: * Adreno GPU quirks - control bits for various workarounds
206: */
207:
208: /* Set TWOPASSUSEWFI in PC_DBG_ECO_CNTL (5XX/6XX) */
209: #define ADRENO_QUIRK_TWO_PASS_USE_WFI BIT(0)
210: /* Submit critical packets at GPU wake up */
211: #define ADRENO_QUIRK_CRITICAL_PACKETS BIT(1)
212: /* Mask out RB1-3 activity signals from HW hang detection logic */
213: #define ADRENO_QUIRK_FAULT_DETECT_MASK BIT(2)
214: /* Disable RB sampler datapath clock gating optimization */
215: #define ADRENO_QUIRK_DISABLE_RB_DP2CLOCKGATING BIT(3)
216: /* Disable local memory(LM) feature to avoid corner case error */
217: #define ADRENO_QUIRK_DISABLE_LMLOADKILL BIT(4)
218: /* Allow HFI to use registers to send message to GMU */
219: #define ADRENO_QUIRK_HFI_USE_REG BIT(5)
220: /* Only set protected SECVID registers once */
221: #define ADRENO_QUIRK_SECVID_SET_ONCE BIT(6)
222: /*
223: * Limit number of read and write transactions from
224: * UCHE block to GBIF to avoid possible deadlock
225: * between GBIF, SMMU and MEMNOC.
226: */
227: #define ADRENO_QUIRK_LIMIT_UCHE_GBIF_RW BIT(8)
228: /* Do explicit mode control of cx gdsc */
229: #define ADRENO_QUIRK_CX_GDSC BIT(9)
--- LINES 332-358 ---
332: ADRENO_REV_GEN8_11_0 = ADRENO_GPUREV_VALUE(8, 11, 0),
333: ADRENO_REV_GEN8_11_1 = ADRENO_GPUREV_VALUE(8, 11, 1),
334: ADRENO_REV_GEN8_14_0 = ADRENO_GPUREV_VALUE(8, 14, 0),
335: };
336:
337: #define ADRENO_SOFT_FAULT BIT(0)
338: #define ADRENO_HARD_FAULT BIT(1)
339: #define ADRENO_TIMEOUT_FAULT BIT(2)
340: #define ADRENO_IOMMU_STALL_ON_PAGE_FAULT BIT(3)
341: #define ADRENO_PREEMPT_FAULT BIT(4)
342: #define ADRENO_GMU_FAULT BIT(5)
343: #define ADRENO_CTX_DETATCH_TIMEOUT_FAULT BIT(6)
344: #define ADRENO_GMU_FAULT_SKIP_SNAPSHOT BIT(7)
345: #define ADRENO_FAULT_TYPES 8
346:
347: /**
348: * Bit fields for GPU_CX_MISC_CX_AHB_*_CNTL registers
349: * AHB_TXFRTIMEOUTRELEASE [8:8]
350: * AHB_TXFRTIMEOUTENABLE [9:9]
351: * AHB_RESPONDERROR [11:11]
352: * AHB_ERRORSTATUSENABLE [12:12]
353: */
354: #define ADRENO_AHB_CNTL_DEFAULT (BIT(12) | BIT(11) | BIT(9) | BIT(8))
355:
356: enum adreno_pipe_type {
357: PIPE_NONE = 0,
358: PIPE_BR = 1,
--- LINES 363-452 ---
363: PIPE_DDE_BR = 6,
364: PIPE_DDE_BV = 7,
365: };
366:
367: /* number of throttle counters for DCVS adjustment */
368: #define ADRENO_GPMU_THROTTLE_COUNTERS 4
369:
370: struct adreno_gpudev;
371:
372: /* Time to allow preemption to complete (in ms) */
373: #define ADRENO_PREEMPT_TIMEOUT 10000
374:
375: #define PREEMPT_SCRATCH_OFFSET(id) (id * sizeof(u64))
376:
377: #define PREEMPT_SCRATCH_ADDR(dev, id) \
378: ((dev)->preempt.scratch->gpuaddr + PREEMPT_SCRATCH_OFFSET(id))
379:
380: /**
381: * enum adreno_preempt_states
382: * ADRENO_PREEMPT_NONE: No preemption is scheduled
383: * ADRENO_PREEMPT_START: The S/W has started
384: * ADRENO_PREEMPT_TRIGGERED: A preeempt has been triggered in the HW
385: * ADRENO_PREEMPT_FAULTED: The preempt timer has fired
386: * ADRENO_PREEMPT_PENDING: The H/W has signaled preemption complete
387: * ADRENO_PREEMPT_COMPLETE: Preemption could not be finished in the IRQ handler,
388: * worker has been scheduled
389: */
390: enum adreno_preempt_states {
391: ADRENO_PREEMPT_NONE = 0,
392: ADRENO_PREEMPT_START,
393: ADRENO_PREEMPT_TRIGGERED,
394: ADRENO_PREEMPT_FAULTED,
395: ADRENO_PREEMPT_PENDING,
396: ADRENO_PREEMPT_COMPLETE,
397: };
398:
399: /**
400: * struct adreno_protected_regs - container for a protect register span
401: */
402: struct adreno_protected_regs {
403: /** @reg: Physical protected mode register to write to */
404: u32 reg;
405: /** @start: Dword offset of the starting register in the range */
406: u32 start;
407: /**
408: * @end: Dword offset of the ending register in the range
409: * (inclusive)
410: */
411: u32 end;
412: /**
413: * @noaccess: 1 if the register should not be accessible from
414: * userspace, 0 if it can be read (but not written)
415: */
416: u32 noaccess;
417: };
418:
419: /**
420: * struct adreno_preemption
421: * @state: The current state of preemption
422: * @scratch: Per-target scratch memory for implementation specific functionality
423: * @timer: A timer to make sure preemption doesn't stall
424: * @work: A work struct for the preemption worker (for 5XX)
425: * preempt_level: The level of preemption (for 6XX)
426: * skipsaverestore: To skip saverestore during L1 preemption (for 6XX)
427: * usesgmem: enable GMEM save/restore across preemption (for 6XX)
428: * count: Track the number of preemptions triggered
429: */
430: struct adreno_preemption {
431: atomic_t state;
432: struct kgsl_memdesc *scratch;
433: struct timer_list timer;
434: struct work_struct work;
435: unsigned int preempt_level;
436: bool skipsaverestore;
437: bool usesgmem;
438: unsigned int count;
439: /* @postamble_len: Number of dwords in KMD postamble pm4 packet */
440: u32 postamble_len;
441: /*
442: * @postamble_bootup_len: Number of dwords in KMD postamble pm4 packet
443: * that needs to be sent before first submission to GPU.
444: * Note: Postambles are not preserved across slumber.
445: */
446: u32 postamble_bootup_len;
447: };
448:
449: struct adreno_busy_data {
450: unsigned int gpu_busy;
451: unsigned int bif_ram_cycles;
452: unsigned int bif_ram_cycles_read_ch1;
--- LINES 464-490 ---
464: * @fwvirt: Buffer which holds the ucode
465: * @size: Size of ucode buffer
466: * @version: Version of ucode
467: * @memdesc: Memory descriptor which holds ucode buffer info
468: */
469: struct adreno_firmware {
470: unsigned int *fwvirt;
471: size_t size;
472: unsigned int version;
473: struct kgsl_memdesc *memdesc;
474: };
475:
476: /**
477: * struct adreno_perfcounter_list_node - struct to store perfcounters
478: * allocated by a process on a kgsl fd.
479: * @groupid: groupid of the allocated perfcounter
480: * @countable: countable assigned to the allocated perfcounter
481: * @node: list node for perfcounter_list of a process
482: */
483: struct adreno_perfcounter_list_node {
484: unsigned int groupid;
485: unsigned int countable;
486: struct list_head node;
487: };
488:
489: /**
490: * struct adreno_device_private - Adreno private structure per fd
--- LINES 627-801 ---
627:
628: /**
629: * struct adreno_dispatch_ops - Common functions for dispatcher operations
630: */
631: struct adreno_dispatch_ops {
632: /* @close: Shut down the dispatcher */
633: void (*close)(struct adreno_device *adreno_dev);
634: /* @queue_cmds: Queue a command on the context */
635: int (*queue_cmds)(struct kgsl_device_private *dev_priv,
636: struct kgsl_context *context, struct kgsl_drawobj *drawobj[],
637: u32 count, u32 *timestamp);
638: /* @queue_context: Queue a context to be dispatched */
639: void (*queue_context)(struct adreno_device *adreno_dev,
640: struct adreno_context *drawctxt);
641: int (*setup_context)(struct adreno_device *adreno_dev,
642: struct adreno_context *drawctxt);
643: /* @create_hw_fence: Create a hardware fence */
644: void (*create_hw_fence)(struct adreno_device *adreno_dev, struct kgsl_sync_fence *kfence);
645: };
646:
647: /**
648: * struct adreno_fault_proc - Structure to hold data on faulting processes
649: */
650: struct adreno_fault_proc {
651: /** @comm: Task name of the faulting process */
652: char comm[TASK_COMM_LEN];
653: /** @fault_count: Count of the GPU faults from this process */
654: u32 fault_count;
655: };
656:
657: #define ADRENO_MAX_FAULTING_PROCS 10
658:
659: /**
660: * struct adreno_device - The mothership structure for all adreno related info
661: * @dev: Reference to struct kgsl_device
662: * @priv: Holds the private flags specific to the adreno_device
663: * @chipid: Chip ID specific to the GPU
664: * @gpucore: Pointer to the adreno_gpu_core structure
665: * @gpmu_cmds_size: Length of gpmu cmd stream
666: * @gpmu_cmds: gpmu cmd stream
667: * @ringbuffers: Array of pointers to adreno_ringbuffers
668: * @num_ringbuffers: Number of ringbuffers for the GPU
669: * @cur_rb: Pointer to the current ringbuffer
670: * @next_rb: Ringbuffer we are switching to during preemption
671: * @prev_rb: Ringbuffer we are switching from during preemption
672: * @ft_policy: Defines the fault tolerance policy
673: * @long_ib_detect: Long IB detection availability
674: * @cooperative_reset: Indicates if graceful death handshake is enabled
675: * between GMU and GPU
676: * @profile: Container for adreno profiler information
677: * @dispatcher: Container for adreno GPU dispatcher
678: * @pwron_fixup: Command buffer to run a post-power collapse shader workaround
679: * @pwron_fixup_dwords: Number of dwords in the command buffer
680: * @input_work: Work struct for turning on the GPU after a touch event
681: * @busy_data: Struct holding GPU VBIF busy stats
682: * @ram_cycles_lo: Number of DDR clock cycles for the monitor session (Only
683: * DDR channel 0 read cycles in case of GBIF)
684: * @ram_cycles_lo_ch1_read: Number of DDR channel 1 Read clock cycles for
685: * the monitor session
686: * @ram_cycles_lo_ch0_write: Number of DDR channel 0 Write clock cycles for
687: * the monitor session
688: * @ram_cycles_lo_ch1_write: Number of DDR channel 0 Write clock cycles for
689: * the monitor session
690: * @starved_ram_lo: Number of cycles VBIF/GBIF is stalled by DDR (Only channel 0
691: * stall cycles in case of GBIF)
692: * @starved_ram_lo_ch1: Number of cycles GBIF is stalled by DDR channel 1
693: * @halt: Atomic variable to check whether the GPU is currently halted
694: * @pending_irq_refcnt: Atomic variable to keep track of running IRQ handlers
695: * @ctx_d_debugfs: Context debugfs node
696: * @profile_buffer: Memdesc holding the drawobj profiling buffer
697: * @profile_index: Index to store the start/stop ticks in the profiling
698: * buffer
699: * @pwrup_reglist: Memdesc holding the power up register list
700: * which is used by CP during preemption and IFPC
701: * @lm_sequence: Pointer to the start of the register write sequence for LM
702: * @lm_size: The dword size of the LM sequence
703: * @lm_limit: limiting value for LM
704: * @lm_threshold_count: register value for counter for lm threshold breakin
705: * @lm_threshold_cross: number of current peaks exceeding threshold
706: * @ifpc_count: Number of times the GPU went into IFPC
707: * @highest_bank_bit: Value of the highest bank bit
708: * @gpmu_throttle_counters - counters for number of throttled clocks
709: * @irq_storm_work: Worker to handle possible interrupt storms
710: * @active_list: List to track active contexts
711: * @active_list_lock: Lock to protect active_list
712: * @gpu_llc_slice: GPU system cache slice descriptor
713: * @gpu_llc_slice_enable: To enable the GPU system cache slice or not
714: * @gpuhtw_llc_slice: GPU pagetables system cache slice descriptor
715: * @gpuhtw_llc_slice_enable: To enable the GPUHTW system cache slice or not
716: * @gpumv_llc_slice: GPU MV buffer system cache slice descriptor
717: * @gpumv_llc_slice_enable: To enable GPUMV buffer system cache slice or not
718: * @zap_loaded: Used to track if zap was successfully loaded or not
719: */
720: struct adreno_device {
721: struct kgsl_device dev; /* Must be first field in this struct */
722: unsigned long priv;
723: unsigned int chipid;
724: /** @uche_gmem_base: Base address of GMEM for UCHE access */
725: u64 uche_gmem_base;
726: const struct adreno_gpu_core *gpucore;
727: struct adreno_firmware fw[2];
728: size_t gpmu_cmds_size;
729: unsigned int *gpmu_cmds;
730: struct adreno_ringbuffer ringbuffers[KGSL_PRIORITY_MAX_RB_LEVELS];
731: int num_ringbuffers;
732: struct adreno_ringbuffer *cur_rb;
733: struct adreno_ringbuffer *next_rb;
734: struct adreno_ringbuffer *prev_rb;
735: unsigned long ft_policy;
736: bool long_ib_detect;
737: bool cooperative_reset;
738: struct adreno_profile profile;
739: struct adreno_dispatcher dispatcher;
740: struct kgsl_memdesc *pwron_fixup;
741: unsigned int pwron_fixup_dwords;
742: struct work_struct input_work;
743: struct adreno_busy_data busy_data;
744: unsigned int ram_cycles_lo;
745: unsigned int ram_cycles_lo_ch1_read;
746: unsigned int ram_cycles_lo_ch0_write;
747: unsigned int ram_cycles_lo_ch1_write;
748: unsigned int starved_ram_lo;
749: unsigned int starved_ram_lo_ch1;
750: atomic_t halt;
751: atomic_t pending_irq_refcnt;
752: struct dentry *ctx_d_debugfs;
753: /** @lm_enabled: True if limits management is enabled for this target */
754: bool lm_enabled;
755: /** @acd_enabled: True if acd is enabled for this target */
756: bool acd_enabled;
757: /** @hwcg_enabled: True if hardware clock gating is enabled */
758: bool hwcg_enabled;
759: /** @throttling_enabled: True if LM throttling is enabled on a5xx */
760: bool throttling_enabled;
761: /** @sptp_pc_enabled: True if SPTP power collapse is enabled on a5xx */
762: bool sptp_pc_enabled;
763: /** @bcl_enabled: True if BCL is enabled */
764: bool bcl_enabled;
765: /** @clx_enabled: True if CLX is enabled */
766: bool clx_enabled;
767: /** @isense_reg_mapped: True if isense registers are mapped to regmap */
768: bool isense_reg_mapped;
769: /** @lpac_enabled: True if LPAC is enabled */
770: bool lpac_enabled;
771: /** @dms_enabled: True if DMS is enabled */
772: bool dms_enabled;
773: /** @minbw_enabled: True if minbw vote is enabled */
774: bool minbw_enabled;
775: /** @malu_enabled: True if mALU is enabled */
776: bool malu_enabled;
777: /** @preempt_override: True if command line param enables preemption */
778: bool preempt_override;
779: struct kgsl_memdesc *profile_buffer;
780: unsigned int profile_index;
781: struct kgsl_memdesc *pwrup_reglist;
782: uint32_t *lm_sequence;
783: uint32_t lm_size;
784: struct adreno_preemption preempt;
785: struct work_struct gpmu_work;
786: uint32_t lm_leakage;
787: uint32_t lm_limit;
788: uint32_t lm_threshold_count;
789: uint32_t lm_threshold_cross;
790: uint32_t ifpc_count;
791:
792: unsigned int highest_bank_bit;
793: /** @ubwc_mode: Supported UBWC mode */
794: u32 ubwc_mode;
795: /** @mal: Minimum access length */
796: u32 mal;
797: unsigned int quirks;
798:
799: #ifdef CONFIG_QCOM_KGSL_CORESIGHT
800: /** @gx_coresight: A coresight instance for GX */
801: struct adreno_coresight_device gx_coresight;
--- LINES 806-855 ---
806: /**
807: * @coresight_en_cnt: Retain mask if either coresight-gfx
808: * or coresight-gfx-cx is enabled; remove only when both
809: * are disabled
810: */
811: u32 coresight_en_cnt;
812: #endif
813:
814: uint32_t gpmu_throttle_counters[ADRENO_GPMU_THROTTLE_COUNTERS];
815: struct work_struct irq_storm_work;
816:
817: struct list_head active_list;
818: spinlock_t active_list_lock;
819:
820: void *gpu_llc_slice;
821: bool gpu_llc_slice_enable;
822: void *gpuhtw_llc_slice;
823: bool gpuhtw_llc_slice_enable;
824: void *gpumv_llc_slice;
825: bool gpumv_llc_slice_enable;
826: unsigned int zap_loaded;
827: /** @zap_enabled: True when zap-shader is present */
828: bool zap_enabled;
829: /**
830: * @critpkts: Memory descriptor for 5xx critical packets if applicable
831: */
832: struct kgsl_memdesc *critpkts;
833: /**
834: * @critpkts: Memory descriptor for 5xx secure critical packets
835: */
836: struct kgsl_memdesc *critpkts_secure;
837: /** @irq_mask: The current interrupt mask for the GPU device */
838: u32 irq_mask;
839: /* @dispatch_ops: A pointer to a set of adreno dispatch ops */
840: const struct adreno_dispatch_ops *dispatch_ops;
841: /** @hwsched: Container for the hardware dispatcher */
842: struct adreno_hwsched hwsched;
843: /*
844: * @perfcounter: Flag to clear perfcounters across contexts and
845: * controls perfcounter ioctl read
846: */
847: bool perfcounter;
848: /** @gmu_hub_clk_freq: Gmu hub interface clock frequency */
849: u64 gmu_hub_clk_freq;
850: /* @patch_reglist: If false power up register list needs to be patched */
851: bool patch_reglist;
852: /*
853: * @uche_client_pf: uche_client_pf client register configuration
854: * for pf debugging
855: */
--- LINES 861-888 ---
861: u32 bcl_data;
862: /* @minbw_data: Min bw level to vote for when entering ifpc */
863: u32 minbw_data;
864: /*
865: * @bcl_debugfs_dir: Debugfs directory node for bcl related nodes
866: */
867: struct dentry *bcl_debugfs_dir;
868: /** @bcl_throttle_time_us: Total time in us spent in BCL throttling */
869: u32 bcl_throttle_time_us;
870: /* @preemption_debugfs_dir: Debugfs directory node for preemption related nodes */
871: struct dentry *preemption_debugfs_dir;
872: /* @hwsched_enabled: If true, hwsched is enabled */
873: bool hwsched_enabled;
874: /* @fastblend_enabled: True if fastblend feature is enabled */
875: bool fastblend_enabled;
876: /* @raytracing_enabled: True if raytracing feature is enabled */
877: bool raytracing_enabled;
878: /* @feature_fuse: feature fuse value read from HW */
879: u32 feature_fuse;
880: /** @gmu_ab: Track if GMU supports ab vote */
881: bool gmu_ab;
882: /** @ifpc_hyst: IFPC long hysteresis value */
883: u32 ifpc_hyst;
884: /** @ifpc_hyst_floor: IFPC long hysteresis floor value */
885: u32 ifpc_hyst_floor;
886: /*
887: * @no_restore_count: Keep track of perfcounter requests that don't have
888: * ADRENO_PERFCOUNTER_GROUP_RESTORE flag set
--- LINES 916-946 ---
916: atomic_t scheduler_fault;
917: /** @dcvs_tuning_mutex: Mutex taken during dcvs tuning */
918: struct mutex dcvs_tuning_mutex;
919: /** @dcvs_tuning_mingap_lvl: Current DCVS tuning level for mingap */
920: u32 dcvs_tuning_mingap_lvl;
921: /** @dcvs_tuning_penalty_lvl: Current DCVS tuning level for penalty */
922: u32 dcvs_tuning_penalty_lvl;
923: /** @dcvs_tuning_numbusy_lvl: Current DCVS tuning level for numbusy */
924: u32 dcvs_tuning_numbusy_lvl;
925: /** @total_ctxt_record_sz: Size of the total preemption record in bytes */
926: u64 total_ctxt_record_sz;
927: /** @dcvs_profile_enabled: True if DCVS profile is enabled */
928: bool dcvs_profile_enabled;
929: /** @aqe_ctxt_record_sz: Size of the AQE section in preemption record in bytes */
930: u64 aqe_ctxt_record_sz;
931: /** @ubwc_cfg: Pointer to hold struct qcom_ubwc_cfg_data fetched from
932: * qcom_ubwc_config_get_data() API
933: */
934: void *ubwc_cfg_data;
935: /** @adreno_ubwc_props: Container of all UBWC props required to program NC_MODE_CNTL
936: * registers
937: */
938: struct adreno_ubwc_props ubwc_props;
939: /** @multidraw_mode: Whether PC unroll is enabled for multidraw **/
940: u32 multidraw_mode;
941: /** @viz_flush_draw_count: Draw count to flush visibility stream **/
942: u32 viz_flush_draw_count;
943: /** @viz_flush_prim_count: Prim count to flush visibility stream **/
944: u32 viz_flush_prim_count;
945: };
946:
--- LINES 951-997 ---
951: * enum adreno_device_flags - Private flags for the adreno_device
952: * @ADRENO_DEVICE_PWRON - Set during init after a power collapse
953: * @ADRENO_DEVICE_PWRON_FIXUP - Set if the target requires the shader fixup
954: * after power collapse
955: * @ADRENO_DEVICE_STARTED - Set if the device start sequence is in progress
956: * @ADRENO_DEVICE_FAULT - Set if the device is currently in fault (and shouldn't
957: * send any more commands to the ringbuffer)
958: * @ADRENO_DEVICE_DRAWOBJ_PROFILE - Set if the device supports drawobj
959: * profiling via the ALWAYSON counter
960: * @ADRENO_DEVICE_PREEMPTION - Turn on/off preemption
961: * @ADRENO_DEVICE_SOFT_FAULT_DETECT - Set if soft fault detect is enabled
962: * @ADRENO_DEVICE_GPMU_INITIALIZED - Set if GPMU firmware initialization succeed
963: * @ADRENO_DEVICE_ISDB_ENABLED - Set if the Integrated Shader DeBugger is
964: * attached and enabled
965: * @ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED - Set if a CACHE_FLUSH_TS irq storm
966: * is in progress
967: */
968: enum adreno_device_flags {
969: ADRENO_DEVICE_PWRON = 0,
970: ADRENO_DEVICE_PWRON_FIXUP = 1,
971: ADRENO_DEVICE_INITIALIZED = 2,
972: ADRENO_DEVICE_STARTED = 5,
973: ADRENO_DEVICE_FAULT = 6,
974: ADRENO_DEVICE_DRAWOBJ_PROFILE = 7,
975: ADRENO_DEVICE_GPU_REGULATOR_ENABLED = 8,
976: ADRENO_DEVICE_PREEMPTION = 9,
977: ADRENO_DEVICE_SOFT_FAULT_DETECT = 10,
978: ADRENO_DEVICE_GPMU_INITIALIZED = 11,
979: ADRENO_DEVICE_ISDB_ENABLED = 12,
980: ADRENO_DEVICE_CACHE_FLUSH_TS_SUSPENDED = 13,
981: /** @ADRENO_DEVICE_DMS: Set if DMS is enabled */
982: ADRENO_DEVICE_DMS = 14,
983: /** @ADRENO_DEVICE_GMU_AB: Set if AB vote via GMU is enabled */
984: ADRENO_DEVICE_GMU_AB = 15,
985: /** @ADRENO_DEVICE_CX_TIMER_INITIALIZED: Set if the CX timer is initialized */
986: ADRENO_DEVICE_CX_TIMER_INITIALIZED = 17,
987: /** @ADRENO_DEVICE_RESET_RECOVERY: Set if the ADRENO device under goes reset recovery */
988: ADRENO_DEVICE_RESET_RECOVERY = 18,
989: /** @ADRENO_DEVICE_FIRST_BOOT_DONE: Set if the ADRENO device first boot is done */
990: ADRENO_DEVICE_FIRST_BOOT_DONE = 19,
991: /** @ADRENO_DEVICE_FAST_CONTEXT_DESTROY: Set if fast context destroy is enabled on GMU */
992: ADRENO_DEVICE_FAST_CONTEXT_DESTROY = 20,
993: /** @ADRENO_DEVICE_ALLOW_MALU_WORKLOAD: mALU workload is supported by GMU and GPU */
994: ADRENO_DEVICE_ALLOW_MALU_WORKLOAD = 21,
995: };
996:
997: /**
--- LINES 1029-1140 ---
1029: };
1030:
1031: /**
1032: * adreno_regs: List of registers that are used in kgsl driver for all
1033: * 3D devices. Each device type has different offset value for the same
1034: * register, so an array of register offsets are declared for every device
1035: * and are indexed by the enumeration values defined in this enum
1036: */
1037: enum adreno_regs {
1038: ADRENO_REG_CP_RB_BASE,
1039: ADRENO_REG_CP_RB_BASE_HI,
1040: ADRENO_REG_CP_LPAC_RB_BASE,
1041: ADRENO_REG_CP_LPAC_RB_BASE_HI,
1042: ADRENO_REG_CP_RB_RPTR,
1043: ADRENO_REG_CP_RB_WPTR,
1044: ADRENO_REG_CP_ME_CNTL,
1045: ADRENO_REG_CP_RB_CNTL,
1046: ADRENO_REG_CP_IB1_BASE,
1047: ADRENO_REG_CP_IB1_BASE_HI,
1048: ADRENO_REG_CP_IB1_BUFSZ,
1049: ADRENO_REG_CP_IB2_BASE,
1050: ADRENO_REG_CP_IB2_BASE_HI,
1051: ADRENO_REG_CP_IB2_BUFSZ,
1052: ADRENO_REG_RBBM_STATUS,
1053: ADRENO_REG_RBBM_STATUS3,
1054: ADRENO_REG_RBBM_INT_0_MASK,
1055: ADRENO_REG_RBBM_SW_RESET_CMD,
1056: ADRENO_REG_GMU_AO_HOST_INTERRUPT_MASK,
1057: ADRENO_REG_GMU_GMU2HOST_INTR_MASK,
1058: ADRENO_REG_REGISTER_MAX,
1059: };
1060:
1061: #define ADRENO_REG_UNUSED 0xFFFFFFFF
1062: #define ADRENO_REG_SKIP 0xFFFFFFFE
1063: #define ADRENO_REG_DEFINE(_offset, _reg)[_offset] = _reg
1064:
1065: struct adreno_irq_funcs {
1066: void (*func)(struct adreno_device *adreno_dev, int mask);
1067: };
1068: #define ADRENO_IRQ_CALLBACK(_c) { .func = _c }
1069:
1070: /*
1071: * struct adreno_debugbus_block - Holds info about debug buses of a chip
1072: * @block_id: Bus identifier
1073: * @dwords: Number of dwords of data that this block holds
1074: */
1075: struct adreno_debugbus_block {
1076: unsigned int block_id;
1077: unsigned int dwords;
1078: };
1079:
1080: struct adreno_gpudev {
1081: /*
1082: * These registers are in a different location on different devices,
1083: * so define them in the structure and use them as variables.
1084: */
1085: unsigned int *const reg_offsets;
1086:
1087: /* GPU specific function hooks */
1088: int (*probe)(struct platform_device *pdev, u32 chipid,
1089: const struct adreno_gpu_core *gpucore);
1090: void (*snapshot)(struct adreno_device *adreno_dev,
1091: struct kgsl_snapshot *snapshot);
1092: irqreturn_t (*irq_handler)(struct adreno_device *adreno_dev);
1093: int (*init)(struct adreno_device *adreno_dev);
1094: void (*remove)(struct adreno_device *adreno_dev);
1095: int (*rb_start)(struct adreno_device *adreno_dev);
1096: int (*start)(struct adreno_device *adreno_dev);
1097: int (*regulator_enable)(struct adreno_device *adreno_dev);
1098: void (*regulator_disable)(struct adreno_device *adreno_dev);
1099: void (*pwrlevel_change_settings)(struct adreno_device *adreno_dev,
1100: unsigned int prelevel, unsigned int postlevel,
1101: bool post);
1102: void (*preemption_schedule)(struct adreno_device *adreno_dev);
1103: void (*context_detach)(struct adreno_context *drawctxt);
1104: void (*pre_reset)(struct adreno_device *adreno_dev);
1105: void (*gpu_keepalive)(struct adreno_device *adreno_dev,
1106: bool state);
1107: bool (*hw_isidle)(struct adreno_device *adreno_dev);
1108: const char *(*iommu_fault_block)(struct kgsl_device *device,
1109: unsigned int fsynr1);
1110: int (*reset)(struct adreno_device *adreno_dev);
1111: /** @soft_reset: Soft reset GPU on fault recovery */
1112: int (*soft_reset)(struct adreno_device *adreno_dev,
1113: struct kgsl_context *context, bool ctx_guilty);
1114: /** @read_alwayson: Return the current value of the alwayson counter */
1115: u64 (*read_alwayson)(struct adreno_device *adreno_dev);
1116: /**
1117: * @power_ops: Target specific function pointers to power up/down the
1118: * gpu
1119: */
1120: const struct adreno_power_ops *power_ops;
1121: int (*clear_pending_transactions)(struct adreno_device *adreno_dev);
1122: void (*deassert_gbif_halt)(struct adreno_device *adreno_dev);
1123: int (*ringbuffer_submitcmd)(struct adreno_device *adreno_dev,
1124: struct kgsl_drawobj_cmd *cmdobj, u32 flags,
1125: struct adreno_submit_time *time);
1126: /**
1127: * @is_hw_collapsible: Return true if the hardware can be collapsed.
1128: * Only used by non GMU/RGMU targets
1129: */
1130: bool (*is_hw_collapsible)(struct adreno_device *adreno_dev);
1131: /**
1132: * @power_stats - Return the perfcounter statistics for DCVS
1133: */
1134: void (*power_stats)(struct adreno_device *adreno_dev,
1135: struct kgsl_power_stats *stats);
1136: int (*add_to_va_minidump)(struct adreno_device *adreno_dev);
1137: /**
1138: * @gx_is_on - Return true if both gfx clock and gxgdsc are enabled.
1139: */
1140: bool (*gx_is_on)(struct adreno_device *adreno_dev);
--- LINES 1151-1179 ---
1151: /**
1152: * @set_isdb_breakpoint_registers - Program isdb registers to issue break command
1153: */
1154: void (*set_isdb_breakpoint_registers)(struct adreno_device *adreno_dev);
1155: /**
1156: * @context_destroy: Target specific function called during context destruction
1157: */
1158: void (*context_destroy)(struct adreno_device *adreno_dev, struct adreno_context *drawctxt);
1159: /**
1160: * @swfuse_irqctrl: To enable/disable sw fuse violation interrupt
1161: */
1162: void (*swfuse_irqctrl)(struct adreno_device *adreno_dev, bool state);
1163: /**
1164: * @lpac_store: To enable/disable lpac at runtime
1165: */
1166: int (*lpac_store)(struct adreno_device *adreno_dev, bool enable);
1167: /*
1168: * @get_uche_trap_base: Return the UCHE_TRAP_BASE value
1169: */
1170: u64 (*get_uche_trap_base)(void);
1171: /**
1172: * @fault_header: Print fault header
1173: */
1174: void (*fault_header)(struct adreno_device *adreno_dev, struct kgsl_drawobj *drawobj);
1175: /**
1176: * @lpac_fault_header: Print LPAC fault header
1177: */
1178: void (*lpac_fault_header)(struct adreno_device *adreno_dev, struct kgsl_drawobj *drawobj);
1179: /**
--- LINES 1248-1292 ---
1248:
1249: long adreno_ioctl_helper(struct kgsl_device_private *dev_priv,
1250: unsigned int cmd, unsigned long arg,
1251: const struct kgsl_ioctl *cmds, int len);
1252:
1253: int adreno_spin_idle(struct adreno_device *device, unsigned int timeout);
1254: int adreno_wait_idle(struct kgsl_device *device);
1255:
1256: int adreno_set_constraint(struct kgsl_device *device,
1257: struct kgsl_context *context,
1258: struct kgsl_device_constraint *constraint);
1259:
1260: void adreno_snapshot(struct kgsl_device *device,
1261: struct kgsl_snapshot *snapshot,
1262: struct kgsl_context *context, struct kgsl_context *context_lpac);
1263:
1264: int adreno_reset(struct kgsl_device *device, int fault);
1265:
1266: void adreno_fault_skipcmd_detached(struct adreno_device *adreno_dev,
1267: struct adreno_context *drawctxt,
1268: struct kgsl_drawobj *drawobj);
1269:
1270: void adreno_hang_int_callback(struct adreno_device *adreno_dev, int bit);
1271: void adreno_cp_callback(struct adreno_device *adreno_dev, int bit);
1272:
1273: int adreno_sysfs_init(struct adreno_device *adreno_dev);
1274:
1275: void adreno_irqctrl(struct adreno_device *adreno_dev, int state);
1276:
1277: long adreno_ioctl_perfcounter_get(struct kgsl_device_private *dev_priv,
1278: unsigned int cmd, void *data);
1279:
1280: long adreno_ioctl_perfcounter_put(struct kgsl_device_private *dev_priv,
1281: unsigned int cmd, void *data);
1282:
1283: bool adreno_gx_is_on(struct adreno_device *adreno_dev);
1284:
1285: u64 adreno_read_cx_timer(struct adreno_device *adreno_dev);
1286:
1287: /**
1288: * adreno_active_count_get - Wrapper for target specific active count get
1289: * @adreno_dev: pointer to the adreno device
1290: *
1291: * Increase the active count for the KGSL device and execute slumber exit
1292: * sequence if this is the first reference. Code paths that need to touch the
--- LINES 1595-1663 ---
1595:
1596: if (offset_name >= ADRENO_REG_REGISTER_MAX ||
1597: gpudev->reg_offsets[offset_name] == ADRENO_REG_UNUSED)
1598: return false;
1599:
1600: /*
1601: * GPU register programming is kept common as much as possible
1602: * across the cores, Use ADRENO_REG_SKIP when certain register
1603: * programming needs to be skipped for certain GPU cores.
1604: * Example: Certain registers on a5xx like IB1_BASE are 64 bit.
1605: * Common programming programs 64bit register but upper 32 bits
1606: * are skipped in a5xx using ADRENO_REG_SKIP.
1607: */
1608: if (gpudev->reg_offsets[offset_name] == ADRENO_REG_SKIP)
1609: return false;
1610:
1611: return true;
1612: }
1613:
1614: /*
1615: * adreno_readreg() - Read a register by getting its offset from the
1616: * offset array defined in gpudev node
1617: * @adreno_dev: Pointer to the adreno device
1618: * @offset_name: The register enum that is to be read
1619: * @val: Register value read is placed here
1620: */
1621: static inline void adreno_readreg(struct adreno_device *adreno_dev,
1622: enum adreno_regs offset_name, unsigned int *val)
1623: {
1624: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1625:
1626: if (adreno_checkreg_off(adreno_dev, offset_name))
1627: kgsl_regread(KGSL_DEVICE(adreno_dev),
1628: gpudev->reg_offsets[offset_name], val);
1629: else
1630: *val = 0;
1631: }
1632:
1633: /*
1634: * adreno_writereg() - Write a register by getting its offset from the
1635: * offset array defined in gpudev node
1636: * @adreno_dev: Pointer to the adreno device
1637: * @offset_name: The register enum that is to be written
1638: * @val: Value to write
1639: */
1640: static inline void adreno_writereg(struct adreno_device *adreno_dev,
1641: enum adreno_regs offset_name, unsigned int val)
1642: {
1643: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1644:
1645: if (adreno_checkreg_off(adreno_dev, offset_name))
1646: kgsl_regwrite(KGSL_DEVICE(adreno_dev),
1647: gpudev->reg_offsets[offset_name], val);
1648: }
1649:
1650: /*
1651: * adreno_getreg() - Returns the offset value of a register from the
1652: * register offset array in the gpudev node
1653: * @adreno_dev: Pointer to the adreno device
1654: * @offset_name: The register enum whore offset is returned
1655: */
1656: static inline unsigned int adreno_getreg(struct adreno_device *adreno_dev,
1657: enum adreno_regs offset_name)
1658: {
1659: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1660:
1661: if (!adreno_checkreg_off(adreno_dev, offset_name))
1662: return ADRENO_REG_REGISTER_MAX;
1663: return gpudev->reg_offsets[offset_name];
--- LINES 1833-1995 ---
1833: unsigned int version)
1834: {
1835: if (adreno_dev->fw[ADRENO_FW_PFP].version == version)
1836: return 0;
1837:
1838: return (adreno_dev->fw[ADRENO_FW_PFP].version > version) ? 1 : -1;
1839: }
1840:
1841: /**
1842: * adreno_in_preempt_state() - Check if preemption state is equal to given state
1843: * @adreno_dev: Device whose preemption state is checked
1844: * @state: State to compare against
1845: */
1846: static inline bool adreno_in_preempt_state(struct adreno_device *adreno_dev,
1847: enum adreno_preempt_states state)
1848: {
1849: return atomic_read(&adreno_dev->preempt.state) == state;
1850: }
1851: /**
1852: * adreno_set_preempt_state() - Set the specified preemption state
1853: * @adreno_dev: Device to change preemption state
1854: * @state: State to set
1855: */
1856: static inline void adreno_set_preempt_state(struct adreno_device *adreno_dev,
1857: enum adreno_preempt_states state)
1858: {
1859: /*
1860: * atomic_set doesn't use barriers, so we need to do it ourselves. One
1861: * before...
1862: */
1863: smp_wmb();
1864: atomic_set(&adreno_dev->preempt.state, state);
1865:
1866: /* ... and one after */
1867: smp_wmb();
1868: }
1869:
1870: static inline bool adreno_is_preemption_enabled(
1871: struct adreno_device *adreno_dev)
1872: {
1873: return test_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv);
1874: }
1875:
1876: /**
1877: * adreno_is_fast_context_destroy_enabled() - Check whether the GMU fast context
1878: * destroy optimization is statically enabled and if the GMU supports the
1879: * capability.
1880: * @adreno_dev: Pointer to the adreno_device struct
1881: */
1882: static inline bool adreno_is_fast_context_destroy_enabled(
1883: struct adreno_device *adreno_dev)
1884: {
1885: return test_bit(ADRENO_DEVICE_FAST_CONTEXT_DESTROY, &adreno_dev->priv);
1886: }
1887:
1888:
1889: /**
1890: * adreno_preemption_feature_set() - Check whether adreno preemption feature is statically enabled
1891: * either via adreno feature bit, or via the cmdline override
1892: * @adreno_dev: Device whose preemption state is checked
1893: */
1894: static inline bool adreno_preemption_feature_set(struct adreno_device *adreno_dev)
1895: {
1896: return ADRENO_FEATURE(adreno_dev, ADRENO_PREEMPTION) || adreno_dev->preempt_override;
1897: }
1898:
1899: /*
1900: * adreno_compare_prio_level() - Compares 2 priority levels based on enum values
1901: * @p1: First priority level
1902: * @p2: Second priority level
1903: *
1904: * Returns greater than 0 if p1 is higher priority, 0 if levels are equal else
1905: * less than 0
1906: */
1907: static inline int adreno_compare_prio_level(int p1, int p2)
1908: {
1909: return p2 - p1;
1910: }
1911:
1912: void adreno_readreg64(struct adreno_device *adreno_dev,
1913: enum adreno_regs lo, enum adreno_regs hi, uint64_t *val);
1914:
1915: void adreno_writereg64(struct adreno_device *adreno_dev,
1916: enum adreno_regs lo, enum adreno_regs hi, uint64_t val);
1917:
1918: unsigned int adreno_get_rptr(struct adreno_ringbuffer *rb);
1919:
1920: void adreno_touch_wake(struct kgsl_device *device);
1921:
1922: static inline bool adreno_rb_empty(struct adreno_ringbuffer *rb)
1923: {
1924: return (adreno_get_rptr(rb) == rb->wptr);
1925: }
1926:
1927: static inline bool adreno_long_ib_detect(struct adreno_device *adreno_dev)
1928: {
1929: return adreno_dev->long_ib_detect &&
1930: !test_bit(ADRENO_DEVICE_ISDB_ENABLED, &adreno_dev->priv);
1931: }
1932:
1933: /**
1934: * adreno_support_64bit - Return true if the GPU supports 64 bit addressing
1935: * @adreno_dev: An Adreno GPU device handle
1936: *
1937: * Return: True if the device supports 64 bit addressing
1938: */
1939: static inline bool adreno_support_64bit(struct adreno_device *adreno_dev)
1940: {
1941: /*
1942: * The IOMMU API takes a unsigned long for the iova so we can't support
1943: * 64 bit addresses when the kernel is in 32 bit mode even if we wanted
1944: * so we need to check that we are using a5xx or newer and that the
1945: * unsigned long is big enough for our purposes.
1946: */
1947: return (BITS_PER_LONG > 32 && ADRENO_GPUREV(adreno_dev) >= 500);
1948: }
1949:
1950: static inline void adreno_ringbuffer_set_pagetable(struct kgsl_device *device,
1951: struct adreno_ringbuffer *rb, struct kgsl_pagetable *pt)
1952: {
1953: unsigned long flags;
1954:
1955: spin_lock_irqsave(&rb->preempt_lock, flags);
1956:
1957: kgsl_sharedmem_writel(device->scratch,
1958: SCRATCH_RB_OFFSET(rb->id, current_rb_ptname), pt->name);
1959:
1960: kgsl_sharedmem_writeq(device->scratch,
1961: SCRATCH_RB_OFFSET(rb->id, ttbr0),
1962: kgsl_mmu_pagetable_get_ttbr0(pt));
1963:
1964: kgsl_sharedmem_writel(device->scratch,
1965: SCRATCH_RB_OFFSET(rb->id, contextidr), 0);
1966:
1967: spin_unlock_irqrestore(&rb->preempt_lock, flags);
1968: }
1969:
1970: static inline u32 counter_delta(struct kgsl_device *device,
1971: unsigned int reg, unsigned int *counter)
1972: {
1973: u32 val, ret = 0;
1974:
1975: if (!reg)
1976: return 0;
1977:
1978: kgsl_regread(device, reg, &val);
1979:
1980: if (*counter) {
1981: if (val >= *counter)
1982: ret = val - *counter;
1983: else
1984: ret = (UINT_MAX - *counter) + val;
1985: }
1986:
1987: *counter = val;
1988: return ret;
1989: }
1990:
1991: static inline int adreno_perfcntr_active_oob_get(
1992: struct adreno_device *adreno_dev)
1993: {
1994: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
1995: int ret = adreno_active_count_get(adreno_dev);
--- LINES 2029-2089 ---
2029: if (ret)
2030: dev_err(device->dev,
2031: "GBIF/VBIF Halt ack timeout: reg=%08x mask=%08x status=%08x\n",
2032: ack_reg, mask, val);
2033:
2034: return ret;
2035: }
2036:
2037: /**
2038: * adreno_move_preempt_state - Update the preemption state
2039: * @adreno_dev: An Adreno GPU device handle
2040: * @old: The current state of the preemption
2041: * @new: The new state of the preemption
2042: *
2043: * Return: True if the state was updated or false if not
2044: */
2045: static inline bool adreno_move_preempt_state(struct adreno_device *adreno_dev,
2046: enum adreno_preempt_states old, enum adreno_preempt_states new)
2047: {
2048: return (atomic_cmpxchg(&adreno_dev->preempt.state, old, new) == old);
2049: }
2050:
2051: /**
2052: * adreno_reg_offset_init - Helper function to initialize reg_offsets
2053: * @reg_offsets: Pointer to an array of register offsets
2054: *
2055: * Helper function to setup register_offsets for a target. Go through
2056: * and set ADRENO_REG_UNUSED for all unused entries in the list.
2057: */
2058: static inline void adreno_reg_offset_init(u32 *reg_offsets)
2059: {
2060: int i;
2061:
2062: /*
2063: * Initialize uninitialzed gpu registers, only needs to be done once.
2064: * Make all offsets that are not initialized to ADRENO_REG_UNUSED
2065: */
2066: for (i = 0; i < ADRENO_REG_REGISTER_MAX; i++) {
2067: if (!reg_offsets[i])
2068: reg_offsets[i] = ADRENO_REG_UNUSED;
2069: }
2070: }
2071:
2072: static inline u32 adreno_get_level(struct kgsl_context *context)
2073: {
2074: u32 level;
2075:
2076: if (kgsl_context_is_lpac(context))
2077: return KGSL_LPAC_RB_ID;
2078:
2079: level = context->priority / KGSL_PRIORITY_MAX_RB_LEVELS;
2080:
2081: return min_t(u32, level, KGSL_PRIORITY_MAX_RB_LEVELS - 1);
2082: }
2083:
2084: /**
2085: * adreno_request_firmware - Helper function for requesting firmware
2086: * @fw: Pointer to firmware image
2087: * @name: Name of firmware file
2088: * @device: Device for which firmware is being loaded
2089: * @log_error: If true, logs an error message on failure
--- LINES 2117-2152 ---
2117: *
2118: * A target indepedent helper function for loading the zap shader.
2119: *
2120: * Return: 0 on success or negative on failure.
2121: */
2122: int adreno_zap_shader_load(struct adreno_device *adreno_dev,
2123: const char *name);
2124:
2125: /**
2126: * adreno_irq_callbacks - Helper function to handle IRQ callbacks
2127: * @adreno_dev: Adreno GPU device handle
2128: * @funcs: List of callback functions
2129: * @status: Interrupt status
2130: *
2131: * Walk the bits in the interrupt status and call any applicable callbacks.
2132: * Return: IRQ_HANDLED if one or more interrupt callbacks were called.
2133: */
2134: irqreturn_t adreno_irq_callbacks(struct adreno_device *adreno_dev,
2135: const struct adreno_irq_funcs *funcs, u32 status);
2136:
2137:
2138: /**
2139: * adreno_device_probe - Generic adreno device probe function
2140: * @pdev: Pointer to the platform device
2141: * @adreno_dev: Adreno GPU device handle
2142: *
2143: * Do the generic setup for the Adreno device. Called from the target specific
2144: * probe functions.
2145: *
2146: * Return: 0 on success or negative on failure
2147: */
2148: int adreno_device_probe(struct platform_device *pdev,
2149: struct adreno_device *adreno_dev);
2150:
2151: /**
2152: * adreno_power_cycle - Suspend and resume the device
--- LINES 2225-2338 ---
2225: * adreno_check_idle - Make sure device is idle
2226: * @device: Pointer to the kgsl device
2227: *
2228: * This function processes the profiling results and log an error if
2229: * device is not idle
2230: */
2231: void adreno_check_idle(struct kgsl_device *device);
2232:
2233: /*
2234: * adreno_profile_submit_time - Populate profiling buffer with timestamps
2235: * @time: Container for the statistics
2236: *
2237: * Populate the draw object user profiling buffer with the timestamps
2238: * recored in the adreno_submit_time structure at the time of draw object
2239: * submission.
2240: */
2241: void adreno_profile_submit_time(struct adreno_submit_time *time);
2242:
2243: void adreno_preemption_timer(struct timer_list *t);
2244:
2245: /**
2246: * adreno_create_profile_buffer - Create a buffer to store profiling data
2247: * @adreno_dev: Adreno GPU device handle
2248: */
2249: void adreno_create_profile_buffer(struct adreno_device *adreno_dev);
2250:
2251: /**
2252: * adreno_isidle - return true if the hardware is idle
2253: * @adreno_dev: Adreno GPU device handle
2254: *
2255: * Return: True if the hardware is idle
2256: */
2257: bool adreno_isidle(struct adreno_device *adreno_dev);
2258:
2259: /**
2260: * adreno_allocate_global - Helper function to allocate a global GPU object
2261: * @device: A GPU device handle
2262: * @memdesc: Pointer to a &struct kgsl_memdesc pointer
2263: * @size: Size of the allocation in bytes
2264: * @padding: Amount of extra adding to add to the VA allocation
2265: * @flags: Control flags for the allocation
2266: * @priv: Internal flags for the allocation
2267: * @name: Name of the allocation (for the debugfs file)
2268: *
2269: * Allocate a global object if it hasn't already been alllocated and put it in
2270: * the pointer pointed to by @memdesc.
2271: * Return: 0 on success or negative on error
2272: */
2273: static inline int adreno_allocate_global(struct kgsl_device *device,
2274: struct kgsl_memdesc **memdesc, u64 size, u32 padding, u64 flags,
2275: u32 priv, const char *name)
2276: {
2277: if (!IS_ERR_OR_NULL(*memdesc))
2278: return 0;
2279:
2280: *memdesc = kgsl_allocate_global(device, size, padding, flags, priv, name);
2281: return PTR_ERR_OR_ZERO(*memdesc);
2282: }
2283:
2284: static inline void adreno_set_dispatch_ops(struct adreno_device *adreno_dev,
2285: const struct adreno_dispatch_ops *ops)
2286: {
2287: adreno_dev->dispatch_ops = ops;
2288: }
2289:
2290: #ifdef CONFIG_QCOM_KGSL_FENCE_TRACE
2291: /**
2292: * adreno_fence_trace_array_init - Initialize an always on trace array
2293: * @device: A GPU device handle
2294: *
2295: * Register an always-on trace array to for fence timeout debugging
2296: */
2297: void adreno_fence_trace_array_init(struct kgsl_device *device);
2298: #else
2299: static inline void adreno_fence_trace_array_init(struct kgsl_device *device) {}
2300: #endif
2301:
2302: /*
2303: * adreno_drawobj_set_constraint - Set a power constraint
2304: * @device: Pointer to a KGSL device structure
2305: * @drawobj: Draw object for which constraint is to be set
2306: *
2307: * Set the power constraint if requested by this context
2308: */
2309: void adreno_drawobj_set_constraint(struct kgsl_device *device,
2310: struct kgsl_drawobj *drawobj);
2311:
2312: /**
2313: * adreno_get_gpu_model - Gets gpu model name from device tree (or) chipid
2314: * @device: A GPU device handle
2315: *
2316: * Return: GPU model name string
2317: */
2318: const char *adreno_get_gpu_model(struct kgsl_device *device);
2319:
2320: int adreno_verify_cmdobj(struct kgsl_device_private *dev_priv,
2321: struct kgsl_context *context, struct kgsl_drawobj *drawobj[],
2322: uint32_t count);
2323:
2324: /**
2325: * adreno_smmu_is_stalled() - Check whether smmu is stalled or not
2326: * @device: Pointer to adreno device
2327: *
2328: * Return - True if smmu is stalled or false otherwise
2329: */
2330: bool adreno_smmu_is_stalled(struct adreno_device *adreno_dev);
2331:
2332: /**
2333: * adreno_get_ahb_timeout_val() - Get the ahb_timeout value
2334: * @adreno_dev: Adreno device handle
2335: * @noc_timeout_us: GPU config NOC timeout value in usec
2336: *
2337: * Return - AHB timeout value to be programmed in AHB CNTL registers
2338: */
--- LINES 2372-2409 ---
2372: * zero
2373: * @device: A handle to kgsl device
2374: * @wait_jiffies: jiffies to wait for active count to become zero
2375: *
2376: * Return: 0 on success or negative error on failure
2377: */
2378: int adreno_drain(struct kgsl_device *device, unsigned long wait_jiffies);
2379:
2380: /**
2381: * adreno_irq_free - Free an interrupt allocated for GPU
2382: * @adreno_dev: Adreno device handle
2383: */
2384: static inline void adreno_irq_free(struct adreno_device *adreno_dev)
2385: {
2386: struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
2387:
2388: if (!(adreno_dev->irq_mask || device->pwrctrl.interrupt_num))
2389: return;
2390:
2391: devm_free_irq(&device->pdev->dev, device->pwrctrl.interrupt_num, device);
2392: adreno_dev->irq_mask = 0;
2393: device->pwrctrl.interrupt_num = 0;
2394: }
2395:
2396: /**
2397: * adreno_gpudev_reset - Adreno gpu device reset
2398: * @adreno_dev: Adreno device handle
2399: */
2400: static inline int adreno_gpudev_reset(struct adreno_device *adreno_dev)
2401: {
2402: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
2403: int ret = -ENODEV;
2404:
2405: if (gpudev->reset) {
2406: set_bit(ADRENO_DEVICE_RESET_RECOVERY, &adreno_dev->priv);
2407: ret = gpudev->reset(adreno_dev);
2408: clear_bit(ADRENO_DEVICE_RESET_RECOVERY, &adreno_dev->priv);
2409: }
========== FILE: adreno-gpulist.h ==========
--- LINES 128-181 ---
128: /* VBIF control registers for a530, a510, a508, a505 and a506 */
129: static const struct kgsl_regmap_list a530_vbif_regs[] = {
130: {A5XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x00000003},
131: };
132:
133: static const struct adreno_a5xx_core adreno_gpu_core_a530v2 = {
134: .base = {
135: DEFINE_ADRENO_REV(ADRENO_REV_A530, 5, 3, 0, 1),
136: .features = ADRENO_SPTP_PC | ADRENO_LM |
137: ADRENO_PREEMPTION |
138: ADRENO_CONTENT_PROTECTION,
139: .gpudev = &adreno_a5xx_gpudev,
140: .perfcounters = &adreno_a5xx_perfcounters,
141: .uche_gmem_alignment = SZ_1M,
142: .gmem_size = SZ_1M,
143: .bus_width = 32,
144: .snapshot_size = SZ_1M,
145: .highest_bank_bit = 15,
146: },
147: .gpmu_tsens = 0x00060007,
148: .max_power = 5448,
149: .pm4fw_name = "a530_pm4.fw",
150: .pfpfw_name = "a530_pfp.fw",
151: .gpmufw_name = "a530_gpmu.fw2",
152: .regfw_name = "a530v2_seq.fw2",
153: .zap_name = "a530_zap.mdt",
154: .hwcg = a530_hwcg_regs,
155: .hwcg_count = ARRAY_SIZE(a530_hwcg_regs),
156: .vbif = a530_vbif_regs,
157: .vbif_count = ARRAY_SIZE(a530_vbif_regs),
158: };
159:
160: static const struct adreno_a5xx_core adreno_gpu_core_a530v3 = {
161: .base = {
162: DEFINE_ADRENO_REV(ADRENO_REV_A530, 5, 3, 0, ANY_ID),
163: .features = ADRENO_SPTP_PC | ADRENO_LM |
164: ADRENO_PREEMPTION |
165: ADRENO_CONTENT_PROTECTION,
166: .gpudev = &adreno_a5xx_gpudev,
167: .perfcounters = &adreno_a5xx_perfcounters,
168: .uche_gmem_alignment = SZ_1M,
169: .gmem_size = SZ_1M,
170: .bus_width = 32,
171: .snapshot_size = SZ_1M,
172: .highest_bank_bit = 15,
173: },
174: .gpmu_tsens = 0x00060007,
175: .max_power = 5448,
176: .pm4fw_name = "a530_pm4.fw",
177: .pfpfw_name = "a530_pfp.fw",
178: .gpmufw_name = "a530v3_gpmu.fw2",
179: .regfw_name = "a530v3_seq.fw2",
180: .zap_name = "a530_zap.mdt",
181: .hwcg = a530_hwcg_regs,
--- LINES 223-268 ---
223: {A5XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000},
224: {A5XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000},
225: {A5XX_RBBM_CLOCK_DELAY_GPC, 0x00000200},
226: {A5XX_RBBM_CLOCK_DELAY_VFD, 0x00002222}
227: };
228:
229: static const struct adreno_a5xx_core adreno_gpu_core_a505 = {
230: .base = {
231: DEFINE_ADRENO_REV(ADRENO_REV_A505, 5, 0, 5, ANY_ID),
232: .features = ADRENO_PREEMPTION,
233: .gpudev = &adreno_a5xx_gpudev,
234: .perfcounters = &adreno_a5xx_perfcounters,
235: .uche_gmem_alignment = SZ_1M,
236: .gmem_size = (SZ_128K + SZ_8K),
237: .bus_width = 16,
238: .snapshot_size = SZ_1M,
239: },
240: .pm4fw_name = "a530_pm4.fw",
241: .pfpfw_name = "a530_pfp.fw",
242: .hwcg = a50x_hwcg_regs,
243: .hwcg_count = ARRAY_SIZE(a50x_hwcg_regs),
244: .vbif = a530_vbif_regs,
245: .vbif_count = ARRAY_SIZE(a530_vbif_regs),
246: };
247:
248: static const struct adreno_a5xx_core adreno_gpu_core_a506 = {
249: .base = {
250: DEFINE_ADRENO_REV(ADRENO_REV_A506, 5, 0, 6, ANY_ID),
251: .features = ADRENO_PREEMPTION |
252: ADRENO_CONTENT_PROTECTION | ADRENO_CPZ_RETENTION,
253: .gpudev = &adreno_a5xx_gpudev,
254: .perfcounters = &adreno_a5xx_perfcounters,
255: .uche_gmem_alignment = SZ_1M,
256: .gmem_size = (SZ_128K + SZ_8K),
257: .bus_width = 16,
258: .snapshot_size = SZ_1M,
259: .highest_bank_bit = 14,
260: },
261: .pm4fw_name = "a530_pm4.fw",
262: .pfpfw_name = "a530_pfp.fw",
263: .zap_name = "a506_zap.mdt",
264: .hwcg = a50x_hwcg_regs,
265: .hwcg_count = ARRAY_SIZE(a50x_hwcg_regs),
266: .vbif = a530_vbif_regs,
267: .vbif_count = ARRAY_SIZE(a530_vbif_regs),
268: };
--- LINES 446-472 ---
446:
447: static const struct kgsl_regmap_list a540_vbif_regs[] = {
448: {A5XX_VBIF_ROUND_ROBIN_QOS_ARB, 0x00000003},
449: {A5XX_VBIF_GATE_OFF_WRREQ_EN, 0x00000009},
450: };
451:
452: static const struct adreno_a5xx_core adreno_gpu_core_a540v2 = {
453: .base = {
454: DEFINE_ADRENO_REV(ADRENO_REV_A540, 5, 4, 0, ANY_ID),
455: .features = ADRENO_PREEMPTION |
456: ADRENO_CONTENT_PROTECTION |
457: ADRENO_SPTP_PC,
458: .gpudev = &adreno_a5xx_gpudev,
459: .perfcounters = &adreno_a5xx_perfcounters,
460: .uche_gmem_alignment = SZ_1M,
461: .gmem_size = SZ_1M,
462: .bus_width = 32,
463: .snapshot_size = SZ_1M,
464: .highest_bank_bit = 15,
465: },
466: .gpmu_tsens = 0x000c000d,
467: .max_power = 5448,
468: .pm4fw_name = "a530_pm4.fw",
469: .pfpfw_name = "a530_pfp.fw",
470: .gpmufw_name = "a540_gpmu.fw2",
471: .zap_name = "a540_zap.mdt",
472: .hwcg = a540_hwcg_regs,
--- LINES 531-577 ---
531: {A5XX_RBBM_CLOCK_DELAY_HLSQ, 0x00000000},
532: {A5XX_RBBM_CLOCK_DELAY_TSE_RAS_RBBM, 0x00004000},
533: {A5XX_RBBM_CLOCK_DELAY_GPC, 0x00000200},
534: {A5XX_RBBM_CLOCK_DELAY_VFD, 0x00002222},
535: };
536:
537: static const struct adreno_a5xx_core adreno_gpu_core_a512 = {
538: .base = {
539: DEFINE_ADRENO_REV(ADRENO_REV_A512, 5, 1, 2, ANY_ID),
540: .features = ADRENO_PREEMPTION |
541: ADRENO_CONTENT_PROTECTION | ADRENO_CPZ_RETENTION,
542: .gpudev = &adreno_a5xx_gpudev,
543: .perfcounters = &adreno_a5xx_perfcounters,
544: .uche_gmem_alignment = SZ_1M,
545: .gmem_size = (SZ_256K + SZ_16K),
546: .bus_width = 32,
547: .snapshot_size = SZ_1M,
548: .highest_bank_bit = 14,
549: },
550: .pm4fw_name = "a530_pm4.fw",
551: .pfpfw_name = "a530_pfp.fw",
552: .zap_name = "a512_zap.mdt",
553: .hwcg = a512_hwcg_regs,
554: .hwcg_count = ARRAY_SIZE(a512_hwcg_regs),
555: };
556:
557: static const struct adreno_a5xx_core adreno_gpu_core_a508 = {
558: .base = {
559: DEFINE_ADRENO_REV(ADRENO_REV_A508, 5, 0, 8, ANY_ID),
560: .features = ADRENO_PREEMPTION |
561: ADRENO_CONTENT_PROTECTION | ADRENO_CPZ_RETENTION,
562: .gpudev = &adreno_a5xx_gpudev,
563: .perfcounters = &adreno_a5xx_perfcounters,
564: .uche_gmem_alignment = SZ_1M,
565: .gmem_size = (SZ_128K + SZ_8K),
566: .bus_width = 32,
567: .snapshot_size = SZ_1M,
568: .highest_bank_bit = 14,
569: },
570: .pm4fw_name = "a530_pm4.fw",
571: .pfpfw_name = "a530_pfp.fw",
572: .zap_name = "a508_zap.mdt",
573: .hwcg = a50x_hwcg_regs,
574: .hwcg_count = ARRAY_SIZE(a50x_hwcg_regs),
575: .vbif = a530_vbif_regs,
576: .vbif_count = ARRAY_SIZE(a530_vbif_regs),
577: };
--- LINES 727-753 ---
727: { A6XX_CP_PROTECT_REG + 30, 0x0fc00, 0x11bff, 0 },
728: { A6XX_CP_PROTECT_REG + 31, 0x11c00, 0x11c00, 1 },
729: { 0 },
730: };
731:
732: static const struct adreno_a6xx_core adreno_gpu_core_a630v2 = {
733: .base = {
734: DEFINE_ADRENO_REV(ADRENO_REV_A630, 6, 3, 0, ANY_ID),
735: .features = ADRENO_IFPC | ADRENO_CONTENT_PROTECTION |
736: ADRENO_IOCOHERENT | ADRENO_PREEMPTION,
737: .gpudev = &adreno_a630_gpudev.base,
738: .perfcounters = &adreno_a630_perfcounters,
739: .uche_gmem_alignment = SZ_1M,
740: .gmem_size = SZ_1M,
741: .bus_width = 32,
742: .snapshot_size = SZ_1M,
743: .highest_bank_bit = 15,
744: },
745: .prim_fifo_threshold = 0x0018000,
746: .gmu_major = 1,
747: .gmu_minor = 3,
748: .sqefw_name = "a630_sqe.fw",
749: .gmufw_name = "a630_gmu.bin",
750: .zap_name = "a630_zap.mdt",
751: .hwcg = a630_hwcg_regs,
752: .hwcg_count = ARRAY_SIZE(a630_hwcg_regs),
753: .vbif = a630_vbif_regs,
--- LINES 825-936 ---
825:
826: /* For a615, a616, a618 and a619 */
827: static const struct kgsl_regmap_list a615_gbif_regs[] = {
828: {A6XX_RBBM_VBIF_CLIENT_QOS_CNTL, 0x3},
829: };
830:
831: static const struct adreno_a6xx_core adreno_gpu_core_a615 = {
832: .base = {
833: DEFINE_ADRENO_REV(ADRENO_REV_A615, 6, 1, 5, ANY_ID),
834: .features = ADRENO_PREEMPTION |
835: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC |
836: ADRENO_IOCOHERENT,
837: .gpudev = &adreno_a630_gpudev.base,
838: .perfcounters = &adreno_a6xx_legacy_perfcounters,
839: .uche_gmem_alignment = SZ_1M,
840: .gmem_size = SZ_512K,
841: .bus_width = 32,
842: .snapshot_size = SZ_1M,
843: .highest_bank_bit = 14,
844: },
845: .prim_fifo_threshold = 0x0018000,
846: .gmu_major = 1,
847: .gmu_minor = 3,
848: .sqefw_name = "a630_sqe.fw",
849: .gmufw_name = "a630_gmu.bin",
850: .zap_name = "a615_zap.mdt",
851: .hwcg = a615_hwcg_regs,
852: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs),
853: .vbif = a615_gbif_regs,
854: .vbif_count = ARRAY_SIZE(a615_gbif_regs),
855: .hang_detect_cycles = 0xcfffff,
856: .protected_regs = a630_protected_regs,
857: };
858:
859: static const struct adreno_a6xx_core adreno_gpu_core_a618 = {
860: .base = {
861: DEFINE_ADRENO_REV(ADRENO_REV_A618, 6, 1, 8, ANY_ID),
862: .features = ADRENO_PREEMPTION |
863: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC |
864: ADRENO_IOCOHERENT,
865: .gpudev = &adreno_a630_gpudev.base,
866: .perfcounters = &adreno_a6xx_legacy_perfcounters,
867: .uche_gmem_alignment = SZ_1M,
868: .gmem_size = SZ_512K,
869: .bus_width = 32,
870: .snapshot_size = SZ_1M,
871: .highest_bank_bit = 14,
872: },
873: .prim_fifo_threshold = 0x0018000,
874: .gmu_major = 1,
875: .gmu_minor = 7,
876: .sqefw_name = "a630_sqe.fw",
877: .gmufw_name = "a630_gmu.bin",
878: .zap_name = "a615_zap.mdt",
879: .hwcg = a615_hwcg_regs,
880: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs),
881: .vbif = a615_gbif_regs,
882: .vbif_count = ARRAY_SIZE(a615_gbif_regs),
883: .hang_detect_cycles = 0x3fffff,
884: .protected_regs = a630_protected_regs,
885: };
886:
887: static const struct adreno_a6xx_core adreno_gpu_core_a619 = {
888: .base = {
889: DEFINE_ADRENO_REV(ADRENO_REV_A619, 6, 1, 9, ANY_ID),
890: .features = ADRENO_PREEMPTION |
891: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC |
892: ADRENO_IOCOHERENT,
893: .gpudev = &adreno_a630_gpudev.base,
894: .perfcounters = &adreno_a6xx_legacy_perfcounters,
895: .uche_gmem_alignment = SZ_1M,
896: .gmem_size = SZ_512K,
897: .bus_width = 32,
898: .snapshot_size = SZ_2M,
899: .highest_bank_bit = 14,
900: },
901: .prim_fifo_threshold = 0x0018000,
902: .gmu_major = 1,
903: .gmu_minor = 9,
904: .sqefw_name = "a630_sqe.fw",
905: .gmufw_name = "a619_gmu.bin",
906: .zap_name = "a615_zap.mdt",
907: .hwcg = a615_hwcg_regs,
908: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs),
909: .vbif = a615_gbif_regs,
910: .vbif_count = ARRAY_SIZE(a615_gbif_regs),
911: .hang_detect_cycles = 0x3fffff,
912: .protected_regs = a630_protected_regs,
913: };
914:
915: static const struct adreno_a6xx_core adreno_gpu_core_a619_variant = {
916: .base = {
917: DEFINE_ADRENO_REV(ADRENO_REV_A619, 6, 1, 9, ANY_ID),
918: .compatible = "qcom,adreno-gpu-a619-holi",
919: .features = ADRENO_PREEMPTION | ADRENO_CONTENT_PROTECTION,
920: .gpudev = &adreno_a619_holi_gpudev,
921: .perfcounters = &adreno_a6xx_legacy_perfcounters,
922: .uche_gmem_alignment = SZ_1M,
923: .gmem_size = SZ_512K,
924: .bus_width = 32,
925: .snapshot_size = SZ_2M,
926: .highest_bank_bit = 14,
927: },
928: .prim_fifo_threshold = 0x0018000,
929: .sqefw_name = "a630_sqe.fw",
930: .zap_name = "gen6_3_25_0_zap.mdt",
931: .hwcg = a615_hwcg_regs,
932: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs),
933: .vbif = a615_gbif_regs,
934: .vbif_count = ARRAY_SIZE(a615_gbif_regs),
935: .hang_detect_cycles = 0x3fffff,
936: .protected_regs = a630_protected_regs,
--- LINES 1041-1067 ---
1041: { A6XX_CP_PROTECT_REG + 38, 0x1f887, 0x1f8a2, 1 },
1042: { A6XX_CP_PROTECT_REG + 47, 0x1f8c0, 0x1f8c0, 1 },
1043: { 0 },
1044: };
1045:
1046: static const struct adreno_a6xx_core adreno_gpu_core_a620 = {
1047: .base = {
1048: DEFINE_ADRENO_REV(ADRENO_REV_A620, 6, 2, 0, ANY_ID),
1049: .features = ADRENO_CONTENT_PROTECTION | ADRENO_IOCOHERENT |
1050: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_ACD |
1051: ADRENO_APRIV,
1052: .gpudev = &adreno_a630_gpudev.base,
1053: .perfcounters = &adreno_a6xx_perfcounters,
1054: .uche_gmem_alignment = 0,
1055: .gmem_size = SZ_512K,
1056: .bus_width = 32,
1057: .snapshot_size = 2 * SZ_1M,
1058: .highest_bank_bit = 14,
1059: },
1060: .prim_fifo_threshold = 0x0010000,
1061: .gmu_major = 2,
1062: .gmu_minor = 0,
1063: .sqefw_name = "a650_sqe.fw",
1064: .gmufw_name = "a650_gmu.bin",
1065: .zap_name = "a620_zap.mdt",
1066: .hwcg = a620_hwcg_regs,
1067: .hwcg_count = ARRAY_SIZE(a620_hwcg_regs),
--- LINES 1072-1098 ---
1072: .protected_regs = a620_protected_regs,
1073: .disable_tseskip = true,
1074: };
1075:
1076: static const struct adreno_a6xx_core adreno_gpu_core_a621 = {
1077: .base = {
1078: DEFINE_ADRENO_REV(ADRENO_REV_A621, 6, 2, 1, ANY_ID),
1079: .compatible = "qcom,adreno-gpu-a621",
1080: .features = ADRENO_CONTENT_PROTECTION | ADRENO_IOCOHERENT |
1081: ADRENO_APRIV | ADRENO_LSR | ADRENO_PREEMPTION |
1082: ADRENO_IFPC | ADRENO_ACD | ADRENO_BCL,
1083: .gpudev = &adreno_a6xx_hwsched_gpudev.base,
1084: .perfcounters = &adreno_a6xx_perfcounters,
1085: .uche_gmem_alignment = 0,
1086: .gmem_size = SZ_512K,
1087: .bus_width = 32,
1088: .snapshot_size = 2 * SZ_1M,
1089: .highest_bank_bit = 13,
1090: },
1091: .prim_fifo_threshold = 0x0010000,
1092: .gmu_major = 2,
1093: .gmu_minor = 0,
1094: .sqefw_name = "a650_sqe.fw",
1095: .gmufw_name = "a621_gmu.bin",
1096: .zap_name = "a620_zap.mdt",
1097: .hwcg = a620_hwcg_regs,
1098: .hwcg_count = ARRAY_SIZE(a620_hwcg_regs),
--- LINES 1105-1131 ---
1105: .disable_tseskip = true,
1106: .gmu_hub_clk_freq = 200000000,
1107: };
1108:
1109: static const struct adreno_a6xx_core adreno_gpu_core_a622 = {
1110: .base = {
1111: DEFINE_ADRENO_REV(ADRENO_REV_A622, 6, 2, 2, ANY_ID),
1112: .compatible = "qcom,adreno-gpu-a622",
1113: .features = ADRENO_CONTENT_PROTECTION | ADRENO_IOCOHERENT |
1114: ADRENO_APRIV | ADRENO_PREEMPTION | ADRENO_BCL |
1115: ADRENO_IFPC,
1116: .gpudev = &adreno_a6xx_hwsched_gpudev.base,
1117: .perfcounters = &adreno_a6xx_perfcounters,
1118: .uche_gmem_alignment = 0,
1119: .gmem_size = SZ_512K,
1120: .bus_width = 32,
1121: .snapshot_size = 2 * SZ_1M,
1122: .highest_bank_bit = 14,
1123: },
1124: .prim_fifo_threshold = 0x0010000,
1125: .gmu_major = 2,
1126: .gmu_minor = 0,
1127: .sqefw_name = "a650_sqe.fw",
1128: .gmufw_name = "a622_gmu.bin",
1129: .zap_name = "a622_zap.mdt",
1130: .hwcg = a620_hwcg_regs,
1131: .hwcg_count = ARRAY_SIZE(a620_hwcg_regs),
--- LINES 1250-1276 ---
1250: {A6XX_GBIF_QSB_SIDE2, 0x00071620},
1251: {A6XX_GBIF_QSB_SIDE3, 0x00071620},
1252: {A6XX_RBBM_GBIF_CLIENT_QOS_CNTL, 0x3},
1253: };
1254:
1255: static const struct adreno_a6xx_core adreno_gpu_core_a640 = {
1256: .base = {
1257: DEFINE_ADRENO_REV(ADRENO_REV_A640, 6, 4, 0, ANY_ID),
1258: .features = ADRENO_CONTENT_PROTECTION | ADRENO_IOCOHERENT |
1259: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_L3_VOTE,
1260: .gpudev = &adreno_a6xx_gmu_gpudev.base,
1261: .perfcounters = &adreno_a6xx_legacy_perfcounters,
1262: .uche_gmem_alignment = SZ_1M,
1263: .gmem_size = SZ_1M, //Verified 1MB
1264: .bus_width = 32,
1265: .snapshot_size = 2 * SZ_1M,
1266: .highest_bank_bit = 15,
1267: },
1268: .prim_fifo_threshold = 0x00200000,
1269: .gmu_major = 2,
1270: .gmu_minor = 0,
1271: .sqefw_name = "a630_sqe.fw",
1272: .gmufw_name = "a640_gmu.bin",
1273: .zap_name = "a640_zap.mdt",
1274: .hwcg = a640_hwcg_regs,
1275: .hwcg_count = ARRAY_SIZE(a640_hwcg_regs),
1276: .vbif = a640_vbif_regs,
--- LINES 1360-1386 ---
1360: .hang_detect_cycles = 0xcfffff,
1361: .protected_regs = a620_protected_regs,
1362: .disable_tseskip = true,
1363: };
1364:
1365: static const struct adreno_a6xx_core adreno_gpu_core_a650v2 = {
1366: .base = {
1367: DEFINE_ADRENO_REV(ADRENO_REV_A650, 6, 5, 0, ANY_ID),
1368: .features = ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION |
1369: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_ACD |
1370: ADRENO_LM | ADRENO_APRIV | ADRENO_L3_VOTE,
1371: .gpudev = &adreno_a6xx_gmu_gpudev.base,
1372: .perfcounters = &adreno_a6xx_perfcounters,
1373: .uche_gmem_alignment = 0,
1374: .gmem_size = SZ_1M + SZ_128K, /* verified 1152kB */
1375: .bus_width = 32,
1376: .snapshot_size = 2 * SZ_1M,
1377: .highest_bank_bit = 16,
1378: },
1379: .prim_fifo_threshold = 0x00300000,
1380: .gmu_major = 2,
1381: .gmu_minor = 0,
1382: .sqefw_name = "a650_sqe.fw",
1383: .gmufw_name = "a650_gmu.bin",
1384: .zap_name = "a650_zap.mdt",
1385: .hwcg = a650_hwcg_regs,
1386: .hwcg_count = ARRAY_SIZE(a650_hwcg_regs),
--- LINES 1391-1417 ---
1391: .hang_detect_cycles = 0x3ffff,
1392: .protected_regs = a620_protected_regs,
1393: .disable_tseskip = true,
1394: };
1395:
1396: static const struct adreno_a6xx_core adreno_gpu_core_a680 = {
1397: .base = {
1398: DEFINE_ADRENO_REV(ADRENO_REV_A680, 6, 8, 0, ANY_ID),
1399: .features = ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION |
1400: ADRENO_IFPC | ADRENO_PREEMPTION,
1401: .gpudev = &adreno_a6xx_gmu_gpudev.base,
1402: .perfcounters = &adreno_a6xx_legacy_perfcounters,
1403: .uche_gmem_alignment = SZ_1M,
1404: .gmem_size = SZ_2M,
1405: .bus_width = 32,
1406: .snapshot_size = SZ_2M,
1407: .highest_bank_bit = 16,
1408: },
1409: .prim_fifo_threshold = 0x00400000,
1410: .gmu_major = 2,
1411: .gmu_minor = 0,
1412: .sqefw_name = "a630_sqe.fw",
1413: .gmufw_name = "a640_gmu.bin",
1414: .zap_name = "a640_zap.mdt",
1415: .hwcg = a680_hwcg_regs,
1416: .hwcg_count = ARRAY_SIZE(a680_hwcg_regs),
1417: .vbif = a640_vbif_regs,
--- LINES 1468-1575 ---
1468: {A6XX_RBBM_CLOCK_CNTL_GMU_GX, 0x00000222},
1469: {A6XX_RBBM_CLOCK_DELAY_GMU_GX, 0x00000111},
1470: {A6XX_RBBM_CLOCK_HYST_GMU_GX, 0x00000555},
1471: };
1472:
1473: static const struct adreno_a6xx_core adreno_gpu_core_a612 = {
1474: .base = {
1475: DEFINE_ADRENO_REV(ADRENO_REV_A612, 6, 1, 2, ANY_ID),
1476: .features = ADRENO_CONTENT_PROTECTION |
1477: ADRENO_IOCOHERENT | ADRENO_PREEMPTION | ADRENO_IFPC,
1478: .gpudev = &adreno_a6xx_rgmu_gpudev,
1479: .perfcounters = &adreno_a6xx_legacy_perfcounters,
1480: .uche_gmem_alignment = SZ_1M,
1481: .gmem_size = (SZ_128K + SZ_4K),
1482: .bus_width = 32,
1483: .snapshot_size = SZ_1M,
1484: .chipid = 0x06010200,
1485: .ubwc_mode = 2,
1486: .mal = 32,
1487: .highest_bank_bit = 14,
1488: },
1489: .prim_fifo_threshold = 0x00080000,
1490: .sqefw_name = "a630_sqe.fw",
1491: .gmufw_name = "a612_rgmu.bin",
1492: .zap_name = "a612_zap.mbn",
1493: .hwcg = a612_hwcg_regs,
1494: .hwcg_count = ARRAY_SIZE(a612_hwcg_regs),
1495: .vbif = a640_vbif_regs,
1496: .vbif_count = ARRAY_SIZE(a640_vbif_regs),
1497: .hang_detect_cycles = 0x3fffff,
1498: .protected_regs = a630_protected_regs,
1499: };
1500:
1501: static const struct adreno_a6xx_core adreno_gpu_core_a616 = {
1502: .base = {
1503: DEFINE_ADRENO_REV(ADRENO_REV_A616, 6, 1, 6, ANY_ID),
1504: .features = ADRENO_PREEMPTION |
1505: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC |
1506: ADRENO_IOCOHERENT,
1507: .gpudev = &adreno_a630_gpudev.base,
1508: .perfcounters = &adreno_a6xx_legacy_perfcounters,
1509: .uche_gmem_alignment = SZ_1M,
1510: .gmem_size = SZ_512K,
1511: .bus_width = 32,
1512: .snapshot_size = SZ_1M,
1513: .highest_bank_bit = 14,
1514: },
1515: .prim_fifo_threshold = 0x0018000,
1516: .gmu_major = 1,
1517: .gmu_minor = 3,
1518: .sqefw_name = "a630_sqe.fw",
1519: .gmufw_name = "a630_gmu.bin",
1520: .zap_name = "a615_zap.mdt",
1521: .hwcg = a615_hwcg_regs,
1522: .hwcg_count = ARRAY_SIZE(a615_hwcg_regs),
1523: .vbif = a615_gbif_regs,
1524: .vbif_count = ARRAY_SIZE(a615_gbif_regs),
1525: .hang_detect_cycles = 0xcfffff,
1526: .protected_regs = a630_protected_regs,
1527: };
1528:
1529: static const struct adreno_a6xx_core adreno_gpu_core_a610 = {
1530: .base = {
1531: DEFINE_ADRENO_REV(ADRENO_REV_A610, 6, 1, 0, ANY_ID),
1532: .features = ADRENO_CONTENT_PROTECTION |
1533: ADRENO_PREEMPTION,
1534: .gpudev = &adreno_a6xx_gpudev,
1535: .perfcounters = &adreno_a6xx_legacy_perfcounters,
1536: .uche_gmem_alignment = SZ_1M,
1537: .gmem_size = (SZ_128K + SZ_4K),
1538: .bus_width = 32,
1539: .snapshot_size = SZ_1M,
1540: .highest_bank_bit = 14,
1541: },
1542: .prim_fifo_threshold = 0x00080000,
1543: .sqefw_name = "a630_sqe.fw",
1544: .zap_name = "a610_zap.mdt",
1545: .hwcg = a612_hwcg_regs,
1546: .hwcg_count = ARRAY_SIZE(a612_hwcg_regs),
1547: .vbif = a640_vbif_regs,
1548: .vbif_count = ARRAY_SIZE(a640_vbif_regs),
1549: .hang_detect_cycles = 0x3ffff,
1550: .protected_regs = a630_protected_regs,
1551: };
1552:
1553: static const struct adreno_a6xx_core adreno_gpu_core_a611 = {
1554: .base = {
1555: DEFINE_ADRENO_REV(ADRENO_REV_A611, 6, 1, 1, ANY_ID),
1556: .compatible = "qcom,adreno-gpu-a611",
1557: .features = ADRENO_CONTENT_PROTECTION |
1558: ADRENO_PREEMPTION,
1559: .gpudev = &adreno_a6xx_gpudev,
1560: .perfcounters = &adreno_a6xx_legacy_perfcounters,
1561: .uche_gmem_alignment = SZ_1M,
1562: .gmem_size = (SZ_128K + SZ_4K),
1563: .bus_width = 32,
1564: .snapshot_size = SZ_1M,
1565: .highest_bank_bit = 14,
1566: },
1567: .prim_fifo_threshold = 0x00080000,
1568: .sqefw_name = "a630_sqe.fw",
1569: .zap_name = "a610_zap.mbn",
1570: .hwcg = a612_hwcg_regs,
1571: .hwcg_count = ARRAY_SIZE(a612_hwcg_regs),
1572: .vbif = a640_vbif_regs,
1573: .vbif_count = ARRAY_SIZE(a640_vbif_regs),
1574: .hang_detect_cycles = 0x3ffff,
1575: .protected_regs = a630_protected_regs,
--- LINES 1673-1699 ---
1673: { A6XX_CP_PROTECT_REG + 47, 0x1f8c0, 0x1f8c0, 1 },
1674: { 0 },
1675: };
1676:
1677: static const struct adreno_a6xx_core adreno_gpu_core_a660 = {
1678: .base = {
1679: DEFINE_ADRENO_REV(ADRENO_REV_A660, 6, 6, 0, 0),
1680: .features = ADRENO_APRIV |
1681: ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION |
1682: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_L3_VOTE,
1683: .gpudev = &adreno_a6xx_gmu_gpudev.base,
1684: .perfcounters = &adreno_a6xx_perfcounters,
1685: .uche_gmem_alignment = 0,
1686: .gmem_size = SZ_1M + SZ_512K,
1687: .bus_width = 32,
1688: .snapshot_size = SZ_2M,
1689: .highest_bank_bit = 16,
1690: },
1691: .prim_fifo_threshold = 0x00300000,
1692: .gmu_major = 2,
1693: .gmu_minor = 0,
1694: .sqefw_name = "a660_sqe.fw",
1695: .gmufw_name = "a660_gmu.bin",
1696: .zap_name = "a660_zap.mdt",
1697: .hwcg = a660_hwcg_regs,
1698: .hwcg_count = ARRAY_SIZE(a660_hwcg_regs),
1699: .vbif = a650_gbif_regs,
--- LINES 1705-1731 ---
1705: .pdc_in_aop = true,
1706: .ctxt_record_size = 2496 * 1024,
1707: };
1708:
1709: static const struct adreno_a6xx_core adreno_gpu_core_a660v2 = {
1710: .base = {
1711: DEFINE_ADRENO_REV(ADRENO_REV_A660, 6, 6, 0, ANY_ID),
1712: .features = ADRENO_APRIV |
1713: ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION |
1714: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_ACD |
1715: ADRENO_L3_VOTE,
1716: .gpudev = &adreno_a6xx_gmu_gpudev.base,
1717: .perfcounters = &adreno_a6xx_perfcounters,
1718: .uche_gmem_alignment = 0,
1719: .gmem_size = SZ_1M + SZ_512K,
1720: .bus_width = 32,
1721: .snapshot_size = SZ_2M,
1722: .highest_bank_bit = 16,
1723: },
1724: .prim_fifo_threshold = 0x00300000,
1725: .gmu_major = 2,
1726: .gmu_minor = 0,
1727: .sqefw_name = "a660_sqe.fw",
1728: .gmufw_name = "a660_gmu.bin",
1729: .zap_name = "a660_zap.mdt",
1730: .hwcg = a660_hwcg_regs,
1731: .hwcg_count = ARRAY_SIZE(a660_hwcg_regs),
--- LINES 1739-1765 ---
1739: .ctxt_record_size = 2496 * 1024,
1740: };
1741:
1742: static const struct adreno_a6xx_core adreno_gpu_core_a660_shima = {
1743: .base = {
1744: DEFINE_ADRENO_REV(ADRENO_REV_A660, 6, 6, 0, ANY_ID),
1745: .compatible = "qcom,adreno-gpu-a660-shima",
1746: .features = ADRENO_APRIV |
1747: ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION |
1748: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_ACD,
1749: .gpudev = &adreno_a6xx_gmu_gpudev.base,
1750: .perfcounters = &adreno_a6xx_perfcounters,
1751: .uche_gmem_alignment = 0,
1752: .gmem_size = SZ_1M + SZ_512K,
1753: .bus_width = 32,
1754: .snapshot_size = SZ_2M,
1755: .highest_bank_bit = 15,
1756: },
1757: .prim_fifo_threshold = 0x00300000,
1758: .gmu_major = 2,
1759: .gmu_minor = 0,
1760: .sqefw_name = "a660_sqe.fw",
1761: .gmufw_name = "a660_gmu.bin",
1762: .zap_name = "a660_zap.mdt",
1763: .hwcg = a660_hwcg_regs,
1764: .hwcg_count = ARRAY_SIZE(a660_hwcg_regs),
1765: .vbif = a650_gbif_regs,
--- LINES 1804-1830 ---
1804: .ctxt_record_size = 2496 * 1024,
1805: };
1806:
1807: static const struct adreno_a6xx_core adreno_gpu_core_a643 = {
1808: .base = {
1809: DEFINE_ADRENO_REV(ADRENO_REV_A643, ANY_ID, ANY_ID, ANY_ID, ANY_ID),
1810: .compatible = "qcom,adreno-gpu-a643",
1811: .features = ADRENO_APRIV |
1812: ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION |
1813: ADRENO_PREEMPTION | ADRENO_IFPC,
1814: .gpudev = &adreno_a6xx_gmu_gpudev.base,
1815: .perfcounters = &adreno_a6xx_perfcounters,
1816: .uche_gmem_alignment = 0,
1817: .gmem_size = SZ_512K,
1818: .bus_width = 32,
1819: .snapshot_size = SZ_2M,
1820: .chipid = 0x06030500,
1821: .speedbins = KGSL_SPEEDBINS(
1822: { 0, 0 },
1823: { 117, 0 },
1824: { 129, 4 },
1825: { 172, 2 },
1826: { 190, 1 },
1827: ),
1828: .ubwc_mode = 3,
1829: .mal = 32,
1830: .highest_bank_bit = 15,
--- LINES 1846-1872 ---
1846: .pdc_in_aop = true,
1847: .ctxt_record_size = 2496 * 1024,
1848: };
1849:
1850: static const struct adreno_a6xx_core adreno_gpu_core_a662 = {
1851: .base = {
1852: DEFINE_ADRENO_REV(ADRENO_REV_A662, ANY_ID, ANY_ID, ANY_ID, ANY_ID),
1853: .compatible = "qcom,adreno-gpu-a662",
1854: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
1855: ADRENO_CONTENT_PROTECTION | ADRENO_PREEMPTION |
1856: ADRENO_IFPC | ADRENO_BCL | ADRENO_ACD,
1857: .gpudev = &adreno_a6xx_gmu_gpudev.base,
1858: .perfcounters = &adreno_a6xx_perfcounters,
1859: .uche_gmem_alignment = 0,
1860: .gmem_size = SZ_1M + SZ_512K,
1861: .bus_width = 32,
1862: .snapshot_size = SZ_2M,
1863: .highest_bank_bit = 15,
1864: },
1865: .prim_fifo_threshold = 0x00300000,
1866: .gmu_major = 2,
1867: .gmu_minor = 0,
1868: .sqefw_name = "a660_sqe.fw",
1869: .gmufw_name = "a662_gmu.bin",
1870: .zap_name = "a662_zap.mdt",
1871: .hwcg = a660_hwcg_regs,
1872: .hwcg_count = ARRAY_SIZE(a660_hwcg_regs),
--- LINES 1879-1905 ---
1879: .pdc_in_aop = true,
1880: .ctxt_record_size = 2496 * 1024,
1881: };
1882:
1883: static const struct adreno_a6xx_core adreno_gpu_core_gen6_3_26_0 = {
1884: .base = {
1885: DEFINE_ADRENO_REV(ADRENO_REV_GEN6_3_26_0, ANY_ID, ANY_ID, ANY_ID, ANY_ID),
1886: .compatible = "qcom,adreno-gpu-gen6-3-26-0",
1887: .features = ADRENO_CONTENT_PROTECTION | ADRENO_IOCOHERENT |
1888: ADRENO_PREEMPTION,
1889: .gpudev = &adreno_a6xx_gpudev,
1890: .perfcounters = &adreno_a6xx_legacy_perfcounters,
1891: .uche_gmem_alignment = SZ_1M,
1892: .gmem_size = (SZ_128K + SZ_4K),
1893: .bus_width = 32,
1894: .snapshot_size = SZ_2M,
1895: .highest_bank_bit = 15,
1896: },
1897: .prim_fifo_threshold = 0x00080000,
1898: .sqefw_name = "a630_sqe.fw",
1899: .zap_name = "gen6_3_26_0_zap.mdt",
1900: .hwcg = a612_hwcg_regs,
1901: .hwcg_count = ARRAY_SIZE(a612_hwcg_regs),
1902: .vbif = a640_vbif_regs,
1903: .vbif_count = ARRAY_SIZE(a640_vbif_regs),
1904: .hang_detect_cycles = 0x3fffff,
1905: .protected_regs = a630_protected_regs,
--- LINES 1970-1996 ---
1970: {A6XX_RBBM_CLOCK_CNTL_MHUB, 0x00000002},
1971: {A6XX_RBBM_CLOCK_DELAY_MHUB, 0x00000000},
1972: {A6XX_RBBM_CLOCK_HYST_MHUB, 0x00000000},
1973: };
1974:
1975: static const struct adreno_a6xx_core adreno_gpu_core_a702 = {
1976: .base = {
1977: DEFINE_ADRENO_REV(ADRENO_REV_A702, 7, 0, 2, ANY_ID),
1978: .features = ADRENO_CONTENT_PROTECTION |
1979: ADRENO_APRIV | ADRENO_PREEMPTION,
1980: .gpudev = &adreno_a6xx_gpudev,
1981: .perfcounters = &adreno_a6xx_legacy_perfcounters,
1982: .gmem_size = SZ_128K,
1983: .bus_width = 16,
1984: .snapshot_size = SZ_1M,
1985: .highest_bank_bit = 14,
1986: .chipid = 0x07000200,
1987: .speedbins = KGSL_SPEEDBINS(
1988: { 0, 0 },
1989: { 236, 1 },
1990: { 178, 2 },
1991: { 142, 3 },
1992: ),
1993: .ubwc_mode = 1,
1994: .mal = 64,
1995: },
1996: .prim_fifo_threshold = 0x0000c000,
--- LINES 2008-2034 ---
2008: static const struct kgsl_regmap_list a704_smmu_aperture_regs[] = {
2009: { 0x0, 0x000a8000 }, /* GC: CB0 */
2010: { 0x2, 0x00000000 }, /* CTRL: GC only */
2011: };
2012:
2013: static const struct adreno_a6xx_core adreno_gpu_core_a704 = {
2014: .base = {
2015: DEFINE_ADRENO_REV(ADRENO_REV_A704, 7, 0, 4, ANY_ID),
2016: .features = ADRENO_CONTENT_PROTECTION |
2017: ADRENO_APRIV | ADRENO_PREEMPTION,
2018: .gpudev = &adreno_a6xx_gpudev,
2019: .perfcounters = &adreno_a6xx_legacy_perfcounters,
2020: .gmem_size = SZ_128K,
2021: .bus_width = 16,
2022: .snapshot_size = SZ_1M,
2023: .highest_bank_bit = 14,
2024: .chipid = 0x07000400,
2025: .ubwc_mode = 2,
2026: .mal = 32,
2027: .gpu_model = "Adreno704v1",
2028: .smmu_aperture = a704_smmu_aperture_regs,
2029: .smmu_aperture_count = ARRAY_SIZE(a704_smmu_aperture_regs),
2030: },
2031: .prim_fifo_threshold = 0x0000c000,
2032: .sqefw_name = "a702_sqe.fw",
2033: .zap_name = "a704_zap.mbn",
2034: .hwcg = a702_hwcg_regs,
--- LINES 2154-2239 ---
2154:
2155: static const struct adreno_gen7_core adreno_gpu_core_gen7_0_0 = {
2156: .base = {
2157: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_0_0,
2158: UINT_MAX, UINT_MAX, UINT_MAX, 0),
2159: .compatible = "qcom,adreno-gpu-gen7-0-0",
2160: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
2161: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC |
2162: ADRENO_ACD | ADRENO_L3_VOTE | ADRENO_BCL |
2163: ADRENO_PREEMPTION,
2164: .gpudev = &adreno_gen7_gmu_gpudev.base,
2165: .perfcounters = &adreno_gen7_perfcounters,
2166: .uche_gmem_alignment = 0,
2167: .gmem_size = SZ_2M,
2168: .bus_width = 32,
2169: .snapshot_size = SZ_4M,
2170: .highest_bank_bit = 16,
2171: },
2172: .gmu_fw_version = GMU_VERSION(4, 0, 0),
2173: .sqefw_name = "a730_sqe.fw",
2174: .gmufw_name = "gmu_gen70000.bin",
2175: .gmufw_bak_name = "c500_gmu.bin",
2176: .zap_name = "a730_zap.mdt",
2177: .hwcg = gen7_0_0_hwcg_regs,
2178: .hwcg_count = ARRAY_SIZE(gen7_0_0_hwcg_regs),
2179: .ao_hwcg = gen7_0_0_ao_hwcg_regs,
2180: .ao_hwcg_count = ARRAY_SIZE(gen7_0_0_ao_hwcg_regs),
2181: .gbif = gen7_0_0_gbif_cx_regs,
2182: .gbif_count = ARRAY_SIZE(gen7_0_0_gbif_cx_regs),
2183: .hang_detect_cycles = 0xcfffff,
2184: .protected_regs = gen7_0_0_protected_regs,
2185: .gen7_snapshot_block_list = &gen7_0_0_snapshot_block_list,
2186: .preempt_level = 1,
2187: .ctxt_record_size = (2860 * SZ_1K),
2188: .fast_bus_hint = true,
2189: };
2190:
2191: static const struct adreno_gen7_core adreno_gpu_core_gen7_0_1 = {
2192: .base = {
2193: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_0_1,
2194: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
2195: .compatible = "qcom,adreno-gpu-gen7-0-1",
2196: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
2197: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC |
2198: ADRENO_ACD | ADRENO_L3_VOTE | ADRENO_BCL |
2199: ADRENO_PREEMPTION,
2200: .gpudev = &adreno_gen7_gmu_gpudev.base,
2201: .perfcounters = &adreno_gen7_perfcounters,
2202: .uche_gmem_alignment = 0,
2203: .gmem_size = SZ_2M,
2204: .bus_width = 32,
2205: .snapshot_size = SZ_4M,
2206: .highest_bank_bit = 16,
2207: },
2208: .gmu_fw_version = GMU_VERSION(4, 0, 0),
2209: .sqefw_name = "a730_sqe.fw",
2210: .gmufw_name = "gmu_gen70000.bin",
2211: .gmufw_bak_name = "c500_gmu.bin",
2212: .zap_name = "a730_zap.mdt",
2213: .hwcg = gen7_0_0_hwcg_regs,
2214: .hwcg_count = ARRAY_SIZE(gen7_0_0_hwcg_regs),
2215: .ao_hwcg = gen7_0_0_ao_hwcg_regs,
2216: .ao_hwcg_count = ARRAY_SIZE(gen7_0_0_ao_hwcg_regs),
2217: .gbif = gen7_0_0_gbif_cx_regs,
2218: .gbif_count = ARRAY_SIZE(gen7_0_0_gbif_cx_regs),
2219: .hang_detect_cycles = 0xcfffff,
2220: .protected_regs = gen7_0_0_protected_regs,
2221: .gen7_snapshot_block_list = &gen7_0_0_snapshot_block_list,
2222: .preempt_level = 1,
2223: .ctxt_record_size = (2860 * SZ_1K),
2224: .fast_bus_hint = true,
2225: };
2226:
2227: extern const struct gen7_snapshot_block_list gen7_2_0_snapshot_block_list;
2228: extern const struct gen7_snapshot_block_list gen7_6_0_snapshot_block_list;
2229:
2230: static const struct kgsl_regmap_list gen7_2_0_gbif_cx_regs[] = {
2231: { GEN7_GBIF_QSB_SIDE0, 0x00071e20 },
2232: { GEN7_GBIF_QSB_SIDE1, 0x00071e20 },
2233: { GEN7_GBIF_QSB_SIDE2, 0x00071e20 },
2234: { GEN7_GBIF_QSB_SIDE3, 0x00071e20 },
2235: { GEN7_GMU_CX_MRC_GBIF_QOS_CTRL, 0x33 },
2236: };
2237:
2238: extern const struct gen7_snapshot_block_list gen7_3_0_snapshot_block_list;
2239:
--- LINES 2410-2586 ---
2410:
2411: static const struct adreno_gen7_core adreno_gpu_core_gen7_2_0 = {
2412: .base = {
2413: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_2_0,
2414: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
2415: .compatible = "qcom,adreno-gpu-gen7-2-0",
2416: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_IFPC |
2417: ADRENO_CONTENT_PROTECTION | ADRENO_ACD |
2418: ADRENO_LPAC | ADRENO_BCL | ADRENO_L3_VOTE |
2419: ADRENO_PREEMPTION | ADRENO_DMS,
2420: .gpudev = &adreno_gen7_hwsched_gpudev.base,
2421: .perfcounters = &adreno_gen7_2_0_perfcounters,
2422: .uche_gmem_alignment = SZ_16M,
2423: .gmem_size = 3 * SZ_1M,
2424: .bus_width = 32,
2425: .snapshot_size = SZ_8M,
2426: .highest_bank_bit = 16,
2427: },
2428: .gmu_fw_version = GMU_VERSION(4, 1, 0),
2429: .sqefw_name = "a740_sqe.fw",
2430: .gmufw_name = "gmu_gen70200.bin",
2431: .zap_name = "a740_zap.mbn",
2432: .hwcg = gen7_2_0_hwcg_regs,
2433: .hwcg_count = ARRAY_SIZE(gen7_2_0_hwcg_regs),
2434: .ao_hwcg = gen7_2_0_ao_hwcg_regs,
2435: .ao_hwcg_count = ARRAY_SIZE(gen7_2_0_ao_hwcg_regs),
2436: .gbif = gen7_2_0_gbif_cx_regs,
2437: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs),
2438: .hang_detect_cycles = 0xcfffff,
2439: .protected_regs = gen7_2_0_protected_regs,
2440: .gmu_hub_clk_freq = 200000000,
2441: .gen7_snapshot_block_list = &gen7_2_0_snapshot_block_list,
2442: .bcl_data = 1,
2443: .preempt_level = 1,
2444: .ctxt_record_size = (4192 * SZ_1K),
2445: .fast_bus_hint = true,
2446: };
2447:
2448: static const struct adreno_gen7_core adreno_gpu_core_gen7_2_1 = {
2449: .base = {
2450: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_2_1,
2451: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
2452: .compatible = "qcom,adreno-gpu-gen7-2-1",
2453: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_IFPC |
2454: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC |
2455: ADRENO_BCL | ADRENO_L3_VOTE | ADRENO_ACD |
2456: ADRENO_PREEMPTION | ADRENO_DMS,
2457: .gpudev = &adreno_gen7_hwsched_gpudev.base,
2458: .perfcounters = &adreno_gen7_2_0_perfcounters,
2459: .uche_gmem_alignment = SZ_16M,
2460: .gmem_size = 3 * SZ_1M,
2461: .bus_width = 32,
2462: .snapshot_size = SZ_8M,
2463: .highest_bank_bit = 16,
2464: },
2465: .gmu_fw_version = GMU_VERSION(4, 1, 0),
2466: .sqefw_name = "a740_sqe.fw",
2467: .gmufw_name = "gmu_gen70200.bin",
2468: .zap_name = "a740_zap.mbn",
2469: .hwcg = gen7_2_0_hwcg_regs,
2470: .hwcg_count = ARRAY_SIZE(gen7_2_0_hwcg_regs),
2471: .ao_hwcg = gen7_2_0_ao_hwcg_regs,
2472: .ao_hwcg_count = ARRAY_SIZE(gen7_2_0_ao_hwcg_regs),
2473: .gbif = gen7_2_0_gbif_cx_regs,
2474: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs),
2475: .hang_detect_cycles = 0xcfffff,
2476: .protected_regs = gen7_2_0_protected_regs,
2477: .gmu_hub_clk_freq = 200000000,
2478: .gen7_snapshot_block_list = &gen7_2_0_snapshot_block_list,
2479: .bcl_data = 1,
2480: .preempt_level = 1,
2481: .ctxt_record_size = (4192 * SZ_1K),
2482: .fast_bus_hint = true,
2483: };
2484:
2485: static const struct adreno_gen7_core adreno_gpu_core_gen7_3_0 = {
2486: .base = {
2487: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_3_0,
2488: UINT_MAX, UINT_MAX, UINT_MAX, 0),
2489: .compatible = "qcom,adreno-gpu-gen7-3-0",
2490: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
2491: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC |
2492: ADRENO_PREEMPTION | ADRENO_BCL | ADRENO_ACD,
2493: .gpudev = &adreno_gen7_gmu_gpudev.base,
2494: .perfcounters = &adreno_gen7_no_cb_perfcounters,
2495: .uche_gmem_alignment = SZ_16M,
2496: .gmem_size = SZ_512K,
2497: .bus_width = 32,
2498: .snapshot_size = SZ_2M,
2499: .highest_bank_bit = 15,
2500: },
2501: .gmu_fw_version = GMU_VERSION(4, 0, 0),
2502: .sqefw_name = "a710_sqe.fw",
2503: .gmufw_name = "gmu_gen70000.bin",
2504: .zap_name = "a710_zap.mdt",
2505: .hwcg = gen7_3_0_hwcg_regs,
2506: .hwcg_count = ARRAY_SIZE(gen7_3_0_hwcg_regs),
2507: .ao_hwcg = gen7_0_0_ao_hwcg_regs,
2508: .ao_hwcg_count = ARRAY_SIZE(gen7_0_0_ao_hwcg_regs),
2509: .gbif = gen7_0_0_gbif_cx_regs,
2510: .gbif_count = ARRAY_SIZE(gen7_0_0_gbif_cx_regs),
2511: .hang_detect_cycles = 0xcfffff,
2512: .protected_regs = gen7_0_0_protected_regs,
2513: .gen7_snapshot_block_list = &gen7_3_0_snapshot_block_list,
2514: .preempt_level = 1,
2515: .ctxt_record_size = (862 * SZ_1K),
2516: };
2517:
2518: static const struct adreno_gen7_core adreno_gpu_core_gen7_4_0 = {
2519: .base = {
2520: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_4_0,
2521: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
2522: .compatible = "qcom,adreno-gpu-gen7-4-0",
2523: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
2524: ADRENO_CONTENT_PROTECTION | ADRENO_L3_VOTE |
2525: ADRENO_PREEMPTION | ADRENO_IFPC | ADRENO_ACD |
2526: ADRENO_BCL,
2527: .gpudev = &adreno_gen7_gmu_gpudev.base,
2528: .perfcounters = &adreno_gen7_perfcounters,
2529: .uche_gmem_alignment = 0,
2530: .gmem_size = SZ_2M,
2531: .bus_width = 32,
2532: .snapshot_size = SZ_4M,
2533: .highest_bank_bit = 16,
2534: },
2535: .gmu_fw_version = GMU_VERSION(4, 0, 7),
2536: .sqefw_name = "a730_sqe.fw",
2537: .gmufw_name = "gmu_gen70000.bin",
2538: .gmufw_bak_name = "c500_gmu.bin",
2539: .zap_name = "a730_zap.mdt",
2540: .hwcg = gen7_0_0_hwcg_regs,
2541: .hwcg_count = ARRAY_SIZE(gen7_0_0_hwcg_regs),
2542: .ao_hwcg = gen7_0_0_ao_hwcg_regs,
2543: .ao_hwcg_count = ARRAY_SIZE(gen7_0_0_ao_hwcg_regs),
2544: .gbif = gen7_0_0_gbif_cx_regs,
2545: .gbif_count = ARRAY_SIZE(gen7_0_0_gbif_cx_regs),
2546: .hang_detect_cycles = 0xcfffff,
2547: .protected_regs = gen7_0_0_protected_regs,
2548: .gen7_snapshot_block_list = &gen7_0_0_snapshot_block_list,
2549: .preempt_level = 1,
2550: .ctxt_record_size = (2860 * SZ_1K),
2551: .fast_bus_hint = true,
2552: };
2553:
2554: static const struct kgsl_regmap_list gen7_9_0_ao_hwcg_regs[] = {
2555: { GEN7_GPU_GMU_AO_GMU_CGC_MODE_CNTL, 0x00020222 },
2556: { GEN7_GPU_GMU_AO_GMU_CGC_DELAY_CNTL, 0x00010111 },
2557: { GEN7_GPU_GMU_AO_GMU_CGC_HYST_CNTL, 0x00005555 },
2558: { GEN7_GMU_CX_GMU_WFI_CONFIG, 0x00000003 },
2559: };
2560:
2561: extern const struct gen7_snapshot_block_list gen7_5_0_snapshot_block_list;
2562:
2563: static const struct adreno_gen7_core adreno_gpu_core_gen7_5_0 = {
2564: .base = {
2565: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_5_0,
2566: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
2567: .compatible = "qcom,adreno-gpu-gen7-5-0",
2568: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_IFPC |
2569: ADRENO_PREEMPTION | ADRENO_L3_VOTE | ADRENO_DMS | ADRENO_LPAC,
2570: .gpudev = &adreno_gen7_gmu_gpudev.base,
2571: .perfcounters = &adreno_gen7_2_0_perfcounters,
2572: .uche_gmem_alignment = SZ_16M,
2573: .gmem_size = 3 * SZ_1M,
2574: .bus_width = 32,
2575: .snapshot_size = SZ_8M,
2576: .num_ddr_channels = 8,
2577: .chipid = 0x43050c01,
2578: .speedbins = KGSL_SPEEDBINS(
2579: { 0, 0 },
2580: { 59, 1 },
2581: { 7, 2 },
2582: { 232, 3 },
2583: { 146, 4 },
2584: ),
2585: .ubwc_mode = 4,
2586: .mal = 32,
--- LINES 2594-2658 ---
2594: .hwcg_count = ARRAY_SIZE(gen7_2_0_hwcg_regs),
2595: .ao_hwcg = gen7_9_0_ao_hwcg_regs,
2596: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs),
2597: .gbif = gen7_2_0_gbif_cx_regs,
2598: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs),
2599: .hang_detect_cycles = 0xcfffff,
2600: .protected_regs = gen7_2_0_protected_regs,
2601: .gmu_hub_clk_freq = 200000000,
2602: .gen7_snapshot_block_list = &gen7_5_0_snapshot_block_list,
2603: .preempt_level = 1,
2604: .ctxt_record_size = (4192 * SZ_1K),
2605: .fast_bus_hint = true,
2606: };
2607:
2608: static const struct adreno_gen7_core adreno_gpu_core_gen7_6_0 = {
2609: .base = {
2610: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_6_0,
2611: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
2612: .compatible = "qcom,adreno-gpu-gen7-6-0",
2613: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
2614: ADRENO_CONTENT_PROTECTION | ADRENO_L3_VOTE |
2615: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_BCL |
2616: ADRENO_ACD | ADRENO_LPAC | ADRENO_DMS,
2617: .gpudev = &adreno_gen7_hwsched_gpudev.base,
2618: .perfcounters = &adreno_gen7_2_0_perfcounters,
2619: .uche_gmem_alignment = SZ_16M,
2620: .gmem_size = 3 * SZ_1M,
2621: .bus_width = 32,
2622: .snapshot_size = SZ_4M,
2623: .highest_bank_bit = 16,
2624: },
2625: .gmu_fw_version = GMU_VERSION(4, 1, 9),
2626: .sqefw_name = "a740v3_sqe.fw",
2627: .gmufw_name = "gmu_gen70200.bin",
2628: .zap_name = "a740v3_zap.mbn",
2629: .hwcg = gen7_2_0_hwcg_regs,
2630: .hwcg_count = ARRAY_SIZE(gen7_2_0_hwcg_regs),
2631: .ao_hwcg = gen7_2_0_ao_hwcg_regs,
2632: .ao_hwcg_count = ARRAY_SIZE(gen7_2_0_ao_hwcg_regs),
2633: .gbif = gen7_2_0_gbif_cx_regs,
2634: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs),
2635: .hang_detect_cycles = 0xcfffff,
2636: .protected_regs = gen7_2_0_protected_regs,
2637: .gmu_hub_clk_freq = 200000000,
2638: .bcl_data = 1,
2639: .gen7_snapshot_block_list = &gen7_6_0_snapshot_block_list,
2640: .qos_value = gen7_6_0_gbif_client_qos_values,
2641: .preempt_level = 1,
2642: .ctxt_record_size = (4192 * SZ_1K),
2643: };
2644:
2645: extern const struct gen7_snapshot_block_list gen7_9_0_snapshot_block_list;
2646:
2647: /* GEN7_9_0 protected register list */
2648: static const struct gen7_protected_regs gen7_9_0_protected_regs[] = {
2649: { GEN7_CP_PROTECT_REG + 0, 0x00000, 0x004ff, 0 },
2650: { GEN7_CP_PROTECT_REG + 1, 0x0050b, 0x00563, 0 },
2651: { GEN7_CP_PROTECT_REG + 2, 0x00584, 0x006c1, 0 },
2652: { GEN7_CP_PROTECT_REG + 3, 0x00706, 0x00706, 0 },
2653: { GEN7_CP_PROTECT_REG + 4, 0x00720, 0x0073f, 0 },
2654: { GEN7_CP_PROTECT_REG + 5, 0x00760, 0x007ff, 0 },
2655: { GEN7_CP_PROTECT_REG + 6, 0x00800, 0x00882, 1 },
2656: { GEN7_CP_PROTECT_REG + 7, 0x008a0, 0x008a8, 1 },
2657: { GEN7_CP_PROTECT_REG + 8, 0x008ab, 0x00a40, 0 },
2658: { GEN7_CP_PROTECT_REG + 9, 0x00900, 0x0094d, 1 },
--- LINES 2699-2791 ---
2699:
2700: static const struct adreno_gen7_core adreno_gpu_core_gen7_9_0 = {
2701: .base = {
2702: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_9_0,
2703: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
2704: .compatible = "qcom,adreno-gpu-gen7-9-0",
2705: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_AQE |
2706: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_IFPC |
2707: ADRENO_L3_VOTE | ADRENO_BCL | ADRENO_DMS |
2708: ADRENO_HW_FENCE | ADRENO_PREEMPTION | ADRENO_ACD |
2709: ADRENO_GMU_WARMBOOT | ADRENO_GMU_AB,
2710: .gpudev = &adreno_gen7_9_0_hwsched_gpudev.base,
2711: .perfcounters = &adreno_gen7_9_0_perfcounters,
2712: .uche_gmem_alignment = SZ_16M,
2713: .gmem_size = 3 * SZ_1M,
2714: .bus_width = 32,
2715: .snapshot_size = SZ_8M,
2716: .num_ddr_channels = 4,
2717: .highest_bank_bit = 16,
2718: },
2719: .aqefw_name = "gen70900_aqe.fw",
2720: .sqefw_name = "gen70900_sqe.fw",
2721: .gmufw_name = "gmu_gen70900.bin",
2722: .zap_name = "gen70900_zap.mbn",
2723: .ao_hwcg = gen7_9_0_ao_hwcg_regs,
2724: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs),
2725: .gbif = gen7_2_0_gbif_cx_regs,
2726: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs),
2727: .hang_detect_cycles = 0xcfffff,
2728: .protected_regs = gen7_9_0_protected_regs,
2729: .gmu_hub_clk_freq = 200000000,
2730: .gen7_snapshot_block_list = &gen7_9_0_snapshot_block_list,
2731: .bcl_data = 1,
2732: .acv_perfmode_vote = BIT(2),
2733: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4),
2734: .ctxt_record_size = (4208 * SZ_1K),
2735: .preempt_level = 1,
2736: .fast_bus_hint = true,
2737: };
2738:
2739: static const struct adreno_gen7_core adreno_gpu_core_gen7_9_1 = {
2740: .base = {
2741: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_9_1,
2742: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
2743: .compatible = "qcom,adreno-gpu-gen7-9-1",
2744: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_AQE |
2745: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_IFPC |
2746: ADRENO_L3_VOTE | ADRENO_BCL | ADRENO_DMS |
2747: ADRENO_HW_FENCE | ADRENO_PREEMPTION | ADRENO_ACD |
2748: ADRENO_GMU_WARMBOOT | ADRENO_GMU_AB,
2749: .gpudev = &adreno_gen7_9_0_hwsched_gpudev.base,
2750: .perfcounters = &adreno_gen7_9_0_perfcounters,
2751: .uche_gmem_alignment = SZ_16M,
2752: .gmem_size = 3 * SZ_1M,
2753: .bus_width = 32,
2754: .snapshot_size = SZ_8M,
2755: .num_ddr_channels = 4,
2756: .highest_bank_bit = 16,
2757: },
2758: .aqefw_name = "gen70900_aqe.fw",
2759: .sqefw_name = "gen70900_sqe.fw",
2760: .gmufw_name = "gmu_gen70900.bin",
2761: .zap_name = "gen70900_zap.mbn",
2762: .ao_hwcg = gen7_9_0_ao_hwcg_regs,
2763: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs),
2764: .gbif = gen7_2_0_gbif_cx_regs,
2765: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs),
2766: .hang_detect_cycles = 0xcfffff,
2767: .protected_regs = gen7_9_0_protected_regs,
2768: .gmu_hub_clk_freq = 200000000,
2769: .gen7_snapshot_block_list = &gen7_9_0_snapshot_block_list,
2770: .bcl_data = 1,
2771: .acv_perfmode_vote = BIT(2),
2772: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4),
2773: .ctxt_record_size = (4208 * SZ_1K),
2774: .preempt_level = 1,
2775: .fast_bus_hint = true,
2776: };
2777:
2778: extern const struct gen7_snapshot_block_list gen7_13_0_snapshot_block_list;
2779:
2780: /* SMMU aperture registers: GC to context bank 0, LPAC to context bank 1 */
2781: static const struct kgsl_regmap_list gen7_13_0_smmu_aperture_regs[] = {
2782: { 0x0, 0x000c0000 }, /* GC: CB0 */
2783: { 0x1, 0x000c1000 }, /* LPAC: CB1 */
2784: { 0x2, 0x00000002 }, /* CTRL: GC + LPAC */
2785: };
2786:
2787: static const struct adreno_gen7_core adreno_gpu_core_gen7_13_0 = {
2788: .base = {
2789: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_13_0,
2790: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
2791: .features = ADRENO_APRIV | ADRENO_IOCOHERENT,
--- LINES 2808-2915 ---
2808: .ao_hwcg = gen7_9_0_ao_hwcg_regs,
2809: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs),
2810: .gbif = gen7_2_0_gbif_cx_regs,
2811: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs),
2812: .hang_detect_cycles = 0xcfffff,
2813: .protected_regs = gen7_9_0_protected_regs,
2814: .gmu_hub_clk_freq = 200000000,
2815: .gen7_snapshot_block_list = &gen7_13_0_snapshot_block_list,
2816: .ctxt_record_size = (4208 * SZ_1K),
2817: .preempt_level = 1,
2818: };
2819:
2820: extern const struct gen7_snapshot_block_list gen7_14_0_snapshot_block_list;
2821:
2822: static const struct adreno_gen7_core adreno_gpu_core_gen7_14_0 = {
2823: .base = {
2824: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_14_0,
2825: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
2826: .compatible = "qcom,adreno-gpu-gen7-14-0",
2827: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION |
2828: ADRENO_PREEMPTION | ADRENO_IFPC | ADRENO_BCL | ADRENO_ACD,
2829: .gpudev = &adreno_gen7_gmu_gpudev.base,
2830: .perfcounters = &adreno_gen7_no_cb_perfcounters,
2831: .uche_gmem_alignment = 0,
2832: .gmem_size = SZ_1M,
2833: .bus_width = 32,
2834: .snapshot_size = SZ_4M,
2835: .highest_bank_bit = 15,
2836: },
2837: .sqefw_name = "gen70e00_sqe.fw",
2838: .gmufw_name = "gmu_gen70e00.bin",
2839: .zap_name = "gen70e00_zap.mbn",
2840: .hwcg = gen7_0_0_hwcg_regs,
2841: .hwcg_count = ARRAY_SIZE(gen7_0_0_hwcg_regs),
2842: .ao_hwcg = gen7_0_0_ao_hwcg_regs,
2843: .ao_hwcg_count = ARRAY_SIZE(gen7_0_0_ao_hwcg_regs),
2844: .gbif = gen7_0_0_gbif_cx_regs,
2845: .gbif_count = ARRAY_SIZE(gen7_0_0_gbif_cx_regs),
2846: .hang_detect_cycles = 0xcfffff,
2847: .protected_regs = gen7_0_0_protected_regs,
2848: .gen7_snapshot_block_list = &gen7_14_0_snapshot_block_list,
2849: .preempt_level = 1,
2850: .fast_bus_hint = false,
2851: };
2852:
2853: extern const struct gen7_snapshot_block_list gen7_11_0_snapshot_block_list;
2854:
2855: static const struct adreno_gen7_core adreno_gpu_core_gen7_11_0 = {
2856: .base = {
2857: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_11_0,
2858: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
2859: .compatible = "qcom,adreno-gpu-gen7-11-0",
2860: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION |
2861: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_L3_VOTE |
2862: ADRENO_DMS | ADRENO_GMU_AB,
2863: .gpudev = &adreno_gen7_hwsched_gpudev.base,
2864: .perfcounters = &adreno_gen7_2_0_perfcounters,
2865: .uche_gmem_alignment = SZ_16M,
2866: .gmem_size = SZ_1M + SZ_512K,
2867: .bus_width = 32,
2868: .snapshot_size = SZ_4M,
2869: .num_ddr_channels = 4,
2870: .highest_bank_bit = 16,
2871: },
2872: .gmu_fw_version = GMU_VERSION(4, 5, 0),
2873: .sqefw_name = "gen71100_sqe.fw",
2874: .gmufw_name = "gen71100_gmu.bin",
2875: .zap_name = "gen71100_zap.mbn",
2876: .hwcg = gen7_2_0_hwcg_regs,
2877: .hwcg_count = ARRAY_SIZE(gen7_2_0_hwcg_regs),
2878: .ao_hwcg = gen7_9_0_ao_hwcg_regs,
2879: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs),
2880: .gbif = gen7_2_0_gbif_cx_regs,
2881: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs),
2882: .hang_detect_cycles = 0xcfffff,
2883: .protected_regs = gen7_2_0_protected_regs,
2884: .gmu_hub_clk_freq = 200000000,
2885: .gen7_snapshot_block_list = &gen7_11_0_snapshot_block_list,
2886: .preempt_level = 1,
2887: .fast_bus_hint = true,
2888: };
2889:
2890: extern const struct gen7_snapshot_block_list gen7_15_0_snapshot_block_list;
2891:
2892: static const struct adreno_gen7_core adreno_gpu_core_gen7_15_0 = {
2893: .base = {
2894: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_15_0,
2895: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
2896: .compatible = "qcom,adreno-gpu-gen7-15-0",
2897: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_IFPC |
2898: ADRENO_PREEMPTION | ADRENO_L3_VOTE | ADRENO_DMS,
2899: .gpudev = &adreno_gen7_gmu_gpudev.base,
2900: .perfcounters = &adreno_gen7_2_0_perfcounters,
2901: .uche_gmem_alignment = SZ_16M,
2902: .gmem_size = SZ_1M + SZ_512K,
2903: .bus_width = 32,
2904: .snapshot_size = SZ_4M,
2905: .num_ddr_channels = 8,
2906: .highest_bank_bit = 16,
2907: .chipid = 0x43030c00,
2908: .speedbins = KGSL_SPEEDBINS(
2909: { 0, 0 },
2910: { 294, 1 },
2911: { 263, 2 },
2912: { 233, 3 },
2913: { 141, 4 },
2914: ),
2915: .ubwc_mode = 4,
--- LINES 2923-2985 ---
2923: .hwcg_count = ARRAY_SIZE(gen7_2_0_hwcg_regs),
2924: .ao_hwcg = gen7_9_0_ao_hwcg_regs,
2925: .ao_hwcg_count = ARRAY_SIZE(gen7_9_0_ao_hwcg_regs),
2926: .gbif = gen7_2_0_gbif_cx_regs,
2927: .gbif_count = ARRAY_SIZE(gen7_2_0_gbif_cx_regs),
2928: .hang_detect_cycles = 0xcfffff,
2929: .protected_regs = gen7_2_0_protected_regs,
2930: .gmu_hub_clk_freq = 200000000,
2931: .gen7_snapshot_block_list = &gen7_15_0_snapshot_block_list,
2932: .preempt_level = 1,
2933: .fast_bus_hint = true,
2934: };
2935:
2936: extern const struct gen7_snapshot_block_list gen7_17_0_snapshot_block_list;
2937:
2938: static const struct adreno_gen7_core adreno_gpu_core_gen7_17_0 = {
2939: .base = {
2940: DEFINE_ADRENO_REV(ADRENO_REV_GEN7_17_0,
2941: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
2942: .compatible = "qcom,adreno-gpu-gen7-17-0",
2943: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION |
2944: ADRENO_IFPC | ADRENO_PREEMPTION | ADRENO_BCL,
2945: .gpudev = &adreno_gen7_gmu_gpudev.base,
2946: .perfcounters = &adreno_gen7_no_cb_perfcounters,
2947: .uche_gmem_alignment = SZ_16M,
2948: .gmem_size = SZ_1M,
2949: .bus_width = 32,
2950: .snapshot_size = SZ_2M,
2951: .chipid = 0x43020100,
2952: .ubwc_mode = 5,
2953: .mal = 32,
2954: .highest_bank_bit = 15,
2955: },
2956: .sqefw_name = "gen70e00_sqe.fw",
2957: .gmufw_name = "gen71700_gmu.bin",
2958: .zap_name = "gen70e00_zap.mbn",
2959: .hwcg = gen7_0_0_hwcg_regs,
2960: .hwcg_count = ARRAY_SIZE(gen7_0_0_hwcg_regs),
2961: .ao_hwcg = gen7_0_0_ao_hwcg_regs,
2962: .ao_hwcg_count = ARRAY_SIZE(gen7_0_0_ao_hwcg_regs),
2963: .gbif = gen7_0_0_gbif_cx_regs,
2964: .gbif_count = ARRAY_SIZE(gen7_0_0_gbif_cx_regs),
2965: .hang_detect_cycles = 0xcfffff,
2966: .protected_regs = gen7_0_0_protected_regs,
2967: .gen7_snapshot_block_list = &gen7_17_0_snapshot_block_list,
2968: .preempt_level = 1,
2969: .ctxt_record_size = 1536 * 1024
2970: };
2971:
2972: static const struct kgsl_regmap_list a663_hwcg_regs[] = {
2973: {A6XX_RBBM_CLOCK_CNTL_SP0, 0x02222222},
2974: {A6XX_RBBM_CLOCK_CNTL2_SP0, 0x02222220},
2975: {A6XX_RBBM_CLOCK_DELAY_SP0, 0x00000080},
2976: {A6XX_RBBM_CLOCK_HYST_SP0, 0x0000F3CF},
2977: {A6XX_RBBM_CLOCK_CNTL_TP0, 0x22222222},
2978: {A6XX_RBBM_CLOCK_CNTL2_TP0, 0x22222222},
2979: {A6XX_RBBM_CLOCK_CNTL3_TP0, 0x22222222},
2980: {A6XX_RBBM_CLOCK_CNTL4_TP0, 0x00022222},
2981: {A6XX_RBBM_CLOCK_DELAY_TP0, 0x11111111},
2982: {A6XX_RBBM_CLOCK_DELAY2_TP0, 0x11111111},
2983: {A6XX_RBBM_CLOCK_DELAY3_TP0, 0x11111111},
2984: {A6XX_RBBM_CLOCK_DELAY4_TP0, 0x00011111},
2985: {A6XX_RBBM_CLOCK_HYST_TP0, 0x77777777},
--- LINES 3025-3051 ---
3025: {A6XX_GMUAO_GMU_CGC_HYST_CNTL, 0x00005555},
3026: {A6XX_GMUCX_GMU_WFI_CONFIG, 0x00000000},
3027: };
3028:
3029: static const struct adreno_a6xx_core adreno_gpu_core_a663 = {
3030: .base = {
3031: DEFINE_ADRENO_REV(ADRENO_REV_A663, 6, 6, 3, ANY_ID),
3032: .features = ADRENO_APRIV |
3033: ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION |
3034: ADRENO_PREEMPTION | ADRENO_ACD,
3035: .gpudev = &adreno_a6xx_gmu_gpudev.base,
3036: .perfcounters = &adreno_a6xx_perfcounters,
3037: .gmem_size = SZ_1M + SZ_512K,
3038: .bus_width = 32,
3039: .snapshot_size = SZ_2M,
3040: .chipid = 0x06060300,
3041: .speedbins = KGSL_SPEEDBINS(
3042: { 0, 0 },
3043: { 169, 0 },
3044: { 113, 1 },
3045: ),
3046: .ubwc_mode = 4,
3047: .mal = 32,
3048: .highest_bank_bit = 13,
3049: },
3050: .prim_fifo_threshold = 0x00300000,
3051: .gmu_major = 2,
--- LINES 3076-3102 ---
3076: { GEN8_GMUCX_MRC_GBIF_QOS_CTRL, 0x33 },
3077: };
3078:
3079: /* GEN8_0_0 noncontext register list */
3080: static const struct gen8_nonctxt_regs gen8_0_0_nonctxt_regs[] = {
3081: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) },
3082: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BR) | BIT(PIPE_BV) },
3083: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) },
3084: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BR) | BIT(PIPE_BV) },
3085: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BR) | BIT(PIPE_BV) },
3086: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) | BIT(PIPE_BV) },
3087: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BR) | BIT(PIPE_BV) },
3088: /* Disable BR throttling */
3089: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BR) | BIT(PIPE_BV) },
3090: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) },
3091: /* Configure GBIF GX registers */
3092: { GEN8_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) },
3093: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) },
3094: /* Enable full concurrent resolve and unresolves */
3095: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) },
3096: { GEN8_RB_GC_GMEM_PROTECT, 0x0c000000, BIT(PIPE_BR) },
3097: /* Configure number of outstanding transactions to 32 */
3098: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) },
3099: /* Configure UCHE request time out to 16 cycles for CCU/UCHE arbitration */
3100: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) },
3101: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) },
3102: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) },
--- LINES 3256-3282 ---
3256:
3257: static const struct adreno_gen8_core adreno_gpu_core_gen8_0_0 = {
3258: .base = {
3259: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_0_0,
3260: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
3261: .compatible = "qcom,adreno-gpu-gen8-0-0",
3262: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
3263: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_AQE |
3264: ADRENO_GMU_WARMBOOT | ADRENO_L3_VOTE | ADRENO_BCL |
3265: ADRENO_IFPC | ADRENO_HW_FENCE | ADRENO_PREEMPTION |
3266: ADRENO_ACD | ADRENO_CLX | ADRENO_GMU_THERMAL_MITIGATION |
3267: ADRENO_GMU_AB,
3268: .gpudev = &adreno_gen8_hwsched_gpudev.base,
3269: .perfcounters = &adreno_gen8_perfcounters,
3270: .uche_gmem_alignment = SZ_64M,
3271: .gmem_size = 12 * SZ_1M,
3272: .bus_width = 32,
3273: .snapshot_size = SZ_8M,
3274: .num_ddr_channels = 4,
3275: .highest_bank_bit = 16,
3276: },
3277: .aqefw_name = "gen80000_aqe.fw",
3278: .sqefw_name = "gen80000_sqe.fw",
3279: .gmufw_name = "gen80000_gmu.bin",
3280: .zap_name = "gen80000_zap.mbn",
3281: .ao_hwcg = gen8_ao_hwcg_regs,
3282: .ao_hwcg_count = ARRAY_SIZE(gen8_ao_hwcg_regs),
--- LINES 3286-3329 ---
3286: .protected_regs = gen8_0_0_protected_regs,
3287: .nonctxt_regs = gen8_0_0_nonctxt_regs,
3288: .gmu_hub_clk_freq = 200000000,
3289: .gen8_snapshot_block_list = &gen8_0_0_snapshot_block_list,
3290: .fast_bus_hint = true,
3291: .bcl_data = 1,
3292: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4),
3293: .noc_timeout_us = 3410, /* 3.41 msec */
3294: .ctxt_record_size = (13536 * SZ_1K),
3295: .preempt_level = 1,
3296: .cl_no_ft_timeout_ms = 6500,
3297: .therm_cfg = &therm_mit_cfg_8_0_0,
3298: .clx_tbl = &gen8_0_0_clx_table,
3299: };
3300:
3301: static const struct adreno_gen8_core adreno_gpu_core_gen8_0_1 = {
3302: .base = {
3303: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_0_1,
3304: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
3305: .compatible = "qcom,adreno-gpu-gen8-0-1",
3306: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
3307: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_AQE |
3308: ADRENO_GMU_WARMBOOT | ADRENO_L3_VOTE | ADRENO_BCL |
3309: ADRENO_IFPC | ADRENO_HW_FENCE | ADRENO_PREEMPTION |
3310: ADRENO_ACD | ADRENO_CLX | ADRENO_GMU_THERMAL_MITIGATION |
3311: ADRENO_GMU_AB,
3312: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION |
3313: ADRENO_IFPC | ADRENO_AQE | ADRENO_CONTENT_PROTECTION,
3314: .gpudev = &adreno_gen8_hwsched_gpudev.base,
3315: .perfcounters = &adreno_gen8_perfcounters,
3316: .uche_gmem_alignment = SZ_64M,
3317: .gmem_size = 12 * SZ_1M,
3318: .bus_width = 32,
3319: .snapshot_size = SZ_8M,
3320: .num_ddr_channels = 4,
3321: .highest_bank_bit = 16,
3322: .chipid = 0x44050001,
3323: .speedbins = KGSL_SPEEDBINS(
3324: { 0, 0 },
3325: { 252, 1 },
3326: { 242, 2 },
3327: { 232, 3 },
3328: { 221, 4 },
3329: { 190, 5 },
--- LINES 3344-3370 ---
3344: .protected_regs = gen8_0_0_protected_regs,
3345: .nonctxt_regs = gen8_0_0_nonctxt_regs,
3346: .gmu_hub_clk_freq = 200000000,
3347: .gen8_snapshot_block_list = &gen8_0_0_snapshot_block_list,
3348: .fast_bus_hint = true,
3349: .bcl_data = 1,
3350: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4),
3351: .noc_timeout_us = 3410, /* 3.41 msec */
3352: .ctxt_record_size = (13536 * SZ_1K),
3353: .preempt_level = 1,
3354: .cl_no_ft_timeout_ms = 6500,
3355: .therm_cfg = &therm_mit_cfg_8_0_0,
3356: .clx_tbl = &gen8_0_0_clx_table,
3357: };
3358:
3359: extern const struct gen8_snapshot_block_list gen8_2_0_snapshot_block_list;
3360:
3361: static const struct hfi_clx_table_v2_cmd gen8_2_0_clx_table = {
3362: .version = (2 << 16) | 1,
3363: .domain = {
3364: /* GFX domain */
3365: {
3366: .data0 = CLX_DATA(60, 5, 1, 1),
3367: .clxt = 0,
3368: .clxh = 0,
3369: .urgmode = 1,
3370: .lkgen = 0,
--- LINES 3512-3538 ---
3512: };
3513:
3514: /* GEN8_2_0 noncontext register list */
3515: static const struct gen8_nonctxt_regs gen8_2_0_nonctxt_regs[] = {
3516: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) },
3517: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BV) | BIT(PIPE_BR) },
3518: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) },
3519: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) },
3520: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) },
3521: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) },
3522: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BV) | BIT(PIPE_BR) },
3523: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) },
3524: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BV) | BIT(PIPE_BR) },
3525: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) },
3526: /* Disable Dead Draw Merge scheme on RB-HLSQ */
3527: { GEN8_RB_RBP_CNTL, BIT(5), BIT(PIPE_BV) | BIT(PIPE_BR) },
3528: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) },
3529: /* Partially enable perf clear, Disable DINT to c/z be data forwarding */
3530: { GEN8_RB_CCU_DBG_ECO_CNTL, 0x00002200, BIT(PIPE_BR) },
3531: { GEN8_RB_GC_GMEM_PROTECT, 0x12000000, BIT(PIPE_BR) },
3532: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) },
3533: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) },
3534: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) },
3535: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) },
3536: { GEN8_RBBM_POWER_UP_RESET_SW_OVERRIDE, 0x70809060, BIT(PIPE_NONE) },
3537: { GEN8_RBBM_POWER_UP_RESET_SW_BV_OVERRIDE, 0x30000000, BIT(PIPE_NONE) },
3538: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) },
--- LINES 3608-3636 ---
3608: /* Set the BCL throttle levels to 62/75/83 percent */
3609: #define GEN8_2_X_BCL_DATA ((62 << 15) | (75 << 8) | (83 << 1) | 0x1)
3610:
3611: static const struct adreno_gen8_core adreno_gpu_core_gen8_2_0 = {
3612: .base = {
3613: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_2_0,
3614: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
3615: .compatible = "qcom,adreno-gpu-gen8-2-0",
3616: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
3617: ADRENO_PREEMPTION | ADRENO_LPAC | ADRENO_AQE |
3618: ADRENO_GMU_WARMBOOT | ADRENO_IFPC | ADRENO_CONTENT_PROTECTION |
3619: ADRENO_HW_FENCE | ADRENO_BCL | ADRENO_ACD | ADRENO_GMU_BASED_DCVS |
3620: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_CLX | ADRENO_DEFER_GMEM_ALLOC |
3621: ADRENO_GMU_MINBW | ADRENO_DCVS_PROFILE | ADRENO_TSENSE_DYNAMIC_PERIOD |
3622: ADRENO_GMU_AB,
3623: .gpudev = &adreno_gen8_hwsched_gpudev.base,
3624: .perfcounters = &adreno_gen8_2_x_perfcounters,
3625: .uche_gmem_alignment = SZ_64M,
3626: .gmem_size = 18 * SZ_1M,
3627: .bus_width = 32,
3628: .snapshot_size = SZ_8M,
3629: .num_ddr_channels = 4,
3630: .highest_bank_bit = 16,
3631: },
3632: .aqefw_name = "gen80200_aqe.fw",
3633: .sqefw_name = "gen80200_sqe.fw",
3634: .gmufw_name = "gen80200_gmu.bin",
3635: .zap_name = "gen80200_zap.mbn",
3636: .ao_hwcg = gen8_2_0_ao_hwcg_regs,
--- LINES 3644-3686 ---
3644: .gen8_snapshot_block_list = &gen8_2_0_snapshot_block_list,
3645: .fast_bus_hint = true,
3646: .bcl_data = GEN8_2_X_BCL_DATA,
3647: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4),
3648: .noc_timeout_us = 3410, /* 3.41 msec */
3649: .cl_no_ft_timeout_ms = 6500,
3650: .ctxt_record_size = (19708 * SZ_1K),
3651: .therm_cfg = &therm_mit_cfg_8_2_0,
3652: .limits_mit_cfg = &gen8_2_0_limits_mit_cfg,
3653: .preempt_level = 1,
3654: .clx_tbl = &gen8_2_0_clx_table,
3655: };
3656:
3657: static const struct adreno_gen8_core adreno_gpu_core_gen8_2_1 = {
3658: .base = {
3659: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_2_1,
3660: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
3661: .compatible = "qcom,adreno-gpu-gen8-2-1",
3662: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
3663: ADRENO_PREEMPTION | ADRENO_LPAC | ADRENO_AQE |
3664: ADRENO_GMU_WARMBOOT | ADRENO_IFPC | ADRENO_CONTENT_PROTECTION |
3665: ADRENO_HW_FENCE | ADRENO_BCL | ADRENO_ACD | ADRENO_GMU_BASED_DCVS |
3666: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_CLX | ADRENO_DEFER_GMEM_ALLOC |
3667: ADRENO_GMU_MINBW | ADRENO_DCVS_PROFILE | ADRENO_TSENSE_DYNAMIC_PERIOD |
3668: ADRENO_GMU_AB,
3669: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION |
3670: ADRENO_IFPC | ADRENO_AQE | ADRENO_CONTENT_PROTECTION,
3671: .gpudev = &adreno_gen8_hwsched_gpudev.base,
3672: .perfcounters = &adreno_gen8_2_x_perfcounters,
3673: .uche_gmem_alignment = SZ_64M,
3674: .gmem_size = 18 * SZ_1M,
3675: .bus_width = 32,
3676: .snapshot_size = SZ_8M,
3677: .num_ddr_channels = 4,
3678: .highest_bank_bit = 16,
3679: .chipid = 0x44050a01,
3680: .speedbins = KGSL_SPEEDBINS(
3681: { 0, 0 },
3682: { 273, 1 },
3683: { 252, 2 },
3684: { 221, 3 },
3685: ),
3686: .ubwc_mode = 6,
--- LINES 3702-3738 ---
3702: .gen8_snapshot_block_list = &gen8_2_0_snapshot_block_list,
3703: .fast_bus_hint = true,
3704: .bcl_data = GEN8_2_X_BCL_DATA,
3705: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4),
3706: .noc_timeout_us = 3410, /* 3.41 msec */
3707: .cl_no_ft_timeout_ms = 6500,
3708: .ctxt_record_size = (19708 * SZ_1K),
3709: .therm_cfg = &therm_mit_cfg_8_2_0,
3710: .limits_mit_cfg = &gen8_2_0_limits_mit_cfg,
3711: .preempt_level = 1,
3712: .clx_tbl = &gen8_2_0_clx_table,
3713: };
3714:
3715: static const struct gen8_nonctxt_regs gen8_1_0_nonctxt_regs[] = {
3716: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) },
3717: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BV) | BIT(PIPE_BR) },
3718: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) },
3719: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) },
3720: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) },
3721: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) },
3722: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BV) | BIT(PIPE_BR) },
3723: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) },
3724: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BV) | BIT(PIPE_BR) },
3725: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) },
3726: { GEN8_RB_GC_GMEM_PROTECT, 0x15000000, BIT(PIPE_BR) },
3727: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) },
3728: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) },
3729: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) },
3730: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) },
3731: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) },
3732: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) },
3733: { GEN8_RBBM_INTERFACE_HANG_INT_CNTL, 0x0fffffff, BIT(PIPE_NONE) },
3734: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) },
3735: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) },
3736: { GEN8_SP_CHICKEN_BITS_2, 0x00820800, BIT(PIPE_NONE) },
3737: { GEN8_SP_CHICKEN_BITS_3, 0x00300000, BIT(PIPE_NONE) },
3738: { GEN8_SP_PERFCTR_SHADER_MASK, 0x0000003f, BIT(PIPE_NONE) },
--- LINES 3820-3846 ---
3820: };
3821:
3822: extern const struct gen8_snapshot_block_list gen8_1_0_snapshot_block_list;
3823:
3824: static const struct adreno_gen8_core adreno_gpu_core_gen8_1_0 = {
3825: .base = {
3826: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_1_0,
3827: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
3828: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION |
3829: ADRENO_SOFTFUSE | ADRENO_ACD | ADRENO_PREEMPTION | ADRENO_AQE,
3830: .gpudev = &adreno_gen8_hwsched_gpudev.base,
3831: .perfcounters = &adreno_gen8_perfcounters,
3832: .uche_gmem_alignment = SZ_64M,
3833: .gmem_size = 21 * SZ_1M,
3834: .bus_width = 32,
3835: .snapshot_size = SZ_8M,
3836: .num_ddr_channels = 4,
3837: /* bits[7:4] patched at runtime with active slice count */
3838: .chipid = 0x44070001,
3839: .speedbins = KGSL_SPEEDBINS(
3840: { 0, 0 },
3841: { 388, 1 },
3842: { 357, 2 },
3843: { 284, 3 },
3844: ),
3845: .ubwc_mode = 5,
3846: .mal = 32,
--- LINES 3858-3894 ---
3858: .hang_detect_cycles = 0xcfffff,
3859: .protected_regs = gen8_1_0_protected_regs,
3860: .nonctxt_regs = gen8_1_0_nonctxt_regs,
3861: .gmu_hub_clk_freq = 200000000,
3862: .gen8_snapshot_block_list = &gen8_1_0_snapshot_block_list,
3863: .fast_bus_hint = true,
3864: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4),
3865: .noc_timeout_us = 3410, /* 3.41 msec */
3866: .ctxt_record_size = (23088 * SZ_1K),
3867: .preempt_level = 1,
3868: };
3869:
3870: static const struct adreno_gen8_core adreno_gpu_core_gen8_5_0 = {
3871: .base = {
3872: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_5_0,
3873: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
3874: .compatible = "qcom,adreno-gpu-gen8-5-0",
3875: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION |
3876: ADRENO_LPAC | ADRENO_AQE | ADRENO_GMU_WARMBOOT | ADRENO_IFPC |
3877: ADRENO_CONTENT_PROTECTION | ADRENO_HW_FENCE | ADRENO_BCL |
3878: ADRENO_GMU_AB | ADRENO_GMU_BASED_DCVS | ADRENO_GMU_THERMAL_MITIGATION |
3879: ADRENO_DEFER_GMEM_ALLOC | ADRENO_GMU_MINBW |
3880: ADRENO_TSENSE_DYNAMIC_PERIOD | ADRENO_DCVS_PROFILE,
3881: .gpudev = &adreno_gen8_hwsched_gpudev.base,
3882: .perfcounters = &adreno_gen8_2_x_perfcounters,
3883: .uche_gmem_alignment = SZ_64M,
3884: .gmem_size = 18 * SZ_1M,
3885: .bus_width = 32,
3886: .snapshot_size = SZ_8M,
3887: .num_ddr_channels = 4,
3888: .highest_bank_bit = 16,
3889: },
3890: .aqefw_name = "gen80200_aqe.fw",
3891: .sqefw_name = "gen80200_sqe.fw",
3892: .gmufw_name = "gen80200_gmu.bin",
3893: .zap_name = "gen80200_zap.mbn",
3894: .ao_hwcg = gen8_2_0_ao_hwcg_regs,
--- LINES 3902-3938 ---
3902: .gen8_snapshot_block_list = &gen8_2_0_snapshot_block_list,
3903: .fast_bus_hint = true,
3904: .bcl_data = GEN8_2_X_BCL_DATA,
3905: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4),
3906: .noc_timeout_us = 3410, /* 3.41 msec */
3907: .cl_no_ft_timeout_ms = 6500,
3908: .ctxt_record_size = (19708 * SZ_1K),
3909: .therm_cfg = &therm_mit_cfg_8_2_0,
3910: .limits_mit_cfg = &gen8_2_0_limits_mit_cfg,
3911: .preempt_level = 1,
3912: .clx_tbl = &gen8_2_0_clx_table,
3913: };
3914:
3915: /* GEN8_4_0 noncontext register list */
3916: static const struct gen8_nonctxt_regs gen8_4_0_nonctxt_regs[] = {
3917: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) },
3918: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BR) | BIT(PIPE_BV) },
3919: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) },
3920: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BR) | BIT(PIPE_BV) },
3921: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BR) | BIT(PIPE_BV) },
3922: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) | BIT(PIPE_BV) },
3923: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BR) | BIT(PIPE_BV) },
3924: /* Disable BR throttling */
3925: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BR) | BIT(PIPE_BV) },
3926: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) },
3927: /* Configure GBIF GX registers */
3928: { GEN8_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) },
3929: /* Reset value of RBBM_GBIF_CLIENT_QOS_CNTL is 0. So, no need to program explicitly. */
3930: /* Enable full concurrent resolve and unresolves */
3931: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) },
3932: { GEN8_RB_GC_GMEM_PROTECT, 0x0c000000, BIT(PIPE_BR) },
3933: /* Configure number of outstanding transactions to 32 */
3934: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) },
3935: /* Configure UCHE request time out to 16 cycles for CCU/UCHE arbitration */
3936: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) },
3937: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) },
3938: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) },
--- LINES 3983-4036 ---
3983:
3984: static const struct adreno_gen8_core adreno_gpu_core_gen8_4_0 = {
3985: .base = {
3986: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_4_0,
3987: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
3988: .compatible = "qcom,adreno-gpu-gen8-4-0",
3989: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
3990: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_AQE |
3991: ADRENO_GMU_WARMBOOT | ADRENO_L3_VOTE | ADRENO_IFPC |
3992: ADRENO_BCL | ADRENO_ACD | ADRENO_HW_FENCE |
3993: ADRENO_PREEMPTION | ADRENO_GMU_AB,
3994: .gpudev = &adreno_gen8_hwsched_gpudev.base,
3995: .perfcounters = &adreno_gen8_perfcounters,
3996: .uche_gmem_alignment = SZ_64M,
3997: .gmem_size = 12 * SZ_1M,
3998: .bus_width = 32,
3999: .snapshot_size = SZ_8M,
4000: .num_ddr_channels = 4,
4001: .highest_bank_bit = 16,
4002: },
4003: .aqefw_name = "gen80000_aqe.fw",
4004: .sqefw_name = "gen80000_sqe.fw",
4005: .gmufw_name = "gen80000_gmu.bin",
4006: .zap_name = "gen80000_zap.mbn",
4007: .ao_hwcg = gen8_ao_hwcg_regs,
4008: .ao_hwcg_count = ARRAY_SIZE(gen8_ao_hwcg_regs),
4009: .gbif = gen8_0_0_gbif_cx_regs,
4010: .gbif_count = ARRAY_SIZE(gen8_0_0_gbif_cx_regs),
4011: .hang_detect_cycles = 0xcfffff,
4012: .protected_regs = gen8_0_0_protected_regs,
4013: .nonctxt_regs = gen8_4_0_nonctxt_regs,
4014: .gmu_hub_clk_freq = 200000000,
4015: .gen8_snapshot_block_list = &gen8_0_0_snapshot_block_list,
4016: .qos_value = gen8_4_0_gbif_client_qos_values,
4017: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4),
4018: .bcl_data = 1,
4019: .preempt_level = 1,
4020: .ctxt_record_size = (13536 * SZ_1K),
4021: .noc_timeout_us = 3410, /* 3.41 msec */
4022: .cl_no_ft_timeout_ms = 10000,
4023: };
4024:
4025: extern const struct gen8_snapshot_block_list gen8_3_0_snapshot_block_list;
4026:
4027: static const struct kgsl_regmap_list gen8_3_0_gbif_cx_regs[] = {
4028: { GEN8_GBIF_QSB_SIDE0, 0x00071e20 },
4029: { GEN8_GBIF_QSB_SIDE1, 0x00071e20 },
4030: { GEN8_GBIF_QSB_SIDE2, 0x00071e20 },
4031: { GEN8_GBIF_QSB_SIDE3, 0x00071e20 },
4032: { GEN8_GBIF_CX_CONFIG, 0x20023000 },
4033: };
4034:
4035: static const struct kgsl_regmap_list gen8_8_0_gbif_cx_regs[] = {
4036: { GEN8_GBIF_QSB_SIDE0, 0x00071e20 },
--- LINES 4040-4066 ---
4040: { GEN8_GBIF_CX_CONFIG, 0x40023000 },
4041: };
4042:
4043: /* GEN8_3_0 noncontext register list */
4044: static const struct gen8_nonctxt_regs gen8_3_0_nonctxt_regs[] = {
4045: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) },
4046: { GEN8_GRAS_DBG_ECO_CNTL, 0x00f80800, BIT(PIPE_BV) | BIT(PIPE_BR) },
4047: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) },
4048: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) },
4049: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) },
4050: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) },
4051: { GEN8_PC_CHICKEN_BITS_1, 0x00000023, BIT(PIPE_BV) }, /* Avoid partial waves at VFD */
4052: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) },
4053: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BV) | BIT(PIPE_BR) },
4054: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) },
4055: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) },
4056: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) },
4057: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) },
4058: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) },
4059: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) },
4060: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) },
4061: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) },
4062: { GEN8_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) },
4063: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) },
4064: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) },
4065: { GEN8_SP_CHICKEN_BITS_2, BIT(22) | BIT(23), BIT(PIPE_NONE) },
4066: { GEN8_SP_CHICKEN_BITS_3, 0x00300000, BIT(PIPE_NONE) },
--- LINES 4085-4144 ---
4085: { 0 },
4086: };
4087:
4088: static const struct adreno_gen8_core adreno_gpu_core_gen8_3_0 = {
4089: .base = {
4090: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_3_0,
4091: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
4092: .compatible = "qcom,adreno-gpu-gen8-3-0",
4093: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
4094: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | ADRENO_PREEMPTION |
4095: ADRENO_GMU_AB,
4096: .gpudev = &adreno_gen8_hwsched_gpudev.base,
4097: .perfcounters = &adreno_gen8_perfcounters,
4098: .uche_gmem_alignment = SZ_64M,
4099: .gmem_size = (SZ_512K + SZ_64K),
4100: .bus_width = 32,
4101: .snapshot_size = SZ_8M,
4102: .num_ddr_channels = 2,
4103: .highest_bank_bit = 15,
4104: },
4105: .sqefw_name = "gen80300_sqe.fw",
4106: .gmufw_name = "gen80300_gmu.bin",
4107: .zap_name = "gen80300_zap.mbn",
4108: .ao_hwcg = gen8_ao_hwcg_regs,
4109: .ao_hwcg_count = ARRAY_SIZE(gen8_ao_hwcg_regs),
4110: .gbif = gen8_3_0_gbif_cx_regs,
4111: .gbif_count = ARRAY_SIZE(gen8_3_0_gbif_cx_regs),
4112: .hang_detect_cycles = 0xcfffff,
4113: .protected_regs = gen8_0_0_protected_regs, /* Reuse the protected regs list from Gen8_0_0 */
4114: .nonctxt_regs = gen8_3_0_nonctxt_regs,
4115: .gmu_hub_clk_freq = 200000000,
4116: .gen8_snapshot_block_list = &gen8_3_0_snapshot_block_list,
4117: .ctxt_record_size = (4558 * SZ_1K),
4118: .preempt_level = 1,
4119: };
4120:
4121: /* GEN8_6_0 noncontext register list */
4122: static const struct gen8_nonctxt_regs gen8_6_0_nonctxt_regs[] = {
4123: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) },
4124: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BR) | BIT(PIPE_BV) },
4125: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) },
4126: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BR) | BIT(PIPE_BV) },
4127: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BR) | BIT(PIPE_BV) },
4128: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) | BIT(PIPE_BV) },
4129: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BR) | BIT(PIPE_BV) },
4130: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BR) | BIT(PIPE_BV) },
4131: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) },
4132: /* Configure GBIF GX registers */
4133: { GEN8_UCHE_GBIF_GX_CONFIG, 0x010240e0, BIT(PIPE_NONE) },
4134: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) },
4135: /* Enable full concurrent resolve and unresolves */
4136: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) },
4137: { GEN8_RB_GC_GMEM_PROTECT, 0x02600000, BIT(PIPE_BR) },
4138: /* Configure number of outstanding transactions to 32 */
4139: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) },
4140: /* Configure UCHE request time out to 16 cycles for CCU/UCHE arbitration */
4141: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) },
4142: { GEN8_RBBM_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) },
4143: { GEN8_RBBM_SLICE_NC_MODE_CNTL, 0x00000001, BIT(PIPE_NONE) },
4144: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) },
--- LINES 4186-4272 ---
4186:
4187: static const struct adreno_gen8_core adreno_gpu_core_gen8_6_0 = {
4188: .base = {
4189: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_6_0,
4190: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
4191: .compatible = "qcom,adreno-gpu-gen8-6-0",
4192: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
4193: ADRENO_CONTENT_PROTECTION | ADRENO_LPAC | ADRENO_AQE |
4194: ADRENO_GMU_WARMBOOT | ADRENO_L3_VOTE | ADRENO_IFPC |
4195: ADRENO_PREEMPTION | ADRENO_BCL | ADRENO_ACD | ADRENO_GMU_AB,
4196: .gpudev = &adreno_gen8_hwsched_gpudev.base,
4197: .perfcounters = &adreno_gen8_perfcounters,
4198: .uche_gmem_alignment = SZ_64M,
4199: .gmem_size = (SZ_2M + SZ_256K + SZ_128K),
4200: .bus_width = 32,
4201: .snapshot_size = SZ_8M,
4202: .num_ddr_channels = 4,
4203: .highest_bank_bit = 16,
4204: },
4205: .aqefw_name = "gen80000_aqe.fw",
4206: .sqefw_name = "gen80000_sqe.fw",
4207: .gmufw_name = "gen80600_gmu.bin",
4208: .zap_name = "gen80000_zap.mbn",
4209: .ao_hwcg = gen8_ao_hwcg_regs,
4210: .ao_hwcg_count = ARRAY_SIZE(gen8_ao_hwcg_regs),
4211: .gbif = gen8_3_0_gbif_cx_regs,
4212: .gbif_count = ARRAY_SIZE(gen8_3_0_gbif_cx_regs),
4213: .hang_detect_cycles = 0xcfffff,
4214: .protected_regs = gen8_0_0_protected_regs,
4215: .nonctxt_regs = gen8_6_0_nonctxt_regs,
4216: .gmu_hub_clk_freq = 200000000,
4217: .gen8_snapshot_block_list = &gen8_6_0_snapshot_block_list,
4218: .noc_timeout_us = 6800, /* 6.8 msec */
4219: .ctxt_record_size = (3372 * SZ_1K),
4220: .preempt_level = 1,
4221: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4),
4222: .bcl_data = 1,
4223: };
4224:
4225: static const struct adreno_gen8_core adreno_gpu_core_gen8_8_0 = {
4226: .base = {
4227: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_8_0,
4228: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
4229: .compatible = "qcom,adreno-gpu-gen8-8-0",
4230: .features = ADRENO_APRIV | ADRENO_IOCOHERENT |
4231: ADRENO_CONTENT_PROTECTION | ADRENO_IFPC | ADRENO_PREEMPTION |
4232: ADRENO_HW_FENCE | ADRENO_BCL | ADRENO_GMU_AB,
4233: .gpudev = &adreno_gen8_hwsched_gpudev.base,
4234: .perfcounters = &adreno_gen8_perfcounters,
4235: .uche_gmem_alignment = SZ_64M,
4236: .gmem_size = (SZ_512K + SZ_64K),
4237: .bus_width = 32,
4238: .snapshot_size = SZ_8M,
4239: .num_ddr_channels = 1,
4240: .highest_bank_bit = 14,
4241: },
4242: .sqefw_name = "gen80300_sqe.fw",
4243: .gmufw_name = "gen80800_gmu.bin",
4244: .zap_name = "gen80300_zap.mbn",
4245: .ao_hwcg = gen8_ao_hwcg_regs,
4246: .ao_hwcg_count = ARRAY_SIZE(gen8_ao_hwcg_regs),
4247: .gbif = gen8_8_0_gbif_cx_regs,
4248: .gbif_count = ARRAY_SIZE(gen8_8_0_gbif_cx_regs),
4249: .hang_detect_cycles = 0xcfffff,
4250: .protected_regs = gen8_0_0_protected_regs, /* Reuse the protected regs list from Gen8_0_0 */
4251: .nonctxt_regs = gen8_3_0_nonctxt_regs,
4252: .gmu_hub_clk_freq = 200000000,
4253: .gen8_snapshot_block_list = &gen8_3_0_snapshot_block_list,
4254: .ctxt_record_size = (4558 * SZ_1K),
4255: .preempt_level = 1,
4256: .noc_timeout_us = 3410, /* 3.41 msec */
4257: .bcl_data = 1,
4258: };
4259:
4260: /* GEN8_9_0 noncontext register list */
4261: static const struct gen8_nonctxt_regs gen8_9_0_nonctxt_regs[] = {
4262: { GEN8_RBBM_GBIF_CLIENT_QOS_CNTL, 0x22122212, BIT(PIPE_NONE) },
4263: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL, 0x00000030, BIT(PIPE_NONE) },
4264: { GEN8_RBBM_WAIT_IDLE_CLOCKS_CNTL2, 0x00000030, BIT(PIPE_NONE) },
4265: /* Disable Dead Draw Merge scheme on RB-HLSQ */
4266: { GEN8_RB_RBP_CNTL, BIT(5), BIT(PIPE_BV) | BIT(PIPE_BR) },
4267: { GEN8_RBBM_INTERFACE_HANG_INT_CNTL, 0x0fffffff, BIT(PIPE_NONE) },
4268: { GEN8_RBBM_POWER_UP_RESET_SW_OVERRIDE, 0x70809060, BIT(PIPE_NONE) },
4269: { GEN8_RBBM_POWER_UP_RESET_SW_BV_OVERRIDE, 0x30000000, BIT(PIPE_NONE) },
4270: { GEN8_RBBM_CGC_P2S_CNTL, 0x00000040, BIT(PIPE_NONE) },
4271: /* Disable mode_switch optimization in UMAS */
4272: { GEN8_SP_CHICKEN_BITS, BIT(26), BIT(PIPE_NONE) },
--- LINES 4289-4315 ---
4289: { GEN8_RB_GC_GMEM_PROTECT, 0x02600000, BIT(PIPE_BR) },
4290: { GEN8_RB_RESOLVE_PREFETCH_CNTL, 0x00000007, BIT(PIPE_BR) },
4291: { GEN8_RB_CMP_DBG_ECO_CNTL, 0x00004000, BIT(PIPE_BR) },
4292: { GEN8_VPC_FLATSHADE_MODE_CNTL, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) },
4293: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BR) | BIT(PIPE_BV) },
4294: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BR) | BIT(PIPE_BV) },
4295: { GEN8_PC_CHICKEN_BITS_3, 0x00500000, BIT(PIPE_BR) | BIT(PIPE_BV) },
4296: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) },
4297: { GEN8_PC_CHICKEN_BITS_1, 0x00000003, BIT(PIPE_BR) | BIT(PIPE_BV) },
4298: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BR) | BIT(PIPE_BV) },
4299: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BR) | BIT(PIPE_BV) },
4300: { GEN8_VFD_DBG_ECO_CNTL, 0x00008000, BIT(PIPE_BR) | BIT(PIPE_BV) },
4301: { GEN8_VFD_CB_BV_THRESHOLD, 0x00500050, BIT(PIPE_BR) | BIT(PIPE_BV) },
4302: { GEN8_VFD_CB_BR_THRESHOLD, 0x00600060, BIT(PIPE_BR) | BIT(PIPE_BV) },
4303: { GEN8_VFD_CB_BUSY_REQ_CNT, 0x00200020, BIT(PIPE_BR) | BIT(PIPE_BV) },
4304: { GEN8_VFD_CB_LP_REQ_CNT, 0x00000020, BIT(PIPE_BR) | BIT(PIPE_BV) },
4305: { GEN8_SP_CHICKEN_BITS_3, 0x00300000, BIT(PIPE_NONE) },
4306: { GEN8_SP_PERFCTR_SHADER_MASK, 0x0000003f, BIT(PIPE_NONE) },
4307: /* Ignore HLSQ shared constant feedback from SP */
4308: { GEN8_SP_HLSQ_DBG_ECO_CNTL_1, BIT(17), BIT(PIPE_NONE) },
4309: /* Disable CS dead batch merge */
4310: { GEN8_SP_HLSQ_DBG_ECO_CNTL_2, BIT(24), BIT(PIPE_NONE) },
4311: { GEN8_SP_HLSQ_TIMEOUT_THRESHOLD_DP, 0x00000080, BIT(PIPE_NONE) },
4312: { GEN8_SP_READ_SEL, 0x0001ff00, BIT(PIPE_NONE) },
4313: { GEN8_TPL1_DBG_ECO_CNTL, 0x10100000, BIT(PIPE_NONE) },
4314: { GEN8_TPL1_DBG_ECO_CNTL1, 0x04000720, BIT(PIPE_NONE) },
4315: { 0 },
--- LINES 4319-4346 ---
4319:
4320: static const struct adreno_gen8_core adreno_gpu_core_gen8_9_0 = {
4321: .base = {
4322: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_9_0,
4323: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
4324: .compatible = "qcom,adreno-gpu-gen8-9-0",
4325: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_LPAC |
4326: ADRENO_GMU_WARMBOOT | ADRENO_AQE | ADRENO_IFPC |
4327: ADRENO_CONTENT_PROTECTION | ADRENO_GMU_BASED_DCVS |
4328: ADRENO_DEFER_GMEM_ALLOC | ADRENO_PREEMPTION | ADRENO_GMU_AB |
4329: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_HW_FENCE |
4330: ADRENO_DCVS_PROFILE | ADRENO_GMU_MINBW |
4331: ADRENO_BCL | ADRENO_ACD,
4332: .gpudev = &adreno_gen8_hwsched_gpudev.base,
4333: .perfcounters = &adreno_gen8_perfcounters,
4334: .uche_gmem_alignment = SZ_64M,
4335: .gmem_size = 2432 * SZ_1K,
4336: .bus_width = 32,
4337: .snapshot_size = SZ_8M,
4338: .num_ddr_channels = 4,
4339: .highest_bank_bit = 16,
4340: },
4341: .aqefw_name = "gen80900_aqe.fw",
4342: .sqefw_name = "gen80900_sqe.fw",
4343: .gmufw_name = "gen80900_gmu.bin",
4344: .zap_name = "gen80900_zap.mbn",
4345: .ao_hwcg = gen8_2_0_ao_hwcg_regs,
4346: .ao_hwcg_count = ARRAY_SIZE(gen8_2_0_ao_hwcg_regs),
--- LINES 4350-4386 ---
4350: .protected_regs = gen8_2_0_protected_regs,
4351: .nonctxt_regs = gen8_9_0_nonctxt_regs,
4352: .gmu_hub_clk_freq = 200000000,
4353: .gen8_snapshot_block_list = &gen8_9_0_snapshot_block_list,
4354: .fast_bus_hint = true,
4355: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4),
4356: .noc_timeout_us = 3410, /* 3.41 msec */
4357: .cl_no_ft_timeout_ms = 6500,
4358: .ctxt_record_size = (3708 * SZ_1K),
4359: .preempt_level = 1,
4360: .therm_cfg = &therm_mit_cfg_8_2_0,
4361: .bcl_data = 1,
4362: };
4363:
4364: static const struct adreno_a6xx_core adreno_gpu_core_a623 = {
4365: .base = {
4366: DEFINE_ADRENO_REV(ADRENO_REV_A623, 6, 2, 3, ANY_ID),
4367: .features = ADRENO_APRIV |
4368: ADRENO_IOCOHERENT | ADRENO_CONTENT_PROTECTION |
4369: ADRENO_PREEMPTION | ADRENO_ACD,
4370: .gpudev = &adreno_a6xx_gmu_gpudev.base,
4371: .perfcounters = &adreno_a6xx_perfcounters,
4372: .uche_gmem_alignment = SZ_1M + SZ_512K,
4373: .gmem_size = SZ_512K,
4374: .bus_width = 32,
4375: .snapshot_size = SZ_2M,
4376: .chipid = 0x06020300,
4377: .speedbins = KGSL_SPEEDBINS(
4378: { 0, 0 },
4379: { 185, 0 },
4380: { 127, 1 },
4381: ),
4382: .ubwc_mode = 4,
4383: .mal = 32,
4384: .highest_bank_bit = 16,
4385: },
4386: .prim_fifo_threshold = 0x0010000,
--- LINES 4402-4429 ---
4402: };
4403:
4404: extern const struct gen8_snapshot_block_list gen8_10_0_snapshot_block_list;
4405:
4406: static const struct adreno_gen8_core adreno_gpu_core_gen8_10_0 = {
4407: .base = {
4408: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_10_0,
4409: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
4410: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_BCL | ADRENO_ACD
4411: | ADRENO_IFPC | ADRENO_CONTENT_PROTECTION | ADRENO_PREEMPTION,
4412: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION |
4413: ADRENO_CONTENT_PROTECTION | ADRENO_SOFTFUSE,
4414: .compatible = "qcom,adreno-gpu-gen8-10-0",
4415: .gpudev = &adreno_gen8_hwsched_gpudev.base,
4416: .perfcounters = &adreno_gen8_perfcounters,
4417: .uche_gmem_alignment = SZ_64M,
4418: .gmem_size = (15 * SZ_1M + 768 * SZ_1K),
4419: .bus_width = 32,
4420: .snapshot_size = SZ_8M,
4421: .num_ddr_channels = 8,
4422: .chipid = 0x44060000,
4423: .speedbins = KGSL_SPEEDBINS(
4424: { 0, 0 },
4425: { 388, 1 },
4426: { 357, 2 },
4427: { 284, 3 },
4428: ),
4429: .ubwc_mode = 5,
--- LINES 4444-4470 ---
4444: .nonctxt_regs = gen8_1_0_nonctxt_regs,
4445: .gmu_hub_clk_freq = 200000000,
4446: .fast_bus_hint = true,
4447: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4),
4448: .noc_timeout_us = 3410, /* 3.41 msec */
4449: .cl_no_ft_timeout_ms = 6500,
4450: .ctxt_record_size = (23088 * SZ_1K),
4451: .bcl_data = 1,
4452: .gen8_snapshot_block_list = &gen8_10_0_snapshot_block_list,
4453: .preempt_level = 1,
4454: };
4455:
4456: static const struct hfi_clx_table_v2_cmd gen8_11_0_clx_table = {
4457: .version = (2 << 16) | 1,
4458: .domain = {
4459: /* GFX domain */
4460: {
4461: .data0 = CLX_DATA(60, 5, 0, 1),
4462: .clxt = 0,
4463: .clxh = 0,
4464: .urgmode = 1,
4465: .lkgen = 0,
4466: .currbudget = 100,
4467: },
4468: /* MxG domain */
4469: {
4470: .data0 = CLX_DATA(30, 1, 1, 1),
--- LINES 4630-4656 ---
4630: /* GEN8_11_0 noncontext register list */
4631: static const struct gen8_nonctxt_regs gen8_11_0_nonctxt_regs[] = {
4632: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) },
4633: { GEN8_CP_MULTIDRAW_CNTL, 0x00000001, BIT(PIPE_NONE) },
4634: { GEN8_GRAS_DBG_ECO_CNTL, 0x00000800, BIT(PIPE_BV) | BIT(PIPE_BR) },
4635: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) },
4636: { GEN8_GRAS_NC_MODE_CNTL, 0x00000220, BIT(PIPE_BV) | BIT(PIPE_BR) },
4637: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) },
4638: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) },
4639: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) },
4640: /* BIT(11): Disable skipIdx to avoid PDMA hang with restart-index draws */
4641: { GEN8_PC_CHICKEN_BITS_1, 0x00000803, BIT(PIPE_BV) | BIT(PIPE_BR) },
4642: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) },
4643: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BV) | BIT(PIPE_BR) },
4644: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) },
4645: /*
4646: * BIT(28): Disable GS Quad primitive
4647: * BIT(30): Disable skipIdx to avoid PDMA hang with restart-index draws
4648: */
4649: { GEN8_PC_CHICKEN_BITS_5, BIT(28) | BIT(30), BIT(PIPE_BV) | BIT(PIPE_BR) },
4650: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) },
4651: /*
4652: * BIT(10): Disable sysmem nonfclear feature
4653: * BIT(9): Disable DINT to c/z be data forwarding
4654: */
4655: { GEN8_RB_CCU_DBG_ECO_CNTL, BIT(10) | BIT(9), BIT(PIPE_BR) },
4656: { GEN8_RB_CCU_NC_MODE_CNTL, 0x00000002, BIT(PIPE_BR) },
--- LINES 4753-4796 ---
4753: .gmu_hub_clk_freq = 150000000,
4754: .gen8_snapshot_block_list = &gen8_11_0_snapshot_block_list,
4755: .fast_bus_hint = true,
4756: .bcl_data = 1,
4757: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(2736, 4),
4758: .noc_timeout_us = 3410, /* 3.41 msec */
4759: .cl_no_ft_timeout_ms = 6500,
4760: .ctxt_record_size = (19708 * SZ_1K),
4761: .limits_mit_cfg = &gen8_11_0_limits_mit_cfg,
4762: .preempt_level = 1,
4763: .gmu_mx_gdsc = true,
4764: .three_rail_memory = true,
4765: .malu = true,
4766: .clx_tbl = &gen8_11_0_clx_table,
4767: };
4768:
4769: /* GEN8_11_1 noncontext register list */
4770: static const struct gen8_nonctxt_regs gen8_11_1_nonctxt_regs[] = {
4771: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) },
4772: { GEN8_CP_MULTIDRAW_CNTL, 0x00000001, BIT(PIPE_NONE) },
4773: /* Keep the raster direction as topleft */
4774: { GEN8_GRAS_DBG_ECO_CNTL, 0x01000800, BIT(PIPE_BV) | BIT(PIPE_BR) },
4775: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) },
4776: /* GEN8_GRAS_NC_MODE_CNTL explicitly set elsewhere */
4777: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) },
4778: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) },
4779: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) },
4780: /* BIT(11): Disable skipIdx to avoid PDMA hang with restart-index draws */
4781: { GEN8_PC_CHICKEN_BITS_1, 0x00000803, BIT(PIPE_BV) | BIT(PIPE_BR) },
4782: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) },
4783: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BV) | BIT(PIPE_BR) },
4784: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) },
4785: /*
4786: * BIT(28): Disable GS Quad primitive
4787: * BIT(30): Disable skipIdx to avoid PDMA hang with restart-index draws
4788: */
4789: { GEN8_PC_CHICKEN_BITS_5, BIT(28) | BIT(30), BIT(PIPE_BV) | BIT(PIPE_BR) },
4790: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) },
4791: /*
4792: * BIT(10): Disable sysmem nonfclear feature
4793: * BIT(9): Disable DINT to c/z be data forwarding
4794: */
4795: { GEN8_RB_CCU_DBG_ECO_CNTL, BIT(10) | BIT(9), BIT(PIPE_BR) },
4796: /* GEN8_RB_CCU_NC_MODE_CNTL explicitly set elsewhere */
--- LINES 4854-4886 ---
4854: { GEN8_VSC_VISIBILITY_FLUSH_CNTL, 0x00080004, BIT(PIPE_NONE) },
4855: { 0 },
4856: };
4857:
4858: static const struct adreno_gen8_core adreno_gpu_core_gen8_11_1 = {
4859: .base = {
4860: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_11_1,
4861: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
4862: .compatible = "qcom,adreno-gpu-gen8-11-1",
4863: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_LPAC | ADRENO_PREEMPTION |
4864: ADRENO_GMU_WARMBOOT | ADRENO_GMU_BASED_DCVS | ADRENO_CLX |
4865: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_AQE | ADRENO_CONTENT_PROTECTION |
4866: ADRENO_BCL | ADRENO_DCVS_PROFILE | ADRENO_IFPC | ADRENO_GMU_MINBW |
4867: ADRENO_DEFER_GMEM_ALLOC | ADRENO_GMU_FAST_CONTEXT_DESTROY |
4868: ADRENO_ACD | ADRENO_GMU_AB | ADRENO_HW_FENCE,
4869: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION |
4870: ADRENO_IFPC | ADRENO_AQE | ADRENO_CONTENT_PROTECTION | ADRENO_CLX |
4871: ADRENO_GMU_FAST_CONTEXT_DESTROY | ADRENO_GMU_BASED_DCVS | ADRENO_ACD,
4872: .gpudev = &adreno_gen8_hwsched_gpudev.base,
4873: .perfcounters = &adreno_gen8_2_x_perfcounters,
4874: .uche_gmem_alignment = SZ_64M,
4875: .gmem_size = 18 * SZ_1M,
4876: .bus_width = 32,
4877: .snapshot_size = SZ_8M,
4878: .num_ddr_channels = 4,
4879: .highest_bank_bit = 16,
4880: .chipid = 0x44051401,
4881: .speedbins = KGSL_SPEEDBINS(
4882: { 0, 0 },
4883: { 284, 2 },
4884: { 216, 3 },
4885: ),
4886: .ubwc_mode = 7,
--- LINES 4900-4942 ---
4900: .gmu_hub_clk_freq = 150000000,
4901: .gen8_snapshot_block_list = &gen8_11_0_snapshot_block_list,
4902: .fast_bus_hint = true,
4903: .bcl_data = GEN8_2_X_BCL_DATA,
4904: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(4224, 4),
4905: .noc_timeout_us = 3410, /* 3.41 msec */
4906: .cl_no_ft_timeout_ms = 6500,
4907: .ctxt_record_size = (19708 * SZ_1K),
4908: .limits_mit_cfg = &gen8_11_0_limits_mit_cfg,
4909: .preempt_level = 1,
4910: .gmu_mx_gdsc = true,
4911: .three_rail_memory = true,
4912: .malu = true,
4913: .clx_tbl = &gen8_11_0_clx_table,
4914: };
4915:
4916: static const struct gen8_nonctxt_regs gen8_14_0_nonctxt_regs[] = {
4917: { GEN8_CP_SMMU_STREAM_ID_LPAC, 0x00000101, BIT(PIPE_NONE) },
4918: { GEN8_CP_MULTIDRAW_CNTL, 0x00000001, BIT(PIPE_NONE) },
4919: /* Keep the raster direction as topleft */
4920: { GEN8_GRAS_DBG_ECO_CNTL, 0x01000800, BIT(PIPE_BV) | BIT(PIPE_BR) },
4921: { GEN8_GRAS_TSEFE_DBG_ECO_CNTL, 0x00200000, BIT(PIPE_BV) | BIT(PIPE_BR) },
4922: /* GEN8_GRAS_NC_MODE_CNTL explicitly set elsewhere */
4923: { GEN8_PC_AUTO_VERTEX_STRIDE, 0x00000001, BIT(PIPE_BV) | BIT(PIPE_BR) },
4924: { GEN8_PC_VIS_STREAM_CNTL, 0x10010000, BIT(PIPE_BV) | BIT(PIPE_BR) },
4925: { GEN8_PC_CONTEXT_SWITCH_STABILIZE_CNTL_1, 0x00000002, BIT(PIPE_BV) | BIT(PIPE_BR) },
4926: /* BIT(11): Disable skipIdx to avoid PDMA hang with restart-index draws */
4927: { GEN8_PC_CHICKEN_BITS_1, 0x00000803, BIT(PIPE_BV) | BIT(PIPE_BR) },
4928: { GEN8_PC_CHICKEN_BITS_2, 0x00000200, BIT(PIPE_BV) | BIT(PIPE_BR) },
4929: { GEN8_PC_CHICKEN_BITS_3, 0x00400000, BIT(PIPE_BV) | BIT(PIPE_BR) },
4930: { GEN8_PC_CHICKEN_BITS_4, 0x00500050, BIT(PIPE_BV) | BIT(PIPE_BR) },
4931: /*
4932: * BIT(28): Disable GS Quad primitive
4933: * BIT(30): Disable skipIdx to avoid PDMA hang with restart-index draws
4934: */
4935: { GEN8_PC_CHICKEN_BITS_5, BIT(28) | BIT(30), BIT(PIPE_BV) | BIT(PIPE_BR) },
4936: { GEN8_RB_CCU_CNTL, 0x00000068, BIT(PIPE_BR) },
4937: /*
4938: * BIT(10): Disable sysmem nonfclear feature
4939: * BIT(9): Disable DINT to c/z be data forwarding
4940: */
4941: { GEN8_RB_CCU_DBG_ECO_CNTL, BIT(10) | BIT(9), BIT(PIPE_BR) },
4942: /* GEN8_RB_CCU_NC_MODE_CNTL explicitly set elsewhere */
--- LINES 4998-5030 ---
4998: { GEN8_VSC_VISIBILITY_FLUSH_CNTL, 0x00080004, BIT(PIPE_NONE) },
4999: { 0 },
5000: };
5001:
5002: static const struct adreno_gen8_core adreno_gpu_core_gen8_14_0 = {
5003: .base = {
5004: DEFINE_ADRENO_REV(ADRENO_REV_GEN8_14_0,
5005: UINT_MAX, UINT_MAX, UINT_MAX, ANY_ID),
5006: .compatible = "qcom,adreno-gpu-gen8-14-0",
5007: .features = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_LPAC | ADRENO_PREEMPTION |
5008: ADRENO_GMU_WARMBOOT | ADRENO_GMU_BASED_DCVS |
5009: ADRENO_GMU_THERMAL_MITIGATION | ADRENO_AQE | ADRENO_CONTENT_PROTECTION |
5010: ADRENO_DCVS_PROFILE | ADRENO_IFPC | ADRENO_GMU_MINBW |
5011: ADRENO_DEFER_GMEM_ALLOC | ADRENO_GMU_FAST_CONTEXT_DESTROY |
5012: ADRENO_GMU_AB | ADRENO_HW_FENCE | ADRENO_CLX | ADRENO_ACD,
5013: .features_standard = ADRENO_APRIV | ADRENO_IOCOHERENT | ADRENO_PREEMPTION |
5014: ADRENO_IFPC | ADRENO_AQE | ADRENO_CONTENT_PROTECTION | ADRENO_CLX |
5015: ADRENO_GMU_FAST_CONTEXT_DESTROY | ADRENO_GMU_BASED_DCVS,
5016: .gpudev = &adreno_gen8_hwsched_gpudev.base,
5017: .perfcounters = &adreno_gen8_2_x_perfcounters,
5018: .uche_gmem_alignment = SZ_64M,
5019: .gmem_size = 12 * SZ_1M,
5020: .bus_width = 32,
5021: .snapshot_size = SZ_8M,
5022: .num_ddr_channels = 4,
5023: .highest_bank_bit = 16,
5024: .chipid = 0x44041400,
5025: .speedbins = KGSL_SPEEDBINS(
5026: { 0, 0 },
5027: { 216, 0 },
5028: { 284, 1 },
5029: ),
5030: .ubwc_mode = 7,
--- LINES 5043-5069 ---
5043: .nonctxt_regs = gen8_14_0_nonctxt_regs,
5044: .gmu_hub_clk_freq = 150000000,
5045: .gen8_snapshot_block_list = &gen8_11_0_snapshot_block_list,
5046: .fast_bus_hint = true,
5047: .acv_perfmode_ddr_freq = MHZ_TO_KBPS(4224, 4),
5048: .noc_timeout_us = 3410, /* 3.41 msec */
5049: .cl_no_ft_timeout_ms = 6500,
5050: .ctxt_record_size = (13564 * SZ_1K),
5051: .limits_mit_cfg = &gen8_11_0_limits_mit_cfg,
5052: .preempt_level = 1,
5053: .gmu_mx_gdsc = true,
5054: .three_rail_memory = true,
5055: .malu = false,
5056: .clx_tbl = &gen8_14_0_clx_table,
5057: };
5058:
5059: static const struct adreno_gpu_core *adreno_gpulist[] = {
5060: &adreno_gpu_core_a306, /* Deprecated */
5061: &adreno_gpu_core_a306a, /* Deprecated */
5062: &adreno_gpu_core_a304, /* Deprecated */
5063: &adreno_gpu_core_a405, /* Deprecated */
5064: &adreno_gpu_core_a418, /* Deprecated */
5065: &adreno_gpu_core_a420, /* Deprecated */
5066: &adreno_gpu_core_a430, /* Deprecated */
5067: &adreno_gpu_core_a530v1, /* Deprecated */
5068: &adreno_gpu_core_a530v2.base,
5069: &adreno_gpu_core_a530v3.base,
========== FILE: kgsl_sync.c ==========
--- LINES 7-1020 ---
7: #include <dt-bindings/soc/qcom,ipcc.h>
8: #include <linux/file.h>
9: #include <linux/slab.h>
10: #include <linux/sync_file.h>
11:
12: #include "kgsl_device.h"
13: #include "kgsl_gmu_core.h"
14: #include "kgsl_sync.h"
15:
16: const struct dma_fence_ops kgsl_sync_fence_ops;
17: static const struct dma_fence_ops kgsl_syncsource_fence_ops;
18:
19: /* Only allow a single log in a second */
20: static DEFINE_RATELIMIT_STATE(_rs, HZ, 1);
21:
22: /* List of hardware fences that haven't been destroyed */
23: struct list_head hw_fence_list;
24: /* Spinlock to protect access to hw_fence_list */
25: spinlock_t hw_fence_list_lock;
26:
27: static void destroy_all_hw_fences(void);
28: static void _hw_fence_destroy(struct kgsl_sync_fence *kfence);
29:
30: static inline void add_hw_fence(struct kgsl_sync_fence *kfence)
31: {
32: spin_lock(&hw_fence_list_lock);
33: list_add_tail(&kfence->hw_fence_list, &hw_fence_list);
34: spin_unlock(&hw_fence_list_lock);
35: }
36:
37: #ifdef CONFIG_QCOM_KGSL_SYNX
38:
39: #include <synx_api.h>
40: #include <synx_interop.h>
41:
42: static struct synx_hw_fence_descriptor {
43: /** @handle: Handle for hardware fences */
44: struct synx_session *handle;
45: /** @descriptor: Memory descriptor for hardware fences */
46: struct synx_queue_desc mem_descriptor;
47: } kgsl_synx;
48:
49: int kgsl_hw_fence_soccp_vote(bool pwr_on)
50: {
51: return synx_enable_resources(SYNX_CLIENT_HW_FENCE_GFX_CTX0, SYNX_RESOURCE_SOCCP, pwr_on);
52: }
53:
54: int kgsl_hw_fence_init(struct kgsl_device *device)
55: {
56: struct synx_initialization_params params;
57:
58: params.id = (enum synx_client_id)SYNX_CLIENT_HW_FENCE_GFX_CTX0;
59: params.ptr = &kgsl_synx.mem_descriptor;
60: kgsl_synx.handle = synx_initialize(¶ms);
61:
62: if (IS_ERR_OR_NULL(kgsl_synx.handle)) {
63: dev_err(device->dev, "HW fences not supported: %d\n",
64: PTR_ERR_OR_ZERO(kgsl_synx.handle));
65: kgsl_synx.handle = NULL;
66: return -EINVAL;
67: }
68:
69: INIT_LIST_HEAD(&hw_fence_list);
70: spin_lock_init(&hw_fence_list_lock);
71:
72: return 0;
73: }
74:
75: void kgsl_hw_fence_close(struct kgsl_device *device)
76: {
77: destroy_all_hw_fences();
78:
79: synx_uninitialize(kgsl_synx.handle);
80: }
81:
82: void kgsl_hw_fence_populate_md(struct kgsl_device *device, struct kgsl_memdesc *md)
83: {
84: md->physaddr = kgsl_synx.mem_descriptor.dev_addr;
85: md->size = kgsl_synx.mem_descriptor.size;
86: md->hostptr = kgsl_synx.mem_descriptor.vaddr;
87: }
88:
89: int kgsl_hw_fence_create(struct kgsl_device *device, struct kgsl_sync_fence *kfence)
90: {
91: struct synx_create_params params = {0};
92: int ret;
93:
94: params.fence = &kfence->fence;
95: params.h_synx = (u32 *)&kfence->hw_fence_index;
96: params.flags = SYNX_CREATE_DMA_FENCE;
97:
98: ret = synx_create(kgsl_synx.handle, ¶ms);
99: if (!ret) {
100: add_hw_fence(kfence);
101: return 0;
102: }
103:
104: if (__ratelimit(&_rs))
105: dev_err(device->dev, "Failed to create ctx:%d ts:%d hardware fence:%d\n",
106: kfence->context_id, kfence->timestamp, ret);
107:
108: return -EINVAL;
109: }
110:
111: int kgsl_hw_fence_add_waiter(struct kgsl_device *device, struct dma_fence *fence, u32 *hash_index)
112: {
113: struct synx_import_params params;
114: u32 handle = 0;
115: int ret;
116:
117: params.indv.fence = fence;
118: params.type = SYNX_IMPORT_INDV_PARAMS;
119: params.indv.new_h_synx = &handle;
120: params.indv.flags = SYNX_IMPORT_DMA_FENCE;
121:
122: ret = synx_import(kgsl_synx.handle, ¶ms);
123: if (ret) {
124: dev_err_ratelimited(device->dev,
125: "Failed to add GMU as waiter ret:%d fence ctx:%llu ts:%llu\n",
126: ret, fence->context, fence->seqno);
127: return ret;
128: }
129:
130: /* release reference held by synx_import */
131: ret = synx_release(kgsl_synx.handle, handle);
132: if (ret) {
133: dev_err_ratelimited(device->dev,
134: "Failed to release wait fences ret:%d fence ctx:%llu ts:%llu\n",
135: ret, fence->context, fence->seqno);
136: } else {
137: if (hash_index)
138: *hash_index = handle;
139: }
140:
141: return ret;
142: }
143:
144: bool kgsl_hw_fence_tx_slot_available(struct kgsl_device *device, u32 pending_hw_fence_count)
145: {
146: void *ptr = kgsl_synx.mem_descriptor.vaddr;
147: struct synx_hw_fence_hfi_queue_header *hdr = (struct synx_hw_fence_hfi_queue_header *)
148: (ptr + sizeof(struct synx_hw_fence_hfi_queue_table_header));
149: u32 queue_size_dwords = hdr->queue_size / sizeof(u32);
150: u32 payload_size_dwords = hdr->pkt_size / sizeof(u32);
151: u32 free_entries, write_idx = hdr->write_index, read_idx = hdr->read_index;
152:
153: free_entries = read_idx <= write_idx ?
154: queue_size_dwords - (write_idx - read_idx) :
155: read_idx - write_idx;
156:
157: free_entries /= payload_size_dwords;
158:
159: /* Ensure free_entries does not become negative */
160: if (free_entries == 0)
161: return false;
162:
163: free_entries -= 1;
164:
165: if (free_entries > pending_hw_fence_count)
166: return true;
167:
168: return false;
169: }
170:
171: void _hw_fence_destroy(struct kgsl_sync_fence *kfence)
172: {
173: synx_release(kgsl_synx.handle, kfence->hw_fence_index);
174:
175: /*
176: * synx_release() doesn't have a way to get to the dma fence. Hence, the client must clear
177: * this bit from the dma fence flags.
178: */
179: clear_bit(SYNX_HW_FENCE_FLAG_ENABLED_BIT, &kfence->fence.flags);
180: }
181:
182: void kgsl_hw_fence_trigger_cpu(struct kgsl_device *device, struct kgsl_sync_fence *kfence)
183: {
184: /* soccp should be powered on */
185: WARN_RATELIMIT(!test_bit(GMU_SOCCP_VOTE_ON, &device->gmu_core.flags),
186: "signaling hw fence via cpu without soccp powered up\n");
187:
188: synx_signal(kgsl_synx.handle, (u32)kfence->hw_fence_index, SYNX_STATE_SIGNALED_SUCCESS);
189: }
190:
191: bool kgsl_hw_fence_signaled(struct dma_fence *fence)
192: {
193: return test_bit(SYNX_HW_FENCE_FLAG_SIGNALED_BIT, &fence->flags);
194: }
195:
196: static bool kgsl_is_input_hw_fence(struct dma_fence *fence)
197: {
198: return test_bit(SYNX_HW_FENCE_FLAG_ENABLED_BIT, &fence->flags) ||
199: test_bit(SYNX_NATIVE_FENCE_FLAG_ENABLED_BIT, &fence->flags) || is_kgsl_fence(fence);
200: }
201:
202: static bool kgsl_is_output_hw_fence(struct dma_fence *fence)
203: {
204: return test_bit(SYNX_HW_FENCE_FLAG_ENABLED_BIT, &fence->flags);
205: }
206:
207: #else
208:
209: #if (KERNEL_VERSION(6, 3, 0) <= LINUX_VERSION_CODE)
210: #include <msm_hw_fence.h>
211: #else
212: #include <linux/soc/qcom/msm_hw_fence.h>
213: #endif
214:
215: static struct msm_hw_fence_descriptor {
216: /** @handle: Handle for hardware fences */
217: void *handle;
218: /** @descriptor: Memory descriptor for hardware fences */
219: struct msm_hw_fence_mem_addr mem_descriptor;
220: } kgsl_msm_hw_fence;
221:
222: int kgsl_hw_fence_soccp_vote(bool pwr_on)
223: {
224: return -EINVAL;
225: }
226:
227: int kgsl_hw_fence_init(struct kgsl_device *device)
228: {
229: kgsl_msm_hw_fence.handle = msm_hw_fence_register(HW_FENCE_CLIENT_ID_CTX0,
230: &kgsl_msm_hw_fence.mem_descriptor);
231:
232: if (IS_ERR_OR_NULL(kgsl_msm_hw_fence.handle)) {
233: dev_err(device->dev, "HW fences not supported: %d\n",
234: PTR_ERR_OR_ZERO(kgsl_msm_hw_fence.handle));
235: kgsl_msm_hw_fence.handle = NULL;
236: return -EINVAL;
237: }
238:
239: INIT_LIST_HEAD(&hw_fence_list);
240: spin_lock_init(&hw_fence_list_lock);
241:
242: return 0;
243: }
244:
245: void kgsl_hw_fence_close(struct kgsl_device *device)
246: {
247: destroy_all_hw_fences();
248:
249: msm_hw_fence_deregister(kgsl_msm_hw_fence.handle);
250: }
251:
252: void kgsl_hw_fence_populate_md(struct kgsl_device *device, struct kgsl_memdesc *md)
253: {
254: md->physaddr = kgsl_msm_hw_fence.mem_descriptor.device_addr;
255: md->size = kgsl_msm_hw_fence.mem_descriptor.size;
256: md->hostptr = kgsl_msm_hw_fence.mem_descriptor.virtual_addr;
257: }
258:
259: int kgsl_hw_fence_create(struct kgsl_device *device, struct kgsl_sync_fence *kfence)
260: {
261: struct msm_hw_fence_create_params params = {0};
262: int ret;
263:
264: params.fence = &kfence->fence;
265: params.handle = &kfence->hw_fence_index;
266:
267: ret = msm_hw_fence_create(kgsl_msm_hw_fence.handle, ¶ms);
268: if ((ret || IS_ERR_OR_NULL(params.handle))) {
269: if (__ratelimit(&_rs))
270: dev_err(device->dev, "Failed to create ctx:%d ts:%d hardware fence:%d\n",
271: kfence->context_id, kfence->timestamp, ret);
272: return -EINVAL;
273: }
274:
275: add_hw_fence(kfence);
276:
277: return 0;
278: }
279:
280: int kgsl_hw_fence_add_waiter(struct kgsl_device *device, struct dma_fence *fence, u32 *hash_index)
281: {
282: u64 handle = 0;
283: int ret = msm_hw_fence_wait_update_v2(kgsl_msm_hw_fence.handle, &fence, &handle, NULL, 1,
284: true);
285:
286: if (ret)
287: dev_err_ratelimited(device->dev,
288: "Failed to add GMU as waiter ret:%d fence ctx:%llu ts:%llu\n",
289: ret, fence->context, fence->seqno);
290: else {
291: if (hash_index)
292: *hash_index = (u32)handle;
293: }
294:
295: return ret;
296: }
297:
298: bool kgsl_hw_fence_tx_slot_available(struct kgsl_device *device, u32 pending_hw_fence_count)
299: {
300: void *ptr = kgsl_msm_hw_fence.mem_descriptor.virtual_addr;
301: struct msm_hw_fence_hfi_queue_header *hdr = (struct msm_hw_fence_hfi_queue_header *)
302: (ptr + sizeof(struct msm_hw_fence_hfi_queue_table_header));
303: u32 queue_size_dwords = hdr->queue_size / sizeof(u32);
304: u32 payload_size_dwords = hdr->pkt_size / sizeof(u32);
305: u32 free_entries, write_idx = hdr->write_index, read_idx = hdr->read_index;
306:
307: free_entries = read_idx <= write_idx ?
308: queue_size_dwords - (write_idx - read_idx) :
309: read_idx - write_idx;
310:
311: free_entries /= payload_size_dwords;
312:
313: /* Ensure free_entries does not become negative */
314: if (free_entries == 0)
315: return false;
316:
317: free_entries -= 1;
318:
319: if (free_entries > pending_hw_fence_count)
320: return true;
321:
322: return false;
323: }
324:
325: void _hw_fence_destroy(struct kgsl_sync_fence *kfence)
326: {
327: msm_hw_fence_destroy(kgsl_msm_hw_fence.handle, &kfence->fence);
328: }
329:
330: #define IPCC_GPU_PHYS_ID 4
331: void kgsl_hw_fence_trigger_cpu(struct kgsl_device *device, struct kgsl_sync_fence *kfence)
332: {
333: int ret = msm_hw_fence_update_txq(kgsl_msm_hw_fence.handle, kfence->hw_fence_index,
334: 0, 0);
335: if (ret) {
336: dev_err_ratelimited(device->dev,
337: "Failed to trigger hw fence via cpu: ctx:%d ts:%d ret:%d\n",
338: kfence->context_id, kfence->timestamp, ret);
339: return;
340: }
341:
342: msm_hw_fence_trigger_signal(kgsl_msm_hw_fence.handle, IPCC_GPU_PHYS_ID,
343: IPCC_CLIENT_APSS, 0);
344: }
345:
346: bool kgsl_hw_fence_signaled(struct dma_fence *fence)
347: {
348: return test_bit(MSM_HW_FENCE_FLAG_SIGNALED_BIT, &fence->flags);
349: }
350:
351: static bool kgsl_is_output_hw_fence(struct dma_fence *fence)
352: {
353: return test_bit(MSM_HW_FENCE_FLAG_ENABLED_BIT, &fence->flags);
354: }
355:
356: static bool kgsl_is_input_hw_fence(struct dma_fence *fence)
357: {
358: return test_bit(MSM_HW_FENCE_FLAG_ENABLED_BIT, &fence->flags);
359: }
360:
361: #endif
362:
363: static struct kgsl_sync_fence *kgsl_sync_fence_create(
364: struct kgsl_context *context,
365: unsigned int timestamp)
366: {
367: struct kgsl_sync_fence *kfence;
368: struct kgsl_sync_timeline *ktimeline = context->ktimeline;
369: unsigned long flags;
370:
371: /* Get a refcount to the timeline. Put when released */
372: if (!kref_get_unless_zero(&ktimeline->kref))
373: return NULL;
374:
375: kfence = kzalloc(sizeof(*kfence), GFP_KERNEL);
376: if (kfence == NULL) {
377: kgsl_sync_timeline_put(ktimeline);
378: return NULL;
379: }
380:
381: kfence->parent = ktimeline;
382: kfence->context_id = context->id;
383: kfence->timestamp = timestamp;
384:
385: dma_fence_init(&kfence->fence, &kgsl_sync_fence_ops, &ktimeline->lock,
386: ktimeline->fence_context, timestamp);
387:
388: /*
389: * sync_file_create() takes a refcount to the fence. This refcount is
390: * put when the fence is signaled.
391: */
392: kfence->sync_file = sync_file_create(&kfence->fence);
393:
394: if (kfence->sync_file == NULL) {
395: kgsl_sync_timeline_put(ktimeline);
396: dev_err(context->device->dev, "Create sync_file failed\n");
397: kfree(kfence);
398: return NULL;
399: }
400:
401: spin_lock_irqsave(&ktimeline->lock, flags);
402: list_add_tail(&kfence->child_list, &ktimeline->child_list_head);
403: spin_unlock_irqrestore(&ktimeline->lock, flags);
404:
405: return kfence;
406: }
407:
408: static void kgsl_sync_fence_release(struct dma_fence *fence)
409: {
410: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)fence;
411:
412: if (kgsl_is_output_hw_fence(fence))
413: kgsl_hw_fence_destroy(kfence);
414:
415: kgsl_sync_timeline_put(kfence->parent);
416: kfree(kfence);
417: }
418:
419: /* Called with ktimeline->lock held */
420: static bool kgsl_sync_fence_has_signaled(struct dma_fence *fence)
421: {
422: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)fence;
423: struct kgsl_sync_timeline *ktimeline = kfence->parent;
424: unsigned int ts = kfence->timestamp;
425:
426: return (timestamp_cmp(ktimeline->last_timestamp, ts) >= 0);
427: }
428:
429: static bool kgsl_enable_signaling(struct dma_fence *fence)
430: {
431: return !kgsl_sync_fence_has_signaled(fence);
432: }
433:
434: struct kgsl_sync_fence_event_priv {
435: struct kgsl_context *context;
436: unsigned int timestamp;
437: };
438:
439: /**
440: * kgsl_sync_fence_event_cb - Event callback for a fence timestamp event
441: * @device - The KGSL device that expired the timestamp
442: * @context- Pointer to the context that owns the event
443: * @priv: Private data for the callback
444: * @result - Result of the event (retired or canceled)
445: *
446: * Signal a fence following the expiration of a timestamp
447: */
448:
449: static void kgsl_sync_fence_event_cb(struct kgsl_device *device,
450: struct kgsl_event_group *group, void *priv, int result)
451: {
452: struct kgsl_sync_fence_event_priv *ev = priv;
453:
454: kgsl_sync_timeline_signal(ev->context->ktimeline, ev->timestamp);
455: kgsl_context_put(ev->context);
456: kfree(ev);
457: }
458:
459: static int _add_fence_event(struct kgsl_device *device,
460: struct kgsl_context *context, unsigned int timestamp)
461: {
462: struct kgsl_sync_fence_event_priv *event;
463: int ret;
464:
465: event = kmalloc(sizeof(*event), GFP_KERNEL);
466: if (event == NULL)
467: return -ENOMEM;
468:
469: /*
470: * Increase the refcount for the context to keep it through the
471: * callback
472: */
473: if (!_kgsl_context_get(context)) {
474: kfree(event);
475: return -ENOENT;
476: }
477:
478: event->context = context;
479: event->timestamp = timestamp;
480:
481: ret = kgsl_add_event(device, &context->events, timestamp,
482: kgsl_sync_fence_event_cb, event);
483:
484: if (ret) {
485: kgsl_context_put(context);
486: kfree(event);
487: }
488:
489: return ret;
490: }
491:
492: /* Only to be used if creating a related event failed */
493: static void kgsl_sync_cancel(struct kgsl_sync_fence *kfence)
494: {
495: spin_lock(&kfence->parent->lock);
496: if (!list_empty(&kfence->child_list)) {
497: list_del_init(&kfence->child_list);
498: dma_fence_put(&kfence->fence);
499: }
500: spin_unlock(&kfence->parent->lock);
501: }
502:
503: /**
504: * kgsl_add_fence_event - Create a new fence event
505: * @device - KGSL device to create the event on
506: * @timestamp - Timestamp to trigger the event
507: * @data - Return fence fd stored in struct kgsl_timestamp_event_fence
508: * @len - length of the fence event
509: * @owner - driver instance that owns this event
510: * @returns 0 on success or error code on error
511: *
512: * Create a fence and register an event to signal the fence when
513: * the timestamp expires
514: */
515:
516: int kgsl_add_fence_event(struct kgsl_device *device,
517: u32 context_id, u32 timestamp, void __user *data, int len,
518: struct kgsl_device_private *owner)
519: {
520: struct kgsl_timestamp_event_fence priv;
521: struct kgsl_context *context;
522: struct kgsl_sync_fence *kfence = NULL;
523: int ret = -EINVAL;
524: unsigned int cur;
525: bool retired = false;
526:
527: priv.fence_fd = -1;
528:
529: if (len != sizeof(priv))
530: return -EINVAL;
531:
532: context = kgsl_context_get_owner(owner, context_id);
533:
534: if (context == NULL)
535: return -EINVAL;
536:
537: if (test_bit(KGSL_CONTEXT_PRIV_INVALID, &context->priv))
538: goto out;
539:
540: kfence = kgsl_sync_fence_create(context, timestamp);
541: if (kfence == NULL) {
542: ret = -ENOMEM;
543: goto out;
544: }
545:
546: priv.fence_fd = get_unused_fd_flags(0);
547: if (priv.fence_fd < 0) {
548: dev_crit_ratelimited(device->dev,
549: "Unable to get a file descriptor: %d\n",
550: priv.fence_fd);
551: ret = priv.fence_fd;
552: goto out;
553: }
554:
555: /*
556: * If the timestamp hasn't expired yet create an event to trigger it.
557: * Otherwise, just signal the fence - there is no reason to go through
558: * the effort of creating a fence we don't need.
559: */
560:
561: kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, &cur);
562:
563: retired = timestamp_cmp(cur, timestamp) >= 0;
564:
565: if (retired) {
566: ret = 0;
567: kgsl_sync_timeline_signal(context->ktimeline, cur);
568: } else {
569: ret = _add_fence_event(device, context, timestamp);
570: if (ret)
571: goto out;
572: }
573:
574: if (copy_to_user(data, &priv, sizeof(priv))) {
575: ret = -EFAULT;
576: goto out;
577: }
578:
579: if (!retired)
580: device->ftbl->create_hw_fence(device, kfence);
581:
582: fd_install(priv.fence_fd, kfence->sync_file->file);
583:
584: out:
585: kgsl_context_put(context);
586: if (ret) {
587: if (priv.fence_fd >= 0)
588: put_unused_fd(priv.fence_fd);
589:
590: if (kfence) {
591: kgsl_sync_cancel(kfence);
592: /*
593: * Put the refcount of sync file. This will release
594: * kfence->fence as well.
595: */
596: fput(kfence->sync_file->file);
597: }
598: }
599: return ret;
600: }
601:
602: void kgsl_sync_timeline_value_str(struct dma_fence *fence, char *str, int size)
603: {
604: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)fence;
605: struct kgsl_sync_timeline *ktimeline = kfence->parent;
606: struct kgsl_context *context = NULL;
607: unsigned long flags;
608: int ret = 0;
609:
610: unsigned int timestamp_retired;
611: unsigned int timestamp_queued;
612:
613: if (fence->ops != &kgsl_sync_fence_ops)
614: return;
615:
616: if (!kref_get_unless_zero(&ktimeline->kref))
617: return;
618: if (!ktimeline->device)
619: goto put_timeline;
620:
621: spin_lock_irqsave(&ktimeline->lock, flags);
622: ret = _kgsl_context_get(ktimeline->context);
623: context = ret ? ktimeline->context : NULL;
624: spin_unlock_irqrestore(&ktimeline->lock, flags);
625:
626: /* Get the last signaled timestamp if the context is not valid */
627: timestamp_queued = ktimeline->last_timestamp;
628: timestamp_retired = timestamp_queued;
629: if (context) {
630: kgsl_readtimestamp(ktimeline->device, context,
631: KGSL_TIMESTAMP_RETIRED, ×tamp_retired);
632:
633: kgsl_readtimestamp(ktimeline->device, context,
634: KGSL_TIMESTAMP_QUEUED, ×tamp_queued);
635:
636: kgsl_context_put(context);
637: }
638:
639: snprintf(str, size, "%u queued:%u retired:%u",
640: ktimeline->last_timestamp,
641: timestamp_queued, timestamp_retired);
642:
643: put_timeline:
644: kgsl_sync_timeline_put(ktimeline);
645: }
646:
647: static void kgsl_sync_fence_value_str(struct dma_fence *fence,
648: char *str, int size)
649: {
650: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)fence;
651:
652: snprintf(str, size, "%u", kfence->timestamp);
653: }
654:
655: static const char *kgsl_sync_fence_driver_name(struct dma_fence *fence)
656: {
657: return "kgsl-timeline";
658: }
659:
660: static const char *kgsl_sync_timeline_name(struct dma_fence *fence)
661: {
662: struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)fence;
663: struct kgsl_sync_timeline *ktimeline = kfence->parent;
664:
665: return ktimeline->name;
666: }
667:
668: int kgsl_sync_timeline_create(struct kgsl_context *context)
669: {
670: struct kgsl_sync_timeline *ktimeline;
671:
672: /* Put context at detach time */
673: if (!_kgsl_context_get(context))
674: return -ENOENT;
675:
676: ktimeline = kzalloc(sizeof(*ktimeline), GFP_KERNEL);
677: if (ktimeline == NULL) {
678: kgsl_context_put(context);
679: return -ENOMEM;
680: }
681:
682: kref_init(&ktimeline->kref);
683: snprintf(ktimeline->name, sizeof(ktimeline->name),
684: "%s_%u-%.15s(%d)-%.15s(%d)",
685: context->device->name, context->id,
686: current->group_leader->comm, current->group_leader->pid,
687: current->comm, current->pid);
688:
689: ktimeline->fence_context = dma_fence_context_alloc(1);
690: ktimeline->last_timestamp = 0;
691: INIT_LIST_HEAD(&ktimeline->child_list_head);
692: spin_lock_init(&ktimeline->lock);
693: ktimeline->device = context->device;
694:
695: /*
696: * The context pointer is valid till detach time, where we put the
697: * refcount on the context
698: */
699: ktimeline->context = context;
700:
701: context->ktimeline = ktimeline;
702:
703: return 0;
704: }
705:
706: void kgsl_sync_timeline_signal(struct kgsl_sync_timeline *ktimeline,
707: unsigned int timestamp)
708: {
709: unsigned long flags;
710: struct kgsl_sync_fence *kfence, *next;
711:
712: if (!kref_get_unless_zero(&ktimeline->kref))
713: return;
714:
715: spin_lock_irqsave(&ktimeline->lock, flags);
716: if (timestamp_cmp(timestamp, ktimeline->last_timestamp) > 0)
717: ktimeline->last_timestamp = timestamp;
718:
719: list_for_each_entry_safe(kfence, next, &ktimeline->child_list_head,
720: child_list) {
721: if (dma_fence_is_signaled_locked(&kfence->fence)) {
722: list_del_init(&kfence->child_list);
723: dma_fence_put(&kfence->fence);
724: }
725: }
726:
727: spin_unlock_irqrestore(&ktimeline->lock, flags);
728: kgsl_sync_timeline_put(ktimeline);
729: }
730:
731: void kgsl_sync_timeline_detach(struct kgsl_sync_timeline *ktimeline)
732: {
733: unsigned long flags;
734: struct kgsl_context *context = ktimeline->context;
735:
736: /* Set context pointer to NULL and drop our refcount on the context */
737: spin_lock_irqsave(&ktimeline->lock, flags);
738: ktimeline->context = NULL;
739: spin_unlock_irqrestore(&ktimeline->lock, flags);
740: kgsl_context_put(context);
741: }
742:
743: static void kgsl_sync_timeline_destroy(struct kref *kref)
744: {
745: struct kgsl_sync_timeline *ktimeline =
746: container_of(kref, struct kgsl_sync_timeline, kref);
747:
748: kfree(ktimeline);
749: }
750:
751: void kgsl_sync_timeline_put(struct kgsl_sync_timeline *ktimeline)
752: {
753: if (ktimeline)
754: kref_put(&ktimeline->kref, kgsl_sync_timeline_destroy);
755: }
756:
757: const struct dma_fence_ops kgsl_sync_fence_ops = {
758: .get_driver_name = kgsl_sync_fence_driver_name,
759: .get_timeline_name = kgsl_sync_timeline_name,
760: .enable_signaling = kgsl_enable_signaling,
761: .signaled = kgsl_sync_fence_has_signaled,
762: .wait = dma_fence_default_wait,
763: .release = kgsl_sync_fence_release,
764:
765: #if (KERNEL_VERSION(6, 16, 0) > LINUX_VERSION_CODE)
766: .fence_value_str = kgsl_sync_fence_value_str,
767: .timeline_value_str = kgsl_sync_timeline_value_str,
768: #endif
769: };
770:
771: static void kgsl_sync_fence_callback(struct dma_fence *fence,
772: struct dma_fence_cb *cb)
773: {
774: struct kgsl_sync_fence_cb *kcb = (struct kgsl_sync_fence_cb *)cb;
775:
776: kcb->func(kcb->priv);
777: }
778:
779: bool is_kgsl_fence(struct dma_fence *f)
780: {
781: if (f->ops == &kgsl_sync_fence_ops)
782: return true;
783:
784: return false;
785: }
786:
787: void kgsl_hw_fence_destroy(struct kgsl_sync_fence *kfence)
788: {
789: spin_lock(&hw_fence_list_lock);
790:
791: if (!list_empty(&kfence->hw_fence_list)) {
792: _hw_fence_destroy(kfence);
793: list_del_init(&kfence->hw_fence_list);
794: }
795:
796: spin_unlock(&hw_fence_list_lock);
797: }
798:
799: static void destroy_all_hw_fences(void)
800: {
801: struct kgsl_sync_fence *kfence, *next;
802:
803: spin_lock(&hw_fence_list_lock);
804:
805: list_for_each_entry_safe(kfence, next, &hw_fence_list, hw_fence_list) {
806: _hw_fence_destroy(kfence);
807: list_del_init(&kfence->hw_fence_list);
808: }
809:
810: spin_unlock(&hw_fence_list_lock);
811: }
812:
813: static void kgsl_count_hw_fences(struct kgsl_drawobj_sync_event *event, struct dma_fence *fence)
814: {
815: struct kgsl_drawobj_sync *syncobj = event->syncobj;
816: u32 max_hw_fence = event->device->max_syncobj_hw_fence_count;
817:
818: if (test_bit(KGSL_SYNCOBJ_SW, &syncobj->flags))
819: return;
820:
821: if (!kgsl_is_input_hw_fence(fence)) {
822: /*
823: * Ignore software fences that are already signaled. Even one unsignaled sw-only
824: * fence in this sync object means we can't send this sync object to the hardware
825: */
826: if (!dma_fence_is_signaled(fence))
827: set_bit(KGSL_SYNCOBJ_SW, &syncobj->flags);
828: return;
829: }
830:
831: if (!syncobj->hw_fences) {
832: syncobj->hw_fences = kcalloc(max_hw_fence, sizeof(*syncobj->hw_fences), GFP_KERNEL);
833: if (!syncobj->hw_fences) {
834: set_bit(KGSL_SYNCOBJ_SW, &syncobj->flags);
835: return;
836: }
837: }
838:
839: if (syncobj->num_hw_fence < max_hw_fence)
840: syncobj->hw_fences[syncobj->num_hw_fence++].fence = fence;
841: else
842: set_bit(KGSL_SYNCOBJ_SW, &syncobj->flags);
843: }
844:
845: static void kgsl_syncsource_fence_value_str(struct dma_fence *fence, char *str, int size)
846: {
847: /*
848: * Each fence is independent of the others on the same timeline.
849: * We use a different context for each of them.
850: */
851: snprintf(str, size, "%llu", fence->context);
852: }
853:
854: #if (KERNEL_VERSION(6, 16, 0) > LINUX_VERSION_CODE)
855: static int kgsl_get_fence_value_str(struct dma_fence *fence, char *buf, size_t size)
856: {
857: int len = 0;
858:
859: if (!fence || !fence->ops || !buf)
860: return 0;
861:
862: if (fence->ops->fence_value_str) {
863: len += scnprintf(buf + len, size - len, ": ");
864: fence->ops->fence_value_str(fence, buf + len, size - len);
865: }
866:
867: return len;
868: }
869: #else
870: static int kgsl_get_fence_value_str(struct dma_fence *fence, char *buf, size_t size)
871: {
872: int len = 0;
873:
874: if (!fence || !fence->ops || !buf)
875: return 0;
876:
877: if (fence->ops == &kgsl_sync_fence_ops) {
878: len += scnprintf(buf + len, size - len, ": ");
879: kgsl_sync_fence_value_str(fence, buf + len, size - len);
880: }
881:
882: if (fence->ops == &kgsl_syncsource_fence_ops) {
883: len += scnprintf(buf + len, size - len, ": ");
884: kgsl_syncsource_fence_value_str(fence, buf + len, size - len);
885: }
886:
887: return len;
888: }
889: #endif
890:
891: void kgsl_get_fence_name(struct dma_fence *f, char *name, u32 max_size)
892: {
893: int len = scnprintf(name, max_size, "%s %s", f->ops->get_driver_name(f),
894: f->ops->get_timeline_name(f));
895:
896: len += kgsl_get_fence_value_str(f, name + len, max_size - len);
897:
898: }
899:
900: void kgsl_get_fence_info(struct kgsl_drawobj_sync_event *event)
901: {
902: unsigned int num_fences;
903: struct dma_fence *fence, **fences;
904: struct dma_fence_array *array;
905: struct event_fence_info *info_ptr = event->priv;
906: int i;
907:
908: fence = event->handle->fence;
909:
910: array = to_dma_fence_array(fence);
911: if (array != NULL) {
912: num_fences = array->num_fences;
913: fences = array->fences;
914: } else {
915: num_fences = 1;
916: fences = &fence;
917: }
918:
919: if (!info_ptr)
920: goto count;
921:
922: info_ptr->fences = kcalloc(num_fences, sizeof(struct fence_info),
923: GFP_KERNEL);
924: if (info_ptr->fences == NULL)
925: goto count;
926:
927: info_ptr->num_fences = num_fences;
928:
929: for (i = 0; i < num_fences; i++) {
930: struct dma_fence *f = fences[i];
931: struct fence_info *fi = &info_ptr->fences[i];
932:
933: kgsl_get_fence_name(f, fi->name, sizeof(fi->name));
934:
935: kgsl_count_hw_fences(event, f);
936: }
937:
938: return;
939: count:
940: for (i = 0; i < num_fences; i++)
941: kgsl_count_hw_fences(event, fences[i]);
942: }
943:
944: struct kgsl_sync_fence_cb *kgsl_sync_fence_async_wait(int fd,
945: bool (*func)(void *priv), void *priv)
946: {
947: struct kgsl_sync_fence_cb *kcb;
948: struct dma_fence *fence;
949: int status;
950:
951: fence = sync_file_get_fence(fd);
952: if (fence == NULL)
953: return ERR_PTR(-EINVAL);
954:
955: /* create the callback */
956: kcb = kzalloc(sizeof(*kcb), GFP_KERNEL);
957: if (kcb == NULL) {
958: dma_fence_put(fence);
959: return ERR_PTR(-ENOMEM);
960: }
961:
962: kcb->fence = fence;
963: kcb->priv = priv;
964: kcb->func = func;
965:
966: /* if status then error or signaled */
967: status = dma_fence_add_callback(fence, &kcb->fence_cb,
968: kgsl_sync_fence_callback);
969:
970: if (status) {
971: kfree(kcb);
972: if (!dma_fence_is_signaled(fence))
973: kcb = ERR_PTR(status);
974: else
975: kcb = NULL;
976: dma_fence_put(fence);
977: }
978:
979: return kcb;
980: }
981:
982: /*
983: * Cancel the fence async callback.
984: */
985: void kgsl_sync_fence_async_cancel(struct kgsl_sync_fence_cb *kcb)
986: {
987: if (kcb == NULL)
988: return;
989:
990: dma_fence_remove_callback(kcb->fence, &kcb->fence_cb);
991: }
992:
993: struct kgsl_syncsource {
994: struct kref refcount;
995: char name[32];
996: int id;
997: struct kgsl_process_private *private;
998: struct list_head child_list_head;
999: spinlock_t lock;
1000: };
1001:
1002: struct kgsl_syncsource_fence {
1003: struct dma_fence fence;
1004: struct kgsl_syncsource *parent;
1005: struct list_head child_list;
1006: };
1007:
1008: long kgsl_ioctl_syncsource_create(struct kgsl_device_private *dev_priv,
1009: unsigned int cmd, void *data)
1010: {
1011: struct kgsl_syncsource *syncsource = NULL;
1012: struct kgsl_syncsource_create *param = data;
1013: int ret = -EINVAL;
1014: int id = 0;
1015: struct kgsl_process_private *private = dev_priv->process_priv;
1016:
1017: if (!kgsl_process_private_get(private))
1018: return ret;
1019:
1020: syncsource = kzalloc(sizeof(*syncsource), GFP_KERNEL);
--- LINES 1087-1125 ---
1087: void kgsl_syncsource_put(struct kgsl_syncsource *syncsource)
1088: {
1089: if (syncsource)
1090: kref_put(&syncsource->refcount, kgsl_syncsource_destroy);
1091: }
1092:
1093: static void kgsl_syncsource_cleanup(struct kgsl_process_private *private,
1094: struct kgsl_syncsource *syncsource)
1095: {
1096: struct kgsl_syncsource_fence *sfence, *next;
1097: unsigned long flags;
1098:
1099: /* Signal all fences to release any callbacks */
1100: spin_lock_irqsave(&syncsource->lock, flags);
1101:
1102: list_for_each_entry_safe(sfence, next, &syncsource->child_list_head,
1103: child_list) {
1104: dma_fence_signal_locked(&sfence->fence);
1105: list_del_init(&sfence->child_list);
1106: }
1107:
1108: spin_unlock_irqrestore(&syncsource->lock, flags);
1109:
1110: /* put reference from syncsource creation */
1111: kgsl_syncsource_put(syncsource);
1112: }
1113:
1114: long kgsl_ioctl_syncsource_destroy(struct kgsl_device_private *dev_priv,
1115: unsigned int cmd, void *data)
1116: {
1117: struct kgsl_syncsource_destroy *param = data;
1118: struct kgsl_syncsource *syncsource = NULL;
1119: struct kgsl_process_private *private = dev_priv->process_priv;
1120:
1121: spin_lock(&private->syncsource_lock);
1122: syncsource = idr_find(&private->syncsource_idr, param->id);
1123:
1124: if (syncsource == NULL) {
1125: spin_unlock(&private->syncsource_lock);
--- LINES 1130-1337 ---
1130: idr_remove(&private->syncsource_idr, syncsource->id);
1131: syncsource->id = 0;
1132: }
1133: spin_unlock(&private->syncsource_lock);
1134:
1135: kgsl_syncsource_cleanup(private, syncsource);
1136: return 0;
1137: }
1138:
1139: long kgsl_ioctl_syncsource_create_fence(struct kgsl_device_private *dev_priv,
1140: unsigned int cmd, void *data)
1141: {
1142: struct kgsl_syncsource_create_fence *param = data;
1143: struct kgsl_syncsource *syncsource = NULL;
1144: int ret = -EINVAL;
1145: struct kgsl_syncsource_fence *sfence = NULL;
1146: struct sync_file *sync_file = NULL;
1147: int fd = -1;
1148: unsigned long flags;
1149:
1150: /*
1151: * Take a refcount that is released when the fence is released
1152: * (or if fence can't be added to the syncsource).
1153: */
1154: syncsource = kgsl_syncsource_get(dev_priv->process_priv,
1155: param->id);
1156: if (syncsource == NULL)
1157: goto out;
1158:
1159: sfence = kzalloc(sizeof(*sfence), GFP_KERNEL);
1160: if (sfence == NULL) {
1161: ret = -ENOMEM;
1162: goto out;
1163: }
1164: sfence->parent = syncsource;
1165:
1166: /* Use a new fence context for each fence */
1167: dma_fence_init(&sfence->fence, &kgsl_syncsource_fence_ops,
1168: &syncsource->lock, dma_fence_context_alloc(1), 1);
1169:
1170: sync_file = sync_file_create(&sfence->fence);
1171:
1172: if (sync_file == NULL) {
1173: dev_err(dev_priv->device->dev,
1174: "Create sync_file failed\n");
1175: ret = -ENOMEM;
1176: goto out;
1177: }
1178:
1179: fd = get_unused_fd_flags(0);
1180: if (fd < 0) {
1181: ret = -EBADF;
1182: goto out;
1183: }
1184: ret = 0;
1185:
1186: fd_install(fd, sync_file->file);
1187:
1188: param->fence_fd = fd;
1189:
1190: spin_lock_irqsave(&syncsource->lock, flags);
1191: list_add_tail(&sfence->child_list, &syncsource->child_list_head);
1192: spin_unlock_irqrestore(&syncsource->lock, flags);
1193: out:
1194: /*
1195: * We're transferring ownership of the fence to the sync file.
1196: * The sync file takes an extra refcount when it is created, so put
1197: * our refcount.
1198: */
1199: if (sync_file)
1200: dma_fence_put(&sfence->fence);
1201:
1202: if (ret) {
1203: if (sync_file)
1204: fput(sync_file->file);
1205: else if (sfence)
1206: dma_fence_put(&sfence->fence);
1207: else
1208: kgsl_syncsource_put(syncsource);
1209: }
1210:
1211: return ret;
1212: }
1213:
1214: static int kgsl_syncsource_signal(struct kgsl_syncsource *syncsource,
1215: struct dma_fence *fence)
1216: {
1217: struct kgsl_syncsource_fence *sfence, *next;
1218: int ret = -EINVAL;
1219: unsigned long flags;
1220:
1221: spin_lock_irqsave(&syncsource->lock, flags);
1222:
1223: list_for_each_entry_safe(sfence, next, &syncsource->child_list_head,
1224: child_list) {
1225: if (fence == &sfence->fence) {
1226: dma_fence_signal_locked(fence);
1227: list_del_init(&sfence->child_list);
1228:
1229: ret = 0;
1230: break;
1231: }
1232: }
1233:
1234: spin_unlock_irqrestore(&syncsource->lock, flags);
1235:
1236: return ret;
1237: }
1238:
1239: long kgsl_ioctl_syncsource_signal_fence(struct kgsl_device_private *dev_priv,
1240: unsigned int cmd, void *data)
1241: {
1242: int ret = -EINVAL;
1243: struct kgsl_syncsource_signal_fence *param = data;
1244: struct kgsl_syncsource *syncsource = NULL;
1245: struct dma_fence *fence = NULL;
1246:
1247: syncsource = kgsl_syncsource_get(dev_priv->process_priv,
1248: param->id);
1249: if (syncsource == NULL)
1250: goto out;
1251:
1252: fence = sync_file_get_fence(param->fence_fd);
1253: if (fence == NULL) {
1254: ret = -EBADF;
1255: goto out;
1256: }
1257:
1258: ret = kgsl_syncsource_signal(syncsource, fence);
1259: out:
1260: if (fence)
1261: dma_fence_put(fence);
1262: if (syncsource)
1263: kgsl_syncsource_put(syncsource);
1264: return ret;
1265: }
1266:
1267: static void kgsl_syncsource_fence_release(struct dma_fence *fence)
1268: {
1269: struct kgsl_syncsource_fence *sfence =
1270: (struct kgsl_syncsource_fence *)fence;
1271:
1272: /* Signal if it's not signaled yet */
1273: kgsl_syncsource_signal(sfence->parent, fence);
1274:
1275: /* Release the refcount on the syncsource */
1276: kgsl_syncsource_put(sfence->parent);
1277:
1278: kfree(sfence);
1279: }
1280:
1281: void kgsl_syncsource_process_release_syncsources(
1282: struct kgsl_process_private *private)
1283: {
1284: struct kgsl_syncsource *syncsource;
1285: int next = 0;
1286:
1287: while (1) {
1288: spin_lock(&private->syncsource_lock);
1289: syncsource = idr_get_next(&private->syncsource_idr, &next);
1290:
1291: if (syncsource == NULL) {
1292: spin_unlock(&private->syncsource_lock);
1293: break;
1294: }
1295:
1296: if (syncsource->id != 0) {
1297: idr_remove(&private->syncsource_idr, syncsource->id);
1298: syncsource->id = 0;
1299: }
1300: spin_unlock(&private->syncsource_lock);
1301:
1302: kgsl_syncsource_cleanup(private, syncsource);
1303: next = next + 1;
1304: }
1305: }
1306:
1307: static const char *kgsl_syncsource_get_timeline_name(struct dma_fence *fence)
1308: {
1309: struct kgsl_syncsource_fence *sfence =
1310: (struct kgsl_syncsource_fence *)fence;
1311: struct kgsl_syncsource *syncsource = sfence->parent;
1312:
1313: return syncsource->name;
1314: }
1315:
1316: static bool kgsl_syncsource_enable_signaling(struct dma_fence *fence)
1317: {
1318: return true;
1319: }
1320:
1321: static const char *kgsl_syncsource_driver_name(struct dma_fence *fence)
1322: {
1323: return "kgsl-syncsource-timeline";
1324: }
1325:
1326: static const struct dma_fence_ops kgsl_syncsource_fence_ops = {
1327: .get_driver_name = kgsl_syncsource_driver_name,
1328: .get_timeline_name = kgsl_syncsource_get_timeline_name,
1329: .enable_signaling = kgsl_syncsource_enable_signaling,
1330: .wait = dma_fence_default_wait,
1331: .release = kgsl_syncsource_fence_release,
1332:
1333: #if (KERNEL_VERSION(6, 16, 0) > LINUX_VERSION_CODE)
1334: .fence_value_str = kgsl_syncsource_fence_value_str,
1335: #endif
1336: };
1337:
========== FILE: kgsl_events.c ==========
--- LINES 12-421 ---
12: #include "kgsl_eventlog.h"
13: #include "kgsl_trace.h"
14:
15: /*
16: * Define an kmem cache for the event structures since we allocate and free them
17: * so frequently
18: */
19: static struct kmem_cache *events_cache;
20:
21: static inline void signal_event(struct kgsl_device *device,
22: struct kgsl_event *event, int result)
23: {
24: list_del(&event->node);
25: event->result = result;
26: kthread_queue_work(device->events_worker, &event->work);
27: }
28:
29: /**
30: * _kgsl_event_worker() - Work handler for processing GPU event callbacks
31: * @work: Pointer to the kthread_work for the event
32: *
33: * Each event callback has its own kthread_work struct and is run on a event specific
34: * worker thread. This is the worker that queues up the event callback function.
35: */
36: static void _kgsl_event_worker(struct kthread_work *work)
37: {
38: struct kgsl_event *event = container_of(work, struct kgsl_event, work);
39: int id = KGSL_CONTEXT_ID(event->context);
40:
41: trace_kgsl_fire_event(id, event->timestamp, event->result,
42: jiffies - event->created, event->func);
43:
44: log_kgsl_fire_event(id, event->timestamp, event->result,
45: jiffies - event->created);
46:
47: event->func(event->device, event->group, event->priv, event->result);
48:
49: kgsl_context_put(event->context);
50: kmem_cache_free(events_cache, event);
51: }
52:
53: /* return true if the group needs to be processed */
54: static bool _do_process_group(unsigned int processed, unsigned int cur)
55: {
56: if (processed == cur)
57: return false;
58:
59: /*
60: * This ensures that the timestamp didn't slip back accidently, maybe
61: * due to a memory barrier issue. This is highly unlikely but we've
62: * been burned here in the past.
63: */
64: if ((cur < processed) && ((processed - cur) < KGSL_TIMESTAMP_WINDOW))
65: return false;
66:
67: return true;
68: }
69:
70: static void _process_event_group(struct kgsl_device *device,
71: struct kgsl_event_group *group, bool flush)
72: {
73: struct kgsl_event *event, *tmp;
74: unsigned int timestamp;
75: struct kgsl_context *context;
76:
77: if (group == NULL)
78: return;
79:
80: context = group->context;
81:
82: /*
83: * Sanity check to be sure that we aren't racing with the context
84: * getting destroyed
85: */
86: if (WARN_ON(context != NULL && !_kgsl_context_get(context)))
87: return;
88:
89: spin_lock(&group->lock);
90:
91: group->readtimestamp(device, group->priv, KGSL_TIMESTAMP_RETIRED,
92: ×tamp);
93:
94: if (!flush && !_do_process_group(group->processed, timestamp))
95: goto out;
96:
97: list_for_each_entry_safe(event, tmp, &group->events, node) {
98: if (timestamp_cmp(event->timestamp, timestamp) <= 0)
99: signal_event(device, event, KGSL_EVENT_RETIRED);
100: else if (flush)
101: signal_event(device, event, KGSL_EVENT_CANCELLED);
102:
103: }
104:
105: group->processed = timestamp;
106:
107: out:
108: spin_unlock(&group->lock);
109: kgsl_context_put(context);
110: }
111:
112: /**
113: * kgsl_process_event_group() - Handle all the retired events in a group
114: * @device: Pointer to a KGSL device
115: * @group: Pointer to a GPU events group to process
116: */
117:
118: void kgsl_process_event_group(struct kgsl_device *device,
119: struct kgsl_event_group *group)
120: {
121: _process_event_group(device, group, false);
122: }
123:
124: /**
125: * kgsl_flush_event_group() - flush all the events in a group by retiring the
126: * ones can be retired and cancelling the ones that are pending
127: * @device: Pointer to a KGSL device
128: * @group: Pointer to a GPU events group to process
129: */
130: void kgsl_flush_event_group(struct kgsl_device *device,
131: struct kgsl_event_group *group)
132: {
133: _process_event_group(device, group, true);
134: }
135:
136: /**
137: * kgsl_cancel_events_timestamp() - Cancel pending events for a given timestamp
138: * @device: Pointer to a KGSL device
139: * @group: Ponter to the GPU event group that owns the event
140: * @timestamp: Registered expiry timestamp for the event
141: */
142: void kgsl_cancel_events_timestamp(struct kgsl_device *device,
143: struct kgsl_event_group *group, unsigned int timestamp)
144: {
145: struct kgsl_event *event, *tmp;
146:
147: spin_lock(&group->lock);
148:
149: list_for_each_entry_safe(event, tmp, &group->events, node) {
150: if (timestamp_cmp(timestamp, event->timestamp) == 0)
151: signal_event(device, event, KGSL_EVENT_CANCELLED);
152: }
153:
154: spin_unlock(&group->lock);
155: }
156:
157: /**
158: * kgsl_cancel_events() - Cancel all pending events in the group
159: * @device: Pointer to a KGSL device
160: * @group: Pointer to a kgsl_events_group
161: */
162: void kgsl_cancel_events(struct kgsl_device *device,
163: struct kgsl_event_group *group)
164: {
165: struct kgsl_event *event, *tmp;
166:
167: spin_lock(&group->lock);
168:
169: list_for_each_entry_safe(event, tmp, &group->events, node)
170: signal_event(device, event, KGSL_EVENT_CANCELLED);
171:
172: spin_unlock(&group->lock);
173: }
174:
175: /**
176: * kgsl_cancel_event() - Cancel a specific event from a group
177: * @device: Pointer to a KGSL device
178: * @group: Pointer to the group that contains the events
179: * @timestamp: Registered expiry timestamp for the event
180: * @func: Registered callback for the function
181: * @priv: Registered priv data for the function
182: */
183: void kgsl_cancel_event(struct kgsl_device *device,
184: struct kgsl_event_group *group, unsigned int timestamp,
185: kgsl_event_func func, void *priv)
186: {
187: struct kgsl_event *event, *tmp;
188:
189: spin_lock(&group->lock);
190:
191: list_for_each_entry_safe(event, tmp, &group->events, node) {
192: if (timestamp == event->timestamp && func == event->func &&
193: event->priv == priv) {
194: signal_event(device, event, KGSL_EVENT_CANCELLED);
195: break;
196: }
197: }
198:
199: spin_unlock(&group->lock);
200: }
201:
202: /**
203: * kgsl_event_pending() - Searches for an event in an event group
204: * @device: Pointer to a KGSL device
205: * @group: Pointer to the group that contains the events
206: * @timestamp: Registered expiry timestamp for the event
207: * @func: Registered callback for the function
208: * @priv: Registered priv data for the function
209: */
210: bool kgsl_event_pending(struct kgsl_device *device,
211: struct kgsl_event_group *group,
212: unsigned int timestamp, kgsl_event_func func, void *priv)
213: {
214: struct kgsl_event *event;
215: bool result = false;
216:
217: spin_lock(&group->lock);
218: list_for_each_entry(event, &group->events, node) {
219: if (timestamp == event->timestamp && func == event->func &&
220: event->priv == priv) {
221: result = true;
222: break;
223: }
224: }
225: spin_unlock(&group->lock);
226: return result;
227: }
228: /**
229: * kgsl_add_event() - Add a new GPU event to a group
230: * @device: Pointer to a KGSL device
231: * @group: Pointer to the group to add the event to
232: * @timestamp: Timestamp that the event will expire on
233: * @func: Callback function for the event
234: * @priv: Private data to send to the callback function
235: */
236: int kgsl_add_event(struct kgsl_device *device, struct kgsl_event_group *group,
237: unsigned int timestamp, kgsl_event_func func, void *priv)
238: {
239: unsigned int queued;
240: struct kgsl_context *context = group->context;
241: struct kgsl_event *event;
242: unsigned int retired;
243:
244: if (!func)
245: return -EINVAL;
246:
247: /*
248: * If the caller is creating their own timestamps, let them schedule
249: * events in the future. Otherwise only allow timestamps that have been
250: * queued.
251: */
252: if (!context || !(context->flags & KGSL_CONTEXT_USER_GENERATED_TS)) {
253: group->readtimestamp(device, group->priv, KGSL_TIMESTAMP_QUEUED,
254: &queued);
255:
256: if (timestamp_cmp(timestamp, queued) > 0)
257: return -EINVAL;
258: }
259:
260: event = kmem_cache_alloc(events_cache, GFP_KERNEL);
261: if (event == NULL)
262: return -ENOMEM;
263:
264: /* Get a reference to the context while the event is active */
265: if (context != NULL && !_kgsl_context_get(context)) {
266: kmem_cache_free(events_cache, event);
267: return -ENOENT;
268: }
269:
270: event->device = device;
271: event->context = context;
272: event->timestamp = timestamp;
273: event->priv = priv;
274: event->func = func;
275: event->created = jiffies;
276: event->group = group;
277:
278: kthread_init_work(&event->work, _kgsl_event_worker);
279:
280: trace_kgsl_register_event(KGSL_CONTEXT_ID(context), timestamp, func);
281:
282: spin_lock(&group->lock);
283:
284: /*
285: * Check to see if the requested timestamp has already retired. If so,
286: * schedule the callback right away
287: */
288: group->readtimestamp(device, group->priv, KGSL_TIMESTAMP_RETIRED,
289: &retired);
290:
291: if (timestamp_cmp(retired, timestamp) >= 0) {
292: event->result = KGSL_EVENT_RETIRED;
293: kthread_queue_work(device->events_worker, &event->work);
294: spin_unlock(&group->lock);
295: return 0;
296: }
297:
298: /* Add the event to the group list */
299: list_add_tail(&event->node, &group->events);
300:
301: spin_unlock(&group->lock);
302:
303: return 0;
304: }
305:
306: void kgsl_process_event_groups(struct kgsl_device *device)
307: {
308: struct kgsl_event_group *group;
309:
310: read_lock(&device->event_groups_lock);
311: list_for_each_entry(group, &device->event_groups, group)
312: _process_event_group(device, group, false);
313: read_unlock(&device->event_groups_lock);
314: }
315:
316: void kgsl_del_event_group(struct kgsl_device *device,
317: struct kgsl_event_group *group)
318: {
319: /* Check if the group is uninintalized */
320: if (!group->context)
321: return;
322:
323: /* Make sure that all the events have been deleted from the list */
324: WARN_ON(!list_empty(&group->events));
325:
326: write_lock(&device->event_groups_lock);
327: list_del(&group->group);
328: write_unlock(&device->event_groups_lock);
329: }
330:
331: void kgsl_add_event_group(struct kgsl_device *device,
332: struct kgsl_event_group *group, struct kgsl_context *context,
333: readtimestamp_func readtimestamp,
334: void *priv, const char *fmt, ...)
335: {
336: va_list args;
337:
338: WARN_ON(readtimestamp == NULL);
339:
340: spin_lock_init(&group->lock);
341: INIT_LIST_HEAD(&group->events);
342:
343: group->context = context;
344: group->readtimestamp = readtimestamp;
345: group->priv = priv;
346:
347: if (fmt) {
348: va_start(args, fmt);
349: vsnprintf(group->name, sizeof(group->name), fmt, args);
350: va_end(args);
351: }
352:
353: write_lock(&device->event_groups_lock);
354: list_add_tail(&group->group, &device->event_groups);
355: write_unlock(&device->event_groups_lock);
356: }
357:
358: static void events_debugfs_print_group(struct seq_file *s,
359: struct kgsl_event_group *group)
360: {
361: struct kgsl_event *event;
362: unsigned int retired;
363:
364: spin_lock(&group->lock);
365:
366: seq_printf(s, "%s: last=%d\n", group->name, group->processed);
367:
368: list_for_each_entry(event, &group->events, node) {
369:
370: group->readtimestamp(event->device, group->priv,
371: KGSL_TIMESTAMP_RETIRED, &retired);
372:
373: seq_printf(s, "\t%u:%u age=%lu func=%ps [retired=%u]\n",
374: group->context ? group->context->id :
375: KGSL_MEMSTORE_GLOBAL,
376: event->timestamp, jiffies - event->created,
377: event->func, retired);
378: }
379: spin_unlock(&group->lock);
380: }
381:
382: static int events_show(struct seq_file *s, void *unused)
383: {
384: struct kgsl_device *device = s->private;
385: struct kgsl_event_group *group;
386:
387: seq_puts(s, "event groups:\n");
388: seq_puts(s, "--------------\n");
389:
390: read_lock(&device->event_groups_lock);
391: list_for_each_entry(group, &device->event_groups, group) {
392: events_debugfs_print_group(s, group);
393: seq_puts(s, "\n");
394: }
395: read_unlock(&device->event_groups_lock);
396:
397: return 0;
398: }
399:
400: DEFINE_SHOW_ATTRIBUTE(events);
401:
402: void kgsl_device_events_remove(struct kgsl_device *device)
403: {
404: struct kgsl_event_group *group, *tmp;
405:
406: write_lock(&device->event_groups_lock);
407: list_for_each_entry_safe(group, tmp, &device->event_groups, group) {
408: WARN_ON(!list_empty(&group->events));
409: list_del(&group->group);
410: }
411: write_unlock(&device->event_groups_lock);
412: }
413:
414: void kgsl_device_events_probe(struct kgsl_device *device)
415: {
416: INIT_LIST_HEAD(&device->event_groups);
417: rwlock_init(&device->event_groups_lock);
418:
419: debugfs_create_file("events", 0444, device->d_debugfs, device,
420: &events_fops);
421: }
========== FILE: kgsl_iommu.c ==========
--- LINES 72-155 ---
72: return &((iommu->user_context).adreno_smmu);
73: }
74:
75: /* These are dummy TLB ops for the io-pgtable instances */
76:
77: static void _tlb_flush_all(void *cookie)
78: {
79: }
80:
81: static void _tlb_flush_walk(unsigned long iova, size_t size,
82: size_t granule, void *cookie)
83: {
84: }
85:
86: static void _tlb_add_page(struct iommu_iotlb_gather *gather,
87: unsigned long iova, size_t granule, void *cookie)
88: {
89: }
90:
91: static const struct iommu_flush_ops kgsl_iopgtbl_tlb_ops = {
92: .tlb_flush_all = _tlb_flush_all,
93: .tlb_flush_walk = _tlb_flush_walk,
94: .tlb_add_page = _tlb_add_page,
95: };
96:
97: static struct kgsl_iommu_pt *to_iommu_pt(struct kgsl_pagetable *pagetable)
98: {
99: return container_of(pagetable, struct kgsl_iommu_pt, base);
100: }
101:
102: static u32 get_llcc_flags(struct kgsl_mmu *mmu)
103: {
104: if (!test_bit(KGSL_MMU_LLCC_ENABLE, &mmu->features))
105: return 0;
106:
107: /* Return no-write-allocate if mmu feature for no-write-allocate is set */
108: if (test_bit(KGSL_MMU_FORCE_LLCC_NWA, &mmu->features))
109: return IOMMU_SYS_CACHE_NWA;
110:
111: /* Return 0 as default llcc allocation policy */
112: return 0;
113: }
114:
115: static int _iommu_get_protection_flags(struct kgsl_mmu *mmu,
116: struct kgsl_memdesc *memdesc)
117: {
118: int flags = IOMMU_READ | IOMMU_WRITE | IOMMU_NOEXEC;
119:
120: flags |= get_llcc_flags(mmu);
121:
122: if (memdesc->flags & KGSL_MEMFLAGS_GPUREADONLY)
123: flags &= ~IOMMU_WRITE;
124:
125: if (TEST_FLAG(KGSL_MEMDESC_PRIVILEGED, &memdesc->priv))
126: flags |= IOMMU_PRIV;
127:
128: if (memdesc->flags & KGSL_MEMFLAGS_IOCOHERENT)
129: flags |= IOMMU_CACHE;
130:
131: if (TEST_FLAG(KGSL_MEMDESC_UCODE, &memdesc->priv))
132: flags &= ~IOMMU_NOEXEC;
133:
134: return flags;
135: }
136:
137: /* Get a scattterlist for the subrange in the child memdesc */
138: static int get_sg_from_child(struct sg_table *sgt, struct kgsl_memdesc *child,
139: u64 offset, u64 length)
140: {
141: int npages = (length >> PAGE_SHIFT);
142: int pgoffset = (offset >> PAGE_SHIFT);
143: struct scatterlist *target_sg;
144: struct sg_page_iter iter;
145: int i = 0, ret;
146:
147: if (child->pages)
148: return sg_alloc_table_from_pages(sgt,
149: child->pages + pgoffset, npages, 0,
150: length, GFP_KERNEL);
151:
152: ret = sg_alloc_table(sgt, npages, GFP_KERNEL);
153: if (ret)
154: return ret;
155:
--- LINES 177-225 ---
177: }
178:
179: /*
180: * One page allocation for a guard region to protect against over-zealous
181: * GPU pre-fetch
182: */
183: static struct page *kgsl_guard_page;
184: static struct page *kgsl_secure_guard_page;
185:
186: static struct page *iommu_get_guard_page(struct kgsl_memdesc *memdesc)
187: {
188: if (kgsl_memdesc_is_secured(memdesc)) {
189: if (!kgsl_secure_guard_page)
190: kgsl_secure_guard_page = kgsl_alloc_secure_page();
191:
192: return kgsl_secure_guard_page;
193: }
194:
195: if (!kgsl_guard_page)
196: kgsl_guard_page = alloc_page(GFP_KERNEL | __GFP_ZERO |
197: __GFP_NORETRY | __GFP_HIGHMEM);
198:
199: return kgsl_guard_page;
200: }
201:
202: static size_t iommu_pgsize(unsigned long pgsize_bitmap, unsigned long iova,
203: phys_addr_t paddr, size_t size, size_t *count)
204: {
205: unsigned int pgsize_idx, pgsize_idx_next;
206: unsigned long pgsizes;
207: size_t offset, pgsize, pgsize_next;
208: unsigned long addr_merge = paddr | iova;
209:
210: /* Page sizes supported by the hardware and small enough for @size */
211: pgsizes = pgsize_bitmap & GENMASK(__fls(size), 0);
212:
213: /* Constrain the page sizes further based on the maximum alignment */
214: if (likely(addr_merge))
215: pgsizes &= GENMASK(__ffs(addr_merge), 0);
216:
217: /* Make sure we have at least one suitable page size */
218: if (!pgsizes)
219: return 0;
220:
221: /* Pick the biggest page size remaining */
222: pgsize_idx = __fls(pgsizes);
223: pgsize = BIT(pgsize_idx);
224: if (!count)
225: return pgsize;
--- LINES 230-256 ---
230: goto out_set_count;
231:
232: pgsize_idx_next = __ffs(pgsizes);
233: pgsize_next = BIT(pgsize_idx_next);
234:
235: /*
236: * There's no point trying a bigger page size unless the virtual
237: * and physical addresses are similarly offset within the larger page.
238: */
239: if ((iova ^ paddr) & (pgsize_next - 1))
240: goto out_set_count;
241:
242: /* Calculate the offset to the next page size alignment boundary */
243: offset = pgsize_next - (addr_merge & (pgsize_next - 1));
244:
245: /*
246: * If size is big enough to accommodate the larger page, reduce
247: * the number of smaller pages.
248: */
249: if (offset + pgsize_next <= size)
250: size = offset;
251:
252: out_set_count:
253: *count = size >> pgsize_idx;
254: return pgsize;
255: }
256:
--- LINES 264-366 ---
264: /* As LPAC is optional, check LPAC domain is present before flush */
265: if (iommu->lpac_context.domain)
266: iommu_flush_iotlb_all(to_iommu_domain(&iommu->lpac_context));
267:
268: /* Flush iotbl for GMU domian */
269: if (device->gmu_core.domain)
270: iommu_flush_iotlb_all(device->gmu_core.domain);
271: }
272:
273: static int _iopgtbl_unmap(struct kgsl_iommu_pt *pt, u64 gpuaddr, size_t size)
274: {
275: struct io_pgtable_ops *ops = pt->pgtbl_ops;
276: size_t unmapped = 0;
277:
278: while (unmapped < size) {
279: size_t ret, size_to_unmap, remaining, pgcount;
280:
281: remaining = (size - unmapped);
282: size_to_unmap = iommu_pgsize(pt->cfg.pgsize_bitmap,
283: gpuaddr, gpuaddr, remaining, &pgcount);
284: if (size_to_unmap == 0)
285: break;
286:
287: ret = ops->unmap_pages(ops, gpuaddr, size_to_unmap,
288: pgcount, NULL);
289:
290: if (ret == 0)
291: break;
292:
293: gpuaddr += ret;
294: unmapped += ret;
295: }
296:
297: if (unmapped != size)
298: return -EINVAL;
299:
300: kgsl_iommu_flush_tlb(pt->base.mmu);
301: return 0;
302: }
303:
304: static size_t _iopgtbl_map_pages(struct kgsl_iommu_pt *pt, u64 gpuaddr,
305: struct page **pages, int npages, int prot)
306: {
307: struct io_pgtable_ops *ops = pt->pgtbl_ops;
308: size_t mapped = 0;
309: u64 addr = gpuaddr;
310: int ret, i;
311:
312: for (i = 0; i < npages; i++) {
313: ret = ops->map_pages(ops, addr, page_to_phys(pages[i]), PAGE_SIZE, 1,
314: prot, GFP_KERNEL, &mapped);
315: if (ret) {
316: _iopgtbl_unmap(pt, gpuaddr, mapped);
317: return 0;
318: }
319: addr += PAGE_SIZE;
320: }
321:
322: return mapped;
323: }
324:
325: static size_t _iopgtbl_map_sg(struct kgsl_iommu_pt *pt, u64 gpuaddr,
326: struct sg_table *sgt, int prot)
327: {
328: struct io_pgtable_ops *ops = pt->pgtbl_ops;
329: struct scatterlist *sg;
330: size_t mapped = 0;
331: u64 addr = gpuaddr;
332: int ret, i;
333:
334: for_each_sg(sgt->sgl, sg, sgt->nents, i) {
335: size_t size = sg->length;
336: phys_addr_t phys = sg_phys(sg);
337:
338: while (size) {
339: size_t count, map_size = 0;
340: size_t pgsize = iommu_pgsize(pt->cfg.pgsize_bitmap,
341: addr, phys, size, &count);
342:
343: ret = ops->map_pages(ops, addr, phys, pgsize, count,
344: prot, GFP_KERNEL, &map_size);
345:
346: mapped += map_size;
347:
348: if (ret) {
349: _iopgtbl_unmap(pt, gpuaddr, mapped);
350: return 0;
351: }
352:
353: addr += map_size;
354: phys += map_size;
355: size -= map_size;
356: }
357:
358: }
359:
360: return mapped;
361: }
362:
363: static void kgsl_iommu_send_tlb_hint(struct kgsl_mmu *mmu, bool hint)
364: {
365: struct kgsl_device *device = KGSL_MMU_DEVICE(mmu);
366: struct kgsl_iommu *iommu = &mmu->iommu;
--- LINES 379-736 ---
379: * TLB operations are skipped during slumber. Incase CX doesn't
380: * go down, it can result in incorrect translations due to stale
381: * TLB entries. Flush TLB before boot up to ensure fresh start.
382: */
383: if (!hint)
384: kgsl_iommu_flush_tlb(mmu);
385: }
386:
387: static int
388: kgsl_iopgtbl_map_child(struct kgsl_pagetable *pt, struct kgsl_memdesc *memdesc,
389: u64 offset, struct kgsl_memdesc *child, u64 child_offset, u64 length)
390: {
391: struct kgsl_iommu_pt *iommu_pt = to_iommu_pt(pt);
392: struct sg_table sgt;
393: u32 flags;
394: size_t mapped;
395: int ret;
396:
397: ret = get_sg_from_child(&sgt, child, child_offset, length);
398: if (ret)
399: return ret;
400:
401: /* Inherit the flags from the child for this mapping */
402: flags = _iommu_get_protection_flags(pt->mmu, child);
403:
404: mapped = _iopgtbl_map_sg(iommu_pt, memdesc->gpuaddr + offset, &sgt, flags);
405:
406: sg_free_table(&sgt);
407:
408: return mapped ? 0 : -ENOMEM;
409: }
410:
411:
412: static int
413: kgsl_iopgtbl_unmap_range(struct kgsl_pagetable *pt, struct kgsl_memdesc *memdesc,
414: u64 offset, u64 length)
415: {
416: if (WARN_ON(offset >= memdesc->size ||
417: (offset + length) > memdesc->size))
418: return -ERANGE;
419:
420: return _iopgtbl_unmap(to_iommu_pt(pt), memdesc->gpuaddr + offset,
421: length);
422: }
423:
424: static size_t _iopgtbl_map_page_to_range(struct kgsl_iommu_pt *pt,
425: struct page *page, u64 gpuaddr, size_t range, int prot)
426: {
427: struct io_pgtable_ops *ops = pt->pgtbl_ops;
428: size_t mapped = 0;
429: u64 addr = gpuaddr;
430: int ret;
431:
432: while (range) {
433: ret = ops->map_pages(ops, addr, page_to_phys(page), PAGE_SIZE,
434: 1, prot, GFP_KERNEL, &mapped);
435: if (ret) {
436: _iopgtbl_unmap(pt, gpuaddr, mapped);
437: return 0;
438: }
439:
440: addr += PAGE_SIZE;
441: range -= PAGE_SIZE;
442: }
443:
444: return mapped;
445: }
446:
447: static int kgsl_iopgtbl_map_zero_page_to_range(struct kgsl_pagetable *pt,
448: struct kgsl_memdesc *memdesc, u64 offset, u64 length)
449: {
450: /*
451: * The SMMU only does the PRT compare at the bottom level of the page table, because
452: * there is not an easy way for the hardware to perform this check at earlier levels.
453: * Mark this page writable to avoid page faults while writing to it. Since the address
454: * of this zero page is programmed in PRR register, MMU will intercept any accesses to
455: * the page before they go to DDR and will terminate the transaction.
456: */
457: u32 flags = IOMMU_READ | IOMMU_WRITE | IOMMU_NOEXEC | get_llcc_flags(pt->mmu);
458: struct kgsl_iommu_pt *iommu_pt = to_iommu_pt(pt);
459: struct page *page = kgsl_vbo_zero_page;
460:
461: if (WARN_ON(!page))
462: return -ENODEV;
463:
464: if (WARN_ON((offset >= memdesc->size) ||
465: (offset + length) > memdesc->size))
466: return -ERANGE;
467:
468: if (!_iopgtbl_map_page_to_range(iommu_pt, page, memdesc->gpuaddr + offset,
469: length, flags))
470: return -ENOMEM;
471:
472: return 0;
473: }
474:
475: static int kgsl_iopgtbl_map(struct kgsl_pagetable *pagetable,
476: struct kgsl_memdesc *memdesc)
477: {
478: struct kgsl_iommu_pt *pt = to_iommu_pt(pagetable);
479: size_t mapped, padding;
480: int prot;
481:
482: /* Get the protection flags for the user context */
483: prot = _iommu_get_protection_flags(pagetable->mmu, memdesc);
484:
485: if (memdesc->sgt)
486: mapped = _iopgtbl_map_sg(pt, memdesc->gpuaddr,
487: memdesc->sgt, prot);
488: else
489: mapped = _iopgtbl_map_pages(pt, memdesc->gpuaddr,
490: memdesc->pages, memdesc->page_count, prot);
491:
492: if (mapped == 0)
493: return -ENOMEM;
494:
495: padding = kgsl_memdesc_footprint(memdesc) - mapped;
496:
497: if (padding) {
498: struct page *page = iommu_get_guard_page(memdesc);
499: size_t ret;
500:
501: if (page)
502: ret = _iopgtbl_map_page_to_range(pt, page,
503: memdesc->gpuaddr + mapped, padding,
504: prot & ~IOMMU_WRITE);
505:
506: if (!page || !ret) {
507: _iopgtbl_unmap(pt, memdesc->gpuaddr, mapped);
508: return -ENOMEM;
509: }
510: }
511:
512: return 0;
513: }
514:
515: static int kgsl_iopgtbl_unmap(struct kgsl_pagetable *pagetable,
516: struct kgsl_memdesc *memdesc)
517: {
518: return _iopgtbl_unmap(to_iommu_pt(pagetable), memdesc->gpuaddr,
519: kgsl_memdesc_footprint(memdesc));
520: }
521:
522: static int _iommu_unmap(struct iommu_domain *domain, u64 addr, size_t size)
523: {
524: size_t unmapped = 0;
525:
526: if (!domain)
527: return 0;
528:
529: /* Sign extend TTBR1 addresses all the way to avoid warning */
530: if (addr & (1ULL << 48))
531: addr |= 0xffff000000000000;
532:
533: unmapped = iommu_unmap(domain, addr, size);
534:
535: return (unmapped == size) ? 0 : -ENOMEM;
536: }
537:
538:
539: static size_t _iommu_map_page_to_range(struct iommu_domain *domain,
540: struct page *page, u64 gpuaddr, size_t range, int prot)
541: {
542: size_t mapped = 0;
543: u64 addr = gpuaddr;
544:
545: if (!page)
546: return 0;
547:
548: /* Sign extend TTBR1 addresses all the way to avoid warning */
549: if (gpuaddr & (1ULL << 48))
550: gpuaddr |= 0xffff000000000000;
551:
552:
553: while (range) {
554: #if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE)
555: int ret = iommu_map(domain, addr, page_to_phys(page),
556: PAGE_SIZE, prot, GFP_KERNEL);
557: #else
558: int ret = iommu_map(domain, addr, page_to_phys(page),
559: PAGE_SIZE, prot);
560: #endif
561: if (ret) {
562: iommu_unmap(domain, gpuaddr, mapped);
563: return 0;
564: }
565:
566: addr += PAGE_SIZE;
567: mapped += PAGE_SIZE;
568: range -= PAGE_SIZE;
569: }
570:
571: return mapped;
572: }
573:
574: static ssize_t _iommu_map_sg(struct iommu_domain *domain, u64 gpuaddr,
575: struct sg_table *sgt, int prot)
576: {
577: /* Sign extend TTBR1 addresses all the way to avoid warning */
578: if (gpuaddr & (1ULL << 48))
579: gpuaddr |= 0xffff000000000000;
580:
581: return kgsl_mmu_map_sg(domain, gpuaddr, sgt->sgl, sgt->orig_nents, prot);
582: }
583:
584: static int
585: _kgsl_iommu_map(struct kgsl_mmu *mmu, struct iommu_domain *domain,
586: struct kgsl_memdesc *memdesc)
587: {
588: int prot = _iommu_get_protection_flags(mmu, memdesc);
589: ssize_t mapped;
590: size_t padding;
591: int ret = 0;
592:
593: /*
594: * For paged memory allocated through kgsl, memdesc->pages is not NULL.
595: * Allocate sgt here just for its map operation. Contiguous memory
596: * already has its sgt, so no need to allocate it here.
597: */
598: if (!memdesc->pages) {
599: mapped = _iommu_map_sg(domain, memdesc->gpuaddr,
600: memdesc->sgt, prot);
601: } else {
602: struct sg_table sgt;
603:
604: ret = sg_alloc_table_from_pages(&sgt, memdesc->pages,
605: memdesc->page_count, 0, memdesc->size, GFP_KERNEL);
606: if (ret)
607: return ret;
608:
609: mapped = _iommu_map_sg(domain, memdesc->gpuaddr, &sgt, prot);
610: sg_free_table(&sgt);
611: }
612:
613: /* Check for errors or no pages mapped */
614: if (mapped <= 0)
615: return mapped ? mapped : -ENOMEM;
616:
617: padding = kgsl_memdesc_footprint(memdesc) - mapped;
618:
619: if (padding) {
620: struct page *page = iommu_get_guard_page(memdesc);
621: size_t guard_mapped;
622:
623: if (page)
624: guard_mapped = _iommu_map_page_to_range(domain, page,
625: memdesc->gpuaddr + mapped, padding, prot & ~IOMMU_WRITE);
626:
627: if (!page || !guard_mapped) {
628: _iommu_unmap(domain, memdesc->gpuaddr, mapped);
629: ret = -ENOMEM;
630: }
631: }
632:
633: return ret;
634: }
635:
636: static int kgsl_iommu_secure_map(struct kgsl_pagetable *pagetable,
637: struct kgsl_memdesc *memdesc)
638: {
639: struct kgsl_iommu *iommu = &pagetable->mmu->iommu;
640: struct iommu_domain *domain = to_iommu_domain(&iommu->secure_context);
641:
642: return _kgsl_iommu_map(pagetable->mmu, domain, memdesc);
643: }
644:
645: /*
646: * Return true if the address is in the TTBR0 region. This is used for cases
647: * when the "default" pagetable is used for both TTBR0 and TTBR1
648: */
649: static bool is_lower_address(struct kgsl_mmu *mmu, u64 addr)
650: {
651: return (test_bit(KGSL_MMU_IOPGTABLE, &mmu->features) &&
652: addr < KGSL_IOMMU_SPLIT_TABLE_BASE);
653: }
654:
655: static int _kgsl_iommu_unmap(struct iommu_domain *domain,
656: struct kgsl_memdesc *memdesc)
657: {
658: if (memdesc->size == 0 || memdesc->gpuaddr == 0)
659: return -EINVAL;
660:
661: return _iommu_unmap(domain, memdesc->gpuaddr,
662: kgsl_memdesc_footprint(memdesc));
663: }
664:
665: /* Map on the default pagetable and the LPAC pagetable if it exists */
666: static int kgsl_iommu_default_map(struct kgsl_pagetable *pagetable,
667: struct kgsl_memdesc *memdesc)
668: {
669: struct kgsl_mmu *mmu = pagetable->mmu;
670: struct kgsl_iommu *iommu = &mmu->iommu;
671: struct iommu_domain *domain, *lpac;
672: int ret;
673:
674: if (is_lower_address(mmu, memdesc->gpuaddr))
675: return kgsl_iopgtbl_map(pagetable, memdesc);
676:
677: domain = to_iommu_domain(&iommu->user_context);
678:
679: /* Map the object to the default GPU domain */
680: ret = _kgsl_iommu_map(mmu, domain, memdesc);
681:
682: /* Also map the object to the LPAC domain if it exists */
683: lpac = to_iommu_domain(&iommu->lpac_context);
684:
685: if (!ret && lpac) {
686: ret = _kgsl_iommu_map(mmu, lpac, memdesc);
687:
688: /* On failure, also unmap from the default domain */
689: if (ret)
690: _kgsl_iommu_unmap(domain, memdesc);
691:
692: }
693:
694: return ret;
695: }
696:
697: static int kgsl_iommu_secure_unmap(struct kgsl_pagetable *pagetable,
698: struct kgsl_memdesc *memdesc)
699: {
700: struct kgsl_iommu *iommu = &pagetable->mmu->iommu;
701:
702: if (memdesc->size == 0 || memdesc->gpuaddr == 0)
703: return -EINVAL;
704:
705: return _kgsl_iommu_unmap(to_iommu_domain(&iommu->secure_context),
706: memdesc);
707: }
708:
709: static int kgsl_iommu_default_unmap(struct kgsl_pagetable *pagetable,
710: struct kgsl_memdesc *memdesc)
711: {
712: struct kgsl_mmu *mmu = pagetable->mmu;
713: struct kgsl_iommu *iommu = &mmu->iommu;
714: int ret;
715:
716: if (memdesc->size == 0 || memdesc->gpuaddr == 0)
717: return -EINVAL;
718:
719: if (is_lower_address(mmu, memdesc->gpuaddr))
720: return kgsl_iopgtbl_unmap(pagetable, memdesc);
721:
722: /* Unmap from the default domain */
723: ret = _kgsl_iommu_unmap(to_iommu_domain(&iommu->user_context), memdesc);
724:
725: /* Unmap from the LPAC domain if it exists */
726: ret |= _kgsl_iommu_unmap(to_iommu_domain(&iommu->lpac_context), memdesc);
727: return ret;
728: }
729:
730: static bool kgsl_iommu_addr_is_global(struct kgsl_mmu *mmu, u64 addr)
731: {
732: if (test_bit(KGSL_MMU_IOPGTABLE, &mmu->features))
733: return (addr >= KGSL_IOMMU_SPLIT_TABLE_BASE);
734:
735: return ((addr >= KGSL_IOMMU_GLOBAL_MEM_BASE(mmu)) &&
736: (addr < KGSL_IOMMU_GLOBAL_MEM_BASE(mmu) +
--- LINES 777-804 ---
777: }
778:
779: static u32 KGSL_IOMMU_GET_CTX_REG(struct kgsl_iommu_context *ctx, u32 offset)
780: {
781: void __iomem *addr = kgsl_iommu_reg(ctx, offset);
782:
783: return readl_relaxed(addr);
784: }
785:
786: static int kgsl_iommu_get_gpuaddr(struct kgsl_pagetable *pagetable,
787: struct kgsl_memdesc *memdesc);
788:
789: #define KGSL_GLOBAL_MEM_PAGES (KGSL_IOMMU_GLOBAL_MEM_SIZE >> PAGE_SHIFT)
790:
791: static u64 global_get_offset(struct kgsl_device *device, u64 size,
792: atomic_t *priv)
793: {
794: int start = 0, bit;
795:
796: if (!device->global_map) {
797: device->global_map =
798: kcalloc(BITS_TO_LONGS(KGSL_GLOBAL_MEM_PAGES),
799: sizeof(unsigned long), GFP_KERNEL);
800: if (!device->global_map)
801: return (unsigned long) -ENOMEM;
802: }
803:
804: if (TEST_FLAG(KGSL_MEMDESC_RANDOM, priv)) {
--- LINES 823-954 ---
823:
824: if (WARN_ON(start < 0))
825: return (unsigned long) -ENOMEM;
826:
827: bitmap_set(device->global_map, bit, size >> PAGE_SHIFT);
828:
829: return bit << PAGE_SHIFT;
830: }
831:
832: static int kgsl_iommu_reserve_global_gpuaddr(struct kgsl_mmu *mmu,
833: struct kgsl_memdesc *memdesc, u32 padding)
834: {
835: struct kgsl_device *device = KGSL_MMU_DEVICE(mmu);
836: u64 offset;
837:
838: if (memdesc->gpuaddr)
839: return -EINVAL;
840:
841: if (memdesc->flags & KGSL_MEMFLAGS_SECURE) {
842: int ret = kgsl_iommu_get_gpuaddr(mmu->securepagetable, memdesc);
843:
844: WARN_ON(ret);
845:
846: return ret;
847: }
848:
849: offset = global_get_offset(device, memdesc->size + padding, &memdesc->priv);
850:
851: if (IS_ERR_VALUE(offset))
852: return -ENOSPC;
853:
854: memdesc->gpuaddr = mmu->defaultpagetable->global_base + offset;
855:
856: return 0;
857: }
858:
859: static void kgsl_iommu_map_global(struct kgsl_mmu *mmu,
860: struct kgsl_memdesc *memdesc, u32 padding)
861: {
862: if (!memdesc->gpuaddr) {
863: if (kgsl_iommu_reserve_global_gpuaddr(mmu, memdesc, padding))
864: return;
865: }
866:
867: if (memdesc->flags & KGSL_MEMFLAGS_SECURE)
868: kgsl_iommu_secure_map(mmu->securepagetable, memdesc);
869: else
870: kgsl_iommu_default_map(mmu->defaultpagetable, memdesc);
871: }
872:
873: /* Print the mem entry for the pagefault debugging */
874: static void print_entry(struct device *dev, struct kgsl_mem_entry *entry,
875: pid_t pid)
876: {
877: char name[32];
878:
879: if (!entry) {
880: dev_crit(dev, "**EMPTY**\n");
881: return;
882: }
883:
884: kgsl_get_memory_usage(name, sizeof(name), entry->memdesc.flags);
885:
886: dev_err(dev, "[%016llX - %016llX] %s %s (pid = %d) (%s)\n",
887: entry->memdesc.gpuaddr,
888: entry->memdesc.gpuaddr + entry->memdesc.size - 1,
889: TEST_FLAG(KGSL_MEMDESC_GUARD_PAGE, &entry->memdesc.priv) ? "(+guard)" : "",
890: entry->pending_free ? "(pending free)" : "",
891: pid, name);
892: }
893:
894: /* Check if the address in the list of recently freed memory */
895: static void kgsl_iommu_check_if_freed(struct device *dev,
896: struct kgsl_iommu_context *context, u64 addr, u32 ptname)
897: {
898: uint64_t gpuaddr = addr;
899: uint64_t size = 0;
900: uint64_t flags = 0;
901: char name[32];
902: pid_t pid;
903:
904: if (!kgsl_memfree_find_entry(ptname, &gpuaddr, &size, &flags, &pid))
905: return;
906:
907: kgsl_get_memory_usage(name, sizeof(name), flags);
908:
909: dev_err(dev, "---- premature free ----\n");
910: dev_err(dev, "[%8.8llX-%8.8llX] (%s) was already freed by pid %d\n",
911: gpuaddr, gpuaddr + size, name, pid);
912: }
913:
914: static struct kgsl_process_private *kgsl_iommu_get_process(u64 ptbase)
915: {
916: struct kgsl_process_private *p;
917: struct kgsl_iommu_pt *iommu_pt;
918:
919: read_lock(&kgsl_driver.proclist_lock);
920:
921: list_for_each_entry(p, &kgsl_driver.process_list, list) {
922: iommu_pt = to_iommu_pt(p->pagetable);
923: if (iommu_pt->ttbr0 == MMU_SW_PT_BASE(ptbase)) {
924: if (!kgsl_process_private_get(p))
925: p = NULL;
926:
927: read_unlock(&kgsl_driver.proclist_lock);
928: return p;
929: }
930: }
931:
932: read_unlock(&kgsl_driver.proclist_lock);
933:
934: return NULL;
935: }
936:
937: static void kgsl_iommu_add_fault_info(struct kgsl_context *context,
938: unsigned long addr, int flags)
939: {
940: struct kgsl_pagefault_report *report;
941: u32 fault_flag = 0;
942:
943: if (!context || !(context->flags & KGSL_CONTEXT_FAULT_INFO))
944: return;
945:
946: report = kzalloc(sizeof(struct kgsl_pagefault_report), GFP_KERNEL);
947: if (!report)
948: return;
949:
950: if (flags & IOMMU_FAULT_TRANSLATION)
951: fault_flag = KGSL_PAGEFAULT_TYPE_TRANSLATION;
952: else if (flags & IOMMU_FAULT_PERMISSION)
953: fault_flag = KGSL_PAGEFAULT_TYPE_PERMISSION;
954: else if (flags & IOMMU_FAULT_EXTERNAL)
--- LINES 1049-1080 ---
1049:
1050: unlock:
1051: write_unlock(&iommu->pf_stats_lock);
1052: }
1053:
1054: static void kgsl_iommu_print_fault(struct kgsl_mmu *mmu,
1055: struct kgsl_iommu_context *ctxt, unsigned long addr,
1056: u64 ptbase, u32 contextid,
1057: int flags, struct kgsl_process_private *private,
1058: struct kgsl_context *context)
1059: {
1060: struct kgsl_device *device = KGSL_MMU_DEVICE(mmu);
1061: struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
1062: const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
1063: struct kgsl_mem_entry *prev = NULL, *next = NULL, *entry;
1064: const char *fault_type = NULL;
1065: const char *comm = NULL;
1066: u32 ptname = KGSL_MMU_GLOBAL_PT;
1067: struct adreno_context *drawctxt = context ? ADRENO_CONTEXT(context) : NULL;
1068: int id;
1069:
1070: if (private) {
1071: comm = private->comm;
1072: ptname = pid_nr(private->pid);
1073: }
1074:
1075: trace_kgsl_mmu_pagefault(device, addr,
1076: ptname, comm,
1077: (flags & IOMMU_FAULT_WRITE) ? "write" : "read");
1078:
1079: if (flags & IOMMU_FAULT_TRANSLATION)
1080: fault_type = "translation";
--- LINES 1133-1167 ---
1133: }
1134:
1135: if (!private)
1136: return;
1137:
1138: dev_crit(device->dev, "---- nearby memory ----\n");
1139:
1140: spin_lock(&private->mem_lock);
1141: idr_for_each_entry(&private->mem_idr, entry, id) {
1142: u64 cur = entry->memdesc.gpuaddr;
1143:
1144: if (cur < addr) {
1145: if (!prev || prev->memdesc.gpuaddr < cur)
1146: prev = entry;
1147: }
1148:
1149: if (cur > addr) {
1150: if (!next || next->memdesc.gpuaddr > cur)
1151: next = entry;
1152: }
1153: }
1154:
1155: print_entry(device->dev, prev, pid_nr(private->pid));
1156: dev_crit(device->dev, "<- fault @ %16.16lx\n", addr);
1157: print_entry(device->dev, next, pid_nr(private->pid));
1158:
1159: spin_unlock(&private->mem_lock);
1160: }
1161:
1162: /*
1163: * Return true if the IOMMU should stall and trigger a snapshot on a pagefault
1164: */
1165: static bool kgsl_iommu_check_stall_on_fault(struct kgsl_iommu_context *ctx,
1166: struct kgsl_mmu *mmu, int flags)
1167: {
--- LINES 1181-1227 ---
1181: * Make sure we trigger reset/recovery only once.
1182: */
1183: if (ctx->stalled_on_fault)
1184: return false;
1185:
1186: if (!kgsl_mutex_trylock(&device->mutex))
1187: return true;
1188:
1189: /*
1190: * Turn off GPU IRQ so we don't get faults from it too.
1191: * The device mutex must be held to change power state
1192: */
1193: if (gmu_core_isenabled(device))
1194: kgsl_pwrctrl_irq(device, false);
1195: else
1196: kgsl_pwrctrl_change_state(device, KGSL_STATE_AWARE);
1197:
1198: kgsl_mutex_unlock(&device->mutex);
1199: return true;
1200: }
1201:
1202: static int kgsl_iommu_fault_handler(struct kgsl_mmu *mmu,
1203: struct kgsl_iommu_context *ctx, unsigned long addr, int flags)
1204: {
1205: struct kgsl_device *device = KGSL_MMU_DEVICE(mmu);
1206: u64 ptbase;
1207: u32 contextidr;
1208: bool stall, terminate;
1209: struct kgsl_process_private *private;
1210: struct kgsl_context *context;
1211:
1212: ptbase = KGSL_IOMMU_GET_CTX_REG_Q(ctx, KGSL_IOMMU_CTX_TTBR0);
1213: contextidr = KGSL_IOMMU_GET_CTX_REG(ctx, KGSL_IOMMU_CTX_CONTEXTIDR);
1214:
1215: private = kgsl_iommu_get_process(ptbase);
1216: context = kgsl_context_get(device, contextidr);
1217:
1218: stall = kgsl_iommu_check_stall_on_fault(ctx, mmu, flags);
1219: terminate = test_bit(KGSL_FT_PAGEFAULT_GPUHALT_ENABLE, &mmu->pfpolicy) &&
1220: test_bit(KGSL_MMU_PAGEFAULT_TERMINATE, &mmu->features);
1221:
1222: kgsl_iommu_print_fault(mmu, ctx, addr, ptbase, contextidr, flags, private,
1223: context);
1224: kgsl_iommu_add_fault_info(context, addr, flags);
1225:
1226: if (stall || terminate) {
1227: u32 sctlr;
--- LINES 1278-1304 ---
1278: struct kgsl_mmu *mmu = token;
1279: struct kgsl_iommu *iommu = &mmu->iommu;
1280: struct kgsl_iommu_context *ctx = &iommu->lpac_context;
1281: u32 fsynr0, fsynr1;
1282:
1283: fsynr0 = KGSL_IOMMU_GET_CTX_REG(ctx, KGSL_IOMMU_CTX_FSYNR0);
1284: fsynr1 = KGSL_IOMMU_GET_CTX_REG(ctx, KGSL_IOMMU_CTX_FSYNR1);
1285:
1286: dev_crit(KGSL_MMU_DEVICE(mmu)->dev,
1287: "LPAC PAGE FAULT iova=0x%16lx, fsynr0=0x%x, fsynr1=0x%x\n",
1288: addr, fsynr0, fsynr1);
1289:
1290: return kgsl_iommu_fault_handler(mmu, &iommu->lpac_context,
1291: addr, flags);
1292: }
1293:
1294: static int kgsl_iommu_secure_fault_handler(struct iommu_domain *domain,
1295: struct device *dev, unsigned long addr, int flags, void *token)
1296: {
1297: struct kgsl_mmu *mmu = token;
1298: struct kgsl_iommu *iommu = &mmu->iommu;
1299:
1300: return kgsl_iommu_fault_handler(mmu, &iommu->secure_context,
1301: addr, flags);
1302: }
1303:
1304: /*
--- LINES 1374-1413 ---
1374: else
1375: adreno_smmu = dev_get_drvdata(&context->pdev->dev);
1376:
1377: /* Enable CX and clocks before we call into SMMU to setup registers */
1378: kgsl_iommu_enable_clk(mmu);
1379: adreno_smmu->set_ttbr0_cfg(adreno_smmu->cookie, pgtbl_cfg);
1380: kgsl_iommu_disable_clk(mmu);
1381: }
1382:
1383: static int kgsl_iommu_get_context_bank(struct kgsl_pagetable *pt, struct kgsl_context *context)
1384: {
1385: struct kgsl_iommu *iommu = to_kgsl_iommu(pt);
1386: struct iommu_domain *domain;
1387:
1388: if (kgsl_context_is_lpac(context))
1389: domain = to_iommu_domain(&iommu->lpac_context);
1390: else
1391: domain = to_iommu_domain(&iommu->user_context);
1392:
1393: return qcom_iommu_get_context_bank_nr(domain);
1394: }
1395:
1396: static int kgsl_iommu_get_asid(struct kgsl_pagetable *pt, struct kgsl_context *context)
1397: {
1398: struct kgsl_iommu *iommu = to_kgsl_iommu(pt);
1399: struct iommu_domain *domain;
1400:
1401: if (kgsl_context_is_lpac(context))
1402: domain = to_iommu_domain(&iommu->lpac_context);
1403: else
1404: domain = to_iommu_domain(&iommu->user_context);
1405:
1406: return qcom_iommu_get_asid_nr(domain);
1407: }
1408:
1409: static void kgsl_iommu_destroy_default_pagetable(struct kgsl_pagetable *pagetable)
1410: {
1411: struct kgsl_device *device = KGSL_MMU_DEVICE(pagetable->mmu);
1412: struct kgsl_iommu_pt *pt = to_iommu_pt(pagetable);
1413: struct kgsl_global_memdesc *md;
--- LINES 2081-2107 ---
2081: struct kgsl_iommu *iommu = &mmu->iommu;
2082:
2083: kgsl_iommu_context_pagefault_resume(iommu, &iommu->user_context, terminate);
2084:
2085: if (iommu->lpac_context.domain)
2086: kgsl_iommu_context_pagefault_resume(iommu, &iommu->lpac_context, terminate);
2087: }
2088:
2089: static u64
2090: kgsl_iommu_get_current_ttbr0(struct kgsl_mmu *mmu, struct kgsl_context *context)
2091: {
2092: u64 val;
2093: struct kgsl_iommu *iommu = &mmu->iommu;
2094: struct kgsl_iommu_context *ctx = &iommu->user_context;
2095: struct kgsl_device *device = KGSL_MMU_DEVICE(mmu);
2096:
2097: if (kgsl_context_is_lpac(context))
2098: ctx = &iommu->lpac_context;
2099:
2100: /*
2101: * We cannot enable or disable the clocks in interrupt and atomic context, this
2102: * function is called from interrupt context if there is an axi error and atomic
2103: * context GPU snapshot for panic notifier callback.
2104: */
2105: if (in_interrupt() || device->snapshot_atomic)
2106: return 0;
2107:
--- LINES 2151-2254 ---
2151:
2152: kgsl_iommu_set_pf_policy_ctxt(mmu, pf_policy, &iommu->user_context);
2153:
2154: if (iommu->lpac_context.domain)
2155: kgsl_iommu_set_pf_policy_ctxt(mmu, pf_policy, &iommu->lpac_context);
2156:
2157: return 0;
2158: }
2159:
2160: static struct kgsl_iommu_addr_entry *_find_gpuaddr(
2161: struct kgsl_pagetable *pagetable, uint64_t gpuaddr)
2162: {
2163: struct rb_node *node = pagetable->rbtree.rb_node;
2164:
2165: while (node != NULL) {
2166: struct kgsl_iommu_addr_entry *entry = rb_entry(node,
2167: struct kgsl_iommu_addr_entry, node);
2168:
2169: if (gpuaddr < entry->base)
2170: node = node->rb_left;
2171: else if (gpuaddr > entry->base)
2172: node = node->rb_right;
2173: else
2174: return entry;
2175: }
2176:
2177: return NULL;
2178: }
2179:
2180: static int _remove_gpuaddr(struct kgsl_pagetable *pagetable,
2181: uint64_t gpuaddr)
2182: {
2183: struct kgsl_iommu_addr_entry *entry;
2184:
2185: entry = _find_gpuaddr(pagetable, gpuaddr);
2186:
2187: if (WARN(!entry, "GPU address %llx doesn't exist\n", gpuaddr))
2188: return -ENOMEM;
2189:
2190: /*
2191: * If the hint was based on this entry, adjust it to the end of the
2192: * previous entry.
2193: */
2194: if (pagetable->va_hint == (entry->base + entry->size)) {
2195: struct kgsl_iommu_addr_entry *prev =
2196: rb_entry_safe(rb_prev(&entry->node),
2197: struct kgsl_iommu_addr_entry, node);
2198:
2199: pagetable->va_hint = pagetable->va_start;
2200: if (prev)
2201: pagetable->va_hint = max_t(u64, prev->base + prev->size,
2202: pagetable->va_start);
2203: }
2204:
2205: rb_erase(&entry->node, &pagetable->rbtree);
2206: kmem_cache_free(addr_entry_cache, entry);
2207: return 0;
2208: }
2209:
2210: static int _insert_gpuaddr(struct kgsl_pagetable *pagetable,
2211: uint64_t gpuaddr, uint64_t size)
2212: {
2213: struct rb_node **node, *parent = NULL;
2214: struct kgsl_iommu_addr_entry *new =
2215: kmem_cache_alloc(addr_entry_cache, GFP_ATOMIC);
2216:
2217: if (new == NULL)
2218: return -ENOMEM;
2219:
2220: new->base = gpuaddr;
2221: new->size = size;
2222:
2223: node = &pagetable->rbtree.rb_node;
2224:
2225: while (*node != NULL) {
2226: struct kgsl_iommu_addr_entry *this;
2227:
2228: parent = *node;
2229: this = rb_entry(parent, struct kgsl_iommu_addr_entry, node);
2230:
2231: if (new->base < this->base)
2232: node = &parent->rb_left;
2233: else if (new->base > this->base)
2234: node = &parent->rb_right;
2235: else {
2236: /* Duplicate entry */
2237: WARN_RATELIMIT(1, "duplicate gpuaddr: 0x%llx\n", gpuaddr);
2238: kmem_cache_free(addr_entry_cache, new);
2239: return -EEXIST;
2240: }
2241: }
2242:
2243: rb_link_node(&new->node, parent, node);
2244: rb_insert_color(&new->node, &pagetable->rbtree);
2245:
2246: return 0;
2247: }
2248:
2249: static u64 _get_unmapped_area_hint(struct kgsl_pagetable *pagetable,
2250: u64 bottom, u64 top, u64 size, u64 align)
2251: {
2252: u64 hint;
2253:
2254: /*
--- LINES 2259-2302 ---
2259: if (!pagetable->va_hint || !upper_32_bits(top))
2260: return (u64) -EINVAL;
2261:
2262: /* Satisfy requested alignment */
2263: hint = ALIGN(pagetable->va_hint, align);
2264:
2265: /*
2266: * The va_hint is the highest VA that was allocated in the non-SVM
2267: * region. The 64-bit SVM and non-SVM regions do not overlap. So, we
2268: * know there is no VA allocated at this gpuaddr. Therefore, we only
2269: * need to check whether we have enough space for this allocation.
2270: */
2271: if ((hint + size) > top)
2272: return (u64) -ENOMEM;
2273:
2274: pagetable->va_hint = hint + size;
2275: return hint;
2276: }
2277:
2278: static uint64_t _get_unmapped_area(struct kgsl_pagetable *pagetable,
2279: uint64_t bottom, uint64_t top, uint64_t size,
2280: uint64_t align)
2281: {
2282: struct rb_node *node;
2283: uint64_t start;
2284:
2285: /* Check if we can assign a gpuaddr based on the last allocation */
2286: start = _get_unmapped_area_hint(pagetable, bottom, top, size, align);
2287: if (!IS_ERR_VALUE(start))
2288: return start;
2289:
2290: /* Fall back to searching through the range. */
2291: node = rb_first(&pagetable->rbtree);
2292: bottom = ALIGN(bottom, align);
2293: start = bottom;
2294:
2295: while (node != NULL) {
2296: uint64_t gap;
2297: struct kgsl_iommu_addr_entry *entry = rb_entry(node,
2298: struct kgsl_iommu_addr_entry, node);
2299:
2300: /*
2301: * Skip any entries that are outside of the range, but make sure
2302: * to account for some that might straddle the lower bound
--- LINES 2417-2600 ---
2417:
2418: spin_lock(&pagetable->lock);
2419: addr = _get_unmapped_area_topdown(pagetable,
2420: start, end, size, alignment);
2421: spin_unlock(&pagetable->lock);
2422: return addr;
2423: }
2424:
2425: static bool iommu_addr_in_svm_ranges(struct kgsl_pagetable *pagetable,
2426: u64 gpuaddr, u64 size)
2427: {
2428: u64 end = gpuaddr + size;
2429:
2430: /* Make sure size is not zero and we don't wrap around */
2431: if (end <= gpuaddr)
2432: return false;
2433:
2434: if ((gpuaddr >= pagetable->compat_va_start && gpuaddr < pagetable->compat_va_end) &&
2435: (end > pagetable->compat_va_start &&
2436: end <= pagetable->compat_va_end))
2437: return true;
2438:
2439: if ((gpuaddr >= pagetable->svm_start && gpuaddr < pagetable->svm_end) &&
2440: (end > pagetable->svm_start &&
2441: end <= pagetable->svm_end))
2442: return true;
2443:
2444: return false;
2445: }
2446:
2447: static int kgsl_iommu_set_svm_region(struct kgsl_pagetable *pagetable,
2448: uint64_t gpuaddr, uint64_t size)
2449: {
2450: int ret = -ENOMEM;
2451: struct rb_node *node;
2452:
2453: /* Make sure the requested address doesn't fall out of SVM range */
2454: if (!iommu_addr_in_svm_ranges(pagetable, gpuaddr, size))
2455: return -ENOMEM;
2456:
2457: spin_lock(&pagetable->lock);
2458: node = pagetable->rbtree.rb_node;
2459:
2460: while (node != NULL) {
2461: uint64_t start, end;
2462: struct kgsl_iommu_addr_entry *entry = rb_entry(node,
2463: struct kgsl_iommu_addr_entry, node);
2464:
2465: start = entry->base;
2466: end = entry->base + entry->size;
2467:
2468: if (gpuaddr + size <= start)
2469: node = node->rb_left;
2470: else if (end <= gpuaddr)
2471: node = node->rb_right;
2472: else
2473: goto out;
2474: }
2475:
2476: ret = _insert_gpuaddr(pagetable, gpuaddr, size);
2477: out:
2478: spin_unlock(&pagetable->lock);
2479: return ret;
2480: }
2481:
2482: static int get_gpuaddr(struct kgsl_pagetable *pagetable,
2483: struct kgsl_memdesc *memdesc, u64 start, u64 end,
2484: u64 size, u64 align)
2485: {
2486: u64 addr;
2487: int ret;
2488:
2489: spin_lock(&pagetable->lock);
2490: addr = _get_unmapped_area(pagetable, start, end, size, align);
2491: if (addr == (u64) -ENOMEM) {
2492: spin_unlock(&pagetable->lock);
2493: return -ENOMEM;
2494: }
2495:
2496: ret = _insert_gpuaddr(pagetable, addr, size);
2497: spin_unlock(&pagetable->lock);
2498:
2499: if (ret == 0) {
2500: memdesc->gpuaddr = addr;
2501: memdesc->pagetable = pagetable;
2502: }
2503:
2504: return ret;
2505: }
2506:
2507: static int kgsl_iommu_get_gpuaddr(struct kgsl_pagetable *pagetable,
2508: struct kgsl_memdesc *memdesc)
2509: {
2510: int ret = 0;
2511: u64 start, end, size, align;
2512:
2513: if (WARN_ON(kgsl_memdesc_use_cpu_map(memdesc)))
2514: return -EINVAL;
2515:
2516: if (memdesc->flags & KGSL_MEMFLAGS_SECURE &&
2517: pagetable->name != KGSL_MMU_SECURE_PT)
2518: return -EINVAL;
2519:
2520: size = kgsl_memdesc_footprint(memdesc);
2521:
2522: align = kgsl_get_align(memdesc);
2523:
2524: if (memdesc->flags & KGSL_MEMFLAGS_FORCE_32BIT) {
2525: start = pagetable->compat_va_start;
2526: end = pagetable->compat_va_end;
2527: } else {
2528: start = pagetable->va_start;
2529: end = pagetable->va_end;
2530: }
2531:
2532: ret = get_gpuaddr(pagetable, memdesc, start, end, size, align);
2533: /* if OOM, retry once after flushing lockless_workqueue */
2534: if (ret == -ENOMEM) {
2535: flush_workqueue(kgsl_driver.lockless_workqueue);
2536: ret = get_gpuaddr(pagetable, memdesc, start, end, size, align);
2537: }
2538:
2539: return ret;
2540: }
2541:
2542: static void kgsl_iommu_put_gpuaddr(struct kgsl_memdesc *memdesc)
2543: {
2544: if (memdesc->pagetable == NULL)
2545: return;
2546:
2547: spin_lock(&memdesc->pagetable->lock);
2548:
2549: _remove_gpuaddr(memdesc->pagetable, memdesc->gpuaddr);
2550:
2551: spin_unlock(&memdesc->pagetable->lock);
2552: }
2553:
2554: static int kgsl_iommu_svm_range(struct kgsl_pagetable *pagetable,
2555: uint64_t *lo, uint64_t *hi, uint64_t memflags)
2556: {
2557: bool gpu_compat = (memflags & KGSL_MEMFLAGS_FORCE_32BIT) != 0;
2558:
2559: if (lo != NULL)
2560: *lo = gpu_compat ? pagetable->compat_va_start : pagetable->svm_start;
2561: if (hi != NULL)
2562: *hi = gpu_compat ? pagetable->compat_va_end : pagetable->svm_end;
2563:
2564: return 0;
2565: }
2566:
2567: static bool kgsl_iommu_addr_in_range(struct kgsl_pagetable *pagetable,
2568: uint64_t gpuaddr, uint64_t size)
2569: {
2570: u64 end = gpuaddr + size;
2571:
2572: /* Make sure we don't wrap around */
2573: if (gpuaddr == 0 || end < gpuaddr)
2574: return false;
2575:
2576: if (gpuaddr >= pagetable->va_start && end <= pagetable->va_end)
2577: return true;
2578:
2579: if (gpuaddr >= pagetable->compat_va_start &&
2580: end <= pagetable->compat_va_end)
2581: return true;
2582:
2583: if (gpuaddr >= pagetable->svm_start && end <= pagetable->svm_end)
2584: return true;
2585:
2586: return false;
2587: }
2588:
2589: #if (KERNEL_VERSION(6, 13, 0) <= LINUX_VERSION_CODE)
2590: static struct iommu_domain *kgsl_iommu_domain_alloc(struct device *dev)
2591: {
2592: return iommu_paging_domain_alloc(dev);
2593: }
2594: #else
2595: static struct iommu_domain *kgsl_iommu_domain_alloc(struct device *dev)
2596: {
2597: return iommu_domain_alloc(&platform_bus_type);
2598: }
2599: #endif
2600:
--- LINES 2914-2940 ---
2914: * so this should be mostly just a placeholder
2915: */
2916: kgsl_vbo_zero_page = alloc_page(GFP_KERNEL | __GFP_ZERO |
2917: __GFP_NORETRY | __GFP_HIGHMEM);
2918: }
2919: if (!kgsl_vbo_zero_page)
2920: clear_bit(KGSL_MMU_SUPPORT_VBO, &mmu->features);
2921: }
2922:
2923: static void kgsl_iommu_map_globals(struct kgsl_device *device, struct kgsl_mmu *mmu)
2924: {
2925: struct kgsl_global_memdesc *md;
2926:
2927: list_for_each_entry(md, &device->globals, node) {
2928: if (md->memdesc.flags & KGSL_MEMFLAGS_SECURE) {
2929: if (IS_ERR_OR_NULL(mmu->securepagetable))
2930: continue;
2931:
2932: kgsl_iommu_secure_map(mmu->securepagetable,
2933: &md->memdesc);
2934: } else
2935: kgsl_iommu_default_map(mmu->defaultpagetable,
2936: &md->memdesc);
2937: }
2938: }
2939:
2940: static int kgsl_iommu_setup_context_standard(struct kgsl_mmu *mmu,
--- LINES 3097-3123 ---
3097: if (!test_bit(KGSL_MMU_IOPGTABLE, &mmu->features))
3098: return 0;
3099:
3100: pt = to_iommu_pt(mmu->defaultpagetable);
3101:
3102: /* Enable TTBR0 on the default context */
3103: kgsl_iommu_set_ttbr0(&iommu->user_context, mmu, &pt->cfg);
3104:
3105: /* Map any globals that might have been created early */
3106: kgsl_iommu_map_globals(device, mmu);
3107:
3108: /* QDSS is supported only when QCOM_KGSL_QDSS_STM is enabled */
3109: if (IS_ENABLED(CONFIG_QCOM_KGSL_QDSS_STM))
3110: device->qdss_desc = kgsl_allocate_global_fixed(device,
3111: "qcom,gpu-qdss-stm", "gpu-qdss");
3112:
3113: device->qtimer_desc = kgsl_allocate_global_fixed(device,
3114: "qcom,gpu-timer", "gpu-qtimer");
3115:
3116: /*
3117: * Only support VBOs on MMU500 hardware that supports the PRR
3118: * marker register to ignore writes to the zero page
3119: */
3120: kgsl_iommu_setup_vbo(mmu);
3121: of_node_put(smmu_node);
3122: return 0;
3123:
--- LINES 3213-3239 ---
3213: /* Probe the default pagetable */
3214: ret = iommu_probe_user_context(device, node);
3215: if (ret)
3216: goto err;
3217:
3218: /* Probe the secure pagetable (this is optional) */
3219: iommu_probe_secure_context(device, node);
3220:
3221: /* Map any globals that might have been created early */
3222: kgsl_iommu_map_globals(device, mmu);
3223:
3224: /* QDSS is supported only when QCOM_KGSL_QDSS_STM is enabled */
3225: if (IS_ENABLED(CONFIG_QCOM_KGSL_QDSS_STM))
3226: device->qdss_desc = kgsl_allocate_global_fixed(device,
3227: "qcom,gpu-qdss-stm", "gpu-qdss");
3228:
3229: device->qtimer_desc = kgsl_allocate_global_fixed(device,
3230: "qcom,gpu-timer", "gpu-qtimer");
3231:
3232: /*
3233: * Only support VBOs on MMU500 hardware that supports the PRR
3234: * marker register to ignore writes to the zero page
3235: */
3236: kgsl_iommu_setup_vbo(mmu);
3237:
3238: rwlock_init(&iommu->pf_stats_lock);
3239:
--- LINES 3372-3426 ---
3372: .mmu_start = kgsl_iommu_start,
3373: .mmu_ctx_terminated_on_fault = kgsl_iommu_ctx_terminated_on_fault,
3374: .mmu_clear_fsr = kgsl_iommu_clear_fsr,
3375: .mmu_get_current_ttbr0 = kgsl_iommu_get_current_ttbr0,
3376: .mmu_enable_clk = kgsl_iommu_enable_clk,
3377: .mmu_disable_clk = kgsl_iommu_disable_clk,
3378: .mmu_set_pf_policy = kgsl_iommu_set_pf_policy,
3379: .mmu_pagefault_resume = kgsl_iommu_pagefault_resume,
3380: .mmu_getpagetable = kgsl_iommu_getpagetable,
3381: .mmu_map_global = kgsl_iommu_map_global,
3382: .mmu_reserve_global_gpuaddr = kgsl_iommu_reserve_global_gpuaddr,
3383: .mmu_send_tlb_hint = kgsl_iommu_send_tlb_hint,
3384: .mmu_sysfs_init = kgsl_iommu_sysfs_init,
3385: };
3386:
3387: static const struct kgsl_mmu_pt_ops iopgtbl_pt_ops = {
3388: .mmu_map = kgsl_iopgtbl_map,
3389: .mmu_map_child = kgsl_iopgtbl_map_child,
3390: .mmu_map_zero_page_to_range = kgsl_iopgtbl_map_zero_page_to_range,
3391: .mmu_unmap = kgsl_iopgtbl_unmap,
3392: .mmu_unmap_range = kgsl_iopgtbl_unmap_range,
3393: .mmu_destroy_pagetable = kgsl_iommu_destroy_pagetable,
3394: .get_ttbr0 = kgsl_iommu_get_ttbr0,
3395: .get_context_bank = kgsl_iommu_get_context_bank,
3396: .get_asid = kgsl_iommu_get_asid,
3397: .get_gpuaddr = kgsl_iommu_get_gpuaddr,
3398: .put_gpuaddr = kgsl_iommu_put_gpuaddr,
3399: .set_svm_region = kgsl_iommu_set_svm_region,
3400: .find_svm_region = kgsl_iommu_find_svm_region,
3401: .svm_range = kgsl_iommu_svm_range,
3402: .addr_in_range = kgsl_iommu_addr_in_range,
3403: };
3404:
3405: static const struct kgsl_mmu_pt_ops secure_pt_ops = {
3406: .mmu_map = kgsl_iommu_secure_map,
3407: .mmu_unmap = kgsl_iommu_secure_unmap,
3408: .mmu_destroy_pagetable = kgsl_iommu_destroy_pagetable,
3409: .get_context_bank = kgsl_iommu_get_context_bank,
3410: .get_asid = kgsl_iommu_get_asid,
3411: .get_gpuaddr = kgsl_iommu_get_gpuaddr,
3412: .put_gpuaddr = kgsl_iommu_put_gpuaddr,
3413: .addr_in_range = kgsl_iommu_addr_in_range,
3414: };
3415:
3416: static const struct kgsl_mmu_pt_ops default_pt_ops = {
3417: .mmu_map = kgsl_iommu_default_map,
3418: .mmu_unmap = kgsl_iommu_default_unmap,
3419: .mmu_destroy_pagetable = kgsl_iommu_destroy_default_pagetable,
3420: .get_ttbr0 = kgsl_iommu_get_ttbr0,
3421: .get_context_bank = kgsl_iommu_get_context_bank,
3422: .get_asid = kgsl_iommu_get_asid,
3423: .get_gpuaddr = kgsl_iommu_get_gpuaddr,
3424: .put_gpuaddr = kgsl_iommu_put_gpuaddr,
3425: .addr_in_range = kgsl_iommu_addr_in_range,
3426: };
========== FILE: kgsl_gmu_core.c ==========
--- LINES 199-259 ---
199: unsigned int offset, unsigned int expected_ret,
200: unsigned int timeout_ms, unsigned int mask)
201: {
202: u32 val;
203:
204: return kgsl_regmap_read_poll_timeout(&device->regmap, offset,
205: val, (val & mask) == expected_ret, 100, timeout_ms * 1000);
206: }
207:
208: int gmu_core_map_memdesc(struct iommu_domain *domain, struct kgsl_memdesc *memdesc,
209: u64 gmuaddr, int attrs)
210: {
211: ssize_t mapped;
212:
213: if (!memdesc->pages) {
214: mapped = kgsl_mmu_map_sg(domain, gmuaddr, memdesc->sgt->sgl,
215: memdesc->sgt->nents, attrs);
216: } else {
217: struct sg_table sgt = { 0 };
218: int ret;
219:
220: ret = sg_alloc_table_from_pages(&sgt, memdesc->pages,
221: memdesc->page_count, 0, memdesc->size, GFP_KERNEL);
222:
223: if (ret)
224: return ret;
225:
226: mapped = kgsl_mmu_map_sg(domain, gmuaddr, sgt.sgl, sgt.nents, attrs);
227: sg_free_table(&sgt);
228: }
229:
230: if (!mapped)
231: mapped = -ENOMEM;
232:
233: return (mapped < 0) ? mapped : 0;
234: }
235:
236: struct kgsl_memdesc *gmu_core_find_memdesc(struct kgsl_device *device, u32 addr, u32 size)
237: {
238: struct gmu_core_device *gmu = &device->gmu_core;
239: int i;
240:
241: for (i = 0; i < gmu->global_entries; i++) {
242: struct kgsl_memdesc *md = &gmu->gmu_globals[i];
243:
244: if ((addr >= md->gmuaddr) &&
245: (((addr + size) <= (md->gmuaddr + md->size))))
246: return md;
247: }
248:
249: return NULL;
250: }
251:
252: int gmu_core_find_vma_block(struct kgsl_device *device, u32 addr, u32 size)
253: {
254: struct gmu_core_device *gmu = &device->gmu_core;
255: int i;
256:
257: for (i = 0; i < gmu->num_vmas; i++) {
258: struct gmu_vma_entry *vma = &gmu->vma[i];
259:
--- LINES 265-291 ---
265: return -ENOENT;
266: }
267:
268: void gmu_core_free_globals(struct kgsl_device *device)
269: {
270: struct gmu_core_device *gmu = &device->gmu_core;
271: int i;
272:
273: for (i = 0; i < gmu->global_entries && i < ARRAY_SIZE(gmu->gmu_globals); i++) {
274: struct kgsl_memdesc *md = &gmu->gmu_globals[i];
275:
276: if (!md->gmuaddr)
277: continue;
278:
279: iommu_unmap(gmu->domain, md->gmuaddr, md->size);
280:
281: if (TEST_FLAG(KGSL_MEMDESC_SYSMEM, &md->priv))
282: kgsl_sharedmem_free(md);
283:
284: memset(md, 0, sizeof(*md));
285: }
286:
287: if (gmu->domain) {
288: kgsl_detach_iommu_group(gmu->domain, gmu->group);
289: iommu_domain_free(gmu->domain);
290: gmu->domain = NULL;
291: }
--- LINES 372-398 ---
372: node = rb_next(node);
373: }
374:
375: /* Do we have space after the last node? */
376: if (!found && (cur + size <= vma->start + vma->size))
377: found = true;
378: return found ? cur : 0;
379: }
380:
381: static int _map_gmu_dynamic(struct kgsl_device *device, struct kgsl_memdesc *md,
382: u32 addr, u32 vma_id, int attrs, u32 align)
383: {
384: struct gmu_core_device *gmu = &device->gmu_core;
385: struct device *gmu_pdev_dev = GMU_PDEV_DEV(device);
386: struct gmu_vma_entry *vma = &gmu->vma[vma_id];
387: struct gmu_vma_node *vma_node = NULL;
388: int ret;
389: u32 size = ALIGN(md->size, hfi_get_gmu_sz_alignment(align));
390:
391: spin_lock(&vma->lock);
392: if (!addr) {
393: /*
394: * We will end up with a hole (GMU VA range not backed by physical mapping) if
395: * the aligned size is greater than the size of the physical mapping
396: */
397: addr = find_unmapped_va(vma, size, hfi_get_gmu_va_alignment(align));
398: if (addr == 0) {
--- LINES 405-479 ---
405:
406: ret = insert_va(vma, addr, size);
407: spin_unlock(&vma->lock);
408: if (ret < 0) {
409: dev_err(gmu_pdev_dev,
410: "Could not insert va: %x size %x\n", addr, size);
411: return ret;
412: }
413:
414: ret = gmu_core_map_memdesc(gmu->domain, md, addr, attrs);
415: if (!ret) {
416: md->gmuaddr = addr;
417: return 0;
418: }
419:
420: /* Failed to map to GMU */
421: dev_err(gmu_pdev_dev,
422: "Unable to map GMU kernel block: addr:0x%08x size:0x%llx :%d\n",
423: addr, md->size, ret);
424:
425: spin_lock(&vma->lock);
426: vma_node = find_va(vma, md->gmuaddr, size);
427: if (vma_node)
428: rb_erase(&vma_node->node, &vma->vma_root);
429: spin_unlock(&vma->lock);
430: kfree(vma_node);
431:
432: return ret;
433: }
434:
435: static int _map_gmu_static(struct kgsl_device *device, struct kgsl_memdesc *md,
436: u32 addr, u32 vma_id, int attrs, u32 align)
437: {
438: struct gmu_core_device *gmu = &device->gmu_core;
439: struct gmu_vma_entry *vma = &gmu->vma[vma_id];
440: int ret;
441: u32 size = ALIGN(md->size, hfi_get_gmu_sz_alignment(align));
442:
443: if (!addr)
444: addr = ALIGN(vma->next_va, hfi_get_gmu_va_alignment(align));
445:
446: ret = gmu_core_map_memdesc(device->gmu_core.domain, md, addr, attrs);
447: if (ret) {
448: dev_err(GMU_PDEV_DEV(device),
449: "Unable to map GMU kernel block: addr:0x%08x size:0x%llx :%d\n",
450: addr, md->size, ret);
451: return ret;
452: }
453: md->gmuaddr = addr;
454: /*
455: * We will end up with a hole (GMU VA range not backed by physical mapping) if the aligned
456: * size is greater than the size of the physical mapping
457: */
458: vma->next_va = md->gmuaddr + size;
459: return 0;
460: }
461:
462: int gmu_core_reserve_gmuaddr(struct kgsl_device *device, struct kgsl_memdesc *md, u32 vma_id,
463: u32 align)
464: {
465: struct gmu_core_device *gmu = &device->gmu_core;
466: struct gmu_vma_entry *vma = &gmu->vma[vma_id];
467: u32 addr, size = ALIGN(md->size, hfi_get_gmu_sz_alignment(align));
468:
469: if (vma_is_dynamic(device, vma_id)) {
470: spin_lock(&vma->lock);
471: addr = find_unmapped_va(vma, size, hfi_get_gmu_va_alignment(align));
472: spin_unlock(&vma->lock);
473: if (addr == 0)
474: goto error;
475: } else {
476: addr = ALIGN(vma->next_va, hfi_get_gmu_va_alignment(align));
477: if ((addr + size) >= (vma->start + vma->size))
478: goto error;
479: vma->next_va = addr + size;
--- LINES 483-509 ---
483:
484: return 0;
485:
486: error:
487: dev_err_ratelimited(GMU_PDEV_DEV(device),
488: "Insufficient VA space size: %x in vma:%u\n", size, vma_id);
489: return -ENOMEM;
490: }
491:
492: int gmu_core_map_gmu(struct kgsl_device *device, struct kgsl_memdesc *md,
493: u32 addr, u32 vma_id, int attrs, u32 align)
494: {
495: return vma_is_dynamic(device, vma_id) ?
496: _map_gmu_dynamic(device, md, addr, vma_id, attrs, align) :
497: _map_gmu_static(device, md, addr, vma_id, attrs, align);
498: }
499:
500: int gmu_core_get_attrs(u32 flags)
501: {
502: int attrs = IOMMU_READ;
503:
504: if (flags & HFI_MEMFLAG_GMU_PRIV)
505: attrs |= IOMMU_PRIV;
506:
507: if (flags & HFI_MEMFLAG_GMU_WRITEABLE)
508: attrs |= IOMMU_WRITE;
509:
--- LINES 515-555 ---
515: struct hfi_mem_alloc_desc *desc = &entry->desc;
516: u32 attrs = gmu_core_get_attrs(desc->flags);
517: u32 vma_id = (desc->flags & HFI_MEMFLAG_GMU_CACHEABLE) ? GMU_CACHE : GMU_NONCACHED_KERNEL;
518:
519: /*
520: * GMU Tx/Rx queues are mapped as I/O-coherent on both SOCCP and CPU,
521: * mark the buffer I/O-coherent on GMU side as well to prevent stale
522: * data and immediate updates in DDR.
523: */
524: if (desc->mem_kind == HFI_MEMKIND_HW_FENCE &&
525: kgsl_mmu_has_feature(device, KGSL_MMU_IO_COHERENT)) {
526: entry->md->flags |= KGSL_MEMFLAGS_IOCOHERENT;
527: attrs |= IOMMU_CACHE;
528: }
529:
530: return gmu_core_map_gmu(device, entry->md, 0, vma_id, attrs, desc->align);
531: }
532:
533: struct kgsl_memdesc *gmu_core_reserve_kernel_block(struct kgsl_device *device,
534: u32 addr, u32 size, u32 vma_id, u32 align)
535: {
536: int ret;
537: u64 memflags = 0;
538: struct kgsl_memdesc *md;
539: struct gmu_core_device *gmu = &device->gmu_core;
540: int attrs = IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV;
541: struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
542:
543: if (gmu->global_entries == ARRAY_SIZE(gmu->gmu_globals))
544: return ERR_PTR(-ENOMEM);
545:
546: md = &gmu->gmu_globals[gmu->global_entries];
547:
548: /*
549: * Apply WB cache policy to fetch GMU FW successfully for A622.
550: * A622 has specific cache coherency requirements that can lead to data
551: * inconsistency if not using writeback cache policy.
552: */
553: if (adreno_is_a622(adreno_dev))
554: memflags = FIELD_PREP(KGSL_CACHEMODE_MASK, KGSL_CACHEMODE_WRITEBACK);
555:
--- LINES 565-595 ---
565: memset(md, 0x0, sizeof(*md));
566: return ERR_PTR(ret);
567: }
568:
569: gmu->global_entries++;
570:
571: return md;
572: }
573:
574: struct kgsl_memdesc *gmu_core_reserve_kernel_block_fixed(struct kgsl_device *device,
575: u32 addr, u32 size, u32 vma_id, const char *resource, int attrs, u32 align)
576: {
577: int ret;
578: struct kgsl_memdesc *md;
579: struct gmu_core_device *gmu = &device->gmu_core;
580:
581: if (gmu->global_entries == ARRAY_SIZE(gmu->gmu_globals))
582: return ERR_PTR(-ENOMEM);
583:
584: md = &gmu->gmu_globals[gmu->global_entries];
585:
586: ret = kgsl_memdesc_init_fixed(device, GMU_PDEV(device), resource, md);
587: if (ret)
588: return ERR_PTR(ret);
589:
590: ret = gmu_core_map_gmu(device, md, addr, vma_id, attrs, align);
591:
592: sg_free_table(md->sgt);
593: kfree(md->sgt);
594: md->sgt = NULL;
595:
--- LINES 600-672 ---
600: "Unable to map GMU kernel block: addr:0x%08x size:0x%llx :%d\n",
601: addr, md->size, ret);
602: memset(md, 0x0, sizeof(*md));
603: md = ERR_PTR(ret);
604: }
605: return md;
606: }
607:
608: int gmu_core_alloc_kernel_block(struct kgsl_device *device,
609: struct kgsl_memdesc *md, u32 size, u32 vma_id, int attrs)
610: {
611: int ret;
612:
613: ret = kgsl_allocate_kernel(device, md, size, 0, KGSL_MEMDESC_SYSMEM);
614: if (ret)
615: return ret;
616:
617: ret = gmu_core_map_gmu(device, md, 0, vma_id, attrs, 0);
618: if (ret)
619: kgsl_sharedmem_free(md);
620:
621: return ret;
622: }
623:
624: void gmu_core_free_block(struct kgsl_device *device, struct kgsl_memdesc *md)
625: {
626: struct gmu_core_device *gmu = &device->gmu_core;
627: int vma_id = gmu_core_find_vma_block(device, md->gmuaddr, md->size);
628: struct gmu_vma_entry *vma;
629: struct gmu_vma_node *vma_node;
630:
631: if ((vma_id < 0) || !vma_is_dynamic(device, vma_id))
632: return;
633:
634: vma = &gmu->vma[vma_id];
635:
636: /*
637: * Do not remove the vma node if we failed to unmap the entire buffer. This is because the
638: * iommu driver considers remapping an already mapped iova as fatal.
639: */
640: if (md->size != iommu_unmap(device->gmu_core.domain, md->gmuaddr, md->size))
641: goto free;
642:
643: spin_lock(&vma->lock);
644: vma_node = find_va(vma, md->gmuaddr, md->size);
645: if (vma_node)
646: rb_erase(&vma_node->node, &vma->vma_root);
647: spin_unlock(&vma->lock);
648: kfree(vma_node);
649: free:
650: kgsl_sharedmem_free(md);
651: }
652:
653: int gmu_core_process_prealloc(struct kgsl_device *device, struct gmu_block_header *blk)
654: {
655: struct kgsl_memdesc *md;
656: int id = gmu_core_find_vma_block(device, blk->addr, blk->value);
657:
658: if (id < 0) {
659: dev_err(GMU_PDEV_DEV(device),
660: "Invalid prealloc block addr: 0x%x value:%d\n",
661: blk->addr, blk->value);
662: return id;
663: }
664:
665: /* Nothing to do for TCM blocks or user uncached */
666: if (id == GMU_ITCM || id == GMU_DTCM || id == GMU_NONCACHED_USER)
667: return 0;
668:
669: /* Check if the block is already allocated */
670: md = gmu_core_find_memdesc(device, blk->addr, blk->value);
671: if (md != NULL)
672: return 0;
--- LINES 703-729 ---
703: }
704: #else
705: #include <linux/platform_device.h>
706: static struct iommu_domain *gmu_core_iommu_domain_alloc(struct device *dev)
707: {
708: return iommu_domain_alloc(&platform_bus_type);
709: }
710: #endif
711:
712: int gmu_core_iommu_init(struct kgsl_device *device)
713: {
714: struct device *gmu_pdev_dev = GMU_PDEV_DEV(device);
715: int ret;
716:
717: device->gmu_core.domain = gmu_core_iommu_domain_alloc(gmu_pdev_dev);
718: if (IS_ERR_OR_NULL(device->gmu_core.domain)) {
719: ret = (device->gmu_core.domain) ? PTR_ERR(device->gmu_core.domain) : -ENODEV;
720: dev_err(gmu_pdev_dev, "Unable to allocate GMU IOMMU domain: %d\n", ret);
721: return ret;
722: }
723:
724: /*
725: * Disable stall on fault for the GMU context bank.
726: * This sets SCTLR.CFCFG = 0.
727: * Also note that, the smmu driver sets SCTLR.HUPCF = 0 by default.
728: */
729: qcom_iommu_set_fault_model(device->gmu_core.domain,
--- LINES 746-793 ---
746:
747: void gmu_core_dev_force_first_boot(struct kgsl_device *device)
748: {
749: const struct gmu_dev_ops *ops = GMU_DEVICE_OPS(device);
750:
751: if (ops && ops->force_first_boot)
752: return ops->force_first_boot(device);
753: }
754:
755: int gmu_core_set_vrb_register(struct kgsl_memdesc *vrb, u32 index, u32 val)
756: {
757: u32 *vrb_buf;
758:
759: if (WARN_ON(IS_ERR_OR_NULL(vrb)))
760: return -ENODEV;
761:
762: if (WARN_ON(index >= (vrb->size >> 2))) {
763: pr_err("kgsl: Unable to set VRB register for index %u\n", index);
764: return -EINVAL;
765: }
766:
767: vrb_buf = vrb->hostptr;
768: vrb_buf[index] = val;
769:
770: /* Make sure the vrb write is posted before moving ahead */
771: wmb();
772:
773: return 0;
774: }
775:
776: int gmu_core_get_vrb_register(struct kgsl_memdesc *vrb, u32 index, u32 *val)
777: {
778: u32 *vrb_buf;
779:
780: if (IS_ERR_OR_NULL(vrb))
781: return -ENODEV;
782:
783: if (WARN_ON(index >= (vrb->size >> 2))) {
784: pr_err("kgsl: Unable to get VRB register for index %u\n", index);
785: return -EINVAL;
786: }
787:
788: vrb_buf = vrb->hostptr;
789: *val = vrb_buf[index];
790:
791: return 0;
792: }
793:
--- LINES 867-921 ---
867: spin_lock(&pwr->stats_lock);
868: pwr->accum_busy_stats += data->gpu_time;
869: pwr->accum_total_time += data->total_time;
870: spin_unlock(&pwr->stats_lock);
871: }
872:
873: static void stream_trace_data(struct kgsl_device *device, struct gmu_trace_packet *pkt)
874: {
875: switch (pkt->trace_id) {
876: case GMU_TRACE_PREEMPT_TRIGGER: {
877: struct trace_preempt_trigger *data =
878: (struct trace_preempt_trigger *)pkt->payload;
879:
880: trace_adreno_preempt_trigger(data->cur_rb, data->next_rb,
881: data->ctx_switch_cntl, pkt->ticks);
882: break;
883: }
884: case GMU_TRACE_PREEMPT_DONE: {
885: struct trace_preempt_done *data =
886: (struct trace_preempt_done *)pkt->payload;
887:
888: trace_adreno_preempt_done(data->prev_rb, data->next_rb,
889: data->ctx_switch_cntl, pkt->ticks);
890: break;
891: }
892: case GMU_TRACE_EXTERNAL_HW_FENCE_SIGNAL: {
893: struct trace_ext_hw_fence_signal *data =
894: (struct trace_ext_hw_fence_signal *)pkt->payload;
895:
896: trace_adreno_ext_hw_fence_signal(data->context, data->seq_no,
897: data->flags, pkt->ticks);
898: break;
899: }
900: case GMU_TRACE_SYNCOBJ_RETIRE: {
901: struct trace_syncobj_retire *data =
902: (struct trace_syncobj_retire *)pkt->payload;
903:
904: trace_adreno_syncobj_retired(data->gmu_ctxt_id, data->timestamp, pkt->ticks);
905: break;
906: }
907: case GMU_TRACE_DCVS_PWRLVL: {
908: _gmu_trace_dcvs_pwrlevel(device, pkt);
909: break;
910: }
911: case GMU_TRACE_DCVS_BUSLVL: {
912: _gmu_trace_dcvs_buslevel(device, pkt);
913: break;
914: }
915: case GMU_TRACE_DCVS_PWRSTATS: {
916: _gmu_trace_dcvs_pwrstats(device, pkt);
917: break;
918: }
919: case GMU_TRACE_PWR_CONSTRAINT: {
920: struct trace_pwr_constraint *data =
921: (struct trace_pwr_constraint *)pkt->payload;
--- LINES 1050-1082 ---
1050: }
1051:
1052: int gmu_core_soccp_vote(struct kgsl_device *device, bool pwr_on)
1053: {
1054: int ret;
1055:
1056: if (!(test_bit(GMU_SOCCP_VOTE_ON, &device->gmu_core.flags) ^ pwr_on))
1057: return 0;
1058:
1059: ret = kgsl_hw_fence_soccp_vote(pwr_on);
1060: if (!ret) {
1061: change_bit(GMU_SOCCP_VOTE_ON, &device->gmu_core.flags);
1062: return 0;
1063: }
1064:
1065: dev_err(GMU_PDEV_DEV(device), "soccp power %s failed: %d. Disabling hw fences\n",
1066: pwr_on ? "on" : "off", ret);
1067:
1068: return ret;
1069: }
1070:
1071: bool gmu_core_capabilities_enabled(struct firmware_capabilities *caps, u32 field)
1072: {
1073: if (!caps->length || !caps->data)
1074: return false;
1075:
1076: /* Capabilities payload data stored in 1 byte */
1077: if (caps->data[field / BITS_PER_BYTE] & BIT(field % BITS_PER_BYTE))
1078: return true;
1079:
1080: return false;
1081: }
1082: