-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathadreno_gen8_hwsched.c
More file actions
2230 lines (1749 loc) · 62.7 KB
/
Copy pathadreno_gen8_hwsched.c
File metadata and controls
2230 lines (1749 loc) · 62.7 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) 2021, The Linux Foundation. All rights reserved.
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
*/
#include <linux/interconnect.h>
#include "adreno.h"
#include "adreno_gen8.h"
#include "adreno_gen8_hwsched.h"
#include "adreno_snapshot.h"
#include "kgsl_bus.h"
#include "kgsl_device.h"
#include "kgsl_gmu_core.h"
#include "kgsl_trace.h"
#include "kgsl_util.h"
static void _wakeup_hw_fence_waiters(struct adreno_device *adreno_dev, u32 fault)
{
struct gen8_hwsched_hfi *hfi = to_gen8_hwsched_hfi(adreno_dev);
struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence;
bool lock = !in_interrupt();
if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags))
return;
/*
* We could be in interrupt context here, which means we need to use spin_lock_irqsave
* (which disables interrupts) everywhere we take this lock. Instead of that, simply
* avoid taking this lock if we are recording a fault from an interrupt handler.
*/
if (lock)
spin_lock(&hwf->lock);
clear_bit(GEN8_HWSCHED_HW_FENCE_SLEEP_BIT, &hwf->flags);
/* Avoid creating new hardware fences until recovery is complete */
set_bit(GEN8_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags);
if (!lock) {
/*
* This barrier ensures that the above bitops complete before we wake up the waiters
*/
smp_wmb();
} else {
spin_unlock(&hwf->lock);
}
wake_up_all(&hwf->unack_wq);
kgsl_delete_timer(&hfi->hw_fence_timer);
}
void gen8_hwsched_fault(struct adreno_device *adreno_dev, u32 fault)
{
/*
* Wake up any threads that may be sleeping waiting for the hardware fence unack count to
* drop to a desired threshold.
*/
_wakeup_hw_fence_waiters(adreno_dev, fault);
adreno_scheduler_fault(adreno_dev, fault);
}
void gen8_hwsched_snapshot(struct adreno_device *adreno_dev,
struct kgsl_snapshot *snapshot)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct adreno_hwsched *hwsched = &adreno_dev->hwsched;
bool skip_memkind_rb = false;
u32 i;
bool parse_payload;
gen8_gmu_snapshot(adreno_dev, snapshot);
adreno_hwsched_parse_fault_cmdobj(adreno_dev, snapshot);
/*
* First try to dump ringbuffers using context bad HFI payloads
* because they have all the ringbuffer parameters. If ringbuffer
* payloads are not present, fall back to dumping ringbuffers
* based on MEMKIND_RB
*/
parse_payload = adreno_hwsched_parse_payload_rb(adreno_dev, snapshot);
if (parse_payload)
skip_memkind_rb = true;
for (i = 0; i < hwsched->mem_alloc_entries; i++) {
struct hfi_mem_alloc_entry *entry = &hwsched->mem_alloc_table[i];
if (entry->desc.mem_kind == HFI_MEMKIND_RB && !skip_memkind_rb)
kgsl_snapshot_add_section(device,
KGSL_SNAPSHOT_SECTION_RB_V2,
snapshot, adreno_hwsched_snapshot_rb,
entry->md);
if (entry->desc.mem_kind == HFI_MEMKIND_SCRATCH)
kgsl_snapshot_add_section(device,
KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2,
snapshot, adreno_snapshot_global,
entry->md);
if (entry->desc.mem_kind == HFI_MEMKIND_PROFILE)
kgsl_snapshot_add_section(device,
KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2,
snapshot, adreno_snapshot_global,
entry->md);
if (entry->desc.mem_kind == HFI_MEMKIND_CSW_SMMU_INFO)
kgsl_snapshot_add_section(device,
KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2,
snapshot, adreno_snapshot_global,
entry->md);
if (entry->desc.mem_kind == HFI_MEMKIND_CSW_PRIV_NON_SECURE)
adreno_hwsched_snapshot_preemption_records(device, snapshot,
entry->md);
if (entry->desc.mem_kind == HFI_MEMKIND_PREEMPT_SCRATCH)
kgsl_snapshot_add_section(device,
KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2,
snapshot, adreno_snapshot_global,
entry->md);
if (entry->desc.mem_kind == HFI_MEMKIND_AQE_BUFFER)
kgsl_snapshot_add_section(device,
KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2,
snapshot, adreno_hwsched_snapshot_aqe_buffer,
entry->md);
if (entry->desc.mem_kind == HFI_MEMKIND_HW_FENCE) {
struct gmu_mem_type_desc desc;
desc.memdesc = entry->md;
desc.type = SNAPSHOT_GMU_MEM_HW_FENCE;
kgsl_snapshot_add_section(device,
KGSL_SNAPSHOT_SECTION_GMU_MEMORY,
snapshot, adreno_snapshot_gmu_mem, &desc);
}
}
adreno_hwsched_snapshot_context_queue(device, snapshot);
}
static void _get_hw_fence_entries(struct adreno_device *adreno_dev)
{
struct device_node *node = NULL;
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
u32 shadow_num_entries = 0;
if (!ADRENO_FEATURE(adreno_dev, ADRENO_HW_FENCE))
return;
node = of_find_node_by_name(NULL, "qcom,hw-fence");
if (!node)
return;
if (of_property_read_u32(node, "qcom,hw-fence-table-entries",
&shadow_num_entries)) {
dev_err(GMU_PDEV_DEV(KGSL_DEVICE(adreno_dev)),
"qcom,hw-fence-table-entries property not found\n");
shadow_num_entries = 8192;
}
of_node_put(node);
/*
* The return value is ignored as it does not need to be returned to the caller.
* Any errors are logged within the VRB set API if a failure occurs.
*/
gmu_core_set_vrb_register(device->gmu_core.vrb,
VRB_HW_FENCE_SHADOW_NUM_ENTRIES, shadow_num_entries);
}
void gen8_hwsched_soccp_vote(struct adreno_device *adreno_dev, bool pwr_on)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct device *gmu_pdev_dev = GMU_PDEV_DEV(device);
struct adreno_hwsched_hw_fence *hwf = &adreno_dev->hwsched.hw_fence;
if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &adreno_dev->hwsched.flags))
return;
if (!gmu_core_soccp_vote(device, pwr_on))
return;
/* Make sure no more hardware fences are created */
spin_lock(&hwf->lock);
set_bit(GEN8_HWSCHED_HW_FENCE_ABORT_BIT, &hwf->flags);
spin_unlock(&hwf->lock);
/*
* It is possible that some hardware fences were created while we were in slumber. Since
* soccp power vote failed, these hardware fences may never be signaled. Hence, log them
* for debug purposes.
*/
adreno_hwsched_log_remove_pending_hw_fences(adreno_dev, gmu_pdev_dev);
gmu_core_mark_for_coldboot(KGSL_DEVICE(adreno_dev));
adreno_hwsched_deregister_hw_fence(adreno_dev);
}
static void gen8_hwsched_gmu_suspend(struct adreno_device *adreno_dev, bool force)
{
gen8_gmu_suspend(adreno_dev, force);
adreno_hwsched_reset_hfi_mem(adreno_dev);
}
static void gen8_hwsched_set_ctxt_record_vrb(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
if (IS_ERR_OR_NULL(device->gmu_core.vrb))
return;
/* Populate context record sizes in VRB */
gmu_core_set_vrb_register(device->gmu_core.vrb, VRB_CTXRECORD_TOTAL_SZ,
adreno_dev->total_ctxt_record_sz >> 10);
gmu_core_set_vrb_register(device->gmu_core.vrb, VRB_CTXRECORD_GMEM_SZ,
adreno_gmem_size(adreno_dev) >> 10);
/* Populate size of AQE context record */
gmu_core_set_vrb_register(device->gmu_core.vrb, VRB_CTXRECORD_AQE_SZ,
adreno_dev->aqe_ctxt_record_sz >> 10);
}
static int gen8_hwsched_gmu_first_boot(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct kgsl_pwrctrl *pwr = &device->pwrctrl;
struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev);
struct adreno_hwsched *hwsched = &adreno_dev->hwsched;
int level, ret = 0;
kgsl_pwrctrl_request_state(device, KGSL_STATE_AWARE);
gen8_gmu_aop_send_acd_state(gmu, adreno_dev->acd_enabled);
ret = kgsl_pwrctrl_enable_cx_gdsc(device);
if (ret)
return ret;
/* Start the GMU at the lowest available frequency level */
ret = gmu_core_enable_clks(device, 0);
if (ret)
goto gdsc_off;
ret = gen8_scm_gpu_init_cx_regs(adreno_dev);
if (ret)
goto clks_gdsc_off;
gen8_get_gpu_slice_info(adreno_dev);
/*
* Set context record size after determining slice mask,
* as GMEM size depends on it.
*/
gen8_populate_ctxt_record_size(adreno_dev);
gen8_hwsched_set_ctxt_record_vrb(adreno_dev);
/*
* Enable AHB timeout detection to catch any register access taking longer
* time before NOC timeout gets detected. Enable this logic before any
* register access which happens to be just after enabling clocks.
*/
gen8_enable_ahb_timeout_detection(adreno_dev);
/* Initialize the CX timer */
gen8_cx_timer_init(adreno_dev);
ret = gen8_gmu_load_fw(adreno_dev);
if (ret)
goto clks_gdsc_off;
ret = gen8_gmu_itcm_shadow(adreno_dev);
if (ret)
goto clks_gdsc_off;
_get_hw_fence_entries(adreno_dev);
gen8_gmu_register_config(adreno_dev);
ret = gen8_gmu_version_info(adreno_dev);
if (ret)
goto clks_gdsc_off;
gen8_gmu_irq_enable(adreno_dev);
/* Vote for minimal DDR BW for GMU to init */
level = pwr->pwrlevels[pwr->default_pwrlevel].bus_min;
icc_set_bw(pwr->icc_path, 0, kBps_to_icc(pwr->ddr_table[level]));
/* This is the minimum GMU FW HFI version required to enable hw fences */
if (GMU_VER_MINOR(device->gmu_core.ver.hfi) >= 7)
adreno_hwsched_register_hw_fence(adreno_dev);
/* From this GMU FW all RBBM interrupts are handled at GMU */
if (device->gmu_core.ver.core >= GMU_VERSION(5, 01, 06))
adreno_irq_free(adreno_dev);
gen8_hwsched_soccp_vote(adreno_dev, true);
/* Clear any hwsched faults that might have been left over */
adreno_clear_gpu_fault(adreno_dev);
ret = gen8_gmu_device_start(adreno_dev);
if (ret)
goto err;
gen8_get_gpu_feature_info(adreno_dev);
ret = gen8_hwsched_hfi_start(adreno_dev);
if (ret)
goto err;
if (adreno_dev->gmu_ab &&
gen8_hwsched_hfi_get_value(adreno_dev, HFI_VALUE_GMU_AB_VOTE, 0) == 1 &&
!WARN_ONCE(!adreno_dev->gpucore->num_ddr_channels,
"Number of DDR channel is not specified in gpu core")) {
set_bit(ADRENO_DEVICE_GMU_AB, &adreno_dev->priv);
} else {
/* If gmu_ab feature flag is enabled but GMU doesn't support it, set it to false */
adreno_dev->gmu_ab = false;
}
icc_set_bw(pwr->icc_path, 0, 0);
device->gmu_fault = false;
memset(hwsched->default_dcvs_tunables, 0xFF, sizeof(hwsched->default_dcvs_tunables));
if (!device->host_based_dcvs)
gen8_hwsched_hfi_get_dcvs_tuning_attrs(adreno_dev, HFI_DCVS_ATTRS_DEFAULT,
hwsched->default_dcvs_tunables);
kgsl_pwrctrl_set_state(device, KGSL_STATE_AWARE);
return 0;
err:
gen8_gmu_irq_disable(adreno_dev);
gen8_hwsched_soccp_vote(adreno_dev, false);
if (device->gmu_fault) {
gen8_hwsched_gmu_suspend(adreno_dev, false);
return ret;
}
adreno_hwsched_reset_hfi_mem(adreno_dev);
clks_gdsc_off:
gmu_core_disable_clks(device);
gdsc_off:
kgsl_pwrctrl_disable_cx_gdsc(device);
gmu_core_rdpm_cx_freq_update(device, 0);
return ret;
}
static void gen8_scm_gpu_tsense_boot(struct adreno_device *adreno_dev)
{
struct gen8_device *gen8_dev = container_of(adreno_dev,
struct gen8_device, adreno_dev);
/* Cancel any pending TSENSE work that didn't run */
cancel_work_sync(&gen8_dev->tsense_work);
/* Set default tsense measurement window */
gen8_scm_gpu_tsense_default(adreno_dev, true);
}
static int gen8_hwsched_gmu_boot(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
int ret = 0;
kgsl_pwrctrl_request_state(device, KGSL_STATE_AWARE);
ret = kgsl_pwrctrl_enable_cx_gdsc(device);
if (ret)
return ret;
/* Start the GMU at the lowest available frequency level */
ret = gmu_core_enable_clks(device, 0);
if (ret)
goto gdsc_off;
gen8_scm_gpu_tsense_boot(adreno_dev);
/*
* Enable AHB timeout detection to catch any register access taking longer
* time before NOC timeout gets detected. Enable this logic before any
* register access which happens to be just after enabling clocks.
*/
gen8_enable_ahb_timeout_detection(adreno_dev);
/* Initialize the CX timer */
gen8_cx_timer_init(adreno_dev);
ret = gen8_rscc_wakeup_sequence(adreno_dev);
if (ret)
goto clks_gdsc_off;
ret = gen8_gmu_load_fw(adreno_dev);
if (ret)
goto clks_gdsc_off;
gen8_gmu_register_config(adreno_dev);
gen8_gmu_irq_enable(adreno_dev);
gen8_hwsched_soccp_vote(adreno_dev, true);
/* Clear any hwsched faults that might have been left over */
adreno_clear_gpu_fault(adreno_dev);
ret = gen8_gmu_device_start(adreno_dev);
if (ret)
goto err;
ret = gen8_hwsched_hfi_start(adreno_dev);
if (ret)
goto err;
device->gmu_fault = false;
kgsl_pwrctrl_set_state(device, KGSL_STATE_AWARE);
return 0;
err:
gen8_gmu_irq_disable(adreno_dev);
gen8_hwsched_soccp_vote(adreno_dev, false);
if (device->gmu_fault) {
gen8_hwsched_gmu_suspend(adreno_dev, false);
return ret;
}
adreno_hwsched_reset_hfi_mem(adreno_dev);
clks_gdsc_off:
gmu_core_disable_clks(device);
gdsc_off:
kgsl_pwrctrl_disable_cx_gdsc(device);
gmu_core_rdpm_cx_freq_update(device, 0);
return ret;
}
/* TSENSE suspend work can be done in parallel with GPU suspend */
static void gen8_scm_gpu_tsense_suspend_work(struct work_struct *work)
{
struct gen8_device *gen8_dev = container_of(work, struct gen8_device, tsense_work);
/* Set non-default tsense measurement window */
gen8_scm_gpu_tsense_default(&gen8_dev->adreno_dev, false);
}
static void gen8_scm_gpu_tsense_suspend(struct adreno_device *adreno_dev)
{
struct gen8_device *gen8_dev = container_of(adreno_dev,
struct gen8_device, adreno_dev);
if (!ADRENO_FEATURE(adreno_dev, ADRENO_TSENSE_DYNAMIC_PERIOD))
return;
/*
* Schedule on the lockless workqueue instead of the kgsl workqueue
* to avoid deadlocks with the device mutex
*/
queue_work(kgsl_driver.lockless_workqueue, &gen8_dev->tsense_work);
}
static int gen8_hwsched_notify_slumber(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct kgsl_pwrctrl *pwr = &device->pwrctrl;
struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev);
struct hfi_prep_slumber_cmd req;
int ret;
ret = CMD_MSG_HDR(req, H2F_MSG_PREPARE_SLUMBER);
if (ret)
return ret;
req.freq = gmu->dcvs_table.gpu_level_num - pwr->default_pwrlevel - 1;
req.bw = pwr->pwrlevels[pwr->default_pwrlevel].bus_freq;
req.bw |= adreno_gmu_bus_ab_quantize(adreno_dev, 0);
/* Disable the power counter so that the GMU is not busy */
gmu_core_regwrite(device, GEN8_GMUCX_POWER_COUNTER_ENABLE, 0);
gen8_scm_gpu_tsense_suspend(adreno_dev);
ret = gen8_hfi_send_cmd_async(adreno_dev, &req, sizeof(req));
/*
* GEMNOC can enter power collapse state during GPU power down sequence.
* This could abort CX GDSC collapse. Assert Qactive to avoid this.
*/
gmu_core_regwrite(device, GEN8_GMUCX_CX_FALNEXT_INTF, 0x1);
return ret;
}
static int gen8_hwsched_gmu_power_off(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
int ret = 0;
if (device->gmu_fault)
goto error;
/* Wait for the lowest idle level we requested */
ret = gen8_gmu_wait_for_lowest_idle(adreno_dev);
if (ret)
goto error;
ret = gen8_hwsched_notify_slumber(adreno_dev);
if (ret)
goto error;
ret = gen8_gmu_wait_for_idle(adreno_dev);
if (ret)
goto error;
ret = gen8_rscc_sleep_sequence(adreno_dev);
gmu_core_rdpm_mx_freq_update(device, 0);
/* Now that we are done with GMU and GPU, Clear the GBIF */
ret = gen8_halt_gbif(adreno_dev);
gen8_gmu_irq_disable(adreno_dev);
gen8_hwsched_hfi_stop(adreno_dev);
gmu_core_disable_clks(device);
kgsl_pwrctrl_disable_cx_gdsc(device);
gmu_core_rdpm_cx_freq_update(device, 0);
kgsl_pwrctrl_set_state(device, KGSL_STATE_NONE);
adreno_hwsched_reset_hfi_mem(adreno_dev);
return ret;
error:
gen8_gmu_irq_disable(adreno_dev);
gen8_hwsched_hfi_stop(adreno_dev);
gen8_hwsched_gmu_suspend(adreno_dev, false);
return ret;
}
void gen8_hwsched_init_ucode_regs(struct adreno_device *adreno_dev)
{
struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_SQE);
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
/* Program the ucode base for CP */
kgsl_regwrite(device, GEN8_CP_SQE_INSTR_BASE_LO,
lower_32_bits(fw->memdesc->gpuaddr));
kgsl_regwrite(device, GEN8_CP_SQE_INSTR_BASE_HI,
upper_32_bits(fw->memdesc->gpuaddr));
if (ADRENO_FEATURE(adreno_dev, ADRENO_AQE)) {
fw = ADRENO_FW(adreno_dev, ADRENO_FW_AQE);
/* Program the ucode base for AQE0 (BV coprocessor) */
kgsl_regwrite(device, GEN8_CP_AQE_INSTR_BASE_LO_0,
lower_32_bits(fw->memdesc->gpuaddr));
kgsl_regwrite(device, GEN8_CP_AQE_INSTR_BASE_HI_0,
upper_32_bits(fw->memdesc->gpuaddr));
/* Program the ucode base for AQE1 (LPAC coprocessor) */
if (adreno_dev->lpac_enabled) {
kgsl_regwrite(device, GEN8_CP_AQE_INSTR_BASE_LO_1,
lower_32_bits(fw->memdesc->gpuaddr));
kgsl_regwrite(device, GEN8_CP_AQE_INSTR_BASE_HI_1,
upper_32_bits(fw->memdesc->gpuaddr));
}
}
}
static int gen8_hwsched_gpu_boot(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
int ret;
ret = kgsl_mmu_start(device);
if (ret)
goto err;
ret = gen8_gmu_oob_set(device, oob_gpu);
if (ret)
goto err;
/* Clear the busy_data stats - we're starting over from scratch */
memset(&adreno_dev->busy_data, 0, sizeof(adreno_dev->busy_data));
gen8_start(adreno_dev);
/* Re-initialize the coresight registers if applicable */
adreno_coresight_start(adreno_dev);
adreno_perfcounter_start(adreno_dev);
/* Clear FSR here in case it is set from a previous pagefault */
kgsl_mmu_clear_fsr(&device->mmu);
gen8_enable_gpu_irq(adreno_dev);
gen8_hwsched_init_ucode_regs(adreno_dev);
ret = gen8_hwsched_boot_gpu(adreno_dev);
if (ret) {
adreno_llcc_slice_deactivate(adreno_dev);
goto err;
}
if (adreno_is_gen8_2_x(adreno_dev))
gen8_hwcg_set(adreno_dev, true);
/*
* At this point it is safe to assume that we recovered. Setting
* this field allows us to take a new snapshot for the next failure
* if we are prioritizing the first unrecoverable snapshot.
*/
if (device->snapshot)
device->snapshot->recovered = true;
device->reset_counter++;
/*
* If warmboot is enabled and we switched a sysfs node, we will do a coldboot
* in the subseqent slumber exit. Once that is done we need to mark this bool
* as false so that in the next run we can do warmboot
*/
clear_bit(GMU_FORCE_COLDBOOT, &device->gmu_core.flags);
err:
gen8_gmu_oob_clear(device, oob_gpu);
if (ret)
gen8_hwsched_gmu_power_off(adreno_dev);
return ret;
}
static void hwsched_idle_timer(struct timer_list *t)
{
struct kgsl_device *device = container_of(t, struct kgsl_device,
idle_timer);
kgsl_schedule_work(&device->idle_check_ws);
}
static int gen8_gmu_warmboot_init(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev);
int ret = 0;
if (!ADRENO_FEATURE(adreno_dev, ADRENO_GMU_WARMBOOT))
return ret;
if (IS_ERR_OR_NULL(gmu->gmu_init_scratch)) {
gmu->gmu_init_scratch = gmu_core_reserve_kernel_block(device, 0,
SZ_4K, GMU_CACHE, 0);
ret = PTR_ERR_OR_ZERO(gmu->gmu_init_scratch);
if (ret)
return ret;
}
if (IS_ERR_OR_NULL(gmu->gpu_boot_scratch)) {
gmu->gpu_boot_scratch = gmu_core_reserve_kernel_block(device, 0,
SZ_4K, GMU_CACHE, 0);
ret = PTR_ERR_OR_ZERO(gmu->gpu_boot_scratch);
}
return ret;
}
static int gen8_hwsched_gmu_memory_init(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct gmu_core_device *gmu_core = &device->gmu_core;
int ret;
const struct adreno_gen8_core *gen8_core = to_gen8_core(adreno_dev);
ret = gmu_core_hwsched_memory_init(device);
if (ret)
return ret;
/* Set the CL infinite timeout VRB override (if declared in gpulist) */
if (gen8_core->cl_no_ft_timeout_ms)
gmu_core_set_vrb_register(gmu_core->vrb, VRB_CL_NO_FT_TIMEOUT,
gen8_core->cl_no_ft_timeout_ms);
return 0;
}
static int gen8_hwsched_gmu_init(struct adreno_device *adreno_dev)
{
int ret;
if (ADRENO_FEATURE(adreno_dev, ADRENO_GMU_THERMAL_MITIGATION))
set_bit(GMU_THERMAL_MITIGATION, &KGSL_DEVICE(adreno_dev)->gmu_core.flags);
ret = gen8_gmu_parse_fw(adreno_dev);
if (ret)
return ret;
ret = gen8_gmu_memory_init(adreno_dev);
if (ret)
return ret;
ret = gen8_gmu_warmboot_init(adreno_dev);
if (ret)
return ret;
ret = gen8_hwsched_gmu_memory_init(adreno_dev);
if (ret)
return ret;
return gen8_hwsched_hfi_init(adreno_dev);
}
static void gen8_hwsched_touch_wakeup(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev);
int ret;
/*
* Do not wake up a suspended device or until the first boot sequence
* has been completed.
*/
if (test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags) ||
!test_bit(GMU_PRIV_FIRST_BOOT_DONE, &gmu->flags))
return;
if (test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags))
goto done;
kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE);
ret = gen8_hwsched_gmu_boot(adreno_dev);
if (ret)
return;
ret = gen8_hwsched_gpu_boot(adreno_dev);
if (ret)
return;
kgsl_pwrscale_wake(device);
set_bit(GMU_PRIV_GPU_STARTED, &gmu->flags);
device->pwrctrl.last_stat_updated = ktime_get();
kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE);
done:
/*
* When waking up from a touch event we want to stay active long enough
* for the user to send a draw command. The default idle timer timeout
* is shorter than we want so go ahead and push the idle timer out
* further for this special case
*/
mod_timer(&device->idle_timer, jiffies +
msecs_to_jiffies(adreno_wake_timeout));
}
static int gen8_hwsched_boot(struct adreno_device *adreno_dev)
{
struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev);
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
int ret;
if (test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags))
return 0;
kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE);
adreno_hwsched_start(adreno_dev);
ret = gen8_hwsched_gmu_boot(adreno_dev);
if (ret)
return ret;
ret = gen8_hwsched_gpu_boot(adreno_dev);
if (ret)
return ret;
kgsl_start_idle_timer(device);
kgsl_pwrscale_wake(device);
set_bit(GMU_PRIV_GPU_STARTED, &gmu->flags);
device->pwrctrl.last_stat_updated = ktime_get();
kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE);
return ret;
}
static int gen8_aqe_microcode_read(struct adreno_device *adreno_dev)
{
struct adreno_firmware *aqe_fw = ADRENO_FW(adreno_dev, ADRENO_FW_AQE);
const struct adreno_gen8_core *gen8_core = to_gen8_core(adreno_dev);
if (!ADRENO_FEATURE(adreno_dev, ADRENO_AQE))
return 0;
return adreno_get_firmware(adreno_dev, gen8_core->aqefw_name, aqe_fw);
}
static int gen8_hwsched_first_boot(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev);
int ret;
if (test_bit(GMU_PRIV_FIRST_BOOT_DONE, &gmu->flags))
return gen8_hwsched_boot(adreno_dev);
adreno_hwsched_start(adreno_dev);
ret = gen8_microcode_read(adreno_dev);
if (ret)
return ret;
ret = gen8_aqe_microcode_read(adreno_dev);
if (ret)
return ret;
ret = gen8_init(adreno_dev);
if (ret)
return ret;
ret = gen8_hwsched_gmu_init(adreno_dev);
if (ret)
return ret;
kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE);
ret = gen8_hwsched_gmu_first_boot(adreno_dev);
if (ret)
return ret;
ret = gen8_hwsched_gpu_boot(adreno_dev);
if (ret)
return ret;
adreno_dev->cooperative_reset = ADRENO_FEATURE(adreno_dev,
ADRENO_COOP_RESET);
set_bit(GMU_PRIV_FIRST_BOOT_DONE, &gmu->flags);
set_bit(GMU_PRIV_GPU_STARTED, &gmu->flags);
/*
* BCL needs respective Central Broadcast register to
* be programed from TZ. This programing happens only
* when zap shader firmware load is successful. Zap firmware
* load can fail in boot up path hence enable BCL only after we
* successfully complete first boot to ensure that Central
* Broadcast register was programed before enabling BCL.
*/
if (ADRENO_FEATURE(adreno_dev, ADRENO_BCL))
adreno_dev->bcl_enabled = true;
if (device->host_based_dcvs) {
/*
* There is a possible deadlock scenario during kgsl firmware reading
* (firmware_request_nowarn) and devfreq update calls. During first boot, kgsl
* device mutex is held and then firmware_request_nowarn is called for reading
* firmware. firmware_request_nowarn internally takes dev_pm_qos_mtx lock.
* Whereas in case of devfreq update calls triggered by thermal/bcl or
* devfreq sysfs, it first takes the same dev_pm_qos_mtx lock and then
* tries to take kgsl device mutex as part of get_dev_status/target
* calls. This results in deadlock when both thread are unable to acquire
* the mutex held by other thread. Enable devfreq updates now as we are
* done reading all firmware files.
*/
device->pwrscale.devfreq_enabled = true;
device->pwrctrl.last_stat_updated = ktime_get();
}
set_bit(ADRENO_DEVICE_FIRST_BOOT_DONE, &adreno_dev->priv);
kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE);
return 0;
}
/**
* drain_ctx_hw_fences_cpu - Force trigger the hardware fences that
* were not sent to TxQueue by the GMU
*/
static void drain_ctx_hw_fences_cpu(struct adreno_device *adreno_dev,
struct adreno_context *drawctxt)
{
struct adreno_hw_fence_entry *entry, *tmp;
spin_lock(&drawctxt->lock);
list_for_each_entry_safe(entry, tmp, &drawctxt->hw_fence_inflight_list, node) {
kgsl_hw_fence_trigger_cpu(KGSL_DEVICE(adreno_dev), entry->kfence);
adreno_hwsched_remove_hw_fence_entry(adreno_dev, entry);
}
spin_unlock(&drawctxt->lock);
}
static void drain_hw_fences_cpu(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct kgsl_context *context;
int id;
read_lock(&device->context_lock);
idr_for_each_entry(&device->context_idr, context, id) {
if (context->gmu_registered)
drain_ctx_hw_fences_cpu(adreno_dev, ADRENO_CONTEXT(context));
}
read_unlock(&device->context_lock);
}
/**
* check_inflight_hw_fences - During SLUMBER entry, we must make sure all hardware fences across
* all registered contexts have been sent to TxQueue. If not, take a snapshot
*/
static int check_inflight_hw_fences(struct adreno_device *adreno_dev)
{
struct adreno_hwsched *hwsched = &adreno_dev->hwsched;
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct kgsl_context *context;
int id, ret = 0;
if (!test_bit(ADRENO_HWSCHED_HW_FENCE, &hwsched->flags))
return 0;
read_lock(&device->context_lock);
idr_for_each_entry(&device->context_idr, context, id) {
if (context->gmu_registered) {
ret = gen8_hwsched_check_context_inflight_hw_fences(adreno_dev,
ADRENO_CONTEXT(context));
if (ret)
break;
}
}
read_unlock(&device->context_lock);
if (ret)
gmu_core_fault_snapshot(device, GMU_FAULT_HW_FENCE);
return ret;
}
static int gen8_hwsched_power_off(struct adreno_device *adreno_dev)
{
struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
struct gen8_gmu_device *gmu = to_gen8_gmu(adreno_dev);
int ret = 0;
bool drain_cpu = false;
if (!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags))
return 0;
kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER);
ret = gen8_gmu_oob_set(device, oob_gpu);
if (ret) {
gen8_gmu_oob_clear(device, oob_gpu);
goto no_gx_power;
}
kgsl_pwrscale_update_stats(device);
/* Save active coresight registers if applicable */
adreno_coresight_stop(adreno_dev);
adreno_irqctrl(adreno_dev, 0);
gen8_gmu_oob_clear(device, oob_gpu);
no_gx_power:
kgsl_pwrctrl_irq(device, false);