-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathadreno_a6xx_hwsched_hfi.c
More file actions
1785 lines (1430 loc) · 48.3 KB
/
Copy pathadreno_a6xx_hwsched_hfi.c
File metadata and controls
1785 lines (1430 loc) · 48.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
*/
#include <linux/iommu.h>
#include "adreno.h"
#include "adreno_a6xx.h"
#include "adreno_a6xx_hwsched.h"
#include "adreno_hfi.h"
#include "adreno_perfcounter.h"
#include "adreno_pm4types.h"
#include "adreno_trace.h"
#include "kgsl_device.h"
#include "kgsl_eventlog.h"
#include "kgsl_gmu_core.h"
#include "kgsl_pwrctrl.h"
#include "kgsl_trace.h"
#include "kgsl_util.h"
#define HFI_QUEUE_MAX (HFI_QUEUE_DEFAULT_CNT + HFI_QUEUE_DISPATCH_MAX_CNT)
#define DEFINE_QHDR(gmuaddr, id, prio) \
{\
.status = 1, \
.start_addr = GMU_QUEUE_START_ADDR(gmuaddr, id), \
.type = QUEUE_HDR_TYPE(id, prio, 0, 0), \
.queue_size = SZ_4K >> 2, \
.msg_size = 0, \
.unused0 = 0, \
.unused1 = 0, \
.unused2 = 0, \
.unused3 = 0, \
.unused4 = 0, \
.read_index = 0, \
.write_index = 0, \
}
static struct dq_info {
/** @max_dq: Maximum number of dispatch queues per RB level */
u32 max_dq;
/** @base_dq_id: Base dqid for level */
u32 base_dq_id;
/** @offset: Next dqid to use for roundrobin context assignment */
u32 offset;
} a6xx_hfi_dqs[KGSL_PRIORITY_MAX_RB_LEVELS] = {
{ 4, 0, }, /* RB0 */
{ 4, 4, }, /* RB1 */
{ 3, 8, }, /* RB2 */
{ 3, 11, }, /* RB3 */
};
static int a6xx_hfi_dispatch_queue_write(struct adreno_device *adreno_dev, uint32_t queue_idx,
uint32_t *msg, u32 size_bytes, struct kgsl_drawobj_cmd *cmdobj,
struct adreno_submit_time *time);
struct a6xx_hwsched_hfi *to_a6xx_hwsched_hfi(
struct adreno_device *adreno_dev)
{
struct a6xx_device *a6xx_dev = container_of(adreno_dev,
struct a6xx_device, adreno_dev);
struct a6xx_hwsched_device *a6xx_hwsched = container_of(a6xx_dev,
struct a6xx_hwsched_device, a6xx_dev);
return &a6xx_hwsched->hwsched_hfi;
}
static void add_waiter(struct a6xx_hwsched_hfi *hfi, u32 hdr,
struct pending_cmd *ack)
{
memset(ack, 0x0, sizeof(*ack));
init_completion(&ack->complete);
write_lock_irq(&hfi->msglock);
list_add_tail(&ack->node, &hfi->msglist);
write_unlock_irq(&hfi->msglock);
ack->sent_hdr = hdr;
}
static void del_waiter(struct a6xx_hwsched_hfi *hfi, struct pending_cmd *ack)
{
write_lock_irq(&hfi->msglock);
list_del(&ack->node);
write_unlock_irq(&hfi->msglock);
}
static void a6xx_receive_ack_async(struct adreno_device *adreno_dev, void *rcvd)
{
struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev);
struct device *gmu_pdev_dev = GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev));
struct pending_cmd *cmd = NULL;
u32 waiters[64], num_waiters = 0, i;
u32 *ack = rcvd;
u32 hdr = ack[0];
u32 req_hdr = ack[1];
u32 size_bytes = MSG_HDR_GET_SIZE(hdr) << 2;
if (size_bytes > sizeof(cmd->results))
dev_err_ratelimited(gmu_pdev_dev,
"Ack result too big: %d Truncating to: %ld\n",
size_bytes, sizeof(cmd->results));
read_lock(&hfi->msglock);
list_for_each_entry(cmd, &hfi->msglist, node) {
if (CMP_HFI_ACK_HDR(cmd->sent_hdr, req_hdr)) {
memcpy(cmd->results, ack,
min_t(u32, size_bytes,
sizeof(cmd->results)));
complete(&cmd->complete);
read_unlock(&hfi->msglock);
return;
}
if (num_waiters < ARRAY_SIZE(waiters))
waiters[num_waiters++] = cmd->sent_hdr;
}
read_unlock(&hfi->msglock);
/* Didn't find the sender, list the waiter */
dev_err_ratelimited(gmu_pdev_dev,
"Unexpectedly got id %d seqnum %d. Total waiters: %d Top %d Waiters:\n",
MSG_HDR_GET_ID(req_hdr), MSG_HDR_GET_SEQNUM(req_hdr),
num_waiters, min_t(u32, num_waiters, 5));
for (i = 0; i < num_waiters && i < 5; i++)
dev_err_ratelimited(gmu_pdev_dev,
" id %d seqnum %d\n",
MSG_HDR_GET_ID(waiters[i]),
MSG_HDR_GET_SEQNUM(waiters[i]));
}
/* Look up a particular key's value for a given type of payload */
static u32 a6xx_hwsched_lookup_key_value_legacy(struct adreno_device *adreno_dev,
u32 type, u32 key)
{
struct hfi_context_bad_cmd_legacy *cmd = adreno_dev->hwsched.ctxt_bad;
u32 i = 0, payload_bytes;
void *start;
if (!cmd->hdr)
return 0;
payload_bytes = (MSG_HDR_GET_SIZE(cmd->hdr) << 2) -
offsetof(struct hfi_context_bad_cmd_legacy, payload);
start = &cmd->payload[0];
while (i < payload_bytes) {
struct payload_section *payload = start + i;
if (payload->type == type)
return adreno_hwsched_parse_payload(payload, key);
i += struct_size(payload, data, payload->dwords);
}
return 0;
}
static void log_gpu_fault_legacy(struct adreno_device *adreno_dev)
{
struct device *gmu_pdev_dev = GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev));
struct hfi_context_bad_cmd_legacy *cmd = adreno_dev->hwsched.ctxt_bad;
switch (cmd->error) {
case GMU_GPU_HW_HANG:
dev_crit_ratelimited(gmu_pdev_dev, "MISC: GPU hang detected\n");
break;
case GMU_GPU_SW_HANG:
dev_crit_ratelimited(gmu_pdev_dev, "gpu timeout ctx %u ts %u\n",
cmd->ctxt_id, cmd->ts);
break;
case GMU_CP_OPCODE_ERROR:
dev_crit_ratelimited(gmu_pdev_dev,
"CP opcode error interrupt | opcode=0x%8.8x\n",
a6xx_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS,
KEY_CP_OPCODE_ERROR));
break;
case GMU_CP_PROTECTED_ERROR: {
u32 status = a6xx_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS,
KEY_CP_PROTECTED_ERROR);
dev_crit_ratelimited(gmu_pdev_dev,
"CP | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n",
status & (1 << 20) ? "READ" : "WRITE",
status & 0x3FFFF, status);
}
break;
case GMU_CP_ILLEGAL_INST_ERROR:
dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n");
break;
case GMU_CP_UCODE_ERROR:
dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n");
break;
case GMU_CP_HW_FAULT_ERROR:
dev_crit_ratelimited(gmu_pdev_dev,
"CP | Ringbuffer HW fault | status=0x%8.8x\n",
a6xx_hwsched_lookup_key_value_legacy(adreno_dev, PAYLOAD_FAULT_REGS,
KEY_CP_HW_FAULT));
break;
case GMU_GPU_PREEMPT_TIMEOUT: {
u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr;
cur = a6xx_hwsched_lookup_key_value_legacy(adreno_dev,
PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID);
next = a6xx_hwsched_lookup_key_value_legacy(adreno_dev,
PAYLOAD_PREEMPT_TIMEOUT,
KEY_PREEMPT_TIMEOUT_NEXT_RB_ID);
cur_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_RPTR);
cur_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, cur, KEY_RB_WPTR);
next_rptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_RPTR);
next_wptr = adreno_hwsched_get_payload_rb_key_legacy(adreno_dev, next, KEY_RB_WPTR);
dev_crit_ratelimited(gmu_pdev_dev,
"Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n",
cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr);
}
break;
case GMU_CP_GPC_ERROR:
dev_crit_ratelimited(gmu_pdev_dev, "RBBM: GPC error\n");
break;
default:
dev_crit_ratelimited(gmu_pdev_dev, "Unknown GPU fault: %u\n",
cmd->error);
break;
}
}
/* Look up a particular key's value for a given type of payload */
static u32 a6xx_hwsched_lookup_key_value(struct adreno_device *adreno_dev,
u32 type, u32 key)
{
struct hfi_context_bad_cmd *cmd = adreno_dev->hwsched.ctxt_bad;
u32 i = 0, payload_bytes;
void *start;
if (!cmd->hdr)
return 0;
payload_bytes = (MSG_HDR_GET_SIZE(cmd->hdr) << 2) -
offsetof(struct hfi_context_bad_cmd, payload);
start = &cmd->payload[0];
while (i < payload_bytes) {
struct payload_section *payload = start + i;
if (payload->type == type)
return adreno_hwsched_parse_payload(payload, key);
i += struct_size(payload, data, payload->dwords);
}
return 0;
}
static void log_gpu_fault(struct adreno_device *adreno_dev)
{
struct device *gmu_pdev_dev = GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev));
struct hfi_context_bad_cmd *cmd = adreno_dev->hwsched.ctxt_bad;
switch (cmd->error) {
case GMU_GPU_HW_HANG:
dev_crit_ratelimited(gmu_pdev_dev, "MISC: GPU hang detected\n");
break;
case GMU_GPU_SW_HANG:
dev_crit_ratelimited(gmu_pdev_dev, "gpu timeout ctx %u ts %u\n",
cmd->gc.ctxt_id, cmd->gc.ts);
break;
case GMU_CP_OPCODE_ERROR:
dev_crit_ratelimited(gmu_pdev_dev,
"CP opcode error interrupt | opcode=0x%8.8x\n",
a6xx_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS,
KEY_CP_OPCODE_ERROR));
break;
case GMU_CP_PROTECTED_ERROR: {
u32 status = a6xx_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS,
KEY_CP_PROTECTED_ERROR);
dev_crit_ratelimited(gmu_pdev_dev,
"CP | Protected mode error | %s | addr=0x%5.5x | status=0x%8.8x\n",
status & (1 << 20) ? "READ" : "WRITE",
status & 0x3FFFF, status);
}
break;
case GMU_CP_ILLEGAL_INST_ERROR:
dev_crit_ratelimited(gmu_pdev_dev, "CP Illegal instruction error\n");
break;
case GMU_CP_UCODE_ERROR:
dev_crit_ratelimited(gmu_pdev_dev, "CP ucode error interrupt\n");
break;
case GMU_CP_HW_FAULT_ERROR:
dev_crit_ratelimited(gmu_pdev_dev,
"CP | Ringbuffer HW fault | status=0x%8.8x\n",
a6xx_hwsched_lookup_key_value(adreno_dev, PAYLOAD_FAULT_REGS,
KEY_CP_HW_FAULT));
break;
case GMU_GPU_PREEMPT_TIMEOUT: {
u32 cur, next, cur_rptr, cur_wptr, next_rptr, next_wptr;
cur = a6xx_hwsched_lookup_key_value(adreno_dev,
PAYLOAD_PREEMPT_TIMEOUT, KEY_PREEMPT_TIMEOUT_CUR_RB_ID);
next = a6xx_hwsched_lookup_key_value(adreno_dev,
PAYLOAD_PREEMPT_TIMEOUT,
KEY_PREEMPT_TIMEOUT_NEXT_RB_ID);
cur_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_RPTR);
cur_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, cur, KEY_RB_WPTR);
next_rptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_RPTR);
next_wptr = adreno_hwsched_get_payload_rb_key(adreno_dev, next, KEY_RB_WPTR);
dev_crit_ratelimited(gmu_pdev_dev,
"Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n",
cur, cur_rptr, cur_wptr, next, next_rptr, next_wptr);
}
break;
case GMU_CP_GPC_ERROR:
dev_crit_ratelimited(gmu_pdev_dev, "RBBM: GPC error\n");
break;
default:
dev_crit_ratelimited(gmu_pdev_dev, "Unknown GPU fault: %u\n",
cmd->error);
break;
}
}
static void process_ctx_bad(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
if (GMU_VER_MINOR(device->gmu_core.ver.hfi) < 2)
log_gpu_fault_legacy(adreno_dev);
else
log_gpu_fault(adreno_dev);
adreno_scheduler_fault(adreno_dev, ADRENO_HARD_FAULT);
}
static u32 peek_next_header(struct a6xx_gmu_device *gmu, uint32_t queue_idx)
{
struct kgsl_memdesc *mem_addr = gmu->hfi.hfi_mem;
struct hfi_queue_table *tbl = mem_addr->hostptr;
struct hfi_queue_header *hdr = &tbl->qhdr[queue_idx];
u32 *queue;
if (hdr->status == HFI_QUEUE_STATUS_DISABLED)
return 0;
if (hdr->read_index == hdr->write_index)
return 0;
queue = HOST_QUEUE_START_ADDR(mem_addr, queue_idx);
return queue[hdr->read_index];
}
static void a6xx_hwsched_process_msgq(struct adreno_device *adreno_dev)
{
struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
struct a6xx_hwsched_hfi *hw_hfi = to_a6xx_hwsched_hfi(adreno_dev);
u32 rcvd[MAX_RCVD_SIZE], next_hdr;
if (!(hw_hfi->irq_mask & HFI_IRQ_MSGQ_MASK))
return;
mutex_lock(&hw_hfi->msgq_mutex);
for (;;) {
next_hdr = peek_next_header(gmu, HFI_MSG_ID);
if (!next_hdr)
break;
if (MSG_HDR_GET_ID(next_hdr) == F2H_MSG_CONTEXT_BAD) {
a6xx_hfi_queue_read(gmu, HFI_MSG_ID,
(u32 *)adreno_dev->hwsched.ctxt_bad,
HFI_MAX_MSG_SIZE);
process_ctx_bad(adreno_dev);
continue;
}
a6xx_hfi_queue_read(gmu, HFI_MSG_ID, rcvd, sizeof(rcvd));
/*
* We are assuming that there is only one outstanding ack
* because hfi sending thread waits for completion while
* holding the device mutex
*/
if (MSG_HDR_GET_TYPE(rcvd[0]) == HFI_MSG_ACK) {
a6xx_receive_ack_async(adreno_dev, rcvd);
} else if (MSG_HDR_GET_ID(rcvd[0]) == F2H_MSG_TS_RETIRE) {
adreno_scheduler_queue(adreno_dev);
adreno_hwsched_log_profiling_info(adreno_dev, rcvd);
} else if (MSG_HDR_GET_ID(rcvd[0]) == F2H_MSG_GMU_CNTR_RELEASE) {
struct hfi_gmu_cntr_release_cmd *cmd =
(struct hfi_gmu_cntr_release_cmd *) rcvd;
adreno_perfcounter_put(adreno_dev,
cmd->group_id, cmd->countable, PERFCOUNTER_FLAG_KERNEL);
}
}
mutex_unlock(&hw_hfi->msgq_mutex);
}
static void process_log_block(struct adreno_device *adreno_dev, void *data)
{
struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
struct hfi_log_block *cmd = data;
u32 *log_event = gmu->gmu_log->hostptr;
u32 start, end;
start = cmd->start_index;
end = cmd->stop_index;
log_event += start * 4;
while (start != end) {
trace_gmu_event(log_event);
log_event += 4;
start++;
}
}
static void a6xx_hwsched_process_dbgq(struct adreno_device *adreno_dev, bool limited)
{
struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
u32 rcvd[MAX_RCVD_SIZE];
bool recovery = false;
while (a6xx_hfi_queue_read(gmu, HFI_DBG_ID, rcvd, sizeof(rcvd)) > 0) {
if (MSG_HDR_GET_ID(rcvd[0]) == F2H_MSG_ERR) {
adreno_a6xx_receive_err_req(gmu, rcvd);
recovery = true;
break;
}
if (MSG_HDR_GET_ID(rcvd[0]) == F2H_MSG_DEBUG)
adreno_a6xx_receive_debug_req(gmu, rcvd);
if (MSG_HDR_GET_ID(rcvd[0]) == F2H_MSG_LOG_BLOCK)
process_log_block(adreno_dev, rcvd);
/* Process one debug queue message and return to not delay msgq processing */
if (limited)
break;
}
if (!recovery)
return;
adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT);
}
/* HFI interrupt handler */
static irqreturn_t a6xx_hwsched_hfi_handler(int irq, void *data)
{
struct adreno_device *adreno_dev = data;
struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev);
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
u32 status = 0;
/*
* A6XX_GMU_GMU2HOST_INTR_INFO may have bits set not specified in hfi->irq_mask.
* Read and clear only those irq bits that we are processing here.
*/
gmu_core_regread(device, A6XX_GMU_GMU2HOST_INTR_INFO, &status);
gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, status & hfi->irq_mask);
/*
* If interrupts are not enabled on the HFI message queue,
* the inline message processing loop will process it,
* else, process it here.
*/
if (!(hfi->irq_mask & HFI_IRQ_MSGQ_MASK))
status &= ~HFI_IRQ_MSGQ_MASK;
if (status & (HFI_IRQ_MSGQ_MASK | HFI_IRQ_DBGQ_MASK)) {
wake_up_interruptible(&hfi->f2h_wq);
adreno_scheduler_queue(adreno_dev);
}
if (status & HFI_IRQ_CM3_FAULT_MASK) {
atomic_set(&gmu->cm3_fault, 1);
/* make sure other CPUs see the update */
smp_wmb();
dev_err_ratelimited(GMU_PDEV_DEV(device),
"GMU CM3 fault interrupt received\n");
adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT);
}
/* Ignore OOB bits */
status &= GENMASK(31 - (oob_max - 1), 0);
if (status & ~hfi->irq_mask)
dev_err_ratelimited(GMU_PDEV_DEV(device),
"Unhandled HFI interrupts 0x%x\n",
status & ~hfi->irq_mask);
return IRQ_HANDLED;
}
#define HFI_IRQ_MSGQ_MASK BIT(0)
static int check_ack_failure(struct adreno_device *adreno_dev,
struct pending_cmd *ack)
{
const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
u64 ticks = gpudev->read_alwayson(adreno_dev);
if (ack->results[2] != 0xffffffff)
return 0;
dev_err(GMU_PDEV_DEV(device),
"ACK error: sender id %d seqnum %d\n",
MSG_HDR_GET_ID(ack->sent_hdr),
MSG_HDR_GET_SEQNUM(ack->sent_hdr));
KGSL_GMU_CORE_FORCE_PANIC(device->gmu_core.gf_panic,
GMU_PDEV(device), ticks, GMU_FAULT_HFI_ACK);
return -EINVAL;
}
int a6xx_hfi_send_cmd_async(struct adreno_device *adreno_dev, void *data, u32 size_bytes)
{
struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev);
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
u32 *cmd = data;
u32 seqnum;
int rc;
struct pending_cmd pending_ack;
seqnum = atomic_inc_return(&gmu->hfi.seqnum);
*cmd = MSG_HDR_SET_SEQNUM_SIZE(*cmd, seqnum, size_bytes >> 2);
add_waiter(hfi, *cmd, &pending_ack);
rc = a6xx_hfi_cmdq_write(adreno_dev, cmd, size_bytes);
if (rc)
goto done;
rc = adreno_hwsched_wait_ack_completion(adreno_dev,
GMU_PDEV_DEV(device), &pending_ack, a6xx_hwsched_process_msgq);
if (rc)
goto done;
rc = check_ack_failure(adreno_dev, &pending_ack);
done:
del_waiter(hfi, &pending_ack);
return rc;
}
static void init_queues(struct a6xx_hfi *hfi)
{
u32 gmuaddr = hfi->hfi_mem->gmuaddr;
struct hfi_queue_table hfi_table = {
.qtbl_hdr = {
.version = 0,
.size = sizeof(struct hfi_queue_table) >> 2,
.qhdr0_offset =
sizeof(struct hfi_queue_table_header) >> 2,
.qhdr_size = sizeof(struct hfi_queue_header) >> 2,
.num_q = HFI_QUEUE_MAX,
.num_active_q = HFI_QUEUE_MAX,
},
.qhdr = {
DEFINE_QHDR(gmuaddr, HFI_CMD_ID, 0),
DEFINE_QHDR(gmuaddr, HFI_MSG_ID, 0),
DEFINE_QHDR(gmuaddr, HFI_DBG_ID, 0),
/* 4 DQs for RB priority 0 */
DEFINE_QHDR(gmuaddr, 3, 0),
DEFINE_QHDR(gmuaddr, 4, 0),
DEFINE_QHDR(gmuaddr, 5, 0),
DEFINE_QHDR(gmuaddr, 6, 0),
/* 4 DQs for RB priority 1 */
DEFINE_QHDR(gmuaddr, 7, 1),
DEFINE_QHDR(gmuaddr, 8, 1),
DEFINE_QHDR(gmuaddr, 9, 1),
DEFINE_QHDR(gmuaddr, 10, 1),
/* 3 DQs for RB priority 2 */
DEFINE_QHDR(gmuaddr, 11, 2),
DEFINE_QHDR(gmuaddr, 12, 2),
DEFINE_QHDR(gmuaddr, 13, 2),
/* 3 DQs for RB priority 3 */
DEFINE_QHDR(gmuaddr, 14, 3),
DEFINE_QHDR(gmuaddr, 15, 3),
DEFINE_QHDR(gmuaddr, 16, 3),
},
};
memcpy(hfi->hfi_mem->hostptr, &hfi_table, sizeof(hfi_table));
}
/* Total header sizes + queue sizes + 16 for alignment */
#define HFIMEM_SIZE (sizeof(struct hfi_queue_table) + 16 + \
(SZ_4K * HFI_QUEUE_MAX))
static int hfi_f2h_main(void *arg);
int a6xx_hwsched_hfi_init(struct adreno_device *adreno_dev)
{
struct a6xx_hwsched_hfi *hw_hfi = to_a6xx_hwsched_hfi(adreno_dev);
struct a6xx_hfi *hfi = to_a6xx_hfi(adreno_dev);
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
if (IS_ERR_OR_NULL(hw_hfi->big_ib)) {
hw_hfi->big_ib = gmu_core_reserve_kernel_block(device,
0,
HWSCHED_MAX_IBS * sizeof(struct hfi_issue_ib),
GMU_NONCACHED_KERNEL, 0);
if (IS_ERR(hw_hfi->big_ib))
return PTR_ERR(hw_hfi->big_ib);
}
if (ADRENO_FEATURE(adreno_dev, ADRENO_LSR) &&
IS_ERR_OR_NULL(hw_hfi->big_ib_recurring)) {
hw_hfi->big_ib_recurring = gmu_core_reserve_kernel_block(
device, 0,
HWSCHED_MAX_IBS * sizeof(struct hfi_issue_ib),
GMU_NONCACHED_KERNEL, 0);
if (IS_ERR(hw_hfi->big_ib_recurring))
return PTR_ERR(hw_hfi->big_ib_recurring);
}
if (IS_ERR_OR_NULL(hfi->hfi_mem)) {
hfi->hfi_mem = gmu_core_reserve_kernel_block(device,
0, HFIMEM_SIZE, GMU_NONCACHED_KERNEL, 0);
if (IS_ERR(hfi->hfi_mem))
return PTR_ERR(hfi->hfi_mem);
init_queues(hfi);
}
if (IS_ERR_OR_NULL(hw_hfi->f2h_task))
hw_hfi->f2h_task = kthread_run(hfi_f2h_main, adreno_dev, "gmu_f2h");
return PTR_ERR_OR_ZERO(hw_hfi->f2h_task);
}
static int mem_alloc_reply(struct adreno_device *adreno_dev, void *rcvd)
{
struct hfi_mem_alloc_desc desc = {0};
struct hfi_mem_alloc_reply_cmd out = {0};
struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
u32 seqnum;
int ret;
hfi_get_mem_alloc_desc(rcvd, &desc);
ret = adreno_hwsched_process_mem_alloc(adreno_dev, &desc);
if (ret)
return ret;
memcpy(&out.desc, &desc, sizeof(out.desc));
out.hdr = ACK_MSG_HDR(F2H_MSG_MEM_ALLOC);
seqnum = atomic_inc_return(&gmu->hfi.seqnum);
out.hdr = MSG_HDR_SET_SEQNUM_SIZE(out.hdr, seqnum, sizeof(out) >> 2);
out.req_hdr = *(u32 *)rcvd;
return a6xx_hfi_cmdq_write(adreno_dev, (u32 *)&out, sizeof(out));
}
static int gmu_cntr_register_reply(struct adreno_device *adreno_dev, void *rcvd)
{
struct hfi_gmu_cntr_register_cmd *in = (struct hfi_gmu_cntr_register_cmd *)rcvd;
struct hfi_gmu_cntr_register_reply_cmd out = {0};
struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
u32 lo = 0, hi = 0, seqnum;
/*
* Failure to allocate counter is not fatal. Sending lo = 0, hi = 0
* indicates to GMU that counter allocation failed.
*/
adreno_perfcounter_get(adreno_dev,
in->group_id, in->countable, &lo, &hi, PERFCOUNTER_FLAG_KERNEL);
out.hdr = ACK_MSG_HDR(F2H_MSG_GMU_CNTR_REGISTER);
seqnum = atomic_inc_return(&gmu->hfi.seqnum);
out.hdr = MSG_HDR_SET_SEQNUM_SIZE(out.hdr, seqnum, sizeof(out) >> 2);
out.req_hdr = in->hdr;
out.group_id = in->group_id;
out.countable = in->countable;
/* Fill in byte offset of counter */
out.cntr_lo = lo << 2;
out.cntr_hi = hi << 2;
return a6xx_hfi_cmdq_write(adreno_dev, (u32 *)&out, sizeof(out));
}
static int send_start_msg(struct adreno_device *adreno_dev)
{
struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct device *gmu_pdev_dev = GMU_PDEV_DEV(device);
u32 seqnum;
int rc;
struct hfi_start_cmd cmd;
u32 rcvd[MAX_RCVD_SIZE];
struct pending_cmd pending_ack = {0};
rc = CMD_MSG_HDR(cmd, H2F_MSG_START);
if (rc)
return rc;
seqnum = atomic_inc_return(&gmu->hfi.seqnum);
cmd.hdr = MSG_HDR_SET_SEQNUM_SIZE(cmd.hdr, seqnum, sizeof(cmd) >> 2);
pending_ack.sent_hdr = cmd.hdr;
rc = a6xx_hfi_cmdq_write(adreno_dev, (u32 *)&cmd, sizeof(cmd));
if (rc)
return rc;
poll:
rc = adreno_hwsched_poll_msg_queue_write_index(gmu->hfi.hfi_mem);
if (rc) {
dev_err(gmu_pdev_dev,
"Timed out processing MSG_START seqnum: %d\n",
seqnum);
gmu_core_fault_snapshot(device, GMU_FAULT_H2F_MSG_START);
goto done;
}
rc = a6xx_hfi_queue_read(gmu, HFI_MSG_ID, rcvd, sizeof(rcvd));
if (rc <= 0) {
dev_err(gmu_pdev_dev,
"MSG_START: payload error: %d\n",
rc);
gmu_core_fault_snapshot(device, GMU_FAULT_H2F_MSG_START);
goto done;
}
switch (MSG_HDR_GET_ID(rcvd[0])) {
case F2H_MSG_MEM_ALLOC:
rc = mem_alloc_reply(adreno_dev, rcvd);
break;
case F2H_MSG_GMU_CNTR_REGISTER:
rc = gmu_cntr_register_reply(adreno_dev, rcvd);
break;
default:
if (MSG_HDR_GET_TYPE(rcvd[0]) == HFI_MSG_ACK) {
rc = a6xx_receive_ack_cmd(gmu, rcvd, &pending_ack);
/* Check ack failure if we received an expected ack */
if (!rc)
rc = check_ack_failure(adreno_dev, &pending_ack);
goto done;
} else {
dev_err(gmu_pdev_dev,
"MSG_START: unexpected response id:%d, type:%d\n",
MSG_HDR_GET_ID(rcvd[0]),
MSG_HDR_GET_TYPE(rcvd[0]));
gmu_core_fault_snapshot(device, GMU_FAULT_H2F_MSG_START);
rc = -EINVAL;
goto done;
}
}
if (!rc)
goto poll;
done:
/* Clear the interrupt */
gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, HFI_IRQ_MSGQ_MASK);
/*
* Add a write barrier to post the interrupt clear so that we dont have a
* pending interrupt.
*/
wmb();
return rc;
}
static void reset_hfi_queues(struct adreno_device *adreno_dev)
{
struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
struct hfi_queue_table *tbl = gmu->hfi.hfi_mem->hostptr;
u32 i;
/* Flush HFI queues */
for (i = 0; i < HFI_QUEUE_MAX; i++) {
struct hfi_queue_header *hdr = &tbl->qhdr[i];
if (hdr->status == HFI_QUEUE_STATUS_DISABLED)
continue;
hdr->read_index = hdr->write_index;
}
}
void a6xx_hwsched_hfi_stop(struct adreno_device *adreno_dev)
{
struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev);
hfi->irq_mask &= ~HFI_IRQ_MSGQ_MASK;
/*
* In some corner cases, it is possible that GMU put TS_RETIRE
* on the msgq after we have turned off gmu interrupts. Hence,
* drain the queue one last time before we reset HFI queues.
*/
a6xx_hwsched_process_msgq(adreno_dev);
/* Drain the debug queue before we reset HFI queues */
a6xx_hwsched_process_dbgq(adreno_dev, false);
kgsl_pwrctrl_axi(KGSL_DEVICE(adreno_dev), false);
clear_bit(GMU_PRIV_HFI_STARTED, &gmu->flags);
}
static void enable_async_hfi(struct adreno_device *adreno_dev)
{
struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev);
hfi->irq_mask |= HFI_IRQ_MSGQ_MASK;
gmu_core_regwrite(KGSL_DEVICE(adreno_dev), A6XX_GMU_GMU2HOST_INTR_MASK,
(u32)~hfi->irq_mask);
}
static int enable_preemption(struct adreno_device *adreno_dev)
{
u32 data;
int ret;
if (!adreno_is_preemption_enabled(adreno_dev))
return 0;
/*
* Bits [0:1] contains the preemption level
* Bit 2 is to enable/disable gmem save/restore
* Bit 3 is to enable/disable skipsaverestore
*/
data = FIELD_PREP(GENMASK(1, 0), adreno_dev->preempt.preempt_level) |
FIELD_PREP(BIT(2), adreno_dev->preempt.usesgmem) |
FIELD_PREP(BIT(3), adreno_dev->preempt.skipsaverestore);
ret = a6xx_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_PREEMPTION, 1,
data);
if (ret)
return ret;
/*
* Bits[3:0] contain the preemption timeout enable bit per ringbuffer
* Bits[31:4] contain the timeout in ms
*/
return a6xx_hfi_send_set_value(adreno_dev, HFI_VALUE_BIN_TIME, 1,
FIELD_PREP(GENMASK(31, 4), ADRENO_PREEMPT_TIMEOUT) |
FIELD_PREP(GENMASK(3, 0), 0xf));
}
static int enable_gmu_stats(struct adreno_device *adreno_dev)
{
struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
u32 data;
if (!gmu->stats_enable)
return 0;
/*
* Bits [23:0] contains the countables mask
* Bits [31:24] is the sampling interval
*/
data = FIELD_PREP(GENMASK(23, 0), gmu->stats_mask) |
FIELD_PREP(GENMASK(31, 24), gmu->stats_interval);
return a6xx_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_GMU_STATS, 1, data);
}
static int a6xx_hfi_send_perfcounter_feature_ctrl(struct adreno_device *adreno_dev)
{
/*
* Perfcounter retention is disabled by default in GMU firmware.
* In case perfcounter retention behaviour is overwritten by sysfs
* setting dynmaically, send this HFI feature with 'enable = 0' to
* disable this feature in GMU firmware.
*/
if (adreno_dev->perfcounter)
return a6xx_hfi_send_feature_ctrl(adreno_dev,
HFI_FEATURE_PERF_NORETAIN, 0, 0);
return 0;
}
int a6xx_hwsched_hfi_start(struct adreno_device *adreno_dev)
{
struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
int ret;
reset_hfi_queues(adreno_dev);
ret = a6xx_gmu_hfi_start(adreno_dev);
if (ret)
goto err;
ret = a6xx_hfi_send_generic_req(adreno_dev, &gmu->hfi.dcvs_table,
sizeof(gmu->hfi.dcvs_table));
if (ret)
goto err;
ret = a6xx_hfi_send_generic_req(adreno_dev, &gmu->hfi.bw_table, sizeof(gmu->hfi.bw_table));
if (ret)
goto err;
ret = a6xx_hfi_send_acd_feature_ctrl(adreno_dev);
if (ret)
goto err;
ret = a6xx_hfi_send_lm_feature_ctrl(adreno_dev);
if (ret)
goto err;
ret = a6xx_hfi_send_bcl_feature_ctrl(adreno_dev);
if (ret)
goto err;
ret = a6xx_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_HWSCHED, 1, 0);
if (ret)
goto err;
ret = a6xx_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_KPROF, 1, 0);
if (ret)
goto err;
if (ADRENO_FEATURE(adreno_dev, ADRENO_LSR)) {
ret = a6xx_hfi_send_feature_ctrl(adreno_dev, HFI_FEATURE_LSR,
1, 0);
if (ret)
goto err;
}
ret = a6xx_hfi_send_perfcounter_feature_ctrl(adreno_dev);
if (ret)
goto err;
/* Enable the long ib timeout detection */
if (adreno_long_ib_detect(adreno_dev)) {
ret = a6xx_hfi_send_feature_ctrl(adreno_dev,
HFI_FEATURE_BAIL_OUT_TIMER, 1, 0);
if (ret)
goto err;
}
enable_gmu_stats(adreno_dev);
if (gmu->log_stream_enable)
a6xx_hfi_send_set_value(adreno_dev,
HFI_VALUE_LOG_STREAM_ENABLE, 0, 1);
if (gmu->log_group_mask)
a6xx_hfi_send_set_value(adreno_dev, HFI_VALUE_LOG_GROUP, 0, gmu->log_group_mask);
ret = a6xx_hfi_send_core_fw_start(adreno_dev);
if (ret)
goto err;
ret = enable_preemption(adreno_dev);
if (ret)
goto err;
ret = send_start_msg(adreno_dev);
if (ret)
goto err;
enable_async_hfi(adreno_dev);
set_bit(GMU_PRIV_HFI_STARTED, &gmu->flags);
ret = kgsl_pwrctrl_setup_default_votes(device);
err:
if (ret)
a6xx_hwsched_hfi_stop(adreno_dev);
return ret;
}
static int submit_raw_cmds(struct adreno_device *adreno_dev, void *cmds, u32 size_bytes,
const char *str)
{
int ret;
ret = a6xx_hfi_send_cmd_async(adreno_dev, cmds, size_bytes);
if (ret)
return ret;
ret = gmu_core_timed_poll_check(KGSL_DEVICE(adreno_dev),
A6XX_GPU_GMU_AO_GPU_CX_BUSY_STATUS, 0, 200, BIT(23));