Cairnbin

A618 SOURCE PART_3_BLOCK_07

text 5 views Created: November 26, 2026 at 14:55:39 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
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136

	int reset_counter; /* Track how many GPU core resets have occurred */

	struct kthread_worker *events_worker;



	/* Number of active contexts seen globally for this device */

	int active_context_count;

	struct kobject gpu_sysfs_kobj;

	unsigned int l3_freq[3];

	unsigned int num_l3_pwrlevels;

	/* store current L3 vote to determine if we should change our vote */

	unsigned int cur_l3_pwrlevel;

	/** @globals: List of global memory objects */

	struct list_head globals;

	/** @globlal_map: bitmap for global memory allocations */

	unsigned long *global_map;

	/* @qdss_desc: Memory descriptor for the QDSS region if applicable */

	struct kgsl_memdesc *qdss_desc;

	/* @qtimer_desc: Memory descriptor for the QDSS region if applicable */

	struct kgsl_memdesc *qtimer_desc;

	/** @event_groups: List of event groups for this device */

	struct list_head event_groups;

	/** @event_groups_lock: A R/W lock for the events group list */

	rwlock_t event_groups_lock;

	/** @speed_bin: Speed bin for the GPU device if applicable */

	u32 speed_bin;

	/** @debug_bus_bin: Debug bus bin for the GPU device if applicable */

	u32 debug_bus_bin;

	/** @soc_code: Identifier containing product and feature code */

	u32 soc_code;

	/** @gmu_fault: Set when a gmu or rgmu fault is encountered */

	bool gmu_fault;

	/** @regmap: GPU register map */

	struct kgsl_regmap regmap;

	/** @timelines: Iterator for assigning IDs to timelines */

	struct idr timelines;

	/** @timelines_lock: Spinlock to protect the timelines idr */

	spinlock_t timelines_lock;

	/** @fence_trace_array: A local trace array for fence debugging */

	struct trace_array *fence_trace_array;

	/** @l3_vote: Enable/Disable l3 voting */

	bool l3_vote;

	/** @pdev_loaded: Flag to test if platform driver is probed */

	bool pdev_loaded;

	/** @nh: Pointer to head of the SRCU notifier chain */

	struct srcu_notifier_head nh;

	/** @bcl_data_kobj: Kobj for bcl_data sysfs node */

	struct kobject bcl_data_kobj;

	/** @work_period_timer: Timer to capture application GPU work stats */

	struct timer_list work_period_timer;

	/** @work_period_lock: Lock to protect application GPU work periods */

	spinlock_t work_period_lock;

	/** @work_period_ws: Work struct to emulate application GPU work events */

	struct work_struct work_period_ws;

	/** @flags: Flags for gpu_period stats */

	unsigned long flags;

	struct {

		u64 begin;

		u64 end;

	} gpu_period;

	/** @idle_jiffies: Latest idle jiffies */

	unsigned long idle_jiffies;

	/** @dump_all_ibs: Whether to dump all ibs in snapshot */

	bool dump_all_ibs;

	/** @freq_limiter_irq_clear: reset controller to clear freq limiter irq */

	struct reset_control *freq_limiter_irq_clear;

	/** @freq_limiter_intr_num: The interrupt number for freq limiter */

	int freq_limiter_intr_num;

	/** @cx_host_irq_num: Interrupt number for cx_host_irq */

	int cx_host_irq_num;

	/**

	 * @max_syncobj_hw_fence_count: Maximum number of hardware fences that are allowed in a sync

	 * object

	 */

	u32 max_syncobj_hw_fence_count;

	/** @file_mutex: Mutex to protect device open and close operations */

	struct mutex file_mutex;

	/** @host_based_dcvs: Set when KGSL is in charge of DCVS */

	bool host_based_dcvs;

};



#define KGSL_MMU_DEVICE(_mmu) \

	container_of((_mmu), struct kgsl_device, mmu)



/**

 * enum bits for struct kgsl_context.priv

 * @KGSL_CONTEXT_PRIV_SUBMITTED - The context has submitted commands to gpu.

 * @KGSL_CONTEXT_PRIV_DETACHED  - The context has been destroyed by userspace

 *	and is no longer using the gpu.

 * @KGSL_CONTEXT_PRIV_INVALID - The context has been destroyed by the kernel

 *	because it caused a GPU fault.

 * @KGSL_CONTEXT_PRIV_PAGEFAULT - The context has caused a page fault.

 * @KGSL_CONTEXT_PRIV_DEVICE_SPECIFIC - this value and higher values are

 *	reserved for devices specific use.

 * @KGSL_CONTEXT_PRIV_INVALID_DRAIN_HW_FENCE - this context got invalidated

 * and needs its hardware fences drained after device reset

 */

enum kgsl_context_priv {

	KGSL_CONTEXT_PRIV_SUBMITTED = 0,

	KGSL_CONTEXT_PRIV_DETACHED,

	KGSL_CONTEXT_PRIV_INVALID,

	KGSL_CONTEXT_PRIV_PAGEFAULT,

	KGSL_CONTEXT_PRIV_DEVICE_SPECIFIC = 16,

	KGSL_CONTEXT_PRIV_INVALID_DRAIN_HW_FENCE,

};



struct kgsl_process_private;



#define KGSL_MAX_FAULT_ENTRIES 40



/* Maintain faults observed within threshold time (in milliseconds) */

#define KGSL_MAX_FAULT_TIME_THRESHOLD 5000



/**

 * struct kgsl_fault_node - GPU fault descriptor

 * @node: List node for list of faults

 * @type: Type of fault

 * @priv: Pointer to type specific fault

 * @time: Time when fault was observed

 */

struct kgsl_fault_node {

	struct list_head node;

	u32 type;

	void *priv;

	ktime_t time;

};



/**

 * struct kgsl_context - The context fields that are valid for a user defined

 * context

 * @refcount: kref object for reference counting the context

 * @id: integer identifier for the context

 * @priority; The context's priority to submit commands to GPU

 * @tid: task that created this context.

 * @dev_priv: pointer to the owning device instance

 * @proc_priv: pointer to process private, the process that allocated the

 * context

 * @priv: in-kernel context flags, use KGSL_CONTEXT_* values

 * @reset_status: status indication whether a gpu reset occurred and whether

 * this context was responsible for causing it

 * @timeline: sync timeline used to create fences that can be signaled when a

 * sync_pt timestamp expires

 * @events: A kgsl_event_group for this context - contains the list of GPU

 * events

 * @flags: flags from userspace controlling the behavior of this context

 * @pwr_constraint: power constraint from userspace for this context

 * @fault_count: number of times gpu hanged in last _context_throttle_time ms

 * @fault_time: time of the first gpu hang in last _context_throttle_time ms

 * @user_ctxt_record: memory descriptor used by CP to save/restore VPC data

 * across preemption

 * @total_fault_count: number of times gpu faulted in this context

 * @last_faulted_cmd_ts: last faulted command batch timestamp

 * @gmu_registered: whether context is registered with gmu or not

 */

