Cairnbin

A618 RESEARCH PART 1 OF 1

text 5 views Created: November 26, 2026 at 11:59:28 EST
   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
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
A618 LEGACY DISPATCHER AND RETIREMENT
Generated: 2026-11-26T19:57:22
Repository: C:\Users\qwertyhorik\Desktop\GPU_TRANSFER_2026-11-26\external\qualcomm-kgsl

========== FILE: adreno.c ==========
--- LINES 655-709 ---
  655:  * @adreno_dev: Pointer to device
  656:  * @bit: Interrupt bit
  657:  */
  658: void adreno_hang_int_callback(struct adreno_device *adreno_dev, int bit)
  659: {
  660: 	dev_crit_ratelimited(KGSL_DEVICE(adreno_dev)->dev,
  661: 				"MISC: GPU hang detected\n");
  662: 	adreno_irqctrl(adreno_dev, 0);
  663: 
  664: 	/* Trigger a fault in the dispatcher - this will effect a restart */
  665: 	adreno_scheduler_fault(adreno_dev, ADRENO_HARD_FAULT);
  666: }
  667: 
  668: /*
  669:  * adreno_cp_callback() - CP interrupt handler
  670:  * @adreno_dev: Adreno device pointer
  671:  * @irq: irq number
  672:  *
  673:  * Handle the cp interrupt generated by GPU.
  674:  */
  675: void adreno_cp_callback(struct adreno_device *adreno_dev, int bit)
  676: {
  677: 	adreno_scheduler_queue(adreno_dev);
  678: }
  679: 
  680: static irqreturn_t adreno_irq_handler(int irq, void *data)
  681: {
  682: 	struct kgsl_device *device = data;
  683: 	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
  684: 	const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
  685: 	irqreturn_t ret;
  686: 
  687: 	atomic_inc(&adreno_dev->pending_irq_refcnt);
  688: 	/* Ensure this increment is done before the IRQ status is updated */
  689: 	smp_mb__after_atomic();
  690: 
  691: 	ret = gpudev->irq_handler(adreno_dev);
  692: 
  693: 	/* Make sure the regwrites are done before the decrement */
  694: 	smp_mb__before_atomic();
  695: 	atomic_dec(&adreno_dev->pending_irq_refcnt);
  696: 	/* Ensure other CPUs see the decrement */
  697: 	smp_mb__after_atomic();
  698: 
  699: 	return ret;
  700: }
  701: 
  702: static irqreturn_t adreno_freq_limiter_irq_handler(int irq, void *data)
  703: {
  704: 	struct kgsl_device *device = data;
  705: 
  706: 	KGSL_PWRCTRL_LOG_FREQLIM(device);
  707: 
  708: 	reset_control_reset(device->freq_limiter_irq_clear);
  709: 
--- LINES 1919-1985 ---
 1919: 				pd->prepared_count, event);
 1920: 			return NOTIFY_BAD;
 1921: 		}
 1922: 	}
 1923: 
 1924: 	if (event == PM_SUSPEND_PREPARE) {
 1925: 		/*
 1926: 		 * In presence of a hardware fault, cancel system suspend (by returning NOTIFY_BAD)
 1927: 		 * here to make sure system suspend doesn't increment the pd prepared_count. This
 1928: 		 * ensures that cx and gx gdscs can be toggled successfully during fault recovery.
 1929: 		 */
 1930: 		if (adreno_gpu_fault(adreno_dev)) {
 1931: 			dev_err_ratelimited(device->dev, "cancelling suspend because of fault\n");
 1932: 			complete_all(&adreno_dev->suspend_recovery_gate);
 1933: 			adreno_scheduler_queue(adreno_dev);
 1934: 			return NOTIFY_BAD;
 1935: 		}
 1936: 
 1937: 		reinit_completion(&adreno_dev->suspend_recovery_gate);
 1938: 		return NOTIFY_DONE;
 1939: 	}
 1940: 
 1941: 	/*
 1942: 	 * We get PM_POST_SUSPEND if we failed kgsl suspend in the presence of a hardware fault,
 1943: 	 * or when system resume finishes. In either case, this means the system has come out of
 1944: 	 * suspend and has put back the power domain prepared_count. This means we are safe to
 1945: 	 * perform fault recovery.
 1946: 	 */
 1947: 	if (event == PM_POST_SUSPEND) {
 1948: 		complete_all(&adreno_dev->suspend_recovery_gate);
 1949: 		/*
 1950: 		 * Queue the gpu scheduler to proceed with fault recovery in case there was a
 1951: 		 * fault
 1952: 		 */
 1953: 		adreno_scheduler_queue(adreno_dev);
 1954: 	}
 1955: 
 1956: 	return NOTIFY_DONE;
 1957: }
 1958: 
 1959: static void validate_pwrlevels(struct kgsl_device *device)
 1960: {
 1961: 	struct kgsl_pwrctrl *pwr = &device->pwrctrl;
 1962: 	int i, count = pwr->ddr_table_count;
 1963: 
 1964: 	for (i = 0; i < pwr->num_pwrlevels - 1; i++) {
 1965: 		struct kgsl_pwrlevel *pwrlevel = &pwr->pwrlevels[i];
 1966: 
 1967: 		if (pwrlevel->bus_freq >= count) {
 1968: 			dev_err(device->dev, "Bus setting for GPU freq %d is out of bounds\n",
 1969: 				pwrlevel->gpu_freq);
 1970: 			pwrlevel->bus_freq = count - 1;
 1971: 		}
 1972: 
 1973: 		if (pwrlevel->bus_max >= count) {
 1974: 			dev_err(device->dev, "Bus max for GPU freq %d is out of bounds\n",
 1975: 				pwrlevel->gpu_freq);
 1976: 			pwrlevel->bus_max = count - 1;
 1977: 		}
 1978: 
 1979: 		if (pwrlevel->bus_min >= count) {
 1980: 			dev_err(device->dev, "Bus min for GPU freq %d is out of bounds\n",
 1981: 				pwrlevel->gpu_freq);
 1982: 			pwrlevel->bus_min = count - 1;
 1983: 		}
 1984: 
 1985: 		if (pwrlevel->bus_min > pwrlevel->bus_max) {
--- LINES 2917-2963 ---
 2917: 
 2918: 	status = gpudev->rb_start(adreno_dev);
 2919: 	if (status)
 2920: 		goto error_pwr_off;
 2921: 
 2922: 	/*
 2923: 	 * At this point it is safe to assume that we recovered. Setting
 2924: 	 * this field allows us to take a new snapshot for the next failure
 2925: 	 * if we are prioritizing the first unrecoverable snapshot.
 2926: 	 */
 2927: 	if (device->snapshot)
 2928: 		device->snapshot->recovered = true;
 2929: 
 2930: 	/* Start the dispatcher */
 2931: 	adreno_dispatcher_start(device);
 2932: 
 2933: 	device->reset_counter++;
 2934: 
 2935: 	set_bit(ADRENO_DEVICE_STARTED, &adreno_dev->priv);
 2936: 
 2937: 	/*
 2938: 	 * There is a possible deadlock scenario during kgsl firmware reading
 2939: 	 * (firmware_request_nowarn) and devfreq update calls. During first boot, kgsl
 2940: 	 * device mutex is held and then firmware_request_nowarn is called for reading
 2941: 	 * firmware. firmware_request_nowarn internally takes dev_pm_qos_mtx lock.
 2942: 	 * Whereas in case of devfreq update calls triggered by thermal/bcl or
 2943: 	 * devfreq sysfs, it first takes the same dev_pm_qos_mtx lock and then
 2944: 	 * tries to take kgsl device mutex as part of get_dev_status/target
 2945: 	 * calls. This results in deadlock when both thread are unable to acquire
 2946: 	 * the mutex held by other thread. Enable devfreq updates now as we are
 2947: 	 * done reading all firmware files.
 2948: 	 */
 2949: 	device->pwrscale.devfreq_enabled = true;
 2950: 
 2951: 	return 0;
 2952: 
 2953: error_pwr_off:
 2954: 	/* set the state back to original state */
 2955: 	kgsl_pwrctrl_change_state(device, state);
 2956: 
 2957: 	return status;
 2958: }
 2959: 
 2960: /**
 2961:  * adreno_start() - Power up and initialize the GPU
 2962:  * @device: Pointer to the KGSL device to power up
 2963:  * @priority:  Boolean flag to specify of the start should be scheduled in a low
--- LINES 2994-3040 ---
 2994: 
 2995: 	kgsl_pwrscale_update_stats(device);
 2996: 
 2997: 	adreno_irqctrl(adreno_dev, 0);
 2998: 
 2999: 	/* Save active coresight registers if applicable */
 3000: 	adreno_coresight_stop(adreno_dev);
 3001: 
 3002: 	/* Save physical performance counter values before GPU power down*/
 3003: 	adreno_perfcounter_save(adreno_dev);
 3004: 
 3005: 	if (gpudev->clear_pending_transactions)
 3006: 		gpudev->clear_pending_transactions(adreno_dev);
 3007: 
 3008: 	adreno_dispatcher_stop(adreno_dev);
 3009: 
 3010: 	adreno_ringbuffer_stop(adreno_dev);
 3011: 
 3012: 	adreno_llcc_slice_deactivate(adreno_dev);
 3013: 
 3014: 	adreno_set_active_ctxs_null(adreno_dev);
 3015: 
 3016: 	clear_bit(ADRENO_DEVICE_STARTED, &adreno_dev->priv);
 3017: 
 3018: 	return error;
 3019: }
 3020: 
 3021: /**
 3022:  * adreno_reset() - Helper function to reset the GPU
 3023:  * @device: Pointer to the KGSL device structure for the GPU
 3024:  * @fault: Type of fault. Needed to skip soft reset for MMU fault
 3025:  *
 3026:  * Try to reset the GPU to recover from a fault.  First, try to do a low latency
 3027:  * soft reset.  If the soft reset fails for some reason, then bring out the big
 3028:  * guns and toggle the footswitch.
 3029:  */
 3030: int adreno_reset(struct kgsl_device *device, int fault)
 3031: {
 3032: 	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
 3033: 	const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
 3034: 	int ret = -EINVAL;
 3035: 	int i;
 3036: 
 3037: 	if (gpudev->reset)
 3038: 		return adreno_gpudev_reset(adreno_dev);
 3039: 
 3040: 	/*
--- LINES 3791-3837 ---
 3791: 	 * Make sure the device mutex is held so the dispatcher can't send any
 3792: 	 * more commands to the hardware
 3793: 	 */
 3794: 
 3795: 	if (WARN_ON(!kgsl_mutex_is_locked(&device->mutex)))
 3796: 		return -EDEADLK;
 3797: 
 3798: 	/* Check if we are already idle before idling dispatcher */
 3799: 	if (adreno_isidle(adreno_dev))
 3800: 		return 0;
 3801: 	/*
 3802: 	 * Wait for dispatcher to finish completing commands
 3803: 	 * already submitted
 3804: 	 */
 3805: 	ret = adreno_dispatcher_idle(adreno_dev);
 3806: 	if (ret)
 3807: 		return ret;
 3808: 
 3809: 	return adreno_spin_idle(adreno_dev, ADRENO_IDLE_TIMEOUT);
 3810: }
 3811: 
 3812: int adreno_drain(struct kgsl_device *device, unsigned long wait_jiffies)
 3813: {
 3814: 	int ret;
 3815: 
 3816: 	/* Halt any new submissions */
 3817: 	reinit_completion(&device->halt_gate);
 3818: 
 3819: 	/**
 3820: 	 * Wait for the dispatcher to retire everything by waiting
 3821: 	 * for the active count to go to zero.
 3822: 	 */
 3823: 	ret = kgsl_active_count_wait(device, 0, wait_jiffies);
 3824: 	if (ret)
 3825: 		dev_err(device->dev, "Timed out waiting for the active count\n");
 3826: 
 3827: 	return ret;
 3828: }
 3829: 
 3830: /* Caller must hold the device mutex. */
 3831: void adreno_check_idle(struct kgsl_device *device)
 3832: {
 3833: 	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
 3834: 
 3835: 	/* process any profiling results that are available */
 3836: 	adreno_profile_process_results(adreno_dev);
 3837: 
--- LINES 3949-4050 ---
 3949: /**
 3950:  * __adreno_readtimestamp() - Reads the timestamp from memstore memory
 3951:  * @adreno_dev: Pointer to an adreno device
 3952:  * @index: Index into the memstore memory
 3953:  * @type: Type of timestamp to read
 3954:  * @timestamp: The out parameter where the timestamp is read
 3955:  */
 3956: static int __adreno_readtimestamp(struct adreno_device *adreno_dev, int index,
 3957: 				int type, unsigned int *timestamp)
 3958: {
 3959: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
 3960: 	int status = 0;
 3961: 
 3962: 	switch (type) {
 3963: 	case KGSL_TIMESTAMP_CONSUMED:
 3964: 		kgsl_sharedmem_readl(device->memstore, timestamp,
 3965: 			KGSL_MEMSTORE_OFFSET(index, soptimestamp));
 3966: 		break;
 3967: 	case KGSL_TIMESTAMP_RETIRED:
 3968: 		kgsl_sharedmem_readl(device->memstore, timestamp,
 3969: 			KGSL_MEMSTORE_OFFSET(index, eoptimestamp));
 3970: 		break;
 3971: 	default:
 3972: 		status = -EINVAL;
 3973: 		*timestamp = 0;
 3974: 		break;
 3975: 	}
 3976: 	return status;
 3977: }
 3978: 
 3979: /**
 3980:  * adreno_rb_readtimestamp(): Return the value of given type of timestamp
 3981:  * for a RB
 3982:  * @adreno_dev: adreno device whose timestamp values are being queried
 3983:  * @priv: The object being queried for a timestamp (expected to be a rb pointer)
 3984:  * @type: The type of timestamp (one of 3) to be read
 3985:  * @timestamp: Pointer to where the read timestamp is to be written to
 3986:  *
 3987:  * CONSUMED and RETIRED type timestamps are sorted by id and are constantly
 3988:  * updated by the GPU through shared memstore memory. QUEUED type timestamps
 3989:  * are read directly from context struct.
 3990: 
 3991:  * The function returns 0 on success and timestamp value at the *timestamp
 3992:  * address and returns -EINVAL on any read error/invalid type and timestamp = 0.
 3993:  */
 3994: int adreno_rb_readtimestamp(struct adreno_device *adreno_dev,
 3995: 		void *priv, enum kgsl_timestamp_type type,
 3996: 		unsigned int *timestamp)
 3997: {
 3998: 	int status = 0;
 3999: 	struct adreno_ringbuffer *rb = priv;
 4000: 
 4001: 	if (type == KGSL_TIMESTAMP_QUEUED)
 4002: 		*timestamp = rb->timestamp;
 4003: 	else
 4004: 		status = __adreno_readtimestamp(adreno_dev,
 4005: 				rb->id + KGSL_MEMSTORE_MAX,
 4006: 				type, timestamp);
 4007: 
 4008: 	return status;
 4009: }
 4010: 
 4011: /**
 4012:  * adreno_readtimestamp(): Return the value of given type of timestamp
 4013:  * @device: GPU device whose timestamp values are being queried
 4014:  * @priv: The object being queried for a timestamp (expected to be a context)
 4015:  * @type: The type of timestamp (one of 3) to be read
 4016:  * @timestamp: Pointer to where the read timestamp is to be written to
 4017:  *
 4018:  * CONSUMED and RETIRED type timestamps are sorted by id and are constantly
 4019:  * updated by the GPU through shared memstore memory. QUEUED type timestamps
 4020:  * are read directly from context struct.
 4021: 
 4022:  * The function returns 0 on success and timestamp value at the *timestamp
 4023:  * address and returns -EINVAL on any read error/invalid type and timestamp = 0.
 4024:  */
 4025: static int adreno_readtimestamp(struct kgsl_device *device,
 4026: 		void *priv, enum kgsl_timestamp_type type,
 4027: 		unsigned int *timestamp)
 4028: {
 4029: 	int status = 0;
 4030: 	struct kgsl_context *context = priv;
 4031: 
 4032: 	if (type == KGSL_TIMESTAMP_QUEUED) {
 4033: 		struct adreno_context *ctxt = ADRENO_CONTEXT(context);
 4034: 
 4035: 		*timestamp = ctxt->timestamp;
 4036: 	} else
 4037: 		status = __adreno_readtimestamp(ADRENO_DEVICE(device),
 4038: 				context->id, type, timestamp);
 4039: 
 4040: 	return status;
 4041: }
 4042: 
 4043: /**
 4044:  * adreno_device_private_create(): Allocate an adreno_device_private structure
 4045:  */
 4046: static struct kgsl_device_private *adreno_device_private_create(void)
 4047: {
 4048: 	struct adreno_device_private *adreno_priv =
 4049: 			kzalloc(sizeof(*adreno_priv), GFP_KERNEL);
 4050: 
--- LINES 4724-4770 ---
 4724: 	.compat_ioctl = adreno_compat_ioctl,
 4725: 	.power_stats = adreno_power_stats,
 4726: 	.snapshot = adreno_snapshot,
 4727: 	.drain_and_idle = adreno_drain_and_idle,
 4728: 	.device_private_create = adreno_device_private_create,
 4729: 	.device_private_destroy = adreno_device_private_destroy,
 4730: 	/* Optional functions */
 4731: 	.drawctxt_create = adreno_drawctxt_create,
 4732: 	.drawctxt_detach = adreno_drawctxt_detach,
 4733: 	.drawctxt_destroy = adreno_drawctxt_destroy,
 4734: 	.drawctxt_dump = adreno_drawctxt_dump,
 4735: 	.setproperty = adreno_setproperty,
 4736: 	.setproperty_compat = adreno_setproperty_compat,
 4737: 	.drawctxt_sched = adreno_drawctxt_sched,
 4738: 	.resume = adreno_dispatcher_start,
 4739: 	.regulator_enable = adreno_regulator_enable,
 4740: 	.is_hw_collapsible = adreno_is_hw_collapsible,
 4741: 	.regulator_disable = adreno_regulator_disable,
 4742: 	.pwrlevel_change_settings = adreno_pwrlevel_change_settings,
 4743: 	.query_property_list = adreno_query_property_list,
 4744: 	.is_hwcg_on = adreno_is_hwcg_on,
 4745: 	.gpu_clock_set = adreno_gpu_clock_set,
 4746: 	.gpu_bus_set = adreno_gpu_bus_set,
 4747: 	.deassert_gbif_halt = adreno_deassert_gbif_halt,
 4748: 	.queue_recurring_cmd = adreno_queue_recurring_cmd,
 4749: 	.dequeue_recurring_cmd = adreno_dequeue_recurring_cmd,
 4750: 	.set_isdb_breakpoint_registers = adreno_set_isdb_breakpoint_registers,
 4751: 	.create_hw_fence = adreno_create_hw_fence,
 4752: 	.gmu_based_dcvs_pwr_ops = adreno_gmu_based_dcvs_pwr_ops,
 4753: 	.set_thermal_index = adreno_set_thermal_index,
 4754: 	.alloc_dcvs_profile_memory = adreno_alloc_dcvs_profile_memory,
 4755: 	.is_first_boot_done = adreno_is_first_boot_done,
 4756: 	.set_smmu_aperture = adreno_set_smmu_aperture,
 4757: };
 4758: 
 4759: static const struct component_master_ops adreno_ops = {
 4760: 	.bind = adreno_bind,
 4761: 	.unbind = adreno_unbind,
 4762: };
 4763: 
 4764: const struct adreno_power_ops adreno_power_operations = {
 4765: 	.first_open = adreno_open,
 4766: 	.last_close = adreno_close,
 4767: 	.active_count_get = adreno_pwrctrl_active_count_get,
 4768: 	.pm_suspend = adreno_suspend,
 4769: 	.pm_resume = adreno_resume,
 4770: 	.touch_wakeup = adreno_touch_wakeup,

========== FILE: adreno_a6xx.c ==========
--- LINES 1787-1885 ---
 1787: 	case 2:
 1788: 	case 3:
 1789: 		return a6xx_fault_block_uche(device, mid);
 1790: 	case 4:
 1791: 		return "CCU";
 1792: 	case 6:
 1793: 		return "CDP Prefetch";
 1794: 	case 7:
 1795: 		return "GPMU";
 1796: 	}
 1797: 
 1798: 	return "Unknown";
 1799: }
 1800: 
 1801: static void a6xx_cp_callback(struct adreno_device *adreno_dev, int bit)
 1802: {
 1803: 	if (adreno_is_preemption_enabled(adreno_dev))
 1804: 		a6xx_preemption_trigger(adreno_dev, true);
 1805: 
 1806: 	adreno_scheduler_queue(adreno_dev);
 1807: }
 1808: 
 1809: /*
 1810:  * a6xx_gpc_err_int_callback() - Isr for GPC error interrupts
 1811:  * @adreno_dev: Pointer to device
 1812:  * @bit: Interrupt bit
 1813:  */
 1814: static void a6xx_gpc_err_int_callback(struct adreno_device *adreno_dev, int bit)
 1815: {
 1816: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
 1817: 
 1818: 	/*
 1819: 	 * GPC error is typically the result of mistake SW programming.
 1820: 	 * Force GPU fault for this interrupt so that we can debug it
 1821: 	 * with help of register dump.
 1822: 	 */
 1823: 
 1824: 	dev_crit(device->dev, "RBBM: GPC error\n");
 1825: 	adreno_irqctrl(adreno_dev, 0);
 1826: 
 1827: 	/* Trigger a fault in the dispatcher - this will effect a restart */
 1828: 	adreno_scheduler_fault(adreno_dev, ADRENO_SOFT_FAULT);
 1829: }
 1830: 
 1831: static const struct adreno_irq_funcs a6xx_irq_funcs[32] = {
 1832: 	ADRENO_IRQ_CALLBACK(NULL),              /* 0 - RBBM_GPU_IDLE */
 1833: 	ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 1 - RBBM_AHB_ERROR */
 1834: 	ADRENO_IRQ_CALLBACK(NULL), /* 2 - UNUSED */
 1835: 	ADRENO_IRQ_CALLBACK(NULL), /* 3 - UNUSED */
 1836: 	ADRENO_IRQ_CALLBACK(NULL), /* 4 - UNUSED */
 1837: 	ADRENO_IRQ_CALLBACK(NULL), /* 5 - UNUSED */
 1838: 	/* 6 - RBBM_ATB_ASYNC_OVERFLOW */
 1839: 	ADRENO_IRQ_CALLBACK(a6xx_err_callback),
 1840: 	ADRENO_IRQ_CALLBACK(a6xx_gpc_err_int_callback), /* 7 - GPC_ERR */
 1841: 	ADRENO_IRQ_CALLBACK(a6xx_preemption_callback),/* 8 - CP_SW */
 1842: 	ADRENO_IRQ_CALLBACK(a6xx_cp_hw_err_callback), /* 9 - CP_HW_ERROR */
 1843: 	ADRENO_IRQ_CALLBACK(NULL),  /* 10 - CP_CCU_FLUSH_DEPTH_TS */
 1844: 	ADRENO_IRQ_CALLBACK(NULL), /* 11 - CP_CCU_FLUSH_COLOR_TS */
 1845: 	ADRENO_IRQ_CALLBACK(NULL), /* 12 - CP_CCU_RESOLVE_TS */
 1846: 	ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 13 - CP_IB2_INT */
 1847: 	ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 14 - CP_IB1_INT */
 1848: 	ADRENO_IRQ_CALLBACK(adreno_cp_callback), /* 15 - CP_RB_INT */
 1849: 	ADRENO_IRQ_CALLBACK(NULL), /* 16 - UNUSED */
 1850: 	ADRENO_IRQ_CALLBACK(NULL), /* 17 - CP_RB_DONE_TS */
 1851: 	ADRENO_IRQ_CALLBACK(NULL), /* 18 - CP_WT_DONE_TS */
 1852: 	ADRENO_IRQ_CALLBACK(NULL), /* 19 - UNUSED */
 1853: 	ADRENO_IRQ_CALLBACK(a6xx_cp_callback), /* 20 - CP_CACHE_FLUSH_TS */
 1854: 	ADRENO_IRQ_CALLBACK(NULL), /* 21 - UNUSED */
 1855: 	ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 22 - RBBM_ATB_BUS_OVERFLOW */
 1856: 	/* 23 - MISC_HANG_DETECT */
 1857: 	ADRENO_IRQ_CALLBACK(adreno_hang_int_callback),
 1858: 	ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 24 - UCHE_OOB_ACCESS */
 1859: 	ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 25 - UCHE_TRAP_INTR */
 1860: 	ADRENO_IRQ_CALLBACK(NULL), /* 26 - DEBBUS_INTR_0 */
 1861: 	ADRENO_IRQ_CALLBACK(NULL), /* 27 - DEBBUS_INTR_1 */
 1862: 	ADRENO_IRQ_CALLBACK(a6xx_err_callback), /* 28 - TSBWRITEERROR */
 1863: 	ADRENO_IRQ_CALLBACK(NULL), /* 29 - UNUSED */
 1864: 	ADRENO_IRQ_CALLBACK(NULL), /* 30 - ISDB_CPU_IRQ */
 1865: 	ADRENO_IRQ_CALLBACK(NULL), /* 31 - ISDB_UNDER_DEBUG */
 1866: };
 1867: 
 1868: /*
 1869:  * If the AHB fence is not in ALLOW mode when we receive an RBBM
 1870:  * interrupt, something went wrong. This means that we cannot proceed
 1871:  * since the IRQ status and clear registers are not accessible.
 1872:  * This is usually harmless because the GMU will abort power collapse
 1873:  * and change the fence back to ALLOW. Poll so that this can happen.
 1874:  */
 1875: static int a6xx_irq_poll_fence(struct adreno_device *adreno_dev)
 1876: {
 1877: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
 1878: 	u32 status, fence, fence_retries = 0;
 1879: 	u64 a, b, c;
 1880: 
 1881: 	if (!gmu_core_isenabled(device))
 1882: 		return 0;
 1883: 
 1884: 	a = a6xx_read_alwayson(adreno_dev);
 1885: 
--- LINES 2066-2112 ---
 2066: 			return -ENODEV;
 2067: 		}
 2068: 
 2069: 		region = &regmap->region[regmap->count];
 2070: 
 2071: 		ret = kgsl_regmap_init_region(regmap, device->pdev, region, res, NULL, NULL);
 2072: 		if (!ret)
 2073: 			regmap->count++;
 2074: 		platform_device_put(gmu_wrapper_pdev);
 2075: 	}
 2076: 
 2077: 	if (ret)
 2078: 		return ret;
 2079: 
 2080: 	ret = adreno_dispatcher_init(adreno_dev);
 2081: 	if (ret)
 2082: 		return ret;
 2083: 
 2084: 	timer_setup(&device->idle_timer, kgsl_timer, 0);
 2085: 
 2086: 	INIT_WORK(&device->idle_check_ws, kgsl_idle_check);
 2087: 
 2088: 	return 0;
 2089: }
 2090: 
 2091: /* Register offset defines for A6XX, in order of enum adreno_regs */
 2092: static unsigned int a6xx_register_offsets[ADRENO_REG_REGISTER_MAX] = {
 2093: 
 2094: 	ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_BASE, A6XX_CP_RB_BASE),
 2095: 	ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_BASE_HI, A6XX_CP_RB_BASE_HI),
 2096: 	ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_RPTR, A6XX_CP_RB_RPTR),
 2097: 	ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_WPTR, A6XX_CP_RB_WPTR),
 2098: 	ADRENO_REG_DEFINE(ADRENO_REG_CP_RB_CNTL, A6XX_CP_RB_CNTL),
 2099: 	ADRENO_REG_DEFINE(ADRENO_REG_CP_ME_CNTL, A6XX_CP_SQE_CNTL),
 2100: 	ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BASE, A6XX_CP_IB1_BASE),
 2101: 	ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BASE_HI, A6XX_CP_IB1_BASE_HI),
 2102: 	ADRENO_REG_DEFINE(ADRENO_REG_CP_IB1_BUFSZ, A6XX_CP_IB1_REM_SIZE),
 2103: 	ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BASE, A6XX_CP_IB2_BASE),
 2104: 	ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BASE_HI, A6XX_CP_IB2_BASE_HI),
 2105: 	ADRENO_REG_DEFINE(ADRENO_REG_CP_IB2_BUFSZ, A6XX_CP_IB2_REM_SIZE),
 2106: 	ADRENO_REG_DEFINE(ADRENO_REG_RBBM_STATUS, A6XX_RBBM_STATUS),
 2107: 	ADRENO_REG_DEFINE(ADRENO_REG_RBBM_STATUS3, A6XX_RBBM_STATUS3),
 2108: 	ADRENO_REG_DEFINE(ADRENO_REG_RBBM_INT_0_MASK, A6XX_RBBM_INT_0_MASK),
 2109: 	ADRENO_REG_DEFINE(ADRENO_REG_RBBM_SW_RESET_CMD, A6XX_RBBM_SW_RESET_CMD),
 2110: 	ADRENO_REG_DEFINE(ADRENO_REG_GMU_AO_HOST_INTERRUPT_MASK,
 2111: 				A6XX_GMU_AO_HOST_INTERRUPT_MASK),
 2112: 	ADRENO_REG_DEFINE(ADRENO_REG_GMU_GMU2HOST_INTR_MASK,

========== FILE: adreno_a6xx_gmu.c ==========
--- LINES 2974-3020 ---
 2974: 		a6xx_disable_gpu_irq(adreno_dev);
 2975: 		adreno_llcc_slice_deactivate(adreno_dev);
 2976: 		goto oob_clear;
 2977: 	}
 2978: 
 2979: 	/*
 2980: 	 * At this point it is safe to assume that we recovered. Setting
 2981: 	 * this field allows us to take a new snapshot for the next failure
 2982: 	 * if we are prioritizing the first unrecoverable snapshot.
 2983: 	 */
 2984: 	if (device->snapshot)
 2985: 		device->snapshot->recovered = true;
 2986: 
 2987: 	/* Start the dispatcher */
 2988: 	adreno_dispatcher_start(device);
 2989: 
 2990: 	device->reset_counter++;
 2991: 
 2992: 	a6xx_gmu_oob_clear(device, oob_gpu);
 2993: 
 2994: 	if (ADRENO_QUIRK(adreno_dev, ADRENO_QUIRK_HFI_USE_REG))
 2995: 		gmu_core_dev_oob_clear(device, oob_boot_slumber);
 2996: 
 2997: 	return 0;
 2998: 
 2999: oob_clear:
 3000: 	a6xx_gmu_oob_clear(device, oob_gpu);
 3001: 
 3002: 	if (ADRENO_QUIRK(adreno_dev, ADRENO_QUIRK_HFI_USE_REG))
 3003: 		gmu_core_dev_oob_clear(device, oob_boot_slumber);
 3004: 
 3005: err:
 3006: 	a6xx_gmu_power_off(adreno_dev);
 3007: 
 3008: 	return ret;
 3009: }
 3010: 
 3011: static void gmu_idle_timer(struct timer_list *t)
 3012: {
 3013: 	struct kgsl_device *device = container_of(t, struct kgsl_device,
 3014: 					idle_timer);
 3015: 
 3016: 	kgsl_schedule_work(&device->idle_check_ws);
 3017: }
 3018: 
 3019: static int a6xx_boot(struct adreno_device *adreno_dev)
 3020: {
--- LINES 3194-3240 ---
 3194: 	if (adreno_is_a630(adreno_dev))
 3195: 		a630_vbif_halt(adreno_dev);
 3196: 
 3197: 	adreno_irqctrl(adreno_dev, 0);
 3198: 
 3199: 	a6xx_gmu_oob_clear(device, oob_gpu);
 3200: 
 3201: no_gx_power:
 3202: 	kgsl_pwrctrl_irq(device, false);
 3203: 
 3204: 	a6xx_gmu_power_off(adreno_dev);
 3205: 
 3206: 	adreno_set_active_ctxs_null(adreno_dev);
 3207: 
 3208: 	adreno_dispatcher_stop(adreno_dev);
 3209: 
 3210: 	adreno_ringbuffer_stop(adreno_dev);
 3211: 
 3212: 	adreno_llcc_slice_deactivate(adreno_dev);
 3213: 
 3214: 	clear_bit(GMU_PRIV_GPU_STARTED, &gmu->flags);
 3215: 
 3216: 	kgsl_delete_timer_sync(&device->idle_timer);
 3217: 
 3218: 	kgsl_pwrscale_sleep(device);
 3219: 
 3220: 	kgsl_pwrctrl_clear_l3_vote(device);
 3221: 
 3222: 	kgsl_pwrctrl_set_state(device, KGSL_STATE_SLUMBER);
 3223: 
 3224: 	return ret;
 3225: }
 3226: 
 3227: static void gmu_idle_check(struct work_struct *work)
 3228: {
 3229: 	struct kgsl_device *device = container_of(work,
 3230: 					struct kgsl_device, idle_check_ws);
 3231: 	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
 3232: 	struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
 3233: 	int ret;
 3234: 
 3235: 	kgsl_mutex_lock(&device->mutex);
 3236: 
 3237: 	if (test_bit(GMU_DISABLE_SLUMBER, &device->gmu_core.flags))
 3238: 		goto done;
 3239: 
 3240: 	if (atomic_read(&device->active_cnt) || time_is_after_jiffies(device->idle_jiffies)) {
--- LINES 3341-3402 ---
 3341: 	if (ret)
 3342: 		goto err;
 3343: 
 3344: 	if (test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags))
 3345: 		a6xx_power_off(adreno_dev);
 3346: 
 3347: 	set_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags);
 3348: 
 3349: 	adreno_get_gpu_halt(adreno_dev);
 3350: 
 3351: 	kgsl_pwrctrl_set_state(device, KGSL_STATE_SUSPEND);
 3352: 
 3353: 	return 0;
 3354: err:
 3355: 	adreno_dispatcher_start(device);
 3356: 	return ret;
 3357: }
 3358: 
 3359: static void a6xx_gmu_pm_resume(struct adreno_device *adreno_dev)
 3360: {
 3361: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
 3362: 	struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
 3363: 
 3364: 	if (WARN(!test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags),
 3365: 		"resume invoked without a suspend\n"))
 3366: 		return;
 3367: 
 3368: 	adreno_put_gpu_halt(adreno_dev);
 3369: 
 3370: 	adreno_dispatcher_start(device);
 3371: 
 3372: 	clear_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags);
 3373: }
 3374: 
 3375: static void a6xx_gmu_touch_wakeup(struct adreno_device *adreno_dev)
 3376: {
 3377: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
 3378: 	struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
 3379: 	int ret;
 3380: 
 3381: 	/*
 3382: 	 * Do not wake up a suspended device or until the first boot sequence
 3383: 	 * has been completed.
 3384: 	 */
 3385: 	if (test_bit(GMU_PRIV_PM_SUSPEND, &gmu->flags) ||
 3386: 		!test_bit(GMU_PRIV_FIRST_BOOT_DONE, &gmu->flags))
 3387: 		return;
 3388: 
 3389: 	if (test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags))
 3390: 		goto done;
 3391: 
 3392: 	kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE);
 3393: 
 3394: 	ret = a6xx_gmu_boot(adreno_dev);
 3395: 	if (ret)
 3396: 		return;
 3397: 
 3398: 	ret = a6xx_gpu_boot(adreno_dev);
 3399: 	if (ret)
 3400: 		return;
 3401: 
 3402: 	kgsl_pwrscale_wake(device);
