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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
|
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*/
#include "adreno.h"
#include "adreno_a6xx.h"
#include "adreno_a6xx_hwsched.h"
#include "adreno_snapshot.h"
#include "adreno_sysfs.h"
#include "adreno_trace.h"
/* This structure represents inflight command object */
struct cmd_list_obj {
/** @cmdobj: Handle to the command object */
struct kgsl_drawobj_cmd *cmdobj;
/** @node: List node to put it in the list of inflight commands */
struct list_head node;
};
/* Number of milliseconds to wait for the context queue to clear */
static unsigned int _context_queue_wait = 10000;
/* Use a kmem cache to speed up allocations for dispatcher jobs */
static struct kmem_cache *jobs_cache;
/* Use a kmem cache to speed up allocations for inflight command objects */
static struct kmem_cache *obj_cache;
static struct adreno_hwsched *to_hwsched(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;
}
static struct adreno_device *hwsched_to_adreno(struct adreno_hwsched *hwsched)
{
struct a6xx_hwsched_device *a6xx_hwsched = container_of(hwsched,
struct a6xx_hwsched_device, hwsched);
return &a6xx_hwsched->a6xx_dev.adreno_dev;
}
static bool _check_context_queue(struct adreno_context *drawctxt)
{
bool ret;
spin_lock(&drawctxt->lock);
/*
* Wake up if there is room in the context or if the whole thing got
* invalidated while we were asleep
*/
if (kgsl_context_invalid(&drawctxt->base))
ret = false;
else
ret = drawctxt->queued < (ADRENO_CONTEXT_DRAWQUEUE_SIZE - 1);
spin_unlock(&drawctxt->lock);
return ret;
}
static void _pop_drawobj(struct adreno_context *drawctxt)
{
drawctxt->drawqueue_head = DRAWQUEUE_NEXT(drawctxt->drawqueue_head,
ADRENO_CONTEXT_DRAWQUEUE_SIZE);
drawctxt->queued--;
}
static int _retire_syncobj(struct kgsl_drawobj_sync *syncobj,
struct adreno_context *drawctxt)
{
if (!kgsl_drawobj_events_pending(syncobj)) {
_pop_drawobj(drawctxt);
kgsl_drawobj_destroy(DRAWOBJ(syncobj));
return 0;
}
/*
* If we got here, there are pending events for sync object.
* Start the canary timer if it hasnt been started already.
*/
if (!syncobj->timeout_jiffies) {
syncobj->timeout_jiffies = jiffies + msecs_to_jiffies(5000);
mod_timer(&syncobj->timer, syncobj->timeout_jiffies);
}
return -EAGAIN;
}
static bool _marker_expired(struct kgsl_drawobj_cmd *markerobj)
{
struct kgsl_drawobj *drawobj = DRAWOBJ(markerobj);
return (drawobj->flags & KGSL_DRAWOBJ_MARKER) &&
kgsl_check_timestamp(drawobj->device, drawobj->context,
markerobj->marker_timestamp);
}
static void _retire_timestamp(struct kgsl_drawobj *drawobj)
{
struct kgsl_context *context = drawobj->context;
struct kgsl_device *device = context->device;
/*
* Write the start and end timestamp to the memstore to keep the
* accounting sane
*/
kgsl_sharedmem_writel(device->memstore,
KGSL_MEMSTORE_OFFSET(context->id, soptimestamp),
drawobj->timestamp);
kgsl_sharedmem_writel(device->memstore,
KGSL_MEMSTORE_OFFSET(context->id, eoptimestamp),
drawobj->timestamp);
/* Retire pending GPU events for the object */
kgsl_process_event_group(device, &context->events);
kgsl_drawobj_destroy(drawobj);
}
static int _retire_markerobj(struct kgsl_drawobj_cmd *cmdobj,
struct adreno_context *drawctxt)
{
if (_marker_expired(cmdobj)) {
_pop_drawobj(drawctxt);
_retire_timestamp(DRAWOBJ(cmdobj));
return 0;
}
/*
* If the marker isn't expired but the SKIP bit
* is set then there are real commands following
* this one in the queue. This means that we
* need to dispatch the command so that we can
* keep the timestamp accounting correct. If
* skip isn't set then we block this queue
* until the dependent timestamp expires
*/
return test_bit(CMDOBJ_SKIP, &cmdobj->priv) ? 1 : -EAGAIN;
}
/*
* Retires all expired marker and sync objs from the context
* queue and returns one of the below
* a) next drawobj that needs to be sent to ringbuffer
* b) -EAGAIN for syncobj with syncpoints pending.
* c) -EAGAIN for markerobj whose marker timestamp has not expired yet.
* c) NULL for no commands remaining in drawqueue.
*/
static struct kgsl_drawobj *_process_drawqueue_get_next_drawobj(
struct adreno_context *drawctxt)
{
struct kgsl_drawobj *drawobj;
unsigned int i = drawctxt->drawqueue_head;
int ret = 0;
if (drawctxt->drawqueue_head == drawctxt->drawqueue_tail)
return NULL;
for (i = drawctxt->drawqueue_head; i != drawctxt->drawqueue_tail;
i = DRAWQUEUE_NEXT(i, ADRENO_CONTEXT_DRAWQUEUE_SIZE)) {
drawobj = drawctxt->drawqueue[i];
if (drawobj == NULL)
return NULL;
if (drawobj->type == CMDOBJ_TYPE)
return drawobj;
else if (drawobj->type == SYNCOBJ_TYPE)
ret = _retire_syncobj(SYNCOBJ(drawobj), drawctxt);
else if (drawobj->type == MARKEROBJ_TYPE) {
ret = _retire_markerobj(CMDOBJ(drawobj), drawctxt);
/* Special case where marker needs to be sent to GPU */
if (ret == 1)
return drawobj;
} else {
return ERR_PTR(-EINVAL);
}
if (ret == -EAGAIN)
return ERR_PTR(-EAGAIN);
}
return NULL;
}
/**
* hwsched_dispatcher_requeue_cmdobj() - Put a command back on the context
* queue
* @drawctxt: Pointer to the adreno draw context
* @cmdobj: Pointer to the KGSL command object to requeue
*
* Failure to submit a command to the ringbuffer isn't the fault of the command
* being submitted so if a failure happens, push it back on the head of the
* context queue to be reconsidered again unless the context got detached.
*/
static inline int hwsched_dispatcher_requeue_cmdobj(
struct adreno_context *drawctxt,
struct kgsl_drawobj_cmd *cmdobj)
{
unsigned int prev;
struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj);
spin_lock(&drawctxt->lock);
if (kgsl_context_detached(&drawctxt->base) ||
kgsl_context_invalid(&drawctxt->base)) {
spin_unlock(&drawctxt->lock);
/* get rid of this drawobj since the context is bad */
kgsl_drawobj_destroy(drawobj);
return -ENOENT;
}
prev = drawctxt->drawqueue_head == 0 ?
(ADRENO_CONTEXT_DRAWQUEUE_SIZE - 1) :
(drawctxt->drawqueue_head - 1);
/*
* The maximum queue size always needs to be one less then the size of
* the ringbuffer queue so there is "room" to put the drawobj back in
*/
WARN_ON(prev == drawctxt->drawqueue_tail);
drawctxt->drawqueue[prev] = drawobj;
drawctxt->queued++;
/* Reset the command queue head to reflect the newly requeued change */
drawctxt->drawqueue_head = prev;
spin_unlock(&drawctxt->lock);
return 0;
}
/**
* hwsched_queue_context() - Queue a context in the dispatcher list of jobs
* @adreno_dev: Pointer to the adreno device structure
* @drawctxt: Pointer to the adreno draw context
*
* Add a context to the dispatcher list of jobs.
*/
static int hwsched_queue_context(struct adreno_device *adreno_dev,
struct adreno_context *drawctxt)
{
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
struct adreno_dispatch_job *job;
/* Refuse to queue a detached context */
if (kgsl_context_detached(&drawctxt->base))
return 0;
if (!_kgsl_context_get(&drawctxt->base))
return 0;
job = kmem_cache_alloc(jobs_cache, GFP_ATOMIC);
if (!job) {
kgsl_context_put(&drawctxt->base);
return -ENOMEM;
}
job->drawctxt = drawctxt;
trace_dispatch_queue_context(drawctxt);
llist_add(&job->node, &hwsched->jobs[drawctxt->base.priority]);
return 0;
}
void adreno_hwsched_set_fault(struct adreno_device *adreno_dev)
{
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
atomic_set(&hwsched->fault, ADRENO_HWSCHED_FAULT_RESTART);
/* make sure fault is written before triggering dispatcher */
smp_wmb();
adreno_hwsched_trigger(adreno_dev);
}
static bool hwsched_in_fault(struct adreno_hwsched *hwsched)
{
/* make sure we're reading the latest value */
smp_rmb();
return atomic_read(&hwsched->fault) != 0;
}
/**
* sendcmd() - Send a drawobj to the GPU hardware
* @dispatcher: Pointer to the adreno dispatcher struct
* @drawobj: Pointer to the KGSL drawobj being sent
*
* Send a KGSL drawobj to the GPU hardware
*/
static int hwsched_sendcmd(struct adreno_device *adreno_dev,
struct kgsl_drawobj_cmd *cmdobj)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj);
struct kgsl_context *context = drawobj->context;
struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context);
int ret;
struct cmd_list_obj *obj;
obj = kmem_cache_alloc(obj_cache, GFP_KERNEL);
if (!obj)
return -ENOMEM;
mutex_lock(&device->mutex);
if (adreno_gpu_halt(adreno_dev) != 0) {
mutex_unlock(&device->mutex);
kmem_cache_free(obj_cache, obj);
return -EBUSY;
}
if (kgsl_context_detached(context)) {
mutex_unlock(&device->mutex);
kmem_cache_free(obj_cache, obj);
return -ENOENT;
}
hwsched->inflight++;
if (hwsched->inflight == 1 &&
!test_bit(ADRENO_HWSCHED_POWER, &hwsched->flags)) {
ret = adreno_active_count_get(adreno_dev);
if (ret) {
hwsched->inflight--;
mutex_unlock(&device->mutex);
kmem_cache_free(obj_cache, obj);
return ret;
}
set_bit(ADRENO_HWSCHED_POWER, &hwsched->flags);
}
ret = a6xx_hwsched_submit_cmdobj(adreno_dev, cmdobj);
if (ret) {
/*
* If the first submission failed, then put back the active
* count to relinquish active vote
*/
if (hwsched->inflight == 1) {
adreno_active_count_put(adreno_dev);
clear_bit(ADRENO_HWSCHED_POWER, &hwsched->flags);
} else if (device->gmu_fault) {
/*
* If we encountered a GMU fault, then trigger reset and
* recovery.
*/
adreno_get_gpu_halt(adreno_dev);
adreno_hwsched_set_fault(adreno_dev);
}
hwsched->inflight--;
kmem_cache_free(obj_cache, obj);
mutex_unlock(&device->mutex);
return ret;
}
drawctxt->internal_timestamp = drawobj->timestamp;
obj->cmdobj = cmdobj;
list_add_tail(&obj->node, &hwsched->cmd_list);
mutex_unlock(&device->mutex);
return 0;
}
/**
* hwsched_sendcmds() - Send commands from a context to the GPU
* @adreno_dev: Pointer to the adreno device struct
* @drawctxt: Pointer to the adreno context to dispatch commands from
*
* Dequeue and send a burst of commands from the specified context to the GPU
* Returns postive if the context needs to be put back on the pending queue
* 0 if the context is empty or detached and negative on error
*/
static int hwsched_sendcmds(struct adreno_device *adreno_dev,
struct adreno_context *drawctxt)
{
int count = 0;
int ret = 0;
unsigned int timestamp;
while (1) {
struct kgsl_drawobj *drawobj;
struct kgsl_drawobj_cmd *cmdobj;
spin_lock(&drawctxt->lock);
drawobj = _process_drawqueue_get_next_drawobj(drawctxt);
/*
* adreno_context_get_drawobj returns -EAGAIN if the current
* drawobj has pending sync points so no more to do here.
* When the sync points are satisfied then the context will get
* reqeueued
*/
if (IS_ERR_OR_NULL(drawobj)) {
if (IS_ERR(drawobj))
ret = PTR_ERR(drawobj);
spin_unlock(&drawctxt->lock);
break;
}
_pop_drawobj(drawctxt);
spin_unlock(&drawctxt->lock);
timestamp = drawobj->timestamp;
cmdobj = CMDOBJ(drawobj);
ret = hwsched_sendcmd(adreno_dev, cmdobj);
/*
* On error from hwsched_sendcmd() try to requeue the cmdobj
* unless we got back -ENOENT which means that the context has
* been detached and there will be no more deliveries from here
*/
if (ret != 0) {
/* Destroy the cmdobj on -ENOENT */
if (ret == -ENOENT)
kgsl_drawobj_destroy(drawobj);
else {
/*
* If we couldn't put it on dispatch queue
* then return it to the context queue
*/
int r = hwsched_dispatcher_requeue_cmdobj(
drawctxt, cmdobj);
if (r)
ret = r;
}
break;
}
drawctxt->submitted_timestamp = timestamp;
count++;
}
/*
* Wake up any snoozing threads if we have consumed any real commands
* or marker commands and we have room in the context queue.
*/
if (_check_context_queue(drawctxt))
wake_up_all(&drawctxt->wq);
if (!ret)
ret = count;
/* Return error or the number of commands queued */
return ret;
}
static bool adreno_drawctxt_bad(struct adreno_context *drawctxt)
{
return (kgsl_context_detached(&drawctxt->base) ||
kgsl_context_invalid(&drawctxt->base));
}
static void hwsched_handle_jobs_list(struct adreno_device *adreno_dev,
int id, unsigned long *map, struct llist_node *list)
{
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
struct adreno_dispatch_job *job, *next;
if (!list)
return;
/* Reverse the list so we deal with oldest submitted contexts first */
list = llist_reverse_order(list);
llist_for_each_entry_safe(job, next, list, node) {
int ret;
if (adreno_drawctxt_bad(job->drawctxt)) {
kgsl_context_put(&job->drawctxt->base);
kmem_cache_free(jobs_cache, job);
continue;
}
/*
* Due to the nature of the lockless queue the same context
* might have multiple jobs on the list. We allow this so we
* don't have to query the list on the producer side but on the
* consumer side we only want each context to be considered
* once. Use a bitmap to remember which contexts we've already
* seen and quietly discard duplicate jobs
*/
if (test_and_set_bit(job->drawctxt->base.id, map)) {
kgsl_context_put(&job->drawctxt->base);
kmem_cache_free(jobs_cache, job);
continue;
}
ret = hwsched_sendcmds(adreno_dev, job->drawctxt);
/*
* If the context had nothing queued or the context has been
* destroyed then drop the job
*/
if (!ret || ret == -ENOENT) {
kgsl_context_put(&job->drawctxt->base);
kmem_cache_free(jobs_cache, job);
continue;
}
/*
* If the dispatch queue is full then requeue the job to be
* considered first next time. Otherwise the context
* either successfully submmitted to the GPU or another error
* happened and it should go back on the regular queue
*/
if (ret == -ENOSPC)
llist_add(&job->node, &hwsched->requeue[id]);
else
llist_add(&job->node, &hwsched->jobs[id]);
}
}
static void hwsched_handle_jobs(struct adreno_device *adreno_dev, int id)
{
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
unsigned long map[BITS_TO_LONGS(KGSL_MEMSTORE_MAX)];
struct llist_node *requeue, *jobs;
memset(map, 0, sizeof(map));
requeue = llist_del_all(&hwsched->requeue[id]);
jobs = llist_del_all(&hwsched->jobs[id]);
hwsched_handle_jobs_list(adreno_dev, id, map, requeue);
hwsched_handle_jobs_list(adreno_dev, id, map, jobs);
}
/**
* hwsched_issuecmds() - Issue commmands from pending contexts
* @adreno_dev: Pointer to the adreno device struct
*
* Issue as many commands as possible (up to inflight) from the pending contexts
* This function assumes the dispatcher mutex has been locked.
*/
static void hwsched_issuecmds(struct adreno_device *adreno_dev)
{
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
int i;
for (i = 0; i < ARRAY_SIZE(hwsched->jobs); i++)
hwsched_handle_jobs(adreno_dev, i);
}
void adreno_hwsched_trigger(struct adreno_device *adreno_dev)
{
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
kthread_queue_work(&kgsl_driver.worker, &hwsched->work);
}
/**
* adreno_hwsched_issuecmds() - Issue commmands from pending contexts
* @adreno_dev: Pointer to the adreno device struct
*
* Lock the dispatcher and call hwsched_issuecmds
*/
static void adreno_hwsched_issuecmds(struct adreno_device *adreno_dev)
{
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
/* If the dispatcher is busy then schedule the work for later */
if (!mutex_trylock(&hwsched->mutex)) {
adreno_hwsched_trigger(adreno_dev);
return;
}
if (!hwsched_in_fault(hwsched))
hwsched_issuecmds(adreno_dev);
mutex_unlock(&hwsched->mutex);
}
/**
* get_timestamp() - Return the next timestamp for the context
* @drawctxt - Pointer to an adreno draw context struct
* @drawobj - Pointer to a drawobj
* @timestamp - Pointer to a timestamp value possibly passed from the user
* @user_ts - user generated timestamp
*
* Assign a timestamp based on the settings of the draw context and the command
* batch.
*/
static int get_timestamp(struct adreno_context *drawctxt,
struct kgsl_drawobj *drawobj, unsigned int *timestamp,
unsigned int user_ts)
{
if (drawctxt->base.flags & KGSL_CONTEXT_USER_GENERATED_TS) {
/*
* User specified timestamps need to be greater than the last
* issued timestamp in the context
*/
if (timestamp_cmp(drawctxt->timestamp, user_ts) >= 0)
return -ERANGE;
drawctxt->timestamp = user_ts;
} else
drawctxt->timestamp++;
*timestamp = drawctxt->timestamp;
drawobj->timestamp = *timestamp;
return 0;
}
static inline int _check_context_state(struct kgsl_context *context)
{
if (kgsl_context_invalid(context))
return -EDEADLK;
if (kgsl_context_detached(context))
return -ENOENT;
return 0;
}
static inline bool _verify_ib(struct kgsl_device_private *dev_priv,
struct kgsl_context *context, struct kgsl_memobj_node *ib)
{
struct kgsl_device *device = dev_priv->device;
struct kgsl_process_private *private = dev_priv->process_priv;
/* The maximum allowable size for an IB in the CP is 0xFFFFF dwords */
if (ib->size == 0 || ((ib->size >> 2) > 0xFFFFF)) {
pr_context(device, context, "ctxt %d invalid ib size %lld\n",
context->id, ib->size);
return false;
}
/* Make sure that the address is mapped */
if (!kgsl_mmu_gpuaddr_in_range(private->pagetable, ib->gpuaddr)) {
pr_context(device, context, "ctxt %d invalid ib gpuaddr %llX\n",
context->id, ib->gpuaddr);
return false;
}
return true;
}
static inline int _verify_cmdobj(struct kgsl_device_private *dev_priv,
struct kgsl_context *context, struct kgsl_drawobj *drawobj[],
uint32_t count)
{
struct kgsl_device *device = dev_priv->device;
struct kgsl_memobj_node *ib;
unsigned int i;
for (i = 0; i < count; i++) {
/* Verify the IBs before they get queued */
if (drawobj[i]->type == CMDOBJ_TYPE) {
struct kgsl_drawobj_cmd *cmdobj = CMDOBJ(drawobj[i]);
list_for_each_entry(ib, &cmdobj->cmdlist, node)
if (!_verify_ib(dev_priv,
&ADRENO_CONTEXT(context)->base, ib))
return -EINVAL;
/*
* Clear the wake on touch bit to indicate an IB has
* been submitted since the last time we set it.
* But only clear it when we have rendering commands.
*/
device->flags &= ~KGSL_FLAG_WAKE_ON_TOUCH;
}
}
return 0;
}
static inline int _wait_for_room_in_context_queue(
struct adreno_context *drawctxt)
{
int ret = 0;
/* Wait for room in the context queue */
while (drawctxt->queued >= ADRENO_CONTEXT_DRAWQUEUE_SIZE - 2) {
trace_adreno_drawctxt_sleep(drawctxt);
spin_unlock(&drawctxt->lock);
ret = wait_event_interruptible_timeout(drawctxt->wq,
_check_context_queue(drawctxt),
msecs_to_jiffies(_context_queue_wait));
spin_lock(&drawctxt->lock);
trace_adreno_drawctxt_wake(drawctxt);
/*
* Account for the possibility that the context got invalidated
* while we were sleeping
*/
if (ret > 0) {
ret = _check_context_state(&drawctxt->base);
if (ret)
return ret;
} else
return (ret == 0) ? -ETIMEDOUT : (int) ret;
}
return 0;
}
static unsigned int _check_context_state_to_queue_cmds(
struct adreno_context *drawctxt)
{
int ret = _check_context_state(&drawctxt->base);
if (ret)
return ret;
return _wait_for_room_in_context_queue(drawctxt);
}
static void _queue_drawobj(struct adreno_context *drawctxt,
struct kgsl_drawobj *drawobj)
{
/* Put the command into the queue */
drawctxt->drawqueue[drawctxt->drawqueue_tail] = drawobj;
drawctxt->drawqueue_tail = (drawctxt->drawqueue_tail + 1) %
ADRENO_CONTEXT_DRAWQUEUE_SIZE;
drawctxt->queued++;
trace_adreno_cmdbatch_queued(drawobj, drawctxt->queued);
}
static int _queue_cmdobj(struct adreno_device *adreno_dev,
struct adreno_context *drawctxt, struct kgsl_drawobj_cmd *cmdobj,
uint32_t *timestamp, unsigned int user_ts)
{
struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj);
u32 j;
int ret;
ret = get_timestamp(drawctxt, drawobj, timestamp, user_ts);
if (ret)
return ret;
/*
* If this is a real command then we need to force any markers
* queued before it to dispatch to keep time linear - set the
* skip bit so the commands get NOPed.
*/
j = drawctxt->drawqueue_head;
while (j != drawctxt->drawqueue_tail) {
if (drawctxt->drawqueue[j]->type == MARKEROBJ_TYPE) {
struct kgsl_drawobj_cmd *markerobj =
CMDOBJ(drawctxt->drawqueue[j]);
set_bit(CMDOBJ_SKIP, &markerobj->priv);
}
j = DRAWQUEUE_NEXT(j, ADRENO_CONTEXT_DRAWQUEUE_SIZE);
}
drawctxt->queued_timestamp = *timestamp;
_queue_drawobj(drawctxt, drawobj);
return 0;
}
static void _queue_syncobj(struct adreno_context *drawctxt,
struct kgsl_drawobj_sync *syncobj, uint32_t *timestamp)
{
struct kgsl_drawobj *drawobj = DRAWOBJ(syncobj);
*timestamp = 0;
drawobj->timestamp = 0;
_queue_drawobj(drawctxt, drawobj);
}
static int _queue_markerobj(struct adreno_device *adreno_dev,
struct adreno_context *drawctxt, struct kgsl_drawobj_cmd *markerobj,
u32 *timestamp, u32 user_ts)
{
struct kgsl_drawobj *drawobj = DRAWOBJ(markerobj);
int ret;
ret = get_timestamp(drawctxt, drawobj, timestamp, user_ts);
if (ret)
return ret;
/*
* See if we can fastpath this thing - if nothing is queued
* and nothing is inflight retire without bothering the GPU
*/
if (!drawctxt->queued && kgsl_check_timestamp(drawobj->device,
drawobj->context, drawctxt->queued_timestamp)) {
_retire_timestamp(drawobj);
return 1;
}
/*
* Remember the last queued timestamp - the marker will block
* until that timestamp is expired (unless another command
* comes along and forces the marker to execute)
*/
markerobj->marker_timestamp = drawctxt->queued_timestamp;
drawctxt->queued_timestamp = *timestamp;
_queue_drawobj(drawctxt, drawobj);
return 0;
}
int adreno_hwsched_queue_cmds(struct kgsl_device_private *dev_priv,
struct kgsl_context *context, struct kgsl_drawobj *drawobj[],
u32 count, u32 *timestamp)
{
struct kgsl_device *device = dev_priv->device;
struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
struct adreno_context *drawctxt = ADRENO_CONTEXT(context);
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
struct adreno_dispatch_job *job;
int ret;
unsigned int i, user_ts;
if (!count)
return -EINVAL;
for (i = 0; i < count; i++) {
struct kgsl_drawobj_cmd *cmdobj;
struct kgsl_memobj_node *ib;
u32 numibs = 0;
if (drawobj[i]->type != CMDOBJ_TYPE)
continue;
cmdobj = CMDOBJ(drawobj[i]);
list_for_each_entry(ib, &cmdobj->cmdlist, node)
numibs++;
if (numibs > HWSCHED_MAX_NUMIBS)
return -EINVAL;
}
ret = _check_context_state(&drawctxt->base);
if (ret)
return ret;
ret = _verify_cmdobj(dev_priv, context, drawobj, count);
if (ret)
return ret;
/* wait for the suspend gate */
wait_for_completion(&device->halt_gate);
job = kmem_cache_alloc(jobs_cache, GFP_KERNEL);
if (!job)
return -ENOMEM;
job->drawctxt = drawctxt;
spin_lock(&drawctxt->lock);
ret = _check_context_state_to_queue_cmds(drawctxt);
if (ret) {
spin_unlock(&drawctxt->lock);
kmem_cache_free(jobs_cache, job);
return ret;
}
user_ts = *timestamp;
for (i = 0; i < count; i++) {
switch (drawobj[i]->type) {
case MARKEROBJ_TYPE:
ret = _queue_markerobj(adreno_dev, drawctxt,
CMDOBJ(drawobj[i]),
timestamp, user_ts);
if (ret == 1) {
spin_unlock(&drawctxt->lock);
kmem_cache_free(jobs_cache, job);
return 0;
} else if (ret) {
spin_unlock(&drawctxt->lock);
kmem_cache_free(jobs_cache, job);
return ret;
}
break;
case CMDOBJ_TYPE:
ret = _queue_cmdobj(adreno_dev, drawctxt,
CMDOBJ(drawobj[i]),
timestamp, user_ts);
if (ret) {
spin_unlock(&drawctxt->lock);
kmem_cache_free(jobs_cache, job);
return ret;
}
break;
case SYNCOBJ_TYPE:
_queue_syncobj(drawctxt, SYNCOBJ(drawobj[i]),
timestamp);
break;
default:
spin_unlock(&drawctxt->lock);
kmem_cache_free(jobs_cache, job);
return -EINVAL;
}
}
spin_unlock(&drawctxt->lock);
/* Add the context to the dispatcher pending list */
if (_kgsl_context_get(&drawctxt->base)) {
trace_dispatch_queue_context(drawctxt);
llist_add(&job->node, &hwsched->jobs[drawctxt->base.priority]);
adreno_hwsched_issuecmds(adreno_dev);
} else
kmem_cache_free(jobs_cache, job);
return 0;
}
static void retire_cmdobj(struct kgsl_drawobj_cmd *cmdobj)
{
struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj);
struct kgsl_mem_entry *entry;
struct kgsl_drawobj_profiling_buffer *profile_buffer;
if (cmdobj != NULL) {
entry = cmdobj->profiling_buf_entry;
if (entry) {
profile_buffer = kgsl_gpuaddr_to_vaddr(&entry->memdesc,
cmdobj->profiling_buffer_gpuaddr);
if (profile_buffer == NULL)
return;
kgsl_memdesc_unmap(&entry->memdesc);
}
}
kgsl_drawobj_destroy(drawobj);
}
static int retire_cmd_list(struct adreno_device *adreno_dev)
{
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
int count = 0;
struct cmd_list_obj *obj, *tmp;
list_for_each_entry_safe(obj, tmp, &hwsched->cmd_list, node) {
struct kgsl_drawobj_cmd *cmdobj = obj->cmdobj;
struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj);
if (!kgsl_check_timestamp(device, drawobj->context,
drawobj->timestamp))
continue;
retire_cmdobj(cmdobj);
list_del_init(&obj->node);
kmem_cache_free(obj_cache, obj);
hwsched->inflight--;
count++;
}
return count;
}
/* Take down the dispatcher and release any power states */
static void hwsched_power_down(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
mutex_lock(&device->mutex);
if (test_bit(ADRENO_HWSCHED_POWER, &hwsched->flags)) {
adreno_active_count_put(adreno_dev);
clear_bit(ADRENO_HWSCHED_POWER, &hwsched->flags);
}
mutex_unlock(&device->mutex);
}
void adreno_hwsched_queue_context(struct kgsl_device *device,
struct adreno_context *drawctxt)
{
struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
hwsched_queue_context(adreno_dev, drawctxt);
adreno_hwsched_trigger(adreno_dev);
}
void adreno_hwsched_start(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
complete_all(&device->halt_gate);
adreno_hwsched_trigger(adreno_dev);
}
static int _skipsaverestore_store(struct adreno_device *adreno_dev, bool val)
{
return adreno_power_cycle_bool(adreno_dev,
&adreno_dev->preempt.skipsaverestore, val);
}
static bool _skipsaverestore_show(struct adreno_device *adreno_dev)
{
return adreno_dev->preempt.skipsaverestore;
}
static int _usesgmem_store(struct adreno_device *adreno_dev, bool val)
{
return adreno_power_cycle_bool(adreno_dev,
&adreno_dev->preempt.usesgmem, val);
}
static bool _usesgmem_show(struct adreno_device *adreno_dev)
{
return adreno_dev->preempt.usesgmem;
}
static int _preempt_level_store(struct adreno_device *adreno_dev,
unsigned int val)
{
return adreno_power_cycle_u32(adreno_dev,
&adreno_dev->preempt.preempt_level,
min_t(unsigned int, val, 2));
}
static unsigned int _preempt_level_show(struct adreno_device *adreno_dev)
{
return adreno_dev->preempt.preempt_level;
}
static void change_preemption(struct adreno_device *adreno_dev, void *priv)
{
change_bit(ADRENO_DEVICE_PREEMPTION, &adreno_dev->priv);
}
static int _preemption_store(struct adreno_device *adreno_dev, bool val)
{
if (!(ADRENO_FEATURE(adreno_dev, ADRENO_PREEMPTION)) ||
(test_bit(ADRENO_DEVICE_PREEMPTION,
&adreno_dev->priv) == val))
return 0;
return adreno_power_cycle(adreno_dev, change_preemption, NULL);
}
static bool _preemption_show(struct adreno_device *adreno_dev)
{
return adreno_is_preemption_enabled(adreno_dev);
}
static unsigned int _preempt_count_show(struct adreno_device *adreno_dev)
{
int count = a6xx_hwsched_preempt_count_get(adreno_dev);
return count < 0 ? 0 : count;
}
static ADRENO_SYSFS_BOOL(preemption);
static ADRENO_SYSFS_U32(preempt_level);
static ADRENO_SYSFS_BOOL(usesgmem);
static ADRENO_SYSFS_BOOL(skipsaverestore);
static ADRENO_SYSFS_RO_U32(preempt_count);
static const struct attribute *_preempt_attr_list[] = {
&adreno_attr_preemption.attr.attr,
&adreno_attr_preempt_level.attr.attr,
&adreno_attr_usesgmem.attr.attr,
&adreno_attr_skipsaverestore.attr.attr,
&adreno_attr_preempt_count.attr.attr,
NULL,
};
void adreno_hwsched_dispatcher_close(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
kmem_cache_destroy(jobs_cache);
kmem_cache_destroy(obj_cache);
sysfs_remove_files(&device->dev->kobj, _preempt_attr_list);
}
static void adreno_hwsched_init_replay(struct adreno_hwsched *hwsched)
{
struct cmd_list_obj *obj, *tmp;
list_for_each_entry_safe(obj, tmp, &hwsched->cmd_list, node) {
struct kgsl_drawobj_cmd *cmdobj = obj->cmdobj;
clear_bit(KGSL_FT_REPLAY, &cmdobj->fault_policy);
}
}
static void force_retire_timestamp(struct kgsl_device *device,
struct kgsl_drawobj *drawobj)
{
kgsl_sharedmem_writel(device->memstore,
KGSL_MEMSTORE_OFFSET(drawobj->context->id, soptimestamp),
drawobj->timestamp);
kgsl_sharedmem_writel(device->memstore,
KGSL_MEMSTORE_OFFSET(drawobj->context->id, eoptimestamp),
drawobj->timestamp);
}
static void adreno_hwsched_complete_replay(struct adreno_device *adreno_dev)
{
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct cmd_list_obj *obj, *tmp;
u32 retired = 0;
list_for_each_entry_safe(obj, tmp, &hwsched->cmd_list, node) {
struct kgsl_drawobj_cmd *cmdobj = obj->cmdobj;
struct kgsl_drawobj *drawobj = DRAWOBJ(cmdobj);
struct kgsl_context *context = drawobj->context;
/*
* Get rid of retired objects or objects that belong to detached
* or invalidated contexts
*/
if ((kgsl_check_timestamp(device, context, drawobj->timestamp))
|| kgsl_context_invalid(context)
|| kgsl_context_detached(context)) {
retire_cmdobj(cmdobj);
retired++;
list_del_init(&obj->node);
kmem_cache_free(obj_cache, obj);
continue;
}
if (!test_and_set_bit(KGSL_FT_REPLAY, &cmdobj->fault_policy))
a6xx_hwsched_submit_cmdobj(adreno_dev, cmdobj);
}
/* Signal fences */
if (retired)
kgsl_process_event_groups(device);
hwsched->inflight = 0;
/*
* We have nothing to replay. So clear the fault so that
* dispatcher starts accepting new submissions.
*/
if (list_empty(&hwsched->cmd_list)) {
atomic_set(&hwsched->fault, 0);
adreno_clear_gpu_halt(adreno_dev);
adreno_hwsched_trigger(adreno_dev);
}
}
static void do_fault_header(struct adreno_device *adreno_dev,
struct kgsl_drawobj *drawobj)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct adreno_context *drawctxt = ADRENO_CONTEXT(drawobj->context);
u32 status, rptr, wptr, ib1sz, ib2sz;
u64 ib1base, ib2base;
adreno_readreg(adreno_dev, ADRENO_REG_RBBM_STATUS, &status);
adreno_readreg(adreno_dev, ADRENO_REG_CP_RB_RPTR, &rptr);
adreno_readreg(adreno_dev, ADRENO_REG_CP_RB_WPTR, &wptr);
adreno_readreg64(adreno_dev, ADRENO_REG_CP_IB1_BASE,
ADRENO_REG_CP_IB1_BASE_HI, &ib1base);
adreno_readreg(adreno_dev, ADRENO_REG_CP_IB1_BUFSZ, &ib1sz);
adreno_readreg64(adreno_dev, ADRENO_REG_CP_IB2_BASE,
ADRENO_REG_CP_IB2_BASE_HI, &ib2base);
adreno_readreg(adreno_dev, ADRENO_REG_CP_IB2_BUFSZ, &ib2sz);
drawobj->context->last_faulted_cmd_ts = drawobj->timestamp;
drawobj->context->total_fault_count++;
pr_context(device, drawobj->context,
"ctx %d ctx_type %s ts %d status %8.8X dispatch_queue=%d rb %4.4x/%4.4x ib1 %16.16llX/%4.4x ib2 %16.16llX/%4.4x\n",
drawobj->context->id, kgsl_context_type(drawctxt->type),
drawobj->timestamp, status,
drawobj->context->gmu_dispatch_queue, rptr, wptr,
ib1base, ib1sz, ib2base, ib2sz);
trace_adreno_gpu_fault(drawobj->context->id, drawobj->timestamp, status,
rptr, wptr, ib1base, ib1sz, ib2base, ib2sz,
adreno_get_level(drawobj->context->priority));
}
static struct cmd_list_obj *get_fault_cmdobj(struct adreno_device *adreno_dev)
{
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
struct cmd_list_obj *obj, *tmp;
list_for_each_entry_safe(obj, tmp, &hwsched->cmd_list, node) {
if (test_bit(CMDOBJ_FAULT, &obj->cmdobj->priv))
return obj;
}
return NULL;
}
static void reset_and_snapshot(struct adreno_device *adreno_dev)
{
struct kgsl_drawobj *drawobj = NULL;
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct kgsl_context *context = NULL;
struct cmd_list_obj *obj = get_fault_cmdobj(adreno_dev);
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
if (device->state != KGSL_STATE_ACTIVE)
return;
if (!obj) {
kgsl_device_snapshot(device, NULL, false);
goto done;
}
drawobj = DRAWOBJ(obj->cmdobj);
context = drawobj->context;
do_fault_header(adreno_dev, drawobj);
kgsl_device_snapshot(device, context, false);
force_retire_timestamp(device, drawobj);
if (context->flags & KGSL_CONTEXT_INVALIDATE_ON_FAULT) {
adreno_mark_guilty_context(device, context->id);
adreno_drawctxt_invalidate(device, context);
}
/* This must always happen after taking snapshot */
clear_bit(CMDOBJ_FAULT, &obj->cmdobj->priv);
/*
* Put back the reference which we incremented when marking the faulty
* cmdobj
*/
kgsl_drawobj_put(drawobj);
done:
a6xx_hwsched_restart(adreno_dev);
adreno_hwsched_init_replay(hwsched);
}
static void adreno_hwsched_recovery(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
mutex_lock(&device->mutex);
if ((atomic_cmpxchg(&hwsched->fault, ADRENO_HWSCHED_FAULT_RESTART,
ADRENO_HWSCHED_FAULT_REPLAY) == ADRENO_HWSCHED_FAULT_RESTART))
reset_and_snapshot(adreno_dev);
adreno_hwsched_complete_replay(adreno_dev);
mutex_unlock(&device->mutex);
}
static void adreno_hwsched_work(struct kthread_work *work)
{
struct adreno_hwsched *hwsched = container_of(work,
struct adreno_hwsched, work);
struct adreno_device *adreno_dev = hwsched_to_adreno(hwsched);
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
int count = 0;
mutex_lock(&hwsched->mutex);
if (hwsched_in_fault(hwsched)) {
adreno_hwsched_recovery(adreno_dev);
mutex_unlock(&hwsched->mutex);
return;
}
/*
* As long as there are inflight commands, process retired comamnds from
* all drawqueues
*/
count += retire_cmd_list(adreno_dev);
/* Signal fences */
kgsl_process_event_groups(device);
/* Run the scheduler for to dispatch new commands */
hwsched_issuecmds(adreno_dev);
if (hwsched->inflight == 0) {
hwsched_power_down(adreno_dev);
} else {
mutex_lock(&device->mutex);
kgsl_pwrscale_update(device);
mod_timer(&device->idle_timer,
jiffies + device->pwrctrl.interval_timeout);
mutex_unlock(&device->mutex);
}
mutex_unlock(&hwsched->mutex);
}
void adreno_hwsched_init(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
int i;
memset(hwsched, 0, sizeof(*hwsched));
mutex_init(&hwsched->mutex);
kthread_init_work(&hwsched->work, adreno_hwsched_work);
jobs_cache = KMEM_CACHE(adreno_dispatch_job, 0);
obj_cache = KMEM_CACHE(cmd_list_obj, 0);
INIT_LIST_HEAD(&hwsched->cmd_list);
for (i = 0; i < ARRAY_SIZE(hwsched->jobs); i++) {
init_llist_head(&hwsched->jobs[i]);
init_llist_head(&hwsched->requeue[i]);
}
sysfs_create_files(&device->dev->kobj, _preempt_attr_list);
}
void adreno_hwsched_mark_drawobj(struct adreno_device *adreno_dev,
u32 ctxt_id, u32 ts)
{
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
struct cmd_list_obj *obj, *tmp;
struct kgsl_drawobj *drawobj = NULL;
mutex_lock(&hwsched->mutex);
list_for_each_entry_safe(obj, tmp, &hwsched->cmd_list, node) {
drawobj = DRAWOBJ(obj->cmdobj);
if (ctxt_id == drawobj->context->id &&
ts == drawobj->timestamp) {
if (kref_get_unless_zero(&drawobj->refcount))
set_bit(CMDOBJ_FAULT, &obj->cmdobj->priv);
break;
}
}
adreno_hwsched_set_fault(adreno_dev);
mutex_unlock(&hwsched->mutex);
}
void adreno_hwsched_parse_fault_cmdobj(struct adreno_device *adreno_dev,
struct kgsl_snapshot *snapshot)
{
struct adreno_hwsched *hwsched = to_hwsched(adreno_dev);
struct cmd_list_obj *obj, *tmp;
list_for_each_entry_safe(obj, tmp, &hwsched->cmd_list, node) {
struct kgsl_drawobj_cmd *cmdobj = obj->cmdobj;
if (test_bit(CMDOBJ_FAULT, &cmdobj->priv)) {
struct kgsl_memobj_node *ib;
list_for_each_entry(ib, &cmdobj->cmdlist, node) {
adreno_parse_ib(KGSL_DEVICE(adreno_dev),
snapshot, snapshot->process,
ib->gpuaddr, ib->size >> 2);
}
}
}
}
|