struct kgsl_context {

	struct kref refcount;

	uint32_t id;

	uint32_t priority;

	pid_t tid;

	struct kgsl_device_private *dev_priv;

	struct kgsl_process_private *proc_priv;

	unsigned long priv;

	struct kgsl_device *device;

	unsigned int reset_status;

	struct kgsl_sync_timeline *ktimeline;

	struct kgsl_event_group events;

	unsigned int flags;

	struct kgsl_pwr_constraint pwr_constraint;

	struct kgsl_pwr_constraint l3_pwr_constraint;

	unsigned int fault_count;

	ktime_t fault_time;

	struct kgsl_mem_entry *user_ctxt_record;

	unsigned int total_fault_count;

	unsigned int last_faulted_cmd_ts;

	bool gmu_registered;

	/**

	 * @gmu_dispatch_queue: dispatch queue id to which this context will be

	 * submitted

	 */

	u32 gmu_dispatch_queue;

	/** @faults: List of @kgsl_fault_node to store fault information */

	struct list_head faults;

	/** @fault_lock: Mutex to protect faults */

	struct mutex fault_lock;

	/** @deferred_destroy_ws: Work struct used to destroy context in a deferred manner */

	struct work_struct deferred_destroy_ws;

};



#define _context_comm(_c) \

	(((_c) && (_c)->proc_priv) ? (_c)->proc_priv->comm : "unknown")



/*

 * Print log messages with the context process name/pid:

 * [...] kgsl kgsl-3d0: kgsl-api-test[22182]:

 */