--- LINES 3450-3496 ---
 3450: 
 3451: 	a6xx_dev = devm_kzalloc(&pdev->dev, sizeof(*a6xx_dev),
 3452: 			GFP_KERNEL);
 3453: 	if (!a6xx_dev)
 3454: 		return -ENOMEM;
 3455: 
 3456: 	adreno_dev = &a6xx_dev->adreno_dev;
 3457: 
 3458: 	adreno_dev->irq_mask = A6XX_INT_MASK;
 3459: 
 3460: 	ret = a6xx_probe_common(pdev, adreno_dev, chipid, gpucore);
 3461: 	if (ret)
 3462: 		return ret;
 3463: 
 3464: 	ret = adreno_dispatcher_init(adreno_dev);
 3465: 	if (ret)
 3466: 		return ret;
 3467: 
 3468: 	device = KGSL_DEVICE(adreno_dev);
 3469: 
 3470: 	INIT_WORK(&device->idle_check_ws, gmu_idle_check);
 3471: 
 3472: 	timer_setup(&device->idle_timer, gmu_idle_timer, 0);
 3473: 
 3474: 	return 0;
 3475: }
 3476: 
 3477: int a6xx_gmu_reset(struct adreno_device *adreno_dev)
 3478: {
 3479: 	struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
 3480: 
 3481: 	a6xx_disable_gpu_irq(adreno_dev);
 3482: 
 3483: 	a6xx_gmu_irq_disable(adreno_dev);
 3484: 
 3485: 	a6xx_hfi_stop(adreno_dev);
 3486: 
 3487: 	/* Hard reset the gmu and gpu */
 3488: 	a6xx_gmu_suspend(adreno_dev, true);
 3489: 
 3490: 	a6xx_reset_preempt_records(adreno_dev);
 3491: 
 3492: 	adreno_llcc_slice_deactivate(adreno_dev);
 3493: 
 3494: 	clear_bit(GMU_PRIV_GPU_STARTED, &gmu->flags);
 3495: 
 3496: 	/* Attempt to reboot the gmu and gpu */

========== FILE: adreno_a6xx_hwsched.h ==========
--- LINES 25-71 ---
   25:  * @chipid: Chipid of the target
   26:  * @gpucore: Pointer to the gpucore
   27:  *
   28:  * The target specific probe function for hwsched enabled gmu targets.
   29:  *
   30:  * Return: 0 on success or negative error on failure
   31:  */
   32: int a6xx_hwsched_probe(struct platform_device *pdev,
   33: 	u32 chipid, const struct adreno_gpu_core *gpucore);
   34: 
   35: /**
   36:  * a6xx_hwsched_reset_replay - Restart the gmu and gpu
   37:  * @adreno_dev: Pointer to the adreno device
   38:  *
   39:  * Restart the GMU and GPU and replay the inflight commands
   40: 
   41:  * Return: 0 on success or negative error on failure
   42:  */
   43: int a6xx_hwsched_reset_replay(struct adreno_device *adreno_dev);
   44: 
   45: /**
   46:  * a6xx_hwsched_snapshot - take a6xx hwsched snapshot
   47:  * @adreno_dev: Pointer to the adreno device
   48:  * @snapshot: Pointer to the snapshot instance
   49:  *
   50:  * Snapshot the faulty ib and then snapshot rest of a6xx gmu things
   51:  */
   52: void a6xx_hwsched_snapshot(struct adreno_device *adreno_dev,
   53: 	struct kgsl_snapshot *snapshot);
   54: 
   55: /**
   56:  * a6xx_hwsched_handle_watchdog - Handle watchdog interrupt
   57:  * @adreno_dev: Pointer to the adreno device
   58:  */
   59: void a6xx_hwsched_handle_watchdog(struct adreno_device *adreno_dev);
   60: 
   61: /**
   62:  * a6xx_hwsched_add_to_minidump - Register hwsched_device with va minidump
   63:  * @adreno_dev: Pointer to the adreno device
   64:  */
   65: int a6xx_hwsched_add_to_minidump(struct adreno_device *adreno_dev);
   66: 
   67: /**
   68:  * a6xx_hwsched_send_recurring_cmdobj - Dispatch IBs to GMU
   69:  * @adreno_dev: Pointer to adreno device structure
   70:  * @cmdobj: The command object which needs to be submitted
   71:  *

========== FILE: adreno_a6xx_hwsched_hfi.c ==========
--- LINES 382-428 ---
  382: 			process_ctx_bad(adreno_dev);
  383: 			continue;
  384: 		}
  385: 
  386: 		a6xx_hfi_queue_read(gmu, HFI_MSG_ID, rcvd, sizeof(rcvd));
  387: 
  388: 		/*
  389: 		 * We are assuming that there is only one outstanding ack
  390: 		 * because hfi sending thread waits for completion while
  391: 		 * holding the device mutex
  392: 		 */
  393: 		if (MSG_HDR_GET_TYPE(rcvd[0]) == HFI_MSG_ACK) {
  394: 			a6xx_receive_ack_async(adreno_dev, rcvd);
  395: 		} else if (MSG_HDR_GET_ID(rcvd[0]) == F2H_MSG_TS_RETIRE) {
  396: 			adreno_scheduler_queue(adreno_dev);
  397: 			adreno_hwsched_log_profiling_info(adreno_dev, rcvd);
  398: 		} else if (MSG_HDR_GET_ID(rcvd[0]) == F2H_MSG_GMU_CNTR_RELEASE) {
  399: 			struct hfi_gmu_cntr_release_cmd *cmd =
  400: 				(struct hfi_gmu_cntr_release_cmd *) rcvd;
  401: 
  402: 			adreno_perfcounter_put(adreno_dev,
  403: 				cmd->group_id, cmd->countable, PERFCOUNTER_FLAG_KERNEL);
  404: 		}
  405: 	}
  406: 	mutex_unlock(&hw_hfi->msgq_mutex);
  407: }
  408: 
  409: static void process_log_block(struct adreno_device *adreno_dev, void *data)
  410: {
  411: 	struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
  412: 	struct hfi_log_block *cmd = data;
  413: 	u32 *log_event = gmu->gmu_log->hostptr;
  414: 	u32 start, end;
  415: 
  416: 	start = cmd->start_index;
  417: 	end = cmd->stop_index;
  418: 
  419: 	log_event += start * 4;
  420: 	while (start != end) {
  421: 		trace_gmu_event(log_event);
  422: 		log_event += 4;
  423: 		start++;
  424: 	}
  425: }
  426: 
  427: static void a6xx_hwsched_process_dbgq(struct adreno_device *adreno_dev, bool limited)
  428: {
--- LINES 470-516 ---
  470: 	 */
  471: 	gmu_core_regread(device, A6XX_GMU_GMU2HOST_INTR_INFO, &status);
  472: 	gmu_core_regwrite(device, A6XX_GMU_GMU2HOST_INTR_CLR, status & hfi->irq_mask);
  473: 
  474: 	/*
  475: 	 * If interrupts are not enabled on the HFI message queue,
  476: 	 * the inline message processing loop will process it,
  477: 	 * else, process it here.
  478: 	 */
  479: 	if (!(hfi->irq_mask & HFI_IRQ_MSGQ_MASK))
  480: 		status &= ~HFI_IRQ_MSGQ_MASK;
  481: 
  482: 	if (status & (HFI_IRQ_MSGQ_MASK | HFI_IRQ_DBGQ_MASK)) {
  483: 		wake_up_interruptible(&hfi->f2h_wq);
  484: 		adreno_scheduler_queue(adreno_dev);
  485: 	}
  486: 	if (status & HFI_IRQ_CM3_FAULT_MASK) {
  487: 		atomic_set(&gmu->cm3_fault, 1);
  488: 
  489: 		/* make sure other CPUs see the update */
  490: 		smp_wmb();
  491: 
  492: 		dev_err_ratelimited(GMU_PDEV_DEV(device),
  493: 				"GMU CM3 fault interrupt received\n");
  494: 
  495: 		adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT);
  496: 	}
  497: 
  498: 	/* Ignore OOB bits */
  499: 	status &= GENMASK(31 - (oob_max - 1), 0);
  500: 
  501: 	if (status & ~hfi->irq_mask)
  502: 		dev_err_ratelimited(GMU_PDEV_DEV(device),
  503: 			"Unhandled HFI interrupts 0x%x\n",
  504: 			status & ~hfi->irq_mask);
  505: 
  506: 	return IRQ_HANDLED;
  507: }
  508: 
  509: #define HFI_IRQ_MSGQ_MASK BIT(0)
  510: 
  511: static int check_ack_failure(struct adreno_device *adreno_dev,
  512: 	struct pending_cmd *ack)
  513: {
  514: 	const struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
  515: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
  516: 	u64 ticks = gpudev->read_alwayson(adreno_dev);
--- LINES 1367-1413 ---
 1367: 	struct hfi_submit_cmd *cmd, struct kgsl_drawobj_cmd *cmdobj)
 1368: {
 1369: 	struct hfi_issue_ib *issue_ib;
 1370: 	struct kgsl_memobj_node *ib;
 1371: 
 1372: 	if (cmdobj->numibs > HWSCHED_MAX_DISPATCH_NUMIBS) {
 1373: 		struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev);
 1374: 		struct kgsl_memdesc *big_ib;
 1375: 
 1376: 		if (test_bit(CMDOBJ_RECURRING_START, &cmdobj->priv))
 1377: 			big_ib = hfi->big_ib_recurring;
 1378: 		else
 1379: 			big_ib = hfi->big_ib;
 1380: 		/*
 1381: 		 * The dispatcher ensures that there is only one big IB inflight
 1382: 		 */
 1383: 		cmd->big_ib_gmu_va = big_ib->gmuaddr;
 1384: 		cmd->flags |= CMDBATCH_INDIRECT;
 1385: 		issue_ib = big_ib->hostptr;
 1386: 	} else {
 1387: 		issue_ib = (struct hfi_issue_ib *)&cmd[1];
 1388: 	}
 1389: 
 1390: 	list_for_each_entry(ib, &cmdobj->cmdlist, node) {
 1391: 		issue_ib->addr = ib->gpuaddr;
 1392: 		issue_ib->size = ib->size;
 1393: 		issue_ib++;
 1394: 	}
 1395: 
 1396: 	cmd->numibs = cmdobj->numibs;
 1397: }
 1398: 
 1399: /* Size in below functions are in unit of dwords */
 1400: static int a6xx_hfi_dispatch_queue_write(struct adreno_device *adreno_dev, uint32_t queue_idx,
 1401: 	uint32_t *msg, u32 size_bytes, struct kgsl_drawobj_cmd *cmdobj,
 1402: 	struct adreno_submit_time *time)
 1403: {
 1404: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
 1405: 	struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
 1406: 	struct hfi_queue_table *tbl = gmu->hfi.hfi_mem->hostptr;
 1407: 	struct hfi_queue_header *hdr = &tbl->qhdr[queue_idx];
 1408: 	uint32_t *queue;
 1409: 	uint32_t i, write, empty_space;
 1410: 	uint32_t size_dwords = size_bytes >> 2;
 1411: 	u32 align_size = ALIGN(size_dwords, SZ_4);
 1412: 	uint32_t id = MSG_HDR_GET_ID(*msg);
 1413: 
--- LINES 1636-1682 ---
 1636: 	/* Star LSR timer for power stats collection */
 1637: 	mod_timer(&hwsched->lsr_timer, jiffies + msecs_to_jiffies(10));
 1638: 	return ret;
 1639: }
 1640: 
 1641: static void trigger_context_unregister_fault(struct adreno_device *adreno_dev,
 1642: 	struct kgsl_context *context)
 1643: {
 1644: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
 1645: 
 1646: 	gmu_core_fault_snapshot(device, GMU_FAULT_CTX_UNREGISTER);
 1647: 
 1648: 	/*
 1649: 	 * Trigger dispatcher based reset and recovery. Invalidate the
 1650: 	 * context so that any un-finished inflight submissions are not
 1651: 	 * replayed after recovery.
 1652: 	 */
 1653: 	adreno_drawctxt_set_guilty(device, context);
 1654: 	adreno_scheduler_fault(adreno_dev, ADRENO_GMU_FAULT);
 1655: }
 1656: 
 1657: static int send_context_unregister_hfi(struct adreno_device *adreno_dev,
 1658: 	struct kgsl_context *context, u32 ts)
 1659: {
 1660: 	struct a6xx_gmu_device *gmu = to_a6xx_gmu(adreno_dev);
 1661: 	struct a6xx_hwsched_hfi *hfi = to_a6xx_hwsched_hfi(adreno_dev);
 1662: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
 1663: 	struct pending_cmd pending_ack;
 1664: 	struct hfi_unregister_ctxt_cmd cmd;
 1665: 	u32 seqnum;
 1666: 	int ret;
 1667: 
 1668: 	/* Only send HFI if device is not in SLUMBER */
 1669: 	if (!context->gmu_registered ||
 1670: 		!test_bit(GMU_PRIV_GPU_STARTED, &gmu->flags))
 1671: 		return 0;
 1672: 
 1673: 	ret = CMD_MSG_HDR(cmd, H2F_MSG_UNREGISTER_CONTEXT);
 1674: 	if (ret)
 1675: 		return ret;
 1676: 
 1677: 	cmd.ctxt_id = context->id,
 1678: 	cmd.ts = ts,
 1679: 
 1680: 	/*
 1681: 	 * Although we know device is powered on, we can still enter SLUMBER
 1682: 	 * because the wait for ack below is done without holding the mutex. So

========== FILE: adreno_a6xx_perfcounter.c ==========
--- LINES 108-154 ---
  108: 	cmds[2] = countable;
  109: 
  110: 	/* submit to highest priority RB always */
  111: 	ret = a6xx_ringbuffer_addcmds(adreno_dev, rb, NULL,
  112: 		F_NOTPROTECTED, cmds, 3, 0, NULL);
  113: 	if (ret)
  114: 		return ret;
  115: 
  116: 	/*
  117: 	 * schedule dispatcher to make sure rb[0] is run, because
  118: 	 * if the current RB is not rb[0] and gpu is idle then
  119: 	 * rb[0] will not get scheduled to run
  120: 	 */
  121: 	if (adreno_dev->cur_rb != rb)
  122: 		adreno_scheduler_queue(adreno_dev);
  123: 
  124: 	/* wait for the above commands submitted to complete */
  125: 	ret = adreno_ringbuffer_waittimestamp(rb, rb->timestamp,
  126: 		ADRENO_IDLE_TIMEOUT);
  127: 
  128: 	if (ret) {
  129: 		/*
  130: 		 * If we were woken up because of cancelling rb events
  131: 		 * either due to soft reset or adreno_stop, ignore the
  132: 		 * error and return 0 here. The perfcounter is already
  133: 		 * set up in software and it will be programmed in
  134: 		 * hardware when we wake up or come up after soft reset,
  135: 		 * by adreno_perfcounter_restore.
  136: 		 */
  137: 		if (ret == -EAGAIN)
  138: 			ret = 0;
  139: 		else
  140: 			dev_err(KGSL_DEVICE(adreno_dev)->dev,
  141: 				     "Perfcounter %s/%u/%u start via commands failed %d\n",
  142: 				     group->name, counter, countable, ret);
  143: 	}
  144: 
  145: 	if (!ret)
  146: 		reg->value = 0;
  147: 
  148: 	return ret;
  149: }
  150: 
  151: static int a6xx_counter_inline_enable(struct adreno_device *adreno_dev,
  152: 	const struct adreno_perfcount_group *group, u32 counter, u32 countable)
  153: {
  154: 	if (!(KGSL_DEVICE(adreno_dev)->state == KGSL_STATE_ACTIVE))

========== FILE: adreno_a6xx_preempt.c ==========
--- LINES 164-210 ---
  164: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
  165: 	unsigned int status;
  166: 
  167: 	/*
  168: 	 * If the power is on check the preemption status one more time - if it
  169: 	 * was successful then just transition to the complete state
  170: 	 */
  171: 	if (kgsl_state_is_awake(device)) {
  172: 		kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, &status);
  173: 
  174: 		if (!(status & 0x1)) {
  175: 			adreno_set_preempt_state(adreno_dev,
  176: 				ADRENO_PREEMPT_COMPLETE);
  177: 
  178: 			adreno_scheduler_queue(adreno_dev);
  179: 			return;
  180: 		}
  181: 	}
  182: 
  183: 	dev_err(device->dev,
  184: 		     "Preemption Fault: cur=%d R/W=0x%x/0x%x, next=%d R/W=0x%x/0x%x\n",
  185: 		     adreno_dev->cur_rb->id,
  186: 		     adreno_get_rptr(adreno_dev->cur_rb),
  187: 		     adreno_dev->cur_rb->wptr,
  188: 		     adreno_dev->next_rb->id,
  189: 		     adreno_get_rptr(adreno_dev->next_rb),
  190: 		     adreno_dev->next_rb->wptr);
  191: 
  192: 	adreno_scheduler_fault(adreno_dev, ADRENO_PREEMPT_FAULT);
  193: }
  194: 
  195: static void _a6xx_preemption_worker(struct work_struct *work)
  196: {
  197: 	struct adreno_preemption *preempt = container_of(work,
  198: 		struct adreno_preemption, work);
  199: 	struct adreno_device *adreno_dev = container_of(preempt,
  200: 		struct adreno_device, preempt);
  201: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
  202: 
  203: 	/* Need to take the mutex to make sure that the power stays on */
  204: 	kgsl_mutex_lock(&device->mutex);
  205: 
  206: 	if (adreno_in_preempt_state(adreno_dev, ADRENO_PREEMPT_FAULTED))
  207: 		_a6xx_preemption_fault(adreno_dev);
  208: 
  209: 	kgsl_mutex_unlock(&device->mutex);
  210: }
--- LINES 429-475 ---
  429: 	kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_CNTL, &status);
  430: 
  431: 	if (status & 0x1) {
  432: 		dev_err(KGSL_DEVICE(adreno_dev)->dev,
  433: 			     "preempt interrupt with non-zero status: %X\n",
  434: 			     status);
  435: 
  436: 		/*
  437: 		 * Under the assumption that this is a race between the
  438: 		 * interrupt and the register, schedule the worker to clean up.
  439: 		 * If the status still hasn't resolved itself by the time we get
  440: 		 * there then we have to assume something bad happened
  441: 		 */
  442: 		adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_COMPLETE);
  443: 		adreno_scheduler_queue(adreno_dev);
  444: 		return;
  445: 	}
  446: 
  447: 	adreno_dev->preempt.count++;
  448: 
  449: 	/*
  450: 	 * We can now safely clear the preemption keepalive bit, allowing
  451: 	 * power collapse to resume its regular activity.
  452: 	 */
  453: 	_power_collapse_set(adreno_dev, false);
  454: 
  455: 	kgsl_delete_timer(&adreno_dev->preempt.timer);
  456: 
  457: 	kgsl_regread(device, A6XX_CP_CONTEXT_SWITCH_LEVEL_STATUS, &status);
  458: 
  459: 	trace_adreno_preempt_done(adreno_dev->cur_rb->id, adreno_dev->next_rb->id,
  460: 		status, 0);
  461: 
  462: 	adreno_dev->prev_rb = adreno_dev->cur_rb;
  463: 	adreno_dev->cur_rb = adreno_dev->next_rb;
  464: 	adreno_dev->next_rb = NULL;
  465: 
  466: 	/* Update the wptr if it changed while preemption was ongoing */
  467: 	_update_wptr(adreno_dev, true, true);
  468: 
  469: 	/* Update the dispatcher timer for the new command queue */
  470: 	mod_timer(&adreno_dev->dispatcher.timer,
  471: 		adreno_dev->cur_rb->dispatch_q.expires);
  472: 
  473: 	adreno_set_preempt_state(adreno_dev, ADRENO_PREEMPT_NONE);
  474: 
  475: 	a6xx_preemption_trigger(adreno_dev, true);