#define pr_context(_d, _c, fmt, args...) \

		dev_err((_d)->dev, "%s[%d]: " fmt, \

		_context_comm((_c)), \

		pid_nr((_c)->proc_priv->pid), ##args)



/**

 * struct kgsl_dcvs_profile_private - Private structure for a KGSL DCVS profile

 * @gmu_registered: True if DCVS profile is registered with GMU

 * @user_profile_registered: True if user DCVS IOCTL profile is received

 * @md: Memory descriptor for the DCVS profile region

 * @profile_mutex: Mutex lock to protect kgsl_dcvs_profile_private

 */

struct kgsl_dcvs_profile_private {

	bool gmu_registered;

	bool user_profile_registered;

	struct kgsl_memdesc md;

	struct mutex profile_mutex;

};



/**

 * struct kgsl_process_private -  Private structure for a KGSL process (across

 * all devices)

 * @priv: Internal flags, use KGSL_PROCESS_* values

 * @pid: Identification structure for the task owner of the process

 * @comm: task name of the process

 * @mm: mm_struct of the opening process, used to prevent other mm mmap

 * @mem_lock: Spinlock to protect the process memory lists

 * @refcount: kref object for reference counting the process

 * @idr: Iterator for assigning IDs to memory allocations

 * @pagetable: Pointer to the pagetable owned by this process

 * @kobj: Pointer to a kobj for the sysfs directory for this process

 * @debug_root: Pointer to the debugfs root for this process

 * @stats: Memory allocation statistics for this process

 * @gpumem_mapped: KGSL memory mapped in the process address space

 * @syncsource_idr: sync sources created by this process

 * @syncsource_lock: Spinlock to protect the syncsource idr

 * @fd_count: Counter for the number of FDs for this process

 * @ctxt_count: Count for the number of contexts for this process

 * @ctxt_count_lock: Spinlock to protect ctxt_count

 * @frame_count: Count for the number of frames processed

 */

struct kgsl_process_private {

	unsigned long priv;

	struct pid *pid;

	char comm[TASK_COMM_LEN];

	struct mm_struct *mm;

	spinlock_t mem_lock;

	struct kref refcount;

	struct idr mem_idr;

	struct kgsl_pagetable *pagetable;

	struct list_head list;

	struct list_head reclaim_list;

	struct kobject kobj;

	struct dentry *debug_root;

	struct {

		atomic64_t cur;

		uint64_t max;

	} stats[KGSL_MEM_ENTRY_MAX];

	atomic64_t gpumem_mapped;

	struct idr syncsource_idr;

	spinlock_t syncsource_lock;

	int fd_count;

	atomic_t ctxt_count;

	spinlock_t ctxt_count_lock;

	atomic64_t frame_count;

	/**

	 * @state: state consisting KGSL_PROC_STATE and KGSL_PROC_PINNED_STATE

	 */

	unsigned long state;

	/**

	 * @unpinned_page_count: The number of pages unpinned for reclaim

	 */

	atomic_t unpinned_page_count;

	/**

	 * @fg_work: Work struct to schedule foreground work

	 */

	struct work_struct fg_work;

	/**

	 * @reclaim_lock: Mutex lock to protect KGSL_PROC_PINNED_STATE

	 */

	struct mutex reclaim_lock;

	/** @period: Stats for GPU utilization */

	struct gpu_work_period *period;

	/**

	 * @cmd_count: The number of cmds that are active for the process

	 */

	atomic_t cmd_count;

	/**

	 * @kobj_memtype: Pointer to a kobj for memtype sysfs directory for this

	 * process

	 */

	struct kobject kobj_memtype;

	/**

	 * @private_mutex: Mutex lock to protect kgsl_process_private

	 */

	struct mutex private_mutex;

	/**

	 * @cmdline: Cmdline string of the process

	 */

	char *cmdline;

	/** @fault_count: Count of GPU faults from this process */

	u32 fault_count;

	/** @pf_count: Total count of pagefaults from this process */

	u32 pf_count;

	/** @pf_type_counts: Count of pagefaults of each type from this process */

	u32 pf_type_counts[KGSL_IOMMU_PAGEFAULT_TYPES];

	/** @profile: Container for the DCVS profile */

	struct kgsl_dcvs_profile_private profile;

};



struct kgsl_device_private {

	struct kgsl_device *device;

	struct kgsl_process_private *process_priv;

};



/**

 * struct kgsl_snapshot - details for a specific snapshot instance

 * @ib1base: Active IB1 base address at the time of fault

 * @ib2base: Active IB2 base address at the time of fault

 * @ib3base: Active IB3 base address at the time of fault

 * @ib1size: Number of DWORDS pending in IB1 at the time of fault

 * @ib2size: Number of DWORDS pending in IB2 at the time of fault

 * @ib3size: Number of DWORDS pending in IB3 at the time of fault

 * @ib1dumped: Active IB1 dump status to sansphot binary

 * @ib2dumped: Active IB2 dump status to sansphot binary

 * @start: Pointer to the start of the static snapshot region

 * @size: Size of the current snapshot instance

 * @ptr: Pointer to the next block of memory to write to during snapshotting

 * @remain: Bytes left in the snapshot region

 * @timestamp: Timestamp of the snapshot instance (in seconds since boot)

 * @mempool: Pointer to the memory pool for storing memory objects

 * @mempool_size: Size of the memory pool

 * @obj_list: List of frozen GPU buffers that are waiting to be dumped.

 * @cp_list: List of IB's to be dumped.

 * @work: worker to dump the frozen memory

 * @dump_gate: completion gate signaled by worker when it is finished.

 * @process: the process that caused the hang, if known.

 * @sysfs_read: Count of current reads via sysfs

 * @first_read: True until the snapshot read is started

 * @recovered: True if GPU was recovered after previous snapshot

 */

struct kgsl_snapshot {

	u64 ib1base;

	u64 ib2base;

	u64 ib3base;

	u32 ib1size;

	u32 ib2size;

	u32 ib3size;

	bool ib1dumped;

	bool ib2dumped;

	u64 ib1base_lpac;

	u64 ib2base_lpac;

	u32 ib1size_lpac;

	u32 ib2size_lpac;

	bool ib1dumped_lpac;

	bool ib2dumped_lpac;

	u8 *start;

	size_t size;

	u8 *ptr;

	size_t remain;

	unsigned long timestamp;

	u8 *mempool;

	size_t mempool_size;

	struct list_head obj_list;

	struct list_head cp_list;

	struct work_struct work;

	struct completion dump_gate;

	struct kgsl_process_private *process;

	struct kgsl_process_private *process_lpac;

	unsigned int sysfs_read;

	bool first_read;

	bool recovered;

	struct kgsl_device *device;

};



/**

 * struct kgsl_snapshot_object  - GPU memory in the snapshot

 * @gpuaddr: The GPU address identified during snapshot

 * @size: The buffer size identified during snapshot

 * @offset: offset from start of the allocated kgsl_mem_entry

 * @type: SNAPSHOT_OBJ_TYPE_* identifier.

 * @entry: the reference counted memory entry for this buffer

 * @node: node for kgsl_snapshot.obj_list

 */

struct kgsl_snapshot_object {

	uint64_t gpuaddr;

	uint64_t size;

	uint64_t offset;

	int type;

	struct kgsl_mem_entry *entry;

	struct list_head node;

};



struct kgsl_device *kgsl_get_device(int dev_idx);



static inline void kgsl_regread(struct kgsl_device *device,

				unsigned int offsetwords,

				unsigned int *value)

{

	*value = kgsl_regmap_read(&device->regmap, offsetwords);

}



static inline void kgsl_regread64(struct kgsl_device *device,

				  u32 offsetwords_lo, u32 offsetwords_hi,

				  u64 *value)

{

	u32 val_lo = 0, val_hi = 0;



	val_lo = kgsl_regmap_read(&device->regmap, offsetwords_lo);

	val_hi = kgsl_regmap_read(&device->regmap, offsetwords_hi);



	*value = (((u64)val_hi << 32) | val_lo);

}



static inline void kgsl_regwrite(struct kgsl_device *device,

				 unsigned int offsetwords,

				 unsigned int value)

{

	kgsl_regmap_write(&device->regmap, value, offsetwords);

}



static inline void kgsl_regrmw(struct kgsl_device *device,

		unsigned int offsetwords,

		unsigned int mask, unsigned int bits)

{

	kgsl_regmap_rmw(&device->regmap, offsetwords, mask, bits);

}



static inline bool kgsl_state_is_awake(struct kgsl_device *device)

{

	return (device->state == KGSL_STATE_ACTIVE ||

		device->state == KGSL_STATE_AWARE);

}



/**

 * kgsl_start_idle_timer - Start the idle timer

 * @device: A KGSL device handle

 *

 * Start the idle timer to expire in 'interval_timeout' milliseconds

 */

static inline void kgsl_start_idle_timer(struct kgsl_device *device)

{

	device->idle_jiffies = jiffies +

		msecs_to_jiffies(atomic64_read(&device->pwrctrl.interval_timeout));

	mod_timer(&device->idle_timer, device->idle_jiffies);

}



int kgsl_readtimestamp(struct kgsl_device *device, void *priv,

		enum kgsl_timestamp_type type, unsigned int *timestamp);



bool kgsl_check_timestamp(struct kgsl_device *device,

		struct kgsl_context *context, unsigned int timestamp);



int kgsl_device_platform_probe(struct kgsl_device *device);



void kgsl_device_platform_remove(struct kgsl_device *device);



const char *kgsl_pwrstate_to_str(unsigned int state);



/**

 * kgsl_device_snapshot_probe - add resources for the device GPU snapshot

 * @device: The device to initialize

 * @size: The size of the static region to allocate

 *

 * Allocate memory for a GPU snapshot for the specified device,

 * and create the sysfs files to manage it

 */

void kgsl_device_snapshot_probe(struct kgsl_device *device, u32 size);



void kgsl_device_snapshot(struct kgsl_device *device,

			struct kgsl_context *context, struct kgsl_context *context_lpac,

			bool gmu_fault);

void kgsl_device_snapshot_close(struct kgsl_device *device);



void kgsl_events_init(void);

void kgsl_events_exit(void);



/**

 * kgsl_device_events_probe - Set up events for the KGSL device

 * @device: A KGSL GPU device handle

 *

 * Set up the list and lock for GPU events for this device

 */

void kgsl_device_events_probe(struct kgsl_device *device);



/**

 * kgsl_device_events_remove - Remove all event groups from the KGSL device

 * @device: A KGSL GPU device handle

 *

 * Remove all of the GPU event groups from the device and warn if any of them

 * still have events pending

 */

void kgsl_device_events_remove(struct kgsl_device *device);



void kgsl_context_detach(struct kgsl_context *context);



/**

 * kgsl_del_event_group - Remove a GPU event group from a device

 * @device: A KGSL GPU device handle

 * @group: Event group to be removed

 *

 * Remove the specified group from the list of event groups on @device.

 */

void kgsl_del_event_group(struct kgsl_device *device,

		struct kgsl_event_group *group);



/**

 * kgsl_add_event_group - Add a new GPU event group

 * @device: A KGSL GPU device handle

 * @group: Pointer to the new group to add to the list

 * @context: Context that owns the group (or NULL for global)

 * @readtimestamp: Function pointer to the readtimestamp function to call when

 * processing events

 * @priv: Priv member to pass to the readtimestamp function

 * @fmt: The format string to use to build the event name

 * @...: Arguments for the format string

 */

void kgsl_add_event_group(struct kgsl_device *device,

		struct kgsl_event_group *group,

		struct kgsl_context *context, readtimestamp_func readtimestamp,

		void *priv, const char *fmt, ...);



void kgsl_cancel_events_timestamp(struct kgsl_device *device,

		struct kgsl_event_group *group, unsigned int timestamp);

void kgsl_cancel_events(struct kgsl_device *device,

		struct kgsl_event_group *group);

void kgsl_cancel_event(struct kgsl_device *device,

		struct kgsl_event_group *group, unsigned int timestamp,

		kgsl_event_func func, void *priv);

bool kgsl_event_pending(struct kgsl_device *device,

		struct kgsl_event_group *group, unsigned int timestamp,

		kgsl_event_func func, void *priv);

int kgsl_add_event(struct kgsl_device *device, struct kgsl_event_group *group,

		unsigned int timestamp, kgsl_event_func func, void *priv);

void kgsl_process_event_group(struct kgsl_device *device,

	struct kgsl_event_group *group);

void kgsl_flush_event_group(struct kgsl_device *device,

		struct kgsl_event_group *group);

void kgsl_process_event_groups(struct kgsl_device *device);



void kgsl_context_destroy(struct kref *kref);



int kgsl_context_init(struct kgsl_device_private *dev_priv,

		struct kgsl_context *context);



void kgsl_context_dump(struct kgsl_context *context);



int kgsl_memfree_find_entry(pid_t ptname, uint64_t *gpuaddr,

	uint64_t *size, uint64_t *flags, pid_t *pid);



long kgsl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);