========== FILE: adreno_a6xx_rgmu.c ==========
--- LINES 772-818 ---
  772: 		a6xx_disable_gpu_irq(adreno_dev);
  773: 		adreno_llcc_slice_deactivate(adreno_dev);
  774: 		goto err_oob_clear;
  775: 	}
  776: 
  777: 	/*
  778: 	 * At this point it is safe to assume that we recovered. Setting
  779: 	 * this field allows us to take a new snapshot for the next failure
  780: 	 * if we are prioritizing the first unrecoverable snapshot.
  781: 	 */
  782: 	if (device->snapshot)
  783: 		device->snapshot->recovered = true;
  784: 
  785: 	/* Start the dispatcher */
  786: 	adreno_dispatcher_start(device);
  787: 
  788: 	device->reset_counter++;
  789: 
  790: 	a6xx_rgmu_oob_clear(device, oob_gpu);
  791: 
  792: 	return 0;
  793: 
  794: err_oob_clear:
  795: 	a6xx_rgmu_oob_clear(device, oob_gpu);
  796: 
  797: err:
  798: 	a6xx_rgmu_power_off(adreno_dev);
  799: 
  800: 	return ret;
  801: }
  802: 
  803: static int a6xx_rgmu_boot(struct adreno_device *adreno_dev)
  804: {
  805: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
  806: 	int ret;
  807: 
  808: 	kgsl_pwrctrl_request_state(device, KGSL_STATE_AWARE);
  809: 
  810: 	ret = kgsl_pwrctrl_enable_cx_gdsc(device);
  811: 	if (ret)
  812: 		return ret;
  813: 
  814: 	ret = a6xx_rgmu_enable_clks(adreno_dev);
  815: 	if (ret) {
  816: 		kgsl_pwrctrl_disable_cx_gdsc(device);
  817: 		return ret;
  818: 	}
--- LINES 1102-1148 ---
 1102: 
 1103: no_gx_power:
 1104: 	/* Halt all gx traffic */
 1105: 	kgsl_regwrite(device, A6XX_GBIF_HALT, A6XX_GBIF_CLIENT_HALT_MASK);
 1106: 
 1107: 	adreno_wait_for_halt_ack(device, A6XX_GBIF_HALT_ACK,
 1108: 		A6XX_GBIF_CLIENT_HALT_MASK);
 1109: 
 1110: 	kgsl_pwrctrl_irq(device, false);
 1111: 
 1112: 	a6xx_rgmu_power_off(adreno_dev);
 1113: 
 1114: 	adreno_set_active_ctxs_null(adreno_dev);
 1115: 
 1116: 	adreno_dispatcher_stop(adreno_dev);
 1117: 
 1118: 	adreno_ringbuffer_stop(adreno_dev);
 1119: 
 1120: 	adreno_llcc_slice_deactivate(adreno_dev);
 1121: 
 1122: 	clear_bit(RGMU_PRIV_GPU_STARTED, &rgmu->flags);
 1123: 
 1124: 	kgsl_delete_timer_sync(&device->idle_timer);
 1125: 
 1126: 	kgsl_pwrscale_sleep(device);
 1127: 
 1128: 	kgsl_pwrctrl_set_state(device, KGSL_STATE_SLUMBER);
 1129: 
 1130: 	return ret;
 1131: }
 1132: 
 1133: static int a6xx_rgmu_last_close(struct adreno_device *adreno_dev)
 1134: {
 1135: 	struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev);
 1136: 
 1137: 	if (test_bit(RGMU_PRIV_GPU_STARTED, &rgmu->flags))
 1138: 		return a6xx_power_off(adreno_dev);
 1139: 
 1140: 	return 0;
 1141: }
 1142: 
 1143: int a6xx_rgmu_reset(struct adreno_device *adreno_dev)
 1144: {
 1145: 	struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev);
 1146: 
 1147: 	a6xx_disable_gpu_irq(adreno_dev);
 1148: 
--- LINES 1199-1262 ---
 1199: 	if (ret)
 1200: 		goto err;
 1201: 
 1202: 	if (test_bit(RGMU_PRIV_GPU_STARTED, &rgmu->flags))
 1203: 		a6xx_power_off(adreno_dev);
 1204: 
 1205: 	set_bit(RGMU_PRIV_PM_SUSPEND, &rgmu->flags);
 1206: 
 1207: 	adreno_get_gpu_halt(adreno_dev);
 1208: 
 1209: 	kgsl_pwrctrl_set_state(device, KGSL_STATE_SUSPEND);
 1210: 
 1211: 	return 0;
 1212: err:
 1213: 	adreno_dispatcher_start(device);
 1214: 	return ret;
 1215: }
 1216: 
 1217: static void a6xx_rgmu_pm_resume(struct adreno_device *adreno_dev)
 1218: {
 1219: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
 1220: 	struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev);
 1221: 
 1222: 	if (WARN(!test_bit(RGMU_PRIV_PM_SUSPEND, &rgmu->flags),
 1223: 		"resume invoked without a suspend\n"))
 1224: 		return;
 1225: 
 1226: 	adreno_put_gpu_halt(adreno_dev);
 1227: 
 1228: 	clear_bit(RGMU_PRIV_PM_SUSPEND, &rgmu->flags);
 1229: 
 1230: 	adreno_dispatcher_start(device);
 1231: }
 1232: 
 1233: static const struct gmu_dev_ops a6xx_rgmudev = {
 1234: 	.oob_set = a6xx_rgmu_oob_set,
 1235: 	.oob_clear = a6xx_rgmu_oob_clear,
 1236: 	.ifpc_store = a6xx_rgmu_ifpc_store,
 1237: 	.ifpc_isenabled = a6xx_rgmu_ifpc_isenabled,
 1238: 	.send_nmi = a6xx_rgmu_halt_execution,
 1239: };
 1240: 
 1241: static int a6xx_rgmu_irq_probe(struct kgsl_device *device)
 1242: {
 1243: 	struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(ADRENO_DEVICE(device));
 1244: 	int ret;
 1245: 
 1246: 	/* Try with "oob" irq first. Use Fallback legacy name "kgsl_oob" if not found. */
 1247: 	ret = kgsl_request_irq(rgmu->pdev, "oob", "kgsl_oob", -EINVAL,
 1248: 			a6xx_oob_irq_handler, device);
 1249: 
 1250: 	if (ret < 0)
 1251: 		return ret;
 1252: 
 1253: 	rgmu->oob_interrupt_num  = ret;
 1254: 
 1255: 	/* Try with "gmu" irq first. Use Fallback legacy name "kgsl_rgmu" if not found. */
 1256: 	ret = kgsl_request_irq(rgmu->pdev, "gmu", "kgsl_rgmu", -EINVAL,
 1257: 			a6xx_rgmu_irq_handler, device);
 1258: 
 1259: 	if (ret < 0)
 1260: 		return ret;
 1261: 
 1262: 	rgmu->rgmu_interrupt_num = ret;
--- LINES 1329-1375 ---
 1329: 
 1330: 	a6xx_dev = devm_kzalloc(&pdev->dev, sizeof(*a6xx_dev),
 1331: 			GFP_KERNEL);
 1332: 	if (!a6xx_dev)
 1333: 		return -ENOMEM;
 1334: 
 1335: 	adreno_dev = &a6xx_dev->adreno_dev;
 1336: 
 1337: 	adreno_dev->irq_mask = A6XX_INT_MASK;
 1338: 
 1339: 	ret = a6xx_probe_common(pdev, adreno_dev, chipid, gpucore);
 1340: 	if (ret)
 1341: 		return ret;
 1342: 
 1343: 	ret = adreno_dispatcher_init(adreno_dev);
 1344: 	if (ret)
 1345: 		return ret;
 1346: 
 1347: 	device = KGSL_DEVICE(adreno_dev);
 1348: 
 1349: 	INIT_WORK(&device->idle_check_ws, rgmu_idle_check);
 1350: 
 1351: 	timer_setup(&device->idle_timer, rgmu_idle_timer, 0);
 1352: 
 1353: 	return 0;
 1354: }
 1355: 
 1356: int a6xx_rgmu_add_to_minidump(struct adreno_device *adreno_dev)
 1357: {
 1358: 	struct a6xx_device *a6xx_dev = container_of(adreno_dev,
 1359: 					struct a6xx_device, adreno_dev);
 1360: 
 1361: 	return kgsl_add_va_to_minidump(adreno_dev->dev.dev, KGSL_A6XX_DEVICE,
 1362: 				(void *)(a6xx_dev), sizeof(struct a6xx_device));
 1363: }
 1364: 
 1365: /* Do not access any RGMU registers in RGMU probe function */
 1366: static int a6xx_rgmu_probe(struct kgsl_device *device,
 1367: 		struct platform_device *pdev)
 1368: {
 1369: 	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
 1370: 	struct a6xx_rgmu_device *rgmu = to_a6xx_rgmu(adreno_dev);
 1371: 	int ret;
 1372: 
 1373: 	rgmu->pdev = pdev;
 1374: 
 1375: 	/* Set up RGMU gdscs */

========== FILE: adreno_ringbuffer.c ==========
--- LINES 385-426 ---
  385:  * @msecs: The wait timeout period
  386:  */
  387: int adreno_ringbuffer_waittimestamp(struct adreno_ringbuffer *rb,
  388: 					unsigned int timestamp,
  389: 					unsigned int msecs)
  390: {
  391: 	struct adreno_device *adreno_dev = ADRENO_RB_DEVICE(rb);
  392: 	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
  393: 	int ret;
  394: 	unsigned long wait_time;
  395: 
  396: 	/* check immediately if timeout is 0 */
  397: 	if (msecs == 0)
  398: 		return adreno_ringbuffer_check_timestamp(rb,
  399: 			timestamp, KGSL_TIMESTAMP_RETIRED) ? 0 : -EBUSY;
  400: 
  401: 	ret = kgsl_add_event(device, &rb->events, timestamp,
  402: 		adreno_ringbuffer_wait_callback, NULL);
  403: 	if (ret)
  404: 		return ret;
  405: 
  406: 	kgsl_mutex_unlock(&device->mutex);
  407: 
  408: 	wait_time = msecs_to_jiffies(msecs);
  409: 	if (wait_event_timeout(rb->ts_expire_waitq,
  410: 		!kgsl_event_pending(device, &rb->events, timestamp,
  411: 				adreno_ringbuffer_wait_callback, NULL),
  412: 		wait_time) == 0)
  413: 		ret  = -ETIMEDOUT;
  414: 
  415: 	kgsl_mutex_lock(&device->mutex);
  416: 	/*
  417: 	 * after wake up make sure that expected timestamp has retired
  418: 	 * because the wakeup could have happened due to a cancel event
  419: 	 */
  420: 	if (!ret && !adreno_ringbuffer_check_timestamp(rb,
  421: 		timestamp, KGSL_TIMESTAMP_RETIRED)) {
  422: 		ret = -EAGAIN;
  423: 	}
  424: 
  425: 	return ret;
  426: }

========== FILE: adreno_ringbuffer.h ==========
--- LINES 95-141 ---
   95: struct adreno_ringbuffer {
   96: 	unsigned long flags;
   97: 	struct kgsl_memdesc *buffer_desc;
   98: 	unsigned int _wptr;
   99: 	unsigned int wptr;
  100: 	unsigned int last_wptr;
  101: 	int id;
  102: 	unsigned int fault_detect_ts;
  103: 	unsigned int timestamp;
  104: 	struct kgsl_event_group events;
  105: 	struct adreno_context *drawctxt_active;
  106: 	struct kgsl_memdesc *preemption_desc;
  107: 	struct kgsl_memdesc *secure_preemption_desc;
  108: 	struct kgsl_memdesc *perfcounter_save_restore_desc;
  109: 	struct adreno_dispatcher_drawqueue dispatch_q;
  110: 	wait_queue_head_t ts_expire_waitq;
  111: 	unsigned int wptr_preempt_end;
  112: 	unsigned int gpr11;
  113: 	int preempted_midway;
  114: 	spinlock_t preempt_lock;
  115: 	bool skip_inline_wptr;
  116: 	/**
  117: 	 * @profile_desc: global memory to construct IB1s to do user side
  118: 	 * profiling
  119: 	 */
  120: 	struct kgsl_memdesc *profile_desc;
  121: 	/**
  122: 	 * @profile_index: Pointer to the next "slot" in profile_desc for a user
  123: 	 * profiling IB1.  This allows for PAGE_SIZE / 16 = 256 simultaneous
  124: 	 * commands per ringbuffer with user profiling enabled
  125: 	 * enough.
  126: 	 */
  127: 	u32 profile_index;
  128: };
  129: 
  130: /* Returns the current ringbuffer */
  131: #define ADRENO_CURRENT_RINGBUFFER(a)	((a)->cur_rb)
  132: 
  133: /**
  134:  * adreno_ringbuffer_setup - Do generic set up on a ringbuffer
  135:  * @adreno_dev: Pointer to an Adreno GPU handle
  136:  * @rb: Pointer to the ringbuffer struct to set up
  137:  * @id: Index of the ringbuffer
  138:  *
  139:  * Set up generic memory and other bits of a ringbuffer.
  140:  * Return: 0 on success or negative on error.
  141:  */

========== FILE: kgsl_events.c ==========
--- LINES 77-150 ---
   77: 	if (group == NULL)
   78: 		return;
   79: 
   80: 	context = group->context;
   81: 
   82: 	/*
   83: 	 * Sanity check to be sure that we aren't racing with the context
   84: 	 * getting destroyed
   85: 	 */
   86: 	if (WARN_ON(context != NULL && !_kgsl_context_get(context)))
   87: 		return;
   88: 
   89: 	spin_lock(&group->lock);
   90: 
   91: 	group->readtimestamp(device, group->priv, KGSL_TIMESTAMP_RETIRED,
   92: 		&timestamp);
   93: 
   94: 	if (!flush && !_do_process_group(group->processed, timestamp))
   95: 		goto out;
   96: 
   97: 	list_for_each_entry_safe(event, tmp, &group->events, node) {
   98: 		if (timestamp_cmp(event->timestamp, timestamp) <= 0)
   99: 			signal_event(device, event, KGSL_EVENT_RETIRED);
  100: 		else if (flush)
  101: 			signal_event(device, event, KGSL_EVENT_CANCELLED);
  102: 
  103: 	}
  104: 
  105: 	group->processed = timestamp;
  106: 
  107: out:
  108: 	spin_unlock(&group->lock);
  109: 	kgsl_context_put(context);
  110: }
  111: 
  112: /**
  113:  * kgsl_process_event_group() - Handle all the retired events in a group
  114:  * @device: Pointer to a KGSL device
  115:  * @group: Pointer to a GPU events group to process
  116:  */
  117: 
  118: void kgsl_process_event_group(struct kgsl_device *device,
  119: 		struct kgsl_event_group *group)
  120: {
  121: 	_process_event_group(device, group, false);
  122: }
  123: 
  124: /**
  125:  * kgsl_flush_event_group() - flush all the events in a group by retiring the
  126:  * ones can be retired and cancelling the ones that are pending
  127:  * @device: Pointer to a KGSL device
  128:  * @group: Pointer to a GPU events group to process
  129:  */
  130: void kgsl_flush_event_group(struct kgsl_device *device,
  131: 		struct kgsl_event_group *group)
  132: {
  133: 	_process_event_group(device, group, true);
  134: }
  135: 
  136: /**
  137:  * kgsl_cancel_events_timestamp() - Cancel pending events for a given timestamp
  138:  * @device: Pointer to a KGSL device
  139:  * @group: Ponter to the GPU event group that owns the event
  140:  * @timestamp: Registered expiry timestamp for the event
  141:  */
  142: void kgsl_cancel_events_timestamp(struct kgsl_device *device,
  143: 		struct kgsl_event_group *group, unsigned int timestamp)
  144: {
  145: 	struct kgsl_event *event, *tmp;
  146: 
  147: 	spin_lock(&group->lock);
  148: 
  149: 	list_for_each_entry_safe(event, tmp, &group->events, node) {
  150: 		if (timestamp_cmp(timestamp, event->timestamp) == 0)
--- LINES 274-338 ---
  274: 	event->func = func;
  275: 	event->created = jiffies;
  276: 	event->group = group;
  277: 
  278: 	kthread_init_work(&event->work, _kgsl_event_worker);
  279: 
  280: 	trace_kgsl_register_event(KGSL_CONTEXT_ID(context), timestamp, func);
  281: 
  282: 	spin_lock(&group->lock);
  283: 
  284: 	/*
  285: 	 * Check to see if the requested timestamp has already retired.  If so,
  286: 	 * schedule the callback right away
  287: 	 */
  288: 	group->readtimestamp(device, group->priv, KGSL_TIMESTAMP_RETIRED,
  289: 		&retired);
  290: 
  291: 	if (timestamp_cmp(retired, timestamp) >= 0) {
  292: 		event->result = KGSL_EVENT_RETIRED;
  293: 		kthread_queue_work(device->events_worker, &event->work);
  294: 		spin_unlock(&group->lock);
  295: 		return 0;
  296: 	}
  297: 
  298: 	/* Add the event to the group list */
  299: 	list_add_tail(&event->node, &group->events);
  300: 
  301: 	spin_unlock(&group->lock);
  302: 
  303: 	return 0;
  304: }
  305: 
  306: void kgsl_process_event_groups(struct kgsl_device *device)
  307: {
  308: 	struct kgsl_event_group *group;
  309: 
  310: 	read_lock(&device->event_groups_lock);
  311: 	list_for_each_entry(group, &device->event_groups, group)
  312: 		_process_event_group(device, group, false);
  313: 	read_unlock(&device->event_groups_lock);
  314: }
  315: 
  316: void kgsl_del_event_group(struct kgsl_device *device,
  317: 		struct kgsl_event_group *group)
  318: {
  319: 	/* Check if the group is uninintalized */
  320: 	if (!group->context)
  321: 		return;
  322: 
  323: 	/* Make sure that all the events have been deleted from the list */
  324: 	WARN_ON(!list_empty(&group->events));
  325: 
  326: 	write_lock(&device->event_groups_lock);
  327: 	list_del(&group->group);
  328: 	write_unlock(&device->event_groups_lock);
  329: }
  330: 
  331: void kgsl_add_event_group(struct kgsl_device *device,
  332: 		struct kgsl_event_group *group, struct kgsl_context *context,
  333: 		readtimestamp_func readtimestamp,
  334: 		void *priv, const char *fmt, ...)
  335: {
  336: 	va_list args;
  337: 
  338: 	WARN_ON(readtimestamp == NULL);
--- LINES 357-403 ---
  357: 
  358: static void events_debugfs_print_group(struct seq_file *s,
  359: 		struct kgsl_event_group *group)
  360: {
  361: 	struct kgsl_event *event;
  362: 	unsigned int retired;
  363: 
  364: 	spin_lock(&group->lock);
  365: 
  366: 	seq_printf(s, "%s: last=%d\n", group->name, group->processed);
  367: 
  368: 	list_for_each_entry(event, &group->events, node) {
  369: 
  370: 		group->readtimestamp(event->device, group->priv,
  371: 			KGSL_TIMESTAMP_RETIRED, &retired);
  372: 
  373: 		seq_printf(s, "\t%u:%u age=%lu func=%ps [retired=%u]\n",
  374: 			group->context ? group->context->id :
  375: 						KGSL_MEMSTORE_GLOBAL,
  376: 			event->timestamp, jiffies  - event->created,
  377: 			event->func, retired);
  378: 	}
  379: 	spin_unlock(&group->lock);
  380: }
  381: 
  382: static int events_show(struct seq_file *s, void *unused)
  383: {
  384: 	struct kgsl_device *device = s->private;
  385: 	struct kgsl_event_group *group;
  386: 
  387: 	seq_puts(s, "event groups:\n");
  388: 	seq_puts(s, "--------------\n");
  389: 
  390: 	read_lock(&device->event_groups_lock);
  391: 	list_for_each_entry(group, &device->event_groups, group) {
  392: 		events_debugfs_print_group(s, group);
  393: 		seq_puts(s, "\n");
  394: 	}
  395: 	read_unlock(&device->event_groups_lock);
  396: 
  397: 	return 0;
  398: }
  399: 
  400: DEFINE_SHOW_ATTRIBUTE(events);
  401: 
  402: void kgsl_device_events_remove(struct kgsl_device *device)
  403: {

========== FILE: kgsl_sync.c ==========
--- LINES 547-593 ---
  547: 	if (priv.fence_fd < 0) {
  548: 		dev_crit_ratelimited(device->dev,
  549: 					"Unable to get a file descriptor: %d\n",
  550: 					priv.fence_fd);
  551: 		ret = priv.fence_fd;
  552: 		goto out;
  553: 	}
  554: 
  555: 	/*
  556: 	 * If the timestamp hasn't expired yet create an event to trigger it.
  557: 	 * Otherwise, just signal the fence - there is no reason to go through
  558: 	 * the effort of creating a fence we don't need.
  559: 	 */
  560: 
  561: 	kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED, &cur);
  562: 
  563: 	retired = timestamp_cmp(cur, timestamp) >= 0;
  564: 
  565: 	if (retired) {
  566: 		ret = 0;
  567: 		kgsl_sync_timeline_signal(context->ktimeline, cur);
  568: 	} else {
  569: 		ret = _add_fence_event(device, context, timestamp);
  570: 		if (ret)
  571: 			goto out;
  572: 	}
  573: 
  574: 	if (copy_to_user(data, &priv, sizeof(priv))) {
  575: 		ret = -EFAULT;
  576: 		goto out;
  577: 	}
  578: 
  579: 	if (!retired)
  580: 		device->ftbl->create_hw_fence(device, kfence);
  581: 
  582: 	fd_install(priv.fence_fd, kfence->sync_file->file);
  583: 
  584: out:
  585: 	kgsl_context_put(context);
  586: 	if (ret) {
  587: 		if (priv.fence_fd >= 0)
  588: 			put_unused_fd(priv.fence_fd);
  589: 
  590: 		if (kfence) {
  591: 			kgsl_sync_cancel(kfence);
  592: 			/*
  593: 			 * Put the refcount of sync file. This will release
--- LINES 616-665 ---
  616: 	if (!kref_get_unless_zero(&ktimeline->kref))
  617: 		return;
  618: 	if (!ktimeline->device)
  619: 		goto put_timeline;
  620: 
  621: 	spin_lock_irqsave(&ktimeline->lock, flags);
  622: 	ret = _kgsl_context_get(ktimeline->context);
  623: 	context = ret ? ktimeline->context : NULL;
  624: 	spin_unlock_irqrestore(&ktimeline->lock, flags);
  625: 
  626: 	/* Get the last signaled timestamp if the context is not valid */
  627: 	timestamp_queued = ktimeline->last_timestamp;
  628: 	timestamp_retired = timestamp_queued;
  629: 	if (context) {
  630: 		kgsl_readtimestamp(ktimeline->device, context,
  631: 			KGSL_TIMESTAMP_RETIRED, &timestamp_retired);
  632: 
  633: 		kgsl_readtimestamp(ktimeline->device, context,
  634: 			KGSL_TIMESTAMP_QUEUED, &timestamp_queued);
  635: 
  636: 		kgsl_context_put(context);
  637: 	}
  638: 
  639: 	snprintf(str, size, "%u queued:%u retired:%u",
  640: 		ktimeline->last_timestamp,
  641: 		timestamp_queued, timestamp_retired);
  642: 
  643: put_timeline:
  644: 	kgsl_sync_timeline_put(ktimeline);
  645: }
  646: 
  647: static void kgsl_sync_fence_value_str(struct dma_fence *fence,
  648: 					char *str, int size)
  649: {
  650: 	struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)fence;
  651: 
  652: 	snprintf(str, size, "%u", kfence->timestamp);
  653: }
  654: 
  655: static const char *kgsl_sync_fence_driver_name(struct dma_fence *fence)
  656: {
  657: 	return "kgsl-timeline";
  658: }
  659: 
  660: static const char *kgsl_sync_timeline_name(struct dma_fence *fence)
  661: {
  662: 	struct kgsl_sync_fence *kfence = (struct kgsl_sync_fence *)fence;
  663: 	struct kgsl_sync_timeline *ktimeline = kfence->parent;
  664: 
  665: 	return ktimeline->name;

Embed this paste

Install this app

  1. Tap the Share button
  2. Scroll down and tap "Add to Home Screen"
  3. Tap "Add" in the top right

Please confirm