long kgsl_ioctl_copy_in(unsigned int kernel_cmd, unsigned int user_cmd,

		unsigned long arg, unsigned char *ptr);



long kgsl_ioctl_copy_out(unsigned int kernel_cmd, unsigned int user_cmd,

		unsigned long arg, unsigned char *ptr);



/**

 * kgsl_context_type - Return a symbolic string for the context type

 * @type: Context type

 *

 * Return: Symbolic string representing the context type

 */

const char *kgsl_context_type(int type);



/**

 * kgsl_context_put() - Release context reference count

 * @context: Pointer to the KGSL context to be released

 *

 * Reduce the reference count on a KGSL context and destroy it if it is no

 * longer needed

 */

static inline void

kgsl_context_put(struct kgsl_context *context)

{

	if (context)

		kref_put(&context->refcount, kgsl_context_destroy);

}



/*

 * kgsl_context_put_deferred() - Puts refcount and triggers deferred

 * context destroy when refcount is the last refcount.

 * @context: context to put

 *

 * Use this to put a context from within atomic context

 */

static inline void kgsl_context_put_deferred(struct kgsl_context *context)

{

	if (context)

		kref_put(&context->refcount, kgsl_context_destroy_deferred);

}



/**

 * kgsl_context_detached() - check if a context is detached

 * @context: the context

 *

 * Check if a context has been destroyed by userspace and is only waiting

 * for reference counts to go away. This check is used to weed out

 * contexts that shouldn't use the gpu so NULL is considered detached.

 */

static inline bool kgsl_context_detached(struct kgsl_context *context)

{

	return (context == NULL || test_bit(KGSL_CONTEXT_PRIV_DETACHED,

						&context->priv));

}



/**

 * kgsl_context_invalid() - check if a context is invalid

 * @context: the context

 *

 * Check if a context has been invalidated by the kernel and may no

 * longer use the GPU.

 */

static inline bool kgsl_context_invalid(struct kgsl_context *context)

{

	return (context == NULL || test_bit(KGSL_CONTEXT_PRIV_INVALID,

						&context->priv));

}



/** kgsl_context_is_bad - Check if a context is detached or invalid

 * @context: Pointer to a KGSL context handle

 *

 * Return: True if the context has been detached or is invalid

 */

static inline bool kgsl_context_is_bad(struct kgsl_context *context)

{

	return (kgsl_context_detached(context) ||

		kgsl_context_invalid(context));

}



/** kgsl_check_context_state - Check if a context is bad or invalid

 *  @context: Pointer to a KGSL context handle

 *

 * Return: True if the context has been marked bad or invalid

 */

static inline int kgsl_check_context_state(struct kgsl_context *context)

{

	if (kgsl_context_invalid(context))

		return -EDEADLK;



	if (kgsl_context_detached(context))

		return -ENOENT;



	return 0;

}



/**

 * kgsl_context_get() - get a pointer to a KGSL context

 * @device: Pointer to the KGSL device that owns the context

 * @id: Context ID

 *

 * Find the context associated with the given ID number, increase the reference

 * count on it and return it.  The caller must make sure that this call is

 * paired with a kgsl_context_put.  This function is for internal use because it

 * doesn't validate the ownership of the context with the calling process - use

 * kgsl_context_get_owner for that

 */

static inline struct kgsl_context *kgsl_context_get(struct kgsl_device *device,

		uint32_t id)

{

	int result = 0;

	struct kgsl_context *context = NULL;



	read_lock(&device->context_lock);



	context = idr_find(&device->context_idr, id);



	/* Don't return a context that has been detached */

	if (kgsl_context_detached(context))

		context = NULL;

	else

		result = kref_get_unless_zero(&context->refcount);



	read_unlock(&device->context_lock);



	if (!result)

		return NULL;

	return context;

}



/**

 * _kgsl_context_get() - lightweight function to just increment the ref count

 * @context: Pointer to the KGSL context

 *

 * Get a reference to the specified KGSL context structure. This is a

 * lightweight way to just increase the refcount on a known context rather than

 * walking through kgsl_context_get and searching the iterator

 */

static inline int _kgsl_context_get(struct kgsl_context *context)

{

	int ret = 0;



	if (context)

		ret = kref_get_unless_zero(&context->refcount);



	return ret;

}



/**

 * kgsl_context_get_owner() - get a pointer to a KGSL context in a specific

 * process

 * @dev_priv: Pointer to the process struct

 * @id: Context ID to return

 *

 * Find the context associated with the given ID number, increase the reference

 * count on it and return it.  The caller must make sure that this call is

 * paired with a kgsl_context_put. This function validates that the context id

 * given is owned by the dev_priv instancet that is passed in.  See

 * kgsl_context_get for the internal version that doesn't do the check

 */

static inline struct kgsl_context *kgsl_context_get_owner(

		struct kgsl_device_private *dev_priv, uint32_t id)

{

	struct kgsl_context *context;



	context = kgsl_context_get(dev_priv->device, id);



	/* Verify that the context belongs to current calling fd. */

	if (context != NULL && context->dev_priv != dev_priv) {

		kgsl_context_put(context);

		return NULL;

	}



	return context;

}



/**

 * kgsl_process_private_get() - increment the refcount on a

 * kgsl_process_private struct

 * @process: Pointer to the KGSL process_private

 *

 * Returns 0 if the structure is invalid and a reference count could not be

 * obtained, nonzero otherwise.

 */

static inline int kgsl_process_private_get(struct kgsl_process_private *process)

{

	if (process != NULL)

		return kref_get_unless_zero(&process->refcount);

	return 0;

}



void kgsl_process_private_put(struct kgsl_process_private *private);





struct kgsl_process_private *kgsl_process_private_find(pid_t pid);



/*

 * A helper macro to print out "not enough memory functions" - this

 * makes it easy to standardize the messages as well as cut down on

 * the number of strings in the binary

 */

#define SNAPSHOT_ERR_NOMEM(_d, _s) \

	dev_err_ratelimited((_d)->dev, \

	"snapshot: not enough snapshot memory for section %s\n", (_s))



/**

 * struct kgsl_snapshot_registers - list of registers to snapshot

 * @regs: Pointer to an array of register ranges

 * @count: Number of entries in the array

 */

struct kgsl_snapshot_registers {

	const unsigned int *regs;

	unsigned int count;

};



size_t kgsl_snapshot_dump_registers(struct kgsl_device *device, u8 *buf,

		size_t remain, void *priv);



void kgsl_snapshot_indexed_registers(struct kgsl_device *device,

	struct kgsl_snapshot *snapshot, unsigned int index,

	unsigned int data, unsigned int start, unsigned int count);



/**

 * kgsl_snapshot_indexed_registers_v2 - Add a set of indexed registers to the

 * snapshot

 * @device: Pointer to the KGSL device being snapshotted

 * @snapshot: Snapshot instance

 * @index: Offset for the index register

 * @data: Offset for the data register

 * @start: Index to start reading

 * @count: Number of entries to read

 * @pipe_id: Pipe ID to be dumped

 * @slice_id: Slice ID to be dumped

 *

 * Dump the values from an indexed register group into the snapshot

 */

void kgsl_snapshot_indexed_registers_v2(struct kgsl_device *device,

	struct kgsl_snapshot *snapshot, u32 index, u32 data,

	u32 start, u32 count, u32 pipe_id, u32 slice_id);



int kgsl_snapshot_get_object(struct kgsl_snapshot *snapshot,

	struct kgsl_process_private *process, uint64_t gpuaddr,

	uint64_t size, unsigned int type);



int kgsl_snapshot_have_object(struct kgsl_snapshot *snapshot,

	struct kgsl_process_private *process,

	uint64_t gpuaddr, uint64_t size);



struct adreno_ib_object_list;



int kgsl_snapshot_add_ib_obj_list(struct kgsl_snapshot *snapshot,

	struct adreno_ib_object_list *ib_obj_list);



void kgsl_snapshot_add_section(struct kgsl_device *device, u16 id,

	struct kgsl_snapshot *snapshot,

	size_t (*func)(struct kgsl_device *, u8 *, size_t, void *),

	void *priv);



/**

 * kgsl_of_property_read_ddrtype - Get property from devicetree based on

 * the type of DDR.

 * @node: Devicetree node

 * @base: prefix string of the property

 * @ptr:  Pointer to store the value of the property

 *

 * First look up the devicetree property based on the prefix string and DDR

 * type. If property is not specified per DDR type, then look for the property

 * based on prefix string only.

 *

 * Return: 0 on success or error code on failure.

 */

int kgsl_of_property_read_ddrtype(struct device_node *node, const char *base,

		u32 *ptr);



/**

 * kgsl_query_property_list - Get a list of valid properties

 * @device: A KGSL device handle

 * @list: Pointer to a list of u32s

 * @count: Number of items in @list

 *

 * Populate a list with the IDs for supported properties. If @list is NULL,

 * just return the number of properties available, otherwise fill up to @count

 * items in the list with property identifiers.

 *

 * Returns the number of total properties if @list is NULL or the number of

 * properties copied to @list.

 */

int kgsl_query_property_list(struct kgsl_device *device, u32 *list, u32 count);



static inline bool kgsl_mmu_has_feature(struct kgsl_device *device,

		enum kgsl_mmu_feature feature)

{

	return test_bit(feature, &device->mmu.features);

}



static inline void kgsl_mmu_set_feature(struct kgsl_device *device,

	      enum kgsl_mmu_feature feature)

{

	set_bit(feature, &device->mmu.features);

}



/**

 * kgsl_add_fault - Add fault information for a context

 * @context: Pointer to the KGSL context

 * @type: type of fault info

 * @priv: Pointer to type specific fault info

 *

 * Return: 0 on success or error code on failure.

 */

int kgsl_add_fault(struct kgsl_context *context, u32 type, void *priv);



/**

 * kgsl_free_faults - Free fault information for a context

 * @context: Pointer to the KGSL context

 */

void kgsl_free_faults(struct kgsl_context *context);



/**

 * kgsl_trace_gpu_mem_total - Overall gpu memory usage tracking which includes

 * process allocations, imported dmabufs and kgsl globals

 * @device: A KGSL device handle

 * @delta: delta of total mapped memory size

 */

#ifdef CONFIG_TRACE_GPU_MEM

static inline void kgsl_trace_gpu_mem_total(struct kgsl_device *device,

						s64 delta)

{

	u64 total_size;



	total_size = atomic64_add_return(delta, &device->total_mapped);

	trace_gpu_mem_total(0, 0, total_size);

}

#else

static inline void kgsl_trace_gpu_mem_total(struct kgsl_device *device,

						s64 delta) {}

#endif



/*

 * kgsl_context_is_lpac() - Checks if context is LPAC

 * @context: KGSL context to check

 *

 * Function returns true if context is LPAC else false

 */

static inline bool kgsl_context_is_lpac(struct kgsl_context *context)

{

	if (context == NULL)

		return false;



	return (context->flags & KGSL_CONTEXT_LPAC) ? true : false;

}



#endif  /* __KGSL_DEVICE_H */





==========================================================================================
FILE: kgsl_gmu_core.c
LINES: 1421 | BYTES: 39394
==========================================================================================

// SPDX-License-Identifier: GPL-2.0-only

/*

 * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.

 * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.

 */



#include <dt-bindings/power/qcom-rpmpd.h>

#include <linux/of.h>

#include <linux/io.h>

#include <linux/of_platform.h>

#include <linux/pm_opp.h>



#include "adreno.h"

#include "adreno_trace.h"

#include "kgsl_device.h"

#include "kgsl_gmu_core.h"

#include "kgsl_power_trace.h"

#include "kgsl_sync.h"

#include "kgsl_trace.h"



static const struct of_device_id gmu_match_table[] = {

	{ .compatible = "qcom,gpu-gmu", .data = &a6xx_gmu_driver },

	{ .compatible = "qcom,gpu-rgmu", .data = &a6xx_rgmu_driver },

	{ .compatible = "qcom,gen7-gmu", .data = &gen7_gmu_driver },

	{ .compatible = "qcom,gen8-gmu", .data = &gen8_gmu_driver },

	{ .compatible = "qcom,adreno-gmu-623.0", .data = &a6xx_gmu_driver },

	{ .compatible = "qcom,adreno-gmu-663.0", .data = &a6xx_gmu_driver },

	{ .compatible = "qcom,adreno-gmu-635.0", .data = &a6xx_gmu_driver },

	{ .compatible = "qcom,adreno-rgmu", .data = &a6xx_rgmu_driver },

	{ .compatible = "qcom,adreno-gmu-x185.1", .data = &gen7_gmu_driver },

	{ .compatible = "qcom,adreno-gmu-x145.0", .data = &gen7_gmu_driver },

	{ .compatible = "qcom,adreno-gmu-x285.1", .data = &gen8_gmu_driver },

	{ .compatible = "qcom,adreno-gmu-x285.0", .data = &gen8_gmu_driver },

	{ .compatible = "qcom,adreno-gmu-x290.1", .data = &gen8_gmu_driver },

	{ .compatible = "qcom,adreno-gmu-722.0", .data = &gen7_gmu_driver },

	{ .compatible = "qcom,adreno-gmu-753.1", .data = &gen7_gmu_driver },

	{ .compatible = "qcom,adreno-gmu-830.1", .data = &gen8_gmu_driver },

	{ .compatible = "qcom,adreno-gmu-840.1", .data = &gen8_gmu_driver },

	{ .compatible = "qcom,adreno-gmu-845.0", .data = &gen8_gmu_driver },

	{ .compatible = "qcom,adreno-gmu-850.1", .data = &gen8_gmu_driver },

	{},

};



void __init gmu_core_register(void)

{

	const struct of_device_id *match;

	struct device_node *node;



	node = of_find_matching_node_and_match(NULL, gmu_match_table,

		&match);

	if (!node)

		return;



	platform_driver_register((struct platform_driver *) match->data);

	of_node_put(node);

}



void gmu_core_unregister(void)

{

	const struct of_device_id *match;

	struct device_node *node;



	node = of_find_matching_node_and_match(NULL, gmu_match_table,

		&match);

	if (!node)

		return;



	platform_driver_unregister((struct platform_driver *) match->data);

	of_node_put(node);

}



bool gmu_core_isenabled(struct kgsl_device *device)

{

	return test_bit(GMU_ENABLED, &device->gmu_core.flags);

}



bool gmu_core_gpmu_isenabled(struct kgsl_device *device)

{

	return (device->gmu_core.dev_ops != NULL);

}



bool gmu_core_scales_bandwidth(struct kgsl_device *device)

{

	const struct gmu_dev_ops *ops = GMU_DEVICE_OPS(device);



	if (ops && ops->scales_bandwidth)

		return ops->scales_bandwidth(device);



	return false;

}



int gmu_core_dev_acd_set(struct kgsl_device *device, bool val)

{

	const struct gmu_dev_ops *ops = GMU_DEVICE_OPS(device);



	if (ops && ops->acd_set)

		return ops->acd_set(device, val);



	return -EINVAL;

}



void gmu_core_regread(struct kgsl_device *device, unsigned int offsetwords,

		unsigned int *value)

{

	u32 val = kgsl_regmap_read(&device->regmap, offsetwords);

	*value  = val;

}



void gmu_core_regwrite(struct kgsl_device *device, unsigned int offsetwords,

		unsigned int value)

{

	kgsl_regmap_write(&device->regmap, value, offsetwords);

}



void gmu_core_blkwrite(struct kgsl_device *device, unsigned int offsetwords,

		const void *buffer, size_t size)

{

	kgsl_regmap_bulk_write(&device->regmap, offsetwords,

		buffer, size >> 2);

}



void gmu_core_regrmw(struct kgsl_device *device,

		unsigned int offsetwords,

		unsigned int mask, unsigned int bits)

{

	kgsl_regmap_rmw(&device->regmap, offsetwords, mask, bits);

}



int gmu_core_dev_oob_set(struct kgsl_device *device, enum oob_request req)

{

	const struct gmu_dev_ops *ops = GMU_DEVICE_OPS(device);



	if (ops && ops->oob_set)

		return ops->oob_set(device, req);



	return 0;

}



void gmu_core_dev_oob_clear(struct kgsl_device *device, enum oob_request req)

{

	const struct gmu_dev_ops *ops = GMU_DEVICE_OPS(device);



	if (ops && ops->oob_clear)

		ops->oob_clear(device, req);

}



void gmu_core_dev_cooperative_reset(struct kgsl_device *device)

{



	const struct gmu_dev_ops *ops = GMU_DEVICE_OPS(device);



	if (ops && ops->cooperative_reset)

		ops->cooperative_reset(device);

}



int gmu_core_dev_ifpc_isenabled(struct kgsl_device *device)

{

	const struct gmu_dev_ops *ops = GMU_DEVICE_OPS(device);



	if (ops && ops->ifpc_isenabled)

		return ops->ifpc_isenabled(device);



	return 0;

}



int gmu_core_dev_ifpc_store(struct kgsl_device *device, unsigned int val)

{

	const struct gmu_dev_ops *ops = GMU_DEVICE_OPS(device);



	if (ops && ops->ifpc_store)

		return ops->ifpc_store(device, val);



	return -EINVAL;

}



int gmu_core_dev_wait_for_active_transition(struct kgsl_device *device)

{

	const struct gmu_dev_ops *ops = GMU_DEVICE_OPS(device);



	if (ops && ops->wait_for_active_transition)

		return ops->wait_for_active_transition(device);



	return 0;

}



void gmu_core_fault_snapshot(struct kgsl_device *device,

			enum gmu_fault_panic_policy gf_policy)

{

	const struct gmu_dev_ops *ops = GMU_DEVICE_OPS(device);



	/* Send NMI first to halt GMU and capture the state close to the point of failure */

	if (ops && ops->send_nmi)

		ops->send_nmi(device, false, gf_policy);



	kgsl_device_snapshot(device, NULL, NULL, true);

}



int gmu_core_timed_poll_check(struct kgsl_device *device,

		unsigned int offset, unsigned int expected_ret,

		unsigned int timeout_ms, unsigned int mask)

{

	u32 val;



	return kgsl_regmap_read_poll_timeout(&device->regmap, offset,

		val, (val & mask) == expected_ret, 100, timeout_ms * 1000);

}



int gmu_core_map_memdesc(struct iommu_domain *domain, struct kgsl_memdesc *memdesc,

		u64 gmuaddr, int attrs)

{

	ssize_t mapped;



	if (!memdesc->pages) {

		mapped = kgsl_mmu_map_sg(domain, gmuaddr, memdesc->sgt->sgl,

			memdesc->sgt->nents, attrs);

	} else {

		struct sg_table sgt = { 0 };

		int ret;



		ret = sg_alloc_table_from_pages(&sgt, memdesc->pages,

			memdesc->page_count, 0, memdesc->size, GFP_KERNEL);



		if (ret)

			return ret;



		mapped = kgsl_mmu_map_sg(domain, gmuaddr, sgt.sgl, sgt.nents, attrs);

		sg_free_table(&sgt);

	}



	if (!mapped)

		mapped = -ENOMEM;



	return (mapped < 0) ? mapped : 0;

}



struct kgsl_memdesc *gmu_core_find_memdesc(struct kgsl_device *device, u32 addr, u32 size)

{

	struct gmu_core_device *gmu = &device->gmu_core;

	int i;



	for (i = 0; i < gmu->global_entries; i++) {

		struct kgsl_memdesc *md = &gmu->gmu_globals[i];



		if ((addr >= md->gmuaddr) &&

				(((addr + size) <= (md->gmuaddr + md->size))))

			return md;

	}



	return NULL;

}



int gmu_core_find_vma_block(struct kgsl_device *device, u32 addr, u32 size)

{

	struct gmu_core_device *gmu = &device->gmu_core;

	int i;



	for (i = 0; i < gmu->num_vmas; i++) {

		struct gmu_vma_entry *vma = &gmu->vma[i];



		if ((addr >= vma->start) &&

			((addr + size) <= (vma->start + vma->size)))

			return i;

	}



	return -ENOENT;

}



void gmu_core_free_globals(struct kgsl_device *device)

{

	struct gmu_core_device *gmu = &device->gmu_core;

	int i;



	for (i = 0; i < gmu->global_entries && i < ARRAY_SIZE(gmu->gmu_globals); i++) {

		struct kgsl_memdesc *md = &gmu->gmu_globals[i];



		if (!md->gmuaddr)

			continue;



		iommu_unmap(gmu->domain, md->gmuaddr, md->size);



		if (TEST_FLAG(KGSL_MEMDESC_SYSMEM, &md->priv))

			kgsl_sharedmem_free(md);



		memset(md, 0, sizeof(*md));

	}



	if (gmu->domain) {

		kgsl_detach_iommu_group(gmu->domain, gmu->group);

		iommu_domain_free(gmu->domain);

		gmu->domain = NULL;

	}



	gmu->global_entries = 0;

}



static struct gmu_vma_node *find_va(struct gmu_vma_entry *vma, u32 addr, u32 size)

{

	struct rb_node *node = vma->vma_root.rb_node;



	while (node != NULL) {

		struct gmu_vma_node *data = rb_entry(node, struct gmu_vma_node, node);



		if (addr + size <= data->va)

			node = node->rb_left;

		else if (addr >= data->va + data->size)

			node = node->rb_right;

		else

			return data;

	}

	return NULL;

}



/* Return true if VMA supports dynamic allocations */

static bool vma_is_dynamic(struct kgsl_device *device, int vma_id)

{

	/* Dynamic allocations are done in the GMU_NONCACHED_KERNEL space */

	return (vma_id == GMU_NONCACHED_KERNEL) && (!adreno_is_a6xx(ADRENO_DEVICE(device)));

}



static int insert_va(struct gmu_vma_entry *vma, u32 addr, u32 size)

{

	struct rb_node **node, *parent = NULL;

	struct gmu_vma_node *new = kzalloc(sizeof(*new), GFP_NOWAIT);



	if (new == NULL)

		return -ENOMEM;



	new->va = addr;

	new->size = size;



	node = &vma->vma_root.rb_node;

	while (*node != NULL) {

		struct gmu_vma_node *this;



		parent = *node;

		this = rb_entry(parent, struct gmu_vma_node, node);



		if (addr + size <= this->va)

			node = &parent->rb_left;

		else if (addr >= this->va + this->size)

			node = &parent->rb_right;

		else {

			kfree(new);

			return -EEXIST;

		}

	}



	/* Add new node and rebalance tree */

	rb_link_node(&new->node, parent, node);

	rb_insert_color(&new->node, &vma->vma_root);



	return 0;

}



static u32 find_unmapped_va(struct gmu_vma_entry *vma, u32 size, u32 va_align)

{

	struct rb_node *node = rb_first(&vma->vma_root);

	u32 cur = vma->start;

	bool found = false;



	cur = ALIGN(cur, va_align);



	while (node) {

		struct gmu_vma_node *data = rb_entry(node, struct gmu_vma_node, node);



		if (cur + size <= data->va) {

			found = true;

			break;

		}



		cur = ALIGN(data->va + data->size, va_align);

		node = rb_next(node);

	}



	/* Do we have space after the last node? */

	if (!found && (cur + size <= vma->start + vma->size))

		found = true;

	return found ? cur : 0;

}



static int _map_gmu_dynamic(struct kgsl_device *device, struct kgsl_memdesc *md,

	u32 addr, u32 vma_id, int attrs, u32 align)

{

	struct gmu_core_device *gmu = &device->gmu_core;

	struct device *gmu_pdev_dev = GMU_PDEV_DEV(device);

	struct gmu_vma_entry *vma = &gmu->vma[vma_id];

	struct gmu_vma_node *vma_node = NULL;

	int ret;

	u32 size = ALIGN(md->size, hfi_get_gmu_sz_alignment(align));



	spin_lock(&vma->lock);

	if (!addr) {

		/*

		 * We will end up with a hole (GMU VA range not backed by physical mapping) if

		 * the aligned size is greater than the size of the physical mapping

		 */

		addr = find_unmapped_va(vma, size, hfi_get_gmu_va_alignment(align));

		if (addr == 0) {

			spin_unlock(&vma->lock);

			dev_err(gmu_pdev_dev,

				"Insufficient VA space size: %x\n", size);

			return -ENOMEM;

		}

	}



	ret = insert_va(vma, addr, size);

	spin_unlock(&vma->lock);

	if (ret < 0) {

		dev_err(gmu_pdev_dev,

			"Could not insert va: %x size %x\n", addr, size);

		return ret;

	}



	ret = gmu_core_map_memdesc(gmu->domain, md, addr, attrs);

	if (!ret) {

		md->gmuaddr = addr;

		return 0;

	}



	/* Failed to map to GMU */

	dev_err(gmu_pdev_dev,

		"Unable to map GMU kernel block: addr:0x%08x size:0x%llx :%d\n",

		addr, md->size, ret);



	spin_lock(&vma->lock);

	vma_node = find_va(vma, md->gmuaddr, size);

	if (vma_node)

		rb_erase(&vma_node->node, &vma->vma_root);

	spin_unlock(&vma->lock);

	kfree(vma_node);



	return ret;

}



static int _map_gmu_static(struct kgsl_device *device, struct kgsl_memdesc *md,

	u32 addr, u32 vma_id, int attrs, u32 align)

{

	struct gmu_core_device *gmu = &device->gmu_core;

	struct gmu_vma_entry *vma = &gmu->vma[vma_id];

	int ret;

	u32 size = ALIGN(md->size, hfi_get_gmu_sz_alignment(align));



	if (!addr)

		addr = ALIGN(vma->next_va, hfi_get_gmu_va_alignment(align));



	ret = gmu_core_map_memdesc(device->gmu_core.domain, md, addr, attrs);

	if (ret) {

		dev_err(GMU_PDEV_DEV(device),

			"Unable to map GMU kernel block: addr:0x%08x size:0x%llx :%d\n",

			addr, md->size, ret);

		return ret;

	}

	md->gmuaddr = addr;

	/*

	 * We will end up with a hole (GMU VA range not backed by physical mapping) if the aligned

	 * size is greater than the size of the physical mapping

	 */

	vma->next_va = md->gmuaddr + size;

	return 0;

}



int gmu_core_reserve_gmuaddr(struct kgsl_device *device, struct kgsl_memdesc *md, u32 vma_id,

	u32 align)

{

	struct gmu_core_device *gmu = &device->gmu_core;

	struct gmu_vma_entry *vma = &gmu->vma[vma_id];

	u32 addr, size = ALIGN(md->size, hfi_get_gmu_sz_alignment(align));



	if (vma_is_dynamic(device, vma_id)) {

		spin_lock(&vma->lock);

		addr = find_unmapped_va(vma, size, hfi_get_gmu_va_alignment(align));

		spin_unlock(&vma->lock);

		if (addr == 0)

			goto error;

	} else {

		addr = ALIGN(vma->next_va, hfi_get_gmu_va_alignment(align));

		if ((addr + size) >= (vma->start + vma->size))

			goto error;

		vma->next_va = addr + size;

	}



	md->gmuaddr = addr;



	return 0;



error:

	dev_err_ratelimited(GMU_PDEV_DEV(device),

		"Insufficient VA space size: %x in vma:%u\n", size, vma_id);

	return -ENOMEM;

}



int gmu_core_map_gmu(struct kgsl_device *device, struct kgsl_memdesc *md,

	u32 addr, u32 vma_id, int attrs, u32 align)

{

	return vma_is_dynamic(device, vma_id) ?

			_map_gmu_dynamic(device, md, addr, vma_id, attrs, align) :

			_map_gmu_static(device, md, addr, vma_id, attrs, align);

}



int gmu_core_get_attrs(u32 flags)

{

	int attrs = IOMMU_READ;



	if (flags & HFI_MEMFLAG_GMU_PRIV)

		attrs |= IOMMU_PRIV;



	if (flags & HFI_MEMFLAG_GMU_WRITEABLE)

		attrs |= IOMMU_WRITE;



	return attrs;

}



int gmu_core_import_buffer(struct kgsl_device *device, struct hfi_mem_alloc_entry *entry)

{

	struct hfi_mem_alloc_desc *desc = &entry->desc;

	u32 attrs = gmu_core_get_attrs(desc->flags);

	u32 vma_id = (desc->flags & HFI_MEMFLAG_GMU_CACHEABLE) ? GMU_CACHE : GMU_NONCACHED_KERNEL;



	/*

	 * GMU Tx/Rx queues are mapped as I/O-coherent on both SOCCP and CPU,

	 * mark the buffer I/O-coherent on GMU side as well to prevent stale

	 * data and immediate updates in DDR.

	 */

	if (desc->mem_kind == HFI_MEMKIND_HW_FENCE &&

		kgsl_mmu_has_feature(device, KGSL_MMU_IO_COHERENT)) {

		entry->md->flags |= KGSL_MEMFLAGS_IOCOHERENT;

		attrs |= IOMMU_CACHE;

	}



	return gmu_core_map_gmu(device, entry->md, 0, vma_id, attrs, desc->align);

}



struct kgsl_memdesc *gmu_core_reserve_kernel_block(struct kgsl_device *device,

	u32 addr, u32 size, u32 vma_id, u32 align)

{

	int ret;

	u64 memflags = 0;

	struct kgsl_memdesc *md;

	struct gmu_core_device *gmu = &device->gmu_core;

	int attrs = IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV;

	struct adreno_device *adreno_dev = ADRENO_DEVICE(device);



	if (gmu->global_entries == ARRAY_SIZE(gmu->gmu_globals))

		return ERR_PTR(-ENOMEM);



	md = &gmu->gmu_globals[gmu->global_entries];



	/*

	 * Apply WB cache policy to fetch GMU FW successfully for A622.

	 * A622 has specific cache coherency requirements that can lead to data

	 * inconsistency if not using writeback cache policy.

	 */

	if (adreno_is_a622(adreno_dev))

		memflags = FIELD_PREP(KGSL_CACHEMODE_MASK, KGSL_CACHEMODE_WRITEBACK);



	ret = kgsl_allocate_kernel(device, md, size, memflags, KGSL_MEMDESC_SYSMEM);

	if (ret) {

		memset(md, 0x0, sizeof(*md));

		return ERR_PTR(-ENOMEM);

	}



	ret = gmu_core_map_gmu(device, md, addr, vma_id, attrs, align);

	if (ret) {

		kgsl_sharedmem_free(md);

		memset(md, 0x0, sizeof(*md));

		return ERR_PTR(ret);

	}



	gmu->global_entries++;



	return md;

}



struct kgsl_memdesc *gmu_core_reserve_kernel_block_fixed(struct kgsl_device *device,

	u32 addr, u32 size, u32 vma_id, const char *resource, int attrs, u32 align)

{

	int ret;

	struct kgsl_memdesc *md;

	struct gmu_core_device *gmu = &device->gmu_core;



	if (gmu->global_entries == ARRAY_SIZE(gmu->gmu_globals))

		return ERR_PTR(-ENOMEM);



	md = &gmu->gmu_globals[gmu->global_entries];



	ret = kgsl_memdesc_init_fixed(device, GMU_PDEV(device), resource, md);

	if (ret)

		return ERR_PTR(ret);



	ret = gmu_core_map_gmu(device, md, addr, vma_id, attrs, align);



	sg_free_table(md->sgt);

	kfree(md->sgt);

	md->sgt = NULL;



	if (!ret) {

		gmu->global_entries++;

	} else {

		dev_err(GMU_PDEV_DEV(device),

			"Unable to map GMU kernel block: addr:0x%08x size:0x%llx :%d\n",

			addr, md->size, ret);

		memset(md, 0x0, sizeof(*md));

		md = ERR_PTR(ret);

	}

	return md;

}



int gmu_core_alloc_kernel_block(struct kgsl_device *device,

	struct kgsl_memdesc *md, u32 size, u32 vma_id, int attrs)

{

	int ret;



	ret = kgsl_allocate_kernel(device, md, size, 0, KGSL_MEMDESC_SYSMEM);

	if (ret)

		return ret;



	ret = gmu_core_map_gmu(device, md, 0, vma_id, attrs, 0);

	if (ret)

		kgsl_sharedmem_free(md);



	return ret;

}



void gmu_core_free_block(struct kgsl_device *device, struct kgsl_memdesc *md)

{

	struct gmu_core_device *gmu = &device->gmu_core;

	int vma_id = gmu_core_find_vma_block(device, md->gmuaddr, md->size);

	struct gmu_vma_entry *vma;

	struct gmu_vma_node *vma_node;



	if ((vma_id < 0) || !vma_is_dynamic(device, vma_id))

		return;



	vma = &gmu->vma[vma_id];



	/*

	 * Do not remove the vma node if we failed to unmap the entire buffer. This is because the

	 * iommu driver considers remapping an already mapped iova as fatal.

	 */

	if (md->size != iommu_unmap(device->gmu_core.domain, md->gmuaddr, md->size))

		goto free;



	spin_lock(&vma->lock);

	vma_node = find_va(vma, md->gmuaddr, md->size);

	if (vma_node)

		rb_erase(&vma_node->node, &vma->vma_root);

	spin_unlock(&vma->lock);

	kfree(vma_node);

free:

	kgsl_sharedmem_free(md);

}



int gmu_core_process_prealloc(struct kgsl_device *device, struct gmu_block_header *blk)

{

	struct kgsl_memdesc *md;

	int id = gmu_core_find_vma_block(device, blk->addr, blk->value);



	if (id < 0) {

		dev_err(GMU_PDEV_DEV(device),

			"Invalid prealloc block addr: 0x%x value:%d\n",

			blk->addr, blk->value);

		return id;

	}



	/* Nothing to do for TCM blocks or user uncached */

	if (id == GMU_ITCM || id == GMU_DTCM || id == GMU_NONCACHED_USER)